List of usage examples for org.jdom2 Element Element
public Element(final String name)
From source file:com.cybernostics.jsp2thymeleaf.api.elements.CopyElementConverter.java
protected Optional<Element> createElement(JspElementContext node, JSPElementNodeConverter context) { final Element element = new Element(newNameForElement(node)); element.removeNamespaceDeclaration(element.getNamespace()); element.setNamespace(newNamespaceForElement(node)); return Optional.of(element); }
From source file:com.cybernostics.jsp2thymeleaf.api.elements.JspTagElementConverter.java
public static JspTagElementConverter ignore(String tagName) { return new JspTagElementConverter(tagName) { @Override// w w w .ja va 2 s .c o m public List<Content> process(JspElementContext node, JSPElementNodeConverter context) { final Element element = new Element("deleteme"); return Arrays.asList(element); } }; }
From source file:com.dexterapps.android.translator.TranslateAndSaveAndroid.java
License:Apache License
private void generateXMLForCountry(String countryCode, List<String> translatedText, ArrayList<AndroidStringMapping> stringXmlDOM, HashMap<String, Integer> baseStringResourcesMapping, String outPutFolder) {/*from w w w . j a v a 2 s . c o m*/ Element resources = new Element("resources"); Document doc = new Document(resources); //System.out.println("Generating XML"); //int totalNumberOfStrings = 0; for (int i = 0; i < stringXmlDOM.size(); i++) { AndroidStringMapping stringMapping = stringXmlDOM.get(i); if (stringMapping.getType().equalsIgnoreCase("string")) { Element string = new Element("string"); string.setAttribute(new Attribute("name", stringMapping.getAttributeName())); //To get the attribute value, use the hasmap and then string array int translatedTextIndex = baseStringResourcesMapping.get(stringMapping.getAttributeValue()); string.setText(translatedText.get(translatedTextIndex)); //Add element to root doc.getRootElement().addContent(string); } else if (stringMapping.getType().equalsIgnoreCase("string-array")) { Element stringArray = new Element("string-array"); stringArray.setAttribute(new Attribute("name", stringMapping.getAttributeName())); //Since this is String array it will have a list of string items, get the list of string items ArrayList<String> stringArrayItems = (ArrayList<String>) stringMapping.getAttributeValue(); for (int j = 0; j < stringArrayItems.size(); j++) { int translatedTextIndex = baseStringResourcesMapping.get(stringArrayItems.get(j)); stringArray.addContent(new Element("item").setText(translatedText.get(translatedTextIndex))); } //Add element to root doc.getRootElement().addContent(stringArray); } else { Element stringArray = new Element("plurals"); stringArray.setAttribute(new Attribute("name", stringMapping.getAttributeName())); //Since this is plurals it will have a list of string items with values, get the list of string items ArrayList<AndroidStringPlurals> stringPluralItems = (ArrayList<AndroidStringPlurals>) stringMapping .getAttributeValue(); for (int j = 0; j < stringPluralItems.size(); j++) { int translatedTextIndex = baseStringResourcesMapping .get(stringPluralItems.get(j).getAttributeValue()); Element pluralItem = new Element("item"); pluralItem.setAttribute("quantity", stringPluralItems.get(j).getAttributeName()); pluralItem.setText(translatedText.get(translatedTextIndex)); stringArray.addContent(pluralItem); } //Add element to root doc.getRootElement().addContent(stringArray); } } // new XMLOutputter().output(doc, System.out); XMLOutputter xmlOutput = new XMLOutputter(); try { // System.out.println("Saving File"); Format format = Format.getPrettyFormat(); format.setEncoding("UTF-8"); xmlOutput.setFormat(format); File file = new File(outPutFolder + "/values-" + countryCode); if (!file.exists()) { file.mkdir(); } file = new File(outPutFolder + "/values-" + countryCode + "/strings.xml"); FileOutputStream fop = new FileOutputStream(file); xmlOutput.output(doc, fop); System.out.println("Translation Successful !!"); // System.out.println("File Saved!"); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:com.facebook.buck.ide.intellij.projectview.ProjectView.java
License:Apache License
private static Element newElement(String name, Attribute attribute) { Element element = new Element(name); element.setAttribute(attribute);// ww w . j a va 2 s. c o m return element; }
From source file:com.facebook.buck.ide.intellij.projectview.ProjectView.java
License:Apache License
private static Element newElement(String name, Attribute... attributes) { Element element = new Element(name); if (attributes != null) { for (Attribute attribute : attributes) { element.setAttribute(attribute); }/*from www . j a va 2 s . com*/ } return element; }
From source file:com.github.theholywaffle.lolchatapi.LolStatus.java
License:Open Source License
/** * Generate a default LoLStatus that can later be modified and be used to * change the current LolStatus ({@link LolChat#setStatus(LolStatus)}). * /*from w w w. jav a2 s. c o m*/ */ public LolStatus() { outputter.setFormat(outputter.getFormat().setExpandEmptyElements(false)); doc = new Document(new Element("body")); for (final XMLProperty p : XMLProperty.values()) { doc.getRootElement().addContent(new Element(p.toString())); } }
From source file:com.iana.dver.pdf.scrapper.DVERScrapperTask.java
/** * Step - 2 : Generate XML from Text stripper * //from w w w . ja v a2 s . co m * @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.schema.XSDSchema.java
License:Open Source License
public void initDoc() { buildDocument = new Document(); if (schemaDefined == false) { root = null;//from w w w. j a v a 2s .c o m } if (root != null) { buildDocument.setRootElement(new Element(schemaRoot != null ? schemaRoot : root.getName())); } else { /* else no proper root element was defined in the schema and we make a duff one to stop */ /* a future exception... */ buildDocument.setRootElement(new Element(schemaRoot != null ? schemaRoot : "root")); } elementPath = new Element[100]; schemaPath = new XSDElement[100]; // newTrigger = new String[100]; newTrigger = new HashMap<String, Boolean>(); firstCall = true; }
From source file:com.init.octo.schema.XSDSchema.java
License:Open Source License
/** * show me where the money is/*from w w w . java2s . c o m*/ * @param elementSpec * @param value * @param appendCommand * @throws Exception */ public void populateDoc(String elementSpec, String value, String appendCommand) throws Exception { boolean valueIsNull = (null == value); String[] path = elementSpec.split("\\."); log.debug(elementSpec + " contains " + path.length + " elements"); for (int q = 0; q < path.length; q++) { log.debug("path[" + q + "] = " + path[q]); } if (path.length == 0) { log.warn("Zero length element spec [" + elementSpec + "]?"); return; } if (schemaDefined == false && firstCall == true) { if (schemaRoot != null) { /* use the element defined in the xmlselect... */ log.debug("Not using a schema - so creating the root element with the first specified element [" + schemaRoot + "]"); buildDocument.setRootElement(new Element(schemaRoot)); } else { log.debug("Not using a schema - so creating the root element with the first specified element [" + path[0] + "]"); log.debug("element spec: [" + elementSpec + "]"); buildDocument.setRootElement(new Element(path[0])); } firstCall = false; } /** Get the root element from the document and the schema... **/ elementPath[0] = buildDocument.getRootElement(); schemaPath[0] = root; if (schemaDefined && elementPath[0].getName().equals(path[0]) == false) { log.warn("The first element [" + path[0] + " is not the root element"); return; } /** Follow the element spec down the document and schema tree... **/ int idx = 1; boolean elementCreated = false; boolean xToManyElement = false; XSDElement schemaElement = null; while (idx < path.length) { xToManyElement = false; if (path[idx].startsWith("@")) { /** ... attribute specified... **/ idx++; break; } else { String childName = path[idx]; Element parentElement = elementPath[idx - 1]; Element docElement = findElement(parentElement, childName); if (schemaDefined == true) { schemaElement = schemaPath[idx - 1].getChild(path[idx]); if (schemaElement == null) { log.warn("The element [" + path[idx] + "] is not in the schema..."); return; } schemaPath[idx] = schemaElement; } if (docElement == null) { log.debug("Element [" + path[idx] + "] does not exist - will create it"); docElement = new Element(path[idx]); elementPath[idx] = docElement; addElementToDocument(schemaPath[idx - 1], elementPath[idx - 1], docElement); /** Clear any trigger new elements... **/ StringBuffer tmp = new StringBuffer(); for (int j = 0; j <= idx; j++) { if (tmp.length() != 0) { tmp.append("."); } tmp.append(path[j]); } triggerNew(tmp.toString()); elementCreated = true; } else { log.debug("Element [" + path[idx] + "] does exist... checking if we should " + "create a new one..."); /** Check for any throw new triggers... **/ StringBuffer tmp = new StringBuffer(); for (int j = 0; j <= idx; j++) { if (tmp.length() != 0) { tmp.append("."); } tmp.append(path[j]); } if (triggerNew(tmp.toString()) == true) { log.debug("New element trigger detected"); /** Create the element... **/ docElement = new Element(path[idx]); elementPath[idx] = docElement; addElementToDocument(schemaPath[idx - 1], elementPath[idx - 1], docElement); } else if (schemaDefined == true && schemaElement.xToMany() == true) { /* * Flag that a 0..m element has been found... if this is * the element that we are going to populate (the last * one in the while loop) then we will create a new one * if it has not been created a fresh already. This * enables, for example, address lines that come from a * single database row to be mapped into a repeating XML * element. Without this code the trigger mechanism * would not create the new XML element and the address * lines would be overwritten... */ xToManyElement = true; } else { /** * Element is 0..1 so we will just follow the tree * down... **/ log.debug("X..1 cardinality... just keep going..."); } } elementPath[idx] = docElement; } idx++; } // end while following the tree down... idx--; if (path[idx].startsWith("@")) { /** Set the attribute... **/ if (valueIsNull == false) { log.debug("Setting attribute [" + path[idx] + "] (on " + path[idx - 1] + ") to [" + value + "]"); elementPath[idx - 1].setAttribute(path[idx].substring(1, path[idx].length()), value); } } else { /** Set the element... **/ boolean appendValid = false; String separatorChar = null; String[] appendParts; if (appendCommand != null && appendCommand.equals("") == false) { appendParts = appendCommand.split("[()]"); if (appendParts.length != 2) { throw new Exception("append length not 2. :("); } if (appendParts[1].equals("newline")) { separatorChar = "\n"; } else if (appendParts[1].equals("comma")) { separatorChar = ", "; } else if (appendParts[1].equals("dash")) { separatorChar = " - "; } else if (appendParts[1].equals("space")) { separatorChar = " "; } appendValid = true; } if (appendValid) { if (valueIsNull == false) { log.debug("Append data to element [" + path[idx] + "] to [" + value + "]"); String data = elementPath[idx].getText(); data = data + separatorChar + value; elementPath[idx].setText(data); } } else { if (xToManyElement == true && elementCreated == false) { log.debug("Creating an 0..m element [" + path[idx] + "] with value [" + value + "]"); Element docElement = new Element(path[idx]); // @todo may need to check if element is nullable... if (valueIsNull) { docElement.setAttribute("nil", "true"); } docElement.setText(value); elementPath[idx] = docElement; addElementToDocument(schemaPath[idx - 1], elementPath[idx - 1], docElement); } else { log.debug("Setting element [" + path[idx] + "] to [" + value + "]"); elementPath[idx].setText(value); // @todo may need to check if element is nullable... if (valueIsNull) { elementPath[idx].setAttribute("nil", "true"); } } } } /***** * Useful for deep debugging... try { XMLOutputter xmlout = new * XMLOutputter(); * xmlout.setFormat(org.jdom.output.Format.getPrettyFormat()); * xmlout.output(buildDocument, System.out); } catch (Exception ex) { * System.out.println("EXCEPTION: " + ex.toString()); } *****/ }
From source file:com.init.octo.schema.XSDSchema.java
License:Open Source License
/** * /*from www . java 2 s . com*/ * @param elementSpec * @param schemaElement * @param element */ private void addMandatoryElementToDocument(XSDElement schemaElement, String elementSpec, Element element) { String[] eSpec = elementSpec.split("\\."); if (eSpec[0].equals(element.getName()) == false) { log.warn("The parent element [" + element.getName() + "] does not match the element spec [" + elementSpec + "]"); return; } int idx = 1; while (idx < eSpec.length) { if (isAttribute(eSpec[idx])) { String attname = eSpec[idx].substring(1, eSpec[idx].length()); Attribute att = element.getAttribute(attname); if (att == null) { /** Mandatory attribute does not exist so add it.. **/ element.setAttribute(attname, schemaElement.getDefaultAttValue(attname)); } return; } StringBuffer tmp = new StringBuffer(); for (int i = idx; i < eSpec.length; i++) { if (tmp.length() != 0) { tmp.append("."); } tmp.append(eSpec[i]); } Iterator<?> it = element.getChildren(eSpec[idx]).iterator(); /** * If the document does not have the specified child element and we * are at the end **/ /** * of the chain then this is a mandatory element that needs to be * added... **/ if (it.hasNext() == false && idx == eSpec.length - 1) { Element newel = new Element(eSpec[idx]); addElementToDocument(schemaElement, element, newel); return; } /** * If the document does not have the specified child element and * that element is **/ /** just part of the chain, then no need to carry on.. **/ if (it.hasNext() == false) { return; } /** * If the document does have the specified child element and we are * at the end of the chain then every thing is ok, so just return **/ if (idx == eSpec.length - 1) { return; } else { /** We have to follow every one of the elements down the tree.. **/ while (it.hasNext()) { addMandatoryElementToDocument(schemaElement, tmp.toString(), (Element) it.next()); } return; } } }