List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:com.liferay.portal.xml.SAXReaderImpl.java
License:Open Source License
public Document createDocument() { return new DocumentImpl(DocumentHelper.createDocument()); }
From source file:com.littcore.license.LicenseManager.java
/** * ??./*from ww w .j a v a 2 s . c om*/ * * @param license the license * @param targetFile */ public static void writeLicense(License license, File targetFile) throws IOException { Document document = DocumentHelper.createDocument(); document.addElement("license"); Element root = document.getRootElement(); // root.addElement("licenseId").setText(license.getLicenseId()); root.addElement("licenseType").setText(license.getLicenseType()); root.addElement("productName").setText(license.getProductName()); root.addElement("companyName").setText(license.getCompanyName()); root.addElement("customerName").setText(license.getCustomerName()); root.addElement("version").setText(license.getVersion().toString()); root.addElement("createDate").setText(FormatDateTime.formatDate(license.getCreateDate())); root.addElement("expiredDate").setText(FormatDateTime.formatDate(license.getExpiredDate())); root.addElement("signature").setText(license.getSignature()); XmlUtils.writeXml(targetFile, document); }
From source file:com.liveneo.plat.web.action.MakeLicfile.java
public static Document initLicFile(LicForm licForm) { Document doc = DocumentHelper.createDocument(); Element corporationEle = doc.addElement("Liveneo"); corporationEle.addAttribute("platformType", licForm.getPlatformType()); corporationEle.addAttribute("sid", licForm.getSid()); corporationEle.addAttribute("version", licForm.getF_version()); Element licElement = corporationEle.addElement("License"); licElement.addAttribute("genDate", licForm.getGenDate()); licElement.addAttribute("genTime", licForm.getGenTime()); licElement.addAttribute("type", licForm.getType()); licElement.addAttribute("version", licForm.getLic_version()); Element hostidEle = licElement.addElement("HostID"); hostidEle.setText(licForm.getHostID()); Element notesEle = licElement.addElement("Notes"); notesEle.setText(licForm.getNotes()); Element productEle = licElement.addElement("Product"); Element pdNameEle = productEle.addElement("Name"); Element pdDispEle = productEle.addElement("DisplayName"); Element pdVersion = productEle.addElement("Version"); pdNameEle.setText(licForm.getProductName()); pdDispEle.setText(licForm.getProductDisplayName()); pdVersion.setText(licForm.getProductVersion()); Element featuresEle = licElement.addElement("Features"); if (null != licForm.getFeatureList()) { for (FeatureForm ff : licForm.getFeatureList()) { Element feaEle = featuresEle.addElement("Feature"); feaEle.addAttribute("name", ff.getFeatureName()); Element disnameEle = feaEle.addElement("DisplayName"); disnameEle.setText(ff.getFeatureDisplayName()); Element fvalueEle = feaEle.addElement("Value"); fvalueEle.setText(ff.getFeatureValue()); Element fexpEle = feaEle.addElement("ExpirationDate"); fexpEle.setText(ff.getFeatureExpDate()); }//from w w w .j a v a 2s . co m } Element signElement = corporationEle.addElement("Signature"); signElement.setText(licForm.getSignature()); return doc; }
From source file:com.love320.templateparser.templateprocess.impl.SeparationImpl.java
License:Apache License
@Override public String getXML(String str) { Document document = DocumentHelper.createDocument();//?xml Element rootElement = document.addElement("root");// root rootElement.addElement("site").setText("www.love320.com");//? Element contentElement = rootElement.addElement("content");//?? for (String singStr : str.split("\r\n")) {//????? tagStrRow(singStr, contentElement);//??? addContent("/r/n", 3, contentElement);//? -- /r/n }//from w w w.ja v a2 s . co m return document.asXML();//xml }
From source file:com.ltmonitor.jt809.app.GlobalConfig.java
public static void setModel(ParameterModel pm) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("config"); doc.setRootElement(root);/* w w w . j a va2 s . c o m*/ Element pe = root.addElement("parameter"); pe.addAttribute("platip", pm.getPlatformIP()); pe.addAttribute("idletime", String.valueOf(pm.getIdleTime())); pe.addAttribute("localport", String.valueOf(pm.getLocalPort())); pe.addAttribute("platid", String.valueOf(pm.getPlatformCenterId())); pe.addAttribute("platport", String.valueOf(pm.getPlatformPort())); pe.addAttribute("platuserid", String.valueOf(pm.getPlatformUserName())); pe.addAttribute("platpassword", String.valueOf(pm.getPlatformPass())); pe.addAttribute("miyaom", String.valueOf(pm.getMiyaoM())); pe.addAttribute("miyaoa", String.valueOf(pm.getMiyaoA())); pe.addAttribute("miyaoc", String.valueOf(pm.getMiyaoC())); pe.addAttribute("protocolver", pm.getProtocolVer()); pe.addAttribute("localip", pm.getLocalIp()); pe.addAttribute("licenseno", pm.getLicenseNo()); pe.addAttribute("username", pm.getUsername()); try { FileWriter out = new FileWriter(CONFIG_PATH + "database.xml"); XmlUtils.printXml(doc, out); } catch (Exception ex) { //this.logger.warn("" + ex.getMessage()); } }
From source file:com.magicpwd._util.Jxml.java
License:Open Source License
public static Document create() { Document doc = DocumentHelper.createDocument(); // ProcessingInstruction // Map<String, String> pi = new HashMap<String, String>(); // pi.put("type", "text/xsl"); // pi.put("href", "http://amon.me/mpwd/MagicPwd.xsl"); // document.addProcessingInstruction("xml-stylesheet", pi); return doc;/* w w w. j ava 2s . c o m*/ }
From source file:com.mindquarry.desktop.model.task.Task.java
License:Open Source License
public Document getContentAsXML() { Document doc = DocumentHelper.createDocument(); Element task = doc.addElement("task"); //$NON-NLS-1$ Element title = task.addElement("title"); //$NON-NLS-1$ title.setText(getTitle());//from ww w . ja v a2 s .c o m if ((getPriority() != null) && (!getPriority().equals(""))) { //$NON-NLS-1$ Element priority = task.addElement("priority"); //$NON-NLS-1$ priority.setText(getPriority()); } if ((getSummary() != null) && (!getSummary().equals(""))) { //$NON-NLS-1$ Element summary = task.addElement("summary"); //$NON-NLS-1$ summary.setText(getSummary()); } if ((getStatus() != null) && (!getStatus().equals(""))) { //$NON-NLS-1$ Element status = task.addElement("status"); //$NON-NLS-1$ status.setText(getStatus()); } if ((getDate() != null) && (!getDate().equals(""))) { //$NON-NLS-1$ Element date = task.addElement("date"); //$NON-NLS-1$ date.setText(getDate()); } if ((getDescription() != null) && (!getDescription().equals(""))) { //$NON-NLS-1$ Element description = task.addElement("description"); //$NON-NLS-1$ description.setText(getDescription()); } if ((getTargetTime() != null) && (!getTargetTime().equals(""))) { //$NON-NLS-1$ Element description = task.addElement("targettime"); //$NON-NLS-1$ description.setText(getTargetTime()); } if ((getActualTime() != null) && (!getActualTime().equals(""))) { //$NON-NLS-1$ Element description = task.addElement("actualtime"); //$NON-NLS-1$ description.setText(getActualTime()); } if (people.size() > 0) { int count = 0; Element peopleEl = task.addElement("people"); //$NON-NLS-1$ for (Person person : people) { Element itemEl = peopleEl.addElement("item"); //$NON-NLS-1$ itemEl.addAttribute("position", String.valueOf(count)); //$NON-NLS-1$ Element personEl = itemEl.addElement("person"); //$NON-NLS-1$ personEl.addText(person.pid); Element roleEl = itemEl.addElement("role"); //$NON-NLS-1$ roleEl.addText(person.role); count++; } } if (dependencies.size() > 0) { int count = 0; Element dependenciesEl = task.addElement("dependencies"); //$NON-NLS-1$ for (Dependency dependency : dependencies) { Element itemEl = dependenciesEl.addElement("item"); //$NON-NLS-1$ itemEl.addAttribute("position", String.valueOf(count)); //$NON-NLS-1$ Element taskEl = itemEl.addElement("task"); //$NON-NLS-1$ taskEl.addText(dependency.tid); Element roleEl = itemEl.addElement("role"); //$NON-NLS-1$ roleEl.addText(dependency.role); count++; } } return doc; }
From source file:com.nokia.helium.internaldata.ant.listener.XMLRenderer.java
License:Open Source License
/** * Rendering the build node into XML string. */// www .j a va 2 s . c o m public String toString() { // Creating the XML document Document document = DocumentHelper.createDocument(); Element statistics = document.addElement("statistics"); statistics.addAttribute("version", "1.1"); // Creating the document content. insertDatabase(statistics); createTargets(statistics); createAsserts(statistics); createExecutionTree(statistics); createProperties(statistics); try { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLWriter out = new XMLWriter(output, OutputFormat.createPrettyPrint()); out.write(document); return output.toString(); } catch (UnsupportedEncodingException exc) { return document.asXML(); } catch (IOException exc) { return document.asXML(); } }
From source file:com.noterik.bart.fs.action.GenericIndexAction.java
License:Open Source License
/** * Create XML for an index/* w w w. ja va 2 s.c o m*/ * * @param objectUri * @param objectDetails * @param collectionDetails * @param iConfig */ private static void makeTypeFromObject(String objectUri, Map<String, Object> objectDetails, Map<String, Object> collectionDetails, IndexConfig iConfig) { Document typeDocument = DocumentHelper.createDocument(); Element fsxml = typeDocument.addElement("fsxml"); Element type = fsxml.addElement(iConfig.getIndexType()); String objectType = iConfig.getIndexObject(); // add refer to original object Element referObject = type.addElement(objectType); referObject.addAttribute("id", "1"); referObject.addAttribute("referid", objectUri); //add refer to original collection, remove trailing slash, otherwise refer cannot be found! Element referCollectionObject = type.addElement("collection" + objectType); referCollectionObject.addAttribute("id", "1"); String collectionObject = (String) collectionDetails.get("object"); collectionObject = collectionObject.substring(0, collectionObject.length() - 1); referCollectionObject.addAttribute("referid", collectionObject); Element properties = type.addElement("properties"); //add standard properties properties.addElement(objectType).addText((String) collectionDetails.get("object")); properties.addElement(objectType + "uri").addText(objectUri + "/"); properties.addElement(objectType + "title").addText((String) objectDetails.get(objectType + "title")); properties.addElement(objectType + "description") .addText((String) objectDetails.get(objectType + "description")); properties.addElement(objectType + "screenshot") .addText((String) objectDetails.get(objectType + "screenshot")); //properties.addElement(objectType+"type").addText((String) objectDetails.get(objectType+"type")); //properties.addElement(objectType+"author").addText((String) objectDetails.get(objectType+"author")); //properties.addElement(objectType+"copyright").addText((String) objectDetails.get(objectType+"copyright")); //properties.addElement(objectType+"website").addText((String) objectDetails.get(objectType+"website")); properties.addElement("collection").addText((String) collectionDetails.get("collection")); //add user configured properties Map<String, String> items = iConfig.getProperties(); for (String item : items.keySet()) { if (item.equals("collectiontitle") || item.equals("collectiondescription") || item.equals("collectionstatus")) { properties.addElement(item).addText((String) collectionDetails.get(item)); } else if (item.equals("lockmode") || item.equals("date_created") || item.equals(objectType + "duration") || item.equals(objectType + "theme") || item.equals(objectType + "location") || item.equals(objectType + "date") || item.equals(objectType + "date_original") || item.equals(objectType + "public") || item.equals("sponsor")) { properties.addElement(item).addText((String) objectDetails.get(item)); } else if (item.equals("title") || item.equals("name")) { properties.addElement(item).addText((String) objectDetails.get(objectType + "title")); } else if (item.equals("description")) { properties.addElement(item).addText((String) objectDetails.get(objectType + "description")); } else if (item.equals("screenshot")) { properties.addElement(item).addText((String) objectDetails.get(objectType + "screenshot")); } else if (item.equals("rank")) { properties.addElement(item).addText("5"); } else if (item.equals("peercomments")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "peercomments", 0.0, 86400000.0, new String[] { "comment" })); } else if (item.equals("bookmark")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "bookmark", 0.0, 86400000.0, new String[] { "title", "description", "creator" })); } else if (item.equals("webtv_item_id") || item.equals(objectType + "livestate")) { properties.addElement(item).addText((String) objectDetails.get(item)); } else if (item.equals(objectType + "status") || item.equals(objectType + "theme") || item.equals(objectType + "time")) { properties.addElement(item).addText((String) objectDetails.get(item)); } } long timestamp = new Date().getTime(); type.addAttribute("id", String.valueOf(timestamp)); // Add directly to fs so maggie get's updated with first content faster FSXMLRequestHandler.instance().saveFsXml(iConfig.getIndexUri(), typeDocument.asXML(), "PUT", true); }
From source file:com.noterik.bart.fs.action.GenericIndexAction.java
License:Open Source License
/** * Create XML for an index/*from w ww . jav a 2 s. co m*/ * * @param typeContent * @param objectUri * @param objectDetails * @param collectionDetails * @param iConfig */ private static void makeType(Element typeContent, String objectUri, Map<String, Object> objectDetails, Map<String, Object> collectionDetails, IndexConfig iConfig) { // create new type Document typeDocument = DocumentHelper.createDocument(); Element fsxml = typeDocument.addElement("fsxml"); Element type = fsxml.addElement(iConfig.getIndexType()); String objectType = iConfig.getIndexObject(); // add refer to original object Element referObject = type.addElement(objectType); referObject.addAttribute("id", "1"); referObject.addAttribute("referid", objectUri); // add refer to original collection Element referCollectionObject = type.addElement("collection" + objectType); referCollectionObject.addAttribute("id", "1"); String collectionObject = (String) collectionDetails.get("object"); collectionObject = collectionObject.substring(0, collectionObject.length() - 1); referCollectionObject.addAttribute("referid", (String) collectionObject); Element properties = type.addElement("properties"); //add standard properties properties.addElement(objectType).addText((String) collectionDetails.get("object")); properties.addElement(objectType + "uri").addText(objectUri + "/"); properties.addElement("collection").addText((String) collectionDetails.get("collection")); properties.addElement(objectType + "title").addText((String) objectDetails.get(objectType + "title")); properties.addElement(objectType + "description") .addText((String) objectDetails.get(objectType + "description")); properties.addElement(objectType + "screenshot") .addText((String) objectDetails.get(objectType + "screenshot")); //properties.addElement(objectType+"type").addText((String) objectDetails.get(objectType+"type")); //properties.addElement(objectType+"author").addText((String) objectDetails.get(objectType+"author")); //properties.addElement(objectType+"copyright").addText((String) objectDetails.get(objectType+"copyright")); //properties.addElement(objectType+"website").addText((String) objectDetails.get(objectType+"website")); //add user configured properties Map<String, String> items = iConfig.getProperties(); Element typeProperties = typeContent.element("properties"); double start = typeProperties.elementText("starttime") == null ? 0.0 : Double.parseDouble(typeProperties.elementText("starttime")); double duration = typeProperties.elementText("duration") == null ? 0.0 : Double.parseDouble(typeProperties.elementText("duration")); if (duration == 0.0) { duration = typeProperties.elementText("length") == null ? 0.0 : Double.parseDouble(typeProperties.elementText("length")); } for (String item : items.keySet()) { if (item.equals("collectiontitle") || item.equals("collectiondescription") || item.equals("collectionstatus")) { properties.addElement(item).addText((String) collectionDetails.get(item)); } else if (item.equals("lockmode") || item.equals("link") || item.equals("date_created") || item.equals(objectType + "duration") || item.equals(objectType + "theme") || item.equals(objectType + "location") || item.equals(objectType + "date") || item.equals(objectType + "date_original") || item.equals(objectType + "public") || item.equals("sponsor")) { properties.addElement(item).addText((String) objectDetails.get(item)); } else if (item.equals("title") || item.equals("description") || item.equals("name")) { String value = typeProperties.elementText(item) == null ? "" : typeProperties.elementText(item); properties.addElement(item).addText(value); } else if (item.equals("firstnamelastname")) { String firstname = typeProperties.elementText("firstname") == null ? "" : typeProperties.elementText("firstname"); String lastname = typeProperties.elementText("lastname") == null ? "" : typeProperties.elementText("lastname"); properties.addElement("name").addText(firstname + " " + lastname); } else if (item.equals("screenshot")) { //former chapterscreenshot properties.addElement(item).addText(getTypeScreenshot((Document) objectDetails.get(objectType), start, (String) objectDetails.get(objectType + "screenshot"))); } else if (item.equals("rank")) { properties.addElement(item) .addText(String.valueOf(getRankBasedOnLockmode((String) objectDetails.get("lockmode")))); } else if (item.equals("start")) { properties.addElement(item).addText(String.format(Locale.US, "%f", start)); } else if (item.equals("duration")) { properties.addElement(item).addText(String.format(Locale.US, "%f", duration)); } else if (item.equals("locations")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "location", start, duration, new String[] { "name" })); } else if (item.equals("dates")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "date", start, duration, new String[] { "start", "end" })); } else if (item.equals("keywords")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "keyword", start, duration, new String[] { "name" })); } else if (item.equals("persons")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "person", start, duration, new String[] { "name" })); } else if (item.equals("periods")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "period", start, duration, new String[] { "name" })); } else if (item.equals("speakers")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "speakers", start, duration, new String[] { "firstname", "lastname", "organization" })); } else if (item.equals("topics")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "topics", start, duration, new String[] { "name" })); } else if (item.equals("peercomments")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "peercomments", 0.0, 86400000.0, new String[] { "comment" })); } else if (item.equals("voiceindex")) { String voiceindex = typeProperties.elementText("voiceindex") == null ? "" : typeProperties.elementText("voiceindex"); properties.addElement(item).addText(voiceindex); } else if (item.equals(objectType + iConfig.getIndexType())) { properties.addElement(item).addText(getTypeUri(typeContent, objectUri, iConfig)); } else if (item.equals("bookmark")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "bookmark", 0.0, 86400000.0, new String[] { "title", "description", "creator" })); } else if (item.equals("webtv_item_id") || item.equals(objectType + "livestate")) { properties.addElement(item).addText((String) objectDetails.get(item)); } else if (item.equals(objectType + "status") || item.equals(objectType + "theme") || item.equals(objectType + "time") || item.equals(objectType + "type")) { properties.addElement(item).addText((String) objectDetails.get(item)); } } long timestamp = new Date().getTime(); type.addAttribute("id", String.valueOf(timestamp)); // Add directly to fs so maggie get's updated with first content faster FSXMLRequestHandler.instance().saveFsXml(iConfig.getIndexUri(), typeDocument.asXML(), "PUT", true); }