org.w3c.dom.Text#getData ( )源码实例Demo

下面列出了org.w3c.dom.Text#getData ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Knowage-Server   文件: JTidyHTMLHandler.java
/**
 * Gets the title text of the HTML document.
 * 
 * @rawDoc the DOM Element to extract title Node from
 * @return the title text
 */
protected String getTitle(Element rawDoc) {
	if (rawDoc == null) {
		return null;
	}

	String title = "";

	NodeList children = rawDoc.getElementsByTagName("title");
	if (children.getLength() > 0) {
		Element titleElement = ((Element) children.item(0));
		Text text = (Text) titleElement.getFirstChild();
		if (text != null) {
			title = text.getData();
		}
	}
	return title;
}
 
源代码2 项目: XPagesExtensionLibrary   文件: XMLCompareUtils.java
/**
 * This method takes a node and removes any empty text node children from it. 
 * Empty text nodes are defined as text nodes containing a only spaces,
 * \n characters, \r characters and \t characters. 
 * You should normalize the node before calling this method on the off chance
 * it will trim important spaces from text. 
 * @param node
 */
private static void removeEmptyTextNodes(Node node) {
    NodeList nodeList = node.getChildNodes();
    int length = nodeList.getLength();
    for(int i=length-1; i>=0; i--) {
        Node child = nodeList.item(i);
        if(child.getNodeType()==Node.TEXT_NODE) {
            Text txt = (Text) child;
            String data = txt.getData();
            if(StringUtil.isSpace(data)) {
                node.removeChild(child);
            }
        } else {
            removeEmptyTextNodes(child);
        }
    }
}
 
源代码3 项目: pdfxtk   文件: XMLTree.java
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
     Icon icon;
     String label;
     if (value instanceof Element) {
Element e = (Element) value;
label = "<"+e.getTagName()+">";
icon = elementIcon;
     } else if (value instanceof Attr) {
Attr a = (Attr) value;
label = a.getName()+"="+a.getValue();
icon = attributeIcon;
     } else if (value instanceof Text) {
Text t = (Text) value;
label = t.getData();
icon = textIcon;
     } else {
label = "?";
icon = null;
     }
     if (label.length() > MAX_TEXT_LENGTH) {
label = label.substring(0, MAX_TEXT_LENGTH-1-3)+"...";
     }
     return new Cell(label, icon, selected, hasFocus);
   }
 
源代码4 项目: APICloud-Studio   文件: XMLMemento.java
public String getTextData()
{
	Text textNode = getTextNode();
	if (textNode != null)
	{
		return textNode.getData();
	}
	return null;
}
 
源代码5 项目: Open-LaTeX-Studio   文件: OpenTemplate.java
private Template getTemplateFromElement(NodeList templateNodes) {
    List<Element> templateElements = new ArrayList<>(4);
    for (int i = 0; i < templateNodes.getLength(); i++) {
        Node node = templateNodes.item(i);
        if (node instanceof Element) {
            templateElements.add((Element) node);
        }
    }

    Template template = new Template();

    for (Element templateElement : templateElements) {
        Text elementText = (Text) templateElement.getFirstChild();
        String elementString = elementText.getData();

        switch (templateElement.getTagName()) {
            case "name":
                template.setName(elementString);
                break;

            case "filename":
                template.setPath(getFullPathToTemplate(elementString));
                break;

            case "description":
                template.setDescription(elementString);
                break;

            case "source":
                template.setSource(elementString);
                break;
            default:
        }
    }
    return template;
}
 
private static boolean isWhitespaceText(Node n) {
  if (!(n instanceof Text)) {
    return false;
  }
  Text t = (Text) n;
  String s = t.getData();
  for (int i = 0; i < s.length(); i++) {
    if (!Character.isWhitespace(s.charAt(i))) {
      return false;
    }
  }
  return true;
}
 
源代码7 项目: lams   文件: HTMLTitleElementImpl.java
public String getText() {
    Text contentNode = getContentNode();
    return contentNode == null ? "" : contentNode.getData();
}
 
源代码8 项目: Doradus   文件: Utils.java
/**
 * Assert that the given org.w3c.doc.Node is a comment element or a Text element and
 * that it ontains whitespace only, otherwise throw an IllegalArgumentException using
 * the given error message. This is helpful when nothing is expected at a certain
 * place in a DOM tree, yet comments or whitespace text nodes can appear.
 *
 * @param node                      A DOM Node object.
 * @param errMsg                    String used to in the IllegalArgumentException
 *                                  constructor if thrown.
 * @throws IllegalArgumentException If the expression is false.
 */
public static void requireEmptyText(Node node, String errMsg)
        throws IllegalArgumentException {
    require((node instanceof Text) || (node instanceof Comment),
            errMsg + ": " + node.toString());
    if (node instanceof Text) {
        Text text = (Text)node;
        String textValue = text.getData();
        require(textValue.trim().length() == 0, errMsg + ": " + textValue);
    }
}