List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:org.apache.openmeetings.util.XmlExport.java
License:Apache License
public static Document createDocument() { Document document = DocumentHelper.createDocument(); document.setXMLEncoding(StandardCharsets.UTF_8.name()); document.addComment(XmlExport.FILE_COMMENT); return document; }
From source file:org.apache.poi.openxml4j.opc.internal.ContentTypeManager.java
License:Apache License
/** * Save the contents type part./*from ww w . j a v a2s .co m*/ * * @param outStream * The output stream use to save the XML content of the content * types part. * @return <b>true</b> if the operation success, else <b>false</b>. */ public boolean save(OutputStream outStream) { Document xmlOutDoc = DocumentHelper.createDocument(); // Building namespace Namespace dfNs = Namespace.get("", TYPES_NAMESPACE_URI); Element typesElem = xmlOutDoc.addElement(new QName(TYPES_TAG_NAME, dfNs)); // Adding default types for (Entry<String, String> entry : defaultContentType.entrySet()) { appendDefaultType(typesElem, entry); } // Adding specific types if any exist if (overrideContentType != null) { for (Entry<PackagePartName, String> entry : overrideContentType.entrySet()) { appendSpecificTypes(typesElem, entry); } } xmlOutDoc.normalize(); // Save content in the specified output stream return this.saveImpl(xmlOutDoc, outStream); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java
License:Apache License
/** * Marshall package core properties to an XML document. Always return * <code>true</code>.// www .ja va 2s . com */ public boolean marshall(PackagePart part, OutputStream out) throws OpenXML4JException { if (!(part instanceof PackagePropertiesPart)) throw new IllegalArgumentException("'part' must be a PackagePropertiesPart instance."); propsPart = (PackagePropertiesPart) part; // Configure the document xmlDoc = DocumentHelper.createDocument(); Element rootElem = xmlDoc.addElement(new QName("coreProperties", namespaceCoreProperties)); rootElem.addNamespace("cp", PackagePropertiesPart.NAMESPACE_CP_URI); rootElem.addNamespace("dc", PackagePropertiesPart.NAMESPACE_DC_URI); rootElem.addNamespace("dcterms", PackagePropertiesPart.NAMESPACE_DCTERMS_URI); rootElem.addNamespace("xsi", PackagePropertiesPart.NAMESPACE_XSI_URI); addCategory(); addContentStatus(); addContentType(); addCreated(); addCreator(); addDescription(); addIdentifier(); addKeywords(); addLanguage(); addLastModifiedBy(); addLastPrinted(); addModified(); addRevision(); addSubject(); addTitle(); addVersion(); return true; }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller.java
License:Apache License
/** * Save relationships into the part./* w ww . ja v a 2 s .com*/ * * @param rels * The relationships collection to marshall. * @param relPartName * Part name of the relationship part to marshall. * @param zos * Zip output stream in which to save the XML content of the * relationships serialization. */ public static boolean marshallRelationshipPart(PackageRelationshipCollection rels, PackagePartName relPartName, ZipOutputStream zos) { // Building xml Document xmlOutDoc = DocumentHelper.createDocument(); // make something like <Relationships // xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> Namespace dfNs = Namespace.get("", PackageNamespaces.RELATIONSHIPS); Element root = xmlOutDoc.addElement(new QName(PackageRelationship.RELATIONSHIPS_TAG_NAME, dfNs)); // <Relationship // TargetMode="External" // Id="rIdx" // Target="http://www.custom.com/images/pic1.jpg" // Type="http://www.custom.com/external-resource"/> URI sourcePartURI = PackagingURIHelper.getSourcePartUriFromRelationshipPartUri(relPartName.getURI()); for (PackageRelationship rel : rels) { // the relationship element Element relElem = root.addElement(PackageRelationship.RELATIONSHIP_TAG_NAME); // the relationship ID relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel.getId()); // the relationship Type relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel.getRelationshipType()); // the relationship Target String targetValue; URI uri = rel.getTargetURI(); if (rel.getTargetMode() == TargetMode.EXTERNAL) { // Save the target as-is - we don't need to validate it, // alter it etc targetValue = uri.toString(); // add TargetMode attribute (as it is external link external) relElem.addAttribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME, "External"); } else { URI targetURI = rel.getTargetURI(); targetValue = PackagingURIHelper.relativizeURI(sourcePartURI, targetURI, true).toString(); } relElem.addAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME, targetValue); } xmlOutDoc.normalize(); // String schemaFilename = Configuration.getPathForXmlSchema()+ // File.separator + "opc-relationships.xsd"; // Save part in zip ZipEntry ctEntry = new ZipEntry( ZipHelper.getZipURIFromOPCName(relPartName.getURI().toASCIIString()).getPath()); try { zos.putNextEntry(ctEntry); if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) { return false; } zos.closeEntry(); } catch (IOException e) { logger.log(POILogger.ERROR, "Cannot create zip entry " + relPartName, e); return false; } return true; // success }
From source file:org.apache.taglibs.xtags.servlet.XPathServlet.java
License:Apache License
protected Document createDocument(HttpServletRequest request) throws ServletException { Document document = DocumentHelper.createDocument(); Element element = document.addElement("results"); try {/*from w w w. j av a 2 s . co m*/ URL url = getDocumentURL(request); if (url != null) { String path = request.getParameter("path"); if (path != null && path.length() > 0) { Document source = reader.read(url); XPath xpath = source.createXPath(path); String contextPath = request.getParameter("contextPath"); if (contextPath == null) { contextPath = "."; } List context = source.selectNodes(contextPath); List results = null; if (!getBoolean(request, "sort")) { results = xpath.selectNodes(context); } else { String sortPath = request.getParameter("sortPath"); if (sortPath == null) { sortPath = "."; } boolean distinct = getBoolean(request, "distinct"); XPath sortXPath = source.createXPath(sortPath); results = xpath.selectNodes(context, sortXPath, distinct); } appendResults(element, results); } } } catch (DocumentException e) { e.printStackTrace(); throw new ServletException("Error parsing document: " + e, e); } return document; }
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;//w ww . j a v a 2 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.beangle.emsapp.security.action.MenuAction.java
License:Open Source License
public void exportXML() { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("root"); List<Menu> menus = (List<Menu>) entityDao.search(getQueryBuilder().limit(null)); for (Menu m : menus) { Element em = root.addElement("menu"); em.addAttribute("id", m.getId().toString()); em.addAttribute("code", m.getCode()); em.addAttribute("name", m.getName()); em.addAttribute("title", m.getTitle()); em.addAttribute("entry", m.getEntry()); em.addAttribute("remark", m.getRemark()); em.addAttribute("profileId", m.getProfile().getId().toString()); if (m.getParent() != null) { em.addAttribute("parentId", m.getParent().getId().toString()); }/*from w ww. ja va2 s . c o m*/ for (Resource res : m.getResources()) { Element eres = em.addElement("resource"); eres.addAttribute("id", res.getId().toString()); eres.addAttribute("name", res.getName()); eres.addAttribute("title", res.getTitle()); eres.addAttribute("remark", res.getRemark()); eres.addAttribute("scope", res.getScope() + ""); for (Category c : res.getCategories()) { Element ec = eres.addElement("category"); ec.addAttribute("id", c.getId().toString()); } } } try { HttpServletResponse response = ServletActionContext.getResponse(); response.setHeader("Content-Disposition", "attachment;filename=menu.xml"); response.setContentType("application/x-msdownload"); OutputFormat of = new OutputFormat(); of.setIndent(true); of.setNewlines(true); XMLWriter writer = new XMLWriter(getResponse().getOutputStream(), of); writer.write(doc); writer.close(); } catch (UnsupportedEncodingException e) { logger.error("exportXML error", e); } catch (IOException e) { logger.error("exportXML error", e); } }
From source file:org.bigmouth.nvwa.pay.service.prepay.wx.WxPrepayInsideRequest.java
License:Apache License
public String toXML() { Document doc = DocumentHelper.createDocument(); Element xml = doc.addElement("xml"); if (StringUtils.isNotBlank(getAppId())) xml.addElement("appid").setText(getAppId()); if (StringUtils.isNotBlank(getMchId())) xml.addElement("mch_id").setText(getMchId()); if (StringUtils.isNotBlank(getDeviceInfo())) xml.addElement("device_info").setText(getDeviceInfo()); if (StringUtils.isNotBlank(getNonceStr())) xml.addElement("nonce_str").setText(getNonceStr()); if (StringUtils.isNotBlank(getSign())) xml.addElement("sign").setText(getSign()); if (StringUtils.isNotBlank(getBody())) xml.addElement("body").setText(getBody()); if (StringUtils.isNotBlank(getDetail())) xml.addElement("detail").setText(getDetail()); if (StringUtils.isNotBlank(getAttach())) xml.addElement("attach").setText(getAttach()); if (StringUtils.isNotBlank(getOutTradeNo())) xml.addElement("out_trade_no").setText(getOutTradeNo()); if (null != getFeeType()) xml.addElement("fee_type").setText(getFeeType()); xml.addElement("total_fee").setText(String.valueOf(getTotalFee())); if (StringUtils.isNotBlank(getSpbillIp())) xml.addElement("spbill_create_ip").setText(getSpbillIp()); if (StringUtils.isNotBlank(getTimeStart())) xml.addElement("time_start").setText(getTimeStart()); if (StringUtils.isNotBlank(getTimeExpire())) xml.addElement("time_expire").setText(getTimeExpire()); if (StringUtils.isNotBlank(getGoodsTag())) xml.addElement("goods_tag").setText(getGoodsTag()); if (StringUtils.isNotBlank(getNotifyUrl())) xml.addElement("notify_url").setText(getNotifyUrl()); if (null != getTradeType()) xml.addElement("trade_type").setText(getTradeType()); if (StringUtils.isNotBlank(getProductId())) xml.addElement("product_id").setText(getProductId()); if (StringUtils.isNotBlank(getLimitPay())) xml.addElement("limit_pay").setText(getLimitPay()); if (StringUtils.isNotBlank(getOpenId())) xml.addElement("openid").setText(getOpenId()); return doc.asXML(); }
From source file:org.bigmouth.nvwa.utils.xml.Dom4jEncoder.java
License:Apache License
/** * ???XML<br>/*w w w . ja va2 s. c o m*/ * ?{@linkplain org.bigmouth.nvwa.utils.Argument}?? * * <pre> * e.g. * * List<Object> list = new ArrayList<Object>(); * * Object obj1 = new Object(); * obj1.setName("Allen"); * obj1.setOld(18); * obj1.setHomeAddr("Hangzhou"); * obj1.setCellphon_no("10086"); * * Object obj2 = new Object(); * obj2.setName("Lulu"); * obj2.setOld(16); * obj2.setHomeAddr("Hangzhou"); * obj2.setCellphon_no("10086-1"); * * list.add(obj1); * list.add(obj2); * * String xml = Dom4jEncoder.encode(list, "/class", "student"); * System.out.println(xml); * * ------------------------- * | XML Result: * ------------------------- * * <class> * <student> * <name>Allen</Name> * <old>18</old> * <home_addr>Hangzhou</home_addr> * <cellphone__no>10086</cellphone__no> * </student> * <student> * <name>Lulu</Name> * <old>16</old> * <home_addr>Hangzhou</home_addr> * <cellphone__no>10086-1</cellphone__no> * </student> * </class> * * </pre> * * @param <T> * @param objs ??? * @param xpath * @param itemNodeName ?? * @return * @see org.bigmouth.nvwa.utils.Argument */ public static <T> String encode(List<T> objs, String xpath, String itemNodeName) { if (CollectionUtils.isEmpty(objs)) return null; if (StringUtils.isBlank(xpath) || StringUtils.equals(xpath, "/")) { throw new IllegalArgumentException("xpath cannot be blank or '/'!"); } Document doc = DocumentHelper.createDocument(); Element root = null; if (StringUtils.split(xpath, "/").length > 2) { root = DocumentHelper.makeElement(doc, xpath); } else { xpath = StringUtils.removeStart(xpath, "/"); root = doc.addElement(xpath); } for (Object obj : objs) { addElement(itemNodeName, root, obj); } return doc.asXML(); }
From source file:org.cipango.littleims.scscf.charging.CDF.java
License:Apache License
public String start(SipServletRequest event, int role) { log.debug("Start Session CDR"); Document document = DocumentHelper.createDocument(); Element root = document.addElement("ims-cdr"); root.addElement("sip-method").setText(event.getMethod()); root.addElement("role-of-node").setText(String.valueOf(role)); root.addElement("session-id").setText(event.getCallId()); root.addElement("calling-party-address").setText(event.getFrom().getURI().toString()); root.addElement("called-party-address").setText(event.getTo().getURI().toString()); root.addElement("serviceDeliveryStartTimeStamp").setText(getDate()); String cdrID = idGenerator.newRandomID(); cdrs.put(cdrID, document);//from w w w .ja v a 2 s .c o m return cdrID; }