List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:com.hotaviano.tableexporter.pdf.PDFExporter.java
License:Open Source License
private int columnLength(Document document) { Element child = document.getRootElement().getChild("thead"); return child.getChild("tr").getChildren().size(); }
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);/* w w w. ja va 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());//www . j a v a 2s .c o m } } return result; }
From source file:com.hotaviano.tableexporter.xls.XLSExporter.java
License:Open Source License
@Override public byte[] export(String htmlTable) throws DocumentException { Document document = createDocument(htmlTable); Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet();/*from w ww .j a va 2 s . c o m*/ CellStyle headerStyle = createHeaderStyle(wb); Element theadTr = document.getRootElement().getChild("thead").getChildren().get(0); Element tbody = document.getRootElement().getChild("tbody"); createHeader(sheet.createRow(0), theadTr, headerStyle); createBody(sheet, tbody); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { wb.write(out); } catch (IOException ex) { throw new DocumentException(ex); } return out.toByteArray(); }
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 .j a va 2 s . c o m*/ } } 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 w w . ja 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
public static Collection<UFTParameter> convertApiTestXmlToArguments(File parametersFile, boolean isInputParameters) throws IOException { /*<TestParameters> <Schema>// w w w .ja v a2 s. c o m <xsd:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:types="http://hp.vtd.schemas/types/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xs:import schemaLocation="../../../dat/schemas/Types.xsd" namespace="http://hp.vtd.schemas/types/v1.0" /> <xs:element types:displayName="Parameters" name="Arguments"> <xs:complexType> <xs:sequence> <xs:element types:masked="false" name="StartParam1" type="xs:long"> <xs:annotation> <xs:documentation /> </xs:annotation> </xs:element> <xs:element types:masked="false" name="endParam1" type="xs:string"> <xs:annotation> <xs:documentation /> </xs:annotation> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xsd:schema> </Schema> <Values> <Arguments> <StartParam1>1</StartParam1> <endParam1>f</endParam1> </Arguments> </Values> </TestParameters>*/ try { SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, null, null); Document document = saxBuilder.build(parametersFile); Element rootElement = document.getRootElement(); Map<String, UFTParameter> uftParametersMap = new HashMap<>(); List<Element> argElements = getHierarchyChildElement(rootElement, "Schema", "schema", "element", "complexType", "sequence").getChildren(); for (Element argElement : argElements) { String name = argElement.getAttributeValue("name"); String type = argElement.getAttributeValue("type").replace("xs:", ""); int direction = isInputParameters ? 0 : 1; UFTParameter parameter = new UFTParameter(); parameter.setArgName(name); parameter.setArgType(type); parameter.setArgDirection(direction); uftParametersMap.put(parameter.getArgName(), parameter); } //getArg default values List<Element> argDefValuesElements = getHierarchyChildElement(rootElement, "Values", "Arguments") .getChildren(); for (Element argElement : argDefValuesElements) { UFTParameter parameter = uftParametersMap.get(argElement.getName()); if (parameter != null) { parameter.setArgDefaultValue(argElement.getValue()); } } return uftParametersMap.values(); } catch (Exception e) { logger.severe(e.getMessage()); } return Collections.emptySet(); }
From source file:com.hpe.application.automation.tools.octane.actions.UFTTestUtil.java
License:Open Source License
/** * Extract test description from UFT GUI test. * Note : UFT API test doesn't contain description * @param dirPath path of UFT test//w ww.ja v a 2s. c o m * @return test description */ public static String getTestDescription(FilePath dirPath) { String desc; try { if (!dirPath.exists()) { return null; } FilePath tspTestFile = new FilePath(dirPath, "Test.tsp"); InputStream is = new FileInputStream(tspTestFile.getRemote()); String xmlContent = decodeXmlContent(is); SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, null, null); Document document = saxBuilder.build(new StringReader(xmlContent)); Element rootElement = document.getRootElement(); Element descElement = rootElement.getChild("Description"); desc = descElement.getValue(); } catch (Exception e) { return null; } return desc; }
From source file:com.iana.dver.pdf.scrapper.DVERScrapperTask.java
/** * Step - 2 : Generate XML from Text stripper * //ww w.jav a2s .c om * @param tempTextFile * @throws IOException */ private void generateDverXML(String fileName, PDFTextStripperByArea stripper) throws IOException { File outputFile = new File(xmlDir + fileName + ".xml"); OutputStream fos = new FileOutputStream(outputFile); Element dver = new Element("DVER"); Document doc = new Document(dver); // Generate Address Node String addressDetail = stripper.getTextForRegion("ADDRESS"); String[] addressArr = addressDetail.split("\\n"); Element addressNode = new Element("ADDRESS"); addressNode.addContent(new Element("ADDRESS_1").setText(addressArr[0] + "\\n" + addressArr[1])); addressNode.addContent(new Element("ADDRESS_2").setText(addressArr[2] + "\\n" + addressArr[3])); if (addressArr.length > 4) { String[] tempContact = addressArr[4].split(" "); addressNode.addContent(new Element("PHONE").setText(tempContact[1])); addressNode.addContent(new Element("FAX").setText(tempContact[3])); } else { addressNode.addContent(new Element("PHONE").setText("")); addressNode.addContent(new Element("FAX").setText("")); } doc.getRootElement().addContent(addressNode); // Report Information Node String reportDetail = stripper.getTextForRegion("REPORT_INFO"); String[] reportDetailArr = reportDetail.split("\\n"); Element reportInfoNode = new Element("REPORT_INFO"); for (int i = 0; i < reportDetailArr.length; i++) { if (i == 0) { String[] reportInfo = reportDetailArr[i].split(":"); reportInfoNode.addContent(new Element("REPORT_NUMBER").setText(reportInfo[1])); } else if (i == 1) { String[] inspDetail = reportDetailArr[i].split(":"); inspDetail[1] = inspDetail[1].replaceAll("Certification Date", ""); reportInfoNode.addContent(new Element("INSPECTION_DATE").setText(inspDetail[1])); reportInfoNode.addContent(new Element("CERTIFICATION_DATE").setText(inspDetail[2])); } else if (i == 2) { String timings = reportDetailArr[i]; timings = timings.replaceAll("Time Started:", ""); timings = timings.replaceAll("Time Ended:", ""); String[] timeDetail = timings.split(" "); reportInfoNode.addContent(new Element("START_TIME").setText(timeDetail[0])); reportInfoNode.addContent(new Element("END_TIME").setText(timeDetail[1])); } else if (i == 3) { String[] reportInfo = reportDetailArr[i].split(":"); reportInfoNode.addContent(new Element("INSPECTION_LEVEL").setText(reportInfo[1])); } else if (i == 4) { String[] reportInfo = reportDetailArr[i].split(":"); reportInfoNode.addContent(new Element("INSPECTION_TYPE").setText(reportInfo[1])); } } doc.getRootElement().addContent(reportInfoNode); // INTERMODAL EQUIPMENT PROVIDER INFORMATION String iepDetail = stripper.getTextForRegion("IEP_INFO"); String[] iepDetailArr = iepDetail.split("\\n"); Element iepInfoNode = new Element("IEP_INFO"); for (int j = 0; j < iepDetailArr.length; j++) { if (j == 1) { iepInfoNode.addContent(new Element("IEP_NAME").setText(iepDetailArr[j])); } else if (j == 2) { String[] tempIepInfo = iepDetailArr[j].split(" "); iepInfoNode.addContent(new Element("US_DOT").setText(tempIepInfo[3])); iepInfoNode.addContent(new Element("DATA_SOURCE").setText(tempIepInfo[6])); } } doc.getRootElement().addContent(iepInfoNode); // MOTOR CARRIER INFORMATION String mcDetail = stripper.getTextForRegion("MC_INFO"); String[] mcDetailArr = mcDetail.split("\\n"); Element mcDetailNode = new Element("MC_INFO"); for (int k = 0; k < mcDetailArr.length; k++) { if (k == 1) { String mcCompAndDriver = mcDetailArr[k].replaceAll("Driver:", ""); mcDetailNode.addContent(new Element("MC_NAME").setText(mcCompAndDriver.split(" ")[0])); mcDetailNode.addContent(new Element("DRIVER").setText(mcCompAndDriver.split(" ")[1])); } else if (k == 2) { mcDetailNode.addContent(new Element("MC_ADD_1").setText(mcDetailArr[k])); } else if (k == 3) { mcDetailNode.addContent(new Element("MC_ADD_2").setText(mcDetailArr[k])); } else if (k == 4) { String tempStr = mcDetailArr[k]; tempStr = tempStr.replaceAll("USDOT #:", ""); tempStr = tempStr.replaceAll("Phone #:", ""); String[] otherDetails = tempStr.trim().split(" "); mcDetailNode .addContent(new Element("US_DOT").setText(otherDetails[0] != null ? otherDetails[0] : "")); mcDetailNode .addContent(new Element("PHONE").setText(otherDetails[2] != null ? otherDetails[2] : "")); } else if (k == 5) { String tempStr = mcDetailArr[k]; tempStr = tempStr.replaceAll("MC/MX #:", ""); tempStr = tempStr.replaceAll("Fax #:", ""); String[] otherDetails = tempStr.trim().split(" "); mcDetailNode .addContent(new Element("MC_MX").setText(otherDetails[0] != null ? otherDetails[0] : "")); mcDetailNode.addContent(new Element("FAX") .setText(otherDetails.length > 1 && otherDetails[1] != null ? otherDetails[2] : "")); } else if (k == 6) { mcDetailArr[k] = mcDetailArr[k].replaceAll("State #:", ""); mcDetailNode.addContent(new Element("STATE").setText(mcDetailArr[k] != null ? mcDetailArr[k] : "")); } else if (k == 7) { mcDetailArr[k] = mcDetailArr[k].replaceAll("Origin:", ""); mcDetailArr[k] = mcDetailArr[k].replaceAll("Destination:", ""); mcDetailNode.addContent( new Element("ORIGIN_DESTINATION").setText(mcDetailArr[k] != null ? mcDetailArr[k] : "")); } } doc.getRootElement().addContent(mcDetailNode); // VEHICLE IDENTIFICATION String vehicleIdentification = stripper.getTextForRegion("VEHICLE_ID"); String[] vehicleIdArr = vehicleIdentification.split("\\n"); Element vehicleIdNode = new Element("VEHICLE_IDENTIFICATION"); for (int l = 0; l < vehicleIdArr.length; l++) { if (l == 2) { String[] vehicleDetails = vehicleIdArr[l].trim().split(" "); for (int m = 0; m < vehicleDetails.length; m++) { if (m == 0) { vehicleIdNode.addContent( new Element("UNIT").setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 1) { vehicleIdNode.addContent( new Element("TYPE").setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 2) { vehicleIdNode.addContent( new Element("MAKE").setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 3) { vehicleIdNode.addContent( new Element("YEAR").setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 4) { vehicleIdNode.addContent( new Element("STATE").setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 5) { vehicleIdNode.addContent( new Element("LICENSE").setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 6) { vehicleIdNode.addContent(new Element("EQUIPMENT_ID") .setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 7) { vehicleIdNode.addContent(new Element("UNIT_VIN") .setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 8) { vehicleIdNode.addContent( new Element("GVWR").setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 9) { vehicleIdNode.addContent(new Element("ISSUED_DECAL") .setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } else if (m == 10) { vehicleIdNode.addContent(new Element("OOS_STKR") .setText(vehicleDetails[m] != null ? vehicleDetails[m] : "")); } } } } doc.getRootElement().addContent(vehicleIdNode); // Brake Adjustments String breakAdjustment = stripper.getTextForRegion("BREAK_ADJ"); String[] breakAdjustmentArr = breakAdjustment.split("-"); Element breakAdjustmentNode = new Element("BREAK_ADJUSTMENT"); for (int n = 0; n < breakAdjustmentArr.length; n++) { if (n == 1) { breakAdjustmentNode.setText(breakAdjustmentArr[n] != null ? breakAdjustmentArr[n] : ""); } } doc.getRootElement().addContent(breakAdjustmentNode); // Other Chassis Violation details String otherViolationDetail = stripper.getTextForRegion("OTHER_CHASSIS_VIOLATION"); String[] otherViolationDetailArr = otherViolationDetail.split("\\n"); Element otherViolationElement = new Element("OTHER_CHASSIS_VIOLATION"); for (int ocnt = 0; ocnt < (otherViolationDetailArr.length - 1); ocnt++) { if (ocnt > 1) { String[] tempOtrDetail = otherViolationDetailArr[ocnt].split(" "); Element violations = new Element("OTHER_VIOLATIONS"); for (int temp = 0; temp < tempOtrDetail.length; temp++) { if (temp == 0) { violations.addContent(new Element("VIO_CODE").setText(tempOtrDetail[temp])); } else if (temp == 1) { violations.addContent(new Element("SECTION").setText(tempOtrDetail[temp])); } else if (temp == 2) { violations.addContent(new Element("UNIT").setText(tempOtrDetail[temp])); } else if (temp == 3) { violations.addContent(new Element("OOS").setText(tempOtrDetail[temp])); } else if (temp == 4) { violations.addContent(new Element("NUMBER").setText(tempOtrDetail[temp])); } else if (temp == 5) { violations.addContent(new Element("VERIFY").setText(tempOtrDetail[temp])); } else if (temp == 6) { violations.addContent(new Element("CRASH").setText(tempOtrDetail[temp])); } else if (temp == 7) { violations.addContent(new Element("VIO_DESC").setText(tempOtrDetail[temp])); } } otherViolationElement.addContent(violations); } } doc.getRootElement().addContent(otherViolationElement); String driverNotes = stripper.getTextForRegion("DRIVER_NOTES"); Element driverNotesNode = new Element("NOTES_TO_DRIVER"); driverNotesNode.setText(driverNotes); doc.getRootElement().addContent(driverNotesNode); String iepNotes = stripper.getTextForRegion("IEP_NOTES"); Element iepNotesNode = new Element("NOTES_TO_IEP"); iepNotesNode.setText(iepNotes); doc.getRootElement().addContent(iepNotesNode); String creationNotes = stripper.getTextForRegion("CREATION_NOTES"); Element creationNotesNode = new Element("CREATED_BY"); creationNotesNode.setText(creationNotes.split("\\n")[1]); doc.getRootElement().addContent(creationNotesNode); XMLOutputter xmlOutput = new XMLOutputter(); // display nice nice xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(doc, fos); fos.flush(); fos.close(); }
From source file:com.init.octo.query.Query.java
License:Open Source License
/** * This method initialises the object with a parameters object. This will * replace any parameters in the query text with values from the parameters * object./*from ww w .j a v a 2 s . c om*/ * * @param parameters * - an XML structure containing current definitions of * parameters * @throws SQLException */ public void expandParameters(Document parameters) throws SQLException { XMLOutputter xout = new XMLOutputter(); // Format.getPrettyFormat()); log.debug("parameters XML: " + xout.outputString(parameters)); expandedQuery = StringUtils.expand(queryText.toString(), parameters.getRootElement()); log.debug("EXPANDED QUERY [" + expandedQuery + "]"); /** Close everything down... * */ // firstFetch = true; if (rs != null) { rs.close(); rs = null; } if (statement != null) { statement.close(); statement = null; } }