Example usage for org.dom4j ProcessingInstruction getTarget

List of usage examples for org.dom4j ProcessingInstruction getTarget

Introduction

In this page you can find the example usage for org.dom4j ProcessingInstruction getTarget.

Prototype

String getTarget();

Source Link

Document

This method is the equivalent to the #getName method.

Usage

From source file:com.cladonia.xml.viewer.Viewer.java

License:Open Source License

private void update() {
    if (tree != null && document != null) {
        if (showPI()) {
            XElement dummyElement = new XElement(XNGR_DUMMY_ROOT);
            DefaultDocument doc = (DefaultDocument) document.getDocument();
            List pis = doc.processingInstructions();

            Vector allPIs = new Vector();
            ;// w  w  w  .j a v a  2 s  .  co  m
            for (int i = 0; i < pis.size(); i++) {
                ProcessingInstruction pi = (ProcessingInstruction) pis.get(i);
                if (!addedPI(allPIs, pi.getTarget() + pi.getText())) {
                    dummyElement.addProcessingInstruction(pi.getTarget(), pi.getText());
                    allPIs.add(pi.getTarget() + pi.getText());
                }
            }

            XmlElementNode dummyRoot = new XmlElementNode(this, dummyElement);
            XmlElementNode node = new XmlElementNode(this, (XElement) document.getRoot());
            dummyRoot.add(node);
            tree.setRoot(dummyRoot);
            tree.expand(4);

            tree.setRootVisible(false);
        } else {
            XmlElementNode node = new XmlElementNode(this, (XElement) document.getRoot());
            tree.setRoot(node);
            tree.expand(3);

            tree.setRootVisible(true);
        }
    }
}

From source file:com.cladonia.xml.viewer.Viewer.java

License:Open Source License

public void setDocument(ExchangerDocument document) {
    if (DEBUG)//  w  w  w .j a v  a  2  s .c o  m
        System.out.println("Viewer.setDocument( " + document + ")");

    if (this.document != null) {
        this.document.removeListener(this);
    }

    this.document = document;

    if (document != null) {
        document.addListener(this);
    }

    if (document != null && !document.isError()) {

        if (showPI()) {
            XElement dummyElement = new XElement(XNGR_DUMMY_ROOT);
            DefaultDocument doc = (DefaultDocument) document.getDocument();
            List pis = doc.processingInstructions();
            for (int i = 0; i < pis.size(); i++) {
                ProcessingInstruction pi = (ProcessingInstruction) pis.get(i);
                dummyElement.addProcessingInstruction(pi.getTarget(), pi.getText());
            }

            XmlElementNode dummyRoot = new XmlElementNode(this, dummyElement);
            XmlElementNode node = new XmlElementNode(this, (XElement) document.getRoot());
            dummyRoot.add(node);
            tree.setRoot(dummyRoot);
            tree.expand(4);

            tree.setRootVisible(false);
        } else {
            XmlElementNode node = new XmlElementNode(this, (XElement) document.getRoot());
            tree.setRoot(node);
            tree.expand(3);

            tree.setRootVisible(true);
        }

    } else {
        tree.setRoot(null);
    }

    hasLatest = true;
}

From source file:com.cladonia.xml.viewer.XmlElementNode.java

License:Mozilla Public License

protected Line parseProcessingInstructionContent(Vector lines, Line current, ProcessingInstruction pi) {
    String target = pi.getTarget();

    if ((current.length() + 1 >= MAX_LINE_LENGTH) && (target.length() > 0)) {
        current = new Line();
        lines.add(current);//  w  w w  . j a  v a  2  s .co m
        current.addStyledString(TAB);
    }

    if (target.length() > 0) {
        // get the PI Target
        current.addStyledString(new PI_Target(target));
    }

    String text = pi.getText();
    if (text.length() > 0) {
        // get the PI text
        current.addStyledString(SPACE);
        current.addStyledString(new PI_Text(text));
    }

    return current;
}

