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);
}
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. <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;
}
}
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);
}
}
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;
}
}
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));
}
}
Aggregations