List of usage examples for org.dom4j Element addText
Element addText(String text);
Text
node with the given text to this element. From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Add title property if needed./*from w ww .j ava2 s .c o m*/ */ private void addTitle() { if (!propsPart.getTitleProperty().hasValue()) return; Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_TITLE, namespaceDC)); if (elem == null) { // missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_TITLE, namespaceDC)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getTitleProperty().getValue()); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
private void addVersion() { if (!propsPart.getVersionProperty().hasValue()) return;/*from w w w . j av a 2 s . co m*/ Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_VERSION, namespaceCoreProperties)); if (elem == null) { // missing, we add it elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_VERSION, namespaceCoreProperties)); } else { elem.clearContent();// clear the old value } elem.addText(propsPart.getVersionProperty().getValue()); }
From source file:org.apache.taglibs.xtags.servlet.XPathServlet.java
License:Apache License
protected void appendResults(Element element, List results) { for (int i = 0, size = results.size(); i < size; i++) { Object result = results.get(i); if (result instanceof String) { element.addText((String) result); } else if (result instanceof Node) { Node node = (Node) result; node.detach();/*from www .j av a2 s. c o m*/ element.add(node); } else if (result != null) { element.addText(result.toString()); } } }
From source file:org.arangitester.log.XmlResult.java
License:Apache License
public void save(File file, FunctionalSuite result) { // file indicates a pathname Document document = DocumentHelper.createDocument(); // create a new xml document Element root = document.addElement("LccFunctionalSuite"); // create the root tag named LccFunctionalSuite if (result == null) return;// www.jav a2 s .co m SummaryHelper summary = new SummaryHelper(result); root.addAttribute("totalTime", String.valueOf(summary.getTotalTime())); System.out.println("Tempo de Execuo: " + summary.getTotalTime() + " min"); root.addAttribute("total", String.valueOf(summary.getTotal())); System.out.println("Total: " + summary.getTotal()); root.addAttribute("skip", String.valueOf(summary.getSkip())); System.out.println("Skiped: " + summary.getSkip()); root.addAttribute("fail", String.valueOf(summary.getFail())); System.out.println("Fail: " + summary.getFail()); root.addAttribute("successful", String.valueOf(summary.getSuccessful())); System.out.println("Successful: " + summary.getSuccessful()); root.addAttribute("percent", String.valueOf(summary.getPercent())); System.out.println("Sucessful: " + summary.getPercent() + "%"); for (UseCase usecase : result.getCases()) { Element userCaseElement = root.addElement("UseCase").addAttribute("name", usecase.getName()) .addAttribute("startTime", getFormatedDate((usecase.getStartTime()))) .addAttribute("endTime", getFormatedDate(usecase.getEndTime())); for (String obs : usecase.getObs()) { Element obsElement = userCaseElement.addElement("Obs"); obsElement.addText(obs); } for (Object log : usecase.getlogs()) { if (log instanceof Info) { userCaseElement.addElement("info").addText(((Info) log).getMessage()); } else { Error error = ((Error) log); Element errorElement = userCaseElement.addElement("error").addAttribute("cause", error.getCause()); if (error.getScreenshot() != null) errorElement.addAttribute("screenshot", error.getScreenshot()); if (error.getError() != null) errorElement.addText(error.getError()); } } for (TestCase testcase : usecase.getTestcases()) { Element testCaseElement = userCaseElement.addElement("TestCase") .addAttribute("name", testcase.getJavaMethod()) .addAttribute("description", testcase.getTestcase()) .addAttribute("startTime", getFormatedDate(testcase.getStartTime())) .addAttribute("endTime", getFormatedDate(testcase.getEndTime())) .addAttribute("skip", String.valueOf(testcase.isSkip())); for (Object log : testcase.getlogs()) { if (log instanceof Info) { testCaseElement.addElement("info").addText(((Info) log).getMessage()); } else { Error error = ((Error) log); Element errorElement = testCaseElement.addElement("error").addAttribute("cause", error.getCause()); if (error.getScreenshot() != null) errorElement.addAttribute("screenshot", error.getScreenshot()); if (error.getError() != null) errorElement.addText(error.getError()); } } } } // End of the document building // Now, we will start to write in document try { file.getParentFile().mkdirs(); file.createNewFile(); OutputFormat outformat = OutputFormat.createPrettyPrint(); XMLWriter write = new XMLWriter(new FileWriter(file), outformat); // Initialize the xml file write.write(document); // Write the final document on xml file write.close(); } catch (IOException e) { System.out.println("Erro durante a gravao no arquivo " + file + " :\n" + e.toString()); } }
From source file:org.collectionspace.chain.csp.persistence.services.GenericStorage.java
License:Educational Community License
protected static Element createRelationship(Relationship rel, Object data, String csid, String subjtype, String metaType, Boolean reverseIt, Spec spec) throws ExistException, UnderlyingStorageException, JSONException { Document doc = DocumentFactory.getInstance().createDocument(); Element subroot = doc.addElement("relation-list-item"); Element predicate = subroot.addElement("predicate"); predicate.addText(rel.getPredicate()); Element relMetaType = subroot.addElement("relationshipMetaType"); relMetaType.addText(metaType);/* www .java2s. c o m*/ String subjectName = "subject"; String objectName = "object"; if (reverseIt) { subjectName = "object"; objectName = "subject"; } Element subject = subroot.addElement(subjectName); Element subjcsid = subject.addElement("csid"); if (csid != null) { subjcsid.addText(csid); } else { subjcsid.addText("${itemCSID}"); } //find out record type from urn String refName = (String) data; Element object = subroot.addElement(objectName); // We may or may not be dealing with a sub-resource like AuthItems. // TODO - this may all be unneccessary, as the services should fill in // doc types, etc. now automatically. // OTOH, not a bad idea to validate the refName... RefName.AuthorityItem itemParsed = RefName.AuthorityItem.parse(refName); if (itemParsed != null) { String serviceurl = itemParsed.inAuthority.resource; Record myr = spec.getRecordByServicesUrl(serviceurl); if (myr.isType("authority")) { Element objRefName = object.addElement("refName"); objRefName.addText(refName); } else { throw new JSONException( "Relation object refName is for sub-resources other than authority item - NYI!"); } } else { RefName.Authority resourceParsed = RefName.Authority.parse(refName); if (resourceParsed != null) { Element objRefName = object.addElement("refName"); objRefName.addText(refName); } else { throw new JSONException("Relation object refName does not appear to be valid!"); } } //log.info(subroot.asXML()); return subroot; }
From source file:org.collectionspace.chain.csp.persistence.services.vocab.ConfiguredVocabStorage.java
License:Educational Community License
private Document createEntry(String section, String namespace, String root_tag, JSONObject data, String vocab, String refname, Record r, Boolean isAuth) throws UnderlyingStorageException, ConnectionException, ExistException, JSONException { Document out = XmlJsonConversion.convertToXml(r, data, section, "POST", isAuth); if (section.equals("common")) {//XXX not great... but not sure how else to differentiate if (out != null) { Element root = out.getRootElement(); Element vocabtag = root.addElement("inAuthority"); if (vocab != null) { vocabtag.addText(vocab); }//from w w w . ja v a 2 s . co m if (refname != null) { // CSPACE-4460 // Element refnametag=root.addElement("refName"); // refnametag.addText(refname); } if (r.isType("compute-displayname")) { Element dnc = root.addElement("displayNameComputed"); dnc.addText("false"); } //log.info("create Configured Vocab Entry"+out.asXML()); } } return out; }
From source file:org.collectionspace.chain.csp.persistence.services.vocab.VocabInstanceCache.java
License:Educational Community License
private Document createList(String namespace, String tag, String id, String vocab_type) throws ExistException { Document out = DocumentFactory.getInstance().createDocument(); String[] path = tag.split("/"); Element root = out.addElement("ns2:" + path[0], namespace); for (int i = 1; i < path.length; i++) { root = root.addElement(path[i]); }//from www . j a v a 2s.c om Element nametag = root.addElement("displayName"); nametag.addText(vocabByShortIdentifier(id)); Element sidtag = root.addElement("shortIdentifier"); sidtag.addText(id); Element vocabtag = root.addElement("vocabType"); vocabtag.addText(vocab_type); // log.info(out.asXML()); return out; }
From source file:org.collectionspace.chain.csp.persistence.services.XmlJsonConversion.java
License:Educational Community License
private static void addFieldToXml(Element root, Field field, JSONObject in, String permlevel) throws JSONException, UnderlyingStorageException { if (field.isServicesReadOnly()) { // Omit fields that are read-only in the services layer. log.debug("Omitting services-readonly field: " + field.getID()); return;// w w w. j a v a2 s . c o m } Element element = root; if (field.getUIType().startsWith("groupfield") && field.getUIType().contains("selfrenderer")) { //ignore the top level if this is a self renderer as the UI needs it but the services doesn't } else { element = root.addElement(field.getServicesTag()); } String value = in.optString(field.getID()); if (field.getUIType().startsWith("groupfield")) { if (field.getUIType().contains("selfrenderer")) { addSubRecordToXml(element, field, in, permlevel); } else { if (in.has(field.getID())) { addSubRecordToXml(element, field, in.getJSONObject(field.getID()), permlevel); } } } else if (field.getDataType().equals("boolean")) { // Rather than dump what we have coming in, first convert to proper boolean and back. // Properly handles null, in particular. boolean bool = Boolean.parseBoolean(value); element.addText(Boolean.toString(bool)); } else { element.addText(value); } }
From source file:org.collectionspace.chain.csp.persistence.services.XmlJsonConversion.java
License:Educational Community License
public static Document convertToXml(Record r, JSONObject in, String section, String permtype, Boolean useInstance) throws JSONException, UnderlyingStorageException { if (!useInstance) { return convertToXml(r, in, section, permtype); }/* w w w. jav a2 s.c om*/ Document doc = DocumentFactory.getInstance().createDocument(); String[] parts = r.getServicesRecordPath(section).split(":", 2); if (useInstance) { parts = r.getServicesInstancesPath(section).split(":", 2); } String[] rootel = parts[1].split(","); Element root = doc.addElement(new QName(rootel[1], new Namespace("ns2", rootel[0]))); Element element = root.addElement("displayName"); element.addText(in.getString("displayName")); Element element2 = root.addElement("shortIdentifier"); element2.addText(in.getString("shortIdentifier")); if (in.has("vocabType")) { Element element3 = root.addElement("vocabType"); element3.addText(in.getString("vocabType")); } return doc; //yes I know hardcode is bad - but I need this out of the door today /* <ns2:personauthorities_common xmlns:ns2="http://collectionspace.org/services/person"> <displayName>PAHMA Person Authority</displayName> <vocabType>PersonAuthority</vocabType> <shortIdentifier>pamha</shortIdentifier> </ns2:personauthorities_common> */ }
From source file:org.collectionspace.services.id.IDResource.java
License:Educational Community License
/** * Appends a display name to an element representing * an ID generator instance./*from ww w . j av a2 s . com*/ * * @param instanceElement An XML element representing an * ID generator instance. * * @param displayname A displayname for the resource representing that instance. * * @return The XML element representing an ID generator instance, * with the display name appended. */ private Element appendDisplayNameIDGeneratorInformation(Element instanceElement, String displaynameValue) { Element displayname = instanceElement.addElement("displayname"); displayname.addText(displaynameValue); return instanceElement; }