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:org.jivesoftware.openfire.spi.PresenceManagerImpl.java
License:Open Source License
public void probePresence(JID prober, JID probee) { try {//from w w w.ja v a 2s .c om if (server.isLocal(probee)) { // Local probers should receive presences of probee in all connected resources Collection<JID> proberFullJIDs = new ArrayList<JID>(); if (prober.getResource() == null && server.isLocal(prober)) { for (ClientSession session : sessionManager.getSessions(prober.getNode())) { proberFullJIDs.add(session.getAddress()); } } else { proberFullJIDs.add(prober); } // If the probee is a local user then don't send a probe to the contact's server. // But instead just send the contact's presence to the prober Collection<ClientSession> sessions = sessionManager.getSessions(probee.getNode()); if (sessions.isEmpty()) { // If the probee is not online then try to retrieve his last unavailable // presence which may contain particular information and send it to the // prober String presenceXML = offlinePresenceCache.get(probee.getNode()); if (presenceXML == null) { loadOfflinePresence(probee.getNode()); } presenceXML = offlinePresenceCache.get(probee.getNode()); if (presenceXML != null && !NULL_STRING.equals(presenceXML)) { try { // Parse the element Document element = DocumentHelper.parseText(presenceXML); // Create the presence from the parsed element Presence presencePacket = new Presence(element.getRootElement()); presencePacket.setFrom(probee.toBareJID()); // Check if default privacy list of the probee blocks the // outgoing presence PrivacyList list = PrivacyListManager.getInstance() .getDefaultPrivacyList(probee.getNode()); // Send presence to all prober's resources for (JID receipient : proberFullJIDs) { presencePacket.setTo(receipient); if (list == null || !list.shouldBlockPacket(presencePacket)) { // Send the presence to the prober deliverer.deliver(presencePacket); } } } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } } } else { // The contact is online so send to the prober all the resources where the // probee is connected for (ClientSession session : sessions) { // Create presence to send from probee to prober Presence presencePacket = session.getPresence().createCopy(); presencePacket.setFrom(session.getAddress()); // Check if a privacy list of the probee blocks the outgoing presence PrivacyList list = session.getActiveList(); list = list == null ? session.getDefaultList() : list; // Send presence to all prober's resources for (JID receipient : proberFullJIDs) { presencePacket.setTo(receipient); if (list != null) { if (list.shouldBlockPacket(presencePacket)) { // Default list blocked outgoing presence so skip this session continue; } } try { deliverer.deliver(presencePacket); } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } } } } } else { if (routingTable.hasComponentRoute(probee)) { // If the probee belongs to a component then ask the component to process the // probe presence Presence presence = new Presence(); presence.setType(Presence.Type.probe); presence.setFrom(prober); presence.setTo(probee); routingTable.routePacket(probee, presence, true); } else { // Check if the probee may be hosted by this server /*String serverDomain = server.getServerInfo().getName(); if (!probee.getDomain().contains(serverDomain)) {*/ if (server.isRemote(probee)) { // Send the probe presence to the remote server Presence probePresence = new Presence(); probePresence.setType(Presence.Type.probe); probePresence.setFrom(prober); probePresence.setTo(probee.toBareJID()); // Send the probe presence deliverer.deliver(probePresence); } else { // The probee may be related to a component that has not yet been connected so // we will keep a registry of this presence probe. The component will answer // this presence probe when he becomes online componentManager.addPresenceRequest(prober, probee); } } } } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } }
From source file:org.jivesoftware.xmpp.workgroup.WorkgroupStats.java
License:Open Source License
public void getChatTranscript(IQ iq, String sessionID) { final IQ reply = IQ.createResultIQ(iq); String transcriptXML = null;// www .j av a2 s . c o m try { Element transcript = reply.setChildElement("transcript", "http://jivesoftware.com/protocol/workgroup"); transcript.addAttribute("sessionID", sessionID); Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(GET_TRANSCRIPT); pstmt.setString(1, sessionID); rs = pstmt.executeQuery(); if (rs.next()) { transcriptXML = DbConnectionManager.getLargeTextField(rs, 1); } } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); } finally { DbConnectionManager.closeConnection(rs, pstmt, con); } if (transcriptXML != null) { Document element = DocumentHelper.parseText(transcriptXML); // Add the Messages and Presences contained in the retrieved transcript element for (Iterator<Element> it = element.getRootElement().elementIterator(); it.hasNext();) { Element packet = it.next(); transcript.add(packet.createCopy()); } } workgroup.send(reply); } catch (Exception ex) { Log.error("There was an error retrieving the following transcript. SessionID = " + sessionID + " Transcript=" + transcriptXML, ex); reply.setChildElement(iq.getChildElement().createCopy()); reply.setError(new PacketError(PacketError.Condition.item_not_found)); workgroup.send(reply); } }
From source file:org.kie.appformer.formmodeler.codegen.view.impl.html.util.HTMLTemplateFormatter.java
License:Apache License
public String formatHTMLCode(String htmlTemplate) { try {/*ww w . java 2 s . co m*/ Document document = DocumentHelper.parseText(htmlTemplate); StringWriter sw = new StringWriter(); HTMLWriter writer = new HTMLWriter(sw); writer.write(document); return sw.toString(); } catch (Exception e) { log.warn("Error formatting html template: ", e); } return null; }
From source file:org.kuali.kra.budget.nonpersonnel.BudgetJustificationWrapper.java
License:Educational Community License
/** * This method parses the raw budgetJustification String into the fields needed for this class * Expected format://from w w w . j av a 2 s .c o m * <budgetJustification lastUpdateBy="" lastUpdateOn=""> * <![CDATA[ * Justification text * ]]> * </justification> */ private void parse(String budgetJustificationAsXML) { if (budgetJustificationAsXML == null || budgetJustificationAsXML.trim().length() == 0) { return; } try { Document document = DocumentHelper.parseText(budgetJustificationAsXML); Node node = document.selectSingleNode("//budgetJustification"); lastUpdateUser = node.valueOf("@lastUpdateBy"); lastUpdateTime = node.valueOf("@lastUpdateOn"); justificationText = node.getText(); } catch (DocumentException e) { LOG.warn(e.getMessage(), e); } }
From source file:org.light.portal.core.action.PortalConfigAction.java
License:Apache License
public Object uploadAllOpml(HttpServletRequest request, HttpServletResponse response) throws Exception { boolean upload = true; try {/*from w w w. jav a 2 s . com*/ StringBuffer buffer = new StringBuffer(); ServletInputStream in = request.getInputStream(); int i; boolean added = false; while ((i = in.read()) != -1) { buffer.append((char) i); } String text = buffer.toString(); int index = text.indexOf("<?xml"); int endIndex = text.indexOf("</opml>"); if (endIndex <= 0) return false; String result = text.substring(index, endIndex + 7); Document document = DocumentHelper.parseText(result); List list1 = document.selectNodes("//opml/body/outline"); for (Iterator iter = list1.iterator(); iter.hasNext();) { Node node = (Node) iter.next(); String title = node.valueOf("@title"); String feed = node.valueOf("@xmlUrl"); String name = node.valueOf("@name"); String userId = node.valueOf("@userId"); String tag = node.valueOf("@tag"); String subTag = node.valueOf("@subTag"); String language = node.valueOf("@language"); if (feed != null && feed.trim().length() > 0) addFeedFromOpml(request, title, feed, name, userId, tag, subTag, language); } List list = document.selectNodes("//opml/body/outline/outline"); for (Iterator iter = list.iterator(); iter.hasNext();) { Node node = (Node) iter.next(); String title = node.valueOf("@title"); String feed = node.valueOf("@xmlUrl"); String name = node.valueOf("@name"); String userId = node.valueOf("@userId"); String tag = node.valueOf("@tag"); String subTag = node.valueOf("@subTag"); String language = node.valueOf("@language"); if (feed != null && feed.trim().length() > 0) addFeedFromOpml(request, title, feed, name, userId, tag, subTag, language); } } catch (Exception e) { e.printStackTrace(); upload = false; } return upload; }
From source file:org.light.portal.core.action.PortalConfigAction.java
License:Apache License
public Object uploadOpml(HttpServletRequest request, HttpServletResponse response) throws Exception { boolean upload = true; try {//w w w .j ava 2 s .c o m StringBuffer buffer = new StringBuffer(); ServletInputStream in = request.getInputStream(); int i; boolean added = false; while ((i = in.read()) != -1) { buffer.append((char) i); } String text = buffer.toString(); int index = text.indexOf("<?xml"); int endIndex = text.indexOf("</opml>"); if (endIndex <= 0) return false; String result = text.substring(index, endIndex + 7); Document document = DocumentHelper.parseText(result); List list1 = document.selectNodes("//opml/body/outline"); for (Iterator iter = list1.iterator(); iter.hasNext();) { Node node = (Node) iter.next(); String title = node.valueOf("@title"); String feed = node.valueOf("@xmlUrl"); if (feed != null && feed.trim().length() > 0) addMyFeedFromOpml(request, title, feed); } List list = document.selectNodes("//opml/body/outline/outline"); for (Iterator iter = list.iterator(); iter.hasNext();) { Node node = (Node) iter.next(); String title = node.valueOf("@title"); String feed = node.valueOf("@xmlUrl"); if (feed != null && feed.trim().length() > 0) addMyFeedFromOpml(request, title, feed); } } catch (Exception e) { e.printStackTrace(); upload = false; } return upload; }
From source file:org.miloss.fgsms.presentation.Helper.java
License:Mozilla Public License
public static String PrettyPrintXMLToHtml(String xml) { try {//from w ww . j a v a 2 s . c o m Document doc = DocumentHelper.parseText(xml); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter xw = new XMLWriter(sw, format); xw.write(doc); return Utility.encodeHTML(sw.toString()); } catch (Exception ex) { //LogHelper.getLog().log(Level.INFO, "error creating pretty print xml. It's probably not an xml message: " + ex.getLocalizedMessage()); } try { Document doc = DocumentHelper.parseText(xml.substring(xml.indexOf("<"))); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter xw = new XMLWriter(sw, format); xw.write(doc); return Utility.encodeHTML(sw.toString()); } catch (Exception ex) { //LogHelper.getLog().log(Level.INFO, "error creating pretty print xml. It's probably not an xml message: " + ex.getLocalizedMessage()); } LogHelper.getLog().log(Level.INFO, "error creating pretty print xml. It's probably not an xml message. No action is required."); return Utility.encodeHTML(xml); }
From source file:org.mule.example.loanbroker.transformers.CreditProfileXmlToCreditProfile.java
License:Open Source License
@Override public Object doTransform(Object src, String outputEncoding) throws TransformerException { Document doc = null;//www . j av a2 s. c o m if (src instanceof Document) { doc = (Document) src; } else { try { doc = DocumentHelper.parseText(src.toString()); } catch (DocumentException e) { throw new TransformerException(this, e); } } String history = doc.valueOf("/credit-profile/customer-history"); String score = doc.valueOf("/credit-profile/credit-score"); CreditProfile cp = new CreditProfile(); cp.setCreditHistory(Integer.valueOf(history).intValue()); cp.setCreditScore(Integer.valueOf(score).intValue()); return cp; }
From source file:org.mule.intents.model.Module.java
License:Open Source License
public Document loadConfig() throws IOException, DocumentException { if (getConfigUri() == null) return null; File f = new File(getDefinitionFile().getParentFile(), getConfigUri().toString()); return DocumentHelper.parseText(IOUtils.toString(new FileInputStream(f))); }
From source file:org.mule.intents.model.Template.java
License:Open Source License
public Document loadSnippet() throws IOException, DocumentException { File f = new File(module.getDefinitionFile().getParentFile(), getSnippetUri()); return DocumentHelper.parseText(IOUtils.toString(new FileInputStream(f))); }