List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:org.esupportail.lecture.domain.model.ChannelConfig.java
/** * Check syntax file that cannot be checked by DTD. * @param xmlFileChecked//from w w w. jav a 2 s. co m * @return xmlFileLoading */ @SuppressWarnings("unchecked") private synchronized static Document checkConfigFile(Document xmlFileChecked) { if (LOG.isDebugEnabled()) { LOG.debug("checkXmlFile()"); } // Merge categoryProfilesUrl and check number of contexts + categories Document xmlFileLoading = xmlFileChecked; Element channelConfig = xmlFileLoading.getRootElement(); List<Element> contexts = channelConfig.selectNodes("context"); nbContexts = contexts.size(); if (nbContexts == 0) { LOG.warn("No context declared in channel config (esup-lecture.xml)"); } // 1. merge categoryProfilesUrls and refCategoryProfile for (Element context : contexts) { List<Node> nodes = context.selectNodes("categoryProfilesUrl|refCategoryProfile"); for (Node node : nodes) { //Is a refCategoryProfile ? if (node.getName().equals("refCategoryProfile")) { //remove from context (from its current place in original XML file) context.remove(node); //add to context (at the end of new constructed context: With merged refCategoryProfile from categoryProfilesUrl) context.add(node); } else { String categoryProfilesUrlPath = node.valueOf("@url"); //URL url = ChannelConfig.class.getResource(categoryProfilesUrlPath); String idPrefix = node.valueOf("@idPrefix"); if ((categoryProfilesUrlPath == null) || (categoryProfilesUrlPath == "")) { String errorMsg = "URL of : categoryProfilesUrl with prefix " + idPrefix + " is null or empty."; LOG.warn(errorMsg); } else { Document categoryProfilesFile = getFreshConfigFile(categoryProfilesUrlPath); if (categoryProfilesFile == null) { String errorMsg = "Impossible to load categoryProfilesUrl " + categoryProfilesUrlPath; LOG.warn(errorMsg); } else { // merge one categoryProfilesUrl // add categoryProfile Element rootCategoryProfilesFile = categoryProfilesFile.getRootElement(); // replace ids with IdPrefix + "-" + id List<Element> categoryProfiles = rootCategoryProfilesFile.elements(); for (Element categoryProfile : categoryProfiles) { String categoryProfileId = idPrefix + "-" + categoryProfile.valueOf("@id"); //String categoryProfileName = categoryProfile.valueOf("@name"); categoryProfile.addAttribute("id", categoryProfileId); Element categoryProfileAdded = categoryProfile.createCopy(); channelConfig.add(categoryProfileAdded); // delete node categoryProfilesUrl ? // add refCategoryProfile context.addElement("refCategoryProfile").addAttribute("refId", categoryProfileId); } } } //remove now unneeded categoryProfilesUrl context.remove(node); } } } List<Node> categoryProfiles = channelConfig.selectNodes("categoryProfile"); nbProfiles = categoryProfiles.size(); if (nbProfiles == 0) { LOG.warn("checkXmlConfig :: No managed category profile declared in channel config"); } return xmlFileLoading; }
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 va2s.c om * @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// w w w .ja va 2s . 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.esupportail.lecture.domain.model.MappingFile.java
/** * Check syntax file that cannot be checked by DTD. * @param xmlFileChecked //from w w w . j a va2s .c o m * @return Document * @throws MappingFileException */ @SuppressWarnings("unchecked") private synchronized static Document checkMappingFile(Document xmlFileChecked) throws MappingFileException { if (LOG.isDebugEnabled()) { LOG.debug("checkXmlFile()"); } // Merge categoryProfilesUrl and check number of contexts + categories Document xmlFileLoading = xmlFileChecked; Element mappingFile = xmlFileLoading.getRootElement(); List<Element> mappings = mappingFile.selectNodes("mapping"); nbMappings = mappings.size(); if (nbMappings == 0) { LOG.warn("No mapping declared in mapping file (mappings.xml)"); } mappingList = new ArrayList<Mapping>(); for (Element mapping : mappings) { Mapping m = new Mapping(); String sourceURL = mapping.valueOf("@sourceURL"); String dtd = mapping.valueOf("@dtd"); String xmlns = mapping.valueOf("@xmlns"); String xmlType = mapping.valueOf("@xmlType"); String rootElement = mapping.valueOf("@rootElement"); if (sourceURL == null) { sourceURL = ""; } if (dtd == null) { dtd = ""; } if (xmlns == null) { xmlns = ""; } if (xmlType == null) { xmlType = ""; } if (rootElement == null) { rootElement = ""; } if (sourceURL + dtd + xmlns + xmlType + rootElement == "") { String errorMsg = "In mappingFile, a mapping element " + "is empty, you must declare sourceURL or dtd or " + "xmlns or xmltype or rootElement in a mapping."; LOG.error(errorMsg); throw new MappingFileException(errorMsg); } m.setSourceURL(sourceURL); m.setDtd(dtd); m.setXmlns(xmlns); m.setXmlType(xmlType); m.setRootElement(rootElement); m.setXsltUrl(mapping.valueOf("@xsltFile")); m.setItemXPath(mapping.valueOf("@itemXPath")); String mobileXsltFile = mapping.valueOf("@mobileXsltFile"); if (mobileXsltFile == null || mobileXsltFile.equals("")) { m.setMobileXsltUrl(m.getXsltUrl()); } else { m.setMobileXsltUrl(mobileXsltFile); } //loop on XPathNameSpace List<Node> xPathNameSpaces = mapping.selectNodes("XPathNameSpace"); HashMap<String, String> xPathNameSpacesHash = new HashMap<String, String>(); for (Node xPathNameSpace : xPathNameSpaces) { String prefix = xPathNameSpace.valueOf("@prefix"); String uri = xPathNameSpace.valueOf("@uri"); xPathNameSpacesHash.put(prefix, uri); } m.setXPathNameSpaces(xPathNameSpacesHash); mappingList.add(m); } return xmlFileLoading; }
From source file:org.fao.fenix.wds.core.xml.XMLTools.java
License:Open Source License
public static String readAttribute(String xml, String attribute) throws WDSException { try {/*w w w. ja va 2 s . c om*/ Document document = parse(xml); Node root = document.getRootElement(); return root.valueOf("@" + attribute); } catch (NullPointerException e) { return null; } }
From source file:org.infoglue.igide.cms.connection.InfoglueProxy.java
License:Open Source License
private static Content deserializeContent(String xml) throws DocumentException, UnsupportedEncodingException { // TODO: set repositoryId and parentContentId SAXReader reader = new SAXReader(); Document document = reader.read(new StringBufferInputStream(xml)); Content content = new Content(); Node node = document.selectSingleNode("/content"); content.setId(toInteger(node.valueOf("@id"))); content.setName(node.valueOf("@name")); content.setCreatorName(node.valueOf("@creatorName")); content.setTypedefid(toInteger(node.valueOf("@typedefid"))); content.setBranch(Boolean.parseBoolean(node.valueOf("@isbranch"))); content.setActiveVersion(toInteger(node.valueOf("@activeVersion"))); content.setActiveVersionStateId(toInteger(node.valueOf("@activeVersionStateId"))); content.setActiveVersionModifier(node.valueOf("@activeVersionModifier")); content.setMasterLanguageId(toInteger(node.valueOf("@initialLanguageId"))); try {//from ww w. j av a 2 s . c o m content.setExpiredatetime(new Date(new Long(node.valueOf("@expiredatetime")).longValue())); content.setPublishdatetime(new Date(new Long(node.valueOf("@publishdatetime")).longValue())); } catch (Exception e) { Logger.logConsole("failed to set date: " + node.valueOf("@expiredatetime")); Logger.logConsole("failed to set date: " + node.valueOf("@publishdatetime")); } List list = document.selectNodes("//content/versions/contentVersion"); for (Iterator iter = list.iterator(); iter.hasNext();) { Element row = (Element) iter.next(); System.out.println("Deserialize content: Found contentVersion: " + row.asXML()); } return content; }
From source file:org.infoglue.igide.cms.connection.InfoglueProxy.java
License:Open Source License
private static ContentVersion deserializeContentVersion(String xml, boolean headonly) throws DocumentException, UnsupportedEncodingException { SAXReader reader = new SAXReader(); Logger.logConsole("Parsing XML:" + xml); Document document = reader.read(new java.io.ByteArrayInputStream(xml.getBytes("UTF-8"))); //Document document = reader.read(new StringBufferInputStream(xml)); Logger.logConsole("document:" + document); ContentVersion contentVersion = new ContentVersion(); String value = ""; Node node = document.selectSingleNode("/contentVersion/head"); System.out.println("Creating contentVersion of: " + node.asXML()); contentVersion.setId(toInteger(node.valueOf("@id"))); contentVersion.setLanguageId(toInteger(node.valueOf("@languageId"))); contentVersion.setContentId(toInteger(node.valueOf("@contentId"))); contentVersion.setStateId(toInteger(node.valueOf("@activeVersionStateId"))); contentVersion.setVersionModifier(node.valueOf("@activeVersionModifier")); contentVersion.setLanguageName(node.valueOf("@languageName")); try {/*from ww w . ja va 2 s . co m*/ contentVersion.setMod(new Date(new Long(node.valueOf("@mod")).longValue())); } catch (Exception e) { System.out.println("failed to set date: " + node.valueOf("@mod")); } contentVersion.setActive(node.valueOf("@isActive").equalsIgnoreCase("true")); if (!headonly) { Node val = document.selectSingleNode("/contentVersion/value"); value = val.getStringValue(); if (enableCompression) { Base64Encoder decoder = new Base64Encoder(); byte[] b_value = decoder.decode(value); CompressionHelper zip = new CompressionHelper(); String decoded = zip.decompress(b_value); contentVersion.setValue(decoded); } else { contentVersion.setValue(URLDecoder.decode(value, "UTF-8")); } } return contentVersion; }
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 {/* w ww . j av a 2 s. com*/ 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.jdbcluster.clustertype.ClusterTypeConfigImpl.java
License:Apache License
/** * returns the name of the specified clustertype * or null if there is none (via xPath)//from ww w.j a va2s . c om * @param CTName ClusterType name * @return String */ public String getClusterType(String CTName) { String xPath = "//jdbcluster/clustertype/cluster[@id='" + CTName + "']"; Node node = document.selectSingleNode(xPath); if (node == null) { return null; } else { return node.valueOf("@id"); } }
From source file:org.jdbcluster.clustertype.ClusterTypeConfigImpl.java
License:Apache License
/** * returns the classname of the given ClusterType * @deprecated use {@link ClusterType.getClusterClass()} instead * @param ct ClusterType//w w w.j av a2 s. c o m * @return String */ @Deprecated public String getClusterClassName(String clusterTypeName) { //xPath expression to get the classname String xPath = "//jdbcluster/clustertype/cluster[@id='" + clusterTypeName + "']"; Node node = document.selectSingleNode(xPath); if (node == null) { return null; } else { //returns the classname as a String return node.valueOf("@class"); } }