use of org.dom4j.io.OutputFormat in project jbosstools-hibernate by jbosstools.
the class ConfigurationXMLFactory method dump.
public static void dump(OutputStream os, Element element) {
// try to "pretty print" it
OutputFormat outformat = OutputFormat.createPrettyPrint();
try {
XMLWriter writer = new XMLWriter(os, outformat);
writer.write(element);
writer.flush();
} catch (IOException e1) {
// otherwise, just dump it
try {
os.write(element.asXML().getBytes());
} catch (IOException e) {
// ignore
}
}
}
use of org.dom4j.io.OutputFormat in project JFramework by gugumall.
the class JUtilDom4j method toString.
/**
* 将Document对象转换成指定编码的xml字符串
* @param doc
* @param encoding
* @return
* @throws Exception
*/
public static String toString(Document doc, String encoding) throws Exception {
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(encoding);
ByteArrayOutputStream byteOS = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(new OutputStreamWriter(byteOS, encoding), format);
writer.write(doc);
writer.flush();
writer.close();
return byteOS.toString(encoding);
}
use of org.dom4j.io.OutputFormat in project hibernate-orm by hibernate.
the class AdditionalJaxbMappingProducerImpl method produceAdditionalMappings.
@Override
public Collection<MappingDocument> produceAdditionalMappings(final MetadataImplementor metadata, IndexView jandexIndex, final MappingBinder mappingBinder, final MetadataBuildingContext buildingContext) {
final ServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
final EnversService enversService = serviceRegistry.getService(EnversService.class);
if (!enversService.isEnabled()) {
// short-circuit if envers integration has been disabled.
return Collections.emptyList();
}
final ArrayList<MappingDocument> additionalMappingDocuments = new ArrayList<>();
// atm we do not have distinct origin info for envers
final Origin origin = new Origin(SourceType.OTHER, "envers");
// final DOMWriter writer = new DOMWriter();
final MappingCollector mappingCollector = new MappingCollector() {
@Override
public void addDocument(Document document) throws DocumentException {
dump(document);
// while the commented-out code here is more efficient (well, understanding that
// this whole process is un-efficient) it leads to un-decipherable messages when
// we get mapping mapping errors from envers output.
// final DOMSource domSource = new DOMSource( writer.write( document ) );
// domSource.setSystemId( "envers" );
// final Binding jaxbBinding = mappingBinder.bind( domSource, origin );
// this form at least allows us to get better error messages
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
final Writer w = new BufferedWriter(new OutputStreamWriter(baos, "UTF-8"));
final XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
xw.write(document);
w.flush();
} catch (IOException e) {
throw new HibernateException("Unable to bind Envers-generated XML", e);
}
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
BufferedInputStream bis = new BufferedInputStream(bais);
final Binding jaxbBinding = mappingBinder.bind(bis, origin);
final JaxbHbmHibernateMapping jaxbRoot = (JaxbHbmHibernateMapping) jaxbBinding.getRoot();
additionalMappingDocuments.add(new MappingDocument(jaxbRoot, origin, buildingContext));
}
};
enversService.initialize(metadata, mappingCollector);
return additionalMappingDocuments;
}
use of org.dom4j.io.OutputFormat in project OpenOLAT by OpenOLAT.
the class QTIExportProcessor method addMetadata.
private void addMetadata(QuestionItemFull fullItem, String dir, ZipOutputStream zout) {
try {
Document document = DocumentHelper.createDocument();
Element qtimetadata = document.addElement("qtimetadata");
QTIMetadataConverter enricher = new QTIMetadataConverter(qtimetadata);
enricher.toXml(fullItem);
zout.putNextEntry(new ZipEntry(dir + "/" + "qitem_" + fullItem.getKey() + "_metadata.xml"));
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(zout, format);
writer.write(document);
} catch (IOException e) {
log.error("", e);
}
}
use of org.dom4j.io.OutputFormat in project OpenOLAT by OpenOLAT.
the class QTIImportProcessor method processAssessmentFiles.
protected void processAssessmentFiles(QuestionItemImpl item, ItemInfos itemInfos) {
// a package with an item
String dir = item.getDirectory();
String rootFilename = item.getRootFilename();
VFSContainer container = qpoolFileStorage.getContainer(dir);
VFSLeaf endFile = container.createChildLeaf(rootFilename);
// embed in <questestinterop>
DocumentFactory df = DocumentFactory.getInstance();
Document itemDoc = df.createDocument();
Element questestinteropEl = df.createElement(QTIDocument.DOCUMENT_ROOT);
itemDoc.setRootElement(questestinteropEl);
Element deepClone = (Element) itemInfos.getItemEl().clone();
questestinteropEl.add(deepClone);
// write
try {
OutputStream os = endFile.getOutputStream(false);
;
XMLWriter xw = new XMLWriter(os, new OutputFormat(" ", true));
xw.write(itemDoc.getRootElement());
xw.close();
os.close();
} catch (IOException e) {
log.error("", e);
}
// there perhaps some other materials
if (importedFilename.toLowerCase().endsWith(".zip")) {
processAssessmentMaterials(deepClone, container);
}
}
Aggregations