Example usage for org.jdom2 Attribute Attribute

List of usage examples for org.jdom2 Attribute Attribute

Introduction

In this page you can find the example usage for org.jdom2 Attribute Attribute.

Prototype

public Attribute(final String name, final String value) 

Source Link

Document

This will create a new Attribute with the specified (local) name and value, and does not place the attribute in a Namespace .

Usage

From source file:modelo.RegistroPlanesXML.java

public void addUser(Planes planes) throws IOException {
    Element ePlan = new Element("plan");

    Attribute aPrecio = new Attribute("precio", Integer.toString(planes.getPrecio()));
    Attribute aNumMensajes = new Attribute("NumMensajes", planes.getMensajes());
    Attribute aNumMinutos = new Attribute("NumMinutos", planes.getMinutos());
    Attribute aNombre = new Attribute("nombre", planes.getNombre());

    ePlan.setAttribute(aNombre);//from   w w  w . j a  va2 s  .c o m
    ePlan.setAttribute(aPrecio);
    ePlan.setAttribute(aNumMensajes);
    ePlan.setAttribute(aNumMinutos);
    this.raiz.addContent(ePlan);
    this.save();
}

From source file:Modelo.UsuarioXML.java

public void addUser(Usuario user) throws IOException {
    // nombre, apellidos,correo, telefono,contrasea;
    Element usuario = new Element("usuario");
    Element nombre = new Element("nombre");
    Element apellido1 = new Element("apellido1");
    Element apellido2 = new Element("apellido2");
    Attribute cedula = new Attribute("cedula", user.getCedula());
    Element correo = new Element("correo");
    Element telefono = new Element("telefono");
    Element contrasena = new Element("contrasena");

    nombre.addContent(user.getNombre());
    apellido1.addContent(user.getApellido1());
    apellido2.addContent(user.getApellido2());
    correo.addContent(user.getCorreo());
    telefono.addContent(user.getTelefono());
    contrasena.addContent(user.getContrasena());

    usuario.setAttribute(cedula);/*from w w  w  . ja  va 2s .  c  o m*/
    usuario.addContent(nombre);
    usuario.addContent(apellido1);
    usuario.addContent(apellido2);
    usuario.addContent(correo);
    usuario.addContent(telefono);
    usuario.addContent(contrasena);

    raiz.addContent(usuario);
    this.guardar();
}

From source file:mx.com.pixup.portal.dao.ArtistaGenerateDaoJdbc.java

public void generateXML() {

    //querys//from w w w  .  j ava  2s  . com
    String sql = "select * from artista";

    try {
        //seccion de preparacion de la query
        Connection connection = dataSource.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        //seccion de nodo raiz
        Element artistas = new Element("artistas");
        this.xmlLogico.setRootElement(artistas);

        while (resultSet.next()) {

            //aqu se hace la magia para el XML
            Element artista = new Element("artista");
            Attribute id = new Attribute("id", Integer.toString(resultSet.getInt("id")));
            artista.setAttribute(id);

            Element nombre_artistico = new Element("nombre_artistico");
            nombre_artistico.setText(resultSet.getString("nombre_artistico"));
            artista.addContent(nombre_artistico);

            Element descripcion = new Element("descripcion");
            descripcion.setText(resultSet.getString("descripcion"));
            artista.addContent(descripcion);

            artistas.addContent(artista);
        }

        //se genera el xml fsico
        this.xmlFisico.setFormat(Format.getPrettyFormat());
        this.xmlFisico.output(xmlLogico, archivoFisico);
    } catch (Exception e) {
        //*** se quit el return porque el mtodo es void
        System.out.println(e.getMessage());
    }

}

From source file:mx.com.pixup.portal.dao.DiscoPaisGenerateDaoJdbc.java

