Package org.apache.batik.dom

Examples of org.apache.batik.dom.AbstractElement$ElementTypeInfo


        String eltLN = elt.getLocalName();
        if (SVGConstants.SVG_NAMESPACE_URI.equals(eltNS)
                && SVG12Constants.SVG_HANDLER_TAG.equals(eltLN)) {
            // For this 'handler' element, add a handler for the given
            // event type.
            AbstractElement tgt = (AbstractElement) elt.getParentNode();
            String eventType = elt.getAttributeNS
                (XMLConstants.XML_EVENTS_NAMESPACE_URI,
                 XMLConstants.XML_EVENTS_EVENT_ATTRIBUTE);
            String eventNamespaceURI = XMLConstants.XML_EVENTS_NAMESPACE_URI;
            if (eventType.indexOf(':') != -1) {
                String prefix = DOMUtilities.getPrefix(eventType);
                eventType = DOMUtilities.getLocalName(eventType);
                eventNamespaceURI
                    = ((AbstractElement) elt).lookupNamespaceURI(prefix);
            }

            EventListener listener = new HandlerScriptingEventListener
                (eventNamespaceURI, eventType, (AbstractElement) elt);
            tgt.addEventListenerNS
                (eventNamespaceURI, eventType, listener, false, null);
            if (handlerScriptingListeners == null) {
                handlerScriptingListeners = new TriplyIndexedTable();
            }
            handlerScriptingListeners.put
View Full Code Here


        String eltLN = elt.getLocalName();
        if (SVGConstants.SVG_NAMESPACE_URI.equals(eltNS)
                && SVG12Constants.SVG_HANDLER_TAG.equals(eltLN)) {
            // For this 'handler' element, remove the handler for the given
            // event type.
            AbstractElement tgt = (AbstractElement) elt.getParentNode();
            String eventType = elt.getAttributeNS
                (XMLConstants.XML_EVENTS_NAMESPACE_URI,
                 XMLConstants.XML_EVENTS_EVENT_ATTRIBUTE);
            String eventNamespaceURI = XMLConstants.XML_EVENTS_NAMESPACE_URI;
            if (eventType.indexOf(':') != -1) {
                String prefix = DOMUtilities.getPrefix(eventType);
                eventType = DOMUtilities.getLocalName(eventType);
                eventNamespaceURI
                    = ((AbstractElement) elt).lookupNamespaceURI(prefix);
            }

            EventListener listener =
                (EventListener) handlerScriptingListeners.put
                    (eventNamespaceURI, eventType, elt, null);
            tgt.removeEventListenerNS
                (eventNamespaceURI, eventType, listener, false);
        }

        super.removeScriptingListenersOn(elt);
    }
