Package org.apache.pivot.xml

Examples of org.apache.pivot.xml.Element


    @Override
    public void render(Object item, int index, ListView listView, boolean selected,
        boolean checked, boolean highlighted, boolean disabled) {
        if (item != null) {
            Element itemElement = (Element)item;

            String title = XMLSerializer.getText(itemElement, "title");
            titleLabel.setText(title);

            String categories = "Categories:";
            List<Element> categoryElements = itemElement.getElements("category");
            for (int i = 0, n = categoryElements.getLength(); i < n; i++) {
                Element categoryElement = categoryElements.get(i);
                TextNode categoryTextNode = (TextNode)categoryElement.get(0);
                String category = categoryTextNode.getText();

                if (i > 0) {
                    categories += ", ";
                }
View Full Code Here


            public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
                if (count == 1) {
                    index = feedListView.getItemAt(y);
                } else if (count == 2
                    && feedListView.getItemAt(y) == index) {
                    Element itemElement = (Element)feedListView.getListData().get(index);

                    String link = XMLSerializer.getText(itemElement, "link");
                    Desktop desktop = Desktop.getDesktop();

                    try {
                        desktop.browse(new URL(link).toURI());
                    } catch(MalformedURLException exception) {
                        throw new RuntimeException(exception);
                    } catch(URISyntaxException exception) {
                        throw new RuntimeException(exception);
                    } catch(IOException exception) {
                        System.out.println("Unable to open " + link + " in default browser.");
                    }
                }

                return false;
            }
        });

        GetQuery getQuery = new GetQuery("feeds.dzone.com", "/javalobby/frontpage");
        getQuery.setSerializer(new XMLSerializer());
        getQuery.getParameters().put("format", "xml");

        getQuery.execute(new TaskAdapter<Object>(new TaskListener<Object>() {
            @Override
            public void taskExecuted(Task<Object> task) {
                Element root = (Element)task.getResult();
                feedListView.setListData(XMLSerializer.getElements(root, "channel", "item"));
                cardPane.setSelectedIndex(1);
            }

            @Override
View Full Code Here

public class XMLSerializerTest {
    @Test
    public void basicTest() throws IOException, SerializationException {
        XMLSerializer xmlSerializer = new XMLSerializer();

        Element root = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));

        assertEquals(root.getName(), "root");

        Element a = XMLSerializer.getElement(root, "a");
        assertEquals(a.getName(), "a");
        assertEquals(a.get("id"), "x");

        Element b = XMLSerializer.getElement(root, "a/b");
        assertEquals(b.getName(), "b");
        assertEquals(b.get("id"), "y");

        b = XMLSerializer.getElement(a, "b");
        assertEquals(b.getName(), "b");
        assertEquals(b.get("id"), "y");

        List<Element> cs = XMLSerializer.getElements(root, "a/b", "c");
        assertEquals(cs.getLength(), 1);

        List<Element> fs = XMLSerializer.getElements(root, "d/e", "f");
        assertEquals(fs.getLength(), 4);

        Element e = XMLSerializer.getElement(root, "d/e");
        Element f = XMLSerializer.getElement(e, "f");
        assertEquals(f.getName(), "f");

        Element g = XMLSerializer.getElement(e, "g");
        assertEquals(g.getName(), "g");

        String ft = XMLSerializer.getText(root, "d/e/f");
        assertEquals(ft, "1");

        String gt = XMLSerializer.getText(root, "d/e/g");
View Full Code Here

        boolean expanded, boolean selected, TreeView.NodeCheckState checkState,
        boolean highlighted, boolean disabled) {
        if (node != null) {
            String text;
            if (node instanceof Element) {
                Element element = (Element)node;
                text = "<" + element.getName() + ">";
            } else if (node instanceof TextNode) {
                TextNode textNode = (TextNode)node;
                text = textNode.getText();

                if (text.length() > MAXIMUM_TEXT_LENGTH) {
View Full Code Here

public class XMLSerializerTest {
    @Test
    public void basicTest() throws IOException, SerializationException {
        XMLSerializer xmlSerializer = new XMLSerializer();

        Element root = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));

        assertEquals(root.getName(), "root");

        Element a = XML.getElement(root, "a");
        assertEquals(a.getName(), "a");
        assertEquals(a.getElementDictionary().get("id"), "x");

        Element b = XML.getElement(root, "a/b");
        assertEquals(b.getName(), "b");
        assertEquals(b.getElementDictionary().get("id"), "y");

        b = XML.getElement(a, "b");
        assertEquals(b.getName(), "b");
        assertEquals(b.getElementDictionary().get("id"), "y");

        List<Element> cs = XML.getElements(root, "a/b", "c");
        assertEquals(cs.getLength(), 1);

        List<Element> fs = XML.getElements(root, "d/e", "f");
        assertEquals(fs.getLength(), 4);

        Element e = XML.getElement(root, "d/e");
        Element f = XML.getElement(e, "f");
        assertEquals(f.getName(), "f");

        Element g = XML.getElement(e, "g");
        assertEquals(g.getName(), "g");

        String ft = XML.getText(root, "d/e/f");
        assertEquals(ft, "1");

        String gt = XML.getText(root, "d/e/g");
View Full Code Here

                System.out.println("Read text node: " + textNode);
            }
        };

        xmlSerializer.getXMLSerializerListeners().add(xmlSerializerListener);
        Element root1 = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));
        assertNotNull(root1);

        xmlSerializer.getXMLSerializerListeners().remove(xmlSerializerListener);
        Element root2 = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));
        assertNotNull(root2);
    }
