List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:com.userweave.domain.util.xml.InvoiceCreator.java
License:Open Source License
/** * Create XML Representation of Invoice of given Study * @param study/* ww w .ja v a 2s. c o m*/ * @return */ public String toXML(Study study) { DecimalFormat df_us = (DecimalFormat) DecimalFormat.getInstance(Locale.US); df_us.applyPattern("#0.00"); DecimalFormat df_de = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN); df_de.applyPattern("#0.00"); Document document = DocumentHelper.createDocument(); Element invoice = document.addElement("invoice"); Element receipient = invoice.addElement("receipient"); Element details = invoice.addElement("details"); if (study.getOwner().getCompany() != null) { receipient.addElement("company").addText(study.getOwner().getCompany()); } else { receipient.addElement("company").addText(""); } receipient.addElement("surname").addText(study.getOwner().getSurname()); receipient.addElement("forename").addText(study.getOwner().getForename()); Element address = receipient.addElement("address"); if (study.getOwner().getAddress() != null) { address.addElement("street").addText(study.getOwner().getAddress().getStreet()); address.addElement("housenumber").addText(study.getOwner().getAddress().getHouseNumber()); address.addElement("postcode").addText(study.getOwner().getAddress().getPostcode()); address.addElement("city").addText(study.getOwner().getAddress().getCity()); address.addElement("country").addText(study.getOwner().getAddress().getCountry().getName()); } details.addElement("number").addText(study.getConsideration().getInvoice().getNumber()); DateTime invoiceDate = study.getConsideration().getDate(); DateTimeFormatter dateDTF = DateTimeFormat.longDate(); DateTimeFormatter usFmt = dateDTF.withLocale(Locale.US); String dateString = invoiceDate.toString(usFmt); if (evaluateReceipient(study) == Receipient.GERMAN_ALL) { DateTimeFormatter deFmt = dateDTF.withLocale(Locale.GERMAN); dateString = invoiceDate.toString(deFmt); } details.addElement("date").addText(dateString); details.addElement("currency").addText(study.getConsideration().getCurrency().getCurrencyCode()); Double gross = study.getConsideration().getGrossAmount(); if (study.getConsideration().getGrossAmount() != null) { String grossString = df_us.format(study.getConsideration().getGrossAmount()); if (evaluateReceipient(study) == Receipient.GERMAN_ALL) { grossString = df_de.format(study.getConsideration().getGrossAmount()); } details.addElement("gross").addText(grossString); } else { details.addElement("gross").addText(new Integer(0).toString()); } if (study.getConsideration().getInvoice().getPurchaseTaxPercent() != null && study.getConsideration().getInvoice().getPurchaseTaxPercent() > 0d) { String netString = df_us.format(study.getConsideration().getInvoice().getNetAmount()); if (evaluateReceipient(study) == Receipient.GERMAN_ALL) { netString = df_de.format(study.getConsideration().getInvoice().getNetAmount()); } details.addElement("net").addText(netString); Double tax = new Double(study.getConsideration().getGrossAmount() - study.getConsideration().getInvoice().getNetAmount()); tax = Math.round(tax * 100.) / 100.; String taxString = df_us.format(tax); if (evaluateReceipient(study) == Receipient.GERMAN_ALL) { netString = df_de.format(tax); } details.addElement("tax").addText(taxString); String taxRateString = df_us.format(study.getConsideration().getInvoice().getPurchaseTaxPercent()); if (evaluateReceipient(study) == Receipient.GERMAN_ALL) { netString = df_de.format(study.getConsideration().getInvoice().getPurchaseTaxPercent()); } details.addElement("taxrate").addText(taxRateString); } else { details.addElement("net").addText(new Integer(0).toString()); details.addElement("tax").addText(new Integer(0).toString()); details.addElement("taxrate") .addText(study.getConsideration().getInvoice().getPurchaseTaxPercent().toString()); } return document.asXML(); }
From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.ClientState.java
License:Open Source License
private Document getRequestDocument(Action action, ResourceURI resourceURI, OptionSet optionSet, String shelId, Element bodyContent) {/* w w w .j av a 2 s .c o m*/ Document doc = DocumentHelper.createDocument(); final Element envelope = doc.addElement(QName.get("Envelope", Namespaces.NS_SOAP_ENV)); envelope.add(getHeader(action, resourceURI, optionSet, shelId)); final Element body = envelope.addElement(QName.get("Body", Namespaces.NS_SOAP_ENV)); if (bodyContent != null) body.add(bodyContent); return doc; }
From source file:com.weibo.datasys.crawler.impl.crawlUnit.fetcher.wxcs.WXCSFetcher.java
License:Open Source License
@Override protected void configPostReq(SeedData seedData, DownRequest req) { Document doc = DocumentHelper.createDocument(); doc.setXMLEncoding("utf-8"); // /* w w w. ja va2 s . c o m*/ Element root = doc.addElement("root"); // transactionid root.addElement("transactionid").addText(""); // timestamp root.addElement("timestamp").addText(sdf.format(new Date())); // msgname String msgname = seedData.getExtendField(POST_FIELD_PREFIX + "msgname"); msgname = StringUtils.nullToEmpty(msgname); root.addElement("msgname").addText(msgname); // result root.addElement("result").addText(""); // resultdesc root.addElement("resultdesc").addText(""); // body Element body = root.addElement("body"); // dircode ?, root String dircode = seedData.getExtendField(POST_FIELD_PREFIX + "dircode"); dircode = StringUtils.nullToEmpty(dircode); body.addElement("dircode").addText(dircode); // areacode ??? String areacode = seedData.getExtendField(POST_FIELD_PREFIX + "areacode"); areacode = StringUtils.nullToEmpty(areacode); body.addElement("areacode").addText(areacode); // nodeversion ?? String nodeversion = seedData.getExtendField(POST_FIELD_PREFIX + "nodeversion"); nodeversion = StringUtils.nullToEmpty(nodeversion); body.addElement("nodeversion").addText(nodeversion); // depth ?[0..10]?10 // ?0????? // ?>0???? String depth = seedData.getExtendField(POST_FIELD_PREFIX + "depth"); depth = StringUtils.nullToEmpty(depth); body.addElement("depth").addText(depth); // returenres ??? // 0 // 1? // ? String returenres = seedData.getExtendField(POST_FIELD_PREFIX + "returenres"); if (StringUtils.isEmptyString(returenres)) { returenres = "1"; } body.addElement("returenres").addText(returenres); req.setContentType("text/xml"); req.setPostString(doc.asXML()); }
From source file:com.yahoo.validatar.report.junit.JUnitFormatter.java
License:Apache License
/** * {@inheritDoc}/*from w w w .j ava 2 s .c om*/ * Writes out the report for the given testSuites in the JUnit XML format. */ @Override public void writeReport(List<TestSuite> testSuites) throws IOException { Document document = DocumentHelper.createDocument(); Element testSuitesRoot = document.addElement("testsuites"); // Output for each test suite for (TestSuite testSuite : testSuites) { Element testSuiteRoot = testSuitesRoot.addElement("testsuite") .addAttribute("tests", Integer.toString(testSuite.queries.size() + testSuite.tests.size())) .addAttribute("name", testSuite.name); for (Query query : testSuite.queries) { Element queryNode = testSuiteRoot.addElement("testcase").addAttribute("name", query.name); if (query.failed()) { String failureMessage = StringUtils.join(query.getMessages(), ", "); queryNode.addElement("failed").addText(failureMessage); } } for (Test test : testSuite.tests) { Element testNode = testSuiteRoot.addElement("testcase").addAttribute("name", test.name); if (test.failed()) { String failedAsserts = StringUtils.join(test.getMessages(), ", "); String failureMessage = "Description: " + test.description + ";\n" + "Failed asserts: " + failedAsserts + "\n"; testNode.addElement("failed").addText(failureMessage); } } } OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(outputFile), format); writer.write(document); writer.close(); }
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
License:Apache License
/** * /*from w w w. j a v a 2 s .c o m*/ * * @param params * @return */ @POST @Path("/weixinNotify") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) public String weixinNotify(String params) { String req = null; Document reqDoc = DocumentHelper.createDocument(); Element reqRoot = reqDoc.addElement("xml"); Element reqCode = reqRoot.addElement("return_code"); try { Document doc = DocumentHelper.parseText(params); Element root = doc.getRootElement(); Element returnCode = root.element("return_code"); if ("SUCCESS".equals(returnCode.getText())) { String orderNo = root.elementText("out_trade_no"); MemberOrder order = memberOrderBean.findByOrderNo(orderNo); if (order != null && "SUCCESS".equals(root.elementText("result_code"))) { if (order.getState() != OrderStatus.FINISHED) {//???? order.setState(OrderStatus.FINISHED); if (System.currentTimeMillis() >= order.getServiceTime().getTime()) { Account account = accountBean.findByMemberNo(order.getMemberNumber()); int addCall = order.getSurplusCallDuration() + account.getSurplusCallDuration(); account.setSurplusCallDuration(addCall); accountBean.updateAccount(account); order.setUseState(OrderUseStatus.USING); } memberOrderBean.updateOrder(order); System.out.println("orderNo:" + order.getOrderNo() + "|orderState:" + order.getState() + "|orderUseState:" + order.getUseState()); } } else { System.out.println("??"); } PayWeixinLog pwl = new PayWeixinLog(); pwl.setAppid(root.elementText("appid")); pwl.setMchId(root.elementText("mch_id")); if (root.element("device_info") != null) pwl.setDeviceInfo(root.elementText("device_info")); pwl.setNonceStr(root.elementText("nonce_str")); pwl.setSign(root.elementText("sign")); pwl.setResultCode(root.elementText("result_code")); if (root.element("err_code") != null) pwl.setErrCode(root.elementText("err_code")); if (root.element("err_code_des") != null) pwl.setErrCodeDes(root.elementText("err_code_des")); pwl.setOpenid(root.elementText("openid")); if (root.element("is_subscribe") != null) pwl.setIsSubscribe(root.elementText("is_subscribe")); pwl.setTradeType(root.elementText("trade_type")); pwl.setBankType(root.elementText("bank_type")); pwl.setTotalFee(Integer.parseInt(root.elementText("total_fee"))); if (root.element("fee_type") != null) pwl.setFeeType(root.elementText("fee_type")); if (root.element("cash_fee") != null) pwl.setCashFee(Integer.parseInt(root.elementText("cash_fee"))); if (root.element("cash_fee_type") != null) pwl.setCashFeeType(root.elementText("cash_fee_type")); pwl.setTransationId(root.elementText("transation_id")); pwl.setOutTradeNo(root.elementText("out_trade_no")); if (root.element("attach") != null) pwl.setAttach(root.elementText("attach")); pwl.setTimeEnd(root.elementText("time_end")); payWeixinLogBean.createPayWeixinLog(pwl); reqCode.setText("SUCCESS"); } else { reqCode.setText("FAIL"); Element returnMsg = root.element("return_msg"); returnMsg.setText(root.elementText("retrun_msg")); } } catch (Exception e) { e.printStackTrace(); reqCode.setText("FAIL"); Element reqMsg = reqRoot.addElement("return_msg"); reqMsg.setText(""); } req = reqDoc.asXML(); return req; }
From source file:com.zimbra.cs.account.accesscontrol.RightManager.java
License:Open Source License
/** * generates two files in the output directory * * {right}-expanded.xml: the root combo right fully expanded * {right}-ui.xml: all UI covered by the root combo right * * @param outputDir/* ww w .j ava 2 s . c om*/ * @throws ServiceException * @throws IOException */ private void genAdminDocs(String outputDir) throws ServiceException, IOException { if (!outputDir.endsWith("/")) { outputDir = outputDir + "/"; } List<AdminRight> rootRights = ImmutableList.of(Admin.R_adminConsoleRights); for (AdminRight right : rootRights) { Multimap<UI, Right> uiMap = TreeMultimap.create(); /* * output the rights XML. This XML has the root combo right expanded * down to each atom(preset or attrs) right */ Document document = DocumentHelper.createDocument(); Element rightsRoot = document.addElement(E_ROOT); genAdminDocByRight(rightsRoot, right, uiMap); writeXML(outputDir + right.getName() + "-expanded.xml", document); /* * output the UI XML. This XML contains one entry for each UI, sorted by * the description of the UI. */ document = DocumentHelper.createDocument(); Element uiRoot = document.addElement(E_ROOT); genAdminDocByUI(uiRoot, uiMap); writeXML(outputDir + right.getName() + "-ui.xml", document); } }
From source file:com.zimbra.cs.dav.client.DavRequest.java
License:Open Source License
public void setRequestMessage(Element root) { if (mDoc == null) { mDoc = DocumentHelper.createDocument(); } mDoc.setRootElement(root); }
From source file:com.zimbra.soap.util.WsdlGenerator.java
License:Open Source License
public static Document makeWsdlDoc(List<WsdlInfoForNamespace> nsInfos, String serviceName, String targetNamespace) { Namespace nsSvc = new Namespace(svcPrefix, targetNamespace); final QName svcTypes = QName.get("types", nsWsdl); Document document = DocumentHelper.createDocument(); Map<WsdlServiceInfo, Element> bindElems = Maps.newTreeMap(); Map<WsdlServiceInfo, Element> portTypeElems = Maps.newTreeMap(); Element root = document.addElement(QName.get("definitions", nsWsdl)); root.add(nsSvc);/*w w w. j a va2s . c o m*/ for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) { root.add(wsdlNsInfo.getXsdNamespace()); } root.add(nsZimbra); root.add(nsSoap); root.add(nsXsd); root.add(nsWsdl); root.addAttribute("targetNamespace", targetNamespace); root.addAttribute("name", serviceName); addWsdlTypesElement(root, svcTypes, nsInfos); for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) { WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo(); if (!portTypeElems.containsKey(svcInfo)) { // wsdl:definitions/wsdl:portType Element portTypeElem = DocumentHelper.createElement(portType); portTypeElem.addAttribute("name", svcInfo.getPortTypeName()); portTypeElems.put(svcInfo, portTypeElem); } if (!bindElems.containsKey(svcInfo)) { // wsdl:definitions/wsdl:binding Element bindingElem = DocumentHelper.createElement(wsdlBinding); bindingElem.addAttribute("name", svcInfo.getBindingName()); bindingElem.addAttribute("type", svcPrefix + ":" + svcInfo.getPortTypeName()); // wsdl:definitions/wsdl:binding/soap:binding Element soapBindElem = bindingElem.addElement(soapBinding); soapBindElem.addAttribute("transport", "http://schemas.xmlsoap.org/soap/http"); soapBindElem.addAttribute("style", "document"); bindElems.put(svcInfo, bindingElem); } } for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) { WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo(); for (String requestName : wsdlNsInfo.getRequests()) { String rootName = requestName.substring(0, requestName.length() - 7); String responseName = rootName + "Response"; String reqOpName = requestName.substring(0, 1).toLowerCase() + requestName.substring(1); String reqMsgName = wsdlNsInfo.getTag() + requestName + "Message"; String respMsgName = wsdlNsInfo.getTag() + responseName + "Message"; addWsdlRequestAndResponseMessageElements(root, wsdlNsInfo, reqMsgName, respMsgName, requestName, responseName); addWsdlPortTypeOperationElements(portTypeElems.get(svcInfo), reqMsgName, respMsgName, reqOpName); addWsdlBindingOperationElements(bindElems.get(svcInfo), wsdlNsInfo, reqOpName, rootName); } } addWsdlSoapHdrContextMessageElement(root); for (Entry<WsdlServiceInfo, Element> entry : portTypeElems.entrySet()) { root.add(entry.getValue()); } for (Entry<WsdlServiceInfo, Element> entry : bindElems.entrySet()) { root.add(entry.getValue()); } Set<WsdlServiceInfo> svcSet = Sets.newHashSet(); for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) { WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo(); if (!svcSet.contains(svcInfo)) { svcSet.add(svcInfo); addWsdlServiceElement(root, svcInfo); } } return document; }
From source file:condorclient.utilities.XMLHandler.java
public String createName_IdXML() { String strXML = null;/*from w w w .ja v a2s.co m*/ Document document = DocumentHelper.createDocument(); // document. Element root = document.addElement("root"); Element info = root.addElement("info"); Element job = info.addElement("job"); job.addAttribute("name", "test"); job.addAttribute("id", "0"); StringWriter strWtr = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlWriter = new XMLWriter(strWtr, format); try { xmlWriter.write(document); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } strXML = strWtr.toString(); //-------- //------- //strXML=document.asXML(); //------ //------------- File file = new File("niInfo.xml"); if (file.exists()) { file.delete(); } try { file.createNewFile(); XMLWriter out = new XMLWriter(new FileWriter(file)); out.write(document); out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //-------------- return strXML; }
From source file:condorclient.utilities.XMLHandler.java
public String createXML() { String strXML = null;//from w w w. j a v a 2 s . c o m Document document = DocumentHelper.createDocument(); // document. Element root = document.addElement("root"); Element job = root.addElement("Job"); Element jobDescFile = job.addElement("item"); jobDescFile.addAttribute("about", "descfile"); Element file_name = jobDescFile.addElement("name"); file_name.addText("submit.txt"); Element filer_path = jobDescFile.addElement("path"); filer_path.addText("D:\\HTCondor\\test\\2"); StringWriter strWtr = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlWriter = new XMLWriter(strWtr, format); try { xmlWriter.write(document); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } strXML = strWtr.toString(); //-------- //------- //strXML=document.asXML(); //------ //------------- File file = new File("condorclient.xml"); if (file.exists()) { file.delete(); } try { file.createNewFile(); XMLWriter out = new XMLWriter(new FileWriter(file)); out.write(document); out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //-------------- return strXML; }