use of org.w3c.dom.EntityReference in project j2objc by google.
the class TreeWalker method startNode.
/**
* Start processing given node
*
* @param node Node to process
*
* @throws org.xml.sax.SAXException
*/
protected void startNode(Node node) throws org.xml.sax.SAXException {
if (node instanceof Locator) {
Locator loc = (Locator) node;
m_locator.setColumnNumber(loc.getColumnNumber());
m_locator.setLineNumber(loc.getLineNumber());
m_locator.setPublicId(loc.getPublicId());
m_locator.setSystemId(loc.getSystemId());
} else {
m_locator.setColumnNumber(0);
m_locator.setLineNumber(0);
}
switch(node.getNodeType()) {
case Node.COMMENT_NODE:
{
String data = ((Comment) node).getData();
if (m_contentHandler instanceof LexicalHandler) {
LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);
lh.comment(data.toCharArray(), 0, data.length());
}
}
break;
case Node.DOCUMENT_FRAGMENT_NODE:
// ??;
break;
case Node.DOCUMENT_NODE:
break;
case Node.ELEMENT_NODE:
Element elem_node = (Element) node;
{
// Make sure the namespace node
// for the element itself is declared
// to the ContentHandler
String uri = elem_node.getNamespaceURI();
if (uri != null) {
String prefix = elem_node.getPrefix();
if (prefix == null)
prefix = "";
this.m_contentHandler.startPrefixMapping(prefix, uri);
}
}
NamedNodeMap atts = elem_node.getAttributes();
int nAttrs = atts.getLength();
// each attribute is declared to the ContentHandler
for (int i = 0; i < nAttrs; i++) {
final Node attr = atts.item(i);
final String attrName = attr.getNodeName();
final int colon = attrName.indexOf(':');
final String prefix;
// System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue());
if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) {
// to "Steven Murray" <smurray@ebt.com>.
if (colon < 0)
prefix = "";
else
prefix = attrName.substring(colon + 1);
this.m_contentHandler.startPrefixMapping(prefix, attr.getNodeValue());
} else if (colon > 0) {
prefix = attrName.substring(0, colon);
String uri = attr.getNamespaceURI();
if (uri != null)
this.m_contentHandler.startPrefixMapping(prefix, uri);
}
}
String ns = m_dh.getNamespaceOfNode(node);
if (null == ns)
ns = "";
this.m_contentHandler.startElement(ns, m_dh.getLocalNameOfNode(node), node.getNodeName(), new AttList(atts, m_dh));
break;
case Node.PROCESSING_INSTRUCTION_NODE:
{
ProcessingInstruction pi = (ProcessingInstruction) node;
String name = pi.getNodeName();
// String data = pi.getData();
if (name.equals("xslt-next-is-raw")) {
nextIsRaw = true;
} else {
this.m_contentHandler.processingInstruction(pi.getNodeName(), pi.getData());
}
}
break;
case Node.CDATA_SECTION_NODE:
{
boolean isLexH = (m_contentHandler instanceof LexicalHandler);
LexicalHandler lh = isLexH ? ((LexicalHandler) this.m_contentHandler) : null;
if (isLexH) {
lh.startCDATA();
}
dispatachChars(node);
{
if (isLexH) {
lh.endCDATA();
}
}
}
break;
case Node.TEXT_NODE:
{
if (nextIsRaw) {
nextIsRaw = false;
m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
dispatachChars(node);
m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
} else {
dispatachChars(node);
}
}
break;
case Node.ENTITY_REFERENCE_NODE:
{
EntityReference eref = (EntityReference) node;
if (m_contentHandler instanceof LexicalHandler) {
((LexicalHandler) this.m_contentHandler).startEntity(eref.getNodeName());
} else {
// warning("Can not output entity to a pure SAX ContentHandler");
}
}
break;
default:
}
}
use of org.w3c.dom.EntityReference in project aries by apache.
the class SpringOsgiNamespaceHandler method getTextValue.
public static String getTextValue(Element valueEle) {
Assert.notNull(valueEle, "Element must not be null");
StringBuilder sb = new StringBuilder();
NodeList nl = valueEle.getChildNodes();
for (int i = 0, l = nl.getLength(); i < l; ++i) {
Node item = nl.item(i);
if (item instanceof CharacterData && !(item instanceof Comment) || item instanceof EntityReference) {
sb.append(item.getNodeValue());
}
}
return sb.toString();
}
use of org.w3c.dom.EntityReference in project aries by apache.
the class CmNamespaceHandler method getTextValue.
private static String getTextValue(Element element) {
StringBuffer value = new StringBuffer();
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node item = nl.item(i);
if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
value.append(item.getNodeValue());
}
}
return value.toString();
}
use of org.w3c.dom.EntityReference in project knime-core by knime.
the class XMLXpathCellReader method readXML.
/**
* {@inheritDoc}
*/
@Override
public XMLValue<Document> readXML() throws IOException {
if (!m_xpathMatcher.nodeMatches()) {
return null;
}
try {
while (m_parser.hasNext()) {
switch(m_parser.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
updateBasePath();
updateXmlSpaceDefinition();
updateXmlLangDefinition();
pushNamespaceContext();
for (int i = 0; i < m_docs.size(); i++) {
Element element = createElement(m_docs.get(i));
m_currNodes.get(i).appendChild(element);
m_currNodes.set(i, element);
}
boolean match = m_xpathMatcher.startElement(m_parser.getName());
if (match) {
Document doc = m_builder.newDocument();
Element element = createElement(doc);
m_namespaceStack.stream().flatMap(e -> e.stream()).forEach(p -> element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, p.getFirst(), p.getSecond()));
// (see: http://www.w3.org/XML/1998/namespace)
if (!m_base.isEmpty() && null != m_base.get(0)) {
element.setAttributeNS(XMLConstants.XML_NS_URI, "xml:base", m_base.get(0));
}
if (!m_space.isEmpty() && null != m_space.get(0)) {
element.setAttributeNS(XMLConstants.XML_NS_URI, "xml:space", m_space.get(0));
}
if (!m_lang.isEmpty() && null != m_lang.get(0)) {
element.setAttributeNS(XMLConstants.XML_NS_URI, "xml:lang", m_lang.get(0));
}
doc.appendChild(element);
m_docs.add(doc);
m_currNodes.add(element);
}
break;
case XMLStreamConstants.END_ELEMENT:
if (!m_reentrent) {
m_xpathMatcher.endElement();
if (!m_base.isEmpty()) {
m_base.remove(0);
}
if (!m_space.isEmpty()) {
m_space.remove(0);
}
if (!m_lang.isEmpty()) {
m_lang.remove(0);
}
}
for (int i = m_docs.size() - 1; i >= 0; i--) {
Node curr = m_currNodes.get(i);
Node first = m_docs.get(i).getFirstChild();
if (curr.isSameNode(first)) {
XMLValue<Document> cell = null;
cell = createDataCell(m_docs.get(i));
m_docs.remove(i);
m_currNodes.remove(i);
m_reentrent = true;
return cell;
} else {
m_currNodes.set(i, curr.getParentNode());
}
}
popNamespaceContext();
m_reentrent = false;
break;
case XMLStreamConstants.CHARACTERS:
if (!m_parser.isWhiteSpace() || (m_parser.isWhiteSpace() && !m_space.isEmpty() && null != m_space.get(0) && m_space.get(0).equals("preserve"))) {
for (int i = 0; i < m_docs.size(); i++) {
String str = m_parser.getText();
Text text = m_docs.get(i).createTextNode(str);
m_currNodes.get(i).appendChild(text);
}
}
break;
case XMLStreamConstants.SPACE:
if (!m_space.isEmpty() && null != m_space.get(0) && m_space.get(0).equals("preserve")) {
for (int i = 0; i < m_docs.size(); i++) {
String str = m_parser.getText();
Text text = m_docs.get(i).createTextNode(str);
m_currNodes.get(i).appendChild(text);
}
}
break;
case XMLStreamConstants.COMMENT:
for (int i = 0; i < m_docs.size(); i++) {
String str = m_parser.getText();
Comment comment = m_docs.get(i).createComment(str);
m_currNodes.get(i).appendChild(comment);
}
break;
case XMLStreamConstants.ENTITY_REFERENCE:
for (int i = 0; i < m_docs.size(); i++) {
String str = m_parser.getText();
EntityReference ref = m_docs.get(i).createEntityReference(str);
m_currNodes.get(i).appendChild(ref);
}
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
for (int i = 0; i < m_docs.size(); i++) {
String piTarget = m_parser.getPITarget();
String piName = m_parser.getPIData();
ProcessingInstruction pi = m_docs.get(i).createProcessingInstruction(piTarget, piName);
m_currNodes.get(i).appendChild(pi);
}
break;
case XMLStreamConstants.DTD:
// not needed use DOM-Reader for full documents
break;
case XMLStreamConstants.END_DOCUMENT:
// never called
m_parser.close();
default:
break;
}
m_parser.next();
}
return null;
} catch (XMLStreamException e) {
throw new IOException(e);
}
}
use of org.w3c.dom.EntityReference in project robovm by robovm.
the class DomTest method testEntityReferenceSetTextContent.
/**
* Tests setTextContent on entity references. Although the other tests can
* act on a parsed DOM, this needs to use a programmatically constructed DOM
* because the parser may have replaced the entity reference with the
* corresponding text.
*/
public void testEntityReferenceSetTextContent() throws TransformerException {
document = builder.newDocument();
Element root = document.createElement("menu");
document.appendChild(root);
EntityReference entityReference = document.createEntityReference("sp");
root.appendChild(entityReference);
try {
entityReference.setTextContent("Lite Syrup");
fail();
} catch (DOMException e) {
}
}
Aggregations