本文整理汇总了Java中org.w3c.dom.Text类的典型用法代码示例。如果您正苦于以下问题:Java Text类的具体用法?Java Text怎么用?Java Text使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Text类属于org.w3c.dom包,在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextElement
import org.w3c.dom.Text; //导入依赖的package包/类
public static Element nextElement(Iterator iter) {
while (iter.hasNext()) {
Node n = (Node) iter.next();
if (n instanceof Text) {
Text t = (Text) n;
if (t.getData().trim().length() == 0)
continue;
fail("parsing.nonWhitespaceTextFound", t.getData().trim());
}
if (n instanceof Comment)
continue;
if (!(n instanceof Element))
fail("parsing.elementExpected");
return (Element) n;
}
return null;
}
示例2: findSubElements
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Find all direct child elements of an element.
* More useful than {@link Element#getElementsByTagNameNS} because it does
* not recurse into recursive child elements.
* Children which are all-whitespace text nodes or comments are ignored; others cause
* an exception to be thrown.
* @param parent a parent element in a DOM tree
* @return a list of direct child elements (may be empty)
* @throws IllegalArgumentException if there are non-element children besides whitespace
*/
static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
NodeList l = parent.getChildNodes();
List<Element> elements = new ArrayList<>(l.getLength());
for (int i = 0; i < l.getLength(); i++) {
Node n = l.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
elements.add((Element)n);
} else if (n.getNodeType() == Node.TEXT_NODE) {
String text = ((Text)n).getNodeValue();
if (text.trim().length() > 0) {
throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
}
} else if (n.getNodeType() == Node.COMMENT_NODE) {
// OK, ignore
} else {
throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
}
}
return elements;
}
示例3: dump
import org.w3c.dom.Text; //导入依赖的package包/类
private boolean dump(Node node, boolean silent, int depth) {
boolean ok = true;
if (!silent) {
for (int i = 0; i < depth; i++) {
System.out.print(" ");
}
System.out.println(node);
}
if (node.getNodeType() == Node.TEXT_NODE) {
String text = ((Text) node).getData();
ok = ok && text.trim().length() > 0;
}
if (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE) {
Node child = node.getFirstChild();
while (child != null) {
ok = ok && dump(child, silent, depth + 1);
child = child.getNextSibling();
}
}
return ok;
}
示例4: setSignatureValueElement
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Base64 encodes and sets the bytes as the content of the SignatureValue
* Node.
*
* @param bytes bytes to be used by SignatureValue before Base64 encoding
*/
private void setSignatureValueElement(byte[] bytes) {
while (signatureValueElement.hasChildNodes()) {
signatureValueElement.removeChild(signatureValueElement.getFirstChild());
}
String base64codedValue = Base64.encode(bytes);
if (base64codedValue.length() > 76 && !XMLUtils.ignoreLineBreaks()) {
base64codedValue = "\n" + base64codedValue + "\n";
}
Text t = this.doc.createTextNode(base64codedValue);
signatureValueElement.appendChild(t);
}
示例5: getStrFromNode
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Method getStrFromNode
*
* @param xpathnode
* @return the string for the node.
*/
public static String getStrFromNode(Node xpathnode) {
if (xpathnode.getNodeType() == Node.TEXT_NODE) {
// we iterate over all siblings of the context node because eventually,
// the text is "polluted" with pi's or comments
StringBuilder sb = new StringBuilder();
for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
currentSibling != null;
currentSibling = currentSibling.getNextSibling()) {
if (currentSibling.getNodeType() == Node.TEXT_NODE) {
sb.append(((Text) currentSibling).getData());
}
}
return sb.toString();
} else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
return ((Attr) xpathnode).getNodeValue();
} else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
return ((ProcessingInstruction) xpathnode).getNodeValue();
}
return null;
}
示例6: testSplitText
import org.w3c.dom.Text; //导入依赖的package包/类
@Test
public void testSplitText() throws Exception {
Document document = createDOMWithNS("Text01.xml");
NodeList nodeList = document.getElementsByTagName("p");
Node node = nodeList.item(0);
Text textNode = document.createTextNode("This is a text node");
node.appendChild(textNode);
int rawChildNum = node.getChildNodes().getLength();
textNode.splitText(0);
int increased = node.getChildNodes().getLength() - rawChildNum;
assertEquals(increased, 1);
}
示例7: isTextWellFormed
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Checks if an Text node is well-formed, by checking if it contains invalid
* XML characters.
*
* @param data The contents of the comment node
*/
protected void isTextWellFormed(Text node) {
// Does the data valid XML character data
Character invalidChar = isWFXMLChar(node.getData());
if (invalidChar != null) {
String msg =
Utils.messages.createMessage(
MsgKey.ER_WF_INVALID_CHARACTER_IN_TEXT,
new Object[] { Integer.toHexString(Character.getNumericValue(invalidChar.charValue())) });
if (fErrorHandler != null) {
fErrorHandler.handleError(
new DOMErrorImpl(
DOMError.SEVERITY_FATAL_ERROR,
msg,
MsgKey.ER_WF_INVALID_CHARACTER,
null,
null,
null));
}
}
}
示例8: findSubElements
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Find all direct child elements of an element.
* Children which are all-whitespace text nodes or comments are ignored; others cause
* an exception to be thrown.
* @param parent a parent element in a DOM tree
* @return a list of direct child elements (may be empty)
* @throws IllegalArgumentException if there are non-element children besides whitespace
*
* @since 8.4
*/
public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
NodeList l = parent.getChildNodes();
List<Element> elements = new ArrayList<Element>(l.getLength());
for (int i = 0; i < l.getLength(); i++) {
Node n = l.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
elements.add((Element) n);
} else if (n.getNodeType() == Node.TEXT_NODE) {
String text = ((Text) n).getNodeValue();
if (text.trim().length() > 0) {
throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
}
} else if (n.getNodeType() == Node.COMMENT_NODE) {
// OK, ignore
} else {
throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
}
}
return elements;
}
示例9: getFirstChildText
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Obtains the text stored in the first child of a given node.
* @param node the node that stores the text
* @return the text string, <code>null</code> if no text was found
*/
private static String getFirstChildText(Node node) {
if (node == null) {
return null;
}
NodeList nodes = node.getChildNodes();
if (nodes == null || nodes.getLength() == 0) {
return null;
}
Node child = nodes.item(0);
if (child.getNodeType() == Node.TEXT_NODE) {
return ((Text)child).getNodeValue();
}
return null;
}
示例10: decode
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Method decode
*
* Takes the <CODE>Text</CODE> children of the Element and interprets
* them as input for the <CODE>Base64.decode()</CODE> function.
*
* @param element
* @return the byte obtained of the decoding the element
* $todo$ not tested yet
* @throws Base64DecodingException
*/
public static final byte[] decode(Element element) throws Base64DecodingException {
Node sibling = element.getFirstChild();
StringBuilder sb = new StringBuilder();
while (sibling != null) {
if (sibling.getNodeType() == Node.TEXT_NODE) {
Text t = (Text) sibling;
sb.append(t.getData());
}
sibling = sibling.getNextSibling();
}
return decode(sb.toString());
}
示例11: getTextContent
import org.w3c.dom.Text; //导入依赖的package包/类
public String getTextContent() throws DocumentedException {
NodeList childNodes = element.getChildNodes();
if (childNodes.getLength() == 0) {
return DEFAULT_NAMESPACE_PREFIX;
}
for(int i = 0; i < childNodes.getLength(); i++) {
Node textChild = childNodes.item(i);
if (textChild instanceof Text) {
String content = textChild.getTextContent();
return content.trim();
}
}
throw new DocumentedException(getName() + " should contain text.",
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.INVALID_VALUE,
DocumentedException.ErrorSeverity.ERROR
);
}
示例12: engineGetContextFromElement
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Method engineGetContextFromElement
*
* @param element
*/
protected void engineGetContextFromElement(Element element) {
super.engineGetContextFromElement(element);
if (element == null) {
throw new IllegalArgumentException("element null");
}
Text hmaclength =
XMLUtils.selectDsNodeText(element.getFirstChild(), Constants._TAG_HMACOUTPUTLENGTH, 0);
if (hmaclength != null) {
this.HMACOutputLength = Integer.parseInt(hmaclength.getData());
this.HMACOutputLengthSet = true;
}
}
示例13: getServiceResult
import org.w3c.dom.Text; //导入依赖的package包/类
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
Element rootElement = document.getDocumentElement();
Element objectElement;
Text objectText;
objectElement = document.createElement("threads");
rootElement.appendChild(objectElement);
objectText = document.createTextNode("" + com.twinsoft.convertigo.beans.core.RequestableObject.nbCurrentWorkerThreads);
objectElement.appendChild(objectText);
objectElement = document.createElement("contexts");
rootElement.appendChild(objectElement);
try {
objectText = document.createTextNode(Engine.isStarted ? "" + Engine.theApp.contextManager.getNumberOfContexts() : "0");
} catch (Exception e) {
objectText = document.createTextNode("0");
}
objectElement.appendChild(objectText);
objectElement = document.createElement("requests");
rootElement.appendChild(objectElement);
long i = EngineStatistics.getAverage(EngineStatistics.REQUEST);
if (i == -1) i = 0;
objectText = document.createTextNode("" + i);
objectElement.appendChild(objectText);
}
示例14: engineAddContextToElement
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Method engineAddContextToElement
*
* @param element
*/
public void engineAddContextToElement(Element element) {
if (element == null) {
throw new IllegalArgumentException("null element");
}
if (this.HMACOutputLengthSet) {
Document doc = element.getOwnerDocument();
Element HMElem =
XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_HMACOUTPUTLENGTH);
Text HMText =
doc.createTextNode(Integer.valueOf(this.HMACOutputLength).toString());
HMElem.appendChild(HMText);
XMLUtils.addReturnToElement(element);
element.appendChild(HMElem);
XMLUtils.addReturnToElement(element);
}
}
示例15: updateParamValue
import org.w3c.dom.Text; //导入依赖的package包/类
/**
* Update the param-value node of the context-param entry. Don't add it if it already exists.
*
* @param doc
* @param children
* @param childNode
*/
@Override
protected void updateParamValue(Document doc, Node contextParamElement) {
NodeList valueChildren = contextParamElement.getChildNodes();
boolean foundEntry = false;
for (int i = 0; i < valueChildren.getLength() && !foundEntry; i++) {
Node valueChild = valueChildren.item(i);
if (valueChild instanceof Text) {
String value = valueChild.getNodeValue();
int index = value.indexOf(applicationContextPath);
if (index >= 0) {
System.out.println("Application context entry " + getApplicationContextPathWithClasspath()
+ " already in document.");
foundEntry = true;
}
}
}
if (!foundEntry) {
System.out.println("Adding " + getApplicationContextPathWithClasspath() + " to context");
contextParamElement.appendChild(doc.createTextNode(" " + getApplicationContextPathWithClasspath() + "\n"));
}
}