Java Code Examples for org.dom4j.Element#elementIterator()
The following examples show how to use
org.dom4j.Element#elementIterator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: App.java From database-sync with MIT License | 6 votes |
public void init(){ srcDb = new DbInfo(); destDb = new DbInfo(); jobList = new ArrayList<JobInfo>(); SAXReader reader = new SAXReader(); try { //读取xml的配置文件名,并获取其里面的节点 Element root = reader.read("jobs.xml").getRootElement(); Element src = root.element("source"); Element dest = root.element("dest"); Element jobs = root.element("jobs"); //遍历job即同步的表 for(Iterator it = jobs.elementIterator("job"); it.hasNext();){ jobList.add((JobInfo) elementInObject((Element)it.next(), new JobInfo())); } // elementInObject(src, srcDb); elementInObject(dest, destDb); code = root.element("code").getTextTrim(); } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: FoxBPMCfgParseUtil.java From FoxBPM with Apache License 2.0 | 6 votes |
private FoxBPMConfig parseElement(Element element){ Element childElem = null; String nodeName = null; FoxBPMConfig foxBPMConfig = new FoxBPMConfig(); for (Iterator<Element> iterator = element.elementIterator(); iterator.hasNext();) { childElem = iterator.next(); nodeName = childElem.getName(); if (ELEMENT_TASKCOMMANDS.equals(nodeName)) { foxBPMConfig.setTaskCommandDefinitions(parseTaskCommands(childElem)); } else if (ELEMENT_EVENTLISTENERS.equals(nodeName)) { foxBPMConfig.setEventListeners(parseEventListeners(childElem)); } else if (ELEMENT_BIZDATAOBJECTS.equals(nodeName)) { foxBPMConfig.setDataObjectDefinitions(parseBizDataObject(childElem)); }else if(ELEMENT_PLUGINS.equals(nodeName)){ foxBPMConfig.setConfigurators(parsePlugins(childElem)); } } return foxBPMConfig; }
Example 3
Source File: GetInfo.java From cpsolver with GNU Lesser General Public License v3.0 | 5 votes |
public static HashMap<String, String> getInfo(Element root) { try { HashMap<String, String> info = new HashMap<String, String>(); for (Iterator<?> i = root.elementIterator("property"); i.hasNext();) { Element property = (Element) i.next(); String key = property.attributeValue("name"); String value = property.getText(); if (key == null || value == null) continue; if (value.indexOf('(') >= 0 && value.indexOf(')') >= 0) { value = value.substring(value.indexOf('(') + 1, value.indexOf(')')); if (value.indexOf('/') >= 0) { String bound = value.substring(value.indexOf('/') + 1); if (bound.indexOf("..") >= 0) { String min = bound.substring(0, bound.indexOf("..")); String max = bound.substring(bound.indexOf("..") + 2); info.put(key + " Min", min); info.put(key + " Max", max); } else { info.put(key + " Bound", bound); } value = value.substring(0, value.indexOf('/')); } } if (value.length() > 0) info.put(key, value); } return info; } catch (Exception e) { System.err.println("Error reading info, message: " + e.getMessage()); return null; } }
Example 4
Source File: NetconfCodec.java From onos with Apache License 2.0 | 5 votes |
/** * Returns the data root element based on the NETCONF operation parameter. * * @param rootElement root element of document tree to find the root node * @param opType protocol operation being performed * @return the data root node element */ public Element getDataRootElement(Element rootElement, YmsOperationType opType) { Element retElement = null; String elementName = rootElement.getName(); try { validateOpType(elementName, opType); // If config tag name is found then set the root element node. if (DATA.equals(elementName) || CONFIG.equals(elementName) || FILTER.equals(elementName)) { return rootElement; } // If element has child node then traverse through the child node // by recursively calling getDataRootElement method. if (rootElement.hasContent() && !rootElement.isTextOnly()) { for (Iterator i = rootElement.elementIterator(); i.hasNext();) { Element childElement = (Element) i.next(); retElement = getDataRootElement(childElement, opType); } } } catch (Exception e) { // TODO } return retElement; }
Example 5
Source File: ExamConflictStatisticsInfo.java From unitime with Apache License 2.0 | 5 votes |
public void load(Element root) { int version = Integer.parseInt(root.attributeValue("version")); if (version==sVersion) { iVariables.clear(); for (Iterator i1=root.elementIterator("var");i1.hasNext();) { CBSVariable var = new CBSVariable((Element)i1.next()); iVariables.put(new Long(var.getId()),var); } } }
Example 6
Source File: VersionUpdater.java From birt with Eclipse Public License 1.0 | 5 votes |
public void getLastVersion(File controlpath){ System.out.println("old version file path: " + controlpath.getAbsolutePath()); String dayTag = "DayInPast"; String versionTag = "LastDate"; String name; /* this.setCvsControlPath(controlpath); */ SAXReader saxReader = new SAXReader(); Document document = null; try{ document = saxReader.read(this.cvsControlPath); }catch(org.dom4j.DocumentException dex){ dex.printStackTrace(); } Element rootElement = document.getRootElement(); Iterator it = rootElement.elementIterator(); while(it.hasNext()){ Element element = (Element)it.next(); name = element.getName(); if ( name.equalsIgnoreCase(versionTag)){ this.oldVersion = element.getText(); }else if( name.equalsIgnoreCase(dayTag) ){ this.daysInPast = Integer.valueOf(element.getText().trim()).intValue(); } } }
Example 7
Source File: Hint.java From unitime with Apache License 2.0 | 5 votes |
public static Hint fromXml(Element element) { Vector roomIds = new Vector(); for (Iterator i=element.elementIterator("room");i.hasNext();) roomIds.addElement(Long.valueOf(((Element)i.next()).attributeValue("id"))); return new Hint( Long.valueOf(element.attributeValue("id")), Integer.parseInt(element.attributeValue("days")), Integer.parseInt(element.attributeValue("start")), roomIds, (element.attributeValue("pattern")==null?null:Long.valueOf(element.attributeValue("pattern"))), (element.attributeValue("dates")==null?null:Long.valueOf(element.attributeValue("dates"))) ); }
Example 8
Source File: XmlUtil.java From dal with Apache License 2.0 | 5 votes |
public static List<Element> getChildElements(Element element, String elementName) { List<Element> elements = new ArrayList<>(); for (Iterator<Element> it = element.elementIterator(); it.hasNext();) { Element e = it.next(); if (!e.getName().equalsIgnoreCase(elementName)) continue; elements.add(e); } return elements; }
Example 9
Source File: UpdateSequencesFromXml.java From unitime with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void checkSequences(Element classEl, String parentTable, String parentIdColumn, String parentSequence) throws IOException { String table = classEl.attributeValue("table"); if (table == null) table = parentTable; String sequence = null, idColumn = null; for (Iterator<Element> i = classEl.elementIterator("id"); i.hasNext();) { Element el = i.next(); idColumn = el.attributeValue("column").toLowerCase(); if (el.element("generator") != null) for (Iterator<Element> j = el.element("generator").elementIterator("param"); j.hasNext();) { Element p = j.next(); if ("sequence".equals(p.attributeValue("name"))) sequence = p.getTextTrim(); } } if (sequence == null) sequence = parentSequence; if (idColumn == null) idColumn = parentIdColumn; if (sequence != null && table != null) { info(" " + table + "." + idColumn + ": " + sequence); TreeSet<String> tables = iSequences.get(sequence); if (tables == null) { tables = new TreeSet<String>(); iSequences.put(sequence, tables); } tables.add(table); iIdColumns.put(table, idColumn); } for (Iterator<Element> i=classEl.elementIterator("union-subclass");i.hasNext();) { checkSequences(i.next(), table, idColumn, sequence); } for (Iterator<Element> i=classEl.elementIterator("subclass");i.hasNext();) { checkSequences(i.next(), table, idColumn, sequence); } }
Example 10
Source File: BlackListHepler.java From anima with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public static List<String> loadFromLocal() throws Exception { Document document= XMLFileHelper.getXMLFile(null, CONF_NAME_STRING); List<String> addressList = new ArrayList<String>(); Element root = document.getRootElement(); Iterator<Element> eleIt = root.elementIterator(); while (eleIt.hasNext()) { Element itemEle = eleIt.next(); String address = itemEle.attributeValue("ip"); addressList.add(address); } return addressList; }
Example 11
Source File: StudentSectioningQueue.java From unitime with Apache License 2.0 | 5 votes |
public List<Long> getIds() { if (getMessage() == null) return null; Element root = getMessage().getRootElement(); if (!"generic".equals(root.getName())) return null; List<Long> ids = new ArrayList<Long>(); for (Iterator<Element> i = root.elementIterator("id"); i.hasNext(); ) ids.add(Long.valueOf(i.next().getText())); return ids; }
Example 12
Source File: XmlReadUtil.java From PatatiumAppUi with GNU General Public License v2.0 | 5 votes |
public static String getTestngParametersValue(String path,String ParametersName) throws DocumentException, IOException { File file = new File(path); if (!file.exists()) { throw new IOException("Can't find " + path); } String value=null; SAXReader reader = new SAXReader(); Document document = reader.read(file); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(); i.hasNext();) { Element page = (Element) i.next(); if(page.attributeCount()>0) { if (page.attribute(0).getValue().equalsIgnoreCase(ParametersName)) { value=page.attribute(1).getValue(); //System.out.println(page.attribute(1).getValue()); } continue; } //continue; } return value; }
Example 13
Source File: CourseCatalogImport.java From unitime with Apache License 2.0 | 5 votes |
private void loadCredits(Element course, CourseCatalog catalog) throws Exception { for ( Iterator it = course.elementIterator(); it.hasNext(); ) { Element element = (Element) it.next(); if(element.getName().equals("courseCredit")) continue; CourseSubpartCredit credit = new CourseSubpartCredit(); credit.setCourseCatalog(catalog); credit.setCreditFormat(element.attributeValue("creditFormat")); credit.setCreditType(element.attributeValue("creditType")); credit.setCreditUnitType(element.attributeValue("creditUnitType")); String minCredit = element.attributeValue("fixedCredit"); if(minCredit != null) { credit.setFixedMinimumCredit(Float.parseFloat(minCredit)); } else { minCredit = element.attributeValue("minimumCredit"); if(minCredit != null) { credit.setFixedMinimumCredit(Float.parseFloat(minCredit)); } else { credit.setFixedMinimumCredit(new Float(MIN_CREDIT)); } String maxCredit = element.attributeValue("maximumCredit"); if(maxCredit != null) { credit.setMaximumCredit(Float.parseFloat(maxCredit)); } else { credit.setMaximumCredit(new Float(MAX_CREDIT)); } } credit.setFractionalCreditAllowed(Boolean.valueOf(element.attributeValue("fractionalCreditAllowed"))); credit.setSubpartId(element.attributeValue("subpartId")); catalog.addTosubparts(credit); } }
Example 14
Source File: PermissionModel.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Adds a permission model * * @param model * path to the permission model to add */ public void addPermissionModel(String model) { Document document = createDocument(model); Element root = document.getRootElement(); mutableState.lock.writeLock().lock(); try { Attribute defaultPermissionAttribute = root.attribute(DEFAULT_PERMISSION); if (defaultPermissionAttribute != null) { if (defaultPermissionAttribute.getStringValue().equalsIgnoreCase(ALLOW)) { mutableState.defaultPermission = AccessStatus.ALLOWED; } else if (defaultPermissionAttribute.getStringValue().equalsIgnoreCase(DENY)) { mutableState.defaultPermission = AccessStatus.DENIED; } else { throw new PermissionModelException("The default permission must be deny or allow"); } } else { mutableState.defaultPermission = AccessStatus.DENIED; } DynamicNamespacePrefixResolver nspr = new DynamicNamespacePrefixResolver(); // Namespaces for (Iterator<Element> nsit = root.elementIterator(NAMESPACES); nsit.hasNext(); /**/) { Element namespacesElement = (Element) nsit.next(); for (Iterator<Element> it = namespacesElement.elementIterator(NAMESPACE); it.hasNext(); /**/) { Element nameSpaceElement = (Element) it.next(); nspr.registerNamespace(nameSpaceElement.attributeValue(NAMESPACE_PREFIX), nameSpaceElement.attributeValue(NAMESPACE_URI)); } } // Permission Sets for (Iterator<Element> psit = root.elementIterator(PERMISSION_SET); psit.hasNext(); /**/) { Element permissionSetElement = (Element) psit.next(); PermissionSet permissionSet = new PermissionSet(); permissionSet.initialise(permissionSetElement, nspr, this); mutableState.permissionSets.put(permissionSet.getQName(), permissionSet); } mutableState.buildUniquePermissionMap(); // NodePermissions for (Iterator<Element> npit = root.elementIterator(GLOBAL_PERMISSION); npit.hasNext(); /**/) { Element globalPermissionElement = (Element) npit.next(); GlobalPermissionEntry globalPermission = new GlobalPermissionEntry(); globalPermission.initialise(globalPermissionElement, nspr, this); mutableState.globalPermissions.add(globalPermission); } // Cache all aspect list mutableState.allAspects = dictionaryService.getAllAspects(); } finally { mutableState.lock.writeLock().unlock(); } }
Example 15
Source File: XmlLoader.java From crawler4j with Apache License 2.0 | 4 votes |
/** * Load and parse the crawler4j.xml to get all crawlers. * @return WebCrawler instance list; * @throws Exception */ @SuppressWarnings("unchecked") public List<WebCrawler> load() { List<WebCrawler> crawlers = new ArrayList<WebCrawler>(); SAXReader reader = new SAXReader(); try { InputStream is = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_CONFIG_FILE); document = reader.read(is); Element root = document.getRootElement(); for (Iterator<Element> i = root.elementIterator(); i.hasNext();) { Element taskElement = i.next(); String name = taskElement.elementText("name"); long delay = Long.parseLong(taskElement.elementText("delay")); String url = taskElement.elementText("url"); String parserName = taskElement.elementText("parser").trim(); String defaultCharset = taskElement.elementText("charset"); String pageNoStr = taskElement.elementText("max_page"); String crawlerName = taskElement.elementText("crawler"); String nextPageRegex = taskElement.elementText("next_page_key"); String extractLinksElementId = taskElement.elementText("extract_links_elementId"); Class<Parser> c = (Class<Parser>)Class.forName(parserName); Parser parser = c.newInstance(); if (parser == null) { throw new IllegalArgumentException("parser must not be null!"); } int maxPageNo = 1; if (StringUtils.isNotEmpty(pageNoStr)) { maxPageNo = Integer.parseInt(pageNoStr); } CrawlerConfig config = new CrawlerConfig(name, defaultCharset, url, delay, maxPageNo, nextPageRegex, extractLinksElementId, parserName, crawlerName, parser); WebCrawler crawler = null; //get WebCrawler instance throw reflection if (StringUtils.isBlank(crawlerName)) { crawler = new DefaultWebCrawler(config); } else { crawler = (WebCrawler)Reflections.constructorNewInstance(crawlerName, new Class[] { CrawlerConfig.class }, new CrawlerConfig[] { config }); } crawlers.add(crawler); } } catch (Throwable e) { logger.error(e.getMessage(),e); } return crawlers; }
Example 16
Source File: XmlUtil.java From myspring with MIT License | 4 votes |
/** * readXml2 * * @param fileName * @param beanDefines */ @SuppressWarnings("rawtypes") public static ApplicationXmlResult readAppXml(String fileName) { try { // 创建一个读取器 SAXReader saxReader = new SAXReader(); Document document = null; // 获取要读取的配置文件的路径 URL xmlPath = XmlUtil.class.getClassLoader().getResource(fileName); // 读取文件内容 document = saxReader.read(xmlPath); // 获取xml中的根元素 Element rootElement = document.getRootElement(); //不是beans根元素的,文件不对 if (!"beans".equals(rootElement.getName())) { System.err.println("applicationContext.xml文件格式不对,缺少beans"); return null; } ApplicationXmlResult result = new ApplicationXmlResult(); List<BeanDefinition> beanDefines = new ArrayList<>(); result.setBeanDefines(beanDefines); for (Iterator iterator = rootElement.elementIterator(); iterator.hasNext();) { Element element = (Element) iterator.next(); String eleName = element.getName(); if ("component-scan".equals(eleName)) { //扫描目录 String scanPackage = element.attributeValue("base-package"); result.setComponentScan(scanPackage); } else if ("bean".equals(eleName)) { //扫描并解析bean定义 beanDefines.add(parseBeanDefine(element)); } else { System.out.println("不支持此xml标签解析:" + eleName); } } return result; } catch (Exception e) { e.printStackTrace(); } return null; }
Example 17
Source File: AssignmentPreferenceInfo.java From unitime with Apache License 2.0 | 4 votes |
public void load(Element root) { int version = Integer.parseInt(root.attributeValue("version")); if (version==sVersion) { iNormalizedTimePreference = Double.parseDouble(root.elementText("normTimePref")); iBestNormalizedTimePreference = Double.parseDouble(root.elementText("bestNormTimePref")); iTimePreference = Integer.parseInt(root.elementText("timePref")); for (Iterator i=root.elementIterator("roomPref");i.hasNext();) { Element e = (Element)i.next(); iRoomPreference.put(Long.valueOf(e.attributeValue("id")),Integer.valueOf(e.getText())); } iBestRoomPreference = Integer.parseInt(root.elementText("bestRoomPref")); iNrStudentConflicts = Integer.parseInt(root.elementText("nrStudentConf")); iNrHardStudentConflicts = Integer.parseInt(root.elementText("nrHardStudentConf")); iNrDistanceStudentConflicts = Integer.parseInt(root.elementText("nrDistanceStudentConf")); iNrCommitedStudentConflicts = Integer.parseInt(root.elementText("nrCommitedStudentConf")); iNrTimeLocations = Integer.parseInt(root.elementText("nrTimeLoc")); iNrRoomLocations = Integer.parseInt(root.elementText("nrRoomLoc")); iNrSameRoomPlacementsNoConf = Integer.parseInt(root.elementText("nrSameRoomPlacNoConf")); iNrSameTimePlacementsNoConf = Integer.parseInt(root.elementText("nrSameTimePlacNoConf")); iNrPlacementsNoConf = Integer.parseInt(root.elementText("nrPlacNoConf")); iBtbInstructorPreference = Integer.parseInt(root.elementText("btbInstrPref")); iIsInitial = Boolean.valueOf(root.elementText("isInitial")).booleanValue(); iInitialAssignment = root.elementText("iniAssign"); iHasInitialSameTime = Boolean.valueOf(root.elementText("hasIniSameTime")).booleanValue(); iHasInitialSameRoom = Boolean.valueOf(root.elementText("hasIniSameRoom")).booleanValue(); iPerturbationPenalty = Double.parseDouble(root.elementText("pertPenalty")); iTooBigRoomPreference = Integer.parseInt(root.elementText("tooBig")); iMinRoomSize = Long.parseLong(root.elementText("minSize")); iUselessHalfHours = Integer.parseInt(root.elementText("uselessHalfHours")); iDeptBalancPenalty = Double.parseDouble(root.elementText("deptBalanc")); iGroupConstraintPref = Integer.parseInt(root.elementText("groupConstr")); if (root.elementText("spread")!=null) iSpreadPenalty = Double.parseDouble(root.elementText("spread")); if (root.elementText("maxSpread")!=null) iMaxSpreadPenalty = Double.parseDouble(root.elementText("maxSpread")); else iMaxSpreadPenalty = iSpreadPenalty; if (root.elementText("maxDeptBalanc")!=null) iMaxDeptBalancPenalty = Integer.parseInt(root.elementText("maxDeptBalanc")); else iMaxDeptBalancPenalty = (int)iDeptBalancPenalty; if (root.elementText("datePref") != null) iDatePatternPref = Integer.parseInt(root.elementText("datePref")); if (root.elementText("studentGroupPercent") != null) iStudentGroupPercent = Integer.valueOf(root.elementText("studentGroupPercent")); iStudentGroupComment = root.elementText("studentGroupComment"); } }
Example 18
Source File: SQLStoreImpl.java From anyline with Apache License 2.0 | 4 votes |
private static Hashtable<String, SQL> parseSQLFile(String fileName, InputStream is) { Hashtable<String, SQL> result = new Hashtable<String, SQL>(); Document document = createDocument(is); if (null == document) { return result; } Element root = document.getRootElement(); //全局条件分组 Map<String, List<Condition>> gloableConditions = new HashMap<String, List<Condition>>(); for (Iterator<?> itrCons = root.elementIterator("conditions"); itrCons.hasNext(); ) { Element conditionGroupElement = (Element) itrCons.next(); String groupId = conditionGroupElement.attributeValue("id"); List<Condition> conditions = new ArrayList<Condition>(); gloableConditions.put(groupId, conditions); for (Iterator<?> itrParam = conditionGroupElement.elementIterator("condition"); itrParam.hasNext(); ) { conditions.add(parseCondition(null, null, (Element) itrParam.next())); } } for (Iterator<?> itrSql = root.elementIterator("sql"); itrSql.hasNext(); ) { Element sqlElement = (Element) itrSql.next(); String sqlId = fileName + ":" + sqlElement.attributeValue("id"); //SQL 主键 boolean strict = BasicUtil.parseBoolean(sqlElement.attributeValue("strict"), false); //是否严格格式 true:java中不允许添加XML定义之外的临时条件 String sqlText = sqlElement.elementText("text"); //SQL 文本 SQL sql = new XMLSQLImpl(); sql.setDataSource(fileName + ":" + sqlId); sql.setText(sqlText); sql.setStrict(strict); for (Iterator<?> itrParam = sqlElement.elementIterator("condition"); itrParam.hasNext(); ) { parseCondition(sql, gloableConditions, (Element) itrParam.next()); } String group = sqlElement.elementText("group"); String order = sqlElement.elementText("order"); sql.group(group); sql.order(order); if (ConfigTable.isSQLDebug()) { log.warn("[解析SQL][id:{}]\n[text:{}]", sqlId, sqlText); } result.put(sqlId, sql); } return result; }
Example 19
Source File: Alignment.java From AML-Project with Apache License 2.0 | 4 votes |
private void loadMappingsRDF(String file) throws DocumentException { //Open the Alignment file using SAXReader SAXReader reader = new SAXReader(); File f = new File(file); Document doc = reader.read(f); //Read the root, then go to the "Alignment" element Element root = doc.getRootElement(); Element align = root.element("Alignment"); //Get an iterator over the mappings Iterator<?> map = align.elementIterator("map"); while(map.hasNext()) { //Get the "Cell" in each mapping Element e = ((Element)map.next()).element("Cell"); if(e == null) continue; //Get the source class String sourceURI = e.element("entity1").attributeValue("resource"); //Get the target class String targetURI = e.element("entity2").attributeValue("resource"); //Get the similarity measure String measure = e.elementText("measure"); //Parse it, assuming 1 if a valid measure is not found double similarity = 1; if(measure != null) { try { similarity = Double.parseDouble(measure); if(similarity < 0 || similarity > 1) similarity = 1; } catch(Exception ex){/*Do nothing - use the default value*/}; } //Get the relation String r = e.elementText("relation"); if(r == null) r = "?"; MappingRelation rel = MappingRelation.parseRelation(StringEscapeUtils.unescapeXml(r)); //Get the status String s = e.elementText("status"); if(s == null) s = "?"; MappingStatus st = MappingStatus.parseStatus(s); add(sourceURI, targetURI, similarity, rel, st); } }
Example 20
Source File: Host.java From big-c with Apache License 2.0 | 3 votes |
public synchronized void Parse(Element node){ if(node.getName() != "CLUSTER"){ } List<Attribute> arrtibuteList = node.attributes(); //first initialize or update attributes for(Attribute attribute : arrtibuteList){ if(attribute.getName() == "NAME"){ this.setName(attribute.getValue()); } if(attribute.getName()=="IP"){ this.setIp(attribute.getValue()); } } //then parse the child nodes for (Iterator iterator = node.elementIterator( "METRIC" ); iterator.hasNext(); ) { Element element = (Element) iterator.next(); String name = element.attribute("NAME").getValue(); Metric metric= new Metric(); metric.Parse(element); this.nameToMetrics.put(name, metric); } }