本文整理汇总了Java中org.w3c.dom.traversal.TreeWalker类的典型用法代码示例。如果您正苦于以下问题:Java TreeWalker类的具体用法?Java TreeWalker怎么用?Java TreeWalker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreeWalker类属于org.w3c.dom.traversal包,在下文中一共展示了TreeWalker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: parse
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
public void parse(Element typeNode,TreeWalker walker,TaskContext ctx)
{
super.parse(typeNode,walker,ctx);
// <field/component ... >
TypeNativeDirectCallbackImpl typeDec = getTypeNativeDirectCallback();
// En el caso de user defined puede estar ya definida la signatura
// por lo que la carga de una nueva es opcional y se hace si detectamos que
// que en el XML se actualiza la signatura
if ((typeDec.getBehaviorSignature() == null) || TreeWalkerUtil.hasChildElement(walker))
{
// Una vez aqu� dentro, deben existir nodos de declaraci�n de la signatura o falla
NativeBehaviorSignatureXML sigXML = typeDec.newBehaviorSignatureXML();
sigXML.parse(typeNode,walker,ctx);
typeDec.setBehaviorSignature(sigXML.getBehaviorSignature());
}
}
示例3: getElementById
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
public Element getElementById(String elementId)
{
Element element = xmljGetElementById(elementId);
if (element == null)
{
TreeWalker walker = createTreeWalker(this, NodeFilter.SHOW_ELEMENT,
null, false);
for (Node node = walker.nextNode(); node != null;
node = walker.nextNode())
{
GnomeElement e = (GnomeElement) node;
if (e.userIdAttrs != null)
{
for (Iterator i = e.userIdAttrs.iterator(); i.hasNext(); )
{
Attr attr = (Attr) i.next();
if (attr.getNodeValue().equals(elementId))
{
return e;
}
}
}
}
}
return element;
}
示例4: 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;
}
示例5: 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);
}
示例6: dropInitialAlef
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
private void dropInitialAlef(Document doc) throws DOMException {
TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.TOKEN),
false);
Element m = null;
boolean prevEndsWithVowel = false;
while ((m = (Element) tw.nextNode()) != null) {
System.out.println("Element: "+m.getTagName());
if (m != null && m.getTagName().equals(MaryXML.TOKEN)) {
String transcription = m.getAttribute("ph");
System.out.println("transcription: "+transcription+", prevEndsWithVowel: "+prevEndsWithVowel);
if ( transcription.startsWith("' a ") && prevEndsWithVowel ) {
System.out.println("Removing A");
m.setAttribute("ph", transcription.replaceAll("^' a -?","' "));
}
if ( transcription.matches(".*[AUIaui][01]?$") ) {
prevEndsWithVowel = true;
}
}
}
}
示例7: vocaliseDoc
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
protected void vocaliseDoc(Document doc) throws Exception {
TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT,
new NameNodeFilter(MaryXML.TOKEN), false);
Element t = null;
StringBuilder origText = new StringBuilder();
while ((t = (Element) tw.nextNode()) != null) {
//if (MaryDomUtils.hasAncestor(t, MaryXML.SAYAS) || t.hasAttribute("ph") || t.hasAttribute("sounds_like")) {
// ignore token
//continue;
origText.append(" " + MaryDomUtils.tokenText(t));
}
String vocText = vocaliseText(origText.toString());
String[] vocTextList = vocText.split(" ");
TreeWalker tw2 = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT,
new NameNodeFilter(MaryXML.TOKEN), false);
Element t2 = null;
int i = 0;
while ((t2 = (Element) tw2.nextNode()) != null && i < vocTextList.length) {
MaryDomUtils.setTokenText(t2, vocTextList[i]);
i++;
}
}
示例8: 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;
}
示例9: buildOutputDom
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
private static void buildOutputDom(Element root, OutputFilter outputFilter) {
try {
TreeWalker walker = new TwsTreeWalker(root, NodeFilter.SHOW_ELEMENT, outputFilter, false);
traverseLevel(walker,null,"");
outputFilter.doOutPut();
}
finally {
if (outputFilter != null) {
outputFilter.map.clear();
}
}
}
示例10: createTreeWalker
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
/**
* Create and return a TreeWalker.
*
* @param root The root of the iterator.
* @param whatToShow The whatToShow mask.
* @param filter The NodeFilter installed. Null means no filter.
* @param entityReferenceExpansion true to expand the contents of
* EntityReference nodes
* @since WD-DOM-Level-2-19990923
*/
public TreeWalker createTreeWalker(Node root,
int whatToShow,
NodeFilter filter,
boolean entityReferenceExpansion)
{
if (root == null) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
return new TreeWalkerImpl(root, whatToShow, filter,
entityReferenceExpansion);
}
示例11: getCtFieldFromXMLDirectly
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
public static CtField getCtFieldFromXMLDirectly(Element classNode,CtClass ctClass)
{
TreeWalker walker = TreeWalkerUtil.createTreeWalker(classNode);
Element fieldNode = TreeWalkerUtil.firstChildElement(walker, FieldOfClassXML.fieldTagName(), true);
String fieldName = FieldOfClassXML.getName(fieldNode);
try
{
return ctClass.getDeclaredField(fieldName);
}
catch(NotFoundException ex)
{
throw new JNIEasyException(ex);
}
}
示例12: createTreeWalker
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
public static TreeWalker createTreeWalker(Element node)
{
//DocumentTraversal doc = (DocumentTraversal)node.getOwnerDocument();
//return doc.createTreeWalker(node,NodeFilter.SHOW_ELEMENT,null,true);
return new TreeWalkerImpl(node,NodeFilter.SHOW_ELEMENT,null,true);
}
示例13: 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;
}
示例14: 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);
}
示例15: parse
import org.w3c.dom.traversal.TreeWalker; //导入依赖的package包/类
public void parse(Element classNode,TreeWalker walker)
{
// Ej. <class name="SimpleClassName" libraryPath="User32.dll">
JavaClassAsNativeMultipleFieldContainerImpl javaClass = getJavaClassAsMultipleFieldContainer();
Attr libPathAtt = classNode.getAttributeNode("libraryPath");
if (libPathAtt != null)
{
String libraryPath = libPathAtt.getValue();
javaClass.setLibraryPath(libraryPath);
}
}