Example usage for org.jdom2.output Format getPrettyFormat

List of usage examples for org.jdom2.output Format getPrettyFormat

Introduction

In this page you can find the example usage for org.jdom2.output Format getPrettyFormat.

Prototype

public static Format getPrettyFormat() 

Source Link

Document

Returns a new Format object that performs whitespace beautification with 2-space indents, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy.

Usage

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);
            }// ww w.  j av  a2 s.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********/*from  w  ww.ja  v  a 2s .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********/*from   w w w  . ja  v a  2 s  . c o m*/
********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********// w ww. j av a2  s.  c o 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 {//from  w  ww  .j  ava2s.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.universaal.tools.configurationEditor.editors.ConfigurationEditor.java

License:Apache License

/**
 * Saves the multi-page editor's document.
 *//*  w  w w  .  j  a va 2  s  .  c o m*/
@Override
public void doSave(IProgressMonitor monitor) {

    // xml -> config
    if (getActivePage() == 0) {
        getEditor(0).doSave(monitor);
        removePage(1);
        createConfigPage();

        // config -> xml
    } else if (getActivePage() == 1) {
        XMLOutputter outp = new XMLOutputter();

        outp.setFormat(Format.getPrettyFormat());

        StringWriter sw = new StringWriter();
        try {
            outp.output(doc.getContent(), sw);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        StringBuffer sb = sw.getBuffer();
        String editorText = sb.toString();

        editor.getDocumentProvider().getDocument(editor.getEditorInput()).set(editorText);
        getEditor(0).doSave(monitor);
    }
    setDirty(false);
}

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

License:Open Source License

public String PrepareDocumentToBeSign(Element element) {

    try {/*from   w  ww .  java  2 s  .  c  o m*/
        //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.elements.YNet.java

License:Open Source License

public void setIncomingData(YPersistenceManager pmgr, Element incomingData)
        throws YDataStateException, YPersistenceException {
    for (YParameter parameter : getInputParameters().values()) {
        Element actualParam = incomingData.getChild(parameter.getName());
        if (parameter.isMandatory() && actualParam == null) {
            throw new IllegalArgumentException("The input data for Net:" + getID()
                    + " is missing mandatory input data for a parameter (" + parameter.getName() + ").  "
                    + " Alternatively the data is there but the query in the super net produced data with"
                    + " the wrong name (Check your specification). "
                    + new XMLOutputter(Format.getPrettyFormat()).outputString(incomingData).trim());
        }//from   w w  w . ja  v  a2 s. com

        // remove any attributes - not required and cause validation errors if left
        if ((actualParam != null) && !actualParam.getAttributes().isEmpty()) {
            JDOMUtil.stripAttributes(actualParam);
        }
    }

    // validate against schema
    getSpecification().getDataValidator().validate(getInputParameters().values(), incomingData, getID());

    for (Element element : incomingData.getChildren()) {
        if (getInputParameters().containsKey(element.getName())) {
            addData(pmgr, element.clone());
        } else {
            throw new IllegalArgumentException(
                    "Element " + element + " is not a valid input parameter of " + this);
        }
    }
}

From source file:org.yawlfoundation.yawl.swingWorklist.YWorklistModel.java

License:Open Source License

private JPanel createCentrePanel(YDataStateException exception) {
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    JPanel centrePanel = new JPanel(new GridLayout(1, 2));

    JPanel schemaPanel = new JPanel(new BorderLayout());
    schemaPanel.setBackground(YAdminGUI._apiColour);
    schemaPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Schema for completing task"),
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    JTextPane schemaTextPane = new JTextPane();
    schemaTextPane.setContentType("text/xml");
    schemaTextPane.setFont(new Font("courier", Font.PLAIN, 12));
    String schemaXML = xmlOut.outputString(exception.getSchema());

    /**//from w ww  .j  a  v a 2 s. com
     * AJH: Trap various XML format errors gracefully.
     */
    try {
        String xml = schemaXML.substring(schemaXML.indexOf('<'), schemaXML.lastIndexOf("</xsd:schema>") + 13);
        schemaTextPane.setText(xml);
    } catch (Exception e) {
        schemaTextPane.setText(schemaXML);
    }

    schemaTextPane.setEditable(false);
    schemaTextPane.setBackground(Color.LIGHT_GRAY);
    JPanel noWrapPanel = new JPanel();
    noWrapPanel.setLayout(new BorderLayout());
    noWrapPanel.add(schemaTextPane);
    schemaPanel.add(new JScrollPane(noWrapPanel));

    JPanel rightPanel = new JPanel(new GridLayout(2, 1));

    JPanel dataPanel = new JPanel(new BorderLayout());
    dataPanel.setBackground(YAdminGUI._apiColour);
    dataPanel
            .setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
                            "The data that failed to validate"),
                    BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    JTextPane dataTextPane = new JTextPane();
    dataTextPane.setContentType("text/xml");
    dataTextPane.setFont(new Font("courier", Font.PLAIN, 12));
    String data = xmlOut.outputString(exception.get_dataInput());

    /**
     * AJH: Trap various XML format errors gracefully.
     */
    try {
        String temp = data.substring(data.lastIndexOf("<?xml"), data.lastIndexOf('>'));
        dataTextPane.setText(temp);
    } catch (Exception e) {
        dataTextPane.setText(data);
    }

    dataTextPane.setEditable(false);
    dataTextPane.setBackground(Color.LIGHT_GRAY);
    JPanel noWrapPanel2 = new JPanel();
    noWrapPanel2.setLayout(new BorderLayout());
    noWrapPanel2.add(dataTextPane);
    dataPanel.add(new JScrollPane(noWrapPanel2));

    JPanel errorPanel = new JPanel(new BorderLayout());
    errorPanel.setBackground(YAdminGUI._apiColour);
    errorPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
                    "The error message from validation engine"),
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    JTextPane errorTextPane = new JTextPane();
    errorTextPane.setContentType("text/plain");
    errorTextPane.setFont(new Font("courier", Font.PLAIN, 12));

    /**
     * AJH: Trap various XML format errors gracefully.
     */
    try {
        String error = schemaXML.substring(schemaXML.lastIndexOf("ERRORS ="), schemaXML.length());
        errorTextPane.setText(error);
    } catch (Exception e) {
        // null action !
    }

    errorTextPane.setText(exception.getErrors());

    errorTextPane.setEditable(false);
    errorTextPane.setBackground(Color.LIGHT_GRAY);
    JPanel noWrapPanel3 = new JPanel();
    noWrapPanel3.setLayout(new BorderLayout());
    noWrapPanel3.add(errorTextPane);
    errorPanel.add(new JScrollPane(noWrapPanel3));

    rightPanel.add(dataPanel);
    rightPanel.add(errorPanel);
    centrePanel.add(schemaPanel, BorderLayout.NORTH);
    centrePanel.add(rightPanel, BorderLayout.CENTER);
    return centrePanel;
}

From source file:org.yawlfoundation.yawl.util.JDOMUtil.java

License:Open Source License

/****************************************************************************/

public static String documentToString(Document doc) {
    if (doc == null)
        return null;
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    return out.outputString(doc);
}