List of usage examples for javax.xml.bind Marshaller setProperty
public void setProperty(String name, Object value) throws PropertyException;
From source file:eu.hydrologis.jgrass.featureeditor.utils.Utilities.java
/** * Write the {@link AForm} to xml file.//from w w w . j a va 2 s. c o m * * @param form the {@link AForm} object. * @param file the file to which to dump to. * @throws Exception */ public static void writeXML(AForm form, File file) throws Exception { JAXBContext jc = JAXBContext.newInstance(AForm.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(form, file); }
From source file:Main.java
public static String jaxbToString(Class<?> xmlClass, JAXBElement<?> jaxbElement) { // Make sure we are given the correct input. if (xmlClass == null || jaxbElement == null) { return null; }//from ww w .j a v a2s. c o m // We will write the XML encoding into a string. StringWriter writer = new StringWriter(); String result; try { // We will use JAXB to marshal the java objects. final JAXBContext jaxbContext = JAXBContext.newInstance(xmlClass); // Marshal the object. Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(jaxbElement, writer); result = writer.toString(); } catch (Exception e) { // Something went wrong so get out of here. return null; } finally { try { writer.close(); } catch (IOException ex) { } } // Return the XML string. return result; }
From source file:com.technofovea.hl2parse.vdf.MaterialReader.java
public static final MaterialRefList loadFromXml(InputStream stream) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(MaterialReference.class, MaterialRefList.class); Unmarshaller um = jc.createUnmarshaller(); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Object o = um.unmarshal(stream); return (MaterialRefList) o; }
From source file:eu.planets_project.tb.impl.serialization.JaxbUtil.java
/** * Marshalling via Jaxb: Creates a String Serialization of the requested class for * the content of Object objectToSerialize. The provided object and the requested class need to be of the same Type * @param <T>/* w w w . java 2 s. c o m*/ * @param objectClass * @param objectToSerialize * @return * @throws Exception */ public static <T> String marshallObjectwithJAXB(Class<T> objectClass, T objectToSerialize) throws Exception { JAXBContext context; try { context = JAXBContext.newInstance(objectClass); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter sw = new StringWriter(); //now call the actual marshalling job m.marshal(objectToSerialize, sw); return sw.toString(); } catch (Exception e) { log.error("marshalWorkflowResult failed for objectClass: " + objectClass + " with " + e); throw e; } }
From source file:Main.java
/** * @param m//from w ww .j ava 2s. c o m * @param encoding * @return * @throws PropertyException */ private static Marshaller setMarshallerProperty(Marshaller m) throws PropertyException { m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // set Output charset to project's charset; m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); return m; }
From source file:com.biomeris.i2b2.export.ws.messages.MessageBuilder.java
public static String buildPMGetServiceRequest(Network network) throws JAXBException { com.biomeris.i2b2.export.datavo.pm.ObjectFactory pmObjectFactory = new com.biomeris.i2b2.export.datavo.pm.ObjectFactory(); com.biomeris.i2b2.export.ws.messages.extensions.ObjectFactory extObjectFactory = new com.biomeris.i2b2.export.ws.messages.extensions.ObjectFactory(); ProxyedRequestMessageType proxyedRequestMessageType = new ProxyedRequestMessageType(); Proxy proxy = new Proxy(); proxy.setRedirectUrl(network.getPmServiceAddress() + PMSERVICE_NAME); proxyedRequestMessageType.setProxy(proxy); MessageHeaderType messageHeaderType = new MessageHeaderType(); SecurityType securityType = new SecurityType(); securityType.setDomain(network.getDomain()); securityType.setUsername(network.getUsername()); PasswordType passwordType = JAXB.unmarshal(new StringReader(network.getPassword()), PasswordType.class); securityType.setPassword(passwordType); messageHeaderType.setSecurity(securityType); messageHeaderType.setProjectId(network.getProject()); ApplicationType applicationType = new ApplicationType(); applicationType.setApplicationName("Export Cell"); applicationType.setApplicationVersion("1.0"); messageHeaderType.setSendingApplication(applicationType); proxyedRequestMessageType.setMessageHeader(messageHeaderType); RequestHeaderType requestHeaderType = new RequestHeaderType(); requestHeaderType.setResultWaittimeMs(1800000); proxyedRequestMessageType.setRequestHeader(requestHeaderType); BodyType bodyType = new BodyType(); GetUserConfigurationType g = pmObjectFactory.createGetUserConfigurationType(); g.getProject().add("undefined"); JAXBElement<GetUserConfigurationType> any1 = pmObjectFactory.createGetUserConfiguration(g); bodyType.getAny().add(any1);/*from w w w.ja va 2s . c om*/ proxyedRequestMessageType.setMessageBody(bodyType); JAXBContext jc = JAXBContext.newInstance(ProxyedRequestMessageType.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter sw = new StringWriter(); JAXBElement<ProxyedRequestMessageType> xxx = extObjectFactory.createRequestPM(proxyedRequestMessageType); m.marshal(xxx, sw); return sw.toString(); }
From source file:Main.java
public static void saveInstance(OutputStream outputStream, Object instance) throws JAXBException, IOException { Marshaller marshaller = JAXBContext.newInstance(instance.getClass()).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, ENCODING); marshaller.marshal(instance, outputStream); outputStream.flush();/*from ww w.j ava 2 s . c o m*/ }
From source file:Main.java
public static void saveInstance(Writer output, Object instance) throws JAXBException, IOException { Marshaller marshaller = JAXBContext.newInstance(instance.getClass()).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, ENCODING); marshaller.marshal(instance, output); output.flush();// ww w . j ava2s . c om }
From source file:net.orpiske.sas.commons.xml.XmlWriterUtils.java
/** * Marshals an object into a formatted XML document * @param element the JAXB element object that represents an 'object' of * type T//from ww w . j a v a2 s . c o m * @param object the object to be transformed into XML * @param writer the writer object * @throws JAXBException if unable to transform the object to XML */ public static <T> void marshal(JAXBElement<T> element, T object, Writer writer) throws JAXBException { JAXBContext context = JAXBContext.newInstance(object.getClass().getPackage().getName()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(element, writer); }
From source file:net.orpiske.sas.commons.xml.XmlWriterUtils.java
/** * Marshals an object into a formatted XML document * @param element the JAXB element object that represents an 'object' of * type T// w w w . j a va2 s. co m * @param object the object to be transformed into XML * @param stream the output stream * @throws JAXBException if unable to transform the object to XML */ public static <T> void marshal(JAXBElement<T> element, T object, OutputStream stream) throws JAXBException { JAXBContext context = JAXBContext.newInstance(object.getClass().getPackage().getName()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(element, stream); }