vhardy 2002/07/12 09:01:33 Modified: sources/org/apache/batik/apps/svgbrowser XMLInputHandler.java Log: Added DocumentURIResolver to handler document() function properly (i.e., to handle relative uris inputs in the transformation Revision Changes Path 1.2 +39 -7 xml-batik/sources/org/apache/batik/apps/svgbrowser/XMLInputHandler.java Index: XMLInputHandler.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/XMLInputHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XMLInputHandler.java 11 Jul 2002 16:42:45 -0000 1.1 +++ XMLInputHandler.java 12 Jul 2002 16:01:33 -0000 1.2 @@ -32,14 +32,16 @@ import org.w3c.dom.svg.SVGDocument; import org.w3c.dom.stylesheets.StyleSheet; -import javax.xml.transform.TransformerFactory; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Source; import javax.xml.transform.Transformer; -import javax.xml.transform.stream.StreamSource; -import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.stream.StreamSource; import org.apache.batik.dom.util.DOMUtilities; import org.apache.batik.dom.util.HashTable; @@ -182,6 +184,10 @@ = tFactory.newTransformer (new StreamSource(parsedXSLStyleSheetURI.toString())); + // Set the URIResolver to properly handle document() and xsl:include + transformer.setURIResolver + (new DocumentURIResolver(parsedXSLStyleSheetURI.toString())); + // Now, apply the transformation to the input document. DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; @@ -192,7 +198,8 @@ // but this was the only solution found to be able to // generate content in the proper namespaces. // - // SVGOMDocument outDoc = (SVGOMDocument)impl.createDocument(svgNS, "svg", null); + // SVGOMDocument outDoc = + // (SVGOMDocument)impl.createDocument(svgNS, "svg", null); // outDoc.setURLObject(new URL(uri)); // transformer.transform // (new DOMSource(inDoc), @@ -213,6 +220,10 @@ outDoc = f.createDocument(uri, new StringReader(sw.toString())); } catch (Exception e) { + System.err.println("======================================"); + System.err.println(sw.toString()); + System.err.println("======================================"); + throw new IllegalArgumentException (Resources.getString(ERROR_RESULT_GENERATED_EXCEPTION)); } @@ -301,4 +312,25 @@ return null; } + /** + * Implements the URIResolver interface so that relative urls used in + * transformations are resolved properly. + */ + public class DocumentURIResolver implements URIResolver { + String documentURI; + + public DocumentURIResolver(String documentURI) { + this.documentURI = documentURI; + } + + public Source resolve(String href, String base) { + if (base == null || "".equals(base)) { + base = documentURI; + } + + ParsedURL purl = new ParsedURL(base, href); + + return new StreamSource(purl.toString()); + } + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]