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:com.xuan.sdk.msg.InMsgParser.java
License:Apache License
/** * ?/*from www. j av a2 s.c o m*/ * 1text ? * 2image ? * 3voice ? * 4video ? * 5location ??? * 6link ? * 7event */ private static InMsg doParse(String xml) throws DocumentException { Document doc = DocumentHelper.parseText(xml); Element root = doc.getRootElement(); String toUserName = root.elementText("ToUserName"); String fromUserName = root.elementText("FromUserName"); Integer createTime = Integer.parseInt(root.elementText("CreateTime")); String msgType = root.elementText("MsgType"); if ("text".equals(msgType)) return parseInTextMsg(root, toUserName, fromUserName, createTime, msgType); if ("image".equals(msgType)) return parseInImageMsg(root, toUserName, fromUserName, createTime, msgType); if ("voice".equals(msgType)) return parseInVoiceMsgAndInSpeechRecognitionResults(root, toUserName, fromUserName, createTime, msgType); if ("video".equals(msgType)) return parseInVideoMsg(root, toUserName, fromUserName, createTime, msgType); if ("location".equals(msgType)) return parseInLocationMsg(root, toUserName, fromUserName, createTime, msgType); if ("link".equals(msgType)) return parseInLinkMsg(root, toUserName, fromUserName, createTime, msgType); if ("event".equals(msgType)) return parseInEvent(root, toUserName, fromUserName, createTime, msgType); throw new RuntimeException( "? " + msgType + "??"); }
From source file:com.ycszh.ssh.service.sfrz.impl.SfrzServiceImpl.java
public static Map<String, String> parseXml(String strxml) throws Exception { //strxml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><return><head><code>0000</code><msg>???1234</msg><body><cid>1234</cid></body></head></return>"; Document document = DocumentHelper.parseText(strxml); Element root = document.getRootElement(); Element head = root.element("head"); Element body = head.element("body"); String code = head.element("code").getText(); String msg = head.element("msg").getText(); Map<String, String> retmap = new HashMap<String, String>(); retmap.put("code", code); retmap.put("msg", msg); if ("0000".equals(code)) { String cid = body.element("cid").getText(); retmap.put("cid", cid); }//from w ww .ja v a2s . co m return retmap; }
From source file:com.ycszh.ssh.service.sfrz.impl.SfrzServiceImpl.java
public SfrzCjxxb parseXml2(String strxml) throws Exception { //strxml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><return><head><code>0000</code><msg>???1234</msg><body><cid>1234</cid></body></head></return>"; Document document = DocumentHelper.parseText(strxml); Element root = document.getRootElement(); Element head = root.element("head"); Element body = head.element("body"); String code = head.element("code").getText(); String msg = head.element("msg").getText(); SfrzCjxxb sc = new SfrzCjxxb(); if (!"0000".equals(code)) { String xm = body.element("XM").getText(); String sfzmmc = body.element("SFZMMC").getText(); String sfzmhm = body.element("SFZMHM").getText(); String xb = body.element("XB").getText(); String gj = body.element("GJ").getText(); String mz = body.element("MZ").getText(); String jg = body.element("JG").getText(); String txdz = body.element("TXDZ").getText(); String dzyx = body.element("DZYX").getText(); String gddh = body.element("GDDH").getText(); String yddh = body.element("YDDH").getText(); String wx = body.element("WX").getText(); String wb = body.element("WB").getText(); String qq = body.element("QQ").getText(); String rzly = body.element("RZLY").getText(); String rzjs = body.element("RZJS").getText(); String djzsdz = body.element("DJZSDZ").getText(); String xphz = body.element("XPHZ").getText(); String jzzdz = body.element("JZZDZ").getText(); String sfzmhmyxq = body.element("SFZMHMYXQ").getText(); String jzzyxq = body.element("JZZYXQ").getText(); String sfsh = body.element("SFSH").getText(); String jzzhm = body.element("JZZHM").getText(); sc.setXm(xm);//from w ww . j a va2 s .c o m sc.setSfzmmc(sfzmmc); sc.setSfzmhm(sfzmhm); sc.setXb(xb); sc.setGj(gj); sc.setMz(mz); sc.setJg(jg); sc.setTxdz(txdz); sc.setDzyx(dzyx); sc.setGddh(gddh); sc.setYddh(yddh); sc.setWx(wx); sc.setWb(wb); sc.setQq(qq); sc.setRzly(rzly); sc.setRzjs(rzjs); sc.setSynFlag(msg); sc.setTranFlag(code); sc.setDjzsdz(djzsdz); sc.setXphz(xphz); sc.setJzzdz(jzzdz); sc.setSfzmhmyxq(sfzmhmyxq); sc.setJzzyxq(jzzyxq); sc.setSfsh(sfsh); sc.setJzzhm(jzzhm); } else { sc.setSynFlag(msg); sc.setTranFlag(code); } return sc; }
From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java
License:Apache License
/** * /* 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:conviz.gr.server.ConvizResultTab.java
License:Apache License
@Override protected void fillModel(final @NotNull Map<String, Object> model, @NotNull HttpServletRequest request, @NotNull SBuild build) {/*from w ww . j a v a2 s . c o m*/ try { List<ResultVIewBean> diagrams = new ArrayList<ResultVIewBean>(); List<ResultVIewBean> reports = new ArrayList<ResultVIewBean>(); final List<BuildArtifact> reportArtifacts = new ArrayList<BuildArtifact>(); build.getArtifacts(BuildArtifactsViewMode.VIEW_ALL) .iterateArtifacts(new BuildArtifacts.BuildArtifactsProcessor() { @NotNull @Override public Continuation processBuildArtifact(@NotNull BuildArtifact artifact) { if (artifact.getName().matches(REPORT_FILE_PREFIX + ".*" + REPORT_FILE_SUFFIX)) { reportArtifacts.add(artifact); } return Continuation.CONTINUE; } }); for (BuildArtifact report : reportArtifacts) { String reportText = FileCopyUtils .copyToString(new BufferedReader(new InputStreamReader(report.getInputStream()))); Document doc = DocumentHelper.parseText(reportText); for (Element diagram : new ArrayList<Element>(doc.getRootElement().elements(REPORT_ELEMENT_IMG))) { diagrams.add(new ResultVIewBean(diagram.elementText(REPORT_EL_ID), diagram.elementText(REPORT_EL_FILE))); } for (Element customReport : new ArrayList<Element>( doc.getRootElement().elements(REPORT_ELEMENT_HTML))) { reports.add(new ResultVIewBean(customReport.elementText(REPORT_EL_ID), customReport.elementText(REPORT_EL_FILE))); } } model.put("diagrams", diagrams); model.put("reports", reports); } catch (Exception e) { LoggerFactory.getLogger(this.getClass()).error("ConViz failed to construct display tab view: ", e); model.put("conviz.view.error", true); model.put("conviz.error.text", e.toString()); } }
From source file:costumetrade.common.sms.SMSActor.java
License:Open Source License
private boolean isOk(String xml) { try {//from w w w.ja v a2s . c om Document doc = DocumentHelper.parseText(xml); Element root = doc.getRootElement();// ? String returnstatus = root.elementTextTrim("returnstatus"); return "Success".equals(returnstatus); } catch (Exception e) { LOGGER.error("????"); } return false; }
From source file:cparser.CParser.java
License:GNU General Public License
public static void main(final String argv[]) { System.loadLibrary("cparser"); init();/*w ww . jav a 2 s . c o m*/ if (argv.length < 1) System.exit(1); final CParser cp = new CParser(new File(argv[0]).getAbsolutePath()); System.out.println("Parsing"); int ret = cp.parse(); if (ret != 0) System.err.println("Parsing failed with error " + ret); final Node n = cp.getRoot(); System.out.println("Computing"); n.compute(); System.out.println("Creating CFG"); n.createCFG(); System.out.println("Generating XML"); final String xml = n.toXML(); System.out.println("Writing XML text"); try { final FileWriter fw = new FileWriter("xml.text"); fw.write(xml); fw.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } System.err.println("Node:\n\tcls=" + n.getClass().getName()); System.err.println("\tstr=" + n.toString()); System.err.println("\tXML:"); try { System.out.println("Generating XML tree"); Document doc = DocumentHelper.parseText(xml); System.out.println("Writing XML"); OutputFormat format = OutputFormat.createPrettyPrint(); OutputStream os = new FileOutputStream("out.xml"); try { XMLWriter writer = new XMLWriter(os, format); writer.write(doc); writer.close(); os.close(); /* writer = new XMLWriter(System.err, format); writer.write(doc); writer.close();*/ } catch (IOException ex) { ex.printStackTrace(); } } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } fini(); }
From source file:cz.muni.stanse.utils.xmlpatterns.XMLAlgo.java
License:GNU General Public License
public static Document toDocument(final String xml) { try {/*from w w w.ja va 2 s. c om*/ return DocumentHelper.parseText(xml); } catch (final DocumentException e) { return null; } }
From source file:data.BookshareWS.java
@Override public void parse(String tekst) throws Exception { try {/*from www . jav a 2 s .c o m*/ //List<Book> lista=new ArrayList<>(); Document document = DocumentHelper.parseText(tekst); List list = document.selectNodes("//result"); //System.out.println("Velicina liste "+list.size()); if (list == null || list.size() == 0) { System.out.println("Lista je null"); kraj = true; } else { System.out.println("Trenutni broj strana " + trenutnaStrana); for (int i = 0; i < list.size(); i++) { Book b = new Book(); b.setUri(URIGenerator.generateUri(b)); Node node = (Node) list.get(i); b.setTitle(node.selectSingleNode("title").getText()); Node isbn = node.selectSingleNode("isbn13"); if (isbn != null) { b.setIsbn(isbn.getText()); } List autori = node.selectNodes("author"); for (int j = 0; j < autori.size(); j++) { Person p = new Person(); p.setUri(URIGenerator.generateUri(p)); p.setName(((Node) autori.get(j)).getText()); b.getAuthors().add(p); } Organization o = new Organization(); o.setUri(URIGenerator.generateUri(o)); Node publisher = node.selectSingleNode("publisher"); if (publisher != null) { o.setName(publisher.getText()); } b.setPublisher(o); Node description = node.selectSingleNode("brief-synopsis"); if (description != null) { b.setDescription(description.getText()); } lista.add(b); } trenutnaStrana++; //kraj=true; } } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:data.IsbndbWS.java
@Override public void parse(String tekst) throws Exception { try {/* w w w.j a v a2s .c o m*/ //List<Book> lista=new ArrayList<>(); Document document = DocumentHelper.parseText(tekst); List list = document.selectNodes("//BookData"); if (list == null || list.size() == 0) { System.out.println("Doslo do kraja"); kraj = true; } else { System.out.println("ISBNDB, Trenutni broj strane " + trenutniBrojStrane); for (int i = 0; i < list.size(); i++) { Book b = new Book(); b.setUri(URIGenerator.generateUri(b)); Node node = (Node) list.get(i); b.setTitle(node.selectSingleNode("Title").getText()); b.setIsbn(node.valueOf("@isbn13")); Person p = new Person(); p.setUri(URIGenerator.generateUri(p)); p.setName(node.selectSingleNode("AuthorsText").getText()); b.getAuthors().add(p); Organization o = new Organization(); o.setUri(URIGenerator.generateUri(o)); o.setName(node.selectSingleNode("PublisherText").getText()); b.setPublisher(o); lista.add(b); } trenutniBrojStrane++; //kraj=true; } } catch (Exception e) { e.printStackTrace(); throw e; } }