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 }));
}
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();
}
Aggregations