List of usage examples for javax.xml.bind Marshaller JAXB_FRAGMENT
String JAXB_FRAGMENT
To view the source code for javax.xml.bind Marshaller JAXB_FRAGMENT.
Click Source Link
From source file:Main.java
/** * Return the xml translation of an object * /*from w ww . j a va2s.com*/ * @param cls * @param entity * @return */ public static String objectToXML(Class<?> cls, Object entity) { try { Marshaller m = JAXBContext.newInstance(cls).createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); StringWriter sw = new StringWriter(); m.marshal(entity, sw); return sw.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:de.hybris.platform.b2b.punchout.PunchOutUtils.java
public static void removeStandalone(final Marshaller marshaller) throws PropertyException { marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); }
From source file:Main.java
/** * Creates a {@link Marshaller} based on the given {@link JAXBContext} * and configures it to use the given {@link Charset}, and allows to * output the XML code to be generated formatted and as an XML fragment. * /*from w w w . j a v a 2s .c o m*/ * @param ctx the {@link JAXBContext} to create a {@link Marshaller} for * @param charset the {@link Charset} the XML code should be formatted * @param formatted {@code true} if the XML code should be formatted, * {@code false} otherwise * @param fragment {@code false} if the XML code should start with * {@code <?xml }, or {@code true} if just fragment XML code should * get generated * * @return a preconfigured {@link Marshaller} * * @throws IOException in case no {@link Marshaller} could get created */ public static Marshaller createMarshaller(JAXBContext ctx, Charset charset, boolean formatted, boolean fragment) throws IOException { if (charset == null) { return createMarshaller(ctx, Charset.defaultCharset(), formatted, fragment); } Objects.requireNonNull(ctx); try { Marshaller marshaller = ctx.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formatted); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, fragment); marshaller.setProperty(Marshaller.JAXB_ENCODING, charset.name()); return marshaller; } catch (JAXBException e) { throw new IOException(e); } }
From source file:com.evolveum.midpoint.cli.common.ToolsUtils.java
public static void serializeObject(Object object, Writer writer) throws JAXBException { if (object == null) { return;//www .java 2 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); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); if (object instanceof ObjectType) { object = new JAXBElement(C_OBJECT, Object.class, object); } marshaller.marshal(object, writer); }
From source file:eu.impress.impressplatform.IntegrationLayer.ResourcesMgmt.BedAvailabilityServiceBean.java
@Override public String getBedAvailablityHAVE(String hospitalname) { String hospitalstatushave;/*from www. j av a 2 s . c om*/ BedStats bedStats = bedService.getHospitalAvailableBeds(hospitalname); HospitalStatus hospitalStatus = beansTransformation.BedStatstoHAVE(bedStats); try { JAXBContext jaxbContext = JAXBContext.newInstance(HospitalStatus.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter sw = new StringWriter(); //marshal the envelope jaxbMarshaller.marshal(hospitalStatus, sw); hospitalstatushave = sw.toString(); } catch (JAXBException e) { e.printStackTrace(); return "Error Marshalling XML Object" + HttpStatus.INTERNAL_SERVER_ERROR; } return hospitalstatushave; }
From source file:com.consol.citrus.admin.marshal.SpringBeanMarshaller.java
public SpringBeanMarshaller() { setContextPaths("com.consol.citrus.admin.model.spring", "com.consol.citrus.model.config.core", "com.consol.citrus.model.config.jms", "com.consol.citrus.model.config.ws", "com.consol.citrus.model.config.websocket", "com.consol.citrus.model.config.mail", "com.consol.citrus.model.config.ssh", "com.consol.citrus.model.config.vertx", "com.consol.citrus.model.config.ftp", "com.consol.citrus.model.config.mail", "com.consol.citrus.model.config.docker", "com.consol.citrus.model.config.rmi", "com.consol.citrus.model.config.jmx", "com.consol.citrus.model.config.http"); Map<String, Object> marshallerProperties = new HashMap<>(); marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshallerProperties.put(Marshaller.JAXB_ENCODING, "UTF-8"); marshallerProperties.put(Marshaller.JAXB_FRAGMENT, true); marshallerProperties.put("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapper()); setMarshallerProperties(marshallerProperties); try {//from www. ja va 2s . co m afterPropertiesSet(); } catch (Exception e) { log.warn("Failed to setup configuration component marshaller", e); } }
From source file:StringAdapter.java
private void demo(String xml) throws JAXBException { StringReader stringReader = new StringReader(xml); Unmarshaller unmarshaller = jc.createUnmarshaller(); Root root = (Root) unmarshaller.unmarshal(stringReader); System.out.println("ITEM: " + root.getItem()); System.out.print("OUTPUT: "); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.marshal(root, System.out); }
From source file:eu.impress.repository.service.BedAvailabilityServiceImpl.java
@Override public String getBedAvailablityHAVE(String hospitalname) { String hospitalstatushave;/*ww w . ja v a2 s. com*/ BedStats bedStats = bedService.getHospitalAvailableBeds(hospitalname); HospitalStatus hospitalStatus = beansTransformation.BedStatstoHAVE(bedStats); try { JAXBContext jaxbContext = JAXBContext.newInstance(HospitalStatus.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter sw = new StringWriter(); //marshal the envelope jaxbMarshaller.marshal(hospitalStatus, sw); hospitalstatushave = sw.toString(); } catch (JAXBException e) { e.printStackTrace(); return "Error Marshalling XML Object"; } return hospitalstatushave; }
From source file:com.provenance.cloudprovenance.sconverter.PolicyResponseConverter.java
public String marhsallObject(PolicyResponse pResponse) { JAXBContext jaxbContext;/*from w w w.ja v a 2 s . c om*/ StringWriter sw = new StringWriter(); try { jaxbContext = JAXBContext.newInstance(instanceDir); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", cProvPrefixMapper); JAXBElement<PolicyResponse> el = pFactory.createPolicyResponse(pResponse); marshaller.marshal(el, sw); logger.info("Sucessfully marshalled the policy objects: " + el.getName()); } catch (JAXBException e) { e.printStackTrace(); } return sw.toString(); }
From source file:com.healthcit.cacure.xforms.XModuleModel.java
public XModuleModel(Module module) { this.moduleRoot = module; try {/* ww w . ja va2s. c o m*/ 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); } }