List of usage examples for org.jdom2 Element setText
public Element setText(final String text)
From source file:com.github.cat.yum.store.util.YumUtil.java
private static RepoModule createPrimary(RpmData[] rpmdatas, String rootPath) throws IOException, NoSuchAlgorithmException { RepoModule repo = new RepoModule(rootPath, "primary"); Document doc = new Document(); Element root = new Element("metadata", COMMONNAMESPACE); doc.addContent(root);//from w w w . j ava 2s . c om root.addNamespaceDeclaration(RPMNAMESPACE); root.setAttribute("packages", rpmdatas.length + ""); for (RpmData rpmdata : rpmdatas) { RpmMetadata rpmMetadata = rpmdata.rpmMetadata; Element packAge = new Element("package", COMMONNAMESPACE); packAge.setAttribute("type", "rpm"); root.addContent(packAge); Element name = new Element("name", COMMONNAMESPACE); name.setText(rpmMetadata.name); packAge.addContent(name); Element arch = new Element("arch", COMMONNAMESPACE); arch.setText(rpmMetadata.architecture); packAge.addContent(arch); Element version = new Element("version", COMMONNAMESPACE); version.setAttribute("epoch", rpmMetadata.epoch + ""); version.setAttribute("ver", rpmMetadata.version); version.setAttribute("rel", rpmMetadata.release); packAge.addContent(version); Element checksum = new Element("checksum", COMMONNAMESPACE); checksum.setAttribute("type", ALGORITHM); checksum.setAttribute("pkgid", "YES"); checksum.setText(HashFile.getsum(rpmdata.rpm, ALGORITHM)); packAge.addContent(checksum); Element summary = new Element("summary", COMMONNAMESPACE); summary.setText(rpmMetadata.summary); packAge.addContent(summary); Element description = new Element("description", COMMONNAMESPACE); description.setText(rpmMetadata.description); packAge.addContent(description); Element packager = new Element("packager", COMMONNAMESPACE); packager.setText(rpmMetadata.packager); packAge.addContent(packager); Element url = new Element("url", COMMONNAMESPACE); url.setText(rpmMetadata.url); packAge.addContent(url); Element time = new Element("time", COMMONNAMESPACE); time.setAttribute("file", rpmdata.rpm.lastModified() / 1000 + ""); time.setAttribute("build", rpmMetadata.buildTime + ""); packAge.addContent(time); Element size = new Element("size", COMMONNAMESPACE); size.setAttribute("package", rpmdata.rpm.length() + ""); size.setAttribute("installed", rpmMetadata.installedSize + ""); size.setAttribute("archive", rpmMetadata.archiveSize + ""); packAge.addContent(size); Element location = new Element("location", COMMONNAMESPACE); location.setAttribute("href", replacePath(FileUtils.getFileRelativePath(rootPath, rpmdata.rpm))); packAge.addContent(location); Element format = new Element("format", COMMONNAMESPACE); packAge.addContent(format); Element license = new Element("license", RPMNAMESPACE); license.setText(rpmMetadata.license); format.addContent(license); Element vendor = new Element("vendor", RPMNAMESPACE); vendor.setText(rpmMetadata.vendor); format.addContent(vendor); Element group = new Element("group", RPMNAMESPACE); group.setText(rpmMetadata.group); format.addContent(group); Element buildhost = new Element("buildhost", RPMNAMESPACE); buildhost.setText(rpmMetadata.buildHost); format.addContent(buildhost); Element sourcerpm = new Element("sourcerpm", RPMNAMESPACE); sourcerpm.setText(rpmMetadata.sourceRpm); format.addContent(sourcerpm); Element headerRange = new Element("header-range", RPMNAMESPACE); headerRange.setAttribute("start", rpmMetadata.headerStart + ""); headerRange.setAttribute("end", rpmMetadata.headerEnd + ""); format.addContent(headerRange); Element provides = new Element("provides", RPMNAMESPACE); format.addContent(provides); addEntry(provides, rpmMetadata.provide, null); Element requires = new Element("requires", RPMNAMESPACE); format.addContent(requires); addEntry(requires, rpmMetadata.require, new PrivateRequireFilter()); Element conflicts = new Element("conflicts", RPMNAMESPACE); format.addContent(conflicts); addEntry(conflicts, rpmMetadata.conflict, null); Element obsoletes = new Element("obsoletes", RPMNAMESPACE); format.addContent(obsoletes); addEntry(obsoletes, rpmMetadata.obsolete, null); YumFileter fileflter = new PrivateFileFilter(); YumFileter fileDirflter = new PrivateFileDirFilter(); for (com.github.cat.yum.store.model.File file : rpmMetadata.files) { if (StringUtils.isBlank(file.type)) { if (fileflter.filter(file.path)) { continue; } } else if ("dir".equals(file.type)) { if (fileDirflter.filter(file.path)) { continue; } } Element fileElemenrt = new Element("file", COMMONNAMESPACE); fileElemenrt.setText(file.path); if (!StringUtils.isBlank(file.type)) { fileElemenrt.setAttribute("type", file.type); } format.addContent(fileElemenrt); } } yumXmlSave(doc, repo); return repo; }
From source file:com.github.cat.yum.store.util.YumUtil.java
private static RepoModule createFilelitsts(RpmData[] rpmdatas, String rootPath) throws IOException, NoSuchAlgorithmException { RepoModule repo = new RepoModule(rootPath, "filelists"); Document doc = new Document(); Element root = new Element("filelists", FILELISTSNAMESPACE); doc.addContent(root);//w w w . j a va2s . co m root.setAttribute("packages", rpmdatas.length + ""); for (RpmData rpmdata : rpmdatas) { RpmMetadata rpmMetadata = rpmdata.rpmMetadata; Element packAge = new Element("package", FILELISTSNAMESPACE); packAge.setAttribute("pkgid", HashFile.getsum(rpmdata.rpm, ALGORITHM)); packAge.setAttribute("name", rpmMetadata.name); packAge.setAttribute("arch", rpmMetadata.architecture); root.addContent(packAge); Element version = new Element("version", FILELISTSNAMESPACE); version.setAttribute("epoch", rpmMetadata.epoch + ""); version.setAttribute("ver", rpmMetadata.version); version.setAttribute("rel", rpmMetadata.release); packAge.setContent(version); for (com.github.cat.yum.store.model.File file : rpmMetadata.files) { Element fileElement = new Element("file", FILELISTSNAMESPACE); fileElement.setText(file.path); if (file.type != null) { fileElement.setAttribute("type", file.type); } packAge.addContent(fileElement); } } yumXmlSave(doc, repo); return repo; }
From source file:com.globalsight.dispatcher.bo.JobTask.java
License:Apache License
private void setTargetSegment(Element p_trgElement, String p_target, String p_encoding) throws UnsupportedEncodingException { if (p_target == null || p_target.trim().length() == 0) return;// w ww . ja v a 2s.c o m String target = new String(p_target.getBytes("UTF-8"), p_encoding); try { StringReader stringReader = new StringReader("<target>" + p_target + "</target>"); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(stringReader); Element elem = doc.getRootElement().clone().detach(); setNamespace(elem, p_trgElement.getNamespace()); //Delete Original Target Segment. p_trgElement.removeContent(); for (int i = 0; i < elem.getContentSize(); i++) { p_trgElement.addContent(elem.getContent(i).clone().detach()); } } catch (Exception e) { p_trgElement.setText(target); } }
From source file:com.googlecode.mipnp.mediaserver.cds.DidlLiteDocument.java
License:Open Source License
public void addCdsObject(CdsObject obj) { Element element = null;//from w ww . j a v a 2s. co m if (obj.isContainer()) { element = new Element("container", NS_DEFAULT); addProperty(element, obj, CdsConstants.PROPERTY_SEARCHABLE, "true"); } else { element = new Element("item", NS_DEFAULT); } for (String reqProp : REQUIRED_PROPERTIES) { addProperty(element, obj, reqProp); } // TODO: temp fix, res location should be added to CdsObject as a property Resource res = obj.getResource(); if (res != null && (filter.equals("*") || filter.contains("res"))) { Element resEl = new Element(CdsConstants.PROPERTY_RES, NS_DEFAULT); resEl.setAttribute("protocolInfo", "http-get:*:" + res.getMimeType() + ":*"); resEl.setText(mediaLocation.toString() + "/" + obj.getId()); element.addContent(resEl); } // END temp fix if (filter.equals("*")) { for (String property : obj.getProperties()) { if (!REQUIRED_PROPERTIES.contains(property)) { addProperty(element, obj, property); } } } else { String[] filterParts = filter.split("(?<!\\\\),"); for (int i = 0; i < filterParts.length; i++) { filterParts[i] = filterParts[i].replaceAll("\\\\,", ","); if (!REQUIRED_PROPERTIES.contains(filterParts[i])) { addProperty(element, obj, filterParts[i]); } } } document.getRootElement().addContent(element); }
From source file:com.googlecode.mipnp.mediaserver.cds.DidlLiteDocument.java
License:Open Source License
private void addProperty(Element element, CdsObject obj, String property, String propertyValue) { if (property.contains("@")) { Element parentElement = null; String strParentElement = property.substring(0, property.indexOf('@')); if (strParentElement.equals("")) { parentElement = element;/*from w w w . j a v a 2 s . c o m*/ } else { parentElement = element.getChild(removePrefix(strParentElement), getNamespace(strParentElement)); if (parentElement == null) { parentElement = new Element(removePrefix(strParentElement), getNamespace(strParentElement)); parentElement.setText(obj.getProperty(strParentElement)); element.addContent(parentElement); } } parentElement.setAttribute(property.substring(property.indexOf('@') + 1), propertyValue); } else { Element newElement = new Element(removePrefix(property), getNamespace(property)); newElement.setText(propertyValue); element.addContent(newElement); } }
From source file:com.iana.dver.pdf.scrapper.DVERScrapperTask.java
/** * Step - 2 : Generate XML from Text stripper * /*from w ww .j a va 2 s. c o 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
/** * show me where the money is/*w w w . j ava2 s.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.js.quickestquail.server.ViewAllMoviesHandler.java
private Element makeElement(String name, String val) { Element rootElement = new Element(name); rootElement.setText(val); return rootElement; }
From source file:com.js.quickestquail.server.ViewAllMoviesHandler.java
private Element makeElement(String name, String childName, String[] val) { Element rootElement = new Element(name); for (String v : val) { Element childElement = new Element(childName); childElement.setText(v); rootElement.addContent(childElement); }/* w w w.j a v a2 s. c om*/ return rootElement; }
From source file:com.khodev.oradiff.io.XmlSchemaWriter.java
License:Open Source License
private static Element getXml(String tagName, DBObject object) { Element element = new Element(tagName); element.setAttribute("name", object.getName()); if (object instanceof Constraint) { Constraint constraint = (Constraint) object; element.setAttribute("constraintType", constraint.getConstraintType()); element.setAttribute("deferrable", constraint.getDeferrable()); element.setAttribute("deferred", constraint.getDeferred()); element.setAttribute("deleteRule", constraint.getDeleteRule()); element.setAttribute("generated", constraint.getGenerated()); element.setAttribute("refConstraintName", constraint.getRefConstraintName()); element.setAttribute("refUserName", constraint.getRefUserName()); element.setAttribute("searchCondition", constraint.getSearchCondition()); element.setAttribute("status", constraint.getStatus()); element.setAttribute("validated", constraint.getValidated()); Element xmlColumns = new Element("columns"); for (IndexColumn column : constraint.getColumns()) xmlColumns.addContent(getXml("column", column)); element.addContent(xmlColumns);// ww w .j a v a 2s . co m } if (object instanceof TablespaceObject) { element.setAttribute("tablespace", ((TablespaceObject) object).getTablespace()); } if (object instanceof Source) { Source source = (Source) object; Element xmlBody = new Element("body"); String bodyStr = ""; for (String line : source.getBody()) bodyStr += line; xmlBody.setText(bodyStr); element.addContent(xmlBody); } if (object instanceof DBPackage) { DBPackage pkg = (DBPackage) object; Element xmlDeclaration = new Element("declaration"); String bodyStr = ""; for (String line : pkg.getDeclaration()) bodyStr += line; xmlDeclaration.setText(bodyStr); element.addContent(xmlDeclaration); } if (object instanceof Sequence) { Sequence sequence = (Sequence) object; element.setAttribute("cacheSize", Integer.toString(sequence.getCacheSize())); element.setAttribute("cycleFlag", Boolean.toString(sequence.isCycleFlag())); element.setAttribute("incrementBy", sequence.getIncrementBy()); element.setAttribute("lastNumber", sequence.getLastNumber()); element.setAttribute("maxValue", sequence.getMaxValue()); element.setAttribute("minValue", sequence.getMinValue()); element.setAttribute("orderFlag", Boolean.toString(sequence.isOrderFlag())); } if (object instanceof Table) { Table table = (Table) object; element.setAttribute("comments", table.getComments()); element.addContent(XmlSchemaWriter.convertToXml("columns", "column", table.getColumns())); element.addContent(XmlSchemaWriter.convertToXml("indexes", "index", table.getIndexes())); element.addContent(XmlSchemaWriter.convertToXml("constraints", "constraint", table.getConstraints())); element.addContent(XmlSchemaWriter.convertToXml("grants", "grant", table.getGrants())); element.addContent( XmlSchemaWriter.convertToXml("publicSynonyms", "publicSynonym", table.getPublicSynonyms())); return element; } if (object instanceof Trigger) { Trigger trigger = (Trigger) object; element.setAttribute("description", trigger.getDescription()); element.setAttribute("event", trigger.getEvent()); element.setAttribute("status", trigger.getStatus()); element.setAttribute("table", trigger.getTable()); element.setAttribute("type", trigger.getType()); element.addContent(new Element("when").setText(trigger.getWhen())); element.addContent(new Element("body").setText(trigger.getBody())); } if (object instanceof View) { View view = (View) object; Element xmlColumns = new Element("columns"); for (String column : view.getColumns()) xmlColumns.addContent(new Element("column").setAttribute("name", column)); element.addContent(xmlColumns); element.addContent(new Element("source").setText(view.getSource())); } if (object instanceof Column) { Column column = (Column) object; element.setAttribute("id", Integer.toString(column.getId())); element.setAttribute("type", column.getType()); element.setAttribute("length", Integer.toString(column.getLength())); element.setAttribute("precision", Integer.toString(column.getPrecision())); element.setAttribute("scale", Integer.toString(column.getScale())); element.setAttribute("nullable", Boolean.toString(column.isNullable())); element.setAttribute("comments", column.getComment()); element.setAttribute("defaultValue", column.getDefaultValue()); } if (object instanceof Index) { Index index = (Index) object; element.setAttribute("type", index.getType()); element.setAttribute("isUnique", Boolean.toString(index.isUnique())); element.setAttribute("compression", index.getCompression()); Element xmlColumns = new Element("columns"); for (IndexColumn column : index.getColumns()) xmlColumns.addContent(getXml("column", column)); element.addContent(xmlColumns); } if (object instanceof Grant) { Grant grant = (Grant) object; element.setAttribute("selectPriv", Boolean.toString(grant.isSelectPriv())); element.setAttribute("insertPriv", Boolean.toString(grant.isInsertPriv())); element.setAttribute("deletePriv", Boolean.toString(grant.isDeletePriv())); element.setAttribute("updatePriv", Boolean.toString(grant.isUpdatePriv())); element.setAttribute("referencesPriv", Boolean.toString(grant.isReferencesPriv())); element.setAttribute("alterPriv", Boolean.toString(grant.isAlterPriv())); element.setAttribute("indexPriv", Boolean.toString(grant.isIndexPriv())); } if (object instanceof IndexColumn) { IndexColumn indexColumn = (IndexColumn) object; element.setAttribute("position", Integer.toString(indexColumn.getPosition())); } return element; }