List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:com.abyala.decisiontree.SimpleDecisionTreeParser.java
License:Open Source License
InputType parseBooleanInputType(final Element typeElement) { final String name = typeElement.getAttributeValue("name"); final BooleanInputType.Builder builder = new BooleanInputType.Builder(name); return builder.build(); }
From source file:com.abyala.decisiontree.SimpleDecisionTreeParser.java
License:Open Source License
private InputType parseIntegerInputType(final Element typeElement) throws DecisionTreeParserException { final String name = typeElement.getAttributeValue("name"); final IntegerInputType.Builder builder = new IntegerInputType.Builder(name); builder.setMinValue(parseMinInt(typeElement.getAttributeValue("min"), "integer-type " + name)); builder.setMaxValue(parseMaxInt(typeElement.getAttributeValue("max"), "integer-type " + name)); return builder.build(); }
From source file:com.abyala.decisiontree.SimpleDecisionTreeParser.java
License:Open Source License
InputType parseStringInputType(final Element typeElement) throws DecisionTreeParserException { final String name = typeElement.getAttributeValue("name"); final StringInputType.Builder builder = new StringInputType.Builder(name); boolean hasDefaultValue = false; for (Element child : typeElement.getChildren("value")) { final boolean isDefault = "true".equals(child.getAttributeValue("default")); if (isDefault && hasDefaultValue) { throw new DecisionTreeParserException( "Input-type \"" + name + "\" may not have more than one default type."); }//w w w. ja v a 2s . c o m builder.addEnumValue(child.getTextNormalize(), isDefault); hasDefaultValue = isDefault; } return builder.build(); }
From source file:com.android.helpme.demo.utils.position.Position.java
License:Apache License
public Position(Element object) { Element position = object.getChild(User.POSITION); if (position != null) { this.longitude = new Double(position.getAttributeValue(LONGITUDE)); this.latitude = new Double(position.getAttributeValue(LATITUDE)); this.speed = new Double(position.getAttributeValue(SPEED)); this.direction = new Double(position.getAttributeValue(DIRECTION)); this.precision = new Double(position.getAttributeValue(PRECISION)); this.date = new Long(position.getAttributeValue(DATE)); } else {/*from www.j a v a 2 s . c o m*/ this.longitude = new Double(object.getAttributeValue(LONGITUDE)); this.latitude = new Double(object.getAttributeValue(LATITUDE)); this.speed = new Double(object.getAttributeValue(SPEED)); this.direction = new Double(object.getAttributeValue(DIRECTION)); this.precision = new Double(object.getAttributeValue(PRECISION)); this.date = new Long(object.getAttributeValue(DATE)); } }
From source file:com.archimatetool.editor.model.impl.EditorModelManager.java
License:Open Source License
private void loadState() throws IOException, JDOMException { if (backingFile.exists()) { Document doc = JDOMUtils.readXMLFile(backingFile); if (doc.hasRootElement()) { Element rootElement = doc.getRootElement(); for (Object e : rootElement.getChildren("model")) { //$NON-NLS-1$ Element modelElement = (Element) e; String filePath = modelElement.getAttributeValue("file"); //$NON-NLS-1$ if (filePath != null) { loadModel(new File(filePath)); }// w ww . j a va 2 s .c o m } } } }
From source file:com.archimatetool.model.util.RelationshipsMatrix.java
License:Open Source License
private void loadKeyLetters() { //URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_KEYS_FILE); URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_KEYS_FILE); // Load the JDOM Document from XML Document doc = null;/* w w w . j a va2 s. c o m*/ try { doc = new SAXBuilder().build(url); } catch (Exception ex) { ex.printStackTrace(); return; } for (Object object : doc.getRootElement().getChildren(XML_ELEMENT_KEY)) { Element elementKey = (Element) object; String keyLetter = elementKey.getAttributeValue(XML_ATTRIBUTE_CHAR); if (keyLetter == null || keyLetter.length() != 1) { System.err.println(getClass() + ": Key letter incorrect: " + keyLetter); //$NON-NLS-1$ continue; } String relationName = elementKey.getAttributeValue(XML_ATTRIBUTE_RELATIONSHIP); if (relationName == null) { System.err.println(getClass() + ": Relationship name incorrect: " + relationName); //$NON-NLS-1$ continue; } EClass relationship = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(relationName); if (relationship == null) { System.err.println(getClass() + ": Couldn't find relationship " + relationName); //$NON-NLS-1$ continue; } relationsKeyMap.put(keyLetter.charAt(0), relationship); relationsValueMap.put(relationship, keyLetter.charAt(0)); } }
From source file:com.archimatetool.model.util.RelationshipsMatrix.java
License:Open Source License
private void loadRelationships() { //URL url = Platform.getBundle(BUNDLE_ID).getResource(RELATIONSHIPS_FILE); URL url = Platform.getBundle(BUNDLE_ID).getEntry(RELATIONSHIPS_FILE); // Load the JDOM Document from XML Document doc = null;//from w w w . j a va 2 s. co m try { doc = new SAXBuilder().build(url); } catch (Exception ex) { ex.printStackTrace(); return; } // Iterate through all "source" elements Element elementElements = doc.getRootElement().getChild(XML_ELEMENT_ELEMENTS); if (elementElements == null) { // oops System.err.println(getClass() + ": Couldn't find elements element."); //$NON-NLS-1$ return; } for (Object object : elementElements.getChildren(XML_ELEMENT_SOURCE)) { Element elementSource = (Element) object; // Source element name String sourceName = elementSource.getAttributeValue(XML_ATTRIBUTE_ELEMENT); if (sourceName == null) { continue; } // Get EClass source from mapping EClass source = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(sourceName); if (source == null) { System.err.println(getClass() + ": Couldn't find source " + sourceName); //$NON-NLS-1$ continue; } // Create a new list of type TargetMatrix List<TargetMatrix> matrixList = new ArrayList<TargetMatrix>(); // Put it in the main matrix map matrixMap.put(source, matrixList); // Iterate through all child "target" elements for (Object objectChild : elementSource.getChildren(XML_ELEMENT_TARGET)) { Element elementTarget = (Element) objectChild; // Target element name String targetName = elementTarget.getAttributeValue(XML_ATTRIBUTE_ELEMENT); if (targetName == null) { continue; } // Get EClass target from mapping EClass target = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(targetName); if (target == null) { System.err.println(getClass() + ": Couldn't find target " + targetName); //$NON-NLS-1$ continue; } // Create a new TargetMatrix and add it to the list TargetMatrix matrix = new TargetMatrix(); matrixList.add(matrix); // Set target class matrix.targetClass = target; // Get relations string String relations = elementTarget.getAttributeValue(XML_ATTRIBUTE_RELATIONS); if (relations == null) { continue; } // Take each character and add the relationship from the mapping for (int i = 0; i < relations.length(); i++) { char key = relations.charAt(i); EClass relationship = relationsKeyMap.get(key); if (relationship != null) { matrix.getRelationships().add(relationship); } else { System.err.println(getClass() + ": Found unmapped key char: " + key); //$NON-NLS-1$ } } } } }
From source file:com.archimatetool.model.viewpoints.ViewpointManager.java
License:Open Source License
/** * Load viewpoints from XML file//from w w w .j av a 2 s . c o m */ void loadDefaultViewpointsFile() throws IOException, JDOMException { URL url = Platform.getBundle(BUNDLE_ID).getEntry(VIEWPOINTS_FILE); Document doc = new SAXBuilder().build(url); Element rootElement = doc.getRootElement(); for (Element xmlViewpoint : rootElement.getChildren("viewpoint")) { //$NON-NLS-1$ String id = xmlViewpoint.getAttributeValue("id"); //$NON-NLS-1$ if (id == null || "".equals(id)) { //$NON-NLS-1$ System.err.println("Blank id for viewpoint"); //$NON-NLS-1$ continue; } Element xmlName = xmlViewpoint.getChild("name"); //$NON-NLS-1$ if (xmlName == null) { System.err.println("No name element for viewpoint"); //$NON-NLS-1$ continue; } String name = xmlName.getText(); if (name == null || "".equals(name)) { //$NON-NLS-1$ System.err.println("Blank name for viewpoint"); //$NON-NLS-1$ continue; } Viewpoint vp = new Viewpoint(id, name); for (Element xmlConcept : xmlViewpoint.getChildren("concept")) { //$NON-NLS-1$ String conceptName = xmlConcept.getText(); if (conceptName == null || "".equals(conceptName)) { //$NON-NLS-1$ System.err.println("Blank concept name for viewpoint"); //$NON-NLS-1$ continue; } if (ELEMENTS_MAP.containsKey(conceptName)) { addCollection(vp, conceptName); } else { EClass eClass = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(conceptName); if (eClass != null) { addConcept(vp, eClass); } else { System.err.println("Couldn't get eClass: " + conceptName); //$NON-NLS-1$ } } } VIEWPOINTS.put(id, vp); } }
From source file:com.archimatetool.templates.model.TemplateManager.java
License:Open Source License
/** * Load all user templates as declared in the manifest *///from w w w . j a v a2 s .c om protected void loadUserTemplates() { fUserTemplates = new ArrayList<ITemplate>(); fUserTemplateGroups = new ArrayList<ITemplateGroup>(); if (!getUserTemplatesManifestFile().exists()) { return; } Document doc = null; try { doc = JDOMUtils.readXMLFile(getUserTemplatesManifestFile()); } catch (Exception ex) { ex.printStackTrace(); return; } HashMap<String, ITemplate> userTemplateMap = new HashMap<String, ITemplate>(); Element rootElement = doc.getRootElement(); // Templates for (Object child : rootElement.getChildren(XML_TEMPLATE_ELEMENT_TEMPLATE)) { Element templateElement = (Element) child; String type = templateElement.getAttributeValue(XML_TEMPLATE_ATTRIBUTE_TYPE); ITemplate template = createTemplate(type); if (template != null) { String id = templateElement.getAttributeValue(XML_TEMPLATE_ATTRIBUTE_ID); String path = templateElement.getAttributeValue(XML_TEMPLATE_ATTRIBUTE_FILE); if (id != null && path != null) { File file = new File(path); if (file.exists()) { template.setID(id); template.setFile(file); fUserTemplates.add(template); userTemplateMap.put(id, template); } } } } // Groups for (Object child : rootElement.getChildren(XML_TEMPLATE_ELEMENT_GROUP)) { Element groupElement = (Element) child; ITemplateGroup templateGroup = new TemplateGroup(); templateGroup.setName(groupElement.getAttributeValue(XML_TEMPLATE_ATTRIBUTE_NAME)); fUserTemplateGroups.add(templateGroup); // Template refs for (Object child2 : groupElement.getChildren(XML_TEMPLATE_ELEMENT_TEMPLATE_REF)) { Element templateRefElement = (Element) child2; String ref = templateRefElement.getAttributeValue(XML_TEMPLATE_ATTRIBUTE_REF); if (ref != null) { ITemplate template = userTemplateMap.get(ref); if (template != null) { templateGroup.addTemplate(template); } } } } }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaAnimUtils.java
License:Open Source License
/** * Builds data based on an instance controller element. * /* w w w . j a va 2s . co m*/ * @param node * Ardor3D parent Node * @param instanceController */ void buildController(final Node node, final Element instanceController) { final Element controller = _colladaDOMUtil.findTargetWithId(instanceController.getAttributeValue("url")); if (controller == null) { throw new ColladaException( "Unable to find controller with id: " + instanceController.getAttributeValue("url"), instanceController); } final Element skin = controller.getChild("skin"); if (skin != null) { buildSkinMeshes(node, instanceController, controller, skin); } else { // look for morph... can only be one or the other according to Collada final Element morph = controller.getChild("morph"); if (morph != null) { buildMorphMeshes(node, controller, morph); } } }