List of usage examples for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT
String JAXB_FORMATTED_OUTPUT
To view the source code for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT.
Click Source Link
From source file:eu.modaclouds.sla.mediator.Utils.java
public static <E> void print(E e, OutputStream os, Class<?>... classesToBeBound) throws JAXBException { JAXBContext jaxbContext;//from www. jav a 2s . com Marshaller jaxbMarshaller; jaxbContext = JAXBContext.newInstance(classesToBeBound); jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); /* * http://stackoverflow.com/a/22756191 */ jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); jaxbMarshaller.marshal(e, os); }
From source file:controller.JaxbUtil.java
public Marshaller createMarshaller(String encoding) { try {/*from w w w.j av a 2s .c o m*/ Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (StringUtils.isNotBlank(encoding)) { marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); } return marshaller; } catch (JAXBException ex) { throw new RuntimeException(ex); } }
From source file:com.healthcit.cacure.xforms.XModuleModel.java
public XModuleModel(Module module) { this.moduleRoot = module; try {/* w ww .j a v a2 s . com*/ JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.metadata.module"); jaxbMarshaller = jc.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); } catch (JAXBException e) { log.error("Error creating module metadata via jaxb", e); } }
From source file:io.onedecision.engine.decisions.impl.DecisionModelFactory.java
@Override public void write(Definitions dm, Writer out) throws IOException { JAXBContext context;//w w w. ja va 2s . com try { context = JAXBContext.newInstance(Definitions.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // Since no @XmlRootElement generated for Definitions need to create // element wrapper here. See // https://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html m.marshal(new JAXBElement<Definitions>(DEFINITIONS, Definitions.class, dm), out); } catch (JAXBException e) { throw new IOException(e.getMessage(), e); } }
From source file:main.java.refinement_class.Useful.java
public static void mashal(Object o, String xml_file, Class c) { Marshaller marshaller;/*from w w w. ja v a2 s.co m*/ // create a JAXBContext JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(c); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true)); marshaller.marshal(o, new FileOutputStream(xml_file)); } catch (JAXBException e) { e.printStackTrace(); LOG.error(e.toString()); } catch (FileNotFoundException e) { e.printStackTrace(); LOG.error(e.toString()); } }
From source file:grnet.com.entry.Actions.java
private void initRSSMarshaller() throws JAXBException { context = JAXBContext.newInstance(RSSRepo.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); }
From source file:org.cbio.portal.pipelines.foundation.FoundationXmlGeneratorTasklet.java
/** * Converts instance of ClientCaseInfoType to XML document. * /*from w ww . j a v a2s. c om*/ * @param clientCaseInfo */ private void writeFoundationXmlDocument(ClientCaseInfoType clientCaseInfo) { String xmlData = null; StringWriter sw = new StringWriter(); String outputFilename = outputDirectory + File.separator + cancerStudyIdentifier + "_merged.xml"; try { JAXBContext context = JAXBContext.newInstance(clientCaseInfo.getClass()); Marshaller jaxbMarshaller = context.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(clientCaseInfo, new File(outputFilename)); xmlData = sw.toString(); LOG.info("Merged Foundation XML document written to: " + outputFilename); } catch (JAXBException ex) { LOG.error("Error marshalling XML document from client case info object"); } }
From source file:de.tudarmstadt.ukp.integration.alignment.xml.AlignmentXmlWriter.java
public AlignmentXmlWriter(OutputStream out) throws IOException { try {//w w w.j av a2 s . c o m XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance(); xmlEventWriter = xmlOutputFactory.createXMLEventWriter(out); JAXBContext context = JAXBContext.newInstance(XmlMeta.class, Alignments.class); //Source.class marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); // no document level events marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); xmlef = XMLEventFactory.newInstance(); xmlEventWriter.add(xmlef.createStartDocument()); xmlEventWriter.add(xmlef.createStartElement("", "", RESOURCE_ALIGNMENT)); } catch (XMLStreamException e) { throw new IOException(e); } catch (JAXBException e) { throw new IOException(e); } }
From source file:eu.over9000.skadi.io.PersistenceHandler.java
public PersistenceHandler() { try {//from w w w .j av a 2 s . c o m final JAXBContext context = JAXBContext.newInstance(StateContainer.class); this.marshaller = context.createMarshaller(); this.unmarshaller = context.createUnmarshaller(); this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); } catch (final JAXBException e) { LOGGER.error("exception construction persistence handler", e); } }
From source file:com.evolveum.midpoint.cli.common.ToolsUtils.java
public static String serializeObject(Object object) throws JAXBException { if (object == null) { return null; }// w ww . j a v a2 s . c o m Marshaller marshaller = JAXB_CONTEXT.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); marshaller.marshal(object, sw); return sw.toString(); }