List of usage examples for org.dom4j Node selectNodes
List<Node> selectNodes(String xpathExpression);
selectNodes
evaluates an XPath expression and returns the result as a List
of Node
instances or String
instances depending on the XPath expression.
From source file:org.craftercms.studio.impl.v1.service.notification.NotificationServiceImpl.java
License:Open Source License
/** * load canned messages from the configuration file * * @param config//from ww w . ja v a2 s .co m * notification config to store messages * @param nodes * canned messages nodes * @return a list of canned messages */ @SuppressWarnings("unchecked") protected void loadCannedMessages(final NotificationConfigTO config, final List<Node> nodes) { if (nodes != null) { Map<String, List<MessageTO>> messageMap = new HashMap<String, List<MessageTO>>(); for (Node listNode : nodes) { String name = listNode.valueOf("@name"); if (!StringUtils.isEmpty(name)) { List<Node> messageNodes = listNode.selectNodes("message"); if (messageNodes != null) { List<MessageTO> messages = new ArrayList<MessageTO>(messageNodes.size()); for (Node messageNode : messageNodes) { MessageTO message = new MessageTO(); message.setTitle(messageNode.valueOf("title")); message.setBody(messageNode.valueOf("body")); message.setKey(((Element) messageNode).attributeValue("key", "")); messages.add(message); } messageMap.put(name, messages); } } } config.setCannedMessages(messageMap); } }
From source file:org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl.java
License:Open Source License
protected Set<String> populateUserGlobalPermissions(String path, Set<String> roles, PermissionsConfigTO permissionsConfig) { Set<String> permissions = new HashSet<String>(); if (roles != null && !roles.isEmpty()) { for (String role : roles) { Map<String, Map<String, List<Node>>> permissionsMap = permissionsConfig.getPermissions(); Map<String, List<Node>> siteRoles = permissionsMap.get("###GLOBAL###"); if (siteRoles == null || siteRoles.isEmpty()) { siteRoles = permissionsMap.get("*"); }//from www . jav a 2 s . c o m if (siteRoles != null && !siteRoles.isEmpty()) { List<Node> ruleNodes = siteRoles.get(role); if (ruleNodes == null || ruleNodes.isEmpty()) { ruleNodes = siteRoles.get("*"); } if (ruleNodes != null && !ruleNodes.isEmpty()) { for (Node ruleNode : ruleNodes) { String regex = ruleNode.valueOf(StudioXmlConstants.DOCUMENT_ATTR_REGEX); if (path.matches(regex)) { logger.debug("Global permissions found by matching " + regex + " for " + role); List<Node> permissionNodes = ruleNode .selectNodes(StudioXmlConstants.DOCUMENT_ELM_ALLOWED_PERMISSIONS); for (Node permissionNode : permissionNodes) { String permission = permissionNode.getText().toLowerCase(); logger.debug("adding global permissions " + permission + " to " + path + " for " + role); permissions.add(permission); } } } } else { logger.debug("No default role is set. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If no default role is set permissions.add(StudioConstants.PERMISSION_VALUE_READ); } } else { logger.debug("No default site is set. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If no default site is set permissions.add(StudioConstants.PERMISSION_VALUE_READ); } } } else { logger.debug("No user or group matching found. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If user or group did not match the roles-mapping file permissions.add(StudioConstants.PERMISSION_VALUE_READ); } return permissions; }
From source file:org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl.java
License:Open Source License
/** * populate user permissions//from www. j av a 2 s. c om * * @param site * @param path * @param roles * @param permissionsConfig */ protected Set<String> populateUserPermissions(String site, String path, Set<String> roles, PermissionsConfigTO permissionsConfig) { Set<String> permissions = new HashSet<String>(); if (roles != null && !roles.isEmpty()) { for (String role : roles) { Map<String, Map<String, List<Node>>> permissionsMap = permissionsConfig.getPermissions(); Map<String, List<Node>> siteRoles = permissionsMap.get(site); if (siteRoles == null || siteRoles.isEmpty()) { siteRoles = permissionsMap.get("*"); } if (siteRoles != null && !siteRoles.isEmpty()) { List<Node> ruleNodes = siteRoles.get(role); if (ruleNodes == null || ruleNodes.isEmpty()) { ruleNodes = siteRoles.get("*"); } if (ruleNodes != null && !ruleNodes.isEmpty()) { for (Node ruleNode : ruleNodes) { String regex = ruleNode.valueOf(StudioXmlConstants.DOCUMENT_ATTR_REGEX); if (path.matches(regex)) { logger.debug( "Permissions found by matching " + regex + " for " + role + " in " + site); List<Node> permissionNodes = ruleNode .selectNodes(StudioXmlConstants.DOCUMENT_ELM_ALLOWED_PERMISSIONS); for (Node permissionNode : permissionNodes) { String permission = permissionNode.getText().toLowerCase(); logger.debug("adding permissions " + permission + " to " + path + " for " + role + " in " + site); permissions.add(permission); } } } } else { logger.debug("No default role is set. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If no default role is set permissions.add(StudioConstants.PERMISSION_VALUE_READ); } } else { logger.debug("No default site is set. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If no default site is set permissions.add(StudioConstants.PERMISSION_VALUE_READ); } } } else { logger.debug("No user or group matching found. adding default permission: " + StudioConstants.PERMISSION_VALUE_READ); // If user or group did not match the roles-mapping file permissions.add(StudioConstants.PERMISSION_VALUE_READ); } return permissions; }
From source file:org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl.java
License:Open Source License
@SuppressWarnings("unchecked") protected Map<String, List<String>> getRoles(List<Node> nodes, Map<String, List<String>> rolesMap) { for (Node node : nodes) { String name = node.valueOf(StudioXmlConstants.DOCUMENT_ATTR_PERMISSIONS_NAME); if (!StringUtils.isEmpty(name)) { List<Node> roleNodes = node.selectNodes(StudioXmlConstants.DOCUMENT_ELM_PERMISSION_ROLE); List<String> roles = new ArrayList<String>(); for (Node roleNode : roleNodes) { roles.add(roleNode.getText()); }/* ww w. ja va2 s. c o m*/ rolesMap.put(name, roles); } } return rolesMap; }
From source file:org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl.java
License:Open Source License
@SuppressWarnings("unchecked") protected void loadPermissions(Element root, PermissionsConfigTO config) { if (root.getName().equals(StudioXmlConstants.DOCUMENT_PERMISSIONS)) { Map<String, Map<String, List<Node>>> permissionsMap = new HashMap<String, Map<String, List<Node>>>(); List<Node> siteNodes = root.selectNodes(StudioXmlConstants.DOCUMENT_ELM_SITE); for (Node siteNode : siteNodes) { String siteId = siteNode.valueOf(StudioXmlConstants.DOCUMENT_ATTR_SITE_ID); if (!StringUtils.isEmpty(siteId)) { List<Node> roleNodes = siteNode.selectNodes(StudioXmlConstants.DOCUMENT_ELM_PERMISSION_ROLE); Map<String, List<Node>> rules = new HashMap<String, List<Node>>(); for (Node roleNode : roleNodes) { String roleName = roleNode.valueOf(StudioXmlConstants.DOCUMENT_ATTR_PERMISSIONS_NAME); List<Node> ruleNodes = roleNode .selectNodes(StudioXmlConstants.DOCUMENT_ELM_PERMISSION_RULE); rules.put(roleName, ruleNodes); }// w w w. ja v a2s . com permissionsMap.put(siteId, rules); } } config.setPermissions(permissionsMap); } }
From source file:org.danann.cernunnos.xml.NodeIteratorTask.java
License:Apache License
public void perform(TaskRequest req, TaskResponse res) { Node srcNode = (Node) source.evaluate(req, res); List nodes = srcNode.selectNodes((String) xpath.evaluate(req, res)); String name = (String) attribute_name.evaluate(req, res); for (Iterator it = nodes.iterator(); it.hasNext();) { Node n = (Node) it.next(); res.setAttribute(name, n);//from ww w . ja v a 2s . c o m super.performSubtasks(req, res); } }
From source file:org.esupportail.lecture.domain.model.ChannelConfig.java
/** * Load a DefinitionSets that is used to define visibility groups of a managed category profile. * @param fatherName name of the father XML element refered to (which visibility group) * @param categoryProfile//from w ww .ja v a2 s.c o m * @return the initialized DefinitionSets */ @SuppressWarnings("unchecked") private static synchronized DefinitionSets loadDefAndContentSets(final String fatherName, final Node categoryProfile) { DefinitionSets defAndContentSets = new DefinitionSets(); // pathCategoryProfile = "categoryProfile(" + j + ")"; // String fatherPath = pathCategoryProfile + ".visibility." + fatherName; String fatherPath = "visibility/" + fatherName + "/group"; if (LOG.isDebugEnabled()) { LOG.debug("loadDefAndContentSets(" + fatherName + "," + categoryProfile.valueOf("@id") + ")"); } List<Node> groups = categoryProfile.selectNodes(fatherPath); for (Node group : groups) { defAndContentSets.addGroup(group.valueOf("@name")); } fatherPath = "visibility/" + fatherName + "/regular"; List<Node> regulars = categoryProfile.selectNodes(fatherPath); for (Node regular : regulars) { RegularOfSet regularOfSet = new RegularOfSet(); regularOfSet.setAttribute(regular.valueOf("@attribute")); regularOfSet.setValue(regular.valueOf("@value")); defAndContentSets.addRegular(regularOfSet); } fatherPath = "visibility/" + fatherName + "/regex"; List<Node> regexs = categoryProfile.selectNodes(fatherPath); for (Node regex : regexs) { RegexOfSet regexOfSet = new RegexOfSet(); regexOfSet.setAttribute(regex.valueOf("@attribute")); regexOfSet.setPattern(regex.valueOf("@pattern")); defAndContentSets.addRegex(regexOfSet); } return defAndContentSets; }
From source file:org.esupportail.lecture.domain.model.ChannelConfig.java
/** * @param channel// ww w . jav a2 s . c om */ @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.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 . j a v a 2 s . c om * * @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.igide.cms.InfoglueCMS.java
License:Open Source License
public static Map<String, ContentTypeAttribute> getContentTypeAttributes(String schemaValue) { Map<String, ContentTypeAttribute> attributes = new HashMap<String, ContentTypeAttribute>(); try {// w w w.j a v a2s . co m SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(schemaValue)); // Document document = reader.read(new java.io.ByteArrayInputStream(schemaValue.getBytes())); String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element"; @SuppressWarnings("unchecked") List<Element> anl = document.selectNodes(attributesXPath); // XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); int cnt = 0; for (Iterator<Element> i = anl.iterator(); i.hasNext();) { cnt++; Element child = i.next(); String attributeName = child.valueOf("@name"); String attributeType = child.valueOf("@type"); ContentTypeAttribute contentTypeAttribute = new ContentTypeAttribute(); contentTypeAttribute.setPosition(cnt); contentTypeAttribute.setName(attributeName); contentTypeAttribute.setInputType(attributeType); //attributes.put(contentTypeAttribute.getName(), contentTypeAttribute); attributes.put(contentTypeAttribute.getName(), contentTypeAttribute); // Get extra parameters org.dom4j.Node paramsNode = child.selectSingleNode("xs:annotation/xs:appinfo/params"); if (paramsNode != null) { @SuppressWarnings("unchecked") List<Element> childnl = paramsNode.selectNodes("param"); for (Iterator<Element> i2 = childnl.iterator(); i2.hasNext();) { Element param = i2.next(); String paramId = param.valueOf("@id"); String paramInputTypeId = param.valueOf("@inputTypeId"); ContentTypeAttributeParameter contentTypeAttributeParameter = new ContentTypeAttributeParameter(); contentTypeAttributeParameter.setId(paramId); if (paramInputTypeId != null && paramInputTypeId.length() > 0) contentTypeAttributeParameter.setType(Integer.parseInt(paramInputTypeId)); contentTypeAttribute.putContentTypeAttributeParameter(paramId, contentTypeAttributeParameter); @SuppressWarnings("unchecked") List<Element> valuesNodeList = param.selectNodes("values"); for (Iterator<Element> i3 = valuesNodeList.iterator(); i3.hasNext();) { Element values = i3.next(); @SuppressWarnings("unchecked") List<Element> valueNodeList = values.selectNodes("value"); String valueId; ContentTypeAttributeParameterValue contentTypeAttributeParameterValue; for (Iterator<Element> i4 = valueNodeList.iterator(); i4 .hasNext(); contentTypeAttributeParameter.addContentTypeAttributeParameterValue( valueId, contentTypeAttributeParameterValue)) { Element value = i4.next(); valueId = value.valueOf("@id"); contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue(); contentTypeAttributeParameterValue.setId(valueId); @SuppressWarnings("unchecked") List<Attribute> nodeMap = value.attributes(); String valueAttributeName; String valueAttributeValue; for (Iterator<Attribute> i5 = nodeMap.iterator(); i5 .hasNext(); contentTypeAttributeParameterValue .addAttribute(valueAttributeName, valueAttributeValue)) { Attribute attribute = i5.next(); valueAttributeName = attribute.getName(); valueAttributeValue = attribute.getValue(); } } } } } // End extra parameters //comparator.appendToStaticCompareString(contentTypeAttribute.getName()); } } catch (Exception e) { Logger.logInfo( "An error occurred when we tried to get the attributes of the content type: " + e.getMessage()); } return attributes; }