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:com.alibaba.toolkit.util.resourcebundle.xml.XMLResourceBundle.java
License:Open Source License
/** * ?XML Node?resource.//from w w w.j a v a2s .com * * @param groupNode resource?XML Node * @throws ResourceBundleCreateException ? */ protected void initGroup(Node groupNode) throws ResourceBundleCreateException { String enumTypeName = (String) groupNode.selectObject(ResourceBundleConstant.XPATH_GROUP_ENUM); Class enumType = null; if (enumTypeName.length() > 0) { try { enumType = ContextClassLoader.loadClass(enumTypeName); } catch (ClassNotFoundException e) { throw new ResourceBundleCreateException(ResourceBundleConstant.RB_ENUM_CLASS_NOT_FOUND, new Object[] { enumTypeName, ContextClassLoader.getClassLoader() }, e); } } for (Iterator i = groupNode.selectNodes(ResourceBundleConstant.XPATH_RESOURCES).iterator(); i.hasNext();) { Node resourceNode = (Node) i.next(); initResource(resourceNode, enumType); } }
From source file:com.alibaba.toolkit.util.resourcebundle.xml.XMLResourceBundle.java
License:Open Source License
/** * ?XML Nodemap resource.//from ww w . ja va 2 s.c om * * @param id resource ID * @param resourceNode resource?XML Node * @return resource * @throws ResourceBundleCreateException ? */ protected Object getMapResource(String id, Node resourceNode) throws ResourceBundleCreateException { ListMap map = new ArrayHashMap(); for (Iterator i = resourceNode.selectNodes(ResourceBundleConstant.XPATH_RESOURCES).iterator(); i .hasNext();) { Node mapItemNode = (Node) i.next(); Object mapKey = mapItemNode.selectObject(ResourceBundleConstant.XPATH_RESOURCE_ID); if (map.containsKey(id)) { throw new ResourceBundleCreateException(ResourceBundleConstant.RB_DUPLICATED_MAP_RESOURCE_KEY, new Object[] { mapKey, id }, null); } String mapItemType = mapItemNode.getName(); Object value = null; if (ResourceBundleConstant.RB_RESOURCE_TYPE_MESSAGE.equals(mapItemType)) { value = getMessageResource(id, mapItemNode); } else if (ResourceBundleConstant.RB_RESOURCE_TYPE_MAP.equals(mapItemType)) { value = getMapResource(id, mapItemNode); } else if (ResourceBundleConstant.RB_RESOURCE_TYPE_LIST.equals(mapItemType)) { value = getListResource(id, mapItemNode); } map.put(mapKey, value); } return Collections.unmodifiableMap(map); }
From source file:com.alibaba.toolkit.util.resourcebundle.xml.XMLResourceBundle.java
License:Open Source License
/** * ?XML Nodelist resource.//from www . j a v a 2s .com * * @param id resource ID * @param resourceNode resource?XML Node * @return resource * @throws ResourceBundleCreateException ? */ protected Object getListResource(String id, Node resourceNode) throws ResourceBundleCreateException { List list = new ArrayList(); for (Iterator i = resourceNode.selectNodes(ResourceBundleConstant.XPATH_RESOURCES).iterator(); i .hasNext();) { Node listItemNode = (Node) i.next(); String listItemType = listItemNode.getName(); Object value = null; if (ResourceBundleConstant.RB_RESOURCE_TYPE_MESSAGE.equals(listItemType)) { value = getMessageResource(id, listItemNode); } else if (ResourceBundleConstant.RB_RESOURCE_TYPE_MAP.equals(listItemType)) { value = getMapResource(id, listItemNode); } else if (ResourceBundleConstant.RB_RESOURCE_TYPE_LIST.equals(listItemType)) { value = getListResource(id, listItemNode); } list.add(value); } return Collections.unmodifiableList(list); }
From source file:com.amalto.workbench.widgets.xmleditor.pagecontent.ExtensibleXMLEditorPageContent.java
License:Open Source License
protected List<?> getXMLNodesByPath(Node parent, String relativePath) { return parent.selectNodes("./" + relativePath);//$NON-NLS-1$ }
From source file:com.beetle.framework.business.service.server.ServiceConfig.java
License:Apache License
private static void gendoc(Document doc) throws ClassNotFoundException { Node node = doc.selectSingleNode("binder"); if (node != null) { Iterator<?> it = node.selectNodes("item").iterator(); while (it.hasNext()) { ServiceDef sdf = new ServiceDef(); Element e = (Element) it.next(); String face = e.valueOf("@interface"); String imp = e.valueOf("@implement"); String enabled = e.valueOf("@enabled"); sdf.setIface(face);//from ww w .j av a 2 s . c o m sdf.setImp(imp); sdf.setEnabled(enabled); @SuppressWarnings("unchecked") Iterator<Attribute> ait = e.attributeIterator(); while (ait.hasNext()) { Attribute at = ait.next(); sdf.addExtension(at.getName(), at.getValue()); } register(sdf); } } }
From source file:com.beetle.framework.resource.container.ContainerConfig.java
License:Apache License
/** * //from w w w. j av a2 s .c o m * * @param tagname --?? * @param key --?? * @throws Exception */ public static void setContainValue(String tagname, String key, String value) throws Exception { Document doc = XMLReader.getXmlDoc(sysconfigFileName); Node node = doc.selectSingleNode(XMLReader.convertPath(tagname)); if (node != null) { @SuppressWarnings("rawtypes") Iterator it = node.selectNodes("item").iterator(); while (it.hasNext()) { Element e = (Element) it.next(); String id = e.valueOf("@name"); if (id != null && id.equals(key)) { e.addAttribute("value", value); break; } } } File f = new File(sysconfigFileName); if (f.exists()) { OutputFormat format = OutputFormat.createPrettyPrint(); FileOutputStream fos = new FileOutputStream(f); XMLWriter writer = new XMLWriter(fos, format); writer.write(doc); writer.close(); } else { AppLogger.getInstance(ContainerConfig.class).error("??jarxml"); } }
From source file:com.beetle.framework.resource.dic.ReleBinder.java
License:Apache License
private void gendoc(Document doc) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Node node = doc.selectSingleNode("binder"); if (node != null) { Iterator<?> it = node.selectNodes("item").iterator(); while (it.hasNext()) { Element e = (Element) it.next(); String aopid = e.valueOf("@aopid"); if (aopid != null && aopid.trim().length() > 0) { String inerceptor = e.valueOf("@interceptor"); this.bindAopInterceptor(aopid, (AopInterceptor) Class.forName(inerceptor.trim()).newInstance()); } else { dealInject(e);/*from w w w .j av a 2s .co m*/ } } } }
From source file:com.beetle.framework.util.file.XMLReader.java
License:Apache License
/** * //from w ww. ja v a 2 s . co m * @param xmlFileInputStream * @param itemPath * @param ElementName * @param keyName * @param valueName * @return */ public static Map<String, String> getProperties(InputStream xmlFileInputStream, String itemPath, String ElementName, String keyName, String valueName) { Map<String, String> map = new HashMap<String, String>(); if (xmlFileInputStream == null) { // System.out.println("WARN:the resource do not exist"); return map; } SAXReader reader = new SAXReader(); Document doc = null; try { doc = reader.read(xmlFileInputStream); // Document doc = reader.read(new File(xmlFileName)); Node node = doc.selectSingleNode(convertPath(itemPath)); if (node != null) { Iterator<?> it = node.selectNodes(ElementName).iterator(); while (it.hasNext()) { Element e = (Element) it.next(); map.put(e.valueOf("@" + keyName), e.valueOf("@" + valueName)); } } else { // throw new com.beetle.framework.AppRuntimeException( // "?????!"); // System.out.println("WARN:Can't find the paht[" + itemPath // + "],please check it!"); // throw new RuntimeException("{" + itemPath + // "}does not exist"); } } catch (Exception e) { e.printStackTrace(); } finally { if (doc != null) { doc.clearContent(); } reader = null; } // xmlFileInputStream.close(); return map; }
From source file:com.beetle.framework.util.file.XMLReader.java
License:Apache License
public static Map<String, String> getProperties(String xmlFileName, String itemPath, String ElementName, String keyName, String valueName) { Map<String, String> map = new HashMap<String, String>(); SAXReader reader = new SAXReader(); Document doc = null;/*w w w. j a va2s.com*/ try { // // InputStream // in=ClassLoader.getSystemResourceAsStream(xmlFileName); // Document doc=reader.read(in); // doc = reader.read(new File(xmlFileName)); Node node = doc.selectSingleNode(convertPath(itemPath)); if (node != null) { Iterator<?> it = node.selectNodes(ElementName).iterator(); while (it.hasNext()) { Element e = (Element) it.next(); map.put(e.valueOf("@" + keyName), e.valueOf("@" + valueName)); } } else { // throw new com.beetle.framework.AppRuntimeException( // "?????!"); System.out.println("WARN:Can't find the paht[" + itemPath + "],please check it!"); } } catch (Exception e) { e.printStackTrace(); } finally { if (doc != null) { doc.clearContent(); } reader = null; } return map; }
From source file:com.beetle.framework.util.file.XMLReader.java
License:Apache License
public static void setProperties(String xmlFileName, String itemPath, String ElementName, String keyName, String valueName, String key, String value) { // ? ??????//from w w w . j a va2 s . co m // ???? synchronized (writeLock) { SAXReader reader = new SAXReader(); XMLWriter writer = null; try { Document doc = reader.read(new File(xmlFileName)); Node node = doc.selectSingleNode(convertPath(itemPath)); if (node != null) { Iterator<?> it = node.selectNodes(ElementName).iterator(); while (it.hasNext()) { Element e = (Element) it.next(); if (e.attributeValue(keyName).equals(key)) { e.addAttribute(valueName, value); break; } } } writer = new XMLWriter(new FileWriter(xmlFileName)); writer.write(doc); } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException ex) { ex.printStackTrace(); } } reader = null; } } }