View Full Code Here

        if (len == 0) {
            return;
        }

        for (int i = 0; i < len; i++) {
            AbstractElement script = (AbstractElement) scripts.item(i);
            String type = script.getAttributeNS
                (null, SVGConstants.SVG_TYPE_ATTRIBUTE);

            if (type.length() == 0) {
                type = SVGConstants.SVG_SCRIPT_TYPE_DEFAULT_VALUE;
            }

            //
            // Java code invocation.
            //
            if (type.equals(SVGConstants.SVG_SCRIPT_TYPE_JAVA)) {
                try {
                    String href = XLinkSupport.getXLinkHref(script);
                    ParsedURL purl = new ParsedURL(script.getBaseURI(), 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) {
                        // Run the script handler.
                        ScriptHandler h;
                        h = (ScriptHandler)cll.loadClass(sh).newInstance();

                        if (window == null) {
                            window = createWindow();
                        }

                        h.run(document, window);
                    }

                    sh = man.getMainAttributes().getValue("SVG-Handler-Class");
                    if (sh != null) {
                        // Run the initializer
                        EventListenerInitializer initializer;
                        initializer =
                            (EventListenerInitializer)cll.loadClass(sh).newInstance();

                        if (window == null) {
                            window = createWindow();
                        }

                        initializer.initializeEventListeners((SVGDocument)document);
                    }
                } catch (Exception e) {
                    if (userAgent != null) {
                        userAgent.displayError(e);
                    }
                }
                continue;
            }

            //
            // Scripting language invocation.
            //
            Interpreter interpreter = getInterpreter(type);
            if (interpreter == null)
                // Can't find interpreter so just skip this script block.
                continue;

            try {
                String href = XLinkSupport.getXLinkHref(script);
                String desc = null;
                Reader reader = null;

                if (href.length() > 0) {
                    desc = href;

                    // External script.
                    ParsedURL purl = new ParsedURL(script.getBaseURI(), href);

                    checkCompatibleScriptURL(type, purl);
                    InputStream is = purl.openStream();
                    String mediaType = purl.getContentTypeMediaType();
                    String enc = purl.getContentTypeCharset();
                    if (enc != null) {
                        try {
                            reader = new InputStreamReader(is, enc);
                        } catch (UnsupportedEncodingException uee) {
                            enc = null;
                        }
                    }
                    if (reader == null) {
                        if (APPLICATION_ECMASCRIPT.equals(mediaType)) {
                            // No encoding was specified in the MIME type, so
                            // infer it according to RFC 4329.
                            if (purl.hasContentTypeParameter("version")) {
                                // Future versions of application/ecmascript
                                // are not supported, so skip this script
                                // element if the version parameter is present.
                                continue;
                            }

                            PushbackInputStream pbis =
                                new PushbackInputStream(is, 8);
                            byte[] buf = new byte[4];
                            int read = pbis.read(buf);
                            if (read > 0) {
                                pbis.unread(buf, 0, read);
                                if (read >= 2) {
                                    if (buf[0] == (byte)0xff &&
                                            buf[1] == (byte)0xfe) {
                                        if (read >= 4 && buf[2] == 0 &&
                                                buf[3] == 0) {
                                            enc = "UTF32-LE";
                                            pbis.skip(4);
                                        } else {
                                            enc = "UTF-16LE";
                                            pbis.skip(2);
                                        }
                                    } else if (buf[0] == (byte)0xfe &&
                                            buf[1] == (byte)0xff) {
                                        enc = "UTF-16BE";
                                        pbis.skip(2);
                                    } else if (read >= 3
                                            && buf[0] == (byte)0xef
                                            && buf[1] == (byte)0xbb
                                            && buf[2] == (byte)0xbf) {
                                        enc = "UTF-8";
                                        pbis.skip(3);
                                    } else if (read >= 4 && buf[0] == 0 &&
                                            buf[1] == 0 &&
                                            buf[2] == (byte)0xfe &&
                                            buf[3] == (byte)0xff) {
                                        enc = "UTF-32BE";
                                        pbis.skip(4);
                                    }
                                }
                                if (enc == null) {
                                    enc = "UTF-8";
                                }
                            }
                            reader = new InputStreamReader(pbis, enc);
                        } else {
                            reader = new InputStreamReader(is);
                        }
                    }
                } else {
                    checkCompatibleScriptURL(type, docPURL);
                    DocumentLoader dl = bridgeContext.getDocumentLoader();
                    Element e = script;
                    SVGDocument d = (SVGDocument)e.getOwnerDocument();
                    int line = dl.getLineNumber(script);
                    desc = Messages.formatMessage
                        (INLINE_SCRIPT_DESCRIPTION,
                         new Object [] {d.getURL(),
                                        "<"+script.getNodeName()+">",
                                        new Integer(line)});
                    // Inline script.
                    Node n = script.getFirstChild();
                    if (n != null) {
                        StringBuffer sb = new StringBuffer();
                        while (n != null) {
                            if (n.getNodeType() == Node.CDATA_SECTION_NODE
                                || n.getNodeType() == Node.TEXT_NODE)
View Full Code Here

    public boolean runImplBasic() throws Exception {
        String parser = XMLResourceDescriptor.getXMLParserClassName();
        SAXDocumentFactory df = new SAXDocumentFactory(GenericDOMImplementation.getDOMImplementation(), parser);
        Document doc = df.createDocument("http://example.org/", new StringReader(DOC));

        AbstractElement a = (AbstractElement) doc.getDocumentElement();
        AbstractElement b = (AbstractElement) a.getFirstChild();
        AbstractElement c = (AbstractElement) b.getNextSibling();
        AbstractElement d = (AbstractElement) c.getNextSibling();
        AbstractElement g = (AbstractElement) d.getNextSibling();

        // (1) Test firstElementChild with no children
        ensure(1, b.getFirstElementChild() == null);

        // (2) Test firstElementChild with children but no element children
        ensure(2, c.getFirstElementChild() == null);

        // (3) Test firstElementChild with children but element child is not first
        AbstractElement e = (AbstractElement) d.getFirstElementChild();
        ensure(3, e != null && e.getNodeName().equals("e"));

        // (4) Test firstElementChild with children and element child is first
        AbstractElement h = (AbstractElement) g.getFirstElementChild();
        ensure(4, h != null && h.getNodeName().equals("h"));

        // (5) Test lastElementChild with no children
        ensure(5, b.getLastElementChild() == null);

        // (6) Test lastElementChild with children but no element children
        ensure(6, c.getLastElementChild() == null);

        // (7) Test lastElementChild with children but element child is not last
        AbstractElement f = (AbstractElement) d.getLastElementChild();
        ensure(7, f != null && f.getNodeName().equals("f"));

        // (8) Test lastElementChild with children and element child is last
        AbstractElement i = (AbstractElement) g.getLastElementChild();
        ensure(8, i != null && i.getNodeName().equals("i"));

        // (9) Test nextElementSibling with no next sibling
        ensure(9, a.getNextElementSibling() == null);

        // (10) Test nextElementSibling with next siblings but no element next sibling
        ensure(10, f.getNextElementSibling() == null);

        // (11) Test nextElementSibling with next element sibling but not first
        ensure(11, h.getNextElementSibling() == i);

        // (12) Test nextElementSibling with next element sibling which is first
        ensure(12, e.getNextElementSibling() == f);

        // (13) Test previousElementSibling with no previous sibling
        ensure(13, a.getPreviousElementSibling() == null);

        // (14) Test previousElementSibling with previous siblings but no element previous sibling
        ensure(14, e.getPreviousElementSibling() == null);

        // (15) Test previousElementSibling with previous element sibling but not first
        ensure(15, i.getPreviousElementSibling() == h);

        // (16) Test previousElementSibling with previous element sibling which is first
        ensure(16, f.getPreviousElementSibling() == e);

        // (17-20) Test childElementCount for a few cases
View Full Code Here

        if (len == 0) {
            return;
        }

        for (int i = 0; i < len; i++) {
            AbstractElement script = (AbstractElement) scripts.item(i);
            String type = script.getAttributeNS
                (null, SVGConstants.SVG_TYPE_ATTRIBUTE);

            if (type.length() == 0) {
                type = SVGConstants.SVG_SCRIPT_TYPE_DEFAULT_VALUE;
            }

            //
            // Java code invocation.
            //
            if (type.equals(SVGConstants.SVG_SCRIPT_TYPE_JAVA)) {
                try {
                    String href = XLinkSupport.getXLinkHref(script);
                    ParsedURL purl = new ParsedURL(script.getBaseURI(), 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) {
                        // Run the script handler.
                        ScriptHandler h;
                        h = (ScriptHandler)cll.loadClass(sh).newInstance();

                        if (window == null) {
                            window = createWindow();
                        }

                        h.run(document, window);
                    }

                    sh = man.getMainAttributes().getValue("SVG-Handler-Class");
                    if (sh != null) {
                        // Run the initializer
                        EventListenerInitializer initializer;
                        initializer =
                            (EventListenerInitializer)cll.loadClass(sh).newInstance();

                        if (window == null) {
                            window = createWindow();
                        }

                        initializer.initializeEventListeners((SVGDocument)document);
                    }
                } catch (Exception e) {
                    if (userAgent != null) {
                        userAgent.displayError(e);
                    }
                }
                continue;
            }

            //
            // Scripting language invocation.
            //
            Interpreter interpreter = getInterpreter(type);
            if (interpreter == null)
                // Can't find interpreter so just skip this script block.
                continue;

            try {
                String href = XLinkSupport.getXLinkHref(script);
                String desc = null;
                Reader reader = null;

                if (href.length() > 0) {
                    desc = href;

                    // External script.
                    ParsedURL purl = new ParsedURL(script.getBaseURI(), href);

                    checkCompatibleScriptURL(type, purl);
                    InputStream is = purl.openStream();
                    String mediaType = purl.getContentTypeMediaType();
                    String enc = purl.getContentTypeCharset();
                    if (enc != null) {
                        try {
                            reader = new InputStreamReader(is, enc);
                        } catch (UnsupportedEncodingException uee) {
                            enc = null;
                        }
                    }
                    if (reader == null) {
                        if (APPLICATION_ECMASCRIPT.equals(mediaType)) {
                            // No encoding was specified in the MIME type, so
                            // infer it according to RFC 4329.
                            if (purl.hasContentTypeParameter("version")) {
                                // Future versions of application/ecmascript
                                // are not supported, so skip this script
                                // element if the version parameter is present.
                                continue;
                            }

                            PushbackInputStream pbis =
                                new PushbackInputStream(is, 8);
                            byte[] buf = new byte[4];
                            int read = pbis.read(buf);
                            if (read > 0) {
                                pbis.unread(buf, 0, read);
                                if (read >= 2) {
                                    if (buf[0] == (byte)0xff &&
                                            buf[1] == (byte)0xfe) {
                                        if (read >= 4 && buf[2] == 0 &&
                                                buf[3] == 0) {
                                            enc = "UTF32-LE";
                                            pbis.skip(4);
                                        } else {
                                            enc = "UTF-16LE";
                                            pbis.skip(2);
                                        }
                                    } else if (buf[0] == (byte)0xfe &&
                                            buf[1] == (byte)0xff) {
                                        enc = "UTF-16BE";
                                        pbis.skip(2);
                                    } else if (read >= 3
                                            && buf[0] == (byte)0xef
                                            && buf[1] == (byte)0xbb
                                            && buf[2] == (byte)0xbf) {
                                        enc = "UTF-8";
                                        pbis.skip(3);
                                    } else if (read >= 4 && buf[0] == 0 &&
                                            buf[1] == 0 &&
                                            buf[2] == (byte)0xfe &&
                                            buf[3] == (byte)0xff) {
                                        enc = "UTF-32BE";
                                        pbis.skip(4);
                                    }
                                }
                                if (enc == null) {
                                    enc = "UTF-8";
                                }
                            }
                            reader = new InputStreamReader(pbis, enc);
                        } else {
                            reader = new InputStreamReader(is);
                        }
                    }
                } else {
                    checkCompatibleScriptURL(type, docPURL);
                    DocumentLoader dl = bridgeContext.getDocumentLoader();
                    Element e = script;
                    SVGDocument d = (SVGDocument)e.getOwnerDocument();
                    int line = dl.getLineNumber(script);
                    desc = Messages.formatMessage
                        (INLINE_SCRIPT_DESCRIPTION,
                         new Object [] {d.getURL(),
                                        "<"+script.getNodeName()+">",
                                        new Integer(line)});
                    // Inline script.
                    Node n = script.getFirstChild();
                    if (n != null) {
                        StringBuffer sb = new StringBuffer();
                        while (n != null) {
                            if (n.getNodeType() == Node.CDATA_SECTION_NODE
                                || n.getNodeType() == Node.TEXT_NODE)
View Full Code Here

TOP

Related Classes of org.apache.batik.dom.AbstractElement$ElementTypeInfo

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.