From source file:freemarker.ext.xml._Dom4jNavigator.java

License:Apache License

void getAttributes(Object node, String localName, String namespaceUri, List result) {
    if (node instanceof Element) {
        Element e = (Element) node;
        if (localName == null) {
            result.addAll(e.attributes());
        } else {//from  ww w . java 2s .  c  o m
            Attribute attr = e
                    .attribute(e.getQName().getDocumentFactory().createQName(localName, "", namespaceUri));
            if (attr != null) {
                result.add(attr);
            }
        }
    } else if (node instanceof ProcessingInstruction) {
        ProcessingInstruction pi = (ProcessingInstruction) node;
        if ("target".equals(localName)) {
            result.add(new DefaultAttribute("target", pi.getTarget()));
        } else if ("data".equals(localName)) {
            result.add(new DefaultAttribute("data", pi.getText()));
        } else {
            result.add(new DefaultAttribute(localName, pi.getValue(localName)));
        }
    } else if (node instanceof DocumentType) {
        DocumentType doctype = (DocumentType) node;
        if ("publicId".equals(localName)) {
            result.add(new DefaultAttribute("publicId", doctype.getPublicID()));
        } else if ("systemId".equals(localName)) {
            result.add(new DefaultAttribute("systemId", doctype.getSystemID()));
        } else if ("elementName".equals(localName)) {
            result.add(new DefaultAttribute("elementName", doctype.getElementName()));
        }
    }
}

From source file:org.hudsonci.xpath.impl.Dom2Dom.java

License:Open Source License

private org.w3c.dom.Node createChild(Node child, org.w3c.dom.Node wparent) {
    int type = child.getNodeType();

    // Collapse multiple consecutive text nodes to a single text node
    // with trimmed value.
    if (type != Node.TEXT_NODE)
        endText(wparent);/*w ww. j  a  v  a  2s . c o  m*/

    Name name;
    org.w3c.dom.Node node = null;

    switch (type) {
    case Node.ATTRIBUTE_NODE:
        break;
    case Node.CDATA_SECTION_NODE:
        CDATA cd = (CDATA) child;
        wparent.appendChild(node = wdoc.createCDATASection(cd.getText()));
        break;
    case Node.COMMENT_NODE:
        Comment co = (Comment) child;
        wparent.appendChild(node = wdoc.createComment(co.getText()));
        break;
    case Node.DOCUMENT_TYPE_NODE:
        DocumentType dt = (DocumentType) child;
        wparent.appendChild(new XDocumentType(dt, wparent));
        break;
    case Node.ELEMENT_NODE:
        Element el = (Element) child;
        name = new Name(el);
        org.w3c.dom.Element e = name.namespaceURI == null ? wdoc.createElement(name.qualifiedName)
                : wdoc.createElementNS(name.namespaceURI, name.qualifiedName);
        wparent.appendChild(e);
        node = currentElement = e;

        for (int i = 0, n = el.attributeCount(); i < n; i++) {
            Attribute at = el.attribute(i);
            name = new Name(at);
            if (name.namespaceURI == null)
                e.setAttribute(name.qualifiedName, at.getValue());
            else
                e.setAttributeNS(name.namespaceURI, name.qualifiedName, at.getValue());
        }
        return e;
    case Node.ENTITY_REFERENCE_NODE:
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        ProcessingInstruction p = (ProcessingInstruction) child;
        wparent.appendChild(node = wdoc.createProcessingInstruction(p.getTarget(), p.getText()));
        break;
    case Node.TEXT_NODE:
        textBuilder.append(child.getText());
        lastText = (Text) child;
        break;
    case Node.NAMESPACE_NODE:
        Namespace ns = (Namespace) child;
        name = new Name(ns);
        currentElement.setAttribute(name.qualifiedName, ns.getURI());
        break;
    default:
        throw new IllegalStateException("Unknown node type");
    }
    if (node != null)
        reverseMap.put(node, child);
    return null;
}