public static boolean isEmpty(File xmlFile) { Document document = XMLUtil.parseQuietlyToDocument(xmlFile); if (document != null) { List<Element> results = XMLUtil.getQueryElements(document, "*/" + ResultElement.TAG); if (results.size() == 0) { return true; } } return false; }
private static Element createResults0(Element element) { Element newElement = null; String tag = element.getLocalName(); if (ResultsElement.TAG.equals(tag)) { newElement = new ResultsElement(); } else if (ResultElement.TAG.equals(tag)) { newElement = new ResultElement(); } else { LOG.error("Unknown element: " + tag); } XMLUtil.copyAttributes(element, newElement); for (int i = 0; i < element.getChildCount(); i++) { Node child = element.getChild(i); if (child instanceof Text) { child = child.copy(); } else { child = ResultsElement.createResults0((Element) child); } if (newElement != null && child != null) { newElement.appendChild(child); } } LOG.trace("XML :" + newElement.toXML()); return newElement; }
/** Copy constructor from non-subclassed elements */ public static AbstractEditorElement createEditorElement(Element element) { AbstractEditorElement newElement = null; String tag = element.getLocalName(); if (tag == null || tag.equals("")) { throw new RuntimeException("no tag"); } else if (tag.equals(CombineElement.TAG)) { newElement = new CombineElement(); } else if (tag.equals(ConstantElement.TAG)) { newElement = new ConstantElement(); } else if (tag.equals(EditorElement.TAG)) { newElement = new EditorElement(); } else if (tag.equals(FieldElement.TAG)) { newElement = new FieldElement(); } else if (tag.equals(PatternElement.TAG)) { newElement = new PatternElement(); } else if (tag.equals(PatternListElement.TAG)) { newElement = new PatternListElement(); } else if (tag.equals(SpaceElement.TAG)) { newElement = new SpaceElement(); } else if (tag.equals(SubstitutionElement.TAG)) { newElement = new SubstitutionElement(); } else { throw new RuntimeException("unsupported editor element: " + tag); } if (newElement != null) { XMLUtil.copyAttributes(element, newElement); createSubclassedChildren(element, newElement); } return newElement; }
public List<MetadataElement> getMetadataElements() { List<Element> taggerList0 = XMLUtil.getQueryElements(this, MetadataElement.TAG); metadataList = new ArrayList<MetadataElement>(); for (Element tag : taggerList0) { metadataList.add((MetadataElement) tag); } return metadataList; }
protected void copyAttributesAndAddChildren(ResultsElement resultsElement) { if (resultsElement == null) { throw new RuntimeException("Null ResultsElement"); } XMLUtil.copyAttributesFromTo(resultsElement, this); for (ResultElement resultElement : resultsElement) { this.appendChild(resultElement); } }
public HtmlElement transform(File infile, File outfile) throws Exception { HtmlElement htmlElement = null; if (infile == null) { throw new RuntimeException("null input file"); } if (outfile == null) { throw new RuntimeException("null output file"); } String xmlString = transformToXML(infile); // debug output FileUtils.write(new File("target/debug/transform.xml"), xmlString, Charset.forName("UTF-8")); Element xmlElement = XMLUtil.parseXML(xmlString); htmlElement = new HtmlFactory().parse(xmlElement); XMLUtil.debug(xmlElement, new FileOutputStream("target/firstpass.html"), 1); return htmlElement; }
public List<ResultElement> getOrCreateResultElementList() { // always create // if (resultElementList == null) { resultElementList = new ArrayList<ResultElement>(); List<Element> resultChildren = XMLUtil.getQueryElements(this, "./*[local-name()='" + ResultElement.TAG + "']"); for (Element resultElement : resultChildren) { resultElementList.add((ResultElement) resultElement); } // } return resultElementList; }
public static AbstractEditorElement createEditorElement(InputStream is) { Element element = XMLUtil.parseQuietlyToDocument(is).getRootElement(); AbstractEditorElement editorElement = AbstractEditorElement.createEditorElement(element); return editorElement; }