List of usage examples for org.jdom2 Attribute getName
public String getName()
Attribute
. From source file:de.andrena.tools.macker.rule.RuleSetBuilder.java
License:Open Source License
public Pattern buildPattern(final Element patternElem, final RuleSet ruleSet, final boolean isTopElem, final Pattern nextPat) throws RulesException { // handle options final String otherPatName = patternElem.getAttributeValue("pattern"); final String className = getClassNameAttributeValue(patternElem); final String filterName = patternElem.getAttributeValue("filter"); CompositePatternType patType;//from w w w .ja v a 2 s . co m if (patternElem.getName().equals("include")) { patType = CompositePatternType.INCLUDE; } else if (patternElem.getName().equals("exclude")) { patType = filterName == null ? CompositePatternType.EXCLUDE : CompositePatternType.INCLUDE; } else if (isTopElem) { patType = CompositePatternType.INCLUDE; } else { throw new RulesDocumentException(patternElem, "Invalid element <" + patternElem.getName() + "> --" + " expected <include> or <exclude>"); } if (otherPatName != null && className != null) { throw new RulesDocumentException(patternElem, "patterns cannot have both a \"pattern\" and a \"class\" attribute"); } // do the head thing Pattern head = null; if (className != null) { head = new RegexPattern(className); } else if (otherPatName != null) { head = ruleSet.getPattern(otherPatName); if (head == null) { throw new UndeclaredPatternException(otherPatName); } } // build up children Pattern childrenPat = null; final List<Element> children = new ArrayList<Element>(getChildren(patternElem)); // ! // workaround // for // bug // in // JUnit // List children = patternElem.getChildren(); // this should work // instead when JUnit bug is fixed for (final ListIterator<Element> childIter = children.listIterator(children.size()); childIter .hasPrevious();) { final Element subElem = childIter.previous(); if (subElem.getName().equals("message")) { continue; } childrenPat = buildPattern(subElem, ruleSet, false, childrenPat); } // wrap head in a filter if necessary if (filterName != null) { final Map<String, String> options = new HashMap<String, String>(); for (final Attribute attr : getAttributes(patternElem)) { options.put(attr.getName(), attr.getValue()); } options.remove("name"); options.remove("pattern"); options.remove("class"); options.remove("regex"); final Filter filter = FilterFinder.findFilter(filterName); head = filter.createPattern(ruleSet, head == null ? new ArrayList<Pattern>() : Collections.singletonList(head), options); if (patternElem.getName().equals("exclude")) { head = CompositePattern.create(CompositePatternType.EXCLUDE, head, null, null); } } // pull together composite return CompositePattern.create(patType, head, childrenPat, nextPat); }
From source file:de.bund.bfr.knime.pmm.xml2table.XML2TableNodeDialog.java
License:Open Source License
private static List<String> getElements(BufferedDataTable table, String column) { int index = table.getSpec().findColumnIndex(column); Set<String> elements = new LinkedHashSet<>(); for (DataRow row : table) { PmmXmlDoc xml = XML2TableNodeModel.createXml(row.getCell(index)); if (xml != null) { for (PmmXmlElementConvertable e : xml.getElementSet()) { for (Attribute attr : e.toXmlElement().getAttributes()) { elements.add(attr.getName()); }// w ww.j a v a 2 s . c o m } } } return new ArrayList<>(elements); }
From source file:delfos.io.xml.recommendations.RecommendationsToXML.java
License:Open Source License
/** * Convierte el elemento XML indicado en un objeto que representa las recomendaciones al usuario. * * @param element Elemento XML a convertir. * @return Recomendaciones.//from w ww.j a v a 2 s. c om * * @throws IllegalArgumentException Si el elemento no contiene la informacin necesaria para recuperar un objeto * {@link Recommendations}. * * @see RecommendationsToXML#getRecommendationsElement(delfos.RS.Recommendation.Recommendations) * */ public static Recommendations getRecommendations(Element element) { if (!element.getName().equals(RECOMMENDATIONS_ELEMENT_NAME)) { throw new IllegalArgumentException("Element name doesn't match this reader: found '" + element.getName() + "' expected '" + RECOMMENDATIONS_ELEMENT_NAME + "'"); } String idTarget = element.getAttributeValue(ID_TARGET_ATTRIBUTE_NAME); Map<DetailField, Object> details = new TreeMap<>(); for (Attribute attribute : element.getAttributes()) { if (ID_TARGET_ATTRIBUTE_NAME.equals(attribute.getName())) { continue; } DetailField detailField = DetailField.valueOfNoCase(attribute.getName()); String detailFieldValueString = attribute.getValue(); Object detailFieldValue = detailField.parseValue(detailFieldValueString); details.put(detailField, detailFieldValue); } RecommendationComputationDetails recommendationComputationDetails = new RecommendationComputationDetails( details); List<Recommendation> recommendations = new LinkedList<>(); for (Object r : element.getChildren(RECOMMENDATION_ELEMENT_NAME)) { Element recommendationElement = (Element) r; if (!recommendationElement.getName().equals(RECOMMENDATION_ELEMENT_NAME)) { throw new IllegalArgumentException("Element name doesn't match this reader: found '" + recommendationElement.getName() + "' expected '" + RECOMMENDATION_ELEMENT_NAME + "'"); } int idItem = Integer.parseInt(recommendationElement.getAttributeValue(ID_ITEM_ATTRIBUTE_NAME)); double preference = Double .parseDouble(recommendationElement.getAttributeValue(PREFERENCE_ATTRIBUTE_NAME)); recommendations.add(new Recommendation(idItem, preference)); } return RecommendationsFactory.createRecommendations(idTarget, recommendations, recommendationComputationDetails); }
From source file:delfos.main.managers.experiment.join.xml.AggregateResultsXML.java
License:Open Source License
public Map<String, Object> extractCaseParametersMapFromElement(Element element) { Map<String, Object> valuesByColumnName = new TreeMap<>(); String elementName = element.getName(); if (element.getAttribute("name") != null) { elementName = elementName + "." + element.getAttributeValue("name"); }/*from w w w .j a v a 2 s . c o m*/ if (elementName.equals(CASE_ROOT_ELEMENT_NAME)) { for (Attribute attribute : element.getAttributes()) { String name = CaseStudyXML.CASE_ROOT_ELEMENT_NAME + "." + attribute.getName(); String value = attribute.getValue(); valuesByColumnName.put(name, value); } } if (elementName.equals(RelevanceCriteriaXML.ELEMENT_NAME)) { double threshold = RelevanceCriteriaXML.getRelevanceCriteria(element).getThreshold().doubleValue(); valuesByColumnName.put(RelevanceCriteriaXML.ELEMENT_NAME, threshold); } else if (element.getChildren().isEmpty()) { String columnName; String value; if (!element.hasAttributes()) { throw new IllegalArgumentException("arg"); } if (element.getAttribute("name") != null) { columnName = elementName; value = element.getAttributeValue("name"); } else if (element.getAttribute("parameterName") != null) { columnName = element.getAttributeValue("parameterName"); value = element.getAttributeValue("parameterValue"); } else { throw new IllegalStateException("arg"); } valuesByColumnName.put(columnName, value); } else { for (Element child : element.getChildren()) { if (child.getName().equals(AGGREGATE_VALUES_ELEMENT_NAME)) { continue; } if (child.getName().equals(EXECUTIONS_RESULTS_ELEMENT_NAME)) { throw new IllegalArgumentException("The file is a full results file!"); } Map<String, Object> extractCaseParametersMapFromElement = extractCaseParametersMapFromElement( child); for (Map.Entry<String, Object> entry : extractCaseParametersMapFromElement.entrySet()) { String columnNameWithPrefix = elementName + "." + entry.getKey(); Object value = entry.getValue(); valuesByColumnName.put(columnNameWithPrefix, value); } } } return valuesByColumnName; }
From source file:devicemodel.conversions.XmlConversions.java
public static DeviceNode xmlToNode(Element e, String id) { String[] ids = new String[] { "" }; if (e.getAttribute("ids") != null) { ids = e.getAttributeValue("ids").split(","); e.removeAttribute("ids"); }//from w w w. j a va 2 s .c o m DeviceNode node = new DeviceNode(e.getName() + id); node.setValue(e.getTextTrim()); for (Attribute a : e.getAttributes()) { node.getAttributes().put(a.getName(), a.getValue()); } for (String cid : ids) { for (Element c : e.getChildren()) { try { node.addChild(xmlToNode(c, cid)); } catch (Exception ex) { } } } return node; }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.AttributeListInferencerImpl.java
License:Apache License
/** * @see AttributeListInferencer#learnAttributeList(List, int) *//*www .j a v a 2s . c om*/ @Override public void learnAttributeList(List<Attribute> attrList, int documentIndex) { checkNotNull(attrList, "'attrList' must not be null"); if (!firstTime) { //First, we mark as optional any known attribute which does not reoccur for (SchemaAttribute schemaAttribute : knownAttributes.keySet()) { boolean found = false; for (Attribute attribute : attrList) { if (attribute.getName().equals(schemaAttribute.getName()) && attribute.getNamespace().getURI().equals(schemaAttribute.getNamespace())) found = true; } if (!found) schemaAttribute.setOptional(true); } } //Now, we learn the information given by this list of atttributes for (Attribute attribute : attrList) { if (attribute.getNamespaceURI().equals(XSI_NAMESPACE_URI)) continue;//Attributes in the XSI namespace are not extracted. SchemaAttribute schemaAttribute = searchSchemaAttribute(attribute.getNamespaceURI(), attribute.getName()); //New attribute if (schemaAttribute == null) { schemaAttribute = new SchemaAttribute(attribute.getName(), attribute.getNamespaceURI(), true, new SimpleType("")); if (firstTime) schemaAttribute.setOptional(false); SimpleTypeInferencer simpleTypeInferencer = InferencersFactory.getInstance() .getSimpleTypeInferencerInstance(schemaAttribute.getNamespace() + config.getTypeNamesAncestorsSeparator() + schemaAttribute.getName(), config); simpleTypeInferencer.learnValue(attribute.getValue(), attribute.getNamespaceURI(), "@" + attribute.getName()); knownAttributes.put(schemaAttribute, simpleTypeInferencer); } //Already known attribute else { knownAttributes.get(schemaAttribute).learnValue(attribute.getValue(), attribute.getNamespaceURI(), "@" + attribute.getName()); } complexTypeStatisticsEntry.registerAttributeOccurrenceInfoCount(schemaAttribute, documentIndex); complexTypeStatisticsEntry.registerValueOfNodeCount(attribute.getValue(), schemaAttribute, documentIndex); String realPathFiltered = TypesExtractorImpl.filterAndJoinRealPath(TypesExtractorImpl .getRealPathOfAttributeUnfiltered(attribute, config, solvedNamespaceToPrefixMapping)); statistics.registerAttributeOccurrenceAtPathCount(realPathFiltered, documentIndex); statistics.registerValueAtPathCount(realPathFiltered, attribute.getValue(), documentIndex); } firstTime = false; }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.TypesExtractorImpl.java
License:Apache License
/** * Returns a path of the attribute made of the name of the elements and their prefixes. * Prefixes are separated from element names by :, so THEY MUST BE REPLACED BY _ if they are going to be used to build type names. * Note that the : WILL always appear, although there is not any namespace prefix. * @param attribute the attribute/*from w w w . j a va 2s. c om*/ * @param config current inference configuration * @param solvedNamespaceToPrefixMapping the solved mappings between the namespace URIs and prefix * @return a list that represents the path * @throws NullPointerException if any argument is null */ public static List<String> getRealPathOfAttributeUnfiltered(Attribute attribute, XSDInferenceConfiguration config, Map<String, String> solvedNamespaceToPrefixMapping) { checkNotNull(attribute, "'attribute' must not be null"); checkNotNull(config, "'config' must not be null"); List<String> path = getRealPathOfElementUnfiltered(attribute.getParent(), config, false, solvedNamespaceToPrefixMapping); path.add("@" + attribute.getNamespacePrefix() + ":" + attribute.getName()); return path; }
From source file:helpers.XMLParser.java
public static ParsedSingleXML parseSingleDoc(String xml) { ParsedSingleXML doc = null;/* www. j ava 2s . c o m*/ try { SAXBuilder saxBuilder = new SAXBuilder(); Document document = saxBuilder.build(new StringReader(xml)); Element root = document.getRootElement(); List<Attribute> rootAttributes = root.getAttributes(); doc = new ParsedSingleXML(root.getName()); for (Attribute attr : rootAttributes) { doc.addAttr(attr.getName(), attr.getValue()); } XMLRow row; List<Element> rootChildren = root.getChildren(); List<Element> tempChildren; List<Attribute> tempAttributes; for (Element child : rootChildren) { tempChildren = child.getChildren(); row = new XMLRow(child.getName()); tempAttributes = child.getAttributes(); for (Attribute attr : tempAttributes) { row.addRootAttr(attr.getName(), attr.getValue()); } for (Element tChild : tempChildren) { row.addRowElement(tChild.getName(), tChild.getValue()); } doc.addRow(row); } } catch (JDOMException ex) { Logger.getLogger(XMLParser.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(XMLParser.class.getName()).log(Level.SEVERE, null, ex); } return doc; }
From source file:io.smartspaces.workbench.project.jdom.JdomProjectGroupTemplateSpecificationReader.java
License:Apache License
/** * Get any attributes attached to the project. * * @param spec/*ww w. ja v a 2 s . c om*/ * the specification whose data is being read * @param rootElement * root element of the XML DOM containing the project data */ private void getSpecificationAttributes(GroupProjectTemplateSpecification spec, Element rootElement) { @SuppressWarnings("unchecked") List<Attribute> attributes = rootElement.getAttributes(); for (Attribute attribute : attributes) { spec.addAttribute(attribute.getName(), attribute.getValue()); } }
From source file:io.smartspaces.workbench.project.jdom.JdomProjectReader.java
License:Apache License
/** * Get any attributes attached to the project. * * @param project//from w ww.jav a 2s .co m * the project description whose data is being read * @param rootElement * root element of the XML DOM containing the project data */ private void getProjectAttributes(Project project, Element rootElement) { @SuppressWarnings("unchecked") List<Attribute> attributes = rootElement.getAttributes(); for (Attribute attribute : attributes) { project.addAttribute(attribute.getName(), attribute.getValue()); } }