public void generateXML() {

    //querys/*from w w w  . java 2  s . com*/
    String sql = "SELECT id_idioma, id_disquera, pais.id as id_pais, pais.nombre as pais,\n"
            + "disco.titulo FROM disco\n" + "INNER JOIN pais ON pais.id = disco.id_pais";

    try {
        //seccion de preparacion de la query
        Connection connection = dataSource.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        //seccion de nodo raiz
        Element discos = new Element("discos");
        this.xmlLogico.setRootElement(discos);

        while (resultSet.next()) {
            //Elementos de Segundo Orden
            Element disco = new Element("disco");

            Attribute idioma = new Attribute("idioma", Integer.toString(resultSet.getInt("id_idioma")));
            disco.setAttribute(idioma);

            Attribute disquera = new Attribute("disquera", Integer.toString(resultSet.getInt("id_disquera")));
            disco.setAttribute(disquera);

            //Elementos de Tercer Orden
            Element pais = new Element("pais");

            Attribute id = new Attribute("id", Integer.toString(resultSet.getInt("id_pais")));
            pais.setAttribute(id);

            pais.setText(resultSet.getString("pais"));
            disco.addContent(pais);

            Element titulo = new Element("titulo");
            titulo.setText(resultSet.getString("titulo"));

            disco.addContent(titulo);

            discos.addContent(disco);
            //aqu se hace la magia para el XML
        }

        //se genera el xml fsico
        this.xmlFisico.setFormat(Format.getPrettyFormat());
        this.xmlFisico.output(this.xmlLogico, this.archivoFisico);
    } catch (Exception e) {
        //*** se quit el return porque el mtodo es void
        System.out.println(e.getMessage());
    }

}

From source file:mx.com.pixup.portal.dao.MunicipioGenerateDaoJdbc.java

public void generateXML(int idMunicipioPasado) {

    //querys/* w w w.j ava2s. c o  m*/
    String sql = "SELECT * from municipio WHERE id = ?";

    try {
        //seccion de preparacion de la query
        Connection connection = dataSource.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1, idMunicipioPasado);
        ResultSet resultSet = preparedStatement.executeQuery();
        //seccion de nodo raiz

        resultSet.next();
        /*while (resultSet.next()) {
                
        //aqu se hace la magia para el XML
        }*/
        Element municipio = new Element("municipio");
        Attribute id = new Attribute("id", Integer.toString(resultSet.getInt("id")));

        this.xmlLogico.setRootElement(municipio);
        municipio.setAttribute(id);

        //Elementos de 2do nivel
        Element nombre = new Element("nombre");
        nombre.setText(resultSet.getString("nombre"));
        Element id_estado = new Element("id_estado");
        id_estado.setText(Integer.toString(resultSet.getInt("id_estado")));

        municipio.addContent(nombre);
        municipio.addContent(id_estado);

        //se genera el xml fsico
        this.xmlFisico.setFormat(Format.getRawFormat());
        this.xmlFisico.output(this.xmlLogico, this.archivoFisico);
    } catch (Exception e) {
        //*** se quit el return porque el mtodo es void
        System.out.println(e.getMessage());
    }

}

From source file:nl.nn.adapterframework.util.XmlBuilder.java

License:Apache License

public void addAttribute(String name, String value) {
    if (value != null) {
        if (name.equalsIgnoreCase("xmlns")) {
            element.setNamespace(Namespace.getNamespace(value));
        } else if (StringUtils.startsWithIgnoreCase(name, "xmlns:")) {
            String prefix = name.substring(6);
            element.addNamespaceDeclaration(Namespace.getNamespace(prefix, value));
        } else {/*from  w ww.  j ava2s  .  co  m*/
            element.setAttribute(new Attribute(name, value));
        }
    }
}

From source file:org.crazyt.xgogdownloader.Util.java

License:Open Source License

