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.jivesoftware.openfire.clearspace.ClearspaceUserProvider.java
License:Open Source License
/** * Search for the user using the userService/searchBounded POST method. * * @param fields the fields to search on. * @param query the query string./*from www . j a v a 2 s. c o m*/ * @param startIndex the starting index in the search result to return. * @param numResults the number of users to return in the search result. * @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, int startIndex, int numResults) throws UnsupportedOperationException { // Creates the XML with the data Element paramsE = DocumentHelper.createDocument().addElement("searchBounded"); 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"); paramsE.addElement("startIndex").addText(String.valueOf(startIndex)); paramsE.addElement("numResults").addText(String.valueOf(numResults)); 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()])); }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceUserProvider.java
License:Open Source License
/** * Translates a Clearspace xml user response into a Openfire User * * @param responseNode the Clearspace response * @return a User instance with its information */// w w w . java 2s . co m private User translate(Node responseNode) { String username; String name = null; String email = null; Date creationDate = null; Date modificationDate = null; Node userNode = responseNode.selectSingleNode("return"); Node tmpNode; // Gets the username username = userNode.selectSingleNode("username").getText(); // Escape the username so that it can be used as a JID. username = JID.escapeNode(username); // Gets the name if it is visible boolean nameVisible = Boolean.valueOf(userNode.selectSingleNode("nameVisible").getText()); // Gets the name tmpNode = userNode.selectSingleNode("name"); if (tmpNode != null) { name = tmpNode.getText(); } // Gets the email if it is visible boolean emailVisible = Boolean.valueOf(userNode.selectSingleNode("emailVisible").getText()); // Gets the email tmpNode = userNode.selectSingleNode("email"); if (tmpNode != null) { email = tmpNode.getText(); } // Gets the creation date tmpNode = userNode.selectSingleNode("creationDate"); if (tmpNode != null) { creationDate = WSUtils.parseDate(tmpNode.getText()); } // Gets the modification date tmpNode = userNode.selectSingleNode("modificationDate"); if (tmpNode != null) { modificationDate = WSUtils.parseDate(tmpNode.getText()); } // Creates the user User user = new User(username, name, email, creationDate, modificationDate); user.setNameVisible(nameVisible); user.setEmailVisible(emailVisible); return user; }
From source file:org.jivesoftware.openfire.clearspace.WSUtils.java
License:Open Source License
/** * Returns the text of the first an element with name 'name'. * * @param node the element to search for a "name" element. * @param name the name of the element to search * @return the text of the corresponding element *///from ww w . j a v a 2s .co m protected static String getElementText(Node node, String name) { Node n = node.selectSingleNode(name); if (n != null) { return n.getText(); } return null; }
From source file:org.jivesoftware.openfire.clearspace.WSUtils.java
License:Open Source License
/** * Modifies the text of the elmement with name 'name'. * * @param node the element to search * @param name the name to search//from ww w . ja va2s. c o m * @param newValue the new value of the text */ protected static void modifyElementText(Node node, String name, String newValue) { Node n = node.selectSingleNode(name); n.setText(newValue); }
From source file:org.jivesoftware.openfire.container.PluginCacheConfigurator.java
License:Open Source License
private Map<String, String> readInitParams(Node configData) { Map<String, String> paramMap = new HashMap<String, String>(); List<Node> params = configData.selectNodes("init-params/init-param"); for (Node param : params) { String paramName = param.selectSingleNode("param-name").getStringValue(); String paramValue = param.selectSingleNode("param-value").getStringValue(); paramMap.put(paramName, paramValue); }//from w w w . j a va 2s .c o m return paramMap; }
From source file:org.jivesoftware.spark.PluginManager.java
License:Open Source License
/** * Loads public plugins./*from w w w .j a va 2 s . c o m*/ * * @param pluginDir the directory of the expanded public plugin. * @return the new Plugin model for the Public Plugin. */ private Plugin loadPublicPlugin(File pluginDir) { File pluginFile = new File(pluginDir, "plugin.xml"); SAXReader saxReader = new SAXReader(); Document pluginXML = null; try { pluginXML = saxReader.read(pluginFile); } catch (DocumentException e) { Log.error(e); } Plugin pluginClass = null; List<? extends Node> plugins = pluginXML.selectNodes("/plugin"); for (Node plugin1 : plugins) { PublicPlugin publicPlugin = new PublicPlugin(); String clazz = null; String name; String minVersion; try { name = plugin1.selectSingleNode("name").getText(); clazz = plugin1.selectSingleNode("class").getText(); try { String lower = name.replaceAll("[^0-9a-zA-Z]", "").toLowerCase(); // Dont load the plugin if its on the Blacklist if (_blacklistPlugins.contains(lower) || _blacklistPlugins.contains(clazz) || SettingsManager.getLocalPreferences().getDeactivatedPlugins().contains(name)) { return null; } } catch (Exception e) { // Whatever^^ return null; } // Check for minimum Spark version try { minVersion = plugin1.selectSingleNode("minSparkVersion").getText(); String buildNumber = JiveInfo.getVersion(); boolean ok = buildNumber.compareTo(minVersion) >= 0; if (!ok) { return null; } } catch (Exception e) { Log.error("Unable to load plugin " + name + " due to missing <minSparkVersion>-Tag in plugin.xml."); return null; } // Check for minimum Java version try { String javaversion = plugin1.selectSingleNode("java").getText().replaceAll("[^0-9]", ""); javaversion = javaversion == null ? "0" : javaversion; int jv = Integer.parseInt(attachMissingZero(javaversion)); String myversion = System.getProperty("java.version").replaceAll("[^0-9]", ""); int mv = Integer.parseInt(attachMissingZero(myversion)); boolean ok = (mv >= jv); if (!ok) { Log.error("Unable to load plugin " + name + " due to old JavaVersion.\nIt Requires " + plugin1.selectSingleNode("java").getText() + " you have " + System.getProperty("java.version")); return null; } } catch (NullPointerException e) { Log.warning("Plugin " + name + " has no <java>-Tag, consider getting a newer Version"); } // set dependencies try { List<? extends Node> dependencies = plugin1.selectNodes("depends/plugin"); dependencies.stream().map((depend1) -> (Element) depend1).map((depend) -> { PluginDependency dependency = new PluginDependency(); dependency.setVersion(depend.selectSingleNode("version").getText()); dependency.setName(depend.selectSingleNode("name").getText()); return dependency; }).forEach((dependency) -> { publicPlugin.addDependency(dependency); }); } catch (Exception e) { e.printStackTrace(); } // Do operating system check. boolean operatingSystemOK = isOperatingSystemOK(plugin1); if (!operatingSystemOK) { return null; } publicPlugin.setPluginClass(clazz); publicPlugin.setName(name); try { String version = plugin1.selectSingleNode("version").getText(); publicPlugin.setVersion(version); String author = plugin1.selectSingleNode("author").getText(); publicPlugin.setAuthor(author); String email = plugin1.selectSingleNode("email").getText(); publicPlugin.setEmail(email); String description = plugin1.selectSingleNode("description").getText(); publicPlugin.setDescription(description); String homePage = plugin1.selectSingleNode("homePage").getText(); publicPlugin.setHomePage(homePage); } catch (Exception e) { if (Log.debugging) Log.debug("We can ignore these."); } try { pluginClass = (Plugin) getParentClassLoader().loadClass(clazz).newInstance(); if (Log.debugging) Log.debug(name + " has been loaded."); publicPlugin.setPluginDir(pluginDir); publicPlugins.add(publicPlugin); registerPlugin(pluginClass); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { Log.error("Unable to load plugin " + clazz + ".", e); } } catch (NumberFormatException ex) { Log.error("Unable to load plugin " + clazz + ".", ex); } } return pluginClass; }
From source file:org.jivesoftware.spark.PluginManager.java
License:Open Source License
/** * Checks the plugin for required operating system. * * @param plugin the Plugin element to check. * @return true if the operating system is ok for the plugin to run on. */// w w w . j a va 2 s. c o m private boolean isOperatingSystemOK(Node plugin) { // Check for operating systems try { final Element osElement = (Element) plugin.selectSingleNode("os"); if (osElement != null) { String operatingSystem = osElement.getText(); boolean ok = false; final String currentOS = JiveInfo.getOS().toLowerCase(); // Iterate through comma delimited string StringTokenizer tkn = new StringTokenizer(operatingSystem, ","); while (tkn.hasMoreTokens()) { String os = tkn.nextToken().toLowerCase(); if (currentOS.contains(os) || currentOS.equalsIgnoreCase(os)) { ok = true; } } if (!ok) { if (Log.debugging) Log.debug("Unable to load plugin " + plugin.selectSingleNode("name").getText() + " due to invalid operating system. Required OS = " + operatingSystem); return false; } } } catch (Exception e) { Log.error(e); } return true; }
From source file:org.kitodo.production.plugin.importer.massimport.googlecode.fascinator.redbox.sru.NLAIdentity.java
License:Open Source License
private List<Map<String, String>> getSourceIdentities() { List<Map<String, String>> returnList = new ArrayList<>(); // Top level institution Map<String, String> idMap = new HashMap<>(); Node institutionNode = eac.selectSingleNode("eac:eac-cpf/eac:control/eac:maintenanceAgency/eac:agencyName"); String institutionString = institutionNode.getText(); // Top level name Node nlaNamesNode = eac.selectSingleNode("eac:eac-cpf/eac:cpfDescription/eac:identity"); // Get all the names this ID lists List<Map<String, String>> nameList = getNames(nlaNamesNode); for (Map<String, String> name : nameList) { // Only use the longest top-level name for display purposes String oldDisplayName = idMap.get(DISPLAY_NAME); String thisDisplayName = name.get(DISPLAY_NAME); if (oldDisplayName == null || (thisDisplayName != null && thisDisplayName.length() > oldDisplayName.length())) { // Clear any old data idMap.clear();//from ww w . j a va 2s .co m // Store this ID idMap.putAll(name); idMap.put(INSTITUTION, institutionString); } } // And add to the list returnList.add(idMap); // All name entities from contributing institutions List<Node> sourceIdentities = eac.selectNodes("eac:eac-cpf/eac:cpfDescription//eac:eac-cpf"); for (Node identity : sourceIdentities) { // Institution for this ID institutionNode = identity.selectSingleNode("*//eac:maintenanceAgency/eac:agencyName"); if (Objects.nonNull(institutionNode)) { institutionString = institutionNode.getText(); // Any names for this ID List<Node> idNodes = identity.selectNodes("*//eac:identity"); for (Node idNode : idNodes) { // A Map for each name idMap = new HashMap<>(); // Get all the names this ID lists nameList = getNames(idNode); for (Map<String, String> name : nameList) { idMap.putAll(name); } // Indicate the institution for each one idMap.put(INSTITUTION, institutionString); // And add to the list returnList.add(idMap); } } } return returnList; }
From source file:org.kitodo.production.plugin.importer.massimport.googlecode.fascinator.redbox.sru.NLAIdentity.java
License:Open Source License
private Map<String, String> getNameMap(Node name) { Map<String, String> nameMap = new HashMap<>(); String thisDisplay = null;//from w w w . j a v a2 s . co m String thisFirstName = null; String thisSurname = null; String title = null; // First name Node firstNameNode = name .selectSingleNode("eac:part[(@localType=\"forename\") " + "or (@localType=\"givenname\")]"); if (Objects.nonNull(firstNameNode)) { thisFirstName = firstNameNode.getText(); } // Surname Node surnameNode = name .selectSingleNode("eac:part[(@localType=\"surname\") " + "or (@localType=\"familyname\")]"); if (Objects.nonNull(surnameNode)) { thisSurname = surnameNode.getText(); } // Title Node titleNode = name.selectSingleNode("eac:part[@localType=\"title\"]"); if (Objects.nonNull(titleNode)) { title = titleNode.getText(); } // Display Name if (Objects.nonNull(thisSurname)) { thisDisplay = thisSurname; nameMap.put("surname", thisSurname); if (Objects.nonNull(thisFirstName)) { thisDisplay += ", " + thisFirstName; nameMap.put("firstName", thisFirstName); } if (Objects.nonNull(title)) { thisDisplay += " (" + title + ")"; } nameMap.put(DISPLAY_NAME, thisDisplay); } // Last ditch effort... we couldn't find simple name information // from recommended values. So just concatenate what we can see. if (Objects.isNull(thisDisplay)) { // Find every part List<Node> parts = name.selectNodes("eac:part"); for (Node part : parts) { String value = getValueFromPart((Element) part); // And add to the display name if (Objects.isNull(thisDisplay)) { thisDisplay = value; } else { thisDisplay += ", " + value; } } nameMap.put(DISPLAY_NAME, thisDisplay); } return nameMap; }
From source file:org.kuali.ext.mm.utility.BeanDDCreator.java
License:Educational Community License
/** * Use this application to generate Data dictionary drafts for the Materiel Management project. * Files will be placed in org.kuali.ext.mm.businessobject.datadictionary. This generator * will produce an incomplete draft of the data dictionary and will require replacement of * certain fields, especially those pre-populated with "FILL ME IN". Also there may be * additional property configurations required such as maxLength, control size, and attribute descriptions. * @param args name of a file containing the list of BOs to be generated; in this case use boGen.Conf.xml located in the root of the project directory */// w ww. j a v a 2 s. c o m public static void main(String[] args) throws Exception { String filename = "boGen.conf.xml"; try { SAXReader saxReader = new SAXReader(); Document document = saxReader.read(filename); List<Node> boList = document.selectNodes("//bo"); for (Node bo : boList) { String boName = bo.selectSingleNode("@name").getStringValue(); String className = bo.selectSingleNode("@class").getStringValue(); Class<? extends BusinessObject> boClass = (Class<? extends BusinessObject>) Class .forName(className); PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(boClass); StringBuffer sb = new StringBuffer(4000); sb.append("<beans xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xmlns:p=\"http://www.springframework.org/schema/p\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans\r\n" + " http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\">\r\n" + "\r\n" + " <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("\" parent=\""); sb.append(boClass.getSimpleName()); sb.append("-parentBean\" />\r\n" + "\r\n" + " <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("-parentBean\" abstract=\"true\" parent=\"BusinessObjectEntry\"\r\n" + " p:businessObjectClass=\""); sb.append(boClass.getName()); sb.append("\"\r\n"); sb.append(" p:titleAttribute=\""); sb.append("FILL ME IN"); sb.append("\"\r\n"); sb.append(" p:objectLabel=\""); sb.append(camelCaseToString(boClass.getSimpleName())); sb.append("\"\r\n"); sb.append(" p:inquiryDefinition-ref=\""); sb.append(boClass.getSimpleName()); sb.append("-inquiryDefinition\"\r\n"); sb.append(" p:lookupDefinition-ref=\""); sb.append(boClass.getSimpleName()); sb.append("-lookupDefinition\" >\r\n"); sb.append(" <property name=\"attributes\" >\r\n" + " <list>\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { sb.append(" <ref bean=\"").append(boClass.getSimpleName()).append('-'); sb.append(p.getName()); sb.append("\" />\r\n"); } } sb.append(" </list>\r\n" + " </property>\r\n" + " </bean>\r\n" + "\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { if (p.getName().equals("versionNumber")) { sb.append(getSimpleParentBeanReference(boClass, p.getName())); sb.append(getSimpleAbstractInheritanceBean(boClass, p.getName(), "AttributeReferenceDummy-versionNumber")); } /*else if ( p.getName().endsWith("chartOfAccountsCode" ) ) { sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "Chart-chartOfAccountsCode" ) ); } else if ( p.getName().endsWith("organizationCode" ) ) { sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "Org-organizationCode" ) ); } else if ( p.getName().endsWith("accountNumber" ) ) { sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "Account-accountNumber" ) ); } else if ( p.getName().equals("active" ) ) { sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "GenericAttributes-activeIndicator" ) ); } else if ( p.getName().equals("codeAndDescription" ) ) { sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); sb.append( getSimpleAbstractInheritanceBeanWithLabel(boClass, p.getName(), "CommonField-CodeAndDescription", camelCaseToString(boClass.getSimpleName()) ) ); } else if ( p.getPropertyType() == Boolean.TYPE ) { sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "GenericAttributes-genericBoolean" ) ); } else if ( p.getPropertyType() == Date.class && !p.getName().equals("lastUpdateDate")) { sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); sb.append( getSimpleAbstractInheritanceBeanWithLabel(boClass, p.getName(), "GenericAttributes-genericDate", camelCaseToString(p.getName()) ) ); } else if( p.getName().equals("lastUpdateDate")) { sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); sb.append( getSimpleAbstractInheritanceBeanWithLabel(boClass, p.getName(), "GenericAttributes-genericTimestamp", camelCaseToString(p.getName()) ) ); } */else { // attribute bean sb.append(getSimpleParentBeanReference(boClass, p.getName())); // attribute parent bean sb.append(" <bean id=\"").append(boClass.getSimpleName()).append('-'); sb.append(p.getName()) .append("-parentBean\" parent=\"AttributeDefinition\" abstract=\"true\"\r\n"); sb.append(" p:name=\"").append(p.getName()).append("\"\r\n"); sb.append(" p:forceUppercase=\"false\"\r\n"); sb.append(" p:label=\"").append(camelCaseToString(p.getName())).append("\"\r\n"); sb.append(" p:shortLabel=\"").append(camelCaseToString(p.getName())) .append("\"\r\n"); sb.append(" p:maxLength=\"10\"\r\n"); sb.append(" p:required=\"false\" >\r\n"); sb.append(" <property name=\"validationPattern\" >\r\n" + " <bean parent=\"AnyCharacterValidationPattern\"\r\n" + " p:allowWhitespace=\"true\" />\r\n" + " </property>\r\n" + " <property name=\"control\" >\r\n"); if (p.getName().equals("lastUpdateDate")) { sb.append(" <bean parent=\"HiddenControlDefinition\" />\r\n"); } else if (p.getName().equals("lastUpdateId")) { sb.append(" <bean parent=\"HiddenControlDefinition\" />\r\n"); } else { sb.append(" <bean parent=\"TextControlDefinition\"\r\n" + " p:size=\"10\" />\r\n"); } sb.append(" </property>\r\n" + " </bean>\r\n"); } sb.append("\r\n"); } } // inquiry definition sb.append("<!-- Business Object Inquiry Definition -->\r\n"); sb.append("\r\n"); sb.append(getSimpleParentBeanReference(boClass, "inquiryDefinition")); sb.append("\r\n"); sb.append(" <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("-inquiryDefinition-parentBean\" abstract=\"true\" parent=\"InquiryDefinition\"\r\n" + " p:title=\""); sb.append(camelCaseToString(boClass.getSimpleName())); sb.append(" Inquiry\" >\r\n" + " <property name=\"inquirySections\" >\r\n" + " <list>\r\n" + " <bean parent=\"InquirySectionDefinition\"\r\n" + " p:title=\""); sb.append(camelCaseToString(boClass.getSimpleName())); sb.append(" Attributes\"\r\n" + " p:numberOfColumns=\"1\" >\r\n" + " <property name=\"inquiryFields\" >\r\n" + " <list>\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\""); sb.append(p.getName()).append("\" />\r\n"); } } sb.append(" </list>\r\n" + " </property>\r\n" + " </bean>\r\n" + " </list>\r\n" + " </property>\r\n" + " </bean>\r\n" + "\r\n"); sb.append("<!-- Business Object Lookup Definition -->"); sb.append("\r\n"); sb.append(getSimpleParentBeanReference(boClass, "lookupDefinition")); sb.append("\r\n"); sb.append(" <bean id=\""); sb.append(boClass.getSimpleName()); sb.append("-lookupDefinition-parentBean\" abstract=\"true\" parent=\"LookupDefinition\"\r\n" + " p:title=\""); sb.append(camelCaseToString(boClass.getSimpleName())); sb.append(" Lookup\" \r\n"); sb.append(" >\r\n"); sb.append(" <property name=\"defaultSort\" >\r\n" + " <bean parent=\"SortDefinition\">\r\n" + " <property name=\"attributeNames\" >\r\n" + " <list>\r\n" + " <value>FILL ME IN</value>\r\n" + " </list>\r\n" + " </property>\r\n" + " <property name=\"sortAscending\" value=\"true\" />\r\n" + " </bean>\r\n" + " </property>\r\n" + " <property name=\"lookupFields\" >\r\n" + " <list>\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\""); sb.append(p.getName()).append("\" />\r\n"); } } sb.append(" </list>\r\n" + " </property>\r\n" + " <property name=\"resultFields\" >\r\n" + " <list>\r\n"); for (PropertyDescriptor p : props) { if (isNormalProperty(p)) { sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\""); sb.append(p.getName()).append("\" />\r\n"); } } sb.append(" </list>\r\n" + " </property>\r\n" + " </bean>\r\n"); sb.append("\r\n</beans>"); FileWriter outputfile = null; try { outputfile = new FileWriter(getOutputFilePath(className, false) + boName + ".xml"); outputfile.write(sb.toString()); } catch (IOException e) { System.err.println("Error writing bean data to file."); } finally { outputfile.close(); } } } catch (DocumentException e) { System.err.println("Error parsing xml document."); } }