Example usage for org.jdom2 Element addContent

List of usage examples for org.jdom2 Element addContent

Introduction

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

Prototype

@Override
public Element addContent(final Collection<? extends Content> newContent) 

Source Link

Document

Appends all children in the given collection to the end of the content list.

Usage

From source file:com.archimatetool.editor.model.compatibility.Archimate2To3Converter.java

License:Open Source License

/**
 * Remove "Derived" folder and move contents to "Relations" folder
 *///  w  w w.  j  a  v  a  2s . c om
private void moveDerivedRelationsFolderContents() {
    Element eDerivedFolder = getModelFolder("derived");
    if (eDerivedFolder != null) {
        eDerivedFolder.detach();

        Element eRelationsFolder = getModelFolder("relations");
        if (eRelationsFolder != null) {
            List<Element> copy = new ArrayList<>(eDerivedFolder.getChildren());
            for (Element eChild : copy) {
                eChild.detach();
                eRelationsFolder.addContent(eChild);
            }
        }
    }
}

From source file:com.archimatetool.editor.model.compatibility.Archimate2To3Converter.java

License:Open Source License

/**
 * Move concepts to different folders/*from  ww w .jav a 2 s.  c om*/
 */
private void moveConceptType(Element element) {
    Attribute attType = element.getAttribute("type", JDOMUtils.XSI_Namespace);

    if (attType != null) {
        String value = attType.getValue();

        // Location
        if ("archimate:Location".equals(value)) {
            Element eFolder = getModelFolder("other");
            if (eFolder != null) {
                element.detach();
                eFolder.addContent(element);
            }
        }

        // Value / Meaning
        if ("archimate:Value".equals(value) || "archimate:Meaning".equals(value)) {
            Element eFolder = getModelFolder("motivation");
            if (eFolder != null) {
                element.detach();
                eFolder.addContent(element);
            }
        }
    }
}

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);/*  w  w  w  . ja  v a  2 s. co m*/
    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  v a2s.com*/

    // 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);
}

From source file:com.archimatetool.templates.model.AbstractTemplate.java

License:Open Source License

@Override
public void save() throws IOException {
    if (fFile == null || !fFile.exists()) {
        return;/* ww  w.jav  a2s  .com*/
    }

    // Manifest
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);

    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(getName());
    root.addContent(elementName);

    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(getDescription());
    root.addContent(elementDescription);

    if (fKeyThumbnailPath != null) {
        Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
        elementKeyThumb.setText(fKeyThumbnailPath);
        root.addContent(elementKeyThumb);
    }

    String manifest = JDOMUtils.write2XMLString(doc);

    // Model
    String model = ZipUtils.extractZipEntry(fFile, TemplateManager.ZIP_ENTRY_MODEL);

    // Start a zip stream
    File tmpFile = File.createTempFile("architemplate", null); //$NON-NLS-1$
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmpFile));
    ZipOutputStream zOut = new ZipOutputStream(out);

    ZipUtils.addStringToZip(manifest, TemplateManager.ZIP_ENTRY_MANIFEST, zOut);
    ZipUtils.addStringToZip(model, TemplateManager.ZIP_ENTRY_MODEL, zOut);

    // Thumbnails
    Image[] images = getThumbnails();
    int i = 1;
    for (Image image : images) {
        ZipUtils.addImageToZip(image, TemplateManager.ZIP_ENTRY_THUMBNAILS + i++ + ".png", zOut, SWT.IMAGE_PNG, //$NON-NLS-1$
                null);
    }

    zOut.flush();
    zOut.close();

    // Delete and copy
    fFile.delete();
    FileUtils.copyFile(tmpFile, fFile, false);
    tmpFile.delete();
}

From source file:com.archimatetool.templates.model.TemplateManager.java

License:Open Source License

