List of usage examples for javax.xml.bind Marshaller setProperty
public void setProperty(String name, Object value) throws PropertyException;
From source file:com.bluexml.side.build.tools.reader.MavenProjectReader.java
/** * @return//from w ww . ja v a2s.c om * @throws JAXBException * @throws PropertyException */ private static Unmarshaller getUnmarshaller(String packageName) throws JAXBException, PropertyException { JAXBContext jaxbContext = JAXBContext.newInstance(packageName); Marshaller alfrescoMarshaller = jaxbContext.createMarshaller(); alfrescoMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); alfrescoMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); Unmarshaller alfrescoUnmarshaller = jaxbContext.createUnmarshaller(); return alfrescoUnmarshaller; }
From source file:cz.lbenda.dataman.rc.DbConfigFactory.java
public static String storeStructureCache(DbConfig dbConfig) { cz.lbenda.dataman.schema.dbstructure.ObjectFactory of = new cz.lbenda.dataman.schema.dbstructure.ObjectFactory(); try {//from www . j a va2 s . co m JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dbstructure.ObjectFactory.class); Marshaller m = jc.createMarshaller(); StringWriter sw = new StringWriter(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); DatabaseStructureType dst = DbStructureFactory.createXMLDatabaseStructure(dbConfig.getCatalogs()); JAXBElement<DatabaseStructureType> element = of.createDatabaseType(dst); m.marshal(element, sw); return sw.toString(); } catch (JAXBException e) { LOG.error("Problem with write configuration: " + e.toString(), e); throw new RuntimeException("Problem with write configuration: " + e.toString(), e); } }
From source file:com.faceye.feature.util.JaxbMapper.java
/** * Marshallerencoding(?null).// www . j a v a2s. 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); } // marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, ""); // marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, ""); // marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapper() { // @Override // public String[] getPreDeclaredNamespaceUris() { // return new String[] { WellKnownNamespace.XML_SCHEMA_INSTANCE }; // } // // @Override // public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) { // if (namespaceUri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE)) // return "xsi"; // if (namespaceUri.equals(WellKnownNamespace.XML_SCHEMA)) // return "xs"; // if (namespaceUri.equals(WellKnownNamespace.XML_MIME_URI)) // return "xmime"; // return suggestion; // // } // }); return marshaller; } catch (JAXBException e) { logger.error(">>FaceYe form xml 2 class exception:", e); throw Exceptions.unchecked(e); } }
From source file:cz.lbenda.dataman.rc.DbConfigFactory.java
public static String storeToString(Callback<DbConfig, String> cacheDbStructureWriteFactory) { cz.lbenda.dataman.schema.dataman.ObjectFactory of = new cz.lbenda.dataman.schema.dataman.ObjectFactory(); DatamanType config = of.createDatamanType(); config.setSessions(of.createSessionsType()); for (DbConfig sc : getConfigurations()) { config.getSessions().getSession() .add(sc.storeToSessionType(null, cacheDbStructureWriteFactory.call(sc))); }// www . jav a 2s . c om try { JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dataman.ObjectFactory.class); Marshaller m = jc.createMarshaller(); StringWriter sw = new StringWriter(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(of.createDataman(config), sw); return sw.toString(); } catch (JAXBException e) { LOG.error("Problem with write configuration: " + e.toString(), e); throw new RuntimeException("Problem with write configuration: " + e.toString(), e); } }
From source file:Main.java
public static void Object2XmlFile(Object ob, String path) throws JAXBException, FileNotFoundException { Class local = ob.getClass();/* ww w .jav a2 s . com*/ JAXBContext context = JAXBContext.newInstance(new Class[] { local }); Marshaller marshaller = context.createMarshaller(); // marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", // paramNamespacePrefixMapper); // marshaller.setProperty("jaxb.formatted.output", // Boolean.valueOf(true)); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(ob, new FileOutputStream(new File(path))); }
From source file:com.sarm.lonelyplanet.process.DestinationProcessorTest.java
/** * This method is not a JUnit test method. This is used to create an XML * file of 30000 destinations and to regressively test the UnMarshalling * technique used in the LPUnMarshaller. This is called by the test method : * testProcessDestinationByStAXfor30000 to test the 30000 destinations. * * @param destinationFileName/*from w w w . j a v a 2 s . c om*/ * @throws JAXBException * @throws FileNotFoundException * @throws XMLStreamException * @throws UnsupportedEncodingException */ public static void testMarshall(String destinationFileName) throws JAXBException, FileNotFoundException, XMLStreamException, UnsupportedEncodingException { DestinationProcessor destinationProcessor = new DestinationProcessor(); List<Destination> destinations = destinationProcessor.processDestinationByStAX(destinationFileName); List<Destination> tempDestinations = new ArrayList<>(); for (int i = 0; i < 1500; i++) { for (Destination destination : destinations) { Destination temp = new Destination(); temp = destination.clone(); temp.setTitle(temp.getTitle() + i); tempDestinations.add(temp); } } Destinations destinationList = new Destinations(); destinationList.setDestinations(tempDestinations); logger.info(" destinationList " + destinationList.getDestinations().size()); JAXBContext jc = JAXBContext.newInstance(Destinations.class); logger.debug(jc.getClass()); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(destinationList, new File(regressDestinationfile)); logger.info("Successfully created regressDestinationfile " + regressDestinationfile); }
From source file:cool.pandora.modeller.DocManifestBuilder.java
/** * marshal.//from ww w . j a v a 2s . c o m * * @param hocr File * @return hocr * @throws JAXBException Exception */ private static ByteArrayOutputStream marshal(final File hocr) throws JAXBException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final JAXBContext jaxbContext = JAXBContext.newInstance(File.class); final Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(hocr, out); return out; }
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);/*w w w . jav a 2 s . co m*/ 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:br.ufpb.dicomflow.integrationAPI.tools.ReadService.java
private static void saveMessages(List<MessageIF> messages, File destDir) throws JAXBException, IOException { Iterator<MessageIF> it = messages.iterator(); while (it.hasNext()) { MessageIF messageIF = (MessageIF) it.next(); ServiceIF service = messageIF.getService(); Logger.v(rb.getString("loaded-service") + service.getName() + " - " + service.getAction() + " - " + service.getMessageID()); JAXBContext jaxbContext = JAXBContext.newInstance(messageIF.getService().getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); FileOutputStream fos = new FileOutputStream(destDir.getAbsolutePath() + File.pathSeparator + service.getName() + "_" + service.getAction() + "_" + service.getMessageID()); jaxbMarshaller.marshal(messageIF.getService(), fos); if (messageIF.getAttach() != null && messageIF.getAttach().length > 0) { fos = new FileOutputStream(destDir.getAbsolutePath() + File.pathSeparator + service.getName() + "_" + service.getAction() + "_" + service.getMessageID() + "_attach"); fos.write(messageIF.getAttach()); fos.close();// w w w . j a va 2s . c o m } } }
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 w ww .ja v a 2 s . c o m*/ 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); }