List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator(QName qName);
From source file:com.mingsoft.weixin.util.XmlUtils.java
License:Open Source License
/** * ?xml??document??key?</br> xml?</br> * /* w w w.ja v a2s . c om*/ * @param str * * @param key * ?? * @param sonKey ??? * @return ??stringnull */ public static String getString(String str, String key, String sonKey) { try { Document document = DocumentHelper.parseText(str); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(key); i.hasNext();) { Element foo = (Element) i.next(); return foo.elementText(sonKey); } } catch (Exception e) { e.printStackTrace(); LOG.debug("Exception?xml:" + str); LOG.debug("Exception?key:" + key); } return null; }
From source file:com.mpaike.core.config.xml.XMLConfigService.java
License:Open Source License
protected void parse(InputStream stream) { Map<String, ConfigElementReader> parsedElementReaders = null; Map<String, Evaluator> parsedEvaluators = null; List<ConfigSection> parsedConfigSections = new ArrayList<ConfigSection>(); String currentArea = null;//w w w. ja v a 2s . c o m try { // get the root element SAXReader reader = new SAXReader(); Document document = reader.read(stream); Element rootElement = document.getRootElement(); // see if there is an area defined currentArea = rootElement.attributeValue("area"); // parse the plug-ins section of a config file Element pluginsElement = rootElement.element(ELEMENT_PLUG_INS); if (pluginsElement != null) { // parse the evaluators section parsedEvaluators = parseEvaluatorsElement(pluginsElement.element(ELEMENT_EVALUATORS)); // parse the element readers section parsedElementReaders = parseElementReadersElement(pluginsElement.element(ELEMENT_ELEMENT_READERS)); } // parse each config section in turn @SuppressWarnings("unchecked") Iterator<Element> configElements = rootElement.elementIterator(ELEMENT_CONFIG); while (configElements.hasNext()) { Element configElement = configElements.next(); parsedConfigSections.add(parseConfigElement(parsedElementReaders, configElement, currentArea)); } } catch (Throwable e) { if (e instanceof ConfigException) { throw (ConfigException) e; } else { throw new ConfigException("Failed to parse config stream", e); } } try { // valid for this stream, now add to config service ... if (parsedEvaluators != null) { for (Map.Entry<String, Evaluator> entry : parsedEvaluators.entrySet()) { // add the evaluators to the config service addEvaluator(entry.getKey(), entry.getValue()); } } if (parsedElementReaders != null) { for (Map.Entry<String, ConfigElementReader> entry : parsedElementReaders.entrySet()) { // add the element readers to the config service addConfigElementReader(entry.getKey(), entry.getValue()); } } if (parsedConfigSections != null) { for (ConfigSection section : parsedConfigSections) { // add the config sections to the config service addConfigSection(section, currentArea); } } } catch (Throwable e) { throw new ConfigException("Failed to add config to config service", e); } }
From source file:com.npower.dm.hibernate.management.ModelManagementBeanImpl.java
License:Open Source License
/** * /*from w w w .ja v a2s. c om*/ * <pre> * Import the TAC list of models form file. * <pre> * * @param xmlFile * @throws DMException * */ public void importModelTAC(File xmlFile) throws DMException { try { ManagementBeanFactory factory = this.getManagementBeanFactory(); ModelBean modelBean = factory.createModelBean(); factory.beginTransaction(); SAXReader reader = new SAXReader(); Document confDoc = reader.read(xmlFile); Element root = confDoc.getRootElement(); for (Iterator<Element> i = root.elementIterator("Manufacturer"); i.hasNext();) { String manufacturerExternalID = ""; Element manElement = i.next(); manufacturerExternalID = manElement.elementText("ExternalID"); Manufacturer manufacturerBean = modelBean.getManufacturerByExternalID(manufacturerExternalID); if (manufacturerBean == null) { System.err.println("Could not find this manufacturer: " + manufacturerExternalID); continue; } for (Iterator<Element> j = manElement.elementIterator("Model"); j.hasNext();) { String modelExternalID = ""; Element modelElement = j.next(); modelExternalID = modelElement.elementText("ExternalID"); Model model = modelBean.getModelByManufacturerModelID(manufacturerBean, modelExternalID); if (model == null) { System.err.println("Could not find this model: " + modelExternalID); continue; } List<Element> TACsList = modelElement.elements("TACs"); List<String> TACInfos = new ArrayList<String>(); for (int k = 0; k < TACsList.size(); k++) { List<Element> TACList = ((TACsList.get(k))).elements("TAC"); for (int m = 0; m < TACList.size(); m++) { Element tacElement = TACList.get(m); String tac = tacElement.getText(); if (StringUtils.isNotEmpty(tac) && tac.length() >= 8) { TACInfos.add(tac); } } } modelBean.update(model); modelBean.setTACInfos(model, TACInfos); } } factory.commit(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.olympum.tools.CsJniNetWrapperGenerator.java
License:Open Source License
/** * Defines the direct base class and the interfaces implemented by * <code>clazz</code>./*from w w w. ja v a 2 s . c o m*/ * * @see Section 10.1.2. of the C# language specification. */ private void emitClassBase(PrintStream out, Element clazz) { String parent = clazz.attributeValue("parent"); Element interfacesRoot = clazz.element("implements"); if (parent == null && interfacesRoot == null) return; out.print(" : "); if (parent != null) { out.print(normalize(parent)); if (interfacesRoot != null) out.print(", "); } if (interfacesRoot != null) { Iterator interfaces = interfacesRoot.elementIterator("interface"); while (interfaces.hasNext()) { Element e = (Element) interfaces.next(); out.print(normalize(e.attributeValue("name"))); if (interfaces.hasNext()) out.print(", "); } } }
From source file:com.olympum.tools.CsJniNetWrapperGenerator.java
License:Open Source License
private void generate(Element root, String dir) { int count = 0; try {//ww w. j a va2 s .com Iterator iter = root.elementIterator("class"); while (iter.hasNext()) { Element e = (Element) iter.next(); emitWrapperClass(e, dir); count++; } } catch (Exception e) { throw new RuntimeException(e); } finally { System.out.println(count + " proxy classes generated into directory `" + dir + "'."); } }
From source file:com.olympum.tools.CsJniNetWrapperGenerator.java
License:Open Source License
private void populateMangleMap(Element root) { try {//from w ww . ja v a 2 s . com Iterator iter = root.elementIterator("class"); while (iter.hasNext()) { Element e = (Element) iter.next(); mangleType(e, null); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.openedit.modules.update.UpdateModule.java
License:Open Source License
public List loadSiteList(WebPageRequest inReq) throws Exception { Page sites = getPageManager().getPage("/openedit/update/sites.xml"); Element root = new XmlUtil().getXml(sites.getReader(), sites.getCharacterEncoding()); List all = new ArrayList(); for (Iterator iter = root.elementIterator("site"); iter.hasNext();) { Element child = (Element) iter.next(); Site site = new Site(); site.setId(child.attributeValue("id")); site.setText(child.attributeValue("text")); site.setHref(child.attributeValue("href")); all.add(site);/*from w w w . j a v a 2 s .c om*/ } List dirs = new ArrayList(); dirs.add("/"); List names = getPageManager().getChildrenNames("/"); for (Iterator iterator = names.iterator(); iterator.hasNext();) { String path = (String) iterator.next(); Page dir = getPageManager().getPage(path); if (dir.isFolder()) { dirs.add(path); } } inReq.putPageValue("dirs", dirs); inReq.putPageValue("sites", all); return all; }
From source file:com.openedit.users.filesystem.FileSystemUserManager.java
License:Open Source License
/** * @see com.openedit.users.UserManager#getGroup(String) *///from w ww.j av a 2 s . co m public Group getGroup(String inGroupId) { Group group = (Group) getGroupIdToGroupMap().get(inGroupId); File find = loadGroupFile(inGroupId); if (group != null) { if (group.getLastModified() == find.lastModified()) { return group; } } if (!find.exists()) { ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/groups/" + inGroupId + ".xml"); find = new File(stub.getAbsolutePath()); } if (!find.exists()) { return null; } if (group == null) { group = new FileSystemGroup(); } FileSystemGroup loadgroup = (FileSystemGroup) group; group = loadgroup; loadgroup.setLastModified(find.lastModified()); getGroupIdToGroupMap().put(inGroupId, group); Element root = getXmlUtil().getXml(find, "UTF-8"); loadgroup.setId(root.attributeValue("id")); if (loadgroup.getId() == null) { loadgroup.setId(inGroupId); } loadgroup.setName(root.elementText("group-name")); if (loadgroup.getName() == null) { loadgroup.setName(inGroupId); } Element perm = root.element("permissions"); if (perm != null) { for (Iterator iterator = perm.elementIterator("permission"); iterator.hasNext();) { Element type = (Element) iterator.next(); loadgroup.addPermission(type.getTextTrim()); } } MapPropertyContainer properties = new MapPropertyContainer(); Element props = root.element("properties"); properties.loadProperties(props); loadgroup.setPropertyContainer(properties); return loadgroup; }
From source file:com.openedit.users.filesystem.FileSystemUserManager.java
License:Open Source License
/** * May be subclassed// w ww .ja v a 2s .c o m */ protected User loadUser(String inUserName) throws UserManagerException { File userFile = loadUserFile(inUserName); if (!userFile.exists()) { ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/users/" + inUserName + ".xml"); userFile = new File(stub.getAbsolutePath()); } if (!userFile.exists()) { return null; } FileSystemUser user = new FileSystemUser(); user.setUserName(inUserName); Element root = getXmlUtil().getXml(userFile, "UTF-8"); user.setEnabled(true); String enabled = root.attributeValue("enabled"); if (enabled != null && Boolean.parseBoolean(enabled) == false) { user.setEnabled(false); } else { user.setEnabled(true); } Element passwordElem = root.element("password"); if (passwordElem != null) { user.setPassword(passwordElem.getText()); } Element lastLoginElem = root.element("lastLogined-Time"); if (lastLoginElem != null) { user.setLastLoginTime(lastLoginElem.getText()); } Element creationDateElem = root.element("creation-date"); if (creationDateElem != null) { long time = Long.parseLong(creationDateElem.getText()); user.setCreationDate(new Date(time)); } MapPropertyContainer container = new MapPropertyContainer(); container.loadProperties(root.element("properties")); user.setPropertyContainer(container); for (Iterator iter = root.elementIterator("group"); iter.hasNext();) { Element group = (Element) iter.next(); Group g = getGroup(group.attributeValue("id")); if (g != null) { user.addGroup(g); } else { log.error("Missing group " + group.attributeValue("id")); } } getUserNameToUserMap().put(user.getUserName(), user); return user; }
From source file:com.openedit.users.filesystem.XmlUserArchive.java
License:Open Source License
/** * @see com.openedit.users.UserManager#getGroup(String) *///w w w. j av a 2s. c o m public Group getGroup(String inGroupId) { Group group = (Group) getGroupIdToGroupMap().get(inGroupId); File find = loadGroupFile(inGroupId); if (group != null) { if (group.getLastModified() == find.lastModified()) { return group; } } if (!find.exists()) { ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/groups/" + inGroupId + ".xml"); find = new File(stub.getAbsolutePath()); } if (!find.exists()) { return null; } if (group == null) { // System.out.println("calling " + inGroupId + " " + hashCode() ); group = new FileSystemGroup(); } FileSystemGroup loadgroup = (FileSystemGroup) group; group = loadgroup; loadgroup.setLastModified(find.lastModified()); getGroupIdToGroupMap().put(inGroupId, group); Element root = getXmlUtil().getXml(find, "UTF-8"); loadgroup.setId(root.attributeValue("id")); if (loadgroup.getId() == null) { loadgroup.setId(inGroupId); } loadgroup.setName(root.elementText("group-name")); if (loadgroup.getName() == null) { loadgroup.setName(inGroupId); } Element perm = root.element("permissions"); if (perm != null) { for (Iterator iterator = perm.elementIterator("permission"); iterator.hasNext();) { Element type = (Element) iterator.next(); loadgroup.addPermission(type.getTextTrim()); } } MapPropertyContainer properties = new MapPropertyContainer(); Element props = root.element("properties"); properties.loadProperties(props); loadgroup.setPropertyContainer(properties); return loadgroup; }