List of usage examples for org.dom4j DocumentHelper parseText
public static Document parseText(String text) throws DocumentException
parseText
parses the given text as an XML document and returns the newly created Document.
From source file:$.MessageController.java
License:Apache License
/** * Converts input XML to "nice" XML. */* w w w.ja v a2 s .com*/ * @param original the original XML * @return pretty XML */ static String prettyPrintXML(String original) { try { OutputFormat format = OutputFormat.createPrettyPrint(); Document document = DocumentHelper.parseText(original); StringWriter sw = new StringWriter(); XMLWriter writer = new XMLWriter(sw, format); writer.write(document); return sw.toString(); } catch (Exception exc) { Log.debug("Error pretty-printing XML: ", exc); return original; } }
From source file:architecture.common.license.io.LicenseWriter.java
License:Apache License
public LicenseWriter(License license, LicenseSigner signer) throws LicenseException { this.license = license; try {//from ww w .j av a 2 s.c o m document = DocumentHelper.parseText(license.toXML()); Element root = document.getRootElement(); signer.sign(license); Element sig = root.addElement("signature"); sig.setText(license.getSignature()); } catch (Exception e) { log.fatal(e.getMessage(), e); throw new LicenseException(L10NUtils.format("002101", e.getMessage()), e); } }
From source file:architecture.common.license.License.java
License:Apache License
public static License fromXML(String xml) { try {//from w ww.j a v a 2 s.c o m Document d = DocumentHelper.parseText(xml); Element root = d.getRootElement(); License l = new License(); String id = root.attributeValue("id"); if (id == null) throw new LicenseException(L10NUtils.format("002105")); l.setID(Long.parseLong(id)); String name0 = root.attributeValue("name"); if (name0 == null) throw new LicenseException(L10NUtils.format("002106")); l.setName(name0); String edition = root.attributeValue("edition"); if (edition != null) l.setEdition(edition); String dateString = root.attributeValue("creationDate"); if (dateString == null) throw new LicenseException(L10NUtils.format("002107")); try { Date date = parseDate(dateString); l.setCreationDate(date); } catch (Exception e) { throw new LicenseException(L10NUtils.format("002108")); } String license = root.attributeValue("version"); if (license == null) throw new LicenseException(L10NUtils.format("002109")); l.setVersion(Version.parseVersion(license)); try { l.setType(Type.valueOf(root.attributeValue("type"))); } catch (IllegalArgumentException e) { throw new LicenseException(L10NUtils.format("002110")); } Element clientElement = root.element("client"); Client client = new Client(); client.setName(clientElement.attributeValue("name")); client.setCompany(clientElement.attributeValue("company")); l.setClient(client); for (Element e : (List<Element>) root.elements("module")) { Module m = new Module(); m.setName(e.attributeValue("name")); l.getModules().add(m); } Map<String, String> properties = new HashMap<String, String>(); for (Element e : (List<Element>) root.elements("property")) { String name = e.attributeValue("name"); String value = e.getTextTrim(); properties.put(name, value); } l.setProperties(properties); Element sig = root.element("signature"); l.setSignature(sig.getTextTrim()); return l; } catch (DocumentException e) { log.fatal(e.getMessage(), e); throw new LicenseException(L10NUtils.format("002111"), e); } }
From source file:at.kc.tugraz.ss.serv.dataimport.impl.fct.op.SSDataImportAchsoFct.java
License:Apache License
public static List<SSi5CloudAchsoVideo> getVideoObjs(final SSUri userUri, final String vidXML) throws Exception { try {// ww w .jav a 2 s . co m final Document document = DocumentHelper.parseText(vidXML); final Element rootElement = document.getRootElement(); final Iterator vidIterator = rootElement.elementIterator(); final List<SSi5CloudAchsoVideo> videos = new ArrayList<>(); Iterator vidContentIterator; Element vid; Element vidContent; String title; String video_uri; String creator; Long created_at; List<String> annotations; List<String> keywords; SSi5CloudAchsoVideo videoObj; while (vidIterator.hasNext()) { vid = (Element) vidIterator.next(); vidContentIterator = vid.elementIterator(); title = null; video_uri = null; creator = null; created_at = null; annotations = new ArrayList<>(); keywords = new ArrayList<>(); while (vidContentIterator.hasNext()) { vidContent = (Element) vidContentIterator.next(); switch (SSI5CloudAchsoVideoMetaDataE.get(vidContent.getName())) { case title: title = (String) vidContent.getData(); break; case video_uri: video_uri = (String) vidContent.getData(); break; case creator: creator = (String) vidContent.getData(); break; case created_at: created_at = getCreationTime((String) vidContent.getData()); break; case keywords: keywords = getKeywords(vidContent.nodeIterator()); break; case annotations: annotations = getAnnotations(vidContent.nodeIterator()); break; } } try { videoObj = SSi5CloudAchsoVideo.get(SSUri.get(video_uri), SSLabel.get(title), SSLabel.get(creator), keywords, annotations); videoObj.creationTime = created_at; videos.add(videoObj); } catch (Exception error) { SSLogU.warn("couldnt add vid: " + video_uri); } } return videos; } catch (Exception error) { SSServErrReg.regErrThrow(error); return null; } }
From source file:au.com.centrumsystems.hudson.plugin.buildpipeline.BuildPipelineView.java
License:Open Source License
@JavaScriptMethod public Set<String> getAllFirstJobsName(String url) { Jenkins jk = Jenkins.getInstance();/* ww w. j av a 2s.c o m*/ Collection<View> views = jk.getViews(); Set<String> firstJobNameSet = new HashSet<String>(); String shortUrl = getViewShortUrlFromURL(url); StringBuilder sb = null; Document configXmlDoc = null; String viewName = null; for (View view : views) { sb = new StringBuilder(shortUrl); viewName = view.getViewName(); if ("ALL".equals(viewName)) { continue; } sb.append(viewName).append("/"); String viewConfigXml = fetchViewConfig(sb.toString()); try { configXmlDoc = DocumentHelper.parseText(viewConfigXml); } catch (DocumentException e) { e.printStackTrace(); } Iterator iter = configXmlDoc.getRootElement().elementIterator("gridBuilder"); while (iter.hasNext()) { Element elt = (Element) iter.next(); firstJobNameSet.add(elt.elementTextTrim("firstJob")); } } return firstJobNameSet; }
From source file:br.gov.jfrj.siga.wf.tag.ProcessImageTag.java
License:Open Source License
/** * Desenha um quadro sobre a tarefa atual. * @throws IOException/*www . j a va 2s. c om*/ * @throws DocumentException */ private void writeTable() throws IOException, DocumentException { int borderWidth = 4; Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement(); int[] boxConstraint; int[] imageDimension = extractImageDimension(rootDiagramElement); String imageLink = "loadPhoto?pdId=" + processDefinition.getId(); JspWriter jspOut = pageContext.getOut(); if (tokenInstanceId > 0) { List allTokens = new ArrayList(); walkTokens(currentToken, allTokens); jspOut.println("<div style='position:relative; background-image:url(" + imageLink + "); width: " + imageDimension[0] + "px; height: " + imageDimension[1] + "px;'>"); for (int i = 0; i < allTokens.size(); i++) { Token token = (Token) allTokens.get(i); // check how many tokens are on teh same level (= having the // same parent) int offset = i; if (i > 0) { while (offset > 0 && ((Token) allTokens.get(offset - 1)).getParent().equals(token.getParent())) { offset--; } } boxConstraint = extractBoxConstraint(rootDiagramElement, token); // Adjust for borders // boxConstraint[2]-=borderWidth*2; // boxConstraint[3]-=borderWidth*2; jspOut.println("<div style='position:absolute; left: " + boxConstraint[0] + "px; top: " + boxConstraint[1] + "px; "); if (i == (allTokens.size() - 1)) { jspOut.println("border: " + currentTokenColor); } else { jspOut.println("border: " + childTokenColor); } jspOut.println(" " + borderWidth + "px groove; " + "width: " + boxConstraint[2] + "px; height: " + boxConstraint[3] + "px;'>"); if (token.getName() != null) { jspOut.println("<span style='color:" + tokenNameColor + ";font-style:italic;position:absolute;left:" + (boxConstraint[2] + 10) + "px;top:" + ((i - offset) * 20) + ";'> " + token.getName() + "</span>"); } jspOut.println("<span style='color:" + actorIDColor + ";font-style:italic;position:absolute;left:" + (boxConstraint[2] + 10) + "px;top:-30;'> " + WfContextBuilder.getJbpmContext() .getJbpmContext().getTaskInstance(taskInstanceId).getActorId() + "</span>"); jspOut.println("</div>"); } jspOut.println("</div>"); } else { boxConstraint = extractBoxConstraint(rootDiagramElement); jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width=" + imageDimension[0] + " height=" + imageDimension[1] + ">"); jspOut.println(" <tr>"); jspOut.println(" <td width=" + imageDimension[0] + " height=" + imageDimension[1] + " style=\"background-image:url(" + imageLink + ")\" valign=top>"); jspOut.println(" <table border=0 cellspacing=0 cellpadding=0>"); jspOut.println(" <tr>"); jspOut.println(" <td width=" + (boxConstraint[0] - borderWidth) + " height=" + (boxConstraint[1] - borderWidth) + " style=\"background-color:transparent;\"></td>"); jspOut.println(" </tr>"); jspOut.println(" <tr>"); jspOut.println(" <td style=\"background-color:transparent;\"></td>"); jspOut.println(" <td style=\"border-color:" + currentTokenColor + "; border-width:" + borderWidth + "px; border-style:groove; background-color:transparent;\" width=" + boxConstraint[2] + " height=" + (boxConstraint[3] + (2 * borderWidth)) + "> </td>"); jspOut.println(" </tr>"); jspOut.println(" </table>"); jspOut.println(" </td>"); jspOut.println(" </tr>"); jspOut.println("</table>"); } }
From source file:ca.qc.cegepoutaouais.tge.pige.server.report.LateLoanReport.java
License:Open Source License
protected Document generateReport() throws ReportException { try {/*from www .j a v a 2s. c om*/ String template = ReportHelper .convertStreamToString(ReportHelper.loadFileAsStream(TEMPLATE_BASE_PATH + TEMPLATE_FILENAME)); String css = ReportHelper.convertStreamToString( ReportHelper.loadFileAsStream(TEMPLATE_BASE_PATH + TEMPLATE_STYLES_FILENAME)); logger.debug("Inscription des donnes du rapport dans le modle."); template = MessageFormat.format(template, locale.getProperty("msg.report.lateLoansReportTitle"), MessageFormat.format(locale.getProperty("msg.report.reportGeneratedBy"), getAuthor(), SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG, Locale.CANADA_FRENCH) .format(new Date())), locale.getProperty("msg.report.statistics"), locale.getProperty("msg.report.totalNumberOfLoans"), locale.getProperty("msg.report.numberOfLentLoans"), locale.getProperty("msg.report.numberOfLateLoans"), ((Integer) get("total-count")).toString(), ((Integer) get("lent-count")).toString(), ((Integer) get("late-count")).toString(), String.format("%2.2f", (Float) get("percent-lent")), String.format("%2.2f", (Float) get("percent-late")), locale.getProperty("msg.report.userListWithLateLoans")); Document docRoot = DocumentHelper.parseText(template); ReportHelper.applyStyleToHTML(docRoot, css); Element body = (Element) docRoot.selectSingleNode("//data"); List<User> users = (List) get("users"); StringBuilder builder = new StringBuilder("<div>"); if (users.size() > 0) { for (User u : users) { builder.append( "<table class='user-section' border='0' cellspacing='0' cellpadding='5px'><thead><tr><td class='user-section-header'>") .append("[").append(u.getLoanNo()).append("] ").append(u.getLastname()).append(", ") .append(u.getFirstname()).append("</td><td colspan='2' class='user-section-header'>") .append(u.getEmail()).append("</td></tr><tr><td class='user-section-header'>") .append("Quantit").append("</td><td class='user-section-header'>") .append("Description").append("</td><td class='user-section-header'>") .append("chance").append("</td></tr></thead><tbody>"); Set<Loan> loans = u.getLoans(); for (Loan l : loans) { builder.append("<tr><td class='user-section-body'>").append(l.getQuantity()) .append("</td><td class='user-section-body'>").append(l.getDescription()) .append("</td><td class='user-section-body'>").append(l.getTerm().toString()) .append("</td></tr>"); } builder.append("</tbody></table>"); } } else { builder.append("<span>Aucun emprunt en retard!</span>"); } builder.append("</div>"); Document finalDoc = DocumentHelper.parseText(builder.toString()); Element content = finalDoc.getRootElement(); body.add(content); return docRoot; } catch (Exception ex) { throw new ReportException(ex); } }
From source file:cmcc.gz.adc.message.CorpBindReq.java
@SuppressWarnings("unchecked") public CorpBindReq(String msg) throws Exception { XmlParseTool xml = new XmlParseTool(msg); //??// www . j a v a 2 s. c om this.header = xml.getHeader(); //?? String bodyText; if (null == (bodyText = xml.getBodyText())) { throw new Exception("CorpBindReq??"); } try { Document document = DocumentHelper.parseText(bodyText); Element root = document.getRootElement(); this.corpName = root.element("CORPNAME").getTextTrim(); this.corpAccount = root.element("CORPACCOUNT").getTextTrim(); this.license = root.element("LICENSE").getTextTrim(); this.optype = root.element("OPTYPE").getTextTrim(); this.opnote = root.element("OPNOTE").getTextTrim(); //PARAMMAP paramMap = new HashMap<String, String>(); if (null != root.element("PARAMLIST").element("PARAMMAP")) { for (Iterator<Element> it = root.element("PARAMLIST").elementIterator("PARAMMAP"); it.hasNext();) { Element e = it.next(); String name = e.element("PARAMNAME").getTextTrim(); String value = e.element("PARAMVALUE").getTextTrim(); if (0 < name.length() && 0 < value.length()) paramMap.put(name, value); } } //CORPINFOMAP corpInfoMap = new HashMap<String, String>(); if (null != root.element("CORPINFOLIST").element("CORPINFOMAP")) { for (Iterator<Element> it = root.element("CORPINFOLIST").elementIterator("CORPINFOMAP"); it .hasNext();) { Element e = it.next(); String name = e.element("CORPINFONAME").getTextTrim(); String value = e.element("CORPINFOVALUE").getTextTrim(); if (0 < name.length() && 0 < value.length()) { corpInfoMap.put(name, value); if ("CORP_SHORTNAME".equals(name)) this.corpShortName = value; else if ("CORP_LINKMAN".equals(name)) this.corpLinkMan = value; else if ("CORP_LINKPHONE".equals(name)) this.corpLinkPhone = value; else if ("CORP_LINKMOBILE".equals(name)) this.corpLinkMobile = value; } } } //ORDERPOINTMAP orderPointMap = new HashMap<String, String>(); int count = 1; if (null != root.element("POINTLIST").element("ORDERPOINTMAP")) { for (Iterator<Element> it = root.element("POINTLIST").elementIterator("ORDERPOINTMAP"); it .hasNext();) { Element e = it.next(); String name = e.element("POINTNAME").getTextTrim(); String value = e.element("POINTVALUE").getTextTrim(); if (0 < name.length() && 0 < value.length()) { orderPointMap.put(name, value); this.point = (count == 1) ? name : String.format("%s,%s", point, name); count++; } } } } catch (Exception ex) { throw new Exception(ex.getMessage()); } }
From source file:cn.b2b.index.product.create.ProductDataFromDB.java
private String getBrand(String xml) { Document doc;/* w w w .j a v a 2 s. c o m*/ try { doc = DocumentHelper.parseText(xml); Element rootNode = doc.getRootElement(); Iterator iter = rootNode.nodeIterator(); while (iter.hasNext()) { Element recordEle = (Element) iter.next(); String title = recordEle.getName(); if (title.equals("P1")) { return recordEle.getText(); } return ""; } } catch (DocumentException e) { // e.printStackTrace(); } return ""; }
From source file:cn.b2b.index.product.create.ProductDataFromDB.java
private String getItemByXml(String xml, String nodeName) { Document doc;/*from w w w .jav a 2 s . c om*/ try { doc = DocumentHelper.parseText(xml); Element rootNode = doc.getRootElement(); Iterator iter = rootNode.nodeIterator(); while (iter.hasNext()) { Element recordEle = (Element) iter.next(); String title = recordEle.getName(); if (title.equals(nodeName)) { return recordEle.getText(); } return ""; } } catch (DocumentException e) { // e.printStackTrace(); } return ""; }