List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:org.apache.openmeetings.documents.InstallationDocumentHandler.java
License:Apache License
public static int getCurrentStepNumber() throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(OmFileHelper.getInstallFile()); Node node = document.selectSingleNode("//install/step/stepnumber"); return Integer.valueOf(node.getText()).intValue(); }
From source file:org.apache.openmeetings.installation.InstallationDocumentHandler.java
License:Apache License
public static int getCurrentStepNumber() throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(OmFileHelper.getInstallFile()); Node node = document.selectSingleNode("//install/step/stepnumber"); return Integer.valueOf(node.getText()).intValue(); }
From source file:org.apereo.portal.io.xml.permission.PermissionSetsFilenameFunction.java
License:Apache License
@Override public String apply(Tuple<String, Node> data) { final String[] keyParts = splitKey(data.first); final Node node = data.second.selectSingleNode("/permission-set/principal/child::node()/child::text()"); final String principal = node.getText(); return principal + "__" + keyParts[3] + "__" + keyParts[0]; }
From source file:org.apereo.portal.io.xml.SpELDataTemplatingStrategy.java
License:Apache License
@Override public Source processTemplates(Document data, String filename) { log.trace("Processing templates for document XML={}", data.asXML()); for (String xpath : XPATH_EXPRESSIONS) { @SuppressWarnings("unchecked") List<Node> nodes = data.selectNodes(xpath); for (Node n : nodes) { String inpt, otpt;/* w w w. j a v a 2s . co m*/ switch (n.getNodeType()) { case org.w3c.dom.Node.ATTRIBUTE_NODE: Attribute a = (Attribute) n; inpt = a.getValue(); otpt = processText(inpt); if (otpt == null) { throw new RuntimeException("Invalid expression '" + inpt + "' in file " + filename); } if (!otpt.equals(inpt)) { a.setValue(otpt); } break; case org.w3c.dom.Node.TEXT_NODE: case org.w3c.dom.Node.CDATA_SECTION_NODE: inpt = n.getText(); otpt = processText(inpt); if (otpt == null) { throw new RuntimeException("Invalid expression '" + inpt + "' in file " + filename); } if (!otpt.equals(inpt)) { n.setText(otpt); } break; default: String msg = "Unsupported node type: " + n.getNodeTypeName(); throw new RuntimeException(msg); } } } final SAXSource rslt = new DocumentSource(data); rslt.setSystemId(filename); // must be set, else import chokes return rslt; }
From source file:org.bigmouth.nvwa.utils.xml.Dom4jDecoder.java
License:Apache License
/** * <p>XML???</p>/*from w w w . j av a 2s . c om*/ * ? * appId? * ?XMLappId?appid?APPID?app_id?APP_ID * @param <T> * @param xml * @param xpath * @param cls * @return */ public static <T> T decode(String xml, String xpath, Class<T> cls) throws Exception { if (StringUtils.isBlank(xml)) return null; T t = cls.newInstance(); Document doc = DocumentHelper.parseText(xml); Node itemNode = doc.selectSingleNode(xpath); Field[] fields = cls.getDeclaredFields(); for (Field field : fields) { // if the field name is 'appId' String name = field.getName(); String nodename = name; if (field.isAnnotationPresent(Argument.class)) { nodename = field.getAnnotation(Argument.class).name(); } // select appId node Node current = itemNode.selectSingleNode(nodename); if (null == current) { // select appid node current = itemNode.selectSingleNode(nodename.toLowerCase()); } if (null == current) { // select APPID node current = itemNode.selectSingleNode(nodename.toUpperCase()); } if (null == current) { // select app_id node nodename = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(nodename), "_").toLowerCase(); current = itemNode.selectSingleNode(nodename); } if (null == current) { // select APP_ID node nodename = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(nodename), "_").toUpperCase(); current = itemNode.selectSingleNode(nodename); } if (null != current) { String invokeName = StringUtils.join(new String[] { "set", StringUtils.capitalize(name) }); try { MethodUtils.invokeMethod(t, invokeName, current.getText()); } catch (NoSuchMethodException e) { LOGGER.warn("NoSuchMethod-" + invokeName); } catch (IllegalAccessException e) { LOGGER.warn("IllegalAccess-" + invokeName); } catch (InvocationTargetException e) { LOGGER.warn("InvocationTarget-" + invokeName); } } } return t; }
From source file:org.client.one.service.OAuthAuthenticationService.java
License:Apache License
public boolean registerUserWSSoap(String token, Profile profile) throws DocumentException { String msg = ""; msg += "<registerUserRequest xmlns=\"http://aktios.com/appthree/webservice/model\">"; msg += " <token>" + token + "</token>"; msg += " <user>"; msg += " <username>" + profile.getUsername() + "</username>"; msg += " <password>" + profile.getPassword() + "</password>"; msg += " <firstName>" + profile.getFirstName() + "</firstName>"; msg += " <lastName>" + profile.getLastName() + "</lastName>"; msg += " <phoneNumber>" + profile.getPhoneNumber() + "</phoneNumber>"; msg += " </user>"; msg += "</registerUserRequest>"; StreamSource source = new StreamSource(new StringReader(msg)); StringResult xmlResult = new StringResult(); webServiceTemplate.sendSourceAndReceiveToResult(appThreeWebServices, source, xmlResult); String res = xmlResult.toString(); Document doc = DocumentHelper.parseText(res); Node nId = doc.selectSingleNode("//ns2:registerUserResponse/ns2:id"); Integer id = Integer.valueOf(nId.getText()); // If the ID == -1 an error ocurred return (id != -1); }
From source file:org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean.java
License:Apache License
public void afterPropertiesSet() throws Exception { if (descriptor != null && descriptor.exists()) { // Enforce UTF-8 on source code for reloads CompilerConfiguration config = CompilerConfiguration.DEFAULT; config.setSourceEncoding("UTF-8"); GroovyClassLoader classLoader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), config);/*from w w w. j a v a 2 s . c o m*/ List classes = new ArrayList(); SAXReader reader = new SAXReader(); InputStream inputStream = null; try { inputStream = descriptor.getInputStream(); Document doc = reader.read(inputStream); List grailsClasses = doc.selectNodes("/grails/resources/resource"); for (Iterator i = grailsClasses.iterator(); i.hasNext();) { Node node = (Node) i.next(); try { classes.add(classLoader.loadClass(node.getText())); } catch (ClassNotFoundException e) { LOG.warn("Class with name [" + node.getText() + "] was not found, and hence not loaded. Possible empty class or script definition?"); } } } finally { if (inputStream != null) inputStream.close(); } Class[] loadedClasses = (Class[]) classes.toArray(new Class[classes.size()]); this.grailsApplication = new DefaultGrailsApplication(loadedClasses, classLoader); } else { Assert.notNull(resourceLoader, "Property [resourceLoader] must be set!"); this.grailsApplication = new DefaultGrailsApplication(this.resourceLoader); } ApplicationHolder.setApplication(this.grailsApplication); }
From source file:org.codehaus.groovy.grails.plugins.DefaultPluginMetaManager.java
License:Apache License
/** * Constructs a PluginMetaManager instance for the given set of plug-in descriptors * * @param pluginDescriptors A set of plug-in descriptors *//*from ww w. j a va 2 s . co m*/ public DefaultPluginMetaManager(Resource[] pluginDescriptors) { for (int i = 0; i < pluginDescriptors.length; i++) { Resource pluginDescriptor = pluginDescriptors[i]; SAXReader reader = new SAXReader(); InputStream inputStream = null; try { try { inputStream = pluginDescriptor.getInputStream(); Document doc = reader.read(inputStream); Element pluginElement = doc.getRootElement(); String pluginName = pluginElement.attributeValue("name"); String pluginVersion = pluginElement.attributeValue("version"); if (StringUtils.isBlank(pluginName)) throw new GrailsConfigurationException("Plug-in descriptor [" + pluginDescriptor + "] doesn't specify a plug-in name. It must be corrupted, try re-install the plug-in"); if (StringUtils.isBlank(pluginVersion)) throw new GrailsConfigurationException("Plug-in descriptor [" + pluginDescriptor + "] with name [" + pluginName + "] doesn't specify a plug-in version. It must be corrupted, try re-install the plug-in"); List grailsClasses = new ArrayList(); try { grailsClasses = doc.selectNodes("/plugin/resources/resource"); } catch (Exception e) { //ignore missing nodes } List pluginResources = new ArrayList(); for (Iterator j = grailsClasses.iterator(); j.hasNext();) { Node node = (Node) j.next(); pluginResources.add(node.getText()); } PluginMeta pluginMeta = new PluginMeta(pluginName, pluginVersion); pluginMeta.pluginResources = (String[]) pluginResources .toArray(new String[pluginResources.size()]); pluginInfo.put(pluginName, pluginMeta); for (int j = 0; j < pluginMeta.pluginResources.length; j++) { String pluginResource = pluginMeta.pluginResources[j]; resourceToPluginMap.put(pluginResource, pluginMeta); } } finally { if (inputStream != null) inputStream.close(); } } catch (IOException e) { throw new GrailsConfigurationException( "Error loading plug-in descriptor [" + pluginDescriptor + "]:" + e.getMessage(), e); } catch (DocumentException e) { throw new GrailsConfigurationException( "Error loading plug-in descriptor [" + pluginDescriptor + "]:" + e.getMessage(), e); } } }
From source file:org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean.java
License:Apache License
public void afterPropertiesSet() throws Exception { this.pluginManager = PluginManagerHolder.getPluginManager(); if (pluginManager == null) { if (descriptor == null) throw new IllegalStateException("Cannot create PluginManager, /WEB-INF/grails.xml not found!"); GroovyClassLoader classLoader = application.getClassLoader(); List classes = new ArrayList(); SAXReader reader = new SAXReader(); InputStream inputStream = null; try {/*w ww. j av a 2 s . c om*/ inputStream = descriptor.getInputStream(); Document doc = reader.read(inputStream); List grailsClasses = doc.selectNodes("/grails/plugins/plugin"); for (Iterator i = grailsClasses.iterator(); i.hasNext();) { Node node = (Node) i.next(); final String pluginName = node.getText(); classes.add(classLoader.loadClass(pluginName)); } } finally { if (inputStream != null) inputStream.close(); } Class[] loadedPlugins = (Class[]) classes.toArray(new Class[classes.size()]); pluginManager = new DefaultGrailsPluginManager(loadedPlugins, application); pluginManager.setApplicationContext(applicationContext); PluginManagerHolder.setPluginManager(pluginManager); pluginManager.loadPlugins(); } this.pluginManager.setApplication(application); this.pluginManager.doArtefactConfiguration(); application.initialise(); }
From source file:org.codehaus.modello.plugin.utils.Dom4jUtils.java
License:Apache License
/** * Asserts that the specified {@link Node} is not a {@link Node#TEXT_NODE} * or {@link Node#CDATA_SECTION_NODE}./*from w w w . ja v a 2 s. c om*/ * * @param message Assertion message to print. * @param node Node to interrogate for {@link Node#TEXT_NODE} or * {@link Node#CDATA_SECTION_NODE} property. * @param recursive <code>true</code> if the node is to be recursively * searched, else <code>false</code>. * @return <code>true</code> if the specified {@link Node} is not of type * {@link Node#TEXT_NODE} or {@link Node#CDATA_SECTION_NODE} */ public static boolean assertNoTextNode(String message, Node node, boolean recursive) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { // Double check that it isn't just whitespace. String text = StringUtils.trim(node.getText()); if (StringUtils.isNotEmpty(text)) { throw new AssertionFailedError(message + " found <" + text + ">"); } } if (recursive) { if (node instanceof Branch) { Iterator it = ((Branch) node).nodeIterator(); while (it.hasNext()) { Node child = (Node) it.next(); assertNoTextNode(message, child, recursive); } } } return false; }