use of org.dom4j.io.OutputFormat in project OpenOLAT by OpenOLAT.
the class ContentPackage method writeToFile.
/**
* writes the manifest.xml
*/
void writeToFile() {
String filename = "imsmanifest.xml";
OutputFormat format = OutputFormat.createPrettyPrint();
try {
VFSLeaf outFile;
// file may exist
outFile = (VFSLeaf) cpcore.getRootDir().resolve("/" + filename);
if (outFile == null) {
// if not, create it
outFile = cpcore.getRootDir().createChildLeaf("/" + filename);
}
DefaultDocument manifestDocument = cpcore.buildDocument();
XMLWriter writer = new XMLWriter(outFile.getOutputStream(false), format);
writer.write(manifestDocument);
} catch (Exception e) {
log.error("imsmanifest for ores " + ores.getResourceableId() + "couldn't be written to file.", e);
throw new OLATRuntimeException(CPOrganizations.class, "Error writing imsmanifest-file", new IOException());
}
}
use of org.dom4j.io.OutputFormat in project xresloader by xresloader.
the class DataDstXml method build.
@Override
public final byte[] build(DataDstImpl compiler) throws ConvException {
// pretty print
OutputFormat of = null;
if (ProgramOptions.getInstance().prettyIndent <= 0) {
of = OutputFormat.createCompactFormat();
} else {
of = OutputFormat.createPrettyPrint();
of.setIndentSize(ProgramOptions.getInstance().prettyIndent);
}
// build data
DataDstObject data_obj = build_data(compiler);
// build xml tree
Document doc = DocumentHelper.createDocument();
String encoding = SchemeConf.getInstance().getKey().getEncoding();
if (null != encoding && false == encoding.isEmpty()) {
doc.setXMLEncoding(encoding);
of.setEncoding(encoding);
}
doc.setRootElement(DocumentHelper.createElement(ProgramOptions.getInstance().xmlRootName));
doc.getRootElement().addComment("this file is generated by xresloader, please don't edit it.");
Element header = DocumentHelper.createElement("header");
Element body = DocumentHelper.createElement("body");
writeData(header, data_obj.header, header.getName());
// body
for (Map.Entry<String, List<Object>> item : data_obj.body.entrySet()) {
for (Object obj : item.getValue()) {
Element xml_item = DocumentHelper.createElement(item.getKey());
writeData(xml_item, obj, item.getKey());
body.add(xml_item);
}
}
writeData(body, data_obj.body, body.getName());
doc.getRootElement().add(header);
doc.getRootElement().add(body);
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(bos, of);
writer.write(doc);
return bos.toByteArray();
} catch (Exception e) {
ProgramOptions.getLoger().error("write xml failed, %s", e.getMessage());
return null;
}
}
use of org.dom4j.io.OutputFormat in project fmv by f-agu.
the class Project method save.
/**
*/
public void save() throws IOException {
Document document = DocumentHelper.createDocument();
Element root = document.addElement("fmv");
saveMain(root);
saveSources(root);
saveExtensions(root);
saveProperties(root);
saveUndeleteFileName(root);
saveOutputInfos(root);
saveExecutables(root);
// write
OutputFormat format = new OutputFormat("\t");
format.setTrimText(true);
format.setNewlines(true);
XMLWriter writer = new XMLWriter(new FileWriter(getSaveFile()), format);
writer.write(document);
writer.close();
modified = false;
}
use of org.dom4j.io.OutputFormat in project mule by mulesoft.
the class DefaultExtensionSchemaGenerator method renderSchema.
private String renderSchema(Schema schema) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Schema.class);
Marshaller marshaller = jaxbContext.createMarshaller();
NamespaceFilter outFilter = new NamespaceFilter(CORE_PREFIX, CORE_NAMESPACE, true);
OutputFormat format = new OutputFormat();
format.setIndent(true);
format.setNewlines(true);
StringWriter sw = new StringWriter();
XMLWriter writer = new XMLWriter(sw, format);
outFilter.setContentHandler(writer);
marshaller.marshal(schema, outFilter);
return sw.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
use of org.dom4j.io.OutputFormat in project notes by KevinBlandy.
the class Dom4jDemo method add.
/**
* ��ӽڵ����(���һ��gender��ǩ)
*/
public static void add() throws Exception {
// ǰ�漸���趼һ��.ʡ��ע����
Document document = new SAXReader().read(file);
// ��ȡ���ڵ�
Element element = document.getRootElement();
// ��ȡҪ��ӵĽڵ����,,Ҳ���ǵڶ���p�ڵ�
Element ele = (Element) element.elements("p").get(1);
// ���һ������gender���ӱ�ǩ
Element newEle = ele.addElement("gender");
// Ϊ�±�ǩ����ı�
newEle.setText("��");
/**
*ע��,��д������,��ɾ����һ��Ҫ�ǵû�д*
*/
// �����ı���ʽ,��������
OutputFormat format = OutputFormat.createPrettyPrint();
// ����������
XMLWriter wr = new XMLWriter(new FileOutputStream(file), format);
// ���ڴ��е�Document��д���ļ���
wr.write(document);
// �ر���Դ
wr.close();
}
Aggregations