本文整理汇总了Java中org.w3c.dom.EntityReference类的典型用法代码示例。如果您正苦于以下问题:Java EntityReference类的具体用法?Java EntityReference怎么用?Java EntityReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityReference类属于org.w3c.dom包,在下文中一共展示了EntityReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getText
import org.w3c.dom.EntityReference; //导入依赖的package包/类
/**
* Extract the textual content from a Node.
* This is rather like the XPath value of a Node.
* @param node The node to extract the text from
* @return The textual value of the node
*/
public static String getText(Node node)
{
StringBuffer reply = new StringBuffer();
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++)
{
Node child = children.item(i);
if ((child instanceof CharacterData && !(child instanceof Comment)) || child instanceof EntityReference)
{
reply.append(child.getNodeValue());
}
else if (child.getNodeType() == Node.ELEMENT_NODE)
{
reply.append(getText(child));
}
}
return reply.toString();
}
示例2: getTextForNode
import org.w3c.dom.EntityReference; //导入依赖的package包/类
public static String getTextForNode(Node node) {
StringBuilder sb = new StringBuilder();
NodeList children = node.getChildNodes();
if (children.getLength() == 0)
return null;
for (int i = 0; i < children.getLength(); ++i) {
Node n = children.item(i);
if (n instanceof Text)
sb.append(n.getNodeValue());
else if (n instanceof EntityReference) {
String s = getTextForNode(n);
if (s == null)
return null;
else
sb.append(s);
} else
return null;
}
return sb.toString();
}
示例3: endNode
import org.w3c.dom.EntityReference; //导入依赖的package包/类
/**
* End processing of given node
*
*
* @param node Node we just finished processing
*
* @throws org.xml.sax.SAXException
*/
protected void endNode(Node node) throws org.xml.sax.SAXException {
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE :
break;
case Node.DOCUMENT_TYPE_NODE :
serializeDocType((DocumentType) node, false);
break;
case Node.ELEMENT_NODE :
serializeElement((Element) node, false);
break;
case Node.CDATA_SECTION_NODE :
break;
case Node.ENTITY_REFERENCE_NODE :
serializeEntityReference((EntityReference) node, false);
break;
default :
}
}
示例4: moveToChild
import org.w3c.dom.EntityReference; //导入依赖的package包/类
protected int moveToChild(final int currentChild) {
content = getCurrentElement().getChildNodes().item(currentChild);
if (content instanceof Text) {
return CHARACTERS;
} else if (content instanceof Element) {
return START_ELEMENT;
} else if (content instanceof CDATASection) {
return CDATA;
} else if (content instanceof Comment) {
return CHARACTERS;
} else if (content instanceof EntityReference) {
return ENTITY_REFERENCE;
}
throw new IllegalStateException();
}
示例5: startEntity
import org.w3c.dom.EntityReference; //导入依赖的package包/类
public void startEntity (String name)
throws SAXException
{
// are we ignoring what would be contents of an
// entity ref, since we can't populate it?
if (currentEntity != null)
return;
// Are we hiding all entity boundaries?
if (consumer.isHidingReferences ())
return;
// SAX2 shows parameter entities; DOM hides them
if (name.charAt (0) == '%' || "[dtd]".equals (name))
return;
// Since we can't create a populated entity ref node in any
// standard way, we create an unpopulated one.
EntityReference ref = document.createEntityReference (name);
top.appendChild (ref);
top = ref;
// ... allowing subclasses to populate them
if (!canPopulateEntityRefs ())
currentEntity = name;
}
示例6: createEntityReference
import org.w3c.dom.EntityReference; //导入依赖的package包/类
/**
* <b>DOM L1</b>
* Returns a newly created reference to the specified entity.
* The caller should populate this with the appropriate children
* and then mark it as readonly.
*
* @see DomNode#makeReadonly
*/
public EntityReference createEntityReference(String name)
{
DomEntityReference ret = new DomEntityReference(this, name);
DocumentType doctype = getDoctype();
if (doctype != null)
{
DomEntity ent = (DomEntity) doctype.getEntities().getNamedItem(name);
if (ent != null)
{
for (DomNode ctx = ent.first; ctx != null; ctx = ctx.next)
{
ret.appendChild(ctx.cloneNode(true));
}
}
}
ret.makeReadonly();
return ret;
}
示例7: startEntity
import org.w3c.dom.EntityReference; //导入依赖的package包/类
public void startEntity (String name)
throws SAXException
{
// are we ignoring what would be contents of an
// entity ref, since we can't populate it?
if (currentEntity != null)
return;
// Are we hiding all entity boundaries?
if (consumer.isHidingReferences ())
return;
// SAX2 shows parameter entities; DOM hides them
if (name.charAt (0) == '%' || "[dtd]".equals (name))
return;
// Since we can't create a populated entity ref node in any
// standard way, we create an unpopulated one.
EntityReference ref = document.createEntityReference (name);
top.appendChild (ref);
top = ref;
// ... allowing subclasses to populate them
if (!canPopulateEntityRefs ())
currentEntity = name;
}
示例8: appendNode
import org.w3c.dom.EntityReference; //导入依赖的package包/类
public static void appendNode(Node node, StringBuffer buf) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
appendElement((Element) node, buf);
break;
case Node.TEXT_NODE:
appendText((Text) node, buf);
break;
case Node.CDATA_SECTION_NODE:
appendCDATASection((CDATASection) node, buf);
break;
case Node.ENTITY_REFERENCE_NODE:
appendEntityReference((EntityReference) node, buf);
break;
}
}
示例9: visitNode
import org.w3c.dom.EntityReference; //导入依赖的package包/类
static <R> R visitNode(Node node, NodeVisitor<R> visitor) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE: return visitor.visitElement((Element) node);
case Node.ATTRIBUTE_NODE: return visitor.visitAttr((Attr) node);
case Node.TEXT_NODE: return visitor.visitText((Text) node);
case Node.CDATA_SECTION_NODE: return visitor.visitCDATASection((CDATASection) node);
case Node.ENTITY_REFERENCE_NODE: return visitor.visitEntityReference((EntityReference) node);
case Node.ENTITY_NODE: return visitor.visitEntity((Entity) node);
case Node.PROCESSING_INSTRUCTION_NODE:
return visitor.visitProcessingInstruction((ProcessingInstruction) node);
case Node.COMMENT_NODE: return visitor.visitComment((Comment) node);
case Node.DOCUMENT_NODE: return visitor.visitDocument((Document) node);
case Node.DOCUMENT_TYPE_NODE: return visitor.visitDocumentType((DocumentType) node);
case Node.DOCUMENT_FRAGMENT_NODE:
return visitor.visitDocumentFragment((DocumentFragment) node);
case Node.NOTATION_NODE: return visitor.visitNotation((Notation) node);
default: throw new RuntimeException();
}
}
示例10: endNode
import org.w3c.dom.EntityReference; //导入依赖的package包/类
/**
* End processing of given node
*
*
* @param node Node we just finished processing
*
* @throws org.xml.sax.SAXException
*/
protected void endNode(Node node) throws org.xml.sax.SAXException {
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE :
break;
case Node.DOCUMENT_TYPE_NODE :
serializeDocType((DocumentType) node, false);
break;
case Node.ELEMENT_NODE :
serializeElement((Element) node, false);
break;
case Node.CDATA_SECTION_NODE :
break;
case Node.ENTITY_REFERENCE_NODE :
serializeEntityReference((EntityReference) node, false);
break;
default :
}
}
示例11: testIsSupported4
import org.w3c.dom.EntityReference; //导入依赖的package包/类
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies that isSupported method returns false value.",
method = "isSupported",
args = {java.lang.String.class, java.lang.String.class}
)
public void testIsSupported4() throws Throwable {
Document doc;
EntityReference entRef;
boolean success;
doc = (Document) load("staffNS", builder);
entRef = doc.createEntityReference("ent1");
assertNotNull("createdEntRefNotNull", entRef);
success = entRef.isSupported("XML CORE", "");
assertFalse("nodeissupported04", success);
}
示例12: writeNode
import org.w3c.dom.EntityReference; //导入依赖的package包/类
/**
* @param xmlNode XML node
* @param xmlStreamWriter XML stream writer
* @throws XMLStreamException the XML stream exception
*/
public static void writeNode(Node xmlNode, XMLStreamWriter xmlStreamWriter)
throws XMLStreamException {
if (xmlNode instanceof Element) {
addElement((Element) xmlNode, xmlStreamWriter);
} else if (xmlNode instanceof Text) {
xmlStreamWriter.writeCharacters(xmlNode.getNodeValue());
} else if (xmlNode instanceof CDATASection) {
xmlStreamWriter.writeCData(((CDATASection) xmlNode).getData());
} else if (xmlNode instanceof Comment) {
xmlStreamWriter.writeComment(((Comment) xmlNode).getData());
} else if (xmlNode instanceof EntityReference) {
xmlStreamWriter.writeEntityRef(xmlNode.getNodeValue());
} else if (xmlNode instanceof ProcessingInstruction) {
ProcessingInstruction procInst = (ProcessingInstruction) xmlNode;
xmlStreamWriter.writeProcessingInstruction(procInst.getTarget(),
procInst.getData());
} else if (xmlNode instanceof Document) {
writeToDocument((Document) xmlNode, xmlStreamWriter);
}
}
示例13: writeNode
import org.w3c.dom.EntityReference; //导入依赖的package包/类
/**
*
* @param xmlNode
* @param xmlStreamWriter
* @throws XMLStreamException
*/
public static void writeNode(Node xmlNode, XMLStreamWriter xmlStreamWriter)
throws XMLStreamException {
if (xmlNode instanceof Element) {
addElement((Element) xmlNode, xmlStreamWriter);
} else if (xmlNode instanceof Text) {
xmlStreamWriter.writeCharacters(((Text) xmlNode).getNodeValue());
} else if (xmlNode instanceof CDATASection) {
xmlStreamWriter.writeCData(((CDATASection) xmlNode).getData());
} else if (xmlNode instanceof Comment) {
xmlStreamWriter.writeComment(((Comment) xmlNode).getData());
} else if (xmlNode instanceof EntityReference) {
xmlStreamWriter.writeEntityRef(((EntityReference) xmlNode)
.getNodeValue());
} else if (xmlNode instanceof ProcessingInstruction) {
ProcessingInstruction procInst = (ProcessingInstruction) xmlNode;
xmlStreamWriter.writeProcessingInstruction(procInst.getTarget(),
procInst.getData());
} else if (xmlNode instanceof Document) {
writeToDocument((Document) xmlNode, xmlStreamWriter);
}
}
示例14: getTextForNode
import org.w3c.dom.EntityReference; //导入依赖的package包/类
public static String getTextForNode(Node node) {
StringBuffer sb = new StringBuffer();
NodeList children = node.getChildNodes();
if (children.getLength() == 0)
return null;
for (int i = 0; i < children.getLength(); ++i) {
Node n = children.item(i);
if (n instanceof Text)
sb.append(n.getNodeValue());
else if (n instanceof EntityReference) {
String s = getTextForNode(n);
if (s == null)
return null;
else
sb.append(s);
} else
return null;
}
return sb.toString();
}
示例15: getTextValue
import org.w3c.dom.EntityReference; //导入依赖的package包/类
@Override
public String getTextValue(Element valueEle) {
if (valueEle != null) {
StringBuilder sb = new StringBuilder();
NodeList nl = valueEle.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node item = nl.item(i);
if ((item instanceof CharacterData && !(item instanceof Comment))
|| item instanceof EntityReference) {
sb.append(item.getNodeValue());
}
}
return sb.toString().trim();
}
return null;
}