bug fix with user agent style sheet. Now it works both in the main document and the reference element or svg image.

PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/batik/trunk@199760 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sources/org/apache/batik/bridge/BridgeContext.java b/sources/org/apache/batik/bridge/BridgeContext.java
index 60a2bd4..be9cfa0 100644
--- a/sources/org/apache/batik/bridge/BridgeContext.java
+++ b/sources/org/apache/batik/bridge/BridgeContext.java
@@ -142,7 +142,7 @@
         this(userAgent,
              rc,
              sharedPool,
-             new DocumentLoader(userAgent.getXMLParserClassName()));
+             new DocumentLoader(userAgent));
     }
 
     /**
diff --git a/sources/org/apache/batik/bridge/DocumentLoader.java b/sources/org/apache/batik/bridge/DocumentLoader.java
index d988d6f..40864f7 100644
--- a/sources/org/apache/batik/bridge/DocumentLoader.java
+++ b/sources/org/apache/batik/bridge/DocumentLoader.java
@@ -11,8 +11,10 @@
 import java.io.IOException;
 import java.util.HashMap;
 
+import org.apache.batik.dom.svg.DefaultSVGContext;
 import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
 import org.apache.batik.dom.svg.SVGDocumentFactory;
+import org.apache.batik.dom.svg.SVGOMDocument;
 
 import org.apache.batik.dom.util.DocumentDescriptor;
 
@@ -47,16 +49,23 @@
     protected HashMap cacheMap = new HashMap();
 
     /**
+     * The user agent.
+     */
+    protected UserAgent userAgent;
+
+    /**
      * Constructs a new <tt>DocumentLoader</tt>.
      */
     protected DocumentLoader() { }
 
     /**
      * Constructs a new <tt>DocumentLoader</tt> with the specified XML parser.
-     * @param parser The SAX2 parser classname.
+     * @param userAgent the user agent to use
      */
-    public DocumentLoader(String parser) {
-        documentFactory = new SAXSVGDocumentFactory(parser, true);
+    public DocumentLoader(UserAgent userAgent) {
+        this.userAgent = userAgent;
+        documentFactory = new SAXSVGDocumentFactory
+            (userAgent.getXMLParserClassName(), true);
     }
 
     /**
@@ -74,6 +83,10 @@
             //System.out.println("loading: "+uri);
             // load the document
             Document document = documentFactory.createDocument(uri);
+            DefaultSVGContext ctx
+                = (DefaultSVGContext)((SVGOMDocument)document).getSVGContext();
+            ctx.setUserStyleSheetURI(userAgent.getUserStyleSheetURI());
+
             DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
             state = new DocumentState(uri, document, desc);
             cacheMap.put(uri, state);
diff --git a/sources/org/apache/batik/swing/gvt/JGVTComponent.java b/sources/org/apache/batik/swing/gvt/JGVTComponent.java
index 237df74..de72240 100755
--- a/sources/org/apache/batik/swing/gvt/JGVTComponent.java
+++ b/sources/org/apache/batik/swing/gvt/JGVTComponent.java
@@ -55,7 +55,7 @@
  * @version $Id$
  */
 public class JGVTComponent extends JComponent {
-    
+
     /**
      * The listener.
      */
@@ -165,12 +165,12 @@
 
     /**
      * Whether to suspend interactions.
-     */ 
+     */
     protected boolean suspendInteractions;
 
     /**
      * Whether to inconditionally disable interactions.
-     */ 
+     */
     protected boolean disableInteractions;
 
     /**
@@ -456,7 +456,7 @@
             gvtTreeRenderer.addGVTTreeRendererListener
                 ((GVTTreeRendererListener)it.next());
         }
-        
+
         // Disable the dispatch during the rendering
         // to avoid concurrent access to the GVT tree.
         if (eventDispatcher != null) {
@@ -588,7 +588,7 @@
                 suspendInteractions = false;
             }
         }
-        
+
         /**
          * Called when a rendering was completed.
          */
@@ -611,14 +611,14 @@
                 eventDispatcher.setRootNode(gvtRoot);
             }
         }
-        
+
         /**
          * Called when a rendering was cancelled.
          */
         public void gvtRenderingCancelled(GVTTreeRendererEvent e) {
             renderingStopped();
         }
-        
+
         /**
          * Called when a rendering failed.
          */
@@ -659,7 +659,7 @@
                 deselectInteractor();
             }
         }
-        
+
         /**
          * Invoked when a key has been pressed.
          */
@@ -687,7 +687,7 @@
         }
 
         // MouseListener ///////////////////////////////////////////////////////
-        
+
         /**
          * Invoked when the mouse has been clicked on a component.
          */
@@ -756,7 +756,7 @@
         // MouseMotionListener /////////////////////////////////////////////////
 
         /**
-         * Invoked when a mouse button is pressed on a component and then 
+         * Invoked when a mouse button is pressed on a component and then
          * dragged.  Mouse drag events will continue to be delivered to
          * the component where the first originated until the mouse button is
          * released (regardless of whether the mouse position is within the
diff --git a/sources/org/apache/batik/swing/svg/JSVGComponent.java b/sources/org/apache/batik/swing/svg/JSVGComponent.java
index f7a2f8c..563bcfa 100755
--- a/sources/org/apache/batik/swing/svg/JSVGComponent.java
+++ b/sources/org/apache/batik/swing/svg/JSVGComponent.java
@@ -35,7 +35,6 @@
 import org.apache.batik.bridge.ViewBox;
 import org.apache.batik.bridge.UserAgent;
 
-import org.apache.batik.dom.svg.DefaultSVGContext;
 import org.apache.batik.dom.svg.SVGDOMImplementation;
 import org.apache.batik.dom.svg.SVGOMDocument;
 
@@ -193,7 +192,7 @@
         url = newURI.toString();
         fragmentIdentifier = newURI.getRef();
 
-        loader = new DocumentLoader(userAgent.getXMLParserClassName());
+        loader = new DocumentLoader(userAgent);
         nextDocumentLoader = new SVGDocumentLoader(url, loader);
         nextDocumentLoader.setPriority(Thread.MIN_PRIORITY);
 
@@ -237,9 +236,6 @@
 
         svgDocument = doc;
 
-        DefaultSVGContext ctx = (DefaultSVGContext)((SVGOMDocument)doc).getSVGContext();
-        ctx.setUserStyleSheetURI(userAgent.getUserStyleSheetURI());
-
         Element root = doc.getDocumentElement();
         String znp = root.getAttributeNS(null, SVGConstants.SVG_ZOOM_AND_PAN_ATTRIBUTE);
         disableInteractions = !znp.equals(SVGConstants.SVG_MAGNIFY_VALUE);
@@ -300,7 +296,7 @@
      */
     protected BridgeContext createBridgeContext() {
         if (loader == null) {
-            loader = new DocumentLoader(userAgent.getXMLParserClassName());
+            loader = new DocumentLoader(userAgent);
         }
         return new BridgeContext(userAgent,
                                  rendererFactory.getRenderContext(),
@@ -567,7 +563,7 @@
                 return;
             }
         }
-        
+
         /**
          * Called when a rendering failed.
          */