List of usage examples for org.dom4j Element getText
String getText();
From source file:com.bplow.netconn.base.net.Request.java
License:Open Source License
static Request parse(ByteBuffer bb) throws MalformedRequestException, UnsupportedEncodingException { byte[] requestMessage = bb.array(); String requestMsg = new String(requestMessage, "GBK"); System.out.println("??:" + requestMsg); String tradeType = null;//from w w w . jav a 2 s. c om SAXReader reader = new SAXReader(); reader.setStripWhitespaceText(true); Document document; try { document = reader.read(new ByteArrayInputStream(requestMsg.trim().getBytes())); Iterator orderIt = document.selectNodes("/TX/TX_CODE").iterator(); while (orderIt.hasNext()) { Element elem = (Element) orderIt.next(); tradeType = elem.getText(); } } catch (DocumentException e) { e.printStackTrace(); } int i = 0; String outNo = ""; String jyteype = ""; /*42+2 22*/ byte[] type = new byte[2]; //bb.get(type, 44, 2); while (bb.hasRemaining()) { byte c = bb.get(); //int devIdInt = Integer.parseInt(devId); //String devIdString = Integer.toHexString(c); String hex = Integer.toHexString(c & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } if (i >= 41 && i < 44) { outNo = outNo + hex; } if (i >= 44 && i < 46) { jyteype = jyteype + hex; } i++; System.out.print(hex.toUpperCase() + " "); } System.out.println(""); System.out.println("" + tradeType); System.out.println(outNo); //outOrderNo = outNo; /*CharBuffer cb = ascii.decode(bb); Matcher m = requestPattern.matcher(cb); if (!m.matches()) throw new MalformedRequestException(); Action a; try { a = Action.parse(m.group(1)); } catch (IllegalArgumentException x) { throw new MalformedRequestException(); } URI u; try { u = new URI("http://" + m.group(4) + m.group(2)); } catch (URISyntaxException x) { throw new MalformedRequestException(); } return new Request(a, m.group(3), u);*/ return new Request(outNo, tradeType); }
From source file:com.buddycloud.channeldirectory.search.handler.content.ContentQueryHandler.java
License:Apache License
@Override public IQ handle(IQ iq) { Element queryElement = iq.getElement().element("query"); Element searchElement = queryElement.element("search"); if (searchElement == null) { return XMPPUtils.error(iq, "Query does not contain search element.", getLogger()); }// w ww . j ava 2 s . co m String search = searchElement.getText(); if (search == null || search.isEmpty()) { return XMPPUtils.error(iq, "Search content cannot be empty.", getLogger()); } RSM rsm = RSMUtils.parseRSM(queryElement); List<PostData> relatedPosts; try { relatedPosts = findObjectsByContent(search, rsm); } catch (Exception e) { return XMPPUtils.error(iq, "Search could not be performed, service is unavailable.", getLogger()); } return createIQResponse(iq, relatedPosts, rsm); }
From source file:com.buddycloud.channeldirectory.search.handler.metadata.MetadataQueryHandler.java
License:Apache License
@Override public IQ handle(IQ iq) { Element queryElement = iq.getElement().element("query"); Element searchElement = queryElement.element("search"); if (searchElement == null) { return XMPPUtils.error(iq, "Query does not contain search element.", getLogger()); }//from w ww .j ava 2s . c om String search = searchElement.getText(); if (search == null || search.isEmpty()) { return XMPPUtils.error(iq, "Search content cannot be empty.", getLogger()); } RSM rsm = RSMUtils.parseRSM(queryElement); List<ChannelData> channelObjects; try { channelObjects = findObjectsByMetadata(rsm, search); } catch (Exception e) { return XMPPUtils.error(iq, "Search could not be performed, service is unavailable.", getLogger()); } return createIQResponse(iq, channelObjects, rsm); }
From source file:com.buddycloud.channeldirectory.search.handler.recommendation.RecommendationQueryHandler.java
License:Apache License
@Override public IQ handle(IQ iq) { Element queryElement = iq.getElement().element("query"); Element userJidElement = queryElement.element("user-jid"); if (userJidElement == null) { return XMPPUtils.error(iq, "Query does not contain user-jid element.", getLogger()); }// ww w .j av a 2s . co m String userJid = userJidElement.getText(); if (userJid == null || userJid.isEmpty()) { return XMPPUtils.error(iq, "User-jid cannot be empty.", getLogger()); } RSM rsm = RSMUtils.parseRSM(queryElement); rsm.setMax(rsm.getMax() != null ? rsm.getMax() : DEFAULT_PAGE); List<ChannelData> recommendedChannels; try { recommendedChannels = findRecommendedChannels(userJid, rsm); } catch (Exception e) { return XMPPUtils.error(iq, "Search could not be performed, service is unavailable.", e, getLogger()); } List<ChannelData> recommendedChannelsFullData; try { recommendedChannelsFullData = retrieveFromSolr(recommendedChannels); } catch (Exception e) { return XMPPUtils.error(iq, "Search could not be performed, service is unavailable.", e, getLogger()); } return createIQResponse(iq, recommendedChannelsFullData, rsm); }
From source file:com.buddycloud.channeldirectory.search.handler.similarity.SimilarityQueryHandler.java
License:Apache License
@Override public IQ handle(IQ iq) { Element queryElement = iq.getElement().element("query"); Element channelJidElement = queryElement.element("channel-jid"); if (channelJidElement == null) { return XMPPUtils.error(iq, "Query does not contain channel-jid element.", getLogger()); }/*from w w w . ja va 2 s . co m*/ String channelJid = channelJidElement.getText(); if (channelJid == null || channelJid.isEmpty()) { return XMPPUtils.error(iq, "Channel-jid cannot be empty.", getLogger()); } RSM rsm = RSMUtils.parseRSM(queryElement); rsm.setMax(rsm.getMax() != null ? rsm.getMax() : DEFAULT_PAGE); List<ChannelData> similarChannels; try { similarChannels = findSimilarChannels(channelJid, rsm); } catch (Exception e) { return XMPPUtils.error(iq, "Search could not be performed, service is unavailable.", e, getLogger()); } List<ChannelData> similarChannelsFullData; try { similarChannelsFullData = retrieveFromSolr(similarChannels); } catch (Exception e) { return XMPPUtils.error(iq, "Search could not be performed, service is unavailable.", e, getLogger()); } return createIQResponse(iq, similarChannelsFullData, rsm); }
From source file:com.buddycloud.channeldirectory.search.rsm.RSMUtils.java
License:Apache License
/** * Parses an RSM from a query XML element * @param queryElement//from www . ja v a 2 s.c o m * @return The parsed RSM object */ public static RSM parseRSM(Element queryElement) { RSM rsm = new RSM(); Element setElement = queryElement.element("set"); if (setElement == null) { return rsm; } Element after = setElement.element("after"); if (after != null) { rsm.setAfter(after.getText()); } Element before = setElement.element("before"); if (before != null) { String beforeText = before.getText(); rsm.setBefore(beforeText == null ? "" : beforeText); } Element index = setElement.element("index"); if (index != null) { rsm.setIndex(Integer.parseInt(index.getText())); } Element max = setElement.element("max"); if (max != null) { rsm.setMax(Integer.parseInt(max.getText())); } return rsm; }
From source file:com.buddycloud.friendfinder.handler.MatchContactFromContactProviderHandler.java
License:Apache License
@Override public IQ handle(IQ iq) { Element queryElement = iq.getElement().element("query"); String accessToken = queryElement.element("access_token").getText(); Element accessTokenSecretEl = queryElement.element("access_token_secret"); String accessTokenSecret = null; if (accessTokenSecretEl != null) { accessTokenSecret = accessTokenSecretEl.getText(); }//from w w w . j av a 2s . c o m ContactProfile profile = null; try { if (accessTokenSecret != null) { profile = ((OAuth1ContactProvider) getProvider()).getProfile(accessToken, accessTokenSecret); } else { profile = ((OAuth2ContactProvider) getProvider()).getProfile(accessToken); } } catch (Exception e) { return XMPPUtils.error(iq, "Could not retrieve contact profile. Namespace [" + getNamespace() + "]", getLogger()); } HashUtils.reportHash(iq.getFrom().toBareJID(), profile.getMyHash(), getDataSource()); List<MatchedUser> reportedHashes = new LinkedList<MatchedUser>(); for (String friendHash : profile.getMyFriendsHashes()) { String jid = HashUtils.retrieveJid(friendHash, getDataSource()); if (jid != null) { reportedHashes.add(new MatchedUser(jid, friendHash)); } } return createResponse(iq, reportedHashes); }
From source file:com.buddycloud.pusher.handler.GetNotificationSettingsQueryHandler.java
License:Apache License
@Override protected IQ handleQuery(IQ iq) { String userJid = iq.getFrom().toBareJID(); Element queryElement = iq.getElement().element("query"); Element typeEl = queryElement.element("type"); NotificationSettings notificationSettings = NotificationUtils.getNotificationSettingsByType(userJid, typeEl.getText(), getDataSource()); return createResponse(iq, userJid, notificationSettings); }
From source file:com.buddycloud.pusher.handler.GetPusherMetadataQueryHandler.java
License:Apache License
@Override protected IQ handleQuery(IQ iq) { String userJid = iq.getFrom().toBareJID(); Element queryElement = iq.getElement().element("query"); Element typeEl = queryElement.element("type"); Pusher pusher = Pushers.getInstance(getProperties()).get(typeEl.getText()); return createResponse(iq, userJid, pusher.getMetadata()); }
From source file:com.buddycloud.pusher.handler.internal.FollowRequestQueryHandler.java
License:Apache License
@Override protected IQ handleQuery(IQ iq) { Element queryElement = iq.getElement().element("query"); Element jidElement = queryElement.element("userJid"); Element channelElement = queryElement.element("channel"); Element channelOwnerElement = queryElement.element("channelOwnerJid"); if (jidElement == null || channelElement == null || channelOwnerElement == null) { return XMPPUtils.error(iq, "You must provide the userJid, the channel and the channelOwner", getLogger());// ww w. j a v a 2 s. c o m } String userJid = jidElement.getText(); String ownerJid = channelOwnerElement.getText(); String channelJid = channelElement.getText(); Map<String, String> tokens = new HashMap<String, String>(); tokens.put("FIRST_PART_JID", userJid.split("@")[0]); tokens.put("FIRST_PART_OWNER_JID", ownerJid.split("@")[0]); List<NotificationSettings> allNotificationSettings = NotificationUtils.getNotificationSettings(ownerJid, getDataSource()); for (NotificationSettings notificationSettings : allNotificationSettings) { if (!notificationSettings.getFollowRequest()) { getLogger().warn("User " + ownerJid + " won't receive follow request notifications."); continue; } if (notificationSettings.getTarget() == null) { getLogger().warn("User " + ownerJid + " has no target registered."); continue; } Pusher pusher = Pushers.getInstance(getProperties()).get(notificationSettings.getType()); pusher.push(notificationSettings.getTarget(), Event.FOLLOW_REQUEST, tokens); } return createResponse(iq, "User [" + userJid + "] sent a request to " + "follow your channel [" + channelJid + "]."); }