View Full Code Here

        } else if (node instanceof TextNode) {
            TextNode textNode = (TextNode)node;
            textArea.setText(textNode.getText());
            propertiesCardPane.setSelectedIndex(1);
        } else if (node instanceof Element) {
            Element element = (Element)node;

            // Populate the namespaces table
            ArrayList<HashMap<String, String>> namespacesTableData =
                new ArrayList<HashMap<String, String>>();

            String defaultNamespaceURI = element.getDefaultNamespaceURI();
            if (defaultNamespaceURI != null) {
                HashMap<String, String> row = new HashMap<String, String>();
                row.put("prefix", "(default)");
                row.put("uri", defaultNamespaceURI);
                namespacesTableData.add(row);
            }

            Element.NamespaceDictionary namespaceDictionary = element.getNamespaces();
            for (String prefix : namespaceDictionary) {
                HashMap<String, String> row = new HashMap<String, String>();
                row.put("prefix", prefix);
                row.put("uri", namespaceDictionary.get(prefix));
                namespacesTableData.add(row);
            }

            namespacesTableView.setTableData(namespacesTableData);

            // Populate the attributes table
            ArrayList<HashMap<String, String>> attributesTableData =
                new ArrayList<HashMap<String, String>>();

            for (Element.Attribute attribute : element.getAttributes()) {
                HashMap<String, String> row = new HashMap<String, String>();

                String attributeName = attribute.getName();
                row.put("name", attributeName);
                row.put("value", element.getElementDictionary().get(attributeName));
                attributesTableData.add(row);
            }

            attributesTableView.setTableData(attributesTableData);
View Full Code Here

        boolean expanded, boolean selected, TreeView.NodeCheckState checkState,
        boolean highlighted, boolean disabled) {
        if (node != null) {
            String text;
            if (node instanceof Element) {
                Element element = (Element)node;
                text = "<" + element.getName() + ">";
            } else if (node instanceof TextNode) {
                TextNode textNode = (TextNode)node;
                text = textNode.getText();

                if (text.length() > MAXIMUM_TEXT_LENGTH) {
View Full Code Here

    @Override
    public String toString(Object node) {
        String string;
        if (node instanceof Element) {
            Element element = (Element)node;
            string = element.getName();
        } else if (node instanceof TextNode) {
            TextNode textNode = (TextNode)node;
            string = textNode.getText();
        } else {
            throw new IllegalArgumentException();
View Full Code Here

public class XMLSerializerTest {
    @Test
    public void basicTest() throws IOException, SerializationException {
        XMLSerializer xmlSerializer = new XMLSerializer();

        Element root = xmlSerializer.readObject(getClass().getResourceAsStream("sample.xml"));

        assertEquals(root.getName(), "root");

        Element a = XML.getElement(root, "a");
        assertEquals(a.getName(), "a");
        assertEquals(a.get("id"), "x");

        Element b = XML.getElement(root, "a/b");
        assertEquals(b.getName(), "b");
        assertEquals(b.get("id"), "y");

        b = XML.getElement(a, "b");
        assertEquals(b.getName(), "b");
        assertEquals(b.get("id"), "y");

        List<Element> cs = XML.getElements(root, "a/b", "c");
        assertEquals(cs.getLength(), 1);

        List<Element> fs = XML.getElements(root, "d/e", "f");
        assertEquals(fs.getLength(), 4);

        Element e = XML.getElement(root, "d/e");
        Element f = XML.getElement(e, "f");
        assertEquals(f.getName(), "f");

        Element g = XML.getElement(e, "g");
        assertEquals(g.getName(), "g");

        String ft = XML.getText(root, "d/e/f");
        assertEquals(ft, "1");

        String gt = XML.getText(root, "d/e/g");
View Full Code Here

TOP

Related Classes of org.apache.pivot.xml.Element

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.