Search in sources :

Example 41 with Format

use of org.jdom.output.Format in project ma-core-public by infiniteautomation.

the class JDOMConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    try {
        Format outformat = Format.getCompactFormat();
        outformat.setEncoding("UTF-8");
        // Setup the destination
        StringWriter xml = new StringWriter();
        XMLOutputter writer = new XMLOutputter(outformat);
        // Using XSLT to convert to a stream. Setup the source
        if (data instanceof Document) {
            Document doc = (Document) data;
            writer.output(doc, xml);
        } else if (data instanceof Element) {
            Element ele = (Element) data;
            writer.output(ele, xml);
        } else {
            throw new MarshallException(data.getClass());
        }
        xml.flush();
        String script = EnginePrivate.xmlStringToJavascriptDom(xml.toString());
        OutboundVariable ov = new SimpleOutboundVariable(script, outctx, false);
        outctx.put(data, ov);
        return ov;
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Format(org.jdom.output.Format) StringWriter(java.io.StringWriter) OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Element(org.jdom.Element) Document(org.jdom.Document) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException)

Example 42 with Format

use of org.jdom.output.Format in project intellij-plugins by StepicOrg.

the class StudySerializationUtilsTest method before.

@BeforeClass
public static void before() {
    outputter = new XMLOutputter();
    Format format = Format.getPrettyFormat().setLineSeparator("\n");
    outputter.setFormat(format);
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Format(org.jdom.output.Format) BeforeClass(org.junit.BeforeClass)

Example 43 with Format

use of org.jdom.output.Format in project maven-plugins by apache.

the class MavenJDOMWriter method write.

// -- void write(Model, Document, OutputStream)
/**
 * Method write
 *
 * @param project
 * @param writer
 * @param document
 */
public void write(Model project, Document document, OutputStreamWriter writer) throws java.io.IOException {
    Format format = Format.getRawFormat();
    format.setEncoding(writer.getEncoding()).setLineSeparator(System.getProperty("line.separator"));
    write(project, document, writer, format);
}
Also used : Format(org.jdom.output.Format)

Example 44 with Format

use of org.jdom.output.Format in project maven-plugins by apache.

the class EffectivePomMojo method prettyFormat.

/**
 * @param effectivePom not null
 * @return pretty format of the xml  or the original <code>effectivePom</code> if an error occurred.
 */
private static String prettyFormat(String effectivePom) {
    SAXBuilder builder = new SAXBuilder();
    try {
        Document effectiveDocument = builder.build(new StringReader(effectivePom));
        StringWriter w = new StringWriter();
        Format format = Format.getPrettyFormat();
        XMLOutputter out = new XMLOutputter(format);
        out.output(effectiveDocument, w);
        return w.toString();
    } catch (JDOMException e) {
        return effectivePom;
    } catch (IOException e) {
        return effectivePom;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException)

Example 45 with Format

use of org.jdom.output.Format in project maven-plugins by apache.

the class AbstractEffectiveMojo method addMavenNamespace.

/**
 * 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) 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)

Aggregations

Format (org.jdom.output.Format)45 XMLOutputter (org.jdom.output.XMLOutputter)40 Document (org.jdom.Document)20 Element (org.jdom.Element)20 StringWriter (java.io.StringWriter)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)6 Namespace (org.jdom.Namespace)6 Writer (java.io.Writer)5 SAXBuilder (org.jdom.input.SAXBuilder)5 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 JDOMException (org.jdom.JDOMException)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 File (java.io.File)3 FileWriter (java.io.FileWriter)3 StringReader (java.io.StringReader)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3