List of usage examples for org.dom4j Element getText
String getText();
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * @param xPath //from w w w. j av a 2 s . c om * @param content * @param overwriteAble ?? * */ @Override public XMLEditor modifyElementContent(String xPath, final String content, final boolean overwriteAble) { super.addModifier(xPath, new ElementModifier() { @Override public Element modifyElement(Element element) throws Exception { StringBuffer contentText = new StringBuffer(); if (overwriteAble) { contentText.append(content); } else { contentText.append(element.getText()); contentText.append(content); } element.setText(contentText.toString()); return element; } }); return this; }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * ?xml attribute//from w w w. ja v a 2s. co m * * @return * @throws org.dom4j.DocumentException */ public Set<String> parserElement(Document rootElement, String xpath) throws DocumentException { Set<String> elementValueSet = new HashSet<String>(); List elements = rootElement.selectNodes(xpath); for (Object elementObject : elements) { if (elementObject instanceof Element) { Element element = (Element) elementObject; String elementValue = element.getText(); if (StringUtils.isNotEmpty(elementValue)) { elementValueSet.add(elementValue); } } } return elementValueSet; }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public Map<String, String> seachElementValueByNodeName(Document documentt, String... nodeNames) { Map<String, String> resultMap = new HashMap<String, String>(); for (String nodeName : nodeNames) { StringBuffer xPathBuff = new StringBuffer(); xPathBuff.append("//"); xPathBuff.append(nodeName);// w ww. j a v a 2 s .c om List<Element> resultList = documentt.selectNodes(xPathBuff.toString()); resultMap.put(nodeName, ""); if (resultList.size() > 0) { Element valueElement = resultList.get(0); resultMap.put(nodeName, valueElement.getText()); } } return resultMap; }
From source file:com.xebialabs.overthere.cifs.winrm.WinRmClient.java
License:Open Source License
private String handleStream(Document responseDocument, ResponseExtractor stream) { StringBuffer buffer = new StringBuffer(); @SuppressWarnings("unchecked") final List<Element> streams = (List<Element>) stream.getXPath().selectNodes(responseDocument); if (!streams.isEmpty()) { final Base64 base64 = new Base64(); Iterator<Element> itStreams = streams.iterator(); while (itStreams.hasNext()) { Element e = itStreams.next(); //TODO check performance with http://www.iharder.net/current/java/base64/ final byte[] decode = base64.decode(e.getText()); buffer.append(new String(decode)); }/* www. j a v a 2 s . com*/ } logger.debug("handleStream {} buffer {}", stream, buffer); return buffer.toString(); }
From source file:com.xebialabs.overthere.winrm.WinRmClient.java
License:Open Source License
private static void handleStream(Document responseDocument, ResponseExtractor stream, OutputStream out) throws IOException { @SuppressWarnings("unchecked") final List<Element> streams = stream.getXPath().selectNodes(responseDocument); if (!streams.isEmpty()) { final Base64 base64 = new Base64(); Iterator<Element> itStreams = streams.iterator(); while (itStreams.hasNext()) { Element e = itStreams.next(); // TODO check performance with http://www.iharder.net/current/java/base64/ final byte[] decode = base64.decode(e.getText()); out.write(decode);/*from w w w .j a v a2 s . c o m*/ } } }
From source file:com.xebialabs.overthere.winrm.WinRmClient.java
License:Open Source License
private static String getFirstElement(Document doc, ResponseExtractor extractor) { @SuppressWarnings("unchecked") final List<Element> nodes = extractor.getXPath().selectNodes(doc); if (nodes.isEmpty()) throw new RuntimeException("Cannot find " + extractor.getXPath() + " in " + toString(doc)); final Element next = nodes.iterator().next(); return next.getText(); }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * ?/*from w ww . j av a2 s .co m*/ * @Title: sendPicToWt * @param thPhoneDTO * @return * @createDate 20161026;?3:26:55 * @author xjf */ public static ClaimPhoneDTO sendPicToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); StringBuffer sql = new StringBuffer(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); StringBuffer json = new StringBuffer(); for (int j = 1; j < list.size() - 1; j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("???".equals(name)) { thPhoneDTO.setPlateNo(returString); } if ("".equals(name)) { thPhoneDTO.setVehicleType(returString); } if ("".equals(name)) { thPhoneDTO.setCustomerName(returString); } if ("??".equals(name)) { thPhoneDTO.setAddress(returString); } if ("??".equals(name)) { thPhoneDTO.setVehicleModels(returString); } if ("?".equals(name)) { thPhoneDTO.setVin(returString); } if ("???".equals(name)) { thPhoneDTO.setEngineNo(returString); } if ("".equals(name)) { thPhoneDTO.setRegisterDate(returString); } if ("??".equals(name)) { thPhoneDTO.setIssueDate(returString); } if ("".equals(name)) { thPhoneDTO.setUseType(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * /*from w w w. ja v a2 s .c o m*/ * @Title: sendPlateNoPicToWt * @param thPhoneDTO * @return * @createDate 20161026;?3:31:45 * @author luy */ public static ClaimPhoneDTO sendPlateNoPicToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); for (int j = 0; j < list.size(); j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("?".equals(name)) { thPhoneDTO.setPlateNo(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * ?// w w w. j a v a2 s .co m * @Title: sendIdCardToWt * @param thPhoneDTO * @return * @createDate 20161026;?3:32:41 * @author xjf */ public static ClaimPhoneDTO sendIdCardToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.IDCARD_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); for (int j = 1; j < list.size() - 1; j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("??".equals(name)) { thPhoneDTO.setUserName(returString); } if ("".equals(name)) { thPhoneDTO.setSex(returString); } if ("?".equals(name)) { thPhoneDTO.setNation(returString); } if ("".equals(name)) { thPhoneDTO.setBirthday(returString); } if ("??".equals(name)) { thPhoneDTO.setAddress(returString); } if ("??".equals(name)) { thPhoneDTO.setIdCardNo(returString); } if ("?".equals(name)) { thPhoneDTO.setIdCardPhoto(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * ?//from ww w . j a v a 2s . c o m * @Title: sendDriverToWt * @param thPhoneDTO * @return * @createDate 20161026;?3:33:28 * @author luy */ public static ClaimPhoneDTO sendDriverToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVER_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); for (int j = 1; j < list.size() - 1; j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("??".equals(name)) { thPhoneDTO.setCardNo(returString); } if ("??".equals(name)) { thPhoneDTO.setUserName(returString); } if ("".equals(name)) { thPhoneDTO.setSex(returString); } if ("??".equals(name)) { thPhoneDTO.setAddress(returString); } if ("".equals(name)) { thPhoneDTO.setBirthday(returString); } if ("??".equals(name)) { thPhoneDTO.setRegisterTime(returString); } if ("".equals(name)) { thPhoneDTO.setDrivingType(returString); } if ("".equals(name)) { thPhoneDTO.setStartTime(returString); } if ("?".equals(name)) { thPhoneDTO.setLimitTime(returString); } if ("".equals(name)) { thPhoneDTO.setEndTime(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }