Search in sources :

Example 1 with EntityRef

use of org.jdom.EntityRef in project freemarker by apache.

the class NodeListModel method getType.

private TemplateModel getType() {
    if (nodes.size() == 0)
        return new SimpleScalar("");
    Object firstNode = nodes.get(0);
    char code;
    if (firstNode instanceof Element)
        code = 'e';
    else if (firstNode instanceof Text || firstNode instanceof String)
        code = 'x';
    else if (firstNode instanceof Attribute)
        code = 'a';
    else if (firstNode instanceof EntityRef)
        code = 'n';
    else if (firstNode instanceof Document)
        code = 'd';
    else if (firstNode instanceof DocType)
        code = 't';
    else if (firstNode instanceof Comment)
        code = 'c';
    else if (firstNode instanceof ProcessingInstruction)
        code = 'p';
    else
        code = '?';
    return new SimpleScalar(new String(new char[] { code }));
}
Also used : Comment(org.jdom.Comment) Attribute(org.jdom.Attribute) Element(org.jdom.Element) Text(org.jdom.Text) Document(org.jdom.Document) SimpleScalar(freemarker.template.SimpleScalar) EntityRef(org.jdom.EntityRef) DocType(org.jdom.DocType) ProcessingInstruction(org.jdom.ProcessingInstruction)

Example 2 with EntityRef

use of org.jdom.EntityRef in project cxf by apache.

the class StaxSerializer method writeElement.

public void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException {
    // need to check if the namespace is declared before we write the
    // start element because that will put the namespace in the context.
    String elPrefix = e.getNamespacePrefix();
    String elUri = e.getNamespaceURI();
    String boundPrefix = writer.getPrefix(elUri);
    boolean writeElementNS = false;
    if (boundPrefix == null || !elPrefix.equals(boundPrefix)) {
        writeElementNS = true;
    }
    writer.writeStartElement(elPrefix, e.getName(), elUri);
    List<?> namespaces = e.getAdditionalNamespaces();
    for (Iterator<?> itr = namespaces.iterator(); itr.hasNext(); ) {
        Namespace ns = (Namespace) itr.next();
        String prefix = ns.getPrefix();
        String uri = ns.getURI();
        writer.setPrefix(prefix, uri);
        writer.writeNamespace(prefix, uri);
        if (elUri.equals(uri) && elPrefix.equals(prefix)) {
            writeElementNS = false;
        }
    }
    for (Iterator<?> itr = e.getAttributes().iterator(); itr.hasNext(); ) {
        Attribute attr = (Attribute) itr.next();
        String attPrefix = attr.getNamespacePrefix();
        String attUri = attr.getNamespaceURI();
        if (attUri == null || attUri.isEmpty()) {
            writer.writeAttribute(attr.getName(), attr.getValue());
        } else {
            writer.writeAttribute(attPrefix, attUri, attr.getName(), attr.getValue());
            if (!isDeclared(writer, attPrefix, attUri)) {
                if (elUri.equals(attUri) && elPrefix.equals(attPrefix)) {
                    if (writeElementNS) {
                        writer.setPrefix(attPrefix, attUri);
                        writer.writeNamespace(attPrefix, attUri);
                        writeElementNS = false;
                    }
                } else {
                    writer.setPrefix(attPrefix, attUri);
                    writer.writeNamespace(attPrefix, attUri);
                }
            }
        }
    }
    if (writeElementNS) {
        if (elPrefix == null || elPrefix.length() == 0) {
            writer.writeDefaultNamespace(elUri);
        } else {
            writer.writeNamespace(elPrefix, elUri);
        }
    }
    for (Iterator<?> itr = e.getContent().iterator(); itr.hasNext(); ) {
        Content n = (Content) itr.next();
        if (n instanceof CDATA) {
            writer.writeCData(n.getValue());
        } else if (n instanceof Text) {
            writer.writeCharacters(((Text) n).getText());
        } else if (n instanceof Element) {
            writeElement((Element) n, writer);
        } else if (n instanceof Comment) {
            writer.writeComment(n.getValue());
        } else if (n instanceof EntityRef) {
        // EntityRef ref = (EntityRef) n;
        // writer.writeEntityRef(ref.)
        }
    }
    writer.writeEndElement();
}
Also used : Comment(org.jdom.Comment) Attribute(org.jdom.Attribute) Content(org.jdom.Content) Element(org.jdom.Element) Text(org.jdom.Text) CDATA(org.jdom.CDATA) EntityRef(org.jdom.EntityRef) Namespace(org.jdom.Namespace)

Aggregations

Attribute (org.jdom.Attribute)2 Comment (org.jdom.Comment)2 Element (org.jdom.Element)2 EntityRef (org.jdom.EntityRef)2 Text (org.jdom.Text)2 SimpleScalar (freemarker.template.SimpleScalar)1 CDATA (org.jdom.CDATA)1 Content (org.jdom.Content)1 DocType (org.jdom.DocType)1 Document (org.jdom.Document)1 Namespace (org.jdom.Namespace)1 ProcessingInstruction (org.jdom.ProcessingInstruction)1