use of org.w3c.dom.EntityReference in project robovm by robovm.
the class ElementSetAttributeNodeNS method _testSetAttributeNodeNS6.
public void _testSetAttributeNodeNS6() throws Throwable {
Document doc;
Element element;
Attr attribute;
Attr attribute2;
EntityReference entRef;
NodeList elementList;
doc = (Document) load("staffNS", builder);
element = doc.createElementNS("http://www.w3.org/DOM/Test", "elem1");
attribute = doc.createAttributeNS("http://www.w3.org/DOM/Test", "attr");
entRef = doc.createEntityReference("ent4");
attribute.appendChild(entRef);
element.setAttributeNodeNS(attribute);
elementList = entRef.getChildNodes();
element = (Element) elementList.item(0);
attribute2 = doc.createAttributeNS("http://www.w3.org/DOM/Test", "attr2");
{
boolean success = false;
try {
element.setAttributeNodeNS(attribute2);
} catch (DOMException ex) {
success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
}
assertTrue("elementsetattributenodens06", success);
}
}
use of org.w3c.dom.EntityReference in project robovm by robovm.
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 karaf by apache.
the class NamespaceHandler 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 webtools.sourceediting by eclipse.
the class TaglibHyperlinkDetector method getContainedText.
private static String getContainedText(Node parent) {
NodeList children = parent.getChildNodes();
if (children.getLength() == 1) {
return children.item(0).getNodeValue().trim();
}
StringBuffer s = new StringBuffer();
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
String reference = ((EntityReference) child).getNodeValue();
if (reference == null && child.getNodeName() != null) {
// $NON-NLS-1$ //$NON-NLS-2$
reference = "&" + child.getNodeName() + ";";
}
if (reference != null) {
s.append(reference.trim());
}
} else {
s.append(child.getNodeValue().trim());
}
child = child.getNextSibling();
}
return s.toString().trim();
}
use of org.w3c.dom.EntityReference in project webtools.sourceediting by eclipse.
the class DeploymentDescriptorPropertyCache method getContainedText.
static String getContainedText(Node parent) {
NodeList children = parent.getChildNodes();
if (children.getLength() == 1) {
return children.item(0).getNodeValue().trim();
}
StringBuffer s = new StringBuffer();
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
String reference = ((EntityReference) child).getNodeValue();
if (reference == null && child.getNodeName() != null) {
// $NON-NLS-1$ //$NON-NLS-2$
reference = "&" + child.getNodeName() + ";";
}
if (reference != null) {
s.append(reference.trim());
}
} else {
s.append(child.getNodeValue().trim());
}
child = child.getNextSibling();
}
return s.toString().trim();
}
Aggregations