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.topsec.tsm.sim.sysconfig.web.SystemConfigController.java
@RequestMapping("/superiorConfigRegist") @ResponseBody/*from ww w.ja v a2 s . c o m*/ public Object superiorConfigRegist(SID sid, HttpServletRequest request) throws Exception { Result result = new Result(true, "??"); String operator = request.getParameter("operator"); String registIp = request.getParameter("registIp"); String registName = request.getParameter("registName"); String param = ""; if (registIp.equals(IpAddress.getLocalIp().toString())) { result = new Result(false, "???"); return result; } if (StringUtils.containsAny(registName, "<>'*?:/|\"\\")) { return result.buildError("?????"); } Node parentNode = nodeMgrFacade.getParentNode(); Node KernelNode = nodeMgrFacade.getKernelAuditor(false); try { if ("regist".equals(operator)) { if (parentNode != null) { return result.buildError("??"); } else { //?? param = "<Register>" + "<Ip>" + IpAddress.getLocalIp() + "</Ip>" + //?IP "<Alias>" + registName + "</Alias>" + "<NodeId>" + KernelNode.getNodeId() + "</NodeId>" + "<Type>register</Type>" + "</Register>"; } } else if ("delete".equals(operator)) { if (parentNode == null) { return result.buildError("??"); } param = "<Register>" + "<Ip>" + IpAddress.getLocalIp() + "</Ip>" + "<Type>delete</Type>" + "</Register>"; } else if ("update".equals(operator)) { if (parentNode == null) { return result.buildError("??"); } try { nodeMgrFacade.delNode(parentNode); param = "<Register>" + "<Ip>" + IpAddress.getLocalIp() + "</Ip>" + "<Type>delete</Type>" + "</Register>"; String url = "https://" + parentNode.getIp() + "/resteasy/node/register"; Map<String, String> cookies = new HashMap<String, String>(); cookies.put("sessionid", RestUtil.getSessionId(registIp)); String returnInfo = HttpUtil.doPostWithSSLByString(url, param, cookies, "UTF-8"); if (StringUtils.isNotBlank(returnInfo)) { log.info("?IP:" + parentNode.getIp()); } } catch (ConnectException e) { log.warn("{}????", parentNode.getIp()); } //? // registNode(registIp, registName,KernelNode); param = "<Register>" + "<Ip>" + IpAddress.getLocalIp() + "</Ip>" + //?IP "<Alias>" + registName + "</Alias>" + "<NodeId>" + KernelNode.getNodeId() + "</NodeId>" + "<Type>register</Type>" + "</Register>"; } String url = "https://" + registIp + "/resteasy/node/register"; Map<String, String> cookies = new HashMap<String, String>(); cookies.put("sessionid", RestUtil.getSessionId(registIp)); String returnInfo = HttpUtil.doPostWithSSLByString(url, param, cookies, "UTF-8"); if (StringUtils.isNotBlank(returnInfo)) { Document document = DocumentHelper.parseText(returnInfo); Element root = document.getRootElement(); String successResponse = root.attribute("success").getValue(); if ("false".equals(successResponse)) { Element elementMessage = root.element("Message"); result.buildError(elementMessage.getText()); return result; } if ("regist".equals(operator)) { // registNode(registIp, registName, KernelNode); log.info("?IP:" + registIp); result = new Result(true, "?"); result.setResult(KernelNode.getResourceId()); } else if ("update".equals(operator)) { registNode(registIp, registName, KernelNode); log.info("??IP:" + registIp); result = new Result(true, "??"); result.setResult(KernelNode.getResourceId()); } else { // nodeMgrFacade.delNode(parentNode); log.info("?IP:" + parentNode.getIp()); result = new Result(true, "?"); } } else { result.buildError("?"); } } catch (Exception e) { e.printStackTrace(); result.buildError("?"); } return result; }
From source file:com.topsec.tsm.sim.sysconfig.web.SystemConfigController.java
/** * ?// www .jav a 2 s.c om * @param sid * @param ip * @param request * @return * @throws Exception */ @RequestMapping("/superiorConfigListSingle") @ResponseBody public Object superiorConfigListSingle(SID sid, @RequestParam("ip") String ip, @RequestParam("numFlag") String numFlag, HttpServletRequest request) throws Exception { Node node = nodeMgrFacade.getChildByIp(ip); JSONObject jObj = new JSONObject(); jObj.put("numFlag", numFlag); if (node != null) { String url = "https://" + node.getIp() + "/resteasy/node/systemInfo"; Map<String, String> cookies = new HashMap<String, String>(); cookies.put("sessionid", RestUtil.getSessionId(ip)); String returnInfo = HttpUtil.doPostWithSSLByMap(url, null, cookies, "UTF-8"); // // ?? // ClientRequest cRequest = new ClientRequest("https://" + node.getIp() + "/resteasy/node/systemInfo"); // cRequest.setHttpMethod("POST"); // String sessionId = RestUtil.getSessionId(node.getIp()) ; // cRequest.cookie("sessionid",sessionId); String sessionId = RestUtil.getSessionId(node.getIp()); jObj.put("sessionid", sessionId); jObj.put("registIp", node.getIp()); jObj.put("registName", node.getResourceName() == null ? 0 : node.getResourceName()); // String info = null; // if(!"".equals(sessionId)) { // ClientResponse<String> response; // response = cRequest.post(String.class); // info = response.getEntity(); // } if (StringUtil.isNotBlank(returnInfo)) { Document document = DocumentHelper.parseText(returnInfo); Element root = document.getRootElement(); jObj.put("cpu_usage", nvlAttribute(root, "cpu_usage", 0)); jObj.put("mem_usage", nvlAttribute(root, "mem_usage", 0)); jObj.put("log_flow", nvlAttribute(root, "log_flow", 0)); jObj.put("storage_usage", nvlAttribute(root, "storage_usage", 0)); jObj.put("storage_avaliable", nvlAttribute(root, "storage_avaliable", 0)); jObj.put("storage_total", nvlAttribute(root, "storage_total", 0)); jObj.put("offlineAssetCount", nvlAttribute(root, "offlineAssetCount", 0)); jObj.put("onlineAssetCount", nvlAttribute(root, "onlineAssetCount", 0)); jObj.put("assetCount", nvlAttribute(root, "assetCount", 0)); jObj.put("alarmCount", nvlAttribute(root, "alarmCount", 0)); jObj.put("eventCount", nvlAttribute(root, "eventCount", 0)); } else { jObj.put("cpu_usage", 0); jObj.put("mem_usage", 0); jObj.put("log_flow", 0); jObj.put("storage_usage", 0); jObj.put("storage_avaliable", 0); jObj.put("storage_total", 0); jObj.put("offlineAssetCount", 0); jObj.put("assetCount", 0); jObj.put("alarmCount", 0); jObj.put("eventCount", 0); } } return jObj; }
From source file:com.twistbyte.affiliate.CommissionJunctionService.java
License:Open Source License
private String getProperty(String xml, String prop) { try {/*from ww w .ja va 2 s.com*/ Document doc = DocumentHelper.parseText(xml); XPath xpath = new Dom4jXPath("//" + prop); List nodes = xpath.selectNodes(doc); if (nodes != null && !nodes.isEmpty()) { String url = ((Element) nodes.get(0)).getText(); return url; } else { logger.info("buy-url not found in result, Item probably not found"); } } catch (Exception e) { logger.error(null, e); } return null; }
From source file:com.uletian.ultcrm.business.service.CustomerInfoMessageService.java
public void handlerCustomerInfo(String message) throws SAXException, DocumentException, IOException { StringWriter writer = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); Document doc;/* w ww . ja v a 2s . c o m*/ doc = DocumentHelper.parseText(message); XMLWriter xmlwriter = new XMLWriter(writer, format); xmlwriter.write(doc); logger.info("??\n" + writer.toString()); Element element = doc.getRootElement(); String action = element.elementText("action"); String sourceSys = element.elementText("sourceSys"); String ultcrmid = element.elementText("ultcrmid"); String crmid = element.elementText("crmid"); String name = element.elementText("name"); String sexy = element.elementText("sexy"); String telephone = element.elementText("telephone"); String country = element.elementText("country"); String province = element.elementText("province"); String city = element.elementText("city"); String address = element.elementText("address"); String postcode = element.elementText("postcode"); if (!"UPDATE".equals(action)) { logger.debug("?\ncrmid:" + crmid + "\nultcrmid:" + ultcrmid); return; } Customer customer = customerRepository.findOne(Long.decode(ultcrmid)); if (customer == null) { logger.warn("?" + ultcrmid); return; } customer.setPhone(telephone); customer.setSyncid(crmid); customer.setName(name); customer.setSex(sexy); customer.setCountry(country); customer.setProvince(province); customer.setCity(city); customer.setAddress(address); customer.setPostcode(postcode); customer.setCrmCustomerId(crmid); customerRepository.save(customer); Element elements = element.element("techs"); Iterator<Element> iterator = elements.elementIterator("tech"); ArrayList<Tech> techs = new ArrayList<Tech>(0); while (iterator.hasNext()) { Element techElement = iterator.next(); String code = techElement.elementText("code"); String techlevelno = techElement.elementText("techlevelno"); String techerno = techElement.elementText("techerno"); String techname = techElement.elementText("techname"); String coursetime = techElement.elementText("coursetime"); String trainExpireDate = techElement.elementText("trainExpireDate"); String trainCompany = techElement.elementText("trainCompany"); String crmTechId = techElement.elementText("crmtechid"); String courseCode = techElement.elementText("courseCode"); String techColor = techElement.elementText("techColor"); String registerDate = techElement.elementText("registerDate"); String courseLicense = techElement.elementText("courseLicense"); String checkExpireDate = techElement.elementText("checkExpireDate"); String memberLevel = techElement.elementText("memberLevel"); String nextMaintCoursetime = techElement.elementText("nextMaintCoursetime"); String nextMaintDate = techElement.elementText("nextMaintDate"); String lastConsumeDate = techElement.elementText("lastConsumeDate"); Tech tech = techRepository.findTechByTechlevelno(techlevelno); if (tech == null) { tech = new Tech(); } TechModel techModel = null; try { techModel = techModelRepository.findModelByCode(code); } catch (Exception e) { } if (techModel == null) { logger.warn("??\n" + code); techModel = techModelRepository.findModelByCode("OTHERS"); } tech.setCrmTechId(crmTechId); tech.setTechlevelno(techlevelno); tech.setTechModel(techModel); tech.setTechSery(techModel.getTechSery()); tech.setTechCourse(techModel.getTechSery().getTechCourse()); tech.setCustomer(customer); tech.setCode(code); tech.setTechlevelno(techlevelno); tech.setTecherno(techerno); tech.setTechname(techname); tech.setCoursetime(coursetime); try { tech.setTrainExpireDate(sdf.parse(trainExpireDate)); } catch (ParseException e) { logger.warn("???\n" + trainExpireDate, e); } tech.setTrainCompany(trainCompany); tech.setCourseCode(courseCode); tech.setMemberLevel(memberLevel); tech.setColor(techColor); try { tech.setRegisterDate(sdf.parse(registerDate)); } catch (ParseException e) { logger.warn("??\n" + registerDate, e); } tech.setCourseLicense(courseLicense); try { tech.setCheckExpireDate(sdf.parse(checkExpireDate)); } catch (ParseException e) { logger.warn("??\n" + checkExpireDate, e); } // ?by xiecheng 2015-11-19 tech.setNextMaintCoursetime(nextMaintCoursetime); try { tech.setNextMaintDate(sdf.parse(nextMaintDate)); } catch (ParseException e) { logger.warn("??\n" + nextMaintDate, e); } try { tech.setLastConsumeDate(sdf.parse(lastConsumeDate)); } catch (ParseException e) { logger.warn("??\n" + lastConsumeDate, e); } techs.add(tech); } techRepository.save(techs); }
From source file:com.voa.weixin.handler.Router.java
License:Open Source License
/** * ??ReciveMessage/*w w w.java2 s . c om*/ * @param recieveMsg * @return */ public static RecieveMessage generateMsg(String recieveMsg) { RecieveMessage message = null; try { Document doc = DocumentHelper.parseText(recieveMsg); Element root = doc.getRootElement(); String type = root.elementText("MsgType"); if (StringUtils.equals(type, MessageType.TYPE_TEXT)) { message = new RecieveTxtMessage(recieveMsg, root); } else if (StringUtils.equals(type, MessageType.TYPE_IMAGE)) { message = new RecieveImgMessage(recieveMsg, root); } else if (StringUtils.equals(type, MessageType.TYPE_VOICE)) { message = new RecieveVoiceMessage(recieveMsg, root); } else if (StringUtils.equals(type, MessageType.TYPE_VIDEO)) { message = new RecieveVedioMessage(recieveMsg, root); } else if (StringUtils.equals(type, MessageType.TYPE_LOCATION)) { message = new RecieveLocationMessage(recieveMsg, root); } else if (StringUtils.equals(type, MessageType.TYPE_LINK)) { message = new RecieveLinkMessage(recieveMsg, root); } else if (StringUtils.equals(type, MessageType.TYPE_EVENT)) { String event = root.elementText("Event"); if (StringUtils.equals(event, MessageType.EVENT_SUBSCRIBE)) { if (root.elementText("EventKey") == null) message = new RecieveEvent(recieveMsg, root); else message = new RecieveTicketEvent(recieveMsg, root); } else if (StringUtils.equals(event, MessageType.EVENT_SCAN)) { message = new RecieveTicketEvent(recieveMsg, root); } else if (StringUtils.equals(event, MessageType.EVENT_LOCATION)) { message = new RecieveLocationEvent(recieveMsg, root); } else if (StringUtils.equals(event, MessageType.EVENT_CLICK)) { message = new RecieveMenuEvent(recieveMsg, root); } } } catch (Exception e) { throw new HandlerException("RecieveMessage parse error.", e); } return message; }
From source file:com.voxeo.moho.sip.SIPNotifyEventImpl.java
License:Apache License
@Override public String getResourceState() { if (getEventType() == Subscription.Type.DIALOG) { // TODO improve the content parser Document doc = null;/*from w w w .j av a 2 s .c o m*/ try { doc = DocumentHelper.parseText(new String(_req.getRawContent(), "UTF-8")); } catch (final Exception e) { throw new IllegalArgumentException(e); } // rfc4235 defined dialog state: Trying, Proceeding, Early, Confirmed, // Terminated return doc.getRootElement().element("dialog").element("state").getText(); } else if (getEventType() == Subscription.Type.PRESENCE) { // TODO improve the content parser Document doc = null; try { doc = DocumentHelper.parseText(new String(_req.getRawContent(), "UTF-8")); } catch (final Exception e) { throw new IllegalArgumentException(e); } // rfc3863 defined "open" and "close". return doc.getRootElement().element("tuple").element("status").elementText("basic"); } else if (getEventType() == Subscription.Type.REFER) { // TODO return null; } return null; }
From source file:com.webarch.common.io.xml.XmlConvert.java
License:Apache License
/** * String?XML{@link org.dom4j.Document}/* w w w .j ava2 s .c o m*/ * * @param xmlStr xml? * @return NULL/Document */ public static Document str2Xml(final String xmlStr) { Document document = null; if (xmlStr != null && !"".equals(xmlStr)) { try { document = DocumentHelper.parseText(xmlStr); } catch (DocumentException e) { logger.error("String?XML?", e); } } return document; }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public static Document todocument(String text) throws DocumentException { Document document = DocumentHelper.parseText(text); return document; }
From source file:com.weibo.datasys.crawler.base.factory.TaskFactory.java
License:Open Source License
/** * /*from w w w .j ava2 s. c om*/ * ?xmlTask * * @param xml * @return * @throws TaskException */ public static Task buildTask(String xml) throws TaskException { Task task = null; try { // xml dom Document doc = DocumentHelper.parseText(xml); // task task = new Task(); // task xml task.setTaskXML(xml); // task idname String taskId = doc.selectSingleNode("//Config/taskId").getText().trim(); task.setTaskId(taskId); String taskName = doc.selectSingleNode("//Config/taskName").getText().trim(); task.setTaskName(taskName); // task String cycleString = doc.selectSingleNode("//Config/taskCycle").getText().trim(); task.setTaskCycle(StringUtils.parseLong(cycleString, 0)); // ???? buildCrawlUnit(task, doc); // ? buildCrawlStrategy(task, doc); // ? buildParseStrategy(task, doc); // buildSaveStrategy(task, doc); } catch (Exception e) { logger.error("[buildTask] - {}", e.toString()); throw new TaskException("build task error.", e); } return task; }
From source file:com.weibo.datasys.crawler.impl.strategy.rule.parse.XpathMatchRule.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w ww .j a va2s .co m public List<CommonData> apply(CommonData in) { List<CommonData> fields = new ArrayList<CommonData>(); String xml = in.getBaseField("src"); try { Document doc = DocumentHelper.parseText(xml); List<Node> baseNodes = doc.selectNodes(baseNodeXpath); for (int i = 0; i < baseNodes.size(); i++) { Node baseNode = baseNodes.get(i); CommonData fieldData = new CommonData(); // ??xpathField for (Entry<String, String> entry : attrXpathMap.entrySet()) { String attr = entry.getKey(); String xpath = entry.getValue(); // ?xml? List<Node> valueNodes = baseNode.selectNodes(xpath); StringBuilder builder = new StringBuilder(); for (Node valueNode : valueNodes) { String tmpValue = valueNode.getText(); if (!StringUtils.isEmptyString(tmpValue)) { builder.append(tmpValue).append(MULTI_VALUE_SPLITER); } } if (builder.length() > 0) { builder.setLength(builder.length() - 1); } String value = builder.toString(); if ("id".equalsIgnoreCase(attr)) { fieldData.setId(value); } else { fieldData.setBaseField(attr, value); } } // Field? fields.add(fieldData); if (!isMultiMatch) { // ?????? break; } } // end of for each baseNode } catch (Exception e) { logger.error("[XpathMatchRuleError] - ", e); } return fields; }