List of usage examples for org.jdom2 Content getCType
public final CType getCType()
From source file:AIR.Common.xml.XmlReader.java
License:Open Source License
public boolean isEmptyElement() { Content thisNode = _stack.peek().getLeft(); switch (thisNode.getCType()) { case CDATA:// w ww .ja v a 2 s.c o m case Text: case Comment: return true; case Element: Element thisElement = getNodeAsElement(); return thisElement.getChildren().size() > 0; } return true; }
From source file:AIR.Common.xml.XmlReader.java
License:Open Source License
private boolean traverseImmediateChild(boolean firstOnly) throws IOException { /*/* w ww . jav a 2 s. com*/ * if (_file.available () == 0) { return false; } */ if (_stack.size() == 0) return false; MutablePair<Content, Integer> topElement = _stack.peek(); Content node = topElement.getLeft(); if (node.getCType() == CType.Element) { Element topElementNode = (Element) node; int nextChild = 0; if (!firstOnly) nextChild = topElement.getRight() + 1; // if we have a next child then we will go to that. if (topElementNode.getChildren().size() > nextChild) { topElement.setRight(nextChild); Element nextTraversalNode = topElementNode.getChildren().get(nextChild); _stack.push(new MutablePair<Content, Integer>(nextTraversalNode, -1)); return true; } } return false; }
From source file:AIR.Common.xml.XmlReader.java
License:Open Source License
private Element getNodeAsElement() { isEmpty();/*from w ww. j a v a2 s . co m*/ Content node = _stack.peek().getLeft(); if (node.getCType() == CType.Element) return (Element) node; return null; }
From source file:com.rometools.rome.io.impl.RSS092Parser.java
License:Open Source License
@Override protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { final Description desc = new Description(); final StringBuilder sb = new StringBuilder(); final XMLOutputter xmlOut = new XMLOutputter(); for (final Content c : eDesc.getContent()) { switch (c.getCType()) { case Text: case CDATA: sb.append(c.getValue());//from ww w . j a v a 2 s. c om break; case EntityRef: LOG.debug("Entity: {}", c.getValue()); sb.append(c.getValue()); break; case Element: sb.append(xmlOut.outputString((Element) c)); break; default: // ignore break; } } desc.setValue(sb.toString()); String att = eDesc.getAttributeValue("type"); if (att == null) { att = "text/html"; } desc.setType(att); return desc; }
From source file:Contabilidad.CodeBase64.java
public void limpia(String ruta) { try {//from w w w .j a va 2 s . c o m org.jdom2.Document doc = new SAXBuilder().build(ruta); Element rootNode = doc.getRootElement(); List list = rootNode.getContent(); for (int i = 0; i < list.size(); i++) { Content elementos = (Content) list.get(i); if (elementos.getCType() == Content.CType.Element) { Element aux = (Element) elementos; if (aux.getName().compareToIgnoreCase("Addenda") == 0) { List list2 = aux.getContent(); for (int j = 0; j < list2.size(); j++) { Content elementos2 = (Content) list2.get(j); if (elementos2.getCType() == Content.CType.Element) { Element aux2 = (Element) elementos2; if (aux2.getName().compareToIgnoreCase("FactDocMX") == 0) { list2.remove(aux2); } if (aux2.getName().compareToIgnoreCase("ECFD") == 0) { Namespace NP = Namespace.getNamespace("", ""); aux2.setNamespace(NP); List list3 = aux2.getContent(); for (int k = 0; k < list3.size(); k++) { Content elementos3 = (Content) list3.get(k); if (elementos3.getCType() == Content.CType.Element) { Element aux3 = (Element) elementos3; aux3.setNamespace(NP); List list4 = aux3.getContent(); for (int l = 0; l < list4.size(); l++) { Content elementos4 = (Content) list4.get(l); if (elementos4.getCType() == Content.CType.Element) { Element aux4 = (Element) elementos4; aux4.setNamespace(NP); List list5 = aux4.getContent(); for (int m = 0; m < list5.size(); m++) { Content elementos5 = (Content) list5.get(m); if (elementos5.getCType() == Content.CType.Element) { Element aux5 = (Element) elementos5; aux5.setNamespace(NP); List list6 = aux5.getContent(); for (int n = 0; n < list6.size(); n++) { Content elementos6 = (Content) list6.get(n); if (elementos6 .getCType() == Content.CType.Element) { Element aux6 = (Element) elementos6; aux6.setNamespace(NP); List list7 = aux6.getContent(); for (int p = 0; p < list7.size(); p++) { Content elementos7 = (Content) list7.get(p); if (elementos7 .getCType() == Content.CType.Element) { Element aux7 = (Element) elementos7; aux7.setNamespace(NP); List list8 = aux7.getContent(); for (int q = 0; q < list8.size(); q++) { Content elementos8 = (Content) list8 .get(q); if (elementos8 .getCType() == Content.CType.Element) { Element aux8 = (Element) elementos8; aux8.setNamespace(NP); } } } } } } } } } } } } List atributos = aux2.getAttributes(); for (int a = 0; a < atributos.size(); a++) { Attribute at = (Attribute) atributos.get(a); if (at.getName().compareToIgnoreCase("schemaLocation") == 0) aux2.removeAttribute(at); } } } } } } } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { outputter.output(doc, new FileOutputStream(ruta)); } catch (IOException e) { System.out.println(e); } } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.himeros.digitaledition.AlignedQuotationParser.java
License:Open Source License
public Element parse(Content content) { switch (content.getCType()) { case Text: case CDATA:/*from w w w . j a va 2 s. c o m*/ String text = ((Text) content).getText(); if (defaultLang.equals(langStack.peek())) { parseTextLine(betaTrans.parse(text)); } break; case Element: List<Content> children = ((Element) content).getContent(); for (Content child : children) { switch (child.getCType()) { case Text: case CDATA: parse(child); break; case Element: langScope = (((Element) child).getAttributeValue("lang") == null ? langScope : ((Element) child).getAttributeValue("lang")); langStack.push(langScope); parse(child); langStack.pop(); } } } return rootOut; }
From source file:eu.himeros.ocr.ngt.NearGroundTruthParser.java
License:Open Source License
public Element parse(Content content) { switch (content.getCType()) { case Text: case CDATA:/*from www. j a v a2 s . co m*/ String text = ((Text) content).getText(); if (defaultLang.equals(langStack.peek())) { parseTextLine(betaTrans.parse(text)); //parseTextLine(text); } break; case Element: List<Content> children = ((Element) content).getContent(); for (Content child : children) { switch (child.getCType()) { case Text: case CDATA: parse(child); break; case Element: langScope = (((Element) child).getAttributeValue("lang") == null ? langScope : ((Element) child).getAttributeValue("lang")); langStack.push(langScope); parse(child); langStack.pop(); } } } return rootOut; }
From source file:migrationextraction.MainWindowUI.java
private OleObject getXMLUntilOle(List<Content> contentList, int nextLvl) { List<String> contentPath = Arrays.asList("AlternateContent", "Choice", "oleObject", "objectPr", "anchor"); for (Iterator<Content> it = contentList.iterator(); it.hasNext();) { Content content = it.next(); if (nextLvl < contentPath.size() - 1 && content.getCType().toString().equals("Element") && ((Element) content).getName().equals(contentPath.get(nextLvl))) { getXMLUntilOle(((Element) content).getContent(), nextLvl++); }//w w w.j a v a2s . c om System.out.println(content); } return null; }
From source file:mil.tatrc.physiology.datamodel.doxygen.XSDToDoxygen.java
License:Open Source License
/** * Obtains any XML comments sibling content that immediately preceed this * element//from ww w . ja va2 s. co m * @param element * @return */ private String getComment(Element element) { Parent parent = element.getParent(); int i = parent.indexOf(element); StringBuffer comments = new StringBuffer(); // Search backward from this position for preceding comments for (int x = i - 1; x >= 0; x--) { Content c = parent.getContent(x); if (c.getCType() == Content.CType.Comment) { Comment comment = (Comment) c; String text = comment.getText().trim(); if (isValidComment(text)) { // This comment pertains to the preceding element if (text.startsWith("<<")) { break; } if (comments.length() > 0) { comments.insert(0, '\n'); } comments.insert(0, text); } } else if (c.getCType() == Content.CType.Element) { // Stop looking when we hit another element break; } } // Search forward from this position for inline commentx for (int x = i + 1; x < parent.getContentSize(); x++) { Content c = parent.getContent(x); if (c.getCType() == Content.CType.Comment) { Comment comment = (Comment) c; String text = comment.getText().trim(); if (isValidComment(text)) { // This comment pertains to the preceding element if (text.startsWith("<<")) { // Strip the "<<" text = text.substring(2); if (comments.length() > 0) { comments.insert(0, '\n'); } comments.insert(0, text); } else { break; } } } else if (c.getCType() == Content.CType.Element) { // Stop looking when we hit another element break; } } return comments.toString(); }
From source file:org.apache.maven.io.util.AbstractJDOMWriter.java
License:Apache License
public final void write(final T source, final Document document, final Writer writer, final Format jdomFormat, final DocumentModifier modifier) throws java.io.IOException { if (modifier != null) { modifier.preProcess(document);//from ww w .ja v a 2 s .c o m } update(source, new IndentationCounter(0), document.getRootElement()); if (modifier != null) { modifier.postProcess(document); } // Override XMLOutputter to correct initial comment trailing newlines. final XMLOutputter outputter = new XMLOutputter(new AbstractXMLOutputProcessor() { /** * This will handle printing of a {@link Document}. * * @param out <code>Writer</code> to use. * @param fstack the FormatStack * @param nstack the NamespaceStack * @param doc <code>Document</code> to write. * @throws IOException if the destination Writer fails */ @Override protected void printDocument(Writer out, FormatStack fstack, NamespaceStack nstack, Document doc) throws IOException { // If there is no root element then we cannot use the normal ways to // access the ContentList because Document throws an exception. // so we hack it and just access it by index. List<Content> list = doc.hasRootElement() ? doc.getContent() : new ArrayList<Content>(doc.getContentSize()); if (list.isEmpty()) { final int sz = doc.getContentSize(); for (int i = 0; i < sz; i++) { list.add(doc.getContent(i)); } } printDeclaration(out, fstack); Walker walker = buildWalker(fstack, list, true); if (walker.hasNext()) { while (walker.hasNext()) { final Content c = walker.next(); // we do not ignore Text-like things in the Document. // the walker creates the indenting for us. if (c == null) { // but, what we do is ensure it is all whitespace, and not CDATA final String padding = walker.text(); if (padding != null && Verifier.isAllXMLWhitespace(padding) && !walker.isCDATA()) { // we do not use the escaping or text* method because this // content is outside of the root element, and thus is not // strict text. write(out, padding); } } else { switch (c.getCType()) { case Comment: printComment(out, fstack, (Comment) c); // This modification we have made to the overridden method in order // to correct newline declarations. write(out, fstack.getLineSeparator()); break; case DocType: printDocType(out, fstack, (DocType) c); break; case Element: printElement(out, fstack, nstack, (Element) c); if (walker.hasNext()) { // This modification we have made to the overridden method in order // to correct newline declarations. write(out, fstack.getLineSeparator()); } break; case ProcessingInstruction: printProcessingInstruction(out, fstack, (ProcessingInstruction) c); break; case Text: final String padding = ((Text) c).getText(); if (padding != null && Verifier.isAllXMLWhitespace(padding)) { // we do not use the escaping or text* method because this // content is outside of the root element, and thus is not // strict text. write(out, padding); } default: // do nothing. } } } if (fstack.getLineSeparator() != null) { write(out, fstack.getLineSeparator()); } } } }); outputter.setFormat(jdomFormat); outputter.output(document, writer); }