public final int createXML(String filepath, int chunk_size, String xml_dir) {
    int res = 0;/*from w  w  w  .  ja  v a  2s  .  c o m*/
    File infile;
    int filesize;
    int size;
    int chunks;
    int i;
    if (xml_dir == "") {
        xml_dir = ".cache/xgogdownloader/xml";
    } // end of if
    File path = Factory.newFile(xml_dir);
    if (!path.exists()) {
        if (!path.mkdirs()) {
            System.out.println("Failed to create directory: " + path);
        }
    }

    infile = Factory.newFile(filepath);
    // RandomAccessFile file = new RandomAccessFile("file.txt", "rw");?
    // fseek/seek ftell/getFilePointer rewind/seek(0)
    if (infile.exists()) {
        filesize = (int) infile.length();
    } else {
        System.out.println(filepath + " doesn't exist");
        return res;
    } // end of if-else

    // Get filename
    String filename = FilenameUtils.removeExtension(infile.getName());
    String filenameXML = xml_dir + "/" + filename + ".xml";

    System.out.println(filename);
    // Determine number of chunks
    int remaining = filesize % chunk_size;
    chunks = (remaining == 0) ? filesize / chunk_size : (filesize / chunk_size) + 1;
    System.out.println("Filesize: " + filesize + " bytes");
    System.out.println("Chunks: " + chunks);
    System.out.println("Chunk size: " + (chunk_size / Math.pow(2.0, 20.0)) + " MB");
    Util util_md5 = new Util();
    String file_md5 = util_md5.getFileHash(filepath);
    System.out.println("MD5: " + file_md5);

    Element fileElem = new Element("file");
    fileElem.setAttribute(new Attribute("name", filename));
    fileElem.setAttribute(new Attribute("md5", file_md5));
    fileElem.setAttribute(new Attribute("chunks", String.valueOf(chunks)));
    fileElem.setAttribute(new Attribute("total_size", String.valueOf(filesize)));

    System.out.println("Getting MD5 for chunks");
    for (i = 0; i < chunks; i++) {
        int range_begin = i * chunk_size;
        // fseek(infile, range_begin, SEEK_SET);
        if ((i == chunks - 1) && (remaining != 0)) {
            chunk_size = remaining;
        }
        int range_end = range_begin + chunk_size - 1;
        String chunk = String.valueOf(chunk_size * 4);

        String hash = util_md5.getChunkHash(chunk); // calculates hash of
        // chunk string?
        Element chunkElem = new Element("chunk");
        chunkElem.setAttribute(new Attribute("id", String.valueOf(i)));
        chunkElem.setAttribute(new Attribute("from", String.valueOf(range_begin)));
        chunkElem.setAttribute(new Attribute("to", String.valueOf(range_begin)));
        chunkElem.setAttribute(new Attribute("method", "md5"));
        chunkElem.addContent(new Text(hash));
        fileElem.addContent(chunkElem);

        System.out.println("Chunks hashed " + (i + 1) + " / " + chunks + "\r");
    }
    Document doc = new Document(fileElem);

    System.out.println("Writing XML: " + filenameXML);
    try {
        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, Factory.newFileWriter(filenameXML));
        res = 1;
    } catch (IOException e) {
        System.out.println("Can't create " + filenameXML);
        return res;
    }
    return res;
}

From source file:org.helm.notation2.MonomerFactory.java

License:Open Source License

