Search in sources :

Example 36 with XMLOutputter

use of org.jdom.output.XMLOutputter in project yamcs-studio by yamcs.

the class XMLUtil method widgetToOutputStream.

/**
 * Write widget to an output stream.
 *
 * @param widgetModel
 *            model of the widget
 * @param out
 *            output stream
 * @param prettyFormat
 *            true if in pretty format
 * @throws IOException
 */
public static void widgetToOutputStream(AbstractWidgetModel widgetModel, OutputStream out, boolean prettyFormat) throws IOException {
    XMLOutputter xmlOutputter = getXMLOutputter(prettyFormat);
    // $NON-NLS-1$
    out.write(XML_HEADER.getBytes("UTF-8"));
    xmlOutputter.output(widgetToXMLElement(widgetModel), out);
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter)

Example 37 with XMLOutputter

use of org.jdom.output.XMLOutputter in project che by eclipse.

the class EffectivePomWriter method addMavenNamespace.

/**
     * method from org.apache.maven.plugins.help.AbstractEffectiveMojo
     * Add a Pom/Settings namespaces to the effective XML content.
     *
     * @param effectiveXml not null the effective POM or Settings
     * @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
     * @return the content of the root element, i.e. &lt;project/&gt; or &lt;settings/&gt; with the Maven namespace or
     *         the original <code>effective</code> if an error occurred.
     * @see #POM_XSD_URL
     * @see #SETTINGS_XSD_URL
     */
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
    SAXBuilder builder = new SAXBuilder();
    try {
        Document document = builder.build(new StringReader(effectiveXml));
        Element rootElement = document.getRootElement();
        // added namespaces
        Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
        rootElement.setNamespace(pomNamespace);
        Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        rootElement.addNamespaceDeclaration(xsiNamespace);
        if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
            rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
        }
        ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
        for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
            Element e = (Element) i.next();
            e.setNamespace(pomNamespace);
        }
        StringWriter w = new StringWriter();
        Format format = Format.getPrettyFormat();
        XMLOutputter out = new XMLOutputter(format);
        out.output(document.getRootElement(), w);
        return w.toString();
    } catch (JDOMException e) {
        return effectiveXml;
    } catch (IOException e) {
        return effectiveXml;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) StringWriter(java.io.StringWriter) Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace)

Example 38 with XMLOutputter

use of org.jdom.output.XMLOutputter in project intellij-community by JetBrains.

the class WorkingContextManager method saveContext.

private synchronized void saveContext(@Nullable String entryName, String zipPostfix, @Nullable String comment) {
    JBZipFile archive = null;
    try {
        archive = getTasksArchive(zipPostfix);
        if (entryName == null) {
            int i = archive.getEntries().size();
            do {
                entryName = "context" + i++;
            } while (archive.getEntry("/" + entryName) != null);
        }
        JBZipEntry entry = archive.getOrCreateEntry("/" + entryName);
        if (comment != null) {
            entry.setComment(StringUtil.first(comment, 200, true));
        }
        Element element = new Element("context");
        saveContext(element);
        String s = new XMLOutputter().outputString(element);
        entry.setData(s.getBytes(CharsetToolkit.UTF8_CHARSET));
    } catch (IOException e) {
        LOG.error(e);
    } finally {
        closeArchive(archive);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) JBZipFile(com.intellij.util.io.zip.JBZipFile) IOException(java.io.IOException) JBZipEntry(com.intellij.util.io.zip.JBZipEntry)

Example 39 with XMLOutputter

use of org.jdom.output.XMLOutputter in project intellij-community by JetBrains.

the class MavenEffectivePomDumper method addMavenNamespace.

/**
   * Copy/pasted from org.apache.maven.plugins.help.AbstractEffectiveMojo
   */
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
    SAXBuilder builder = new SAXBuilder();
    try {
        Document document = builder.build(new StringReader(effectiveXml));
        Element rootElement = document.getRootElement();
        // added namespaces
        Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
        rootElement.setNamespace(pomNamespace);
        Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        rootElement.addNamespaceDeclaration(xsiNamespace);
        if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
            rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
        }
        ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
        for (Iterator i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
            Element e = (Element) i.next();
            e.setNamespace(pomNamespace);
        }
        addLineBreaks(document, pomNamespace);
        StringWriter w = new StringWriter();
        Format format = Format.getRawFormat();
        XMLOutputter out = new XMLOutputter(format);
        out.output(document.getRootElement(), w);
        return w.toString();
    } catch (JDOMException e) {
        return effectiveXml;
    } catch (IOException e) {
        return effectiveXml;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ElementFilter(org.jdom.filter.ElementFilter)

Example 40 with XMLOutputter

use of org.jdom.output.XMLOutputter in project intellij-community by JetBrains.

the class StudyTaskManager method loadState.

@Override
public void loadState(Element state) {
    try {
        int version = StudySerializationUtils.Xml.getVersion(state);
        if (version == -1) {
            LOG.error("StudyTaskManager doesn't contain any version:\n" + state.getValue());
            return;
        }
        switch(version) {
            case 1:
                state = StudySerializationUtils.Xml.convertToSecondVersion(state);
            case 2:
                state = StudySerializationUtils.Xml.convertToThirdVersion(state, myProject);
            case 3:
                state = StudySerializationUtils.Xml.convertToForthVersion(state);
        }
        XmlSerializer.deserializeInto(this, state.getChild(StudySerializationUtils.Xml.MAIN_ELEMENT));
        VERSION = CURRENT_VERSION;
        if (myCourse != null) {
            myCourse.initCourse(true);
            if (version != VERSION) {
                final File updatedCourse = new File(StudyProjectGenerator.OUR_COURSES_DIR, myCourse.getName());
                if (updatedCourse.exists()) {
                    myCourse.setCourseDirectory(updatedCourse.getAbsolutePath());
                }
            }
        }
    } catch (StudySerializationUtils.StudyUnrecognizedFormatException e) {
        LOG.error("Unexpected course format:\n", new XMLOutputter().outputString(state));
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) File(java.io.File)

Aggregations

XMLOutputter (org.jdom.output.XMLOutputter)64 Element (org.jdom.Element)34 Document (org.jdom.Document)22 Format (org.jdom.output.Format)22 IOException (java.io.IOException)16 StringWriter (java.io.StringWriter)14 ArrayList (java.util.ArrayList)7 StringReader (java.io.StringReader)5 Writer (java.io.Writer)5 SAXBuilder (org.jdom.input.SAXBuilder)5 FileWriter (java.io.FileWriter)4 List (java.util.List)3 TreeMap (java.util.TreeMap)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 JDOMException (org.jdom.JDOMException)3 ElementFilter (org.jdom.filter.ElementFilter)3 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2