Examples of AbstractElement


Examples of javax.swing.text.AbstractDocument.AbstractElement

     * Checks that logical style is ResolveAttribute of paragraph.
     */
    public void testGetLogicalStyle02() {
        final StyleContext context = new StyleContext();
        final Style style = context.addStyle("aStyle", null);
        final AbstractElement par = (AbstractElement) doc.getParagraphElement(5);
        doc.writeLock();
        try {
            par.addAttribute(AttributeSet.ResolveAttribute, style);
            assertSame(style, doc.getLogicalStyle(5));
        } finally {
            doc.writeUnlock();
        }
    }
View Full Code Here

Examples of javax.swing.text.AbstractDocument.AbstractElement

    /**
     * Checks what happens when ResolveAttribute of a paragraph is set
     * to non-Style object.
     */
    public void testGetLogicalStyle03() {
        final AbstractElement par = (AbstractElement) doc.getParagraphElement(5);
        final MutableAttributeSet set = new SimpleAttributeSet();
        StyleConstants.setForeground(set, Color.GREEN);
        StyleConstants.setBackground(set, Color.YELLOW);
        doc.writeLock();
        try {
            set.setResolveParent(boldItalic);
            par.setResolveParent(set);
            assertSame(set, par.getResolveParent());
            assertNull(doc.getLogicalStyle(5));
        } finally {
            doc.writeUnlock();
        }
    }
View Full Code Here

Examples of javax.swing.text.AbstractDocument.AbstractElement

        doc.unlockWrite();
    }

    public void testTranslateHTMLToCSSBody() throws Exception {
        AbstractElement body =
            (AbstractElement)doc.getDefaultRootElement().getElement(0);
        assertEquals("body", body.getName());
        assertTrue(body instanceof BlockElement);

        body.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
        body.addAttribute(HTML.Attribute.BACKGROUND, "bg.jpg");
        body.addAttribute(HTML.Attribute.TEXT, "black");
        body.addAttribute(HTML.Attribute.LINK, "blue");
        body.addAttribute(HTML.Attribute.ALINK, "red");
        body.addAttribute(HTML.Attribute.VLINK, "purple");
        attr = ss.translateHTMLToCSS(body);
        assertSame(NamedStyle.class, attr.getClass());
        assertNull(((NamedStyle)attr).getName());
        assertEquals(3, attr.getAttributeCount());
        assertEquals(isHarmony() ? "url(bg.jpg)" : "bg.jpg",
View Full Code Here

Examples of javax.swing.text.AbstractDocument.AbstractElement

        assertEquals("black",
                     attr.getAttribute(CSS.Attribute.COLOR).toString());
    }

    public void testTranslateHTMLToCSSP() throws Exception {
        AbstractElement p =
            (AbstractElement)doc.getDefaultRootElement()
                             .getElement(0).getElement(0);
        assertEquals("p", p.getName());
        assertTrue(p instanceof BlockElement);

        p.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
        p.addAttribute(HTML.Attribute.BACKGROUND, "bg.jpg");
        p.addAttribute(HTML.Attribute.TEXT, "black");
        p.addAttribute(HTML.Attribute.LINK, "blue");
        p.addAttribute(HTML.Attribute.ALINK, "red");
        p.addAttribute(HTML.Attribute.VLINK, "purple");

        attr = ss.translateHTMLToCSS(p);
        assertSame(NamedStyle.class, attr.getClass());
        assertNull(((NamedStyle)attr).getName());
View Full Code Here

Examples of javax.swing.text.AbstractDocument.AbstractElement

        assertEquals("0",
                     attr.getAttribute(CSS.Attribute.MARGIN_TOP).toString());
    }

    public void testTranslateHTMLToCSSPContent() throws Exception {
        AbstractElement content =
            (AbstractElement)doc.getDefaultRootElement()
                             .getElement(0).getElement(0).getElement(0);
        assertEquals("content", content.getName());
        assertTrue(content instanceof RunElement);

        content.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
        content.addAttribute(HTML.Attribute.BACKGROUND, "bg.jpg");
        content.addAttribute(HTML.Attribute.TEXT, "black");
        content.addAttribute(HTML.Attribute.LINK, "blue");
        content.addAttribute(HTML.Attribute.ALINK, "red");
        content.addAttribute(HTML.Attribute.VLINK, "purple");

        attr = ss.translateHTMLToCSS(content);
        assertSame(NamedStyle.class, attr.getClass());
        assertNull(((NamedStyle)attr).getName());
        if (isHarmony()) {
View Full Code Here

Examples of javax.swing.text.AbstractDocument.AbstractElement

        MutableAttributeSet mas = new SimpleAttributeSet();
        mas.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
        mas.addAttribute(HTML.Attribute.TEXT, "black");
        doc.setParagraphAttributes(0, 1, mas, false);

        AbstractElement branch =
            (AbstractElement)doc.getDefaultRootElement().getElement(0);
        assertEquals("paragraph", branch.getName());
        assertTrue(branch instanceof BranchElement);
        assertSame(BranchElement.class, branch.getClass());


        attr = ss.translateHTMLToCSS(branch);
        assertSame(NamedStyle.class, attr.getClass());
        assertNull(((NamedStyle)attr).getName());
View Full Code Here

Examples of org.apache.batik.dom.AbstractElement

        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

Examples of org.apache.batik.dom.AbstractElement

        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

Examples of org.apache.batik.dom.AbstractElement

        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

Examples of org.apache.flex.forks.batik.dom.AbstractElement

        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
Copyright © 2018 www.massapi.com. 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.