Example usage for org.jdom2 Document Document

List of usage examples for org.jdom2 Document Document

Introduction

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

Prototype

public Document(List<? extends Content> content) 

Source Link

Document

This will create a new Document, with the supplied list of content, and a DocType declaration only if the content contains a DocType instance.

Usage

From source file:org.t3.metamediamanager.MediaCenterDataMediaBrowser.java

License:Apache License

/********************************************************************
*********************************************************************
******************************SERIES*********************************
*********************************************************************
*********************************************************************/

@Override//from  w w w . j av a  2 s. c  o  m
public void saveSeries(MediaInfo mediainfo, String directory) {

    HashMap<String, String> hashinfo = _saverconfig.getFieldsAssociation();
    Element root = new Element("Data");
    Element series = new Element("Series");
    for (Entry<String, String> entry : mediainfo.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        for (Entry<String, String> entry2 : hashinfo.entrySet()) {
            String key2 = entry2.getKey();
            String value2 = entry2.getValue();

            if (key.equals(key2)) {
                Element newchild = new Element(value2);
                newchild.setText(value);

                series.addContent(newchild);
            }
        }

    }
    //actors
    Element allactorselement = new Element("Actors");
    String allactors = "";
    ActorInfo[] actors = mediainfo.getActors();
    Element actorselement = new Element("Actors");
    for (int i = 0; i < actors.length; i++) {
        Element actorelement = new Element("Actor");
        Element name = new Element("Name");
        name.setText(actors[i].getName());
        Element role = new Element("Role");
        role.setText(actors[i].getRole());
        actorelement.addContent(name);
        actorelement.addContent(role);
        actorselement.addContent(actorelement);
        allactors += actors[i].getName() + " | ";

    }
    if (allactors != "" && allactors.length() >= 2) {
        allactorselement.setText(allactors.substring(0, allactors.length() - 2));
    }
    series.addContent(allactorselement);
    series.addContent(actorselement);

    root.addContent(series);

    Document document = new Document(root);
    XMLOutputter exit = new XMLOutputter(Format.getPrettyFormat());
    String newFileNameNfo = new File(directory, "Series.xml").getAbsolutePath();
    System.out.println(newFileNameNfo);
    try {
        exit.output(document, new FileOutputStream(newFileNameNfo));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //images
    String images[];

    images = mediainfo.getImages("img_banner");
    if (images[0] != "") {
        copy_images(images[0], new File(directory, "banner.jpg").getAbsolutePath());
    }

    images = mediainfo.getImages("img_poster");
    if (images[0] != "") {
        copy_images(images[0], new File(directory, "folder.jpg").getAbsolutePath());
    }
    images = mediainfo.getImages("img_fanart");

    if (images[0] != "") {
        for (int i = 0; i < images.length; i++) {
            int j = i + 1;
            copy_images(images[i], new File(directory, "backdrop" + j + ".jpg").getAbsolutePath());
        }
    }

}

From source file:org.t3.metamediamanager.MediaCenterDataMediaBrowser.java

License:Apache License

@Override
public void saveEpisode(MediaInfo mediainfo, String filename) {
    HashMap<String, String> hashinfo = _saverconfig.getFieldsAssociation();
    Element root = new Element("Data");
    Element series = new Element("Episode");
    for (Entry<String, String> entry : mediainfo.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        for (Entry<String, String> entry2 : hashinfo.entrySet()) {
            String key2 = entry2.getKey();
            String value2 = entry2.getValue();

            if (key.equals(key2)) {
                Element newchild = new Element(value2);
                newchild.setText(value);

                series.addContent(newchild);
            }/*from   w  w  w  . j a  v  a2s  .  c  o m*/
        }

    }
    root.addContent(series);

    Document document = new Document(root);
    XMLOutputter exit = new XMLOutputter(Format.getPrettyFormat());
    String directory = new File(filename).getParentFile().toString();
    String directorymeta = directory + File.separator + "metadata";
    File directorymetafile = new File(directorymeta);
    if (!directorymetafile.exists())
        directorymetafile.mkdir();
    File mediafile = new File(filename);
    String newFileNameNfo = directorymetafile.getAbsolutePath() + File.separator
            + mediafile.getName().substring(0, mediafile.getName().lastIndexOf('.')) + ".nfo";
    try {
        exit.output(document, new FileOutputStream(newFileNameNfo));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //images
    String images[];

    images = mediainfo.getImages("img_banner");
    if (images[0] != "") {

        copy_images(images[0], new File(directory, "banner.jpg").getAbsolutePath());
    }

    images = mediainfo.getImages("img_poster");
    if (images[0] != "") {
        copy_images(images[0], new File(directory, "folder.jpg").getAbsolutePath());
        System.out.println(directory);
    }
    images = mediainfo.getImages("img_fanart");

}

From source file:org.t3.metamediamanager.MediaCenterDataXBMC.java

License:Apache License

/********************
*********SAVE********/* ww w.j a v a  2 s.  c o  m*/
********************/

@Override
public void save(MediaInfo info, String filename) {
    Element root = new Element("movie");
    Document document = new Document(root);
    Element child, child2, child3;
    String key, value, key2, value2;
    HashMap<String, String> fieldsAssociation = _saverconfig.getFieldsAssociation();
    for (Entry<String, String> entry : info.entrySet()) {

        key = entry.getKey();
        value = entry.getValue();
        for (Entry<String, String> entry2 : fieldsAssociation.entrySet()) {
            key2 = entry2.getKey();
            value2 = entry2.getValue();
            if (key.equals(key2)) {
                child = new Element(value2);
                child.setText(value);
                root.addContent(child);
            }
        }
    }
    ActorInfo[] actors = info.getActors();
    HashMap<String, String> actorsimg = new HashMap<String, String>();
    if (actors.length >= 1) {
        for (int i = 0; i < actors.length; i++) {

            child = new Element("actor");

            child2 = new Element("name");
            child2.setText(actors[i].getName());
            child.addContent(child2);
            //*****
            child3 = new Element("role");
            child3.setText(actors[i].getRole());
            child.addContent(child3);
            //*****
            if (!actors[i].getImgUrl().isEmpty()) {

                actorsimg.put(actors[i].getName(),
                        M3Config.getInstance().getUserConfDirectory() + actors[i].getImgUrl());
            }
            root.addContent(child);
        }
    }

    XMLOutputter exit = new XMLOutputter(Format.getPrettyFormat());
    String newFileName = filename.substring(0, filename.lastIndexOf('.'));
    String newFileNameNfo = newFileName + ".nfo";
    try {
        exit.output(document, new FileOutputStream(newFileNameNfo));
    } catch (FileNotFoundException e) {

    } catch (IOException e) {

    }
    String images[];

    images = info.getImages("img_poster");
    if (images[0] != null && images[0] != "")
        copy_images(images[0], newFileName + "-poster.jpg");
    images = info.getImages("img_fanart");
    System.out.println("->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + Arrays.toString(images));
    if (images[0] != null && images[0] != "")
        copy_images(images[0], newFileName + "-fanart.jpg");
    File dir = new File(new File(filename).getParentFile(), ".actors");
    dir.mkdir();
    String newActorName;
    if (actorsimg != null && !actorsimg.isEmpty()) {
        for (Entry<String, String> entry : actorsimg.entrySet()) {

            String newimage = entry.getValue();
            newActorName = entry.getKey().replace(' ', '_');
            if (newimage != null && newimage != "" && new File(newimage).exists())
                copy_images(newimage, new File(dir, newActorName + ".jpg").toString());
            System.out.println(
                    newimage + "++++++++++++++++++++++++" + new File(dir, newActorName + ".jpg").toString());
        }
    }

}

From source file:org.t3.metamediamanager.MediaCenterDataXBMC.java

License:Apache License

/********************
*********SAVE********/*w w w  . java 2s .  c  om*/
********EPISODE*****/
public void saveEpisode(MediaInfo info, String filename) {
    Element root = new Element("episodedetails");
    Document document = new Document(root);
    Element child;
    String key, value, key2, value2;
    HashMap<String, String> fieldsAssociation = _saverconfig.getFieldsAssociation();
    for (Entry<String, String> entry : info.entrySet()) {

        key = entry.getKey();
        value = entry.getValue();
        for (Entry<String, String> entry2 : fieldsAssociation.entrySet()) {
            key2 = entry2.getKey();
            value2 = entry2.getValue();
            if (key.equals(key2)) {
                child = new Element(value2);
                child.setText(value);
                root.addContent(child);

            }
        }
    }
    XMLOutputter exit = new XMLOutputter(Format.getPrettyFormat());
    String newFileName = filename.substring(0, filename.lastIndexOf('.'));
    String newFileNameNfo = newFileName + ".nfo";
    try {
        exit.output(document, new FileOutputStream(newFileNameNfo));
    } catch (FileNotFoundException e) {

    } catch (IOException e) {

    }
    String images[];

    images = info.getImages("img_poster");
    System.out.println(Arrays.toString(images));
    if (images[0] != null && images[0] != "")
        copy_images(images[0], newFileName + "-thumb.jpg");
}

From source file:org.t3.metamediamanager.MediaCenterDataXBMC.java

License:Apache License

/********************
*********SAVE********//from w  ww  .ja  v  a 2s  . co  m
********SERIES******/
public void saveSeries(MediaInfo info, String directory) {
    Element root = new Element("tvshow");
    Document document = new Document(root);
    Element child;
    String key, value, key2, value2;
    HashMap<String, String> fieldsAssociation = _saverconfig.getFieldsAssociation();
    for (Entry<String, String> entry : info.entrySet()) {

        key = entry.getKey();
        value = entry.getValue();
        for (Entry<String, String> entry2 : fieldsAssociation.entrySet()) {
            key2 = entry2.getKey();
            value2 = entry2.getValue();
            if (key.equals(key2)) {
                child = new Element(value2);
                child.setText(value);
                root.addContent(child);

            }
        }
    }
    XMLOutputter exit = new XMLOutputter(Format.getPrettyFormat());
    String newFileNameNfo = new File(directory, "tvshow.nfo").getAbsolutePath();
    try {
        exit.output(document, new FileOutputStream(newFileNameNfo));
    } catch (FileNotFoundException e) {

    } catch (IOException e) {

    }
    String images[];

    images = info.getImages("img_poster");
    if (images[0] != null && images[0] != "")
        copy_images(images[0], new File(directory, "posterAllSeason.jpg").getAbsolutePath());

    images = info.getImages("img_fanart");
    if (images[0] != null && images[0] != "")
        copy_images(images[0], new File(directory, "fanart.jpg").getAbsolutePath());

    images = info.getImages("img_banner");
    if (images[0] != null && images[0] != "")
        copy_images(images[0], new File(directory, "banner.jpg").getAbsolutePath());
}

From source file:org.t3.metamediamanager.ProviderManager.java

License:Apache License

public void save() {
    try {// w  w w.  j  a  va  2 s.  c  om
        Element root = new Element("fields");
        Document doc = new Document(root);

        for (Entry<String, String[]> infoType : _priorities.entrySet()) {
            Element infoTypeElement = new Element("field");
            infoTypeElement.setAttribute("name", infoType.getKey());
            int priority = 1;
            for (String providerName : infoType.getValue()) {
                Element providerElement = new Element("provider");
                providerElement.setAttribute("name", providerName);
                providerElement.setAttribute("priority", "" + priority);
                infoTypeElement.addContent(providerElement);
                priority++;
            }
            root.addContent(infoTypeElement);
        }

        //Save
        XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
        sortie.output(doc, new FileOutputStream(_configFile));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {

    }
}

From source file:org.yawlfoundation.yawl.digitalSignature.DigitalSignature.java

License:Open Source License

public String PrepareDocumentToBeSign(Element element) {

    try {//from  w  w  w .  ja  v  a2s.  c om
        //extract the Document to sign and transform it in a valid XML DOM 
        Element rootElement = new Element(element.getName());
        rootElement.setContent(element.cloneContent());
        //convert the Element in a JDOM Document
        Document xdoc = new Document(rootElement);
        //create a DOMOutputter to write the content of the JDOM document in a DOM document
        DOMOutputter outputter = new DOMOutputter();
        org.w3c.dom.Document Doctosign = outputter.output(xdoc);

        // Show the document before being sign 
        System.out.println("xml to Sign:");
        XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
        sortie.output(xdoc, System.out);

        //Transform the XML DOM in a String using the xml transformer
        DOMSource domSource = new DOMSource(Doctosign);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);
        String StringTobeSign = writer.toString();

        return StringTobeSign;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}

From source file:org.yawlfoundation.yawl.engine.instance.WorkItemInstance.java

License:Open Source License

public void updateParameterValues(Element data) {
    if (data != null) {
        updateParameterValues(new Document(data));
    }
}

From source file:org.yawlfoundation.yawl.resourcing.codelets.XQueryEvaluator.java

License:Open Source License

public Element execute(Element inData, List<YParameter> inParams, List<YParameter> outParams)
        throws CodeletExecutionException {

    if (outParams == null) {
        String msg = "Cannot perform evaluation: Missing or empty output parameter list.";
        throw new CodeletExecutionException(msg);
    }// ww w . ja va  2  s .c o m

    this.setInputs(inData, inParams, outParams);

    // convert input vars to a Doc
    Document dataDoc = new Document(inData.clone());

    String query = (String) getParameterValue("query");
    String output = evaluateQuery(query, dataDoc);

    setParameterValue("result", output);
    return getOutputData();
}

From source file:org.yawlfoundation.yawl.resourcing.util.DataSchemaBuilder.java

License:Open Source License

private Element createPreamble(String rootName, Namespace defNS) {

    // create a new doc with a root element called 'schema'
    Element root = new Element("schema", defNS);
    root.setAttribute("elementFormDefault", "qualified");
    new Document(root); // attaches a default doc as parent of root element

    // attach an element set to the supplied root name
    Element taskElem = new Element("element", defNS);
    taskElem.setAttribute("name", rootName);
    root.addContent(taskElem);//from ww  w . ja  v  a  2  s .  co m

    Element complex = new Element("complexType", defNS);
    Element sequence = new Element("sequence", defNS);
    taskElem.addContent(complex);
    complex.addContent(sequence);

    return sequence;
}