List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
/** * //from w ww .j a va 2s. c o m * @param node * @param xPath * @param defaultValue * @return */ public static int getNodeTextAsInt(Node node, String xPath, int defaultValue) { int returnValue = 0; if (node != null) { Node tempNode = node.selectSingleNode(xPath); if (tempNode != null) { String nodeValue = tempNode.getText(); returnValue = parseInt(nodeValue, defaultValue); } else { returnValue = defaultValue; } } else { returnValue = defaultValue; } return returnValue; }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
public static String getNodeTextAsString(Node node, String defaultValue) { if (node != null) { String nodeValue = node.getText().trim(); return nodeValue; } else {/*from w w w . ja v a 2 s. co m*/ return defaultValue; } }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
public static String getNodeTextAsStringByPattern(Node node, String xPath, String defaultValue) { String returnValue = ""; if (node != null) { Node tempNode = node.selectSingleNode(xPath); if (tempNode != null) { returnValue = tempNode.getText().trim(); } else {/*www.j a v a 2s . c o m*/ returnValue = defaultValue; } } else { returnValue = defaultValue; } return returnValue; }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
public static double getNodeTextAsDouble(Node node, long defaultValue) { if (node != null) { String nodeValue = node.getText(); return parseDouble(nodeValue, defaultValue); } else {/*from ww w .j a va 2 s . c o m*/ return defaultValue; } }
From source file:com.lafengmaker.tool.util.XMLDataUtil.java
License:Open Source License
public static double getNodeTextAsDouble(Node node, String xPath, long defaultValue) { double returnValue = 0; if (node != null) { Node tempNode = node.selectSingleNode(xPath); if (tempNode != null) { String nodeValue = tempNode.getText(); returnValue = parseDouble(nodeValue, defaultValue); } else {/*from ww w. j ava2 s. c o m*/ returnValue = defaultValue; } } else { returnValue = defaultValue; } return returnValue; }
From source file:com.log4ic.compressor.utils.MemcachedUtils.java
License:Open Source License
private static InetSocketAddress biludAddr(Node node) { Node hostNode = node.selectSingleNode("host"); Node portNode = node.selectSingleNode("port"); if (hostNode != null && StringUtils.isNotBlank(hostNode.getText()) && portNode != null && StringUtils.isNotBlank(portNode.getText())) { return new InetSocketAddress(hostNode.getText(), Integer.parseInt(portNode.getText())); }//from ww w . ja va2 s . com return null; }
From source file:com.log4ic.compressor.utils.MemcachedUtils.java
License:Open Source License
private static AddressConfig biludAddrMapConfig(List<Node> nodeList) { AddressConfig config = new AddressConfig(); config.addressMap = new LinkedHashMap<InetSocketAddress, InetSocketAddress>(); List<Integer> weightsList = new ArrayList<Integer>(); for (Node node : nodeList) { Node masterNode = node.selectSingleNode("master"); Node weightsNode = ((Element) node).attribute("weights"); int weights = 1; if (weightsNode != null) { try { weights = Integer.parseInt(weightsNode.getText()); } catch (Exception e) { //fuck ide }//w w w. j a va 2 s. co m } weightsList.add(weights); InetSocketAddress masterAddr; if (masterNode != null) { masterAddr = biludAddr(masterNode); } else { masterAddr = biludAddr(node); } Node standbyNode = node.selectSingleNode("standby"); InetSocketAddress standbyAddr = null; if (standbyNode != null) { standbyAddr = biludAddr(standbyNode); } config.addressMap.put(masterAddr, standbyAddr); } config.widgets = ArrayUtils.toPrimitive(weightsList.toArray(new Integer[weightsList.size()])); return config; }
From source file:com.love320.templateparser.factory.impl.BeanFactoryCacheImpl.java
License:Apache License
private BeanString action(String name) { BeanString beanString = new BeanString();//bean? beanString.setName(name);//bean?name Node node = docroot.selectSingleNode("/beans/bean[@id='" + name + "']/@class"); //?idnameclass?? beanString.setClassName(node.getText());//bean?className Node beanScope = docroot.selectSingleNode("/beans/bean[@id='" + name + "']/@scope"); //?idnamescope?? if (beanScope != null) beanString.setScope(beanScope.getText());//bean?scope List ls = docroot.selectNodes("/beans/bean[@id='" + name + "']/property");//??? for (int i = 0; i < ls.size(); i++) { Element element = (Element) ls.get(i); String propertyName = element.attributeValue("name");//beanName Node propertyBeanNode = docroot.selectSingleNode( "/beans/bean[@id='" + name + "']/property[@name='" + propertyName + "']/ref/@bean"); if (propertyBeanNode != null) { //?? ???beanId String[] refs = { null, null }; refs[0] = propertyName;//from ww w.j a va 2s .com refs[1] = propertyBeanNode.getText(); beanString.getRefList().add(refs); } Node propertyValueNode = docroot.selectSingleNode( "/beans/bean[@id='" + name + "']/property[@name='" + propertyName + "']/value"); if (propertyValueNode != null) { //?? ???? String[] values = { null, null }; values[0] = propertyName; values[1] = propertyValueNode.getText(); beanString.getValueList().add(values); } } return beanString; }
From source file:com.love320.templateparser.factory.impl.BeanFactoryImpl.java
License:Apache License
@Override public BeanString getBeanString(String name) { BeanString beanString = new BeanString();//bean? beanString.setName(name);//bean?name Node node = docroot.selectSingleNode("/beans/bean[@id='" + name + "']/@class"); //?idnameclass?? beanString.setClassName(node.getText());//bean?className Node beanScope = docroot.selectSingleNode("/beans/bean[@id='" + name + "']/@scope"); //?idnamescope?? if (beanScope != null) beanString.setScope(beanScope.getText());//bean?scope List ls = docroot.selectNodes("/beans/bean[@id='" + name + "']/property");//??? for (int i = 0; i < ls.size(); i++) { Element element = (Element) ls.get(i); String propertyName = element.attributeValue("name");//beanName Node propertyBeanNode = docroot.selectSingleNode( "/beans/bean[@id='" + name + "']/property[@name='" + propertyName + "']/ref/@bean"); if (propertyBeanNode != null) { //?? ???beanId String[] refs = { null, null }; refs[0] = propertyName;/*from w w w.j a v a 2s .co m*/ refs[1] = propertyBeanNode.getText(); beanString.getRefList().add(refs); } Node propertyValueNode = docroot.selectSingleNode( "/beans/bean[@id='" + name + "']/property[@name='" + propertyName + "']/value"); if (propertyValueNode != null) { //?? ???? String[] values = { null, null }; values[0] = propertyName; values[1] = propertyValueNode.getText(); beanString.getValueList().add(values); } } return beanString; }
From source file:com.love320.templateparser.factory.impl.FactoryImpl.java
License:Apache License
private Object procreationXML(String beanName) { Node node = docroot.selectSingleNode("/beans/bean[@id='" + beanName + "']/@class"); Object object = null;//from w ww .j a va 2s .co m try { object = Class.forName(node.getText()).newInstance();//? List ls = docroot.selectNodes("/beans/bean[@id='" + beanName + "']/property");//??? for (int i = 0; i < ls.size(); i++) { Element element = (Element) ls.get(i); String propertyName = element.attributeValue("name");//beanName Node propertyBeanNode = docroot.selectSingleNode( "/beans/bean[@id='" + beanName + "']/property[@name='" + propertyName + "']/ref/@bean"); if (propertyBeanNode != null) { Object refObject = null; if (cache != null) { refObject = getbean(propertyBeanNode.getText());// } else { refObject = procreationXML(propertyBeanNode.getText());// } //?? Method method = object.getClass().getMethod( "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1), refObject.getClass()); method.invoke(object, refObject); } else { Node valueNode = docroot.selectSingleNode( "/beans/bean[@id='" + beanName + "']/property[@name='" + propertyName + "']/value"); if (valueNode != null) { //?? try { Double.parseDouble(valueNode.getText().trim()); Method method = object.getClass().getMethod( "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1), int.class); method.invoke(object, Integer.parseInt(valueNode.getText().trim())); // } catch (NumberFormatException e) { // Method method = object.getClass().getMethod( "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1), valueNode.getText().getClass()); method.invoke(object, valueNode.getText()); } } else { logger.debug("<valueNode>" + valueNode); } } } } catch (InstantiationException e) { logger.error("InstantiationException", e); } catch (IllegalAccessException e) { logger.error("IllegalAccessException", e); } catch (ClassNotFoundException e) { logger.error("ClassNotFoundException", e); } catch (SecurityException e) { logger.error("SecurityException", e); } catch (NoSuchMethodException e) { logger.error("NoSuchMethodException", e); } catch (IllegalArgumentException e) { logger.error("IllegalArgumentException", e); } catch (InvocationTargetException e) { logger.error("InvocationTargetException", e); } return object; }