List of usage examples for org.dom4j Element elementText
String elementText(QName qname);
From source file:com.test.android.push.xmpp.handler.IQAuthHandler.java
License:Open Source License
/** * Handles the received IQ packet.// w w w .j a v a 2 s.c o m * * @param packet the packet * @return the response to send back * @throws UnauthorizedException if the user is not authorized */ public IQ handleIQ(IQ packet) throws UnauthorizedException { IQ reply = null; ClientSession session = sessionManager.getSession(packet.getFrom()); if (session == null) { log.error("Session not found for key " + packet.getFrom()); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.internal_server_error); return reply; } try { Element iq = packet.getElement(); Element query = iq.element("query"); Element queryResponse = probeResponse.createCopy(); if (IQ.Type.get == packet.getType()) { // get query String username = query.elementText("username"); if (username != null) { queryResponse.element("username").setText(username); } reply = IQ.createResultIQ(packet); reply.setChildElement(queryResponse); if (session.getStatus() != Session.STATUS_AUTHENTICATED) { reply.setTo((JID) null); } } else { // set query String resource = query.elementText("resource"); String username = query.elementText("username"); String password = query.elementText("password"); String digest = null; if (query.element("digest") != null) { digest = query.elementText("digest").toLowerCase(); } // Verify the resource if (resource != null) { try { resource = JID.resourceprep(resource); } catch (StringprepException e) { throw new UnauthorizedException("Invalid resource: " + resource, e); } } else { throw new IllegalArgumentException("Invalid resource (empty or null)."); } // Verify the username if (username == null || username.trim().length() == 0) { throw new UnauthorizedException("Invalid username (empty or null)."); } try { Stringprep.nodeprep(username); } catch (StringprepException e) { throw new UnauthorizedException("Invalid username: " + username, e); } username = username.toLowerCase(); // Verify that username and password are correct AuthToken token = null; if (password != null && AuthManager.isPlainSupported()) { token = AuthManager.authenticate(username, password); } else if (digest != null && AuthManager.isDigestSupported()) { token = AuthManager.authenticate(username, session.getStreamID().toString(), digest); } if (token == null) { throw new UnauthenticatedException(); } // Set the session authenticated successfully session.setAuthToken(token, resource); packet.setFrom(session.getAddress()); reply = IQ.createResultIQ(packet); } } catch (Exception ex) { // log.error(ex); ex.printStackTrace(); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); if (ex instanceof IllegalArgumentException) { reply.setError(PacketError.Condition.not_acceptable); } else if (ex instanceof UnauthorizedException) { reply.setError(PacketError.Condition.not_authorized); } else if (ex instanceof UnauthenticatedException) { reply.setError(PacketError.Condition.not_authorized); } else { reply.setError(PacketError.Condition.internal_server_error); } } // Send the response directly to the session if (reply != null) { session.process(reply); } return null; }
From source file:com.test.android.push.xmpp.handler.IQRegisterHandler.java
License:Open Source License
/** * Handles the received IQ packet./*from ww w . j a v a 2s .c o m*/ * * @param packet the packet * @return the response to send back * @throws UnauthorizedException if the user is not authorized */ public IQ handleIQ(IQ packet) throws UnauthorizedException { log.debug("----handleIQ start-----------------"); IQ reply = null; ClientSession session = sessionManager.getSession(packet.getFrom()); Element query = packet.getChildElement(); if (query.element("logoutUserId") != null) { String logoutUserId = query.elementText("logoutUserId"); log.debug("--?logoutUserId--" + logoutUserId); try { ApnUser user = new ApnUser(); user.setId(Long.parseLong(logoutUserId)); user.setOnline(0); androidService.updateAndroidPns(user); } catch (Exception e) { e.printStackTrace(); } } if (session == null) { log.error("Session not found for key " + packet.getFrom()); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.internal_server_error); return reply; } if (IQ.Type.get.equals(packet.getType())) { reply = IQ.createResultIQ(packet); if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // TODO } else { reply.setTo((JID) null); reply.setChildElement(probeResponse.createCopy()); } } else if (IQ.Type.set.equals(packet.getType())) { try { // Element query = packet.getChildElement(); if (query.element("remove") != null) { if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // TODO } else { throw new UnauthorizedException(); } } else { String username = query.elementText("username"); String password = query.elementText("password"); String userId = query.elementText("userId"); ApnUser user = new ApnUser(); log.debug("----cs android?----"); log.debug("username = " + username); log.debug("userId = " + userId); user.setUsername(username); user.setPassword(password); user.setCreateDate(new Date()); user.setId(Long.parseLong(userId)); user.setOnline(1); androidService.updateAndroidPns(user); reply = IQ.createResultIQ(packet); } } catch (Exception ex) { log.error(ex); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); if (ex instanceof UserExistsException) { reply.setError(PacketError.Condition.conflict); } else if (ex instanceof UserNotFoundException) { reply.setError(PacketError.Condition.bad_request); } else if (ex instanceof StringprepException) { reply.setError(PacketError.Condition.jid_malformed); } else if (ex instanceof IllegalArgumentException) { reply.setError(PacketError.Condition.not_acceptable); } else { reply.setError(PacketError.Condition.internal_server_error); } } } // Send the response directly to the session if (reply != null) { session.process(reply); } log.debug("----handleIQ end-----------------"); return null; }
From source file:com.thoughtworks.cruise.util.SvnLogXmlParser.java
License:Apache License
@SuppressWarnings("unchecked") private Revision parseLogEntry(Element logEntry, String path) throws ParseException { // TODO: we may need to add this information to the Revision in a potentially dark future of this probabilistic multiverse. // Date modifiedTime = convertDate(logEntry.elementText("date")); // String author = logEntry.elementText("author"); String comment = logEntry.elementText("msg"); String revisionNumber = logEntry.attributeValue("revision"); Revision revision = new Revision(revisionNumber, comment); Element logEntryPaths = (Element) logEntry.selectSingleNode("/paths"); if (logEntryPaths != null) { for (Element pathElement : (List<Element>) logEntryPaths.selectNodes("/path")) { if (underPath(path, pathElement.getText())) { addModificationToRevision(revision, pathElement); }//from ww w. ja v a 2 s . co m } } return revision; }
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 w w . j av a 2 s . com 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.HandlerManager.java
License:Open Source License
private void init() { chains = new HashMap<String, List<String>>(); chains.put(MessageType.HANDLER_TYPE_TEXT, new ArrayList<String>()); chains.put(MessageType.HANDLER_TYPE_IMAGE, new ArrayList<String>()); chains.put(MessageType.HANDLER_TYPE_VOICE, new ArrayList<String>()); chains.put(MessageType.HANDLER_TYPE_VIDEO, new ArrayList<String>()); chains.put(MessageType.HANDLER_TYPE_LOCATION, new ArrayList<String>()); chains.put(MessageType.HANDLER_TYPE_LINK, new ArrayList<String>()); chains.put(MessageType.HANDLER_EVENT_SUBSCRIBE, new ArrayList<String>()); chains.put(MessageType.HANDLER_EVENT_SUBSCRIBE_QRSCENE, new ArrayList<String>()); chains.put(MessageType.HANDLER_EVENT_UNSUBSCRIBE, new ArrayList<String>()); chains.put(MessageType.HANDLER_EVENT_SCAN, new ArrayList<String>()); chains.put(MessageType.HANDLER_EVENT_LOCATION, new ArrayList<String>()); chains.put(MessageType.HANDLER_EVENT_CLICK, new ArrayList<String>()); Document doc = null;/*from w ww . j a v a2 s.c o m*/ try { doc = WeixinUtils.getDocumentResource("weixin.handler.xml"); } catch (Exception e) { logger.error("weixin.handler.xml parser error"); e.printStackTrace(); return; } Element root = doc.getRootElement(); logger.debug(root.asXML()); List<Element> handlerEs = root.elements(); for (Element handlerE : handlerEs) { String handlerName = handlerE.elementText("name"); logger.debug("handlerName : " + handlerName); List<Element> handlerClzEs = handlerE.elements("handlerclz"); if (handlerClzEs == null || handlerClzEs.size() == 0) continue; List<String> handlerClzNames = chains.get(handlerName); logger.debug("handlerClzNames:" + handlerClzNames); if (handlerClzNames == null) continue; for (Element handlerClzE : handlerClzEs) { String clzName = handlerClzE.getText(); try { Class.forName(clzName); handlerClzNames.add(clzName); } catch (ClassNotFoundException e) { logger.error(clzName + " class not fount exception"); e.printStackTrace(); } } } }
From source file:com.voa.weixin.handler.Router.java
License:Open Source License
/** * ??ReciveMessage/*from w w w .ja v a 2s .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.voa.weixin.message.recieve.RecieveEvent.java
License:Open Source License
@Override public void parseXml(Element root) { this.event = root.elementText("Event"); }
From source file:com.voa.weixin.message.recieve.RecieveImgMessage.java
License:Open Source License
@Override public void parseXml(Element root) { this.picUrl = root.elementText("PicUrl"); this.mediaId = root.elementText("PicUrl"); }
From source file:com.voa.weixin.message.recieve.RecieveLinkMessage.java
License:Open Source License
@Override public void parseXml(Element root) { this.title = root.elementText("Title"); this.description = root.elementText("Description"); this.url = root.elementText("Url"); }
From source file:com.voa.weixin.message.recieve.RecieveLocationEvent.java
License:Open Source License
@Override public void parseXml(Element root) { super.parseXml(root); this.latitude = Float.valueOf(root.elementText("Latitude")); this.longitude = Float.valueOf(root.elementText("Longitude")); this.precision = Float.valueOf(root.elementText("Precision")); }