use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project ddf by codice.
the class CswRecordConverterTest method testMarshalRecord.
@Test
public void testMarshalRecord() throws IOException, JAXBException, SAXException, XpathException {
Metacard metacard = getTestMetacard();
StringWriter stringWriter = new StringWriter();
PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
MarshallingContext context = new TreeMarshaller(writer, null, null);
converter.marshal(metacard, writer, context);
String xml = stringWriter.toString();
assertThat(xml, containsString(CswConstants.CSW_RECORD));
assertRecordXml(xml, metacard, FULL);
}
use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project ddf by codice.
the class CswRecordConverterTest method testMarshalSummaryRecord.
@Test
public void testMarshalSummaryRecord() throws IOException, JAXBException, SAXException, XpathException {
Metacard metacard = getTestMetacard();
StringWriter stringWriter = new StringWriter();
PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
MarshallingContext context = new TreeMarshaller(writer, null, null);
context.put(CswConstants.ELEMENT_SET_TYPE, SUMMARY);
converter.marshal(metacard, writer, context);
String xml = stringWriter.toString();
assertThat(xml, containsString(CswConstants.CSW_SUMMARY_RECORD));
assertRecordXml(xml, metacard, SUMMARY);
}
use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project jgnash by ccavanaugh.
the class XMLContainer method writeXML.
/**
* Writes an XML file given a collection of StoredObjects. TrashObjects and
* objects marked for removal are not written. If the file already exists,
* it will be overwritten.
*
* @param objects Collection of StoredObjects to write
* @param path file to write
*/
static synchronized void writeXML(@NotNull final Collection<StoredObject> objects, @NotNull final Path path, @NotNull final DoubleConsumer percentCompleteConsumer) {
Logger logger = Logger.getLogger(XMLContainer.class.getName());
if (!Files.exists(path.getParent())) {
try {
Files.createDirectories(path.getParent());
logger.info("Created missing directories");
} catch (final IOException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
percentCompleteConsumer.accept(0);
createBackup(path);
List<StoredObject> list = new ArrayList<>();
list.addAll(query(objects, Budget.class));
list.addAll(query(objects, Config.class));
list.addAll(query(objects, CommodityNode.class));
list.addAll(query(objects, ExchangeRate.class));
list.addAll(query(objects, RootAccount.class));
list.addAll(query(objects, Reminder.class));
list.addAll(query(objects, Tag.class));
percentCompleteConsumer.accept(0.25);
// remove any objects marked for removal
list.removeIf(StoredObject::isMarkedForRemoval);
// sort the list
list.sort(new StoredObjectComparator());
percentCompleteConsumer.accept(0.5);
logger.info("Writing XML file");
try (final Writer writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
writer.write("<?fileFormat " + Engine.CURRENT_MAJOR_VERSION + "." + Engine.CURRENT_MINOR_VERSION + "?>\n");
final XStream xstream = configureXStream(new XStreamOut(new PureJavaReflectionProvider(), new StaxDriver()));
try (final ObjectOutputStream out = xstream.createObjectOutputStream(new PrettyPrintWriter(writer))) {
out.writeObject(list);
// forcibly flush before letting go of the resources to help older windows systems write correctly
out.flush();
} catch (final Exception e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
} catch (final IOException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
logger.info("Writing XML file complete");
percentCompleteConsumer.accept(1);
}
use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project Digital by hneemann.
the class Settings method attributeChanged.
@Override
public void attributeChanged() {
XStream xStream = Circuit.getxStream();
try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), "utf-8")) {
out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
xStream.marshal(attributes, new PrettyPrintWriter(out));
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.thoughtworks.xstream.io.xml.PrettyPrintWriter in project Digital by hneemann.
the class Resources method save.
void save(OutputStream out) throws IOException {
XStream xStream = getxStream();
try (Writer w = new OutputStreamWriter(out, "utf-8")) {
w.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
xStream.marshal(resourceMap, new PrettyPrintWriter(w));
}
}
Aggregations