private static String buildMonomerDbXMLFromCache(MonomerCache cache) throws MonomerException {
    XMLOutputter outputer = new XMLOutputter(Format.getPrettyFormat());

    StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + System.getProperty("line.separator")
            + "<MonomerDB xmlns=\"lmr\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
            + System.getProperty("line.separator"));

    Map<String, Map<String, Monomer>> mDB = cache.getMonomerDB();
    Element polymerListElement = new Element(POLYMER_LIST_ELEMENT);
    Set<String> polymerTypeSet = mDB.keySet();
    for (Iterator i = polymerTypeSet.iterator(); i.hasNext();) {
        String polymerType = (String) i.next();
        Element polymerElement = new Element(POLYMER_ELEMENT);
        Attribute att = new Attribute(POLYMER_TYPE_ATTRIBUTE, polymerType);
        polymerElement.setAttribute(att);
        polymerListElement.getChildren().add(polymerElement);

        Map<String, Monomer> monomerMap = mDB.get(polymerType);
        Set<String> monomerSet = monomerMap.keySet();

        for (Iterator it = monomerSet.iterator(); it.hasNext();) {
            String monomerID = (String) it.next();
            Monomer m = monomerMap.get(monomerID);
            Element monomerElement = MonomerParser.getMonomerElement(m);
            polymerElement.getChildren().add(monomerElement);
        }//from  www .  j  a  v a 2 s  .co m
    }
    String polymerListString = outputer.outputString(polymerListElement);
    sb.append(polymerListString + System.getProperty("line.separator"));

    Map<String, Attachment> aDB = cache.getAttachmentDB();
    Element attachmentListElement = new Element(ATTACHMENT_LIST_ELEMENT);
    Set<String> attachmentSet = aDB.keySet();
    for (Iterator itr = attachmentSet.iterator(); itr.hasNext();) {
        String attachmentID = (String) itr.next();
        Attachment attachment = aDB.get(attachmentID);
        Element attachmentElement = MonomerParser.getAttachementElement(attachment);
        attachmentListElement.getChildren().add(attachmentElement);
    }
    String attachmentListString = outputer.outputString(attachmentListElement);
    sb.append(attachmentListString);

    sb.append(System.getProperty("line.separator") + "</MonomerDB>" + System.getProperty("line.separator"));

    return sb.toString();
}

From source file:org.helm.notation2.tools.NucleotideParser.java

License:Open Source License

public static String getNucleotideTemplatesXML(Map<String, Map<String, String>> templates) {
    XMLOutputter outputer = new XMLOutputter(Format.getPrettyFormat());

    StringBuilder sb = new StringBuilder();
    sb.append(//from  ww  w  .  jav a2 s.  c om
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<NUCLEOTIDE_TEMPLATES xsi:schemaLocation=\"lmr NucleotideTemplateSchema.xsd\" xmlns=\"lmr\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n");

    Set<String> templateSet = templates.keySet();
    for (Iterator i = templateSet.iterator(); i.hasNext();) {
        String template = (String) i.next();
        Element templateElement = new Element(TEMPLATE_ELEMENT);
        Attribute att = new Attribute(TEMPLATE_NOTATION_SOURCE_ATTRIBUTE, template);
        templateElement.setAttribute(att);

        Map<String, String> nucMap = templates.get(template);
        Set<String> nucleotideSet = nucMap.keySet();

        for (Iterator it = nucleotideSet.iterator(); it.hasNext();) {
            Element nucleotideElement = new Element(NUCLEOTIDE_ELEMENT);
            templateElement.getChildren().add(nucleotideElement);

            String symbol = (String) it.next();
            Element symbolElement = new Element(NUCLEOTIDE_SYMBOL_ELEMENT);
            symbolElement.setText(symbol);
            nucleotideElement.getChildren().add(symbolElement);

            String notation = nucMap.get(symbol);
            Element notationElement = new Element(NUCLEOTIDE_MONOMER_NOTATION_ELEMENT);
            notationElement.setText(notation);
            nucleotideElement.getChildren().add(notationElement);
        }

        String templateString = outputer.outputString(templateElement);
        sb.append(templateString);
    }

    sb.append("\n</NUCLEOTIDE_TEMPLATES>");

    return sb.toString();
}

From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java

License:Open Source License

