List of usage examples for org.dom4j Node selectSingleNode
Node selectSingleNode(String xpathExpression);
selectSingleNode
evaluates an XPath expression and returns the result as a single Node
instance.
From source file:org.danann.cernunnos.core.InvokeMethodTask.java
License:Apache License
public void init(EntityConfig config) { super.init(config); // Instance Members. this.object = (Phrase) config.getValue(OBJECT); this.clazz = (Phrase) config.getValue(CLASS); this.method = (Phrase) config.getValue(METHOD); this.parameters = new LinkedList<Phrase>(); this.parameter_types = new LinkedList<Phrase>(); List<?> nodes = (List<?>) config.getValue(PARAMETERS); for (Iterator<?> it = nodes.iterator(); it.hasNext();) { Node n = (Node) it.next(); parameters.add(config.getGrammar().newPhrase(n)); // See if a type was explicitly specified... Node y = n.selectSingleNode("../@type"); if (y != null) { parameter_types.add(config.getGrammar().newPhrase(y)); } else {// w w w . j a va 2 s.co m // We need to order this list in parity w/ the other list... parameter_types.add(null); } } this.attribute_name = (Phrase) config.getValue(ATTRIBUTE_NAME); }
From source file:org.esupportail.lecture.domain.model.ChannelConfig.java
/** * @param channel/* w w w. j a va 2 s.c o m*/ */ @SuppressWarnings("unchecked") public static void loadContextsAndCategoryprofiles(final Channel channel) { if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles()"); } String categoryProfileId = ""; Node channelConfig = xmlFile.getRootElement(); List<Node> contexts = channelConfig.selectNodes("context"); for (Node context : contexts) { Context c = new Context(); c.setId(context.valueOf("@id")); c.setName(context.valueOf("@name")); //treeVisible String treeVisible = context.valueOf("@treeVisible"); if (treeVisible.equals("no")) { c.setTreeVisible(TreeDisplayMode.NOTVISIBLE); } else if (treeVisible.equals("forceNo")) { c.setTreeVisible(TreeDisplayMode.NEVERVISIBLE); } else { c.setTreeVisible(TreeDisplayMode.VISIBLE); } if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : contextId " + c.getId()); } Node description = context.selectSingleNode("description"); c.setDescription(description.getStringValue()); List<Node> refCategoryProfiles = context.selectNodes("refCategoryProfile"); // Lire les refCategoryProfilesUrl puis : // - les transformer en refCategoryProfile ds le context // - ajouter les categoryProfile // A faire dans checkXmlFile ? Map<String, Integer> orderedCategoryIDs = Collections.synchronizedMap(new HashMap<String, Integer>()); int xmlOrder = 1; // On parcours les refCategoryProfile de context for (Node refCategoryProfile : refCategoryProfiles) { String refId; // Ajout mcp refId = refCategoryProfile.valueOf("@refId"); if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : refCategoryProfileId " + refId); } List<Node> categoryProfiles = channelConfig.selectNodes("categoryProfile"); // On parcours les categoryProfile de root for (Node categoryProfile : categoryProfiles) { categoryProfileId = categoryProfile.valueOf("@id"); if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : is categoryProfileId " + categoryProfileId + " matching ?"); } if (categoryProfileId.compareTo(refId) == 0) { if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : categoryProfileId " + refId + " matches... create mcp"); } ManagedCategoryProfile mcp = new ManagedCategoryProfile(); // Id = long Id String mcpProfileID = categoryProfileId; mcp.setFileId(c.getId(), mcpProfileID); if (LOG.isDebugEnabled()) { LOG.debug("loadContextsAndCategoryprofiles() : categoryProfileId " + mcp.getId() + " matches... create mcp"); } mcp.setName(categoryProfile.valueOf("@name")); mcp.setCategoryURL(categoryProfile.valueOf("@urlCategory")); mcp.setTrustCategory(getBoolean(categoryProfile.valueOf("@trustCategory"), false)); mcp.setUserCanMarkRead(getBoolean(categoryProfile.valueOf("@userCanMarkRead"), true)); String specificUserContentValue = categoryProfile.valueOf("@specificUserContent"); if (specificUserContentValue.equals("yes")) { mcp.setSpecificUserContent(true); } else { mcp.setSpecificUserContent(false); } String ttl = categoryProfile.valueOf("@ttl"); mcp.setTtl(Integer.parseInt(ttl)); String timeout = categoryProfile.valueOf("@timeout"); mcp.setTimeOut(Integer.parseInt(timeout)); mcp.setName(categoryProfile.valueOf("@name")); // Accessibility String access = categoryProfile.valueOf("@access"); if (access.equalsIgnoreCase("public")) { mcp.setAccess(Accessibility.PUBLIC); } else if (access.equalsIgnoreCase("cas")) { mcp.setAccess(Accessibility.CAS); } // Visibility VisibilitySets visibilitySets = new VisibilitySets(); // foreach (allowed / autoSubscribed / Obliged visibilitySets.setAllowed(loadDefAndContentSets("allowed", categoryProfile)); visibilitySets.setAutoSubscribed(loadDefAndContentSets("autoSubscribed", categoryProfile)); visibilitySets.setObliged(loadDefAndContentSets("obliged", categoryProfile)); mcp.setVisibility(visibilitySets); channel.addManagedCategoryProfile(mcp); c.addRefIdManagedCategoryProfile(mcp.getId()); orderedCategoryIDs.put(mcp.getId(), xmlOrder); break; } } xmlOrder += 1; } c.setOrderedCategoryIDs(orderedCategoryIDs); channel.addContext(c); } }
From source file:org.fao.fenix.wds.core.xml.XMLTools.java
License:Open Source License
@SuppressWarnings("unchecked") public static Map<String, String> readCollection(String xml, String[] tags, String nameTag, String valueTag, String root) throws WDSException { Map<String, String> m = new HashMap<String, String>(); try {/*from w ww. java2 s .c o m*/ Document document = parse(xml); List l = document.selectNodes(buildXPathExpression(tags, root)); for (int i = 0; i < l.size(); i++) { Node parameters = (Node) l.get(i); Node name = parameters.selectSingleNode(nameTag); Node value = parameters.selectSingleNode(valueTag); m.put(name.getText(), value.getText()); } } catch (Exception e) { throw new WDSException(e.getMessage()); } return m; }
From source file:org.fao.fenix.wds.core.xml.XMLTools.java
License:Open Source License
@SuppressWarnings("unchecked") public static Map<String, String> readCollection(String xml, String[] tags, String valueTag, String root) throws WDSException { Map<String, String> m = new HashMap<String, String>(); try {/*from w w w . jav a2 s. c om*/ Document document = parse(xml); List l = document.selectNodes(buildXPathExpression(tags, root)); for (int i = 0; i < l.size(); i++) { Node parameters = (Node) l.get(i); Node value = parameters.selectSingleNode(valueTag); m.put(valueTag, value.getText()); } } catch (Exception e) { throw new WDSException(e.getMessage()); } return m; }
From source file:org.gbif.portal.service.impl.TaxonomyManagerImpl.java
License:Open Source License
/** * This is currently dependent on the Yahoo Image Search Web Service. * TODO review use of DOM4j and XPath//from w w w. ja va 2 s . c o m * * @see org.gbif.portal.service.TaxonomyManager#findImagesForScientificName(java.lang.String, * org.gbif.portal.dto.util.SearchConstraints) */ @SuppressWarnings("unchecked") protected SearchResultsDTO findImagesForScientificName(String scientificName, SearchConstraints searchConstraints) throws ServiceException { try { scientificName = URLEncoder.encode(scientificName, "UTF-8"); String searchUrlAsString = imageWebServiceBaseURL + scientificName + "&results=" + searchConstraints.getMaxResults(); SAXReader xmlReader = new SAXReader(); URL searchUrl = new URL(searchUrlAsString); Document doc = xmlReader.read(searchUrl); Element resultSetElement = doc.getRootElement(); /* * // To use namespace uri's then this is correct * // look at the property store namespace for BIOCASE and see the XPATH objects being created in config * // This file would then have * // - getResultsXPath() * // - getTitleXPath() etc etc etc * Map<String, String> namespaceURIs = new HashMap<String,String>(); * namespaceURIs.put("y", "urn:yahoo:srchmi"); * XPath xpath = new DefaultXPath("//y:Result"); * xpath.setNamespaceURIs(namespaceURIs); * List<Node> results =(List<Node>) xpath.selectNodes(doc); */ List<Node> results = resultSetElement.selectNodes("//*[local-name()='Result']"); SearchResultsDTO searchResults = new SearchResultsDTO(); for (Node result : results) { String title = result.selectSingleNode("//*[local-name()='Title']").getText(); String description = result.selectSingleNode("//*[local-name()='Summary']").getText(); String url = result.selectSingleNode("//*[local-name()='Url']").getText(); String height = result.selectSingleNode("//*[local-name()='Height']").getText(); String width = result.selectSingleNode("//*[local-name()='Width']").getText(); // String fileFormat = result.selectSingleNode("//*[local-name()='FileFormat']").getText(); ImageRecordDTO imageDTO = new ImageRecordDTO(); imageDTO.setUrl(url); imageDTO.setTitle(title); imageDTO.setDescription(description); if (StringUtils.isNotEmpty(height)) imageDTO.setHeightInPixels(Integer.parseInt(height)); if (StringUtils.isNotEmpty(width)) imageDTO.setWidthInPixels(Integer.parseInt(width)); String thumbnailUrl = ((Node) result .selectNodes("//*[local-name()='Thumbnail']/*[local-name()='Url']").get(0)).getText(); // String thumbnailHeight = // ((Node)result.selectNodes("//*[local-name()='Thumbnail']/*[local-name()='Height']").get(0)).getText(); // String thumbnailWidth = // ((Node)result.selectNodes("//*[local-name()='Thumbnail']/*[local-name()='Width']").get(0)).getText(); imageDTO.setUrl(thumbnailUrl); // if(StringUtils.isNotEmpty(thumbnailHeight)) // imageDTO.setThumbnailHeightInPixels(Integer.parseInt(thumbnailHeight)); // if(StringUtils.isNotEmpty(width)) // imageDTO.setThumbnailWidthInPixels(Integer.parseInt(thumbnailWidth)); searchResults.addResult(imageDTO); } return searchResults; } catch (IOException e) { logger.error(e.getMessage(), e); } catch (DocumentException e) { logger.error(e.getMessage(), e); } return new SearchResultsDTO(); }
From source file:org.infoglue.cms.controllers.kernel.impl.simple.ShortcutController.java
License:Open Source License
/** * Returns a list of all available shortcuts defined in the system including personal * @param userPrincipal a user principal * @return a list ShortcutVOs representing available shortcuts *//*from ww w. j a v a 2 s . c o m*/ public List getAvailableShortcutVOList(InfoGluePrincipal userPrincipal) throws SystemException { List availableShortcutVOList = new ArrayList(); try { Map args = new HashMap(); args.put("globalKey", "infoglue"); PropertySet propertySet = PropertySetManager.getInstance("jdbc", args); String xml = getDataPropertyValue(propertySet, "serverNode_-1_shortcuts"); logger.info("xml:" + xml); if (xml != null) { DOMBuilder domBuilder = new DOMBuilder(); Document document = domBuilder.getDocument(xml); List nodes = document.getRootElement().selectNodes("shortcut"); logger.info("nodes:" + nodes.size()); Iterator nodesIterator = nodes.iterator(); while (nodesIterator.hasNext()) { Node node = (Node) nodesIterator.next(); logger.info("Node:" + node.asXML()); Node nameNode = node.selectSingleNode("name"); Node urlNode = node.selectSingleNode("url"); Node popupNode = node.selectSingleNode("popup"); String name = nameNode.getStringValue(); String url = urlNode.getStringValue(); String popup = popupNode.getStringValue(); ShortcutVO shortcut = new ShortcutVO(name, url, Boolean.valueOf(popup).booleanValue()); availableShortcutVOList.add(shortcut); } } } catch (Exception e) { logger.error("An error occurred when reading shortcuts:" + e.getMessage(), e); } return availableShortcutVOList; }
From source file:org.infoglue.igide.cms.connection.InfoglueProxy.java
License:Open Source License
public static NotificationMessage createNotificationMessage(InfoglueConnection connection, String data) throws DocumentException { System.out.println("Creating notification message:" + data); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(data)); Node node = document.selectSingleNode("/org.infoglue.cms.util.NotificationMessage"); NotificationMessage message = new NotificationMessage(connection, node.selectSingleNode("name").getText(), node.selectSingleNode("objectName").getText(), node.selectSingleNode("systemUserName").getText(), toInteger(node.selectSingleNode("type").getText()).intValue(), node.selectSingleNode("objectId").getText(), node.selectSingleNode("className").getText()); Node extraInfo = node.selectSingleNode("extraInfo"); try {/*from w w w . j a va 2 s .c om*/ int hashCode = new Integer(extraInfo.valueOf("@hashCode")).intValue(); String modifier = extraInfo.valueOf("@versionModifier"); message.setVersionModifier(modifier); message.setHashCode(hashCode); } catch (Exception e) { } String value = ""; return message; }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceGroupProvider.java
License:Open Source License
/** * Translate a XML response of a group to a <code>Group</code>. * * @param responseNode the XML representation of a CS group. * @return the group that corresponds to the XML. *//*from ww w . j av a 2 s . c o m*/ private Group translateGroup(Element responseNode) { Node groupNode = responseNode.selectSingleNode("return"); // Gets the CS DISPLAY NAME that is OF NAME String name = groupNode.selectSingleNode("displayName").getText(); // Gets the CS NAME that is OF DISPLAY NAME String displayName = groupNode.selectSingleNode("name").getText(); // Gets the group ID long id = Long.parseLong(groupNode.selectSingleNode("ID").getText()); // Gets the group type int type = Integer.parseInt(groupNode.selectSingleNode("typeID").getText()); // Gets the group description if it exist String description = null; Node tmpNode = groupNode.selectSingleNode("description"); if (tmpNode != null) { description = tmpNode.getText(); } // Get the members and administrators Collection<JID> members = new ArrayList<JID>(); Collection<JID> administrators = new ArrayList<JID>(); try { XMPPServer server = XMPPServer.getInstance(); // Gets the JID from the response List<Element> membersElement = (List<Element>) getGroupMembers(id).elements("return"); for (Element memberElement : membersElement) { String username = memberElement.element("user").element("username").getText(); // Escape username to accept usernames with @ or spaces String escapedUsername = JID.escapeNode(username); String typeID = memberElement.element("typeID").getText(); if (TYPE_ID_OWNER.equals(typeID)) { administrators.add(server.createJID(escapedUsername, null)); } else if (TYPE_ID_MEMBER.equals(typeID)) { members.add(server.createJID(escapedUsername, null)); } else { // nothing to do, waiting for approval } } } catch (GroupNotFoundException e) { // this won't happen, the group exists. } Map<String, String> properties = new HashMap<String, String>(); // Type 0 is OPEN if (type == 0) { properties.put("sharedRoster.showInRoster", "everybody"); } else { // Types 1, 2 or 3 are MEMBER_ONLY, PRIVATE, SECRET properties.put("sharedRoster.showInRoster", "onlyGroup"); } properties.put("sharedRoster.displayName", displayName); properties.put("sharedRoster.groupList", ""); // Creates the group // There are some interesting things happening here. // If this is the first time that this group is loaded from CS, the OF will save this properties. // If this is not the first time and these properties haven't changed, then nothing happens // If this is not the first time but these properties have changed, then OF will update it's saved data. // And this is OK, event if this "getGroup" is to be used in a "change group properties event", the group should // always show the last information. return new Group(name, description, members, administrators, properties); }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceLockOutProvider.java
License:Open Source License
/** * Examines the XML returned about a user to find out if they are enabled or disabled. Returns * <tt>null</tt> when user can log in or a LockOutFlag if user cannot log in. * * @param responseNode Element returned from REST service. (@see #getUserByUsername) * @return Either a LockOutFlag indicating that the user is disabled, or null if everything is fine. *//*from w w w. j a v a 2s. c o m*/ private LockOutFlag checkUserDisabled(Node responseNode) { try { Node userNode = responseNode.selectSingleNode("return"); // Gets the username String username = userNode.selectSingleNode("username").getText(); // Escape the username so that it can be used as a JID. username = JID.escapeNode(username); // Gets the enabled field boolean isEnabled = Boolean.valueOf(userNode.selectSingleNode("enabled").getText()); if (isEnabled) { // We're good, indicate that they're not locked out. return null; } else { // Creates the lock out flag return new LockOutFlag(username, null, null); } } catch (Exception e) { // Hrm. This is not good. We have to opt on the side of positive. Log.error("Error while looking up user's disabled status from Clearspace: ", e); return null; } }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceUserProvider.java
License:Open Source License
/** * Search for the user using the userService/search POST method. * * @param fields the fields to search on. * @param query the query string./*from ww w. j a v a2 s .com*/ * @return a Collection of users that match the search. * @throws UnsupportedOperationException if the provider does not * support the operation (this is an optional operation). */ public Collection<User> findUsers(Set<String> fields, String query) throws UnsupportedOperationException { // Creates the XML with the data Element paramsE = DocumentHelper.createDocument().addElement("search"); Element queryE = paramsE.addElement("query"); queryE.addElement("keywords").addText(query); queryE.addElement("searchUsername").addText("true"); queryE.addElement("searchName").addText("true"); queryE.addElement("searchEmail").addText("true"); queryE.addElement("searchProfile").addText("false"); List<String> usernames = new ArrayList<String>(); try { //TODO create a service on CS to get only the username field String path = SEARCH_URL_PREFIX + "searchProfile"; Element element = ClearspaceManager.getInstance().executeRequest(POST, path, paramsE.asXML()); List<Node> userNodes = (List<Node>) element.selectNodes("return"); for (Node userNode : userNodes) { String username = userNode.selectSingleNode("username").getText(); // Escape the username so that it can be used as a JID. username = JID.escapeNode(username); // Encode potentially non-ASCII characters username = URLUTF8Encoder.encode(username); usernames.add(username); } } catch (Exception e) { Log.error(e.getMessage(), e); } return new UserCollection(usernames.toArray(new String[usernames.size()])); }