当前位置: 首页>>代码示例>>Java>>正文


Java TreeWalker.setCurrentNode方法代码示例

本文整理汇总了Java中org.w3c.dom.traversal.TreeWalker.setCurrentNode方法的典型用法代码示例。如果您正苦于以下问题:Java TreeWalker.setCurrentNode方法的具体用法?Java TreeWalker.setCurrentNode怎么用?Java TreeWalker.setCurrentNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.traversal.TreeWalker的用法示例。


在下文中一共展示了TreeWalker.setCurrentNode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:23,代码来源:Sequence.java

示例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;
}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:24,代码来源:DASFeatureSource.java

示例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);
}
 
开发者ID:proyecto-adalid,项目名称:adalid,代码行数:21,代码来源:XmiDomTree.java

示例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;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:22,代码来源:Readability.java

示例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;
}
 
开发者ID:jmarranz,项目名称:jnieasy,代码行数:12,代码来源:TreeWalkerUtil.java

示例6: 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);
}
 
开发者ID:proyecto-adalid,项目名称:adalid,代码行数:16,代码来源:XmiDomTree.java

示例7: 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);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:34,代码来源:Readability.java

示例8: isFirstOfItsKindIn

import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
public static boolean isFirstOfItsKindIn(Node node, Node ancestor) {
	if (ancestor == null)
		return false;
	Document doc = node.getOwnerDocument();
	if (doc == null)
		return false;
	TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ALL,
			new NameNodeFilter(node.getNodeName()), true);
	tw.setCurrentNode(node);
	Node prev = tw.previousNode();

	return prev == null || // no node with same name before this one
			!isAncestor(ancestor, prev); // prev is not in the same ancestor
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:15,代码来源:DomUtils.java

示例9: isLastOfItsKindIn

import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
public static boolean isLastOfItsKindIn(Node node, Node ancestor) {
	if (node == null || ancestor == null)
		return false;
	Document doc = node.getOwnerDocument();
	if (doc == null)
		return false;
	TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ALL,
			new NameNodeFilter(node.getNodeName()), true);
	tw.setCurrentNode(node);
	Node next = tw.nextNode();

	return next == null || // no node with same name after this one
			!isAncestor(ancestor, next); // next is not in the same ancestor
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:15,代码来源:DomUtils.java

示例10: getPreviousOfItsKindIn

import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
/**
 * Find the Element with the same tag name as <code>element</code> preceding <code>element</code> within the same subtree
 * under <code>root</code>. Precondition: <code>root</code> must be an ancestor of <code>element</code>.
 * 
 * @param element
 *            element
 * @param root
 *            root
 * @return that Element, or <code>null</code> if there is no such Element.
 */
public static Element getPreviousOfItsKindIn(Element element, Element root) {
	if (element == null || root == null)
		return null;
	String tagname = element.getTagName();
	TreeWalker tw = ((DocumentTraversal) element.getOwnerDocument()).createTreeWalker(root, NodeFilter.SHOW_ELEMENT,
			new NameNodeFilter(tagname), true);
	tw.setCurrentNode(element);
	for (Node previous = tw.previousNode(); previous != null; previous = tw.previousNode()) {
		if (previous.getNodeName().equals(tagname)) {
			return (Element) previous;
		}
	}
	return null;
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:25,代码来源:DomUtils.java

示例11: getNextOfItsKindIn

import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
/**
 * Find the Element with the same tag name as <code>element</code> following <code>element</code> within the same subtree
 * under <code>root</code>. Precondition: <code>root</code> must be an ancestor of <code>element</code>.
 * 
 * @param element
 *            element
 * @param root
 *            root
 * @return that Element, or <code>null</code> if there is no such Element.
 */
public static Element getNextOfItsKindIn(Element element, Element root) {
	if (element == null || root == null)
		return null;
	String tagname = element.getTagName();
	TreeWalker tw = ((DocumentTraversal) element.getOwnerDocument()).createTreeWalker(root, NodeFilter.SHOW_ELEMENT,
			new NameNodeFilter(tagname), true);
	tw.setCurrentNode(element);
	for (Node next = tw.nextNode(); next != null; next = tw.nextNode()) {
		if (next.getNodeName().equals(tagname)) {
			return (Element) next;
		}
	}
	return null;
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:25,代码来源:DomUtils.java

示例12: 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;
	}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:53,代码来源:Analyzer.java

示例13: 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;
	}
 
开发者ID:radkovo,项目名称:jStyleParser,代码行数:53,代码来源:Analyzer.java


注:本文中的org.w3c.dom.traversal.TreeWalker.setCurrentNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。