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.seaclouds.platform.planner.core.application.agreements.AgreementGenerator.java
private static String serializeToXml(MonitoringInfo monitoringInfo) { StringWriter sw = new StringWriter(); JAXBContext jaxbContext;/* ww w . ja va 2 s. co m*/ String marshalledMonitoringRules = null; try { jaxbContext = JAXBContext.newInstance(MonitoringRules.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); jaxbMarshaller.marshal(monitoringInfo.getApplicationMonitoringRules(), sw); marshalledMonitoringRules = sw.toString(); } catch (JAXBException e) { log.error("Monitoring rules {} can not be marshalled by addSeaCloudsPolicy in " + "DamGenerator", monitoringInfo.getApplicationMonitoringRules()); } return marshalledMonitoringRules; }
From source file:com.topsem.common.mapper.JaxbMapper.java
/** * Marshallerencoding(?null).//from ww w.j av a 2s.c om * ???pooling */ public static Marshaller createMarshaller(Class clazz, String encoding) { try { JAXBContext jaxbContext = getJaxbContext(clazz); 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 e) { throw Throwables.propagate(e); } }
From source file:com.wsun.seap.common.mapper.JaxbMapper.java
/** * Marshallerencoding(?null)./*from ww w. j ava 2 s . c o m*/ * ???pooling */ public static Marshaller createMarshaller(Class clazz, String encoding) { try { JAXBContext jaxbContext = getJaxbContext(clazz); 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 e) { throw ExceptionUtil.unchecked(e); } }
From source file:eu.planets_project.tb.impl.serialization.ExperimentViaJAXB.java
/** * @param exp/*from w w w . ja v a2 s .co m*/ * @param out */ private static void writeToOutputStream(ExperimentImpl exp, OutputStream out) { try { JAXBContext jc = JAXBContext.newInstance(PACKAGE_CONTEXT); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(exp, out); } catch (JAXBException e) { log.fatal("Writing Experiment to XML failed: " + e); } }
From source file:cn.newtouch.util.utils.encode.JaxbBinder.java
/** * Marshaller, encoding(?Null)./*from ww w . j av a 2 s . c om*/ */ public Marshaller createMarshaller(String encoding) { try { 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 e) { throw new RuntimeException(e); } }
From source file:org.biopax.validator.api.ValidatorUtils.java
/** * Gets the results Marshaller (for validation results.) * @return/* w ww . j av a2 s . c o m*/ */ public static Marshaller getMarshaller() { //return resultsMarshaller; try { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); return marshaller; } catch (JAXBException e) { throw new RuntimeException("Failed to create Marshaller", e); } }
From source file:main.java.refinement_class.Useful.java
public static String mashal2(Object o, Class c) { Marshaller marshaller;/* w w w.j a v a 2 s . c o m*/ // create a JAXBContext JAXBContext jaxbContext; String xmlString = ""; try { jaxbContext = JAXBContext.newInstance(c); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true)); // marshaller.marshal(o, new FileOutputStream(xml_file)); StringWriter sw = new StringWriter(); marshaller.marshal(o, sw); xmlString = sw.toString(); } catch (JAXBException e) { e.printStackTrace(); } return xmlString; }
From source file:net.firejack.platform.core.utils.FileUtils.java
public static <T> void writeJAXB(T obj, OutputStream stream, Class... classes) throws IOException, JAXBException { OutputFormat outputFormat = new OutputFormat(); outputFormat.setCDataElements(new String[] { CDATA_DESCRIPTION }); outputFormat.setIndenting(true);//from w w w . j a v a 2 s.c om XMLSerializer serializer = new XMLSerializer(outputFormat); serializer.setOutputByteStream(stream); if (classes.length == 0) { classes = (Class[]) ArrayUtils.add(classes, obj.getClass()); } JAXBContext jaxbContext = JAXBContext.newInstance(classes); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(obj, serializer.asContentHandler()); }
From source file:net.sourceforge.subsonic.controller.JAXBWriter.java
private Marshaller createJsonMarshaller() throws JAXBException { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, StringUtil.ENCODING_UTF8); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); return marshaller; }
From source file:com.healthcit.cacure.web.controller.ModuleImportExportController.java
@RequestMapping(method = RequestMethod.GET) public void exportModule(@RequestParam(value = "moduleId", required = true) long id, @RequestParam(value = "format", required = true) String format, HttpServletResponse response) { try {// www .j a va2 s .c o m response.setContentType("text/xml"); OutputStream oStream = response.getOutputStream(); Cure cureXml = dataExporter.constructModuleXML(id); JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model"); if (ExportFormat.XML.name().equals(format)) { String fileNameHeader = String.format("attachment; filename=form-%d.xml;", id); response.setHeader("Content-Disposition", fileNameHeader); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(cureXml, oStream); } else if (ExportFormat.EXCEL.name().equals(format)) { String fileNameHeader = String.format("attachment; filename=form-%d.xlxml;", id); response.setHeader("Content-Disposition", fileNameHeader); response.setContentType("application/xml"); StreamSource xslSource = new StreamSource(this.getClass().getClassLoader() .getResourceAsStream(AppConfig.getString(Constants.EXPORT_EXCEL_XSLT_FILE))); JAXBSource xmlSource = new JAXBSource(jc, cureXml); Transformer transformer = TransformerFactory.newInstance().newTransformer(xslSource); transformer.transform(xmlSource, new StreamResult(oStream)); } oStream.flush(); } catch (IOException e) { log.error("Unable to obtain output stream from the response"); log.error(e.getMessage(), e); } catch (JAXBException e) { log.error("Unable to marshal the object"); log.error(e.getMessage(), e); } catch (TransformerException e) { log.error("XSLT transformation failed"); log.error(e.getMessage(), e); } }