List of usage examples for org.dom4j Element elements
List<Element> elements(QName qName);
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
private SurveySection constructSection(Element sectionElement) { SurveySection section = new SurveySection(); section.setSectionName(sectionElement.attributeValue("name")); section.setColor(sectionElement.attributeValue("color")); section.setLightColor(sectionElement.attributeValue("lightColor")); for (Object practiceElement : sectionElement.elements("practice")) { section.getSurveyPractices().add(constructPractice((Element) practiceElement)); }//from ww w .ja v a 2s. c om for (SurveyPractice practice : section.getSurveyPractices()) { practice.setSurveySection(section); } return section; }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
private SurveyPractice constructPractice(Element practiceElement) { SurveyPractice practice = new SurveyPractice(); practice.setName(practiceElement.attributeValue("name")); for (Object objectiveElement : practiceElement.elements("objective")) { practice.getSurveyObjectives().add(constructObjective((Element) objectiveElement)); }//from w w w . j a v a 2s . c om for (SurveyObjective objective : practice.getSurveyObjectives()) { objective.setSurveyPractice(practice); } return practice; }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
private SurveyObjective constructObjective(Element objectiveElement) { SurveyObjective objective = new SurveyObjective(); objective.setDescription(objectiveElement.elementText("description")); objective.setLevelNumber(Integer.parseInt(objectiveElement.attributeValue("level"))); for (Object questionElement : objectiveElement.elements("question")) { objective.getSurveyQuestions().add(constructQuestion((Element) questionElement)); }//from w ww .jav a 2s . co m for (SurveyQuestion question : objective.getSurveyQuestions()) { question.setSurveyObjective(objective); } return objective; }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
private SurveyQuestion constructQuestion(Element questionElement) { SurveyQuestion question = new SurveyQuestion(); question.setSurveyQuestion(questionElement.getTextTrim()); for (Object assertionElement : questionElement.elements("assertion")) { question.getSurveyAssertions().add(constructAssertion((Element) assertionElement)); }/* ww w.j a v a2 s .com*/ for (SurveyAssertion assertion : question.getSurveyAssertions()) { assertion.setSurveyQuestion(question); } return question; }
From source file:com.devoteam.srit.xmlloader.asn1.dictionary.ASNDictionary.java
License:Open Source License
public void parseFromXML(Element root) throws Exception { this.layer = root.attributeValue("layer"); this.className = root.attributeValue("className"); List<Element> listElement = root.elements("element"); for (Element elem : listElement) { String coding = elem.attributeValue("coding"); ElementAbstract elemInfo = ElementAbstract.buildFactory(coding); elemInfo.parseFromXML(elem, this, null, true); addElement(elemInfo);//w ww.j a v a 2 s . c o m } List<Element> listEmbedded = root.elements("embedded"); for (Element elem : listEmbedded) { Embedded embedded = new Embedded(); embedded.parseFromXML(elem, this); this.embeddedList.addEmbedded(embedded); } }
From source file:com.devoteam.srit.xmlloader.core.coding.binary.Dictionary.java
License:Open Source License
public Dictionary(Element root, String syntax) throws Exception { List<Element> listElem = root.element("header").elements("field"); for (Element element : listElem) { fieldsMapHeader.put(element.attributeValue("name"), new EnumerationField(element)); }/*from w ww . j a va 2s. c o m*/ List<Element> list = root.elements("element"); for (Element elem : list) { ElementAbstract elemInfo = null; if ("Q931".equalsIgnoreCase(syntax)) { elemInfo = ElementAbstract.buildFactory("Q931"); } else { String coding = elem.attributeValue("coding"); elemInfo = ElementAbstract.buildFactory(coding); } elemInfo.parseFromXML(elem, null, null); elementsMapByLabel.put(elemInfo.getLabel(), elemInfo); elementsMapByTag.put(elemInfo.getTag(), elemInfo); } }
From source file:com.devoteam.srit.xmlloader.core.coding.binary.ElementAbstract.java
License:Open Source License
public void parseFromXML(Element elementRoot, Dictionary dictionary, ElementAbstract elemDico) throws Exception { //si non present dans le dico on parse le fichier xml if (elemDico == null) { String tagStr = elementRoot.attributeValue("identifier"); if (tagStr == null) { tagStr = elementRoot.attributeValue("tag"); }/*ww w . j ava 2s . c o m*/ tagStr = tagStr.trim(); int iPos = tagStr.indexOf(":"); String label = null; String value = tagStr; if (iPos >= 0) { label = tagStr.substring(0, iPos); value = tagStr.substring(iPos + 1); } int tagInt = getTagValueFromBinary(value); this.tag = tagInt; this.label = label; } // for Q931 protocols String labelTag = elementRoot.attributeValue("name"); if (labelTag != null) { this.label = labelTag; } String instances = elementRoot.attributeValue("instances"); if (instances != null) { this.instances = Integer.parseInt(instances); } List<Element> listField = elementRoot.elements("field"); for (Iterator<Element> it = listField.iterator(); it.hasNext();) { Element fieldRoot = it.next(); String name = fieldRoot.attributeValue("name"); FieldAbstract field = null; // Case if field is present in the dico if (elemDico != null) { field = elemDico.getFieldsByName(name); } if (field == null) { field = FieldAbstract.parseFromXML(fieldRoot); } this.fieldsByName.put(name, field); this.fields.add(field); } // initiate the Array containing the fields this.fieldsArray = new SupArray(); Array emptyArray = new DefaultArray(getLengthElem() / 8); this.fieldsArray.addFirst(emptyArray); this.subelementsArray = new SupArray(); // set the value for each fields listField = elementRoot.elements("field"); //boucle pour setter tous les field de elemV int offset = 0; for (Iterator<Element> it = listField.iterator(); it.hasNext();) { Element element1 = it.next(); String fieldName = element1.attributeValue("name"); FieldAbstract field = this.fieldsByName.get(fieldName); if (field != null) { String value = element1.attributeValue("value"); if (value != null) { field.setValue(value, offset, this.fieldsArray); } else { field.setOffset(offset); } int length = field.length; if (length != 0) { offset += length; } else { offset = this.fieldsArray.length * 8; } } else { throw new ExecutionException( "The field \"" + fieldName + "\" is not found in the element : \"" + this.tag + "\""); } } //parse the sub-elements List<Element> listElement = elementRoot.elements("element"); ElementAbstract subElemDico = null; ElementAbstract elem = null; for (Iterator<Element> it = listElement.iterator(); it.hasNext();) { Element elemElement = it.next(); if (dictionary != null) { subElemDico = dictionary.getElementFromXML(elemElement); elem = (ElementAbstract) subElemDico.cloneAttribute(); elem.parseFromXML(elemElement, dictionary, subElemDico); this.elements.add(elem); } } }
From source file:com.devoteam.srit.xmlloader.core.coding.binary.EnumerationField.java
License:Open Source License
public EnumerationField(Element rootXML) { super(rootXML); List<Element> list = rootXML.elements("enum"); for (Element elemEnum : list) { String valueStr = elemEnum.attributeValue("value"); String nameStr = elemEnum.attributeValue("name"); int iPos = valueStr.indexOf('-'); if (iPos >= 0) { String beginStr = valueStr.substring(0, iPos); String endStr = valueStr.substring(iPos + 1); EnumRange range = new EnumRange(beginStr, endStr, nameStr); ranges.add(range);//from w w w . j a va 2 s . c om this.valuesByLabel.put(nameStr, range.getBegin()); } else { byte[] valueBytes = Utils.parseBinaryString(valueStr); int value = (int) valueBytes[0] & 0xFF; this.valuesByLabel.put(nameStr, value); this.labelsByValue.put(value, nameStr); } } }
From source file:com.devoteam.srit.xmlloader.core.coding.binary.EnumLongField.java
License:Open Source License
@Override public void parseFromXML(Element rootXML, boolean parseDico) { super.parseFromXML(rootXML, parseDico); List<Element> list = rootXML.elements("enum"); for (Element elemEnum : list) { String valueStr = elemEnum.attributeValue("value"); String nameStr = elemEnum.attributeValue("name"); int iPos = valueStr.indexOf('-'); if (iPos >= 0) { String beginStr = valueStr.substring(0, iPos); String endStr = valueStr.substring(iPos + 1); EnumRange range = new EnumRange(beginStr, endStr, nameStr); ranges.add(range);//from ww w . j ava 2 s . co m this.valuesByLabel.put(nameStr, range.getBeginValue()); this.labelsByValue.put(range.getBeginValue(), nameStr); } else { byte[] valueBytes = Utils.parseBinaryString(valueStr); long value = EnumRange.toLong(valueBytes); this.valuesByLabel.put(nameStr, value); this.labelsByValue.put(value, nameStr); } } }
From source file:com.devoteam.srit.xmlloader.core.coding.binary.EnumStringField.java
License:Open Source License
@Override public void parseFromXML(Element rootXML, boolean parseDico) { super.parseFromXML(rootXML, parseDico); List<Element> list = rootXML.elements("enum"); for (Element elemEnum : list) { String valueStr = elemEnum.attributeValue("value"); String nameStr = elemEnum.attributeValue("name"); this.valuesByLabel.put(nameStr, valueStr); this.labelsByValue.put(valueStr, nameStr); }/*from w w w . j a v a 2s . co m*/ }