public void saveUserTemplatesManifest() throws IOException {
    if (fUserTemplates == null || fUserTemplateGroups == null) {
        return;//from  www . j  ava  2s.c o  m
    }

    Document doc = new Document();
    Element rootElement = new Element(XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(rootElement);

    for (ITemplate template : fUserTemplates) {
        Element templateElement = new Element(XML_TEMPLATE_ELEMENT_TEMPLATE);
        rootElement.addContent(templateElement);
        templateElement.setAttribute(XML_TEMPLATE_ATTRIBUTE_TYPE, template.getType());
        templateElement.setAttribute(XML_TEMPLATE_ATTRIBUTE_ID, template.getID());
        templateElement.setAttribute(XML_TEMPLATE_ATTRIBUTE_FILE, template.getFile().getAbsolutePath());
    }

    for (ITemplateGroup group : fUserTemplateGroups) {
        Element groupElement = new Element(XML_TEMPLATE_ELEMENT_GROUP);
        rootElement.addContent(groupElement);
        groupElement.setAttribute(XML_TEMPLATE_ATTRIBUTE_NAME, group.getName());
        for (ITemplate template : group.getTemplates()) {
            Element templateRefElement = new Element(XML_TEMPLATE_ELEMENT_TEMPLATE_REF);
            groupElement.addContent(templateRefElement);
            templateRefElement.setAttribute(XML_TEMPLATE_ATTRIBUTE_REF, template.getID());
        }
    }

    JDOMUtils.write2XMLFile(doc, getUserTemplatesManifestFile());
}

From source file:com.astronomy.project.Alignment.java

/**
 * //from w ww . j a v  a  2s.  c  o  m
 * @return XML element
 */
public Element getXMLElement() {
    Element raiz = new Element("alineamiento");
    raiz.addContent(observatory.getElementoXML());
    raiz.addContent(foresight.getElementoXML());
    raiz.addContent(orientation.getXMLElement());
    raiz.addContent(description.getXMLElement());
    raiz.addContent(imagenPath.getXMLElement());
    raiz.addContent(getDeclination().getElementoXML());
    return raiz;
}

From source file:com.astronomy.project.Orientation.java

/**
 * //from www.j av  a 2s .c  om
 * @return XML element for orientation
 */
public Element getXMLElement() {
    Element raiz = new Element("direccion");
    Element acimutElemento = new Element("acimut");
    acimutElemento.setText(String.valueOf(getAzimuth().getSignedValue()));
    Element elevacionElemento = new Element("elevacion");
    elevacionElemento.setText(String.valueOf(getAltitude().getSignedValue()));
    raiz.addContent(acimutElemento);
    raiz.addContent(elevacionElemento);
    return raiz;
}

From source file:com.astronomy.project.Project.java

/**
 * Save project as XML file// w  ww.  j a v  a2 s  .  c  o m
 * @param file XML file
 * @throws FileNotFoundException File not found error
 * @throws IOException IO error
 * @throws NullPointerException Null pointer error 
 */
public void toXML(File file) throws FileNotFoundException, IOException, NullPointerException {
    Element estudioElemento = new Element("estudio");
    Document doc = new Document(estudioElemento);
    estudioElemento.setAttribute("nombre", name);
    Element aa = new Element("alineamientos");
    estudioElemento.addContent(aa);
    for (int i = 0; i < data.size(); i++) {
        Alignment ali = (Alignment) data.get(i);
        aa.addContent(ali.getXMLElement());
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    FileOutputStream out = null;
    try {
        xmlOutput.output(doc, out = new FileOutputStream(file));
    } finally {
        out.close();
    }
}

From source file:com.astronomy.project.ReferencePoint.java

/**
 * /*from  w w w . j  a  va  2s .c o m*/
 * @return Reference point as XML element
 */
public Element getElementoXML() {
    Element raiz = new Element("lugar");
    raiz.setAttribute("tipo", getType());
    Element nombreElemento = new Element("nombre");
    nombreElemento.setText(getName());
    raiz.addContent(nombreElemento);
    if (getCoordinates() != null) {
        Element coordenadasElemento = new Element("coordenadas");
        Element latitudElemento = new Element("latitud");
        Element longitudElemento = new Element("longitud");
        Element altitudElemento = new Element("altitud");
        latitudElemento.setText(getCoordinates().getLatitude().toString());
        longitudElemento.setText(getCoordinates().getLongitude().toString());
        altitudElemento.setText(String.valueOf(getCoordinates().getElevation()));
        coordenadasElemento.addContent(latitudElemento);
        coordenadasElemento.addContent(longitudElemento);
        coordenadasElemento.addContent(altitudElemento);
        raiz.addContent(coordenadasElemento);
    }
    return raiz;
}