List of usage examples for org.jdom2 Element getChildren
public List<Element> getChildren()
List
of all the child elements nested directly (one level deep) within this element, as Element
objects. From source file:com.hotaviano.tableexporter.csv.CSVExporter.java
License:Open Source License
private void createHeader(Document doc, PrintWriter writer) { Element thead = doc.getRootElement().getChild("thead").getChildren().get(0); String header = ""; for (Element elem : thead.getChildren()) { header += elem.getText() + ","; }//from w w w . ja va 2 s.c o m writer.println(header.subSequence(0, header.length() - 1)); }
From source file:com.hotaviano.tableexporter.docx.DOCXExporter.java
License:Open Source License
private void createBodyTable(XWPFTable table, Document document) { List<Element> elements = document.getRootElement().getChild("tbody").getChildren(); int row = 1;//from w w w.j a v a2s . co m for (Element element : elements) { XWPFTableRow tableRow = table.getRow(row++); int col = 0; for (Element td : element.getChildren()) { tableRow.getCell(col++).setText(td.getText()); } } }
From source file:com.hotaviano.tableexporter.pdf.PDFExporter.java
License:Open Source License
private List<PdfPCell> getHeaders(Document document) { List<PdfPCell> result = new ArrayList<>(); Element tr = document.getRootElement().getChild("thead").getChildren().get(0); for (Element th : tr.getChildren()) { PdfPCell cell = new PdfPCell(new Phrase(th.getText(), new Font(Font.BOLD))); result.add(cell);/* ww w. j av a 2s. co m*/ } return result; }
From source file:com.hotaviano.tableexporter.pdf.PDFExporter.java
License:Open Source License
private List<String> getBodyValues(Document document) { List<String> result = new ArrayList<>(); List<Element> trs = document.getRootElement().getChild("tbody").getChildren(); for (Element tr : trs) { for (Element td : tr.getChildren()) { result.add(td.getText());/* w w w . ja va 2s . co m*/ } } return result; }
From source file:com.hotaviano.tableexporter.xls.XLSExporter.java
License:Open Source License
private void createHeader(Row row, Element element, CellStyle style) { int index = 0; for (Element el : element.getChildren()) { Cell headerColumn = row.createCell(index); headerColumn.setCellStyle(style); headerColumn.setCellValue(el.getText()); index++;//ww w. j a v a 2 s . c om } }
From source file:com.hotaviano.tableexporter.xls.XLSExporter.java
License:Open Source License
private void createBody(Sheet sheet, Element element) { int index = 0; for (Element trs : element.getChildren()) { Row row = sheet.createRow(++index); for (int i = 0; i < trs.getChildren().size(); i++) { Element td = trs.getChildren().get(i); row.createCell(i).setCellValue(td.getText()); }/*from w ww . j av a 2 s.c om*/ } }
From source file:com.hp.application.automation.tools.octane.actions.UFTParameterFactory.java
License:Apache License
public static String convertResourceMtrAsJSON(InputStream resourceMtrInputStream) throws IOException { //TODO: Check is exists poiFS = new POIFSFileSystem(resourceMtrInputStream); DirectoryNode root = poiFS.getRoot(); for (Entry entry : root) { String name = entry.getName(); if (name.equals("ComponentInfo")) { if (entry instanceof DirectoryEntry) { System.out.println(entry); } else if (entry instanceof DocumentEntry) { byte[] content = new byte[((DocumentEntry) entry).getSize()]; poiFS.createDocumentInputStream("ComponentInfo").read(content); String fromUnicodeLE = StringUtil.getFromUnicodeLE(content); xmlData = fromUnicodeLE.substring(fromUnicodeLE.indexOf('<')).replaceAll("\u0000", ""); // System.out.println(xmlData); }//from w ww. ja v a 2 s . c om } } try { SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, (SAXHandlerFactory) null, (JDOMFactory) null); Document document = null; document = saxBuilder.build(new StringReader(xmlData)); Element classElement = document.getRootElement(); List<Element> studentList = classElement.getChildren(); ObjectMapper mapper = new ObjectMapper(); ArrayList<UFTParameter> uftParameters = new ArrayList<UFTParameter>(); UFTParameter uftParameter = new UFTParameter(); for (int temp = 0; temp < studentList.size(); temp++) { Element tag = studentList.get(temp); if ("ArgumentsCollection".equalsIgnoreCase(tag.getName())) { List<Element> children = tag.getChildren(); for (int i = 0; i < children.size(); i++) { Element element = children.get(i); List<Element> elements = element.getChildren(); for (int j = 0; j < elements.size(); j++) { Element element1 = elements.get(j); switch (element1.getName()) { case "ArgName": uftParameter.setArgName(element1.getValue()); break; case "ArgDirection": uftParameter.setArgDirection(Integer.parseInt(element1.getValue())); break; case "ArgDefaultValue": uftParameter.setArgDefaultValue(element1.getValue()); break; case "ArgType": uftParameter.setArgType(element1.getValue()); break; case "ArgIsExternal": uftParameter.setArgIsExternal(Integer.parseInt(element1.getValue())); break; default: logger.warning( String.format("Element name %s didn't match any case", element1.getName())); break; } } uftParameters.add(uftParameter); } return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(uftParameters); } } } catch (Exception e) { logger.severe(e.getMessage()); } return null; }
From source file:com.hpe.application.automation.tools.octane.actions.UFTParameterFactory.java
License:Open Source License
public static String convertResourceMtrAsJSON(InputStream resourceMtrInputStream) throws IOException { //String QTPFileParameterFileName = "resource.mtr"; //InputStream is = paths.get(0).getParent().child("Action0").child(QTPFileParameterFileName).read(); String xmlData = UFTTestUtil.decodeXmlContent(resourceMtrInputStream); try {//from w ww . j a v a2 s .c o m SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, null, null); Document document = saxBuilder.build(new StringReader(xmlData)); Element rootElement = document.getRootElement(); List<Element> rootChildrenElements = rootElement.getChildren(); ArrayList<UFTParameter> uftParameters = new ArrayList<>(); for (int temp = 0; temp < rootChildrenElements.size(); temp++) { Element tag = rootChildrenElements.get(temp); if ("ArgumentsCollection".equalsIgnoreCase(tag.getName())) { List<Element> children = tag.getChildren(); for (int i = 0; i < children.size(); i++) { UFTParameter uftParameter = new UFTParameter(); Element element = children.get(i); List<Element> elements = element.getChildren(); for (int j = 0; j < elements.size(); j++) { Element element1 = elements.get(j); switch (element1.getName()) { case "ArgName": uftParameter.setArgName(element1.getValue()); break; case "ArgDirection": uftParameter.setArgDirection(Integer.parseInt(element1.getValue())); break; case "ArgDefaultValue": uftParameter.setArgDefaultValue(element1.getValue()); break; case "ArgType": uftParameter.setArgType(element1.getValue()); break; case "ArgIsExternal": uftParameter.setArgIsExternal(Integer.parseInt(element1.getValue())); break; default: logger.warning( String.format("Element name %s didn't match any case", element1.getName())); break; } } uftParameters.add(uftParameter); } ObjectMapper mapper = new ObjectMapper(); String result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(uftParameters); return result; } } } catch (Exception e) { logger.severe(e.getMessage()); } return null; }
From source file:com.hpe.application.automation.tools.octane.actions.UFTParameterFactory.java
License:Open Source License
private static Element getHierarchyChildElement(Element root, String... childPath) { Element parent; Element found = root;/*from w w w .ja va2s . c om*/ for (int i = 0; i < childPath.length; i++) { parent = found; found = null; String elementName = childPath[i]; for (Element child : parent.getChildren()) { if (child.getName().equals(elementName)) { found = child; break; } } } return found; }
From source file:com.init.octo.schema.XsdAll.java
License:Open Source License
/** * This method builds a ALL element// w w w.j av a2 s . co m * * @param root - the ALL element that defines this element * @param cache - a list of pre-defined XML types */ public boolean build(Element root, XSDCache cache, String parentName) { log.debug("" + indent + ": " + "Build representation of a ALL"); id = root.getAttributeValue(XSDSchema.ID_ATT); maxOccurs = root.getAttributeValue(XSDSchema.MAXOCCURS_ATT); minOccurs = root.getAttributeValue(XSDSchema.MINOCCURS_ATT); group = new LinkedList<XMLType>(); Element element; String elementName; for (Iterator<?> i = (root.getChildren()).iterator(); i.hasNext();) { element = (Element) i.next(); elementName = element.getName(); log.debug("" + indent + ": " + "Child element <" + elementName + "> found"); /** process the child elements that define this element... **/ if (elementName.equals(XSDSchema.ANNOTATION)) { annotation = element.getTextTrim(); } else if (elementName.equals(XSDSchema.ELEMENT)) { log.debug("" + indent + ": " + "Adding element to the list of child elements"); XSDElement e = new XSDElement(indent + 1); if (e.build(element, cache, parentName) != true) { log.error("Error building an element - " + element); return (false); } group.add(e); } else { log.warn("" + indent + ": " + "Unexpected element <" + elementName + "> found and ignored"); } } // end for all child elements of this <ALL> tag log.debug("" + indent + ": " + "ALL built"); return (true); }