Java Examples for javax.xml.bind.Marshaller.JAXB_ENCODING
The following java examples will help you to understand the usage of javax.xml.bind.Marshaller.JAXB_ENCODING. These source code samples are taken from different open source projects.
Example 1
Project: gridrouter-master File: WithXmlView.java View source code |
default String toXml() {
try {
JAXBContext context = JAXBContext.newInstance(getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(JAXB_ENCODING, UTF_8.toString());
marshaller.setProperty(JAXB_FORMATTED_OUTPUT, true);
StringWriter writer = new StringWriter();
marshaller.marshal(this, writer);
return writer.toString();
} catch (JAXBException e) {
throw new GridRouterException("Unable to marshall bean", e);
}
}
Example 2
Project: mapsforge-platform-master File: OsmGpxImportServiceProvider.java View source code |
private void writeGPX(de.fub.maps.project.openstreetmap.xml.gpx.Gpx gpx) throws IOException, JAXBException {
OutputStream outputStream = null;
try {
if (gpx != null && gpx.getTrk() != null && !gpx.getTrk().isEmpty()) {
FileObject gpxFileObject = getGPXFile(getGPXFolder());
outputStream = gpxFileObject.getOutputStream();
javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(de.fub.maps.project.openstreetmap.xml.gpx.Gpx.class);
javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
//NOI18N
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(gpx, outputStream);
}
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
Example 3
Project: qalingo-engine-master File: MarshallerFactory.java View source code |
public Marshaller createMarshaller() throws Exception {
Marshaller marshaller = context.createMarshaller();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(xsdSources.toArray(new Source[0]));
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
marshaller.setSchema(schema);
return marshaller;
}
Example 4
Project: uPortal-master File: AbstractJaxbDataHandler.java View source code |
@Override
public void afterPropertiesSet() throws Exception {
final Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
properties.put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true);
if (this.schemaLocation != null) {
properties.put(javax.xml.bind.Marshaller.JAXB_SCHEMA_LOCATION, this.schemaLocation);
}
this.jaxb2Marshaller.setMarshallerProperties(properties);
this.jaxb2Marshaller.afterPropertiesSet();
}
Example 5
Project: surefire-master File: JAXB.java View source code |
@SuppressWarnings("unchecked")
public static <T> void marshal(T bean, Charset encoding, File destination) throws JAXBException, IOException {
Class<T> type = (Class<T>) bean.getClass();
JAXBElement<T> rootElement = buildJaxbElement(bean, type);
Class<?>[] classesToBeBound = { type };
JAXBContext context = newInstance(classesToBeBound);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(JAXB_ENCODING, encoding.name());
marshaller.setProperty(JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(JAXB_FRAGMENT, true);
marshaller.marshal(rootElement, destination);
}
Example 6
Project: glassfish-master File: DomainInfoManager.java View source code |
/**
* Parses template information file and uses its information to create
* domain info file.
*/
public void process(DomainTemplate domainTemplate, File domainDir) {
FileOutputStream outputStream = null;
try {
TemplateInfo templateInfo = domainTemplate.getInfo();
File infoDir = new File(domainDir, DomainConstants.INFO_DIRECTORY);
if (!infoDir.exists() && !infoDir.mkdirs()) {
_logger.log(Level.INFO, SLogger.DIR_CREATION_ERROR, infoDir.getAbsolutePath());
return;
}
File domainInfoXML = new File(infoDir, DomainConstants.DOMAIN_INFO_XML);
outputStream = new FileOutputStream(domainInfoXML);
ObjectFactory objFactory = new ObjectFactory();
DomainInfo domainInfo = objFactory.createDomainInfo();
String javaHome = System.getenv(JAVA_HOME);
if (javaHome == null || javaHome.isEmpty()) {
javaHome = System.getProperty("java.home");
}
domainInfo.setJavahome(javaHome);
domainInfo.setMwhome(System.getProperty(SystemPropertyConstants.PRODUCT_ROOT_PROPERTY));
TemplateRef templateRef = new TemplateRef();
templateRef.setName(templateInfo.getName());
templateRef.setVersion(templateInfo.getVersion());
templateRef.setLocation(domainTemplate.getLocation());
domainInfo.setDomainTemplateRef(templateRef);
JAXBContext context = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(objFactory.createDomainInfo(domainInfo), outputStream);
} catch (Exception e) {
LogHelper.log(_logger, Level.WARNING, SLogger.DOMAIN_INFO_CREATION_ERROR, e, DomainConstants.DOMAIN_INFO_XML);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (Exception io) {
}
}
}
}
Example 7
Project: cougar-master File: XMLMarshaller.java View source code |
@Override
public void marshall(final OutputStream outputStream, final Object result, String encoding, boolean client) {
XMLStreamWriter xmlWriter = null;
try {
xmlWriter = factory.createXMLStreamWriter(outputStream);
String resultPackage = result.getClass().getPackage().getName();
JAXBContext jc = getJAXBContext(resultPackage);
final javax.xml.bind.Marshaller marshaller = jc.createMarshaller();
if (encoding != null) {
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, encoding);
}
marshaller.marshal(result, xmlWriter);
} catch (final XMLStreamException e) {
throw CougarMarshallingException.marshallingException(getFormat(), "Failed to stream object to XML", e, client);
} catch (final JAXBException e) {
throw CougarMarshallingException.marshallingException(getFormat(), "Failed to marshal object to XML", e, client);
} finally {
if (xmlWriter != null) {
try {
xmlWriter.close();
} catch (final XMLStreamException ignored) {
}
}
}
}
Example 8
Project: spring-integration-samples-master File: RestHttpClientTest.java View source code |
@Before
public void setUp() {
responseExtractor = new HttpMessageConverterExtractor<EmployeeList>(EmployeeList.class, restTemplate.getMessageConverters());
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
properties.put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setMarshallerProperties(properties);
}
Example 9
Project: VocabularyTrainerSuite-master File: VocabularyXMLApi.java View source code |
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
lesson.setId("1");
lesson.setName("Alphabet");
ObjectFactory obFac = new ObjectFactory();
lesson.getContent().add(obFac.createLessonVocabulary(getVocabulary()));
// Code template start.
try {
javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(lesson.getClass().getPackage().getName());
javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
//NOI18N
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "lesson.xsd");
SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
marshaller.setSchema(sf.newSchema(new StreamSource(VocabularyXMLApi.class.getResourceAsStream("/lesson.xsd"))));
} catch (javax.xml.bind.JAXBException ex) {
ex.printStackTrace(System.err);
} catch (SAXException ex) {
ex.printStackTrace(System.err);
}
}
Example 10
Project: openbel-framework-experimental File: XBELConverter.java View source code |
/**
* Create a new JAXB {@link Marshaller} instance to handle conversion to
* XBEL.
*
* @return a new {@link Marshaller} instance
* @throws JAXBException Thrown if an error was encountered creating the
* JAXB {@link Marshaller}
* @throws PropertyException Thrown if an error was encountered setting
* properties on the {@link Marshaller}
*/
private Marshaller createNewMarshaller() throws JAXBException, PropertyException {
final Marshaller marshaller = ctxt.createMarshaller();
marshaller.setProperty(JAXB_ENCODING, UTF_8);
marshaller.setProperty(JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(JAXB_SCHEMA_LOCATION, XBELConstants.SCHEMA_URI + " " + XBELConstants.SCHEMA_URL);
return marshaller;
}
Example 11
Project: jubula.core-master File: JunitXMLWriter.java View source code |
/**
* Writes the generated content tree into a file provided by the
* generateFileForExport() function
*
* @param path targetpath for the file
*
* @throws JAXBException
* @throws IOException {@link JunitXMLWriter#generateFileForExport(String, String)}
* @throws UnsupportedEncodingException
*/
@Override
public void writeTestResult(String path, String filename) {
//Finds and adds the TestCases of the TestSuite elements, that were defined in
findTestcasesForTestsuite();
//Init of of JACBContext object
javax.xml.bind.JAXBContext jaxbCtx = null;
try {
//Setup
jaxbCtx = javax.xml.bind.JAXBContext.newInstance(m_project.getClass().getPackage().getName());
javax.xml.bind.Marshaller marshaller = null;
marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, CharEncoding.UTF_8);
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
//Execution of filling a file with information
marshaller.marshal(m_project, generateFileForExport(path, filename).getAbsoluteFile());
} catch (IOExceptionJAXBException | e) {
log.error("Exception while writing TestResults to file", e);
}
}