本文整理汇总了Java中org.w3c.dom.traversal.TreeWalker.getCurrentNode方法的典型用法代码示例。如果您正苦于以下问题:Java TreeWalker.getCurrentNode方法的具体用法?Java TreeWalker.getCurrentNode怎么用?Java TreeWalker.getCurrentNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.traversal.TreeWalker
的用法示例。
在下文中一共展示了TreeWalker.getCurrentNode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: traverseLevel
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private static void traverseLevel(TreeWalker walker, Element topParent, String indent) {
// describe current node:
Element current = (Element) walker.getCurrentNode();
//System.out.println(indent + "- " + ((Element) current).getTagName());
// store elements which need to be moved
if (topParent != null) {
Element parent = (Element) current.getParentNode();
if (parent != null && !topParent.equals(parent)) {
OutputFilter outputFilter = (OutputFilter)walker.getFilter();
outputFilter.getToAddList(topParent).add(current);
}
}
// traverse children:
for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
traverseLevel(walker, current, indent + '\t');
}
// return position to the current (level up):
walker.setCurrentNode(current);
}
示例2: parseTree
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private List<Feature> parseTree(TreeWalker walker,
String tag,
String chr,
List<Feature> features) {
Node parent = walker.getCurrentNode();
Element n = (Element) walker.firstChild();
while (n != null) {
if (n.getTagName().equalsIgnoreCase(tag)) {
Feature f = getFeature(walker, chr);
if (f != null) {
features.add(f);
}
n = (Element) walker.nextSibling();
continue;
}
parseTree(walker, tag, chr, features);
n = (Element) walker.nextSibling();
}
walker.setCurrentNode(parent);
return features;
}
示例3: setPackageToElements
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private void setPackageToElements(TreeWalker tw, String currentPackage) {
Node n = tw.getCurrentNode();
XmiElement element = new XmiElement((Element) n, this);
if (isPackageElement(element)) {
if (currentPackage.isEmpty()) {
currentPackage = element.getNameTag();
} else {
currentPackage = currentPackage + XmiTags.SEPARATOR + element.getNameTag();
}
logger.debug("Current package has changed " + currentPackage);
} else if (elementIdMap.get(element.getXmiId()) != null) {
elementIdMap.get(element.getXmiId()).setPackageContainer(currentPackage);
}
for (Node child = tw.firstChild();
child != null;
child = tw.nextSibling()) {
setPackageToElements(tw, currentPackage);
}
tw.setCurrentNode(n);
}
示例4: traverseLevel
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private static int traverseLevel(TreeWalker walker, int counter) {
// describe current node:
final Node parend = walker.getCurrentNode();
if (parend instanceof Element) {
if (((Element) parend).getAttribute("id").length() == 0) {
((Element) parend).setAttribute("id", "gen-id-" + counter);
counter++;
}
}
// traverse children:
for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
counter = traverseLevel(walker, counter);
}
// return position to the current (level up):
walker.setCurrentNode(parend);
return counter;
}
示例5: hasChildElement
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
public static boolean hasChildElement(TreeWalker walker)
{
Node current = walker.getCurrentNode();
Node child = walker.firstChild();
if (child != null)
{
walker.setCurrentNode(current);
return true;
}
return false;
}
示例6: checkElement
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private static void checkElement(Element childNode,TreeWalker walker,String tagName,boolean mustExist,String type)
{
if (childNode == null)
{
if (mustExist)
throw new JNIEasyXMLException("Expected a " + type + " element (<" + tagName + ">)",walker.getCurrentNode());
}
else if ((tagName != null) && !childNode.getTagName().equals(tagName))
throw new JNIEasyXMLException("Expected element with tag name: \"" + tagName + "\"",childNode);
}
示例7: fillElementIdMap
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private void fillElementIdMap(TreeWalker tw) {
Node n = tw.getCurrentNode();
Element element = (Element) n;
if (element.getAttributeNode(XmiTags.XMI_ID_TAG) != null) {
XmiElement xmiElement = new XmiElement(element, this);
elementIdMap.put(xmiElement.getXmiId(), xmiElement);
//System.out.println("entity "+xmiElement.getNameTag()+" type "+xmiElement.getXmiType());
}
for (Node child = tw.firstChild();
child != null;
child = tw.nextSibling()) {
fillElementIdMap(tw);
}
tw.setCurrentNode(n);
}
示例8: getArticleTextMapping
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
protected void getArticleTextMapping(TreeWalker walker, List<MappingNode> map) throws DOMException {
final Node parend = walker.getCurrentNode();
if (parend.getNodeType() == Node.TEXT_NODE && parend.getParentNode().getAttributes().getNamedItem("id") != null)
{
if (parend.getTextContent().trim().length() > 0)
{
final int index = findChildNodeIndex(parend.getParentNode(), parend);
if (index != -1)
{
// square brackets are not valid XML/HTML identifier
// characters, so we can use them here
map.add(new MappingNode(
parend.getParentNode().getAttributes().getNamedItem("id").getNodeValue() + "[" + index + "]",
parend.getNodeValue()));
// System.out.println(
// "ELEMENT '"+parend.getParentNode().getAttributes().getNamedItem("id").getNodeValue()
// + "["+index+"]"+"'");
// System.out.println( "VALUE: '"+parend.getNodeValue()+"'"
// );
}
}
}
// traverse children:
for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
getArticleTextMapping(walker, map);
}
// return position to the current (level up):
walker.setCurrentNode(parend);
}
示例9: matchSelector
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
protected boolean matchSelector(CombinedSelector sel, Element e, TreeWalker w) {
// store current walker position
Node current = w.getCurrentNode();
boolean retval = false;
Selector.Combinator combinator = null;
// traverse simple selector backwards
for (int i = sel.size() - 1; i >= 0; i--) {
// last simple selector
Selector s = sel.get(i);
//log.trace("Iterating loop with selector {}, combinator {}", s, combinator);
// decide according to combinator anti-pattern
if (combinator == null) {
retval = s.matches(e);
} else if (combinator == Selector.Combinator.ADJACENT) {
Element adjacent = (Element) w.previousSibling();
retval = false;
if (adjacent != null)
retval = s.matches(adjacent);
} else if (combinator == Selector.Combinator.PRECEDING) {
Element preceding;
retval = false;
while (!retval && (preceding = (Element) w.previousSibling()) != null) {
retval = s.matches(preceding);
}
} else if (combinator == Selector.Combinator.DESCENDANT) {
Element ancestor;
retval = false;
while (!retval && (ancestor = (Element) w.parentNode()) != null) {
retval = s.matches(ancestor);
}
} else if (combinator == Selector.Combinator.CHILD) {
Element parent = (Element) w.parentNode();
retval = false;
if (parent != null)
retval = s.matches(parent);
}
// set combinator for next loop
combinator = s.getCombinator();
// leave loop if not matched
if (retval == false)
break;
}
// restore walker position
w.setCurrentNode(current);
return retval;
}
示例10: matchSelector
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
protected boolean matchSelector(CombinedSelector sel, Element e, TreeWalker w) {
// store current walker position
Node current = w.getCurrentNode();
boolean retval = false;
Selector.Combinator combinator = null;
// traverse simple selector backwards
for (int i = sel.size() - 1; i >= 0; i--) {
// last simple selector
Selector s = sel.get(i);
//log.trace("Iterating loop with selector {}, combinator {}", s, combinator);
// decide according to combinator anti-pattern
if (combinator == null) {
retval = this.elementSelectorMatches(s, e);
} else if (combinator == Selector.Combinator.ADJACENT) {
Element adjacent = (Element) w.previousSibling();
retval = false;
if (adjacent != null)
retval = this.elementSelectorMatches(s, adjacent);
} else if (combinator == Selector.Combinator.PRECEDING) {
Element preceding;
retval = false;
while (!retval && (preceding = (Element) w.previousSibling()) != null) {
retval = this.elementSelectorMatches(s, preceding);
}
} else if (combinator == Selector.Combinator.DESCENDANT) {
Element ancestor;
retval = false;
while (!retval && (ancestor = (Element) w.parentNode()) != null) {
retval = this.elementSelectorMatches(s, ancestor);
}
} else if (combinator == Selector.Combinator.CHILD) {
Element parent = (Element) w.parentNode();
retval = false;
if (parent != null)
retval = this.elementSelectorMatches(s, parent);
}
// set combinator for next loop
combinator = s.getCombinator();
// leave loop if not matched
if (!retval)
break;
}
// restore walker position
w.setCurrentNode(current);
return retval;
}