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.collabnet.ccf.schemageneration.XSLTInitialMFDGeneratorScriptGenerator.java
License:Apache License
/** * Creates a new CreateInitialMFD.xsl file based on an already existing MFD file * @param mfdTemplateFile path to mfdFile * @param targetSchemaName /*from w ww. ja v a2s.c om*/ * @param sourceSchemaName * @return XML document containing CreateInitialMFD XSLT script * @throws TransformerException * @throws IOException * @throws DocumentException */ public Document generateCreateInitialMFDScript(String mfdTemplateFile, String sourceSchemaName, String targetSchemaName) throws TransformerException, DocumentException, IOException { Document document = DocumentHelper.parseText(readFileAsString(mfdTemplateFile)); return transform(initialMFDFileTransformer, document, sourceSchemaName, targetSchemaName); }
From source file:com.compliance.webapp.filter.LicenseFilter.java
public Boolean resolve(HttpServletRequest hRequest) { Boolean fileIsExist = false;/*from w w w. ja v a 2 s .com*/ try { String path = hRequest.getSession().getServletContext().getRealPath("/"); File file = new File(path + "compliance.licence"); if (file.exists()) { fileIsExist = true; FileInputStream in = null; in = new FileInputStream(file); byte[] buf = new byte[4096]; int len = in.read(buf, 0, 4096); in.close(); byte[] buffer = new byte[len]; for (int i = 0; i < len; i++) { buffer[i] = buf[i]; } char[] key1 = { 0x3F, 0xEE, 0x3F, 0x5A, 0xAE, 0xFA, 0x1F, 0x0A }; char[] key2 = { 0x3D, 0xAE, 0x3A, 0x5B, 0x3F, 0x6A, 0x11, 0xAA }; char[] key3 = { 0x0B, 0x9E, 0xDF, 0x2A, 0xAA, 0xF0, 0x7D, 0x6E }; buffer = EncodeUtil.xorDecode(buffer, key3); buffer = EncodeUtil.xorDecode(buffer, key2); buffer = EncodeUtil.xorDecode(buffer, key1); // ?XML Document document = DocumentHelper.parseText(new String(buffer)); Element root = document.getRootElement(); if (root.getName().equals("reginfo")) { List<Element> elementsList = root.elements(); Iterator<Element> iterator = elementsList.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); if (element.getName().equals("name")) { Serial.SERIAL_NAME = element.getText(); } else if (element.getName().equals("versions")) { Serial.SERIAL_VERSIONS = element.getText(); } else if (element.getName().equals("auth_day")) { Serial.SERIAL_AUTH_DAY = Integer.parseInt(element.getText()); } else if (element.getName().equals("gen_time")) { Serial.SERIAL_GEN_TIME = Long.parseLong(element.getText()); } else if (element.getName().equals("resource_num")) { Serial.SERIAL_RESOURCE_NUM = Integer.parseInt(element.getText()); } else if (element.getName().equals("sign")) { Serial.SERIAL_SIGN = element.getText(); } } } } } catch (Exception e) { fileIsExist = false; e.printStackTrace(); } return fileIsExist; }
From source file:com.core.util.wx.XmlUtils.java
License:Apache License
/** * xmlmap/*w ww .j a v a 2s .com*/ * * @param xml * @return */ @SuppressWarnings("rawtypes") public static Map<String, String> xmlToMap(String xml) { Map<String, String> map = new HashMap<String, String>(); Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { LOG.error(e.getMessage(), e); } if (null == doc) return map; Element root = doc.getRootElement(); for (Iterator iterator = root.elementIterator(); iterator.hasNext();) { Element e = (Element) iterator.next(); map.put(e.getName(), e.getText()); } return map; }
From source file:com.core.util.wx.XmlUtils.java
License:Apache License
/** * @param ??xml//from www.j a va2 s . c o m * @return * @throws UnsupportedEncodingException * @throws DocumentException * ???xml??? */ public static Map<String, String> sfxmlToMap(String xml) throws UnsupportedEncodingException, DocumentException { LOG.info("xml:" + xml); Map<String, String> map = new HashMap<String, String>(); Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { LOG.error(e.getMessage(), e); } if (null == doc) return map; Element root = doc.getRootElement(); for (Iterator iterator = root.elementIterator(); iterator.hasNext();) { Element e = (Element) iterator.next(); if (e.getName().equals("Head")) { if (e.getText().equals("ERR")) { return null; } } if (e.getName().equals("Body")) { Element e1 = e.element("OrderResponse"); if (e1 != null) { if (e1.attribute("mailno") != null) { map.put("mailno", e1.attribute("mailno").getText()); } if (e1.attribute("destcode") != null) { map.put("destcode", e1.attribute("destcode").getText()); } if (e1.attribute("filter_result") != null) { map.put("filter_result", e1.attribute("filter_result").getText()); } } Element e2 = e.element("OrderZDResponse"); if (e2 != null) { Element s = e2.element("OrderZDResponse"); if (s.attribute("mailno_zd") != null) { map.put("mailno_zd", s.attribute("mailno_zd").getText()); } } break; } } return map; }
From source file:com.creditcloud.investmentfund.model.huaan.money.CommonRequestMessage.java
/** * ??XML content/*ww w. ja v a 2s . c o m*/ * * @return */ public String buildXMLPayload() { try { Map<String, String> map = toMapFromXMLPayloadParameters(); final String rootXMLNodeName = "order"; XmlFactory factory = new XmlFactory(new InputFactoryImpl(), new CDataXmlOutputFactoryImpl()); XmlMapper xmlMapper = new XmlMapper(factory); xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); String xml = xmlMapper.writeValueAsString(map); Document doc = DocumentHelper.parseText(xml); Element root = doc.getRootElement(); root.setName(rootXMLNodeName); doc.setXMLEncoding(FundInterfaceConstants.HUA_AN_MONEY_FUND_HTTP_ENCODING); xml = doc.asXML(); setContentXMLPayloadPlainText(xml); return xml; } catch (JsonProcessingException | DocumentException e) { throw new RuntimeException(e); } }
From source file:com.creditcloud.investmentfund.model.lion.moneyfund.response.NotificationResponseMessage.java
/** * ???XML?// www . java 2 s. c o m * * @return * @throws JsonProcessingException * @throws org.dom4j.DocumentException */ public String toXMLMessage() throws JsonProcessingException, DocumentException { final String rootXMLNodeName = "Message"; ObjectMapper xmlMapper = new XmlMapper(); String xml = xmlMapper.writeValueAsString(this); Document doc = DocumentHelper.parseText(xml); Element root = doc.getRootElement(); root.setName(rootXMLNodeName); doc.setXMLEncoding(FundInterfaceConstants.LION_MONEY_FUND_HTTP_ENCODING); xml = doc.asXML(); return xml; }
From source file:com.ctrip.infosec.rule.action.FrozenAccount.java
/** * ?//w ww. ja va 2s .co m * * @param params * @return */ private static Map frozenOrNot(Map params) { beforeInvoke("FrozenAccount.frozenOrNot"); Map<String, String> result = new HashMap(); try { StringBuilder content = new StringBuilder(); content.append("<Uid>").append(params.get("uid")).append("</Uid>"); content.append("<OperStatus>").append(params.get("operStatus")).append("</OperStatus>"); content.append("<Oper>").append(params.get("oper")).append("</Oper>"); content.append("<Remark>").append(params.get("remark")).append("</Remark>"); String request = "<FULogMessageRequest>" + content.toString() + "</FULogMessageRequest>"; String xml = ESBClient.requestESB("Payment.CardRisk.InfoSecurity.EnterFULogMessage", request); if (xml == null || xml.isEmpty()) { return result; } Document document = DocumentHelper.parseText(xml); String xpath = "/Response/FULogMessageResponse"; List<Element> list = document.selectNodes(xpath); if (list == null || list.isEmpty()) { /*xpath = "/Response/Header"; Element header = (Element)document.selectSingleNode(xpath); Attribute resultCode = header.attribute("ResultCode"); Attribute resultMsg = header.attribute("ResultMsg"); result.put("resultCode",resultCode.getValue()); result.put("resultMsg",resultMsg.getValue());*/ result.put("result", xml); return result; } for (Element subElement : list) { Iterator iterator = subElement.elements().iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); result.put(element.getName(), element.getStringValue()); } } } catch (Exception ex) { fault("FrozenAccount.frozenOrNot"); logger.error(Contexts.getLogPrefix() + "invoke FrozenAccount.frozenOrNot fault.", ex); } finally { afterInvoke("FrozenAccount.frozenOrNot"); } return result; }
From source file:com.ctvit.vdp.services.sysconfiguration.user.UserService.java
/** * ?????XML//from w w w . j a v a2 s .c o m **/ public Map<String, String> getXML(Map xmlRightIds, Map thirdRightIds) throws DocumentException { String baseXML = systemConfigDao.selectByPrimaryKey("Rights").getValue();//??XML Document doc = DocumentHelper.parseText(baseXML); Document topDoc = DocumentHelper.createDocument(); Element baseElement = doc.getRootElement(); Element topEl = topDoc.addElement("Rights");//?XML List<Element> secMenuList = new ArrayList<Element>(); String topIdFlag = ""; Iterator elementIter = baseElement.elementIterator(); while (elementIter.hasNext()) {//?? Element element01 = (Element) elementIter.next(); Iterator elementIter01 = element01.elementIterator(); while (elementIter01.hasNext()) {//?? Element element02 = (Element) elementIter01.next(); Iterator elementIter02 = element02.elementIterator(); String idFlag = ""; if (xmlRightIds.get(element02.attributeValue("id")) != null) {//??ID?ID Element tempEl = element02.getParent();//? if (topEl.nodeCount() > 0 && !topIdFlag.equals(tempEl.attributeValue("id"))) { topEl.addElement(tempEl.getName()).addAttribute("id", element01.attributeValue("id")) .addAttribute("name", element01.attributeValue("name")); } if (topEl.nodeCount() == 0) { topEl.addElement(tempEl.getName()).addAttribute("id", element01.attributeValue("id")) .addAttribute("name", element01.attributeValue("name")); } topIdFlag = tempEl.attributeValue("id"); secMenuList.add(element02); } } } StringBuffer secXML = new StringBuffer(); secXML.append("<Rights>"); Element tempTopEl = topEl.createCopy(); // System.out.println("tempTopEl: "+tempTopEl.asXML()); Iterator secIt = tempTopEl.elementIterator();//???? String flag = ""; while (secIt.hasNext()) { Element op = (Element) secIt.next(); for (Element eo : secMenuList) {//eo?? if (eo.attributeValue("id").substring(0, 2).equals(op.attributeValue("id")) && !flag.equals(eo.attributeValue("id"))) { flag = eo.attributeValue("id"); Document secDoc = DocumentHelper.createDocument(); Element secEle = secDoc.addElement("SecMenu"); secEle.addAttribute("id", eo.attributeValue("id")); secEle.addAttribute("name", eo.attributeValue("name")); secEle.addAttribute("source", eo.attributeValue("source")); Iterator eoIter = eo.elementIterator(); while (eoIter.hasNext()) {//?? Element thirdEl = (Element) eoIter.next(); if (thirdRightIds.get(thirdEl.attributeValue("id")) != null) { Document document = DocumentHelper.createDocument(); Element tempEle = document.addElement("ThirdMenu"); tempEle.addAttribute("id", thirdEl.attributeValue("id")); tempEle.addAttribute("name", thirdEl.attributeValue("name")); tempEle.addAttribute("source", thirdEl.attributeValue("source")); secEle.add(tempEle);// } } op.add(secEle);// } //System.out.println("************ op: "+op.asXML()); } secXML.append(op.asXML()); } secXML.append("</Rights>"); Map<String, String> xmlMap = new HashMap<String, String>(); xmlMap.put("topMenu", topEl.asXML()); xmlMap.put("treeMenu", secXML.toString()); xmlMap.put("baseXML", baseElement.asXML()); // this.getElementList(baseElement,xmlRightIds); return xmlMap; }
From source file:com.ctvit.vdp.services.sysconfiguration.user.UserService.java
public String getRightXML(Map rightIds) throws DocumentException { String baseXML = systemConfigDao.selectByPrimaryKey("Rights").getValue();//??XML Document doc = DocumentHelper.parseText(baseXML); Element baseElement = doc.getRootElement(); Iterator elementIter = baseElement.elementIterator(); //?//from w w w.j a v a 2 s . c o m while (elementIter.hasNext()) {//?? Element el01 = (Element) elementIter.next(); if (rightIds.get(el01.attributeValue("id")) == null) { baseElement.remove(el01); } Iterator elIter01 = el01.elementIterator(); while (elIter01.hasNext()) {//?? Element el02 = (Element) elIter01.next(); if (rightIds.get(el02.attributeValue("id")) == null) { el01.remove(el02); } Iterator elIter02 = el02.elementIterator(); while (elIter02.hasNext()) {//??(?) Element el03 = (Element) elIter02.next(); if (rightIds.get(el03.attributeValue("id")) == null) { el02.remove(el03); } Iterator elIter03 = el03.elementIterator(); while (elIter03.hasNext()) {//??() Element el04 = (Element) elIter03.next(); if (rightIds.get(el04.attributeValue("id")) == null) { el03.remove(el04); } Iterator elIter04 = el04.elementIterator(); while (elIter04.hasNext()) {//??() Element el05 = (Element) elIter04.next(); System.out.println(el05.attributeValue("id")); if (rightIds.get(el05.attributeValue("id")) == null) { el04.remove(el05); } } } } } } return baseElement.asXML(); }
From source file:com.cy.dcts.identityVerify.service.impl.IdentityVerifyServiceImpl.java
private Map<String, String> paresXml2Map(String xml) { Map<String, String> map = new HashMap<String, String>(); Document document = null;/*w w w.j a va 2 s . c om*/ String errormesage = ""; String errormesagecol = ""; String idNumberRst = ""; String xmRst = ""; String errorMsg = ""; String errorCode = ""; try { document = DocumentHelper.parseText(xml); Element rootElement = document.getRootElement();//? Attribute rootAttr = rootElement.attribute("errorcode"); if (rootAttr != null) { Node errorCodeNode = rootElement.selectSingleNode("//RESPONSE/ROWS/ROW/ErrorCode"); Node errorMsgNode = rootElement.selectSingleNode("//RESPONSE/ROWS/ROW/ErrorMsg"); if (errorCodeNode != null && errorMsgNode != null) { errorMsg = errorMsgNode.getText(); errorCode = errorCodeNode.getText(); } map.put("errorCode", errorCode); map.put("errorMsg", errorMsg); return map; } Node idNumberNode = rootElement.selectSingleNode("//ROWS/ROW/INPUT/gmsfhm"); String idNumber = idNumberNode.getText(); String name = rootElement.selectSingleNode("//ROWS/ROW/INPUT/xm").getText(); map.put("gmsfhm", idNumber); map.put("xm", name); Node sfNode = rootElement.selectSingleNode("//ROWS/ROW/OUTPUT/ITEM/result_gmsfhm"); Node xmNode = rootElement.selectSingleNode("//ROWS/ROW/OUTPUT/ITEM/result_xm"); if (sfNode == null || xmNode == null) { Node errorMsgNode = rootElement.selectSingleNode("//ROWS/ROW/OUTPUT/ITEM/errormesage"); Node errorColNode = rootElement.selectSingleNode("//ROWS/ROW/OUTPUT/ITEM/errormesagecol"); if (errorMsgNode != null && errorColNode != null) { errormesage = errorMsgNode.getText(); errormesagecol = errorColNode.getText(); } } else { idNumberRst = sfNode.getText(); xmRst = xmNode.getText(); } map.put("result_gmsfhm", idNumberRst); map.put("result_xm", xmRst); map.put("errormesage", errormesage); map.put("errormesagecol", errormesagecol); } catch (DocumentException e) { e.printStackTrace(); } return map; }