List of usage examples for org.dom4j Document getRootElement
Element getRootElement();
From source file:com.jfinal.ext.weixin.msg.InMsgParaser.java
License:Apache License
@SuppressWarnings("unused") public static void main(String[] args) throws DocumentException { String xml = "<xml>\n" + "<ToUserName><![CDATA[James]]></ToUserName>\n" + "<FromUserName><![CDATA[JFinal]]></FromUserName>\n" + "<CreateTime>1348831860</CreateTime>\n" + "<MsgType><![CDATA[text]]></MsgType>\n" + "<Content><![CDATA[this is a test]]></Content>\n" + "<MsgId>1234567890123456</MsgId>\n" + "</xml>"; // InTextMsg msg = (InTextMsg)parse(xml); // System.out.println(msg.getToUserName()); // System.out.println(msg.getFromUserName()); // System.out.println(msg.getContent()); String xml_2 = "<xml>\n" + "<ToUserName><![CDATA[James]]></ToUserName>\n" + "<FromUserName><![CDATA[JFinal]]></FromUserName>\n" + "<CreateTime>1348831860</CreateTime>\n" + "<MsgType><![CDATA[text]]></MsgType>\n" + "<Content><![CDATA[this is a test]]></Content>\n" + "<MsgId>1234567890123456</MsgId>\n" + "</xml>"; Document doc = DocumentHelper.parseText(xml_2); Element root = doc.getRootElement(); String value = root.elementText("abc"); System.out.println(value);// ww w. j ava2 s . co m }
From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java
License:Apache License
/** * ?//from ww w .j ava 2 s . co m * 1text ? * 2image ? * 3voice ? * 4video ? * 5location ??? * 6link ? * 7event */ private static InMessage 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 parseInTextMessage(root, toUserName, fromUserName, createTime, msgType); if ("image".equals(msgType)) return parseInImageMessage(root, toUserName, fromUserName, createTime, msgType); if ("voice".equals(msgType)) return parseInVoiceMessage(root, toUserName, fromUserName, createTime, msgType); if ("video".equals(msgType)) return parseInVideoMessage(root, toUserName, fromUserName, createTime, msgType); if ("location".equals(msgType)) return parseInLocationMessage(root, toUserName, fromUserName, createTime, msgType); if ("link".equals(msgType)) return parseInLinkMessage(root, toUserName, fromUserName, createTime, msgType); if ("event".equals(msgType)) return parseInEvent(root, toUserName, fromUserName, createTime, msgType); throw new RuntimeException("???"); }
From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java
License:Apache License
public static void main(String[] args) throws DocumentException { String xml = "<xml>\n" + "<ToUserName><![CDATA[James]]></ToUserName>\n" + "<FromUserName><![CDATA[JFinal]]></FromUserName>\n" + "<CreateTime>1348831860</CreateTime>\n" + "<MsgType><![CDATA[text]]></MsgType>\n" + "<Content><![CDATA[this is a test]]></Content>\n" + "<MsgId>1234567890123456</MsgId>\n" + "</xml>"; // InTextMessage msg = (InTextMessage)parse(xml); // System.out.println(msg.getToUserName()); // System.out.println(msg.getFromUserName()); // System.out.println(msg.getContent()); String xml_2 = "<xml>\n" + "<ToUserName><![CDATA[James]]></ToUserName>\n" + "<FromUserName><![CDATA[JFinal]]></FromUserName>\n" + "<CreateTime>1348831860</CreateTime>\n" + "<MsgType><![CDATA[text]]></MsgType>\n" + "<Content><![CDATA[this is a test]]></Content>\n" + "<MsgId>1234567890123456</MsgId>\n" + "</xml>"; Document doc = DocumentHelper.parseText(xml_2); Element root = doc.getRootElement(); String value = root.elementText("abc"); System.out.println(value);/*from w ww .j av a2s . co m*/ }
From source file:com.jfinal.weixin.sdk.msg.InMsgParaser.java
License:Apache License
/** * ?//from w w w .j a v a 2s. 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("???"); }
From source file:com.jfinal.weixin.sdk.msg.InMsgParser.java
License:Apache License
/** * ?// ww w. ja v a 2 s . c o m * 1text ? * 2image ? * 3voice ? * 4video ? * shortvideo ?? * 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 ("shortvideo".equals(msgType)) //?? return parseInShortVideoMsg(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.jga.view.seguridad.RolManagedBean.java
protected List<Rol> getSecurityRoles() { HttpServletRequest origRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest();/*ww w .ja v a 2s .c o m*/ ServletContext sc = origRequest.getServletContext(); InputStream is = sc.getResourceAsStream("/WEB-INF/web.xml"); try { SAXReader reader = new SAXReader(); Document doc = reader.read(is); Element webApp = doc.getRootElement(); // Type safety warning: dom4j doesn't use generics List<Element> roleElements = webApp.elements("security-role"); for (Element roleEl : roleElements) { roles.add(new Rol(roleEl.element("role-name").getText())); } } catch (EJBException ex) { Exception ne = (Exception) ex.getCause(); Logger.getLogger(UsuarioManagedBean.class.getName()).log(Level.SEVERE, null, ne); } catch (Exception ex) { Logger.getLogger(UsuarioManagedBean.class.getName()).log(Level.SEVERE, null, ex); } return roles; }
From source file:com.jinglingtec.ijiazu.util.CCPRestSmsSDK.java
License:Open Source License
/** * @param xml/*w ww . j av a 2s . c om*/ * * @return Map * * @description xml??map */ private HashMap<String, Object> xmlToMap(String xml) { HashMap<String, Object> map = new HashMap<String, Object>(); Document doc = null; try { doc = DocumentHelper.parseText(xml); // XML Element rootElt = doc.getRootElement(); // ? HashMap<String, Object> hashMap2 = new HashMap<String, Object>(); for (Iterator i = rootElt.elementIterator(); i.hasNext();) { Element e = (Element) i.next(); if ("statusCode".equals(e.getName()) || "statusMsg".equals(e.getName())) { map.put(e.getName(), e.getText()); } else { if ("SubAccount".equals(e.getName()) || "totalCount".equals(e.getName()) || "token".equals(e.getName()) || "downUrl".equals(e.getName())) { if (!"SubAccount".equals(e.getName())) { hashMap2.put(e.getName(), e.getText()); } else { ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Iterator i2 = e.elementIterator(); i2.hasNext();) { Element e2 = (Element) i2.next(); hashMap3.put(e2.getName(), e2.getText()); arrayList.add(hashMap3); } hashMap2.put("SubAccount", arrayList); } map.put("data", hashMap2); } else { HashMap<String, Object> hashMap3 = new HashMap<String, Object>(); for (Iterator i2 = e.elementIterator(); i2.hasNext();) { Element e2 = (Element) i2.next(); // hashMap2.put(e2.getName(),e2.getText()); hashMap3.put(e2.getName(), e2.getText()); } if (hashMap3.size() != 0) { hashMap2.put(e.getName(), hashMap3); } else { hashMap2.put(e.getName(), e.getText()); } map.put("data", hashMap2); } } } } catch (DocumentException e) { e.printStackTrace(); LoggerUtil.error(e.getMessage()); } catch (Exception e) { LoggerUtil.error(e.getMessage()); e.printStackTrace(); } return map; }
From source file:com.jinmibao.common.util.whois.DomainRegCheckUtil.java
License:Open Source License
public static WhoisBean check(String domain) { WhoisBean whoisBean = new WhoisBean(); whoisBean.setDomain(domain);/*from w w w .j av a 2 s. c o m*/ whoisBean.setQueryStatus(QueryDomainWhoisStatusEnum.QUERY_SUCCESS.getKey()); // ???? if (!DomainUtil.isDomain(domain)) { whoisBean.setQueryStatus(QueryDomainWhoisStatusEnum.ILLEGAL_DOMAIN.getKey()); return whoisBean; } String checkUrl = "http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" + domain.trim(); Document document = null; try { URL url = new URL(checkUrl); URLConnection URLconnection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection) URLconnection; // System.setProperty("sun.net.client.defaultConnectTimeout", "8000"); System.setProperty("sun.net.client.defaultReadTimeout", "8000"); int responseCode = httpConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { } else { logger.error("Check Error." + checkUrl); } InputStream urlStream = httpConnection.getInputStream(); document = XMLUtil.getDocumentByInputStream(urlStream); } catch (Exception e) { logger.error("Check Error.", e); whoisBean.setQueryStatus(QueryDomainWhoisStatusEnum.QUERY_ERROR.getKey()); return whoisBean; } String returncode = XMLUtil.getElementText("returncode", document.getRootElement()); // ?200 if (!"200".equals(returncode)) { whoisBean.setQueryStatus(QueryDomainWhoisStatusEnum.QUERY_ERROR.getKey()); return whoisBean; } String original = XMLUtil.getElementText("original", document.getRootElement()); if (original.startsWith("210")) { whoisBean.setDomainStatus(DomainWhoisStatusEnum.NOT_REG.getKey()); } else if (original.startsWith("211")) { whoisBean.setDomainStatus(DomainWhoisStatusEnum.REG.getKey()); } else if (original.startsWith("212")) { whoisBean.setQueryStatus(QueryDomainWhoisStatusEnum.QUERY_ERROR.getKey()); } return whoisBean; }
From source file:com.jiusit.onePurchase.pay.Pay.java
License:Open Source License
public static Map<String, String> xml2Map(String xml) { Map<String, String> map = new HashMap<String, String>(); try {/*from w ww . j ava2 s .com*/ Document document = DocumentHelper.parseText(xml); Element root = document.getRootElement(); for (Iterator it = root.elementIterator(); it.hasNext();) { Element element = (Element) it.next(); map.put(element.getName(), element.getTextTrim()); } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } return map; }
From source file:com.jiuyi.doctor.call.AuthController.java
License:Open Source License
@RequestMapping("callauth") public void doAuth(HttpServletRequest request, HttpServletResponse response) { Document doc = null; String body = ""; log.info(" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= starts =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= "); try {//from w w w . j a v a 2 s. c o m // ???log InputStream in = request.getInputStream(); BufferedReader bf = new BufferedReader(new InputStreamReader(in)); String str = null; StringBuffer xmlfile = new StringBuffer(); while ((str = bf.readLine()) != null) { xmlfile.append(str); } log.info(" --- xml body --- :" + xmlfile); doc = DocumentHelper.parseText(xmlfile.toString()); } catch (DocumentException e) { log.error(" *** DocumentException ***", e); } catch (IOException e1) { log.error(" *** IOException ***", e1); } Element root = doc.getRootElement(); String action = root.elementTextTrim("action"); if (action.equals("CallAuth")) { // ??? body = parseCallAuth(root); } else if (action.equals("CallEstablish")) { // ? body = parseCallEstablish(root); } else if (action.equals("Hangup")) { // ? body = parseHangup(root); } // header response.setHeader("Status-Code", "HTTP/1.1 200 OK"); response.setHeader("Date", new Date() + ""); response.setHeader("Content-Length", body.length() + ""); try { // OutputStream opt = response.getOutputStream(); OutputStreamWriter out = new OutputStreamWriter(opt); out.write(body); out.flush(); } catch (IOException e) { log.error(" *** IOException ***", e); } log.info("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n"); }