private static void convertDiagramSpecification16ToVirtualModel17(File file, Document diagram,
        List<File> oldPaletteFiles, List<File> oldExampleDiagramFiles, ViewPointResource viewPointResource) {

    // Create the diagram specification and a virtual model with a diagram typed model slot referencing this diagram specification

    final String ADDRESSED_DIAGRAM_MODEL_SLOT = "AddressedDiagramModelSlot";
    final String MODELSLOT_VIRTUAL_MODEL_MODEL_SLOT = "ModelSlot_VirtualModelModelSlot";
    final String MODELSLOT_TYPED_DIAGRAM_MODEL_SLOT = "ModelSlot_TypedDiagramModelSlot";

    try {//from w  w w  . j  a va  2  s.  co m
        String diagramName = file.getName().replace(".xml", "");
        // Create a folder that contains the diagram specification
        File diagramSpecificationFolder = new File(
                file.getParentFile() + "/" + diagramName + ".diagramspecification");
        diagramSpecificationFolder.mkdir();

        // Retrieve diagram drop schemes
        Iterator<Element> dropSchemeElements = diagram.getDescendants(new ElementFilter("DropScheme"));
        List<Element> dropSchemes = IteratorUtils.toList(dropSchemeElements);

        // Retrieve Diagram Model slots references
        Iterator<? extends Content> thisModelSlotsIterator = diagram.getDescendants(
                new ElementFilter("DiagramModelSlot").or(new ElementFilter(ADDRESSED_DIAGRAM_MODEL_SLOT)));
        List<Element> thisModelSlots = IteratorUtils.toList(thisModelSlotsIterator);

        // Retrieve the DiagramModelSlot (this), and transform it to a virtual model slot with a virtual model uri
        int thisID = 0;
        String newThisUri = viewPointResource.getURI() + "/" + diagramName;
        String diagramSpecificationURI = newThisUri + "/" + diagramName + ".diagramspecification";
        Element typedDiagramModelSlot = null;
        boolean foundThis = false;
        for (Element thisMs : thisModelSlots) {
            // Retriev the ID and URI of this DiagramModelSlot
            if (thisMs.getAttribute("name") != null && thisMs.getAttributeValue("name").equals("this")
                    && !foundThis) {
                // Store its ID and its URI
                thisID = thisMs.getAttribute("id").getIntValue();
                if (thisMs.getAttributeValue("virtualModelURI") != null) {
                    newThisUri = thisMs.getAttributeValue("virtualModelURI");
                    thisMs.removeAttribute("virtualModelURI");
                    thisMs.removeAttribute("name");
                    thisMs.getAttribute("id").setName("idref");
                    thisMs.setAttribute("idref", Integer.toString(thisID));
                }
                // Replace by a Typed model slot
                typedDiagramModelSlot = new Element(MODELSLOT_TYPED_DIAGRAM_MODEL_SLOT);
                typedDiagramModelSlot.setAttribute("metaModelURI", diagramSpecificationURI);
                typedDiagramModelSlot.setAttribute("name", "typedDiagramModelSlot");
                typedDiagramModelSlot.setAttribute("id", Integer.toString(computeNewID(diagram)));
                foundThis = true;
            }
        }
        // Replace the Diagram Model Slot by a Virtual Model Model slot
        for (Element thisMs : thisModelSlots) {
            if (hasSameID(thisMs, thisID) && thisMs.getName().equals("DiagramModelSlot")) {
                thisMs.setName("FMLRTModelSlot");
                thisMs.getAttributes().add(new Attribute("virtualModelURI", newThisUri));
                thisMs.getAttributes().add(new Attribute("name", "virtualModelInstance"));
                thisMs.getAttributes().add(new Attribute("id", Integer.toString(thisID)));
                thisMs.removeAttribute("idref");
            }
        }
        // Update ids for all model slots
        Iterator<? extends Content> diagramModelSlotsIterator = diagram.getDescendants(
                new ElementFilter("DiagramModelSlot").or(new ElementFilter(ADDRESSED_DIAGRAM_MODEL_SLOT)));
        List<Element> thisDiagramModelSlots = IteratorUtils.toList(diagramModelSlotsIterator);
        for (Element diagramMs : thisDiagramModelSlots) {
            if (diagramMs.getAttribute("id") != null && typedDiagramModelSlot != null) {
                diagramMs.setAttribute("id", typedDiagramModelSlot.getAttributeValue("id"));
            }
            if (diagramMs.getAttribute("idref") != null) {
                // Change to TypedDiagramModelSlot
                if (diagramMs.getParentElement().getName().equals("AddShape")
                        || diagramMs.getParentElement().getName().equals("AddConnector")
                        || diagramMs.getParentElement().getName().equals("AddDiagram")
                        || diagramMs.getParentElement().getName().equals("ContainedShapePatternRole")
                        || diagramMs.getParentElement().getName().equals("ContainedConnectorPatternRole")
                        || diagramMs.getParentElement().getName().equals("ContainedDiagramPatternRole")) {
                    if (typedDiagramModelSlot.getAttributeValue("id") != null) {
                        diagramMs.setAttribute("idref", typedDiagramModelSlot.getAttributeValue("id"));
                        diagramMs.setName("TypedDiagramModelSlot");
                    }
                } else {
                    diagramMs.setName(MODELSLOT_VIRTUAL_MODEL_MODEL_SLOT);
                }
            }
        }
        for (Content content : diagram.getDescendants()) {
            if (content instanceof Element) {
                Element element = (Element) content;
                if (element.getName().equals("AddShape") || element.getName().equals("AddConnector")
                        || element.getName().equals("AddDiagram")) {
                    if (element.getChild("TypedDiagramModelSlot") == null
                            && element.getChild("AddressedDiagramModelSlot") == null) {
                        Element adressedMsElement = new Element("TypedDiagramModelSlot");
                        Attribute newIdRefAttribute = new Attribute("idref",
                                typedDiagramModelSlot.getAttributeValue("id"));
                        adressedMsElement.getAttributes().add(newIdRefAttribute);
                        element.addContent(adressedMsElement);
                    }
                }
            }
        }

        // Update DiagramSpecification URI
        for (Content content : diagram.getDescendants()) {
            if (content instanceof Element) {
                Element element = (Element) content;
                if (element.getAttribute("diagramSpecificationURI") != null) {
                    String oldDiagramSpecificationUri = element.getAttributeValue("diagramSpecificationURI");
                    String diagramSpecificationName = oldDiagramSpecificationUri
                            .substring(oldDiagramSpecificationUri.lastIndexOf("/"));
                    String newDiagramSpecificationUri = oldDiagramSpecificationUri + diagramSpecificationName
                            + ".diagramspecification";
                    element.getAttribute("diagramSpecificationURI").setValue(newDiagramSpecificationUri);
                }
            }
        }

        // Change all the "diagram" binding with "this", and "toplevel" with typedDiagramModelSlot.topLevel" in case of not
        // DropSchemeAction
        for (Content content : diagram.getDescendants()) {
            if (content instanceof Element) {
                Element element = (Element) content;
                for (Attribute attribute : element.getAttributes()) {
                    if (attribute.getValue().startsWith("diagram")) {
                        attribute.setValue(attribute.getValue().replace("diagram", "this"));
                    }
                    if (attribute.getValue().startsWith("topLevel")) {
                        boolean diagramScheme = false;
                        Element parentElement = element.getParentElement();
                        while (parentElement != null) {
                            if (parentElement.getName().equals("DropScheme")
                                    || parentElement.getName().equals("LinkScheme")) {
                                diagramScheme = true;
                            }
                            parentElement = parentElement.getParentElement();
                        }
                        if (!diagramScheme) {
                            attribute.setValue(attribute.getValue().replace("topLevel",
                                    "virtualModelInstance.typedDiagramModelSlot"));
                        }
                    }
                }
            }
        }

        // Create the diagram specificaion xml file
        File diagramSpecificationFile = new File(diagramSpecificationFolder, file.getName());
        Document diagramSpecification = new Document();
        Element rootElement = new Element("DiagramSpecification");
        Attribute name = new Attribute("name", diagramName);
        Attribute diagramSpecificationURIAttribute = new Attribute("uri", diagramSpecificationURI);
        diagramSpecification.addContent(rootElement);
        rootElement.getAttributes().add(name);
        rootElement.getAttributes().add(diagramSpecificationURIAttribute);
        XMLUtils.saveXMLFile(diagramSpecification, diagramSpecificationFile);

        // Copy the palette files inside diagram specification repository
        ArrayList<File> newPaletteFiles = new ArrayList<File>();
        for (File paletteFile : oldPaletteFiles) {
            File newFile = new File(diagramSpecificationFolder + "/" + paletteFile.getName());
            FileUtils.rename(paletteFile, newFile);
            newPaletteFiles.add(newFile);
            Document palette = XMLUtils.readXMLFile(newFile);
            Attribute diagramSpecUri = new Attribute("diagramSpecificationURI", diagramSpecificationURI);
            palette.getRootElement().getAttributes().add(diagramSpecUri);
            convertNames16ToNames17(palette);
            XMLUtils.saveXMLFile(palette, newFile);
        }

        // Copy the example diagram files inside diagram specification repository
        ArrayList<File> newExampleDiagramFiles = new ArrayList<File>();
        for (File exampleDiagramFile : oldExampleDiagramFiles) {
            File newFile = new File(diagramSpecificationFolder + "/" + exampleDiagramFile.getName());
            FileUtils.rename(exampleDiagramFile, newFile);
            newExampleDiagramFiles.add(newFile);
            Document exampleDiagram = XMLUtils.readXMLFile(newFile);
            exampleDiagram.getRootElement().setAttribute("uri",
                    diagramSpecificationURI + "/" + exampleDiagram.getRootElement().getAttributeValue("name"));
            Attribute diagramSpecUri = new Attribute("diagramSpecificationURI", diagramSpecificationURI);
            exampleDiagram.getRootElement().getAttributes().add(diagramSpecUri);
            exampleDiagram.getRootElement().setAttribute("uri",
                    diagramSpecificationURI + "/" + exampleDiagram.getRootElement().getAttributeValue("name"));
            convertNames16ToNames17(exampleDiagram);
            XMLUtils.saveXMLFile(exampleDiagram, newFile);
        }

        // Update the diagram palette element bindings
        ArrayList<Element> paletteElementBindings = new ArrayList<Element>();
        for (File paletteFile : newPaletteFiles) {
            Document palette = XMLUtils.readXMLFile(paletteFile);
            String paletteUri = diagramSpecificationURI + "/"
                    + palette.getRootElement().getAttribute("name").getValue() + ".palette";
            Iterator<? extends Content> paletteElements = palette
                    .getDescendants(new ElementFilter("DiagramPaletteElement"));
            while (paletteElements.hasNext()) {
                Element paletteElement = (Element) paletteElements.next();
                Element binding = createPaletteElementBinding(paletteElement, paletteUri, dropSchemes);
                if (binding != null) {
                    paletteElementBindings.add(binding);
                }
            }
            XMLUtils.saveXMLFile(palette, paletteFile);
        }
        // Add the Palette Element Bindings to the TypedDiagramModelSlot
        if (!paletteElementBindings.isEmpty()) {
            typedDiagramModelSlot.addContent(paletteElementBindings);
        }
        if (typedDiagramModelSlot != null) {
            diagram.getRootElement().addContent(typedDiagramModelSlot);
        }

        // Update names
        convertNames16ToNames17(diagram);
        convertOldNameToNewNames("DiagramSpecification", "VirtualModel", diagram);

        // Save the files
        XMLUtils.saveXMLFile(diagram, file);

    } catch (JDOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}