List of usage examples for org.jdom2 Element getName
public String getName()
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.TypesExtractorImpl.java
License:Apache License
/** * Recursive method that traverses an element to extract all the possible information from it. * It is recursive because it calls itself for each child of the element (obviously, infinite recursion * is not possible as there are not, or there should not be, parent-child loops). * The index of the current document is necessary in order to add well some information to * the statistics.//from w ww . j av a 2 s.c om * @param documentIndex index of current document * @param element the element to traverse (as a JDOM2 {@link Element}) * @param enclosingComplexType the complex type which will contain the current element */ private void traverseElement(int documentIndex, Element element, String enclosingComplexType) { //Elements in the XSI namespace should be ignored if (element.getNamespaceURI().equalsIgnoreCase(XSI_NAMESPACE_URI)) return; List<String> realPathUnfiltered = getRealPathOfElementUnfiltered(element, configuration, false, solvedNamespaceToPrefixMapping); String realPathFiltered = filterAndJoinRealPath(realPathUnfiltered);//Path for the statistics List<String> typePathUnfiltered = getRealPathOfElementUnfiltered(element, configuration, false, solvedNamespaceToPrefixMapping); List<String> suitablePath = getSuitablePath(typePathUnfiltered);//Path for type name inferencing //First, we will register the information of width and depth //The root is in a level whose width is 1, if we did not do the following, that width would be never registered if (element.isRootElement()) { statistics.registerWidth(documentIndex, 1); } statistics.registerDepth(documentIndex, realPathUnfiltered.size()); int width = element.getChildren().size(); if (width > 0) { statistics.registerWidth(documentIndex, width); } TypeNameInferencer typeNameInferencer = configuration.getTypeNameInferencer(); String complexTypeName = typeNameInferencer.inferTypeName(suitablePath, configuration);//Complex type of this element // //Little workaround that ensures that the same complex type is used // //when the elements on its path are the same (same name and namespace) but some of them // //use different namespace prefixes // List<String> realPathUnfilteredKey=getRealPathOfElementUnfiltered(element, configuration, false, solvedNamespaceToPrefixMapping); // List<String> suitablePathKey=getSuitablePath(realPathUnfilteredKey);//Path for type name inferencing // String complexTypeNameKey = typeNameInferencer.inferTypeName(suitablePathKey, configuration);//Complex type of this element String complexTypeNameKey = complexTypeName; //The complex type object of this element. ComplexType complexType = complexTypes.get(complexTypeNameKey); if (complexType == null) { complexType = new ComplexType(complexTypeName, null, null, null); complexTypes.put(complexTypeNameKey, complexType); //New complex type } complexType.addSourceNodeNamespaceAndName(element.getNamespaceURI(), element.getName()); //Comment processing for (Comment comment : element.getDescendants(Filters.comment())) { if (comment.getParentElement().equals(element)) complexType.getComments().add(comment.getText()); } //Key to find the corresponding SchemaElement //This key is: if the SchemaElement has an enclosing complex type (i.e., it is not a valid root), its name will be: //enclosingComplexType+typeNamesSeparator+elementName //If the element is a suitable root, the key is the name of the element. String schemaElementKey = (!enclosingComplexType.equals("")) ? enclosingComplexType + configuration.getTypeNamesAncestorsSeparator() + element.getName() : element.getName(); if (configuration.getTypeNameInferencer() instanceof NameTypeNameInferencer) { schemaElementKey = element.getName(); //If we use a name-based type inferencer, the key is the name and we avoid problems. } SchemaElement schemaElement = elements.get(element.getNamespaceURI(), schemaElementKey); if (schemaElement == null) { schemaElement = new SchemaElement(element.getName(), element.getNamespaceURI(), complexType);//Complex type already not known. elements.put(element.getNamespaceURI(), schemaElementKey, schemaElement); } boolean wasAlreadyValidRoot = schemaElement.isValidRoot(); schemaElement.setValidRoot(wasAlreadyValidRoot || element.isRootElement()); ComplexTypeStatisticsEntry complexTypeStatisticsEntry = statistics.getComplexTypeInfo().get(complexType); if (complexTypeStatisticsEntry == null) { complexTypeStatisticsEntry = new ComplexTypeStatisticsEntry(xmlDocuments.size()); statistics.getComplexTypeInfo().put(complexType, complexTypeStatisticsEntry); } AttributeListInferencer attributeListInferencer = attributeListInferencers.get(complexTypeName); if (attributeListInferencer == null) { attributeListInferencer = inferencersFactory.getAttributeListInferencerInstance(complexTypeName, configuration, solvedNamespaceToPrefixMapping, statistics); attributeListInferencers.put(complexTypeName, attributeListInferencer); } attributeListInferencer.learnAttributeList(element.getAttributes(), documentIndex); SimpleTypeInferencer simpleTypeInferencer = simpleTypeInferencersOfComplexTypes.get(complexTypeName); if (simpleTypeInferencer == null) { simpleTypeInferencer = inferencersFactory.getSimpleTypeInferencerInstance(complexTypeName, configuration); simpleTypeInferencersOfComplexTypes.put(complexTypeName, simpleTypeInferencer); } simpleTypeInferencer.learnValue(element.getText(), element.getNamespaceURI(), element.getName()); // SchemaElement previousChildSchemaElement=null; //We need to store the previous child in order to add the edge between it and the current child. List<SchemaElement> schemaElementChildren = new ArrayList<>(element.getChildren().size()); for (int i = 0; i < element.getChildren().size(); i++) { Element child = element.getChildren().get(i); traverseElement(documentIndex, child, complexTypeName); String childSchemaElementKey = complexTypeName + configuration.getTypeNamesAncestorsSeparator() + child.getName(); if (configuration.getTypeNameInferencer() instanceof NameTypeNameInferencer) { childSchemaElementKey = child.getName(); // If we use the name-based type name inferencer, the name is the key } SchemaElement childSchemaElement = elements.get(child.getNamespaceURI(), childSchemaElementKey);//The SchemaElement object does exist because the method traverseElement is called before this. // if(i==0){ // automaton.addEdge(automaton.getInitialState(), childSchemaElement); // } // else { // automaton.addEdge(previousChildSchemaElement, childSchemaElement); // if(i==(element.getChildren().size()-1)){ // automaton.addEdge(childSchemaElement, automaton.getFinalState()); // } // } complexTypeStatisticsEntry.registerElementCount(childSchemaElement, documentIndex); schemaElementChildren.add(childSchemaElement); // previousChildSchemaElement=childSchemaElement; } ExtendedAutomaton automaton = automatons.get(complexTypeName); if (automaton == null) { automaton = new ExtendedAutomaton(); SchemaElement initialState = new SchemaElement("initial", DEFAULT_PSEUDOELEMENTS_NAMESPACE, null); automaton.setInitialState(initialState); SchemaElement finalState = new SchemaElement("final", DEFAULT_PSEUDOELEMENTS_NAMESPACE, null); automaton.setFinalState(finalState); automatons.put(complexTypeName, automaton); } List<SchemaElement> schemaElementChildrenWithInitialAndFinal = new ArrayList<>(schemaElementChildren); schemaElementChildrenWithInitialAndFinal.add(0, automaton.getInitialState()); schemaElementChildrenWithInitialAndFinal.add(automaton.getFinalState()); automaton.learn(schemaElementChildrenWithInitialAndFinal); complexTypeStatisticsEntry.registerSubpatternsFromList(schemaElementChildren); complexTypeStatisticsEntry.registerValueOfNodeCount(element.getText(), schemaElement, documentIndex); statistics.registerElementAtPathCount(realPathFiltered, documentIndex); statistics.registerValueAtPathCount(realPathFiltered, element.getText(), documentIndex); if (enclosingComplexType.equals("")) { statistics.registerRootElementOccurrence(schemaElement); } }
From source file:es.upm.dit.xsdinferencer.generation.generatorimpl.schemageneration.XMLSchemaDocumentGenerator.java
License:Apache License
/** * It generates the XSD file of the targetNamespace given at the constructor, taking into account that * the main namespace is the one given at the constructor. * //ww w.j a v a 2 s . c o m * @param schema the schema object * @param configuration the inference configuration * * @return a JDOM2 {@link Document} object containing the XSD contents. * * @see SchemaDocumentGenerator#generateSchemaDocument(Schema, XSDInferenceConfiguration) */ @Override public Document generateSchemaDocument(Schema schema, XSDInferenceConfiguration configuration) { // if(!configuration.getElementsGlobal()==false || // !configuration.getComplexTypesGlobal()==true || // !configuration.getSimpleTypesGlobal()==true // ) // throw new UnsupportedOperationException("Not implemented yet."); // checkArgument(schema.getNamespacesToPossiblePrefixMappingModifiable().containsKey(mainNamespace), "The main namespace must be a known namespace"); checkArgument(schema.getNamespacesToPossiblePrefixMappingModifiable().containsKey(targetNamespace), "The target namespace must be a known namespace"); // checkArgument(!schema.getNamespacesToPossiblePrefixMappingModifiable().containsKey(XSD_NAMESPACE_URI),"The XSD namespace must not be a known namespace"); // checkArgument(!schema.getNamespacesToPossiblePrefixMappingModifiable().containsKey(XSI_NAMESPACE_URI),"The XSI namespace must not be a known namespace"); Map<String, String> namespaceURIToPrefixMappings = schema.getSolvedNamespaceMappings(); if (configuration.getSkipNamespaces().contains(targetNamespace)) { throw new IllegalArgumentException("This is an skipped namespace, so its XSD should not be generated"); } if (targetNamespace.equals(XSD_NAMESPACE_URI)) System.err.println( "The XML Schema namespace is being considered as a target namespace in your documents. Independing of the inferred schemas, the only valid XSD for an XSD would be the normative one present at its first RFC"); Namespace xsdNamespace = Namespace.getNamespace(XSD_NAMESPACE_PREFIX.replace(":", ""), XSD_NAMESPACE_URI); List<Namespace> namespaceDeclarations = getNamespaceDeclarations(namespaceURIToPrefixMappings, xsdNamespace); Element elementSchema = new Element("schema", xsdNamespace); for (int i = 0; i < namespaceDeclarations.size(); i++) { Namespace currentNamespace = namespaceDeclarations.get(i); elementSchema.addNamespaceDeclaration(currentNamespace); String currentNamespaceUri = currentNamespace.getURI(); if (!targetNamespace.equals(mainNamespace) && !currentNamespaceUri.equals(mainNamespace)) continue; if (currentNamespace.equals(Namespace.XML_NAMESPACE) && (!schema.getAttributes().containsRow(XSDInferenceConfiguration.XML_NAMESPACE_URI) && !schema.getElements().containsRow(XSDInferenceConfiguration.XML_NAMESPACE_URI))) { continue; } if (currentNamespaceUri.equals(XSD_NAMESPACE_URI) && !namespaceURIToPrefixMappings.containsKey(XSD_NAMESPACE_URI)) continue; if (targetNamespace.equals(currentNamespaceUri) || (currentNamespaceUri.equals("") && (fileNameGenerator == null))) continue; if (currentNamespaceUri.equals("") && !currentNamespaceUri.equals(mainNamespace) && !schema.getElements().containsRow("")) continue; Element importElement = new Element("import", xsdNamespace); if (!currentNamespaceUri.equals("")) { Attribute namespaceAttr = new Attribute("namespace", currentNamespaceUri); importElement.setAttribute(namespaceAttr); } if (fileNameGenerator != null && !configuration.getSkipNamespaces().contains(currentNamespaceUri)) { String fileName = fileNameGenerator.getSchemaDocumentFileName(currentNamespaceUri, namespaceURIToPrefixMappings); Attribute schemaLocationAttr = new Attribute("schemaLocation", fileName); importElement.setAttribute(schemaLocationAttr); } elementSchema.addContent(importElement); } if (!targetNamespace.equals("")) { Attribute targetNamespaceAttr = new Attribute("targetNamespace", targetNamespace); elementSchema.setAttribute(targetNamespaceAttr); } SortedSet<SimpleType> sortedSimpleTypes = new TreeSet<>(new SimpleTypeComparator()); sortedSimpleTypes.addAll(schema.getSimpleTypes().values()); SortedSet<ComplexType> sortedComplexTypes = new TreeSet<>(new ComplexTypeComparator()); sortedComplexTypes.addAll(schema.getComplexTypes().values()); //CONTINUE FROM HERE: Generate sorted sets for SchemaElement and SchemaAttribute objects and use them where needed. Attribute elementFormDefault = new Attribute("elementFormDefault", "qualified"); elementSchema.setAttribute(elementFormDefault); Document resultingDocument = new Document(elementSchema); if (targetNamespace.equals(mainNamespace)) { //First, we declare global SimpleTypes. //If simpleTypesGlobal is true, any enumeration will be declared as a global simple type. //if not, simple types of complex types which have attributes but not children will be declared globally //(due to limitations of XSD, they may not be declared locally together with the attributes info) if (configuration.getSimpleTypesGlobal()) { for (SimpleType simpleType : sortedSimpleTypes) { if (!simpleType.isEnum() || simpleType.isEmpty()) continue; Element simpleTypeElement = generateSimpleType(simpleType, false, configuration, xsdNamespace); elementSchema.addContent(simpleTypeElement); } } else { for (ComplexType complexType : sortedComplexTypes) { SimpleType simpleType = complexType.getTextSimpleType(); if (complexType.getAttributeList().isEmpty() || !(complexType.getAutomaton().nodeCount() == 0) || !simpleType.isEnum() || simpleType.isEmpty()) continue; Element simpleTypeElement = generateSimpleType(simpleType, false, configuration, xsdNamespace); elementSchema.addContent(simpleTypeElement); } } //Global complexType elements are only generated in the main schema (i.e. the one whose targetNamespace is equal to mainNamespace) if (configuration.getComplexTypesGlobal()) { for (ComplexType complexType : sortedComplexTypes) { boolean hasNoChildren = complexType.getRegularExpression().equals(new EmptyRegularExpression()); boolean hasNoAttributes = complexType.getAttributeList().size() == 0; boolean hasNoComments = complexType.getComments().size() == 0; // boolean simpleTypeIsNotEmpty = !complexType.getTextSimpleType().isEmpty(); boolean simpleTypeIsWhiteSpaceOnlyOrEmpty = !(complexType.getTextSimpleType().isEmpty() || complexType.getTextSimpleType().consistOnlyOfWhitespaceCharacters()); if (hasNoChildren && hasNoAttributes && simpleTypeIsWhiteSpaceOnlyOrEmpty && hasNoComments) continue; //Because the elements which are linked to this ComplexType at our internal model //will be linked to an XSD simple type elsewhere, either a builtin or a custom one. Element complexTypeElement = generateComplexType(configuration, complexType, false, targetNamespace, namespaceURIToPrefixMappings, mainNamespace, xsdNamespace); elementSchema.addContent(complexTypeElement); } } } //If there are many namespaces and the workaround is disabled, we must declare global attributes. //If the targetNamespace is not the mainNamespace, we must declare all the attributes. //if the target namespace is the main namespace, we do not need to declare anything, because the complex types which hold the attributes //are also in the main namespace. if ((namespaceURIToPrefixMappings.size() - configuration.getSkipNamespaces().size()) > 1) { SortedMap<String, SchemaAttribute> globalAttributeCandidates = new TreeMap<>( schema.getAttributes().row(targetNamespace)); if (!targetNamespace.equals(mainNamespace) && !targetNamespace.equals("")) { globalAttributesLoop: for (Map.Entry<String, SchemaAttribute> schemaAttributeEntry : globalAttributeCandidates .entrySet()) { SchemaAttribute schemaAttribute = schemaAttributeEntry.getValue(); //First, we check if the attribute has been already declared when the workaround is disabled. //If so, we update the "use" property. //The type should have been already merged. if (!configuration.getStrictValidRootDefinitionWorkaround()) { List<Element> alreadyGeneratedAttributeElements = elementSchema.getChildren("attribute", xsdNamespace); for (int i = 0; i < alreadyGeneratedAttributeElements.size(); i++) { Element currentAttributeElement = alreadyGeneratedAttributeElements.get(i); if (currentAttributeElement.getAttributeValue("name") .equals(schemaAttribute.getName())) { continue globalAttributesLoop; } } } Element attributeOrAttributeGroupElement = generateAttribute(schemaAttribute, true, configuration, namespaceURIToPrefixMappings, targetNamespace, mainNamespace, schemaAttributeEntry.getKey(), xsdNamespace); elementSchema.addContent(attributeOrAttributeGroupElement); } } } //Now, we declare global elements. //An element will be declared globally if and only if: //1-elementsGlobal is true in the configuration //2-The element is a valid root //3-The element is in a namespace other than the main namespace. Note that the element WILL be surrounded by the corresponding group if the workaround is enabled. //Another important remark: Iterating over a set copy implies iterating over DISTINCT SchemaElements, so if two keys pointed to equal SchemaElements, we would generate it only once- SortedSet<SchemaElement> schemaElementsAtTargetNamespace = new TreeSet<>(new SchemaElementComparator()); schemaElementsAtTargetNamespace.addAll(schema.getElements().row(targetNamespace).values()); globalSchemaElementsLoop: for (SchemaElement schemaElement : schemaElementsAtTargetNamespace) { // if(!configuration.getElementsGlobal()&& // !schemaElement.isValidRoot()&& // (targetNamespace.equals(mainNamespace)||configuration.getStrictValidRootDefinitionWorkaround())) if (!configuration.getElementsGlobal() && !schemaElement.isValidRoot() && (targetNamespace.equals(mainNamespace))) continue; // for(Element currentElement:elementSchema.getContent(Filters.element("element",xsdNamespace))){ // if(schemaElement.getName().equals(currentElement.getAttributeValue("name"))) // continue globalSchemaElementsLoop; // } String possibleGroupName = schemaElement.getName() + configuration.getTypeNamesAncestorsSeparator() + schemaElement.getType().getName(); for (Element currentElement : elementSchema.getContent(Filters.element("group", xsdNamespace))) { if (possibleGroupName.equals(currentElement.getAttributeValue("name"))) continue globalSchemaElementsLoop; } Element elementOrGroupElement = generateElement(schemaElement, true, configuration, targetNamespace, mainNamespace, null, namespaceURIToPrefixMappings, xsdNamespace); if (elementOrGroupElement.getName().equals("element")) { for (Element currentElement : elementSchema.getChildren("element", xsdNamespace)) { if (schemaElement.getName().equals(currentElement.getAttributeValue("name"))) continue globalSchemaElementsLoop; } } elementSchema.addContent(elementOrGroupElement); } return resultingDocument; }
From source file:es.upm.dit.xsdinferencer.generation.generatorimpl.schemageneration.XMLSchemaDocumentGenerator.java
License:Apache License
/** * Method that generates a complexType tag, wherever it has to be generated and in the correct way * @param configuration the inference configuration * @param complexType the complex type to which the tag will be generated * @param anonymous whether this complex type must be anonymous (i.e. it must not have a 'name' attribute) * @param targetNamespace the target namespace which is currently being generated * @param namespaceURIToPrefixMappings solved mappings between namespace URIs and prefixes * @param mainNamespace main namespace// w ww.j a v a 2 s . co m * @param xsdNamespace namespace of the XML Schema * @return a JDOM2 {@link Element} which describes the complex type */ private Element generateComplexType(XSDInferenceConfiguration configuration, ComplexType complexType, boolean anonymous, String targetNamespace, Map<String, String> namespaceURIToPrefixMappings, String mainNamespace, Namespace xsdNamespace) { Element complexTypeElement = new Element("complexType", xsdNamespace); for (String commentOnComplexType : ImmutableSortedSet.copyOf(complexType.getComments())) { complexTypeElement.addContent(new Comment(commentOnComplexType)); } if (!anonymous) { Attribute complexTypeNameAttr = new Attribute("name", ""); complexTypeNameAttr.setValue(complexType.getName()); complexTypeElement.setAttribute(complexTypeNameAttr); } SimpleType simpleType = complexType.getTextSimpleType(); boolean hasChildren = !complexType.getRegularExpression().equals(new EmptyRegularExpression()); boolean hasNonWhitespaceSimpleContent = !simpleType.isEmpty() && !simpleType.consistOnlyOfWhitespaceCharacters(); if (hasChildren) { //Mixed complex type. As far as I know, XSD does not allow to constraint simple content on mixed types if (hasNonWhitespaceSimpleContent) { Attribute mixedAttr = new Attribute("mixed", ""); mixedAttr.setValue("true"); complexTypeElement.setAttribute(mixedAttr); } Element childrenContent = generateRegexpRepresentation(complexType.getRegularExpression(), configuration, targetNamespace, mainNamespace, complexType, namespaceURIToPrefixMappings, xsdNamespace); if (childrenContent.getName().equals("element")) { Element unwrappedChildrenContent = childrenContent; childrenContent = new Element("sequence", xsdNamespace); childrenContent.addContent(unwrappedChildrenContent); } complexTypeElement.addContent(childrenContent); List<Element> attributesInfo = generateAttributeList(complexType, targetNamespace, mainNamespace, configuration, namespaceURIToPrefixMappings, xsdNamespace); complexTypeElement.addContent(attributesInfo); } else if (complexType.getAttributeList().size() > 0 && !simpleType.isEmpty()) { Element simpleContentElement = new Element("simpleContent", xsdNamespace); Element extensionElement = new Element("extension", xsdNamespace); Attribute extensionBaseAttr = new Attribute("base", ""); String simpleTypeRepresentationName = complexType.getTextSimpleType() .getRepresentationName(configuration.getTypeNamesAncestorsSeparator()); if (!simpleTypeRepresentationName.contains(XSD_NAMESPACE_PREFIX) && !namespaceURIToPrefixMappings.get(mainNamespace).equals("")) { simpleTypeRepresentationName = namespaceURIToPrefixMappings.get(mainNamespace) + ":" + simpleTypeRepresentationName; } extensionBaseAttr.setValue(simpleTypeRepresentationName); extensionElement.setAttribute(extensionBaseAttr); List<Element> attributesInfo = generateAttributeList(complexType, targetNamespace, mainNamespace, configuration, namespaceURIToPrefixMappings, xsdNamespace); extensionElement.addContent(attributesInfo); simpleContentElement.addContent(extensionElement); complexTypeElement.addContent(simpleContentElement); } else if (complexType.getAttributeList().size() > 0) { List<Element> attributesInfo = generateAttributeList(complexType, targetNamespace, mainNamespace, configuration, namespaceURIToPrefixMappings, xsdNamespace); complexTypeElement.addContent(attributesInfo); } //If the complex type consists of a non empty simple type without either children or attributes, no complexType tag would be generated, so it is not handled here return complexTypeElement; }
From source file:esiptestbed.mudrod.ontology.pre.AggregateTriples.java
License:Apache License
/** * Method of going through OWL structure *//*from w w w . j a v a2s .c om*/ public void loopxml() { Iterator<?> processDescendants = rootNode.getDescendants(new ElementFilter()); String text = ""; while (processDescendants.hasNext()) { Element e = (Element) processDescendants.next(); String currentName = e.getName(); text = e.getTextTrim(); if ("".equals(text)) { LOG.info(currentName); } else { LOG.info("{} : {}", currentName, text); } } }
From source file:esiptestbed.mudrod.ontology.pre.AggregateTriples.java
License:Apache License
/** * Method of identifying a specific child given a element name * @param str element name//from w w w.ja va2 s . c o m * @param ele parent element * @return the element of child */ public Element findChild(String str, Element ele) { Iterator<?> processDescendants = ele.getDescendants(new ElementFilter()); String name = ""; Element result = null; while (processDescendants.hasNext()) { Element e = (Element) processDescendants.next(); name = e.getName(); if (name.equals(str)) { result = e; return result; } } return result; }
From source file:fi.ni.bcfextractor.BCFExtractorController.java
License:Open Source License
private void listChildren(Element current) { System.out.println(current.getName()); if (current.getName().equals("Comment")) { List<Content> contents = current.getContent(); for (Content c : contents) if (c instanceof Text) { String txt = ((Text) c).getTextNormalize(); if (txt.length() > 0) data.add(new BCF("", txt)); }/*from w w w .j a v a 2 s . com*/ } List children = current.getChildren(); Iterator iterator = children.iterator(); while (iterator.hasNext()) { Element child = (Element) iterator.next(); listChildren(child); } }
From source file:filter.Filter.java
private int getLines(Element root) { List element = root.getChildren(); Iterator i = element.iterator(); int line = 0; while (i.hasNext()) { Element e = (Element) i.next(); if (e.getName().equals("Cycle")) { List<Element> elements = e.getChildren(); line += elements.size();//w ww . j a v a 2 s. c o m } else if (e.getName().equals("Metric")) { List<Element> elements = e.getChildren(); if (elements.get(0).getName().equals("Values")) { elements = elements.get(0).getChildren(); line += elements.size(); } else if (elements.get(0).getName().equals("Value")) { line += 1; } } } return line; }
From source file:filter.Filter.java
private void converterProject(Iterator i) { while (i.hasNext()) { Element e = (Element) i.next(); if (e.getName().equals("Cycle")) { Cycle cycle = new Cycle(e.getAttributeValue("name"), this.project, Integer.parseInt(e.getAttributeValue("nodes")), Integer.parseInt(e.getAttributeValue("diameter"))); int idCycle = new CycleDAO().register(cycle); cycle.setId(idCycle);//w w w . j a va2s . co m incrementValue(); converterDataCycle(cycle, e.getChildren()); } else if (e.getName().equals("Metric")) { // incrementValue(); converterMetrics(e.getAttributeValue("id"), e.getChildren()); } } }
From source file:fourmiz.engine.Engine.java
License:Open Source License
/** * Load a specific game/* w w w. ja va 2 s . co m*/ * @param name * @throws JDOMException * @throws IOException * @throws SlickException */ public void loadLevel(String name) throws JDOMException, IOException, SlickException { currentGame = name; ressources.load(resourcePath + currentGame + renderSuffix); SAXBuilder sax = new SAXBuilder(); Document doc = sax.build(new File(resourcePath + currentGame + mapSuffix)); Element root = doc.getRootElement(); List<Element> listElem = root.getChildren(); for (Element elem : listElem) { switch (elem.getName()) { case "Config": loadConfig(elem.getChildren()); break; case "Entity": loadEntity(elem.getChildren()); break; default: log.warn("loadLevel: unknown type object -> " + elem.getName()); continue; } } this.loaded = true; }
From source file:fourmiz.engine.Engine.java
License:Open Source License
/** * Parse configuration part of xml/* www . j av a 2s . c o m*/ * @param configs */ private void loadConfig(Collection<Element> configs) { for (Element elem : configs) { switch (elem.getName()) { case "Chart": setxCase(Integer.parseInt(elem.getAttributeValue("xCase"))); setyCase(Integer.parseInt(elem.getAttributeValue("yCase"))); setxScale(Float.parseFloat(elem.getAttributeValue("xScale"))); setyScale(Float.parseFloat(elem.getAttributeValue("yScale"))); break; default: log.warn("loadLevel: unknown type config -> " + elem.getName()); continue; } } }