本文整理汇总了Java中org.w3c.dom.traversal.DocumentTraversal类的典型用法代码示例。如果您正苦于以下问题:Java DocumentTraversal类的具体用法?Java DocumentTraversal怎么用?Java DocumentTraversal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DocumentTraversal类属于org.w3c.dom.traversal包,在下文中一共展示了DocumentTraversal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dropInitialAlef
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的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;
}
}
}
}
示例2: filterPunctuation
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
protected void filterPunctuation(MaryData d) {
Document doc = d.getDocument();
NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(
MaryXML.PARAGRAPH), false);
Element p = null;
while ((p = (Element) ni.nextNode()) != null) {
Node textNode = p.getFirstChild();
String s = textNode.getNodeValue();
System.err.println("FilterPunctuation");
System.err.println(s);
s = s.replaceAll("،", ",");
//s = s.replaceAll("XX", "YY");
System.err.println(s);
textNode.setNodeValue(s);
}
}
示例3: vocaliseDoc
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的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++;
}
}
示例4: getPlainTextBelow
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
* Return the concatenation of the values of all text nodes below the given node. One space character is inserted between
* adjacent text nodes.
*
* @param n
* n
* @return null if n is null
*/
public static String getPlainTextBelow(Node n) {
if (n == null)
return null;
Document doc = null;
if (n.getNodeType() == Node.DOCUMENT_NODE) {
doc = (Document) n;
} else {
doc = n.getOwnerDocument();
}
StringBuilder buf = new StringBuilder();
NodeIterator it = ((DocumentTraversal) doc).createNodeIterator(n, NodeFilter.SHOW_TEXT, null, true);
Text text = null;
while ((text = (Text) it.nextNode()) != null) {
buf.append(text.getData().trim());
buf.append(" ");
}
return buf.toString();
}
示例5: init
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
@BeforeClass
public static void init() throws IOException, CSSException, SAXException {
log.info("\n\n\n == AnalyzerTest test at {} == \n\n\n", new Date());
DOMSource ds = new DOMSource(AnalyzerTest.class.getResourceAsStream("/simple/data.html"));
doc = ds.parse();
sheet = CSSFactory.parse(AnalyzerTest.class.getResource("/simple/data.css"), null);
analyzer = new Analyzer(sheet);
NodeList list = doc.getElementsByTagName("body");
assertEquals("There is one <body> element", 1, list.getLength());
//walker = new TidyTreeWalker(list.item(0), NodeFilter.SHOW_ELEMENT);
DocumentTraversal traversal = (DocumentTraversal) doc;
walker = traversal.createTreeWalker(list.item(0), NodeFilter.SHOW_ELEMENT, null, false);
elements = new ElementMap(doc);
}
示例6: outputDebug
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
* Outputs information on the matches for debug purposes.
*
* @param matchSet The set of matching Nodes.
* @param doc The first document being differenced
*/
private static void outputDebug(final NodePairs matchSet,
final Document doc) {
if (DiffFactory.isDebug()) {
NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(
doc.getDocumentElement(), NodeFilter.SHOW_ALL, null, false);
Node n;
while ((n = ni.nextNode()) != null) {
System.err.print(DOMOps.getNodeAsString(n));
if (matchSet.isMatched(n)) {
System.err.println(" matches "
+ DOMOps.getNodeAsString(matchSet.getPartner(n)));
} else {
System.err.println(" unmatched");
}
}
ni.detach();
System.err.println();
}
}
示例7: initialiseAndOrderNodes
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
* Returns a list of Nodes sorted according to their depths.
*
* Does *NOT* include root or documentElement
*
* TreeSet is sorted in reverse order of depth according to
* NodeInfoComparator.
*
* @param doc The document to be initialised and ordered.
* @return A depth-ordered list of the nodes in the doc.
*/
private static List<NodeDepth> initialiseAndOrderNodes(
final Document doc) {
NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(
doc, NodeFilter.SHOW_ALL, null, false);
List<NodeDepth> depthSorted = new ArrayList<NodeDepth>();
Node n;
while ((n = ni.nextNode()) != null) {
if (!(NodeOps.checkIfSameNode(doc, n)
|| NodeOps.checkIfSameNode(doc.getDocumentElement(), n)
|| n.getNodeType() == Node.DOCUMENT_TYPE_NODE)) {
depthSorted.add(new NodeDepth(n));
}
}
ni.detach();
Collections.sort(depthSorted, new NodeDepthComparator());
return depthSorted;
}
示例8: getElementsByTagNameCaseInsensitive
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
public static List<Element> getElementsByTagNameCaseInsensitive(Document doc,
final Set<String> lowerCaseNames) {
final List<Element> result = Lists.newArrayList();
NodeIterator nodeIterator = ((DocumentTraversal) doc)
.createNodeIterator(doc, NodeFilter.SHOW_ELEMENT,
new NodeFilter() {
public short acceptNode(Node n) {
if (lowerCaseNames.contains(n.getNodeName().toLowerCase())) {
return NodeFilter.FILTER_ACCEPT;
}
return NodeFilter.FILTER_REJECT;
}
}, false);
for (Node n = nodeIterator.nextNode(); n != null ; n = nodeIterator.nextNode()) {
result.add((Element)n);
}
return result;
}
示例9: checkDocument
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
private boolean checkDocument() {
while (true) {
if (this.document != panel.getDocument() || textInlineMap == null) {
this.document = panel.getDocument();
textInlineMap = null;
this.dotInfo = null;
this.markInfo = null;
this.lastSelectionRange = null;
try {
this.docRange = (DocumentRange) panel.getDocument();
this.docTraversal = (DocumentTraversal) panel.getDocument();
if (this.document != null && this.createMaps()) {
return true;
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
return false;
}
} catch (ClassCastException cce) {
XRLog.layout(Level.WARNING, "Document instance cannot create ranges: no selection possible");
return false;
}
}
return true;
}
}
示例10: getDocumentTraversal
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
DocumentTraversal getDocumentTraversal(Document doc)
throws XMLStreamException
{
DOMImplementation dom = doc.getImplementation();
if (!dom.hasFeature("Traversal", "2.0"))
throw new XMLStreamException("Traversal not supported");
return (DocumentTraversal) doc;
}
示例11: parseDocument
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
private void parseDocument(Document dasDoc, String chr, List<Feature> features) {
try {
DocumentTraversal traversal = (DocumentTraversal) dasDoc;
TreeWalker treewalker = traversal.createTreeWalker(
dasDoc.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
parseTree(treewalker, "FEATURE", chr, features);
} catch (Exception ex) {
log.error(ex);
throw new DataLoadException("Error loading DAS resource (" + ex.toString() + ")", getPath());
}
}
示例12: XmiDomTree
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
*
* @param filePath
* @param defaultPackageName
* @throws Exception
*/
public XmiDomTree(String filePath, String defaultPackageName) throws Exception {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filePath);
xmiTree = ((DocumentTraversal) document).createTreeWalker(document.getDocumentElement(), NodeFilter.SHOW_ALL, new XmiNodeFilter(), true);
initializeCollections(defaultPackageName);
checkXmiVersion(document);
}
示例13: Traversal
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
public Traversal(Document doc, Object source, int whatToShow) {
if (doc instanceof DocumentTraversal) {
DocumentTraversal dt = (DocumentTraversal) doc;
this.walker = dt.createTreeWalker(doc.getDocumentElement(), whatToShow, null, false);
} else {
this.walker = new GenericTreeWalker(doc.getDocumentElement(), whatToShow);
}
this.source = source;
}
示例14: canProcessPunctuatedArabicToTokens
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
@Test
public void canProcessPunctuatedArabicToTokens() throws Exception {
// setup
MaryInterface mary = new LocalMaryInterface();
mary.setInputType(MaryDataType.TEXT.name());
mary.setOutputType(MaryDataType.TOKENS.name());
mary.setLocale(new Locale("ar"));
String example = "مدينة شِبام الأثريَّة التاريخيَّة، إحدى أقدم مُدن";
// exercise
Document doc = mary.generateXML(example);
// verify
assertNotNull(doc);
//We should get 8 tokens from this example, 7 words and one comma
TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT,
new NameNodeFilter(MaryXML.TOKEN), false);
Element t = null;
int count = 0;
while ((t = (Element) tw.nextNode()) != null) {
count++;
}
assertEquals(8, count);
}
示例15: augmentDocument
import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
* Iterates through all the ELEMENT nodes in a document and gives them ids
* if they don't already have them.
*
* @param document
*/
public static void augmentDocument(Document document) {
final DocumentTraversal traversal = (DocumentTraversal) document;
final TreeWalker walker = traversal.createTreeWalker(document, NodeFilter.SHOW_ELEMENT, null, true);
traverseLevel(walker, 0);
}