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);
}
}
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);
}
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);
}
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;
}
}
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. <project/> or <settings/> 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;
}
}
Aggregations