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.plugin.UI.Windows.Settings.ThemeSelection.java
/** * Parses the theme xml./*from w ww . j a v a 2 s . com*/ * * @param xml the xml */ private void parseThemeXML(String xml) { try { Document doc = DocumentHelper.parseText(xml); Element elmt = doc.getRootElement(); List l = elmt.selectNodes("/themes/theme"); Element e = null; theme = new String[l.size()]; theme_class = new String[l.size()]; for (int i = 0; i < l.size(); i++) { e = (Element) l.get(i); theme[i] = e.attribute("name").getValue(); theme_class[i] = e.attribute("class").getValue(); } } catch (DocumentException e) { System.out.println(e); } }
From source file:com.prj.utils.UfdmXmlUtil.java
/** * ??: dom4j ? xml//from www. j a v a2 s.c o m * @auther * @date 2014-11-28 * @return */ @SuppressWarnings("rawtypes") public static Map doGetAllXmlElementByDom4j(String reqXml) { try { Document document = DocumentHelper.parseText(reqXml); Element root = document.getRootElement(); return readXml(root, null); } catch (Exception er) { er.printStackTrace(); return null; } }
From source file:com.sam.moca.alerts.TU_Alert.java
License:Open Source License
@SuppressWarnings("deprecation") public void testAlertCreation() throws Exception { Alert alert = new Alert.AlertBuilder("SomeEvent", "TEST-SYSTEM").primerFlag(false) .priority(Alert.PRIORITY_INFORMATIONAL).duplicateValue("dupval").build(); Date dt = new Date(); assertEquals(dt.getDate(), alert.getDateTime().getDate()); assertEquals(dt.getMonth(), alert.getDateTime().getMonth()); assertEquals(dt.getYear(), alert.getDateTime().getYear()); assertNotNull(alert.getUrl());//from w w w . java 2 s. c o m assertTrue(alert.getUrl().length() > 0); assertTrue(alert.isInTransFlag()); // This should be the default assertFalse(alert.isPrimerFlag()); // This should be FALSE by default assertNull(alert.getEventDefinition()); // This should be NULL by default String xml = alert.asXML(); assertTrue(!xml.equals("")); // Parse the XML and spot check some nodes. Document document = DocumentHelper.parseText(xml); Node version = document.selectSingleNode("//ems-alert/version"); assertEquals("2", version.getText()); Node inTrans = document.selectSingleNode("//ems-alert/in-trans"); assertEquals("1", inTrans.getText()); Node srcSys = document.selectSingleNode("//ems-alert/event-data/source-system"); assertEquals("TEST-SYSTEM", srcSys.getText()); // Before writing, reset the inTransFlag so that it writes // immediately rather than waiting until the end of the transaction alert.setInTransFlag(false); alert.write(); File alertFile = new File(AlertUtils.getSpoolDir(), alert.getFileName()); assertNotNull(alertFile); // Clean everything up AlertFile af = new AlertFile(alertFile); assertTrue(af.getXmlContents().length() > 0); af.complete(true); // See if this went to the success directory File successFile = new File(AlertUtils.getProcessedDir(), alert.getFileName()); assertTrue(successFile.exists()); // Clean up the file if (successFile.exists()) { assertTrue(successFile.delete()); } }
From source file:com.sam.moca.alerts.TU_Alert.java
License:Open Source License
public void testEventPrime() throws Exception { Alert alert = new Alert.AlertBuilder("SomeEvent", "TEST-SYSTEM").priority(Alert.PRIORITY_INFORMATIONAL) .primerFlag(true).inTransFlag(false).duplicateValue("dupval").build(); alert.setEventName("SomeEvent"); alert.setPriority(Alert.PRIORITY_INFORMATIONAL); alert.setPrimerFlag(true);// w w w. j av a 2 s . c o m alert.setInTransFlag(false); alert.setDuplicateValue("dupval"); alert.setSourceSystem("TEST-SYSTEM"); EventDefinition ed = new EventDefinition.EventDefBuilder("SomeEvent", "SomeDescription", "SomeSubject", "SomeMessage").htmlMessage("<h1>SomeHTMLMessage</h1>").build(); alert.setEventDefinition(ed); assertEquals(EventDefinition.DEFAULT_PRIME_KEY_VAL, alert.getKeyValue()); String xml = alert.asXML(); assertTrue(!xml.equals("")); // Parse the XML and spot check some nodes. Document document = DocumentHelper.parseText(xml); Node primerFlag = document.selectSingleNode("//ems-alert/event-data/primer-flg"); assertEquals("1", primerFlag.getText()); Node keyValue = document.selectSingleNode("//ems-alert/event-data/key-val"); assertEquals(EventDefinition.DEFAULT_PRIME_KEY_VAL, keyValue.getText()); Node timeZone = document.selectSingleNode("//ems-alert/event-data/stored-tz"); assertEquals("----", timeZone.getText()); // Test the messages and stuff Element locale = (Element) document.selectSingleNode("//ems-alert/event-data/event-def/messages/message"); assertEquals("US_ENGLISH", locale.attributeValue("locale-id")); Node description = document .selectSingleNode("//ems-alert/event-data/event-def/messages/message/description"); assertEquals("SomeDescription", description.getText()); Node subject = document.selectSingleNode("//ems-alert/event-data/event-def/messages/message/subject"); assertEquals("SomeSubject", subject.getText()); Node htmlMessage = document .selectSingleNode("//ems-alert/event-data/event-def/messages/message/html-message"); assertEquals("<h1>SomeHTMLMessage</h1>", htmlMessage.getText()); Node textMessage = document .selectSingleNode("//ems-alert/event-data/event-def/messages/message/text-message"); assertEquals("SomeMessage", textMessage.getText()); // Write and clean this up. alert.write(); File alertFile = new File(AlertUtils.getSpoolDir(), alert.getFileName()); assertNotNull(alertFile); // Clean everything up AlertFile af = new AlertFile(alertFile); assertTrue(af.getXmlContents().length() > 0); af.complete(true); // See if this went to the success directory File successFile = new File(AlertUtils.getProcessedDir(), alert.getFileName()); assertTrue(successFile.exists()); // Clean up the file if (successFile.exists()) { assertTrue(successFile.delete()); } }
From source file:com.sammyun.plugin.alipayWap.AlipayWapPlugin.java
License:Open Source License
@Override public boolean verifyMobileNotify(String sn, NotifyMethod notifyMethod, HttpServletRequest request) { Map<String, Object> params = generateMobileSign(request); // ???//ww w . jav a2 s . c o m if (NotifyMethod.sync.equals(notifyMethod)) { if (null != params && params.size() > 0) { // ??? // ?? String outTradeNo = params.get("out_trade_no").toString(); // ? String result = params.get("result").toString(); if (verifyReturn(params) && sn.equals(outTradeNo) && ("success".equals(result))) { return true; } } else { return false; } } else { // RSA?? if (PluginConfig.SIGN_TYPE.equals("0001")) { params = decrypt(params); } // XML?notify_data? Document doc_notify_data = null; try { doc_notify_data = DocumentHelper.parseText(params.get("notify_data").toString()); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (doc_notify_data != null) { // ?? String outTradeNo = doc_notify_data.selectSingleNode("//notify/out_trade_no").getText(); // ? String tradeStatus = doc_notify_data.selectSingleNode("//notify/trade_status").getText(); if (verifyNotify(params) && sn.equals(outTradeNo) && ("TRADE_FINISHED".equals(tradeStatus) || "TRADE_SUCCESS".equals(tradeStatus))) { return true; } } } return false; }
From source file:com.sammyun.plugin.alipayWap.AlipayWapPlugin.java
License:Open Source License
/** * ?????????// w ww .j a v a2s . com * * @param params ?? * @return ? */ public boolean verifyNotify(Map<String, Object> params) { // ??????? String responseTxt = "true"; try { // XML?notify_data??notify_id Document document = DocumentHelper.parseText(params.get("notify_data").toString()); String notify_id = document.selectSingleNode("//notify/notify_id").getText(); responseTxt = verifyResponse(notify_id); } catch (Exception e) { responseTxt = e.toString(); } // ???? String sign = ""; if (params.get("sign") != null) { sign = params.get("sign").toString(); } boolean isSign = getSignVeryfy(params, sign, false); // responsetTxt?trueisSign?true // responsetTxt?true???ID?notify_id // isSign?true???????? if (isSign && responseTxt.equals("true")) { return true; } else { return false; } }
From source file:com.sammyun.plugin.PaymentPlugin.java
License:Open Source License
/** * ?????token ?RSA//from w ww .j a va 2 s . c om * * @param text ?? * @return ? * @throws Exception */ public static String getRequestToken(String text) throws Exception { String request_token = ""; // &? String[] strSplitText = text.split("&"); // ?????? Map<String, String> paraText = new HashMap<String, String>(); for (int i = 0; i < strSplitText.length; i++) { // =? int nPos = strSplitText[i].indexOf("="); // int nLen = strSplitText[i].length(); // ???? String strKey = strSplitText[i].substring(0, nPos); // String strValue = strSplitText[i].substring(nPos + 1, nLen); // MAP paraText.put(strKey, strValue); } if (paraText.get("res_data") != null) { String res_data = paraText.get("res_data"); // ?RSAMD5? if (PluginConfig.SIGN_TYPE.equals("0001")) { res_data = RSAUtils.decrypt(res_data, PluginConfig.ALI_PRIVATE_KEY, PluginConfig.INPUT_CHARSET); } // tokenres_data??res_data??token Document document = DocumentHelper.parseText(res_data); request_token = document.selectSingleNode("//direct_trade_create_res/request_token").getText(); } return request_token; }
From source file:com.sammyun.util.XmlHelper.java
License:Open Source License
/** * ?XMLDto(?XML?)/* w ww. java 2s. co m*/ * * @param pStrXml ?XML * @return outDto Dto */ public static final Dto parseXml2DtoBasedNode(String pStrXml) { Dto outDto = new BaseDto(); String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; Document document = null; try { if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml; document = DocumentHelper.parseText(pStrXml); } catch (DocumentException e) { logger.error( "==??:==\nXML??XML DOM?!" + "\n?:"); e.printStackTrace(); } if (document != null) { // ? Element elNode = document.getRootElement(); // ??Dto for (Iterator it = elNode.elementIterator(); it.hasNext();) { Element leaf = (Element) it.next(); outDto.put(leaf.getName().toLowerCase(), leaf.getData()); } } return outDto; }
From source file:com.sammyun.util.XmlHelper.java
License:Open Source License
/** * ?XMLDto(?XML?)// w w w . j ava 2 s. c om * * @param pStrXml ?XML * @param pXPath ("//paralist/row" paralistrowxPath) * @return outDto Dto */ public static final Dto parseXml2DtoBasedNode(String pStrXml, String pXPath) { Dto outDto = new BaseDto(); String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; Document document = null; try { if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml; document = DocumentHelper.parseText(pStrXml); } catch (DocumentException e) { logger.error( "==??:==\nXML??XML DOM?!" + "\n?:"); e.printStackTrace(); } if (document != null) { // ? Element elNode = document.getRootElement(); // ??Dto for (Iterator it = elNode.elementIterator(); it.hasNext();) { Element leaf = (Element) it.next(); outDto.put(leaf.getName().toLowerCase(), leaf.getData()); } } return outDto; }
From source file:com.sammyun.util.XmlHelper.java
License:Open Source License
/** * ?XMLDto(?XML?)//from w w w . jav a 2 s. co m * * @param pStrXml ?XML * @param pXPath ("//paralist/row" paralistrowxPath) * @return outDto Dto */ public static final Dto parseXml2DtoBasedProperty(String pStrXml, String pXPath) { Dto outDto = new BaseDto(); String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; Document document = null; try { if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml; document = DocumentHelper.parseText(pStrXml); } catch (DocumentException e) { logger.error( "==??:==\nXML??XML DOM?!" + "\n?:"); e.printStackTrace(); } if (document != null) { // ?Xpath? Element elRoot = (Element) document.selectSingleNode(pXPath); // ??Dto for (Iterator it = elRoot.attributeIterator(); it.hasNext();) { Attribute attribute = (Attribute) it.next(); outDto.put(attribute.getName().toLowerCase(), attribute.getData()); } } return outDto; }