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:ch.algotrader.service.ib.IBFixAllocationServiceImpl.java
private String marshal(final GroupMap groups) { try {//w ww.j a va 2s . co m JAXBContext context = JAXBContext.newInstance(GroupMap.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter writer = new StringWriter(); m.marshal(groups, writer); return writer.toString(); } catch (JAXBException ex) { throw new ExternalServiceException(ex); } }
From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java
public static Marshaller getMarshaller(Class... docClass) throws JAXBException { JAXBContext context = JAXBContext.newInstance(docClass); Marshaller m = context.createMarshaller(); m.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, Boolean.TRUE); return m;/*from w w w.j a v a2s . co m*/ }
From source file:ddf.security.pdp.xacml.processor.BalanaPdp.java
/** * Marshalls the XACML request to a string. * //w w w . j a va 2 s .c o m * @param xacmlRequestType * The XACML request to marshal. * @return A string representation of the XACML request. */ private String marshal(RequestType xacmlRequestType) throws PdpException { ObjectFactory objectFactory = new ObjectFactory(); Writer writer = new StringWriter(); JAXBElement<RequestType> xacmlRequestTypeElement = objectFactory.createRequest(xacmlRequestType); Marshaller marshaller = null; String xacmlRequest = null; try { marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(xacmlRequestTypeElement, writer); xacmlRequest = writer.toString(); } catch (JAXBException e) { String message = "Unable to marshal XACML request."; LOGGER.error(message); throw new PdpException(message, e); } LOGGER.debug("\nXACML 3.0 Request:\n{}", xacmlRequest); return xacmlRequest; }
From source file:carisma.ui.eclipse.CarismaGUI.java
public final static void saveXml(final AnalysisResult analysisResult) { IContainer container = analysisResult.getAnalysis().getIFile().getParent(); IFile file = null;//from w ww .j a va 2 s . co m if (container instanceof IFolder) { IFolder folder = (IFolder) container; file = folder.getFile( "xml-output-" + analysisResult.getName() + "-" + analysisResult.getTimestamp() + ".xml"); } else if (container instanceof IProject) { IProject project = (IProject) container; file = project.getFile( "xml-output-" + analysisResult.getName() + "-" + analysisResult.getTimestamp() + ".xml"); } else { Logger.log(LogLevel.ERROR, "Analyzed file is not part of a project."); return; } if (!(file.exists())) { try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { JAXBContext context = JAXBContext.newInstance(carisma.core.analysis.result.AnalysisResult.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.marshal(analysisResult, out); String store = new String(out.toByteArray(), StandardCharsets.UTF_8); InputStream is = new ByteArrayInputStream(store.getBytes(StandardCharsets.UTF_8)); // file.create(Utils.createInputStreamFromString(store), true, // null); file.create(is, true, null); // JSONObject fromXml = XML.toJSONObject(store); // String jsonPrint = fromXml.toString(1); // System.out.println(jsonPrint); // carisma.core.analysis.result.exp.dbexport.exportXml(jsonPrint); out.close(); } catch (Exception e) { System.out.println(e.getMessage()); } } }
From source file:com.jkoolcloud.tnt4j.streams.utils.StreamsCache.java
private static void persist(Map<String, CacheValue> cacheEntries) { try {//from w w w .j a v a2 s.c o m JAXBContext jc = JAXBContext.newInstance(CacheRoot.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); CacheRoot root = new CacheRoot(); root.setEntriesMap(cacheEntries); File persistedFile = new File(DEFAULT_FILE_NAME); LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "StreamsCache.persisting.file", persistedFile.getAbsolutePath()); marshaller.marshal(root, persistedFile); LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "StreamsCache.persisting.done", cacheEntries.size(), persistedFile.getAbsolutePath()); } catch (JAXBException exc) { Utils.logThrowable(LOGGER, OpLevel.ERROR, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "StreamsCache.persisting.failed", exc); } }
From source file:net.di2e.ecdr.commons.endpoint.rest.AbstractRestSearchEndpoint.java
@GET @Path("/osd.xml") @Produces("application/opensearchdescription+xml") public Response getOSD() { OpenSearchDescription osd = new OpenSearchDescription(); osd.setShortName(SystemInfo.getSiteName()); osd.setDescription(getServiceDescription()); osd.setTags("ecdr opensearch cdr ddf"); if (StringUtils.isNotBlank(SystemInfo.getOrganization())) { osd.setDeveloper(SystemInfo.getOrganization()); }/*from w ww . ja v a2 s . com*/ if (StringUtils.isNotBlank(SystemInfo.getSiteContatct())) { osd.setContact(SystemInfo.getSiteContatct()); } Query query = new Query(); query.setRole("example"); query.setSearchTerms("test"); osd.getQuery().add(query); osd.setSyndicationRight(SyndicationRight.OPEN); osd.getLanguage().add(MediaType.MEDIA_TYPE_WILDCARD); osd.getInputEncoding().add(StandardCharsets.UTF_8.name()); osd.getOutputEncoding().add(StandardCharsets.UTF_8.name()); // url example for (QueryLanguage lang : queryLanguageList) { Url url = new Url(); url.setType(MediaType.APPLICATION_ATOM_XML); url.setTemplate(generateTemplateUrl(lang)); osd.getUrl().add(url); } addSourceDescriptions(osd); StringWriter writer = new StringWriter(); InputStream is = null; try { JAXBContext context = JAXBContext.newInstance(OpenSearchDescription.class, SourceDescription.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.marshal(osd, writer); is = getClass().getResourceAsStream("/templates/osd_info.template"); if (is != null) { String osdTemplate = IOUtils.toString(is); osdTemplate = replaceTemplateValues(osdTemplate); String responseStr = osdTemplate + writer.toString(); return Response.ok(responseStr, MediaType.APPLICATION_XML_TYPE).build(); } else { return Response.serverError().entity("COULD NOT LOAD OSD TEMPLATE.").build(); } } catch (JAXBException | IOException e) { LOGGER.warn("Could not create OSD for client due to exception.", e); return Response.serverError().build(); } finally { IOUtils.closeQuietly(is); } }
From source file:com.silverpeas.admin.components.Instanciateur.java
public static void saveComponent(WAComponent waComponent, String fileName, boolean workflow) throws JAXBException { JAXBContext context = JAXBContext.newInstance("com.silverpeas.admin.components"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://silverpeas.org/xml/ns/component http://www.silverpeas.org/xsd/component.xsd"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); String path = getXMLPackage() + File.separatorChar; if (workflow) { path += "workflows" + File.separatorChar; }//from ww w .ja v a 2 s . co m File file = new File(path + fileName); marshaller.marshal(objectFactory.createWAComponent(waComponent), file); }
From source file:eu.eco2clouds.scheduler.accounting.client.AccountingClientHC.java
@Override public Experiment createExperiment(Experiment experiment) { Boolean exception = false;//from w ww .ja va 2 s.c o m String experimentUrl = url + "/experiments/"; logger.debug("URL build: " + experimentUrl); try { JAXBContext jaxbContext = JAXBContext.newInstance(Experiment.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.marshal(experiment, out); String payload = out.toString(); String response = postMethod(experimentUrl, payload, experiment.getBonfireUserId(), experiment.getBonfireGroupId(), exception); logger.debug("PAYLOAD: " + response); try { jaxbContext = JAXBContext.newInstance(Experiment.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); experiment = (Experiment) jaxbUnmarshaller.unmarshal(new StringReader(response)); } catch (JAXBException e) { logger.warn("Error trying incoming experiment to object. Exception: " + e.getMessage()); exception = true; } } catch (JAXBException e) { logger.warn("Error trying to parse returned experiment from database: " + url + "/experiments" + " Exception: " + e.getMessage()); exception = true; } if (exception) return new Experiment(); return experiment; }
From source file:com.esri.geoevent.test.performance.ui.OrchestratorController.java
/** * Saves the current fixtures file to disk. * * @param file File where to save the configuration file. * @throws JAXBException//from ww w.ja v a 2 s.co m * @throws XMLStreamException * @throws IOException */ private void saveFile(File file) throws JAXBException, XMLStreamException, IOException { JAXBContext jaxbContext = JAXBContext.newInstance(Fixtures.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); FileWriter fileWriter = new FileWriter(file); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter xmlWritter = factory.createXMLStreamWriter(fileWriter); marshaller.marshal(fixtures, xmlWritter); fileWriter.flush(); fileWriter.close(); }
From source file:com.moss.veracity.core.data.PersistenceManager.java
private void write(Object o, DatabaseEntry entry) throws JAXBException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(o, out);/*from w ww . j a va2 s . com*/ entry.setData(out.toByteArray()); }