List of usage examples for org.jdom2 Element setAttribute
public Element setAttribute(final String name, final String value)
This sets an attribute value for this element.
From source file:ca.nrc.cadc.vosi.TableSet.java
License:Open Source License
/** * @param td/*w w w .java2 s .c o m*/ * @return */ private Element toXmlElement(TableDesc td, Namespace ns) { Element eleTable = new Element("table", ns); eleTable.setAttribute("type", "output"); Element ele; ele = new Element("name"); ele.setText(td.getTableName()); eleTable.addContent(ele); if (td.getColumnDescs() != null) for (ColumnDesc cd : td.getColumnDescs()) { Element e = toXmlElement(cd); if (e != null) eleTable.addContent(e); } if (td.getKeyDescs() != null) for (KeyDesc kd : td.getKeyDescs()) { Element e = toXmlElement(kd); if (e != null) eleTable.addContent(e); } return eleTable; }
From source file:cager.parser.test.SimpleTest2.java
License:Open Source License
private Element inicializaKDM(String segmentName) { // Creamos el builder basado en SAX SAXBuilder builder = new SAXBuilder(); Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Namespace action = Namespace.getNamespace("action", "http://kdm.omg.org/action"); Namespace code = Namespace.getNamespace("code", "http://kdm.omg.org/code"); Namespace kdm = Namespace.getNamespace("kdm", "http://kdm.omg.org/kdm"); Namespace source = Namespace.getNamespace("source", "http://kdm.omg.org/source"); Element segmento = new Element("Segment", kdm); segmento.addNamespaceDeclaration(xmi); segmento.addNamespaceDeclaration(xsi); segmento.addNamespaceDeclaration(action); segmento.addNamespaceDeclaration(code); segmento.addNamespaceDeclaration(kdm); segmento.addNamespaceDeclaration(source); segmento.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); Element modelo = new Element("model"); modelo.setAttribute("id", "id.0", xmi); idCount++;/*from ww w . ja va 2s . c om*/ modelo.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); modelo.setAttribute("type", "code:CodeModel", xmi); Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id.1", xmi); idCount++; codeElement.setAttribute("name", segmentName); codeElement.setAttribute("type", "code:CompilationUnit", xmi); modelo.addContent(codeElement); elementoTipos = inicializaDataTypes(); modelo.addContent(elementoTipos); segmento.addContent(modelo); return segmento; }
From source file:cager.parser.test.SimpleTest3.java
License:Open Source License
private void trataStatements(ASTStatement astStatement, Element actionElement, Element segmento) { astStatement.getClass().getName();/*from www .jav a 2 s . c o m*/ //System.out.println("SENTENCIA!!"+astStatement.getClass().getName()); /* switch (astStatement.getClass().getName()) { case "ASTIfStatement": System.out.println("SENTENCIA IF encontrada!!"+astStatement.getClass().getName()); break; case "ASTCaseStatment": System.out.println("SENTENCIA CASE encontrada!!"+astStatement.getClass().getName()); break; case "ASTDoWhileStatement": System.out.println("SENTENCIA DOWHILE encontrada!!"+astStatement.getClass().getName()); break; case "ASTForEachStatement": System.out.println("SENTENCIA FOREACH encontrada!!"+astStatement.getClass().getName()); break; case "ASTForWhileWendStatement": System.out.println("SENTENCIA FORWHILE encontrada!!"+astStatement.getClass().getName()); break; case "ASTWithStatement": System.out.println("SENTENCIA WITH encontrada!!"+astStatement.getClass().getName()); break; default: break; } */ if (astStatement.getClass().getName().compareTo("cager.parser.ASTIfStatement") == 0) { System.out.println("SENTENCIA IF encontrada!!" + astStatement.getClass().getName()); System.out.println(((ASTIfStatement) astStatement).toString()); actionElement.setAttribute("kind", "Condition"); if (contextoLocal == "") { //actionElement.setAttribute("kind", "global"); segmento.getChild("model").getChild("codeElement").addContent(actionElement); // this.segmento = segmento; } else { //actionElement.setAttribute("kind", "local"); Element elementAux = hsmMethodUnitsObj.get(hsmMethodUnits.get(contextoLocal)); elementAux.addContent(actionElement); } TratarASTIfStatement(astStatement, actionElement); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTCaseStatment") == 0) { System.out.println("SENTENCIA CASE encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTForStatement") == 0) { System.out.println("SENTENCIA FOR encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTDoWhileStatement") == 0) { System.out.println("SENTENCIA DOWHILE encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTWhileWendStatement") == 0) { System.out.println("SENTENCIA WHILEWEND encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTForEachStatement") == 0) { System.out.println("SENTENCIA FOREACH encontrada!!" + astStatement.getClass().getName()); } else if (astStatement.getClass().getName().compareTo("cager.parser.ASTWithStatement") == 0) { System.out.println("SENTENCIA WITH encontrada!!" + astStatement.getClass().getName()); } else { System.out.println("SENTENCIA encontrada SIN DETERMINAR!!" + astStatement.getClass().getName()); } }
From source file:cager.parser.test.SimpleTest3.java
License:Open Source License
private Element inicializaKDM(String segmentName) { // Creamos el builder basado en SAX SAXBuilder builder = new SAXBuilder(); //Namespace xmi = Namespace.getNamespace("xmi", "http://www.omg.org/XMI"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); Namespace action = Namespace.getNamespace("action", "http://kdm.omg.org/action"); Namespace code = Namespace.getNamespace("code", "http://kdm.omg.org/code"); Namespace kdm = Namespace.getNamespace("kdm", "http://kdm.omg.org/kdm"); Namespace source = Namespace.getNamespace("source", "http://kdm.omg.org/source"); Element segmento = new Element("Segment", kdm); segmento.addNamespaceDeclaration(xmi); segmento.addNamespaceDeclaration(xsi); segmento.addNamespaceDeclaration(action); segmento.addNamespaceDeclaration(code); segmento.addNamespaceDeclaration(kdm); segmento.addNamespaceDeclaration(source); segmento.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); Element modelo = new Element("model"); modelo.setAttribute("id", "id.0", xmi); idCount++;/* ww w .j a v a 2 s.c o m*/ modelo.setAttribute("name", segmentName.substring(0, segmentName.indexOf('.'))); modelo.setAttribute("type", "code:CodeModel", xmi); Element codeElement = new Element("codeElement"); codeElement.setAttribute("id", "id.1", xmi); idCount++; codeElement.setAttribute("name", segmentName); codeElement.setAttribute("type", "code:CompilationUnit", xmi); modelo.addContent(codeElement); elementoTipos = inicializaDataTypes(); modelo.addContent(elementoTipos); segmento.addContent(modelo); return segmento; }
From source file:catalogo.XMLOut.java
public void criaDocument(List<String[]> lista, String[] categorias) { Element artigos = new Element("listagem"); Document doc = new Document(artigos); //iterao sobre a lista com os artigos for (int i = 0; i < lista.size(); i++) { Element artigo1 = new Element("artigo"); artigo1.setAttribute("id", Integer.toString(i)); //iterao sobre os valores do artigo for (int j = 0; j < lista.get(i).length; j++) { if (categorias[j].equals("ano")) artigo1.addContent(new Element("ano").setText(lista.get(i)[j])); else/*from ww w . j a va 2 s .c o m*/ artigo1.addContent(new Element(categorias[j]).setText(lista.get(i)[j])); } doc.getRootElement().addContent(artigo1); } criaXML(doc); }
From source file:com.android.helpme.demo.utils.position.Position.java
License:Apache License
@Override public Element getElementAs(String string) { Element object = new Element(string); object.setAttribute(LONGITUDE, this.longitude.toString()); object.setAttribute(LATITUDE, this.latitude.toString()); object.setAttribute(SPEED, this.speed.toString()); object.setAttribute(DIRECTION, this.direction.toString()); object.setAttribute(PRECISION, this.precision.toString()); object.setAttribute(DATE, this.date.toString()); return object; }
From source file:com.archimatetool.canvas.templates.wizard.SaveCanvasAsTemplateWizard.java
License:Open Source License
private String createManifest() throws IOException { Document doc = new Document(); Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST); doc.setRootElement(root);// w w w. j a v a2s. co m // Type root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE, CanvasModelTemplate.XML_CANVAS_TEMPLATE_ATTRIBUTE_TYPE_MODEL); // Timestamp root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TIMESTAMP, Long.toString(System.currentTimeMillis())); // Name Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME); elementName.setText(fTemplateName); root.addContent(elementName); // Description Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION); elementDescription.setText(fTemplateDescription); root.addContent(elementDescription); // Thumbnail if (fIncludeThumbnail) { String keyThumb = TemplateManager.ZIP_ENTRY_THUMBNAILS + "1.png"; //$NON-NLS-1$ Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL); elementKeyThumb.setText(keyThumb); root.addContent(elementKeyThumb); } return JDOMUtils.write2XMLString(doc); }
From source file:com.archimatetool.editor.model.compatibility.Archimate2To3Converter.java
License:Open Source License
/** * Convert concept name types/*from w w w . j av a 2s .c o m*/ */ private void convertConceptTypeName(Element element) { Attribute attType = element.getAttribute("type", JDOMUtils.XSI_Namespace); if (attType != null) { String oldValue = attType.getValue(); String newValue = ConceptNameMapping.get(oldValue); if (newValue != null) { attType.setValue(newValue); } // Or Junction has type set if ("archimate:OrJunction".equals(oldValue)) { element.setAttribute("type", "or"); } } }
From source file:com.archimatetool.editor.model.impl.EditorModelManager.java
License:Open Source License
public void saveState() throws IOException { Document doc = new Document(); Element rootElement = new Element("models"); //$NON-NLS-1$ doc.setRootElement(rootElement);//from ww w . j av a2s . c om for (IArchimateModel model : getModels()) { File file = model.getFile(); // has been saved if (file != null) { Element modelElement = new Element("model"); //$NON-NLS-1$ modelElement.setAttribute("file", file.getAbsolutePath()); //$NON-NLS-1$ rootElement.addContent(modelElement); } } JDOMUtils.write2XMLFile(doc, backingFile); }
From source file:com.archimatetool.templates.impl.wizard.SaveArchimateModelAsTemplateWizard.java
License:Open Source License
private String createManifest() throws IOException { Document doc = new Document(); Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST); doc.setRootElement(root);//from w w w. j a va 2 s . co m // Type root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE, ArchimateModelTemplate.XML_TEMPLATE_ATTRIBUTE_TYPE_MODEL); // Timestamp root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TIMESTAMP, Long.toString(System.currentTimeMillis())); // Name Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME); elementName.setText(fTemplateName); root.addContent(elementName); // Description Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION); elementDescription.setText(fTemplateDescription); root.addContent(elementDescription); // Thumbnails if (fIncludeThumbnails) { if (fSelectedDiagramModel != null) { int i = 1; for (IDiagramModel dm : fModel.getDiagramModels()) { if (dm == fSelectedDiagramModel) { String keyThumb = TemplateManager.ZIP_ENTRY_THUMBNAILS + i + ".png"; //$NON-NLS-1$ Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL); elementKeyThumb.setText(keyThumb); root.addContent(elementKeyThumb); break; } i++; } } } return JDOMUtils.write2XMLString(doc); }