Package org.apache.batik.util

Examples of org.apache.batik.util.ParsedURL


            /* Nothing to do */
        }

        if (node == null) {
            String baseURI = XMLBaseSupport.getCascadedXMLBase(e);
            ParsedURL purl;
            if (baseURI == null)
                purl = new ParsedURL(uriStr);
            else
                purl = new ParsedURL(baseURI, uriStr);

            // try to load the image as a raster image (JPG or PNG)
            node = createRasterImageNode(ctx, e, purl);
        }

View Full Code Here


     * This method supports gzipped sources.
     * @param uri The document URI.
     * @exception IOException if an error occured while reading the document.
     */
    public SVGOMDocument createDocument(String uri) throws IOException {
        ParsedURL purl = new ParsedURL(uri);

        InputStream is = purl.openStream(MimeTypeConstants.MIME_TYPES_SVG);

        InputSource isrc = new InputSource(is);
       
        // now looking for a charset encoding in the content type such
        // as "image/svg+xml; charset=iso8859-1" this is not official
        // for image/svg+xml yet! only for text/xml and maybe
        // for application/xml
        String contentType = purl.getContentType();
        int cindex = -1;
        if (contentType != null) {
            contentType = contentType.toLowerCase();
            cindex = contentType.indexOf(HTTP_CHARSET);
        }
        if (cindex != -1) {
            int i                 = cindex + HTTP_CHARSET.length();
            int eqIdx = contentType.indexOf('=', i);
            if (eqIdx != -1) {
                eqIdx++; // no one is interested in the equals sign...

                String charset;
                // The patch had ',' as the terminator but I suspect
                // that is the delimiter between possible charsets,
                // but if another 'attribute' were in the accept header
                // charset would be terminated by a ';'.  So I look
                // for both and take to closer of the two.
                int idx     = contentType.indexOf(',', eqIdx);
                int semiIdx = contentType.indexOf(';', eqIdx);
                if ((semiIdx != -1) && ((semiIdx < idx) || (idx == -1)))
                    idx = semiIdx;
                if (idx != -1)
                    charset = contentType.substring(eqIdx, idx);
                else
                    charset = contentType.substring(eqIdx);
                isrc.setEncoding(charset.trim());
            }
        }

        isrc.setSystemId(uri);

        SVGOMDocument doc = (SVGOMDocument)super.createDocument
            (SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", uri, isrc);
        try {
            doc.setURLObject(new URL(purl.toString()));
        } catch (MalformedURLException mue) {
            // Not very likely to happen given we already opened the stream.
            throw new IOException("Malformed URL: " + uri);
        }

View Full Code Here

                                                        ctx);

        Filter filter = null;
        // try to load the image as an svg document
        SVGDocument svgDoc = (SVGDocument)filterElement.getOwnerDocument();
        ParsedURL purl;
        URL baseURL = ((SVGOMDocument)svgDoc).getURLObject();
        if (baseURL != null)
            purl = new ParsedURL(baseURL.toString(), uriStr);
        else
            purl = new ParsedURL(uriStr);

        // try to load an SVG document
        DocumentLoader loader = ctx.getDocumentLoader();
        URIResolver resolver = new URIResolver(svgDoc, loader);
        boolean toBBoxNeeded = false;
        try {
            Element refElement = null;
            Node n = resolver.getNode(purl.toString(), filterElement);
            if (n.getNodeType() == n.DOCUMENT_NODE) {
                refElement = ((SVGDocument)n).getRootElement();
            } else if (n.getNodeType() == Node.ELEMENT_NODE) {
                refElement = (Element)n;
                toBBoxNeeded = true;
View Full Code Here

        Attr xmlBase = localRefElement.getAttributeNodeNS
            (XML_NAMESPACE_URI, "xml:base");
        if (xmlBase != null) {
            // We have a current base so merge it with our new base and
            // set the result...
            ParsedURL purl = new ParsedURL(uri, xmlBase.getNodeValue());
            uri = purl.toString();
        }
        localRefElement.setAttributeNS(XML_NAMESPACE_URI,
                                       "xml:base",
                                       uri);
View Full Code Here

     * Loads an image from a URL
     */
    protected BufferedImage getImage(URL url)
        throws IOException {
        ImageTagRegistry reg = ImageTagRegistry.getRegistry();
        Filter filt = reg.readURL(new ParsedURL(url));
        if(filt == null)
            throw new IOException(Messages.formatMessage
                                  (COULD_NOT_LOAD_IMAGE,
                                   new Object[]{url.toString()}));

View Full Code Here

     * @param ctx the bridge context
     */
    public BaseScriptingEnvironment(BridgeContext ctx) {
        bridgeContext = ctx;
        document = ctx.getDocument();
        docPURL = new ParsedURL(((SVGDocument)document).getURL());
        userAgent     = bridgeContext.getUserAgent();
    }
View Full Code Here

            // Java code invocation.
            //
            if (type.equals(SVGConstants.SVG_SCRIPT_TYPE_JAVA)) {
                try {
                    String href = XLinkSupport.getXLinkHref(script);
                    ParsedURL purl = new ParsedURL
                        (XMLBaseSupport.getCascadedXMLBase(script), href);

                    checkCompatibleScriptURL(type, purl);

                    DocumentJarClassLoader cll;
                    URL docURL = null;
                    try {
                        docURL = new URL(docPURL.toString());
                    } catch (MalformedURLException mue) {
                        /* nothing just let docURL be null */
                    }
                    cll = new DocumentJarClassLoader
                        (new URL(purl.toString()), docURL);
                   
                    // Get the 'Script-Handler' entry in the manifest.
                    URL url = cll.findResource("META-INF/MANIFEST.MF");
                    if (url == null) {
                        continue;
                    }
                    Manifest man = new Manifest(url.openStream());
                    String sh;
                    sh = man.getMainAttributes().getValue("Script-Handler");
                    if (sh == null) {
                        continue;
                    }
                   
                    // Run the script handler.
                    ScriptHandler h;
                    h = (ScriptHandler)cll.loadClass(sh).newInstance();
                   
                    if (window == null) {
                        window = createWindow();
                    }
                   
                    h.run(document, window);
                } catch (Exception e) {
                    if (userAgent != null) {
                        userAgent.displayError(e);
                    }
                }
                continue;
            }

            //
            // Scripting language invocation.
            //
            Interpreter interpreter = bridgeContext.getInterpreter(type);

            if (interpreter == null) {
                UserAgent ua = bridgeContext.getUserAgent();
                if (ua != null) {
                    ua.displayError(new Exception("Unknown language: "+type));
                }
                return;
            }

            if (!languages.contains(type)) {
                languages.add(type);
                initializeEnvironment(interpreter, type);
            }

            try {
                String href = XLinkSupport.getXLinkHref(script);
                Reader reader;
                if (href.length() > 0) {
                    // External script.
                    ParsedURL purl = new ParsedURL
                        (XMLBaseSupport.getCascadedXMLBase(script), href);
                    checkCompatibleScriptURL(type, purl);
                    reader = new InputStreamReader(purl.openStream());
                } else {
                    // Inline script.
                    Node n = script.getFirstChild();
                    if (n != null) {
                        StringBuffer sb = new StringBuffer();
View Full Code Here

                                                        ctx);

        Filter filter = null;
        // try to load the image as an svg document
        SVGDocument svgDoc = (SVGDocument)filterElement.getOwnerDocument();
        ParsedURL purl;
        URL baseURL = ((SVGOMDocument)svgDoc).getURLObject();
        if (baseURL != null)
            purl = new ParsedURL(baseURL.toString(), uriStr);
        else
            purl = new ParsedURL(uriStr);

        // try to load an SVG document
        DocumentLoader loader = ctx.getDocumentLoader();
        URIResolver resolver = new URIResolver(svgDoc, loader);
        boolean toBBoxNeeded = false;
        try {
            Element refElement = null;
            Node n = resolver.getNode(purl.toString(), filterElement);
            if (n.getNodeType() == n.DOCUMENT_NODE) {
                refElement = ((SVGDocument)n).getRootElement();
            } else if (n.getNodeType() == Node.ELEMENT_NODE) {
                refElement = (Element)n;
                toBBoxNeeded = true;
View Full Code Here

        // try to load the corresponding ICC profile xlink:href
        String href = XLinkSupport.getXLinkHref(profile);
        ICC_Profile p = null;
        if (href != null) {
            String baseURI= ((SVGOMDocument)doc).getURL();
            ParsedURL purl = new ParsedURL(baseURI, href);
            if (!purl.complete())
                throw new BridgeException(paintedElement, ERR_URI_MALFORMED,
                                          new Object[] {href});
            try{
                p = ICC_Profile.getInstance(purl.openStream());
            } catch(IOException e) {
                throw new BridgeException(paintedElement, ERR_URI_IO,
                                          new Object[] {href});
                // ??? IS THAT AN ERROR FOR THE SVG SPEC ???
            }
View Full Code Here

        String baseURI = XMLBaseSupport.getCascadedXMLBase(ref);
        if ((baseURI == null) &&
            (uri.startsWith("#")))
            return document.getElementById(uri.substring(1));

        ParsedURL purl = new ParsedURL(baseURI, uri);

        if (documentURI == null)
            documentURI = document.getURL();

        String    frag  = purl.getRef();
        if ((frag != null) && (documentURI != null)) {
            ParsedURL pDocURL = new ParsedURL(documentURI);

            // Check if the rest of the URL matches...
            // if so then return the referenced element.
            if ((pDocURL.getPort()      == purl.getPort()) &&
                ((pDocURL.getPath()     == purl.getPath())
                 || ((pDocURL.getPath()!=null)
                     && pDocURL.getPath().equals(purl.getPath()))) &&
                ((pDocURL.getHost()     == purl.getHost())
                 || ((pDocURL.getHost()!=null)
                     && pDocURL.getHost().equals(purl.getHost()))) &&
                ((pDocURL.getProtocol()     == purl.getProtocol())
                 || ((pDocURL.getProtocol()!=null)
                     && pDocURL.getProtocol().equals(purl.getProtocol()))))
                return document.getElementById(frag);
        }

        // uri is not a reference into this document, so load the
        // document it does reference.
View Full Code Here

TOP

Related Classes of org.apache.batik.util.ParsedURL

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.