List of usage examples for javax.xml.bind Marshaller JAXB_ENCODING
String JAXB_ENCODING
To view the source code for javax.xml.bind Marshaller JAXB_ENCODING.
Click Source Link
From source file:org.finra.herd.tools.common.databridge.DataBridgeWebClient.java
/** * Updates the business object data status. * * @param businessObjectDataKey the business object data key * @param businessObjectDataStatus the status of the business object data * * @return {@link org.finra.herd.model.api.xml.BusinessObjectDataStatusUpdateResponse} * @throws URISyntaxException if error occurs while URI creation * @throws IOException if error occurs communicating with server * @throws JAXBException if error occurs parsing the XML * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception *//*from w w w .jav a 2s .c o m*/ public BusinessObjectDataStatusUpdateResponse updateBusinessObjectDataStatus( BusinessObjectDataKey businessObjectDataKey, String businessObjectDataStatus) throws URISyntaxException, IOException, JAXBException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { BusinessObjectDataStatusUpdateRequest request = new BusinessObjectDataStatusUpdateRequest(); request.setStatus(businessObjectDataStatus); // Create a JAXB context and marshaller JAXBContext requestContext = JAXBContext.newInstance(BusinessObjectDataStatusUpdateRequest.class); Marshaller requestMarshaller = requestContext.createMarshaller(); requestMarshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); requestMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); requestMarshaller.marshal(request, sw); BusinessObjectDataStatusUpdateResponse businessObjectDataStatusUpdateResponse; try (CloseableHttpClient client = httpClientHelper.createHttpClient( regServerAccessParamsDto.isTrustSelfSignedCertificate(), regServerAccessParamsDto.isDisableHostnameVerification())) { StringBuilder uriPathBuilder = new StringBuilder(300); uriPathBuilder.append(HERD_APP_REST_URI_PREFIX + "/businessObjectDataStatus/namespaces/") .append(businessObjectDataKey.getNamespace()); uriPathBuilder.append("/businessObjectDefinitionNames/") .append(businessObjectDataKey.getBusinessObjectDefinitionName()); uriPathBuilder.append("/businessObjectFormatUsages/") .append(businessObjectDataKey.getBusinessObjectFormatUsage()); uriPathBuilder.append("/businessObjectFormatFileTypes/") .append(businessObjectDataKey.getBusinessObjectFormatFileType()); uriPathBuilder.append("/businessObjectFormatVersions/") .append(businessObjectDataKey.getBusinessObjectFormatVersion()); uriPathBuilder.append("/partitionValues/").append(businessObjectDataKey.getPartitionValue()); for (int i = 0; i < org.apache.commons.collections4.CollectionUtils .size(businessObjectDataKey.getSubPartitionValues()) && i < BusinessObjectDataEntity.MAX_SUBPARTITIONS; i++) { uriPathBuilder.append("/subPartition").append(i + 1).append("Values/") .append(businessObjectDataKey.getSubPartitionValues().get(i)); } uriPathBuilder.append("/businessObjectDataVersions/") .append(businessObjectDataKey.getBusinessObjectDataVersion()); URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme()) .setHost(regServerAccessParamsDto.getRegServerHost()) .setPort(regServerAccessParamsDto.getRegServerPort()).setPath(uriPathBuilder.toString()); HttpPut httpPut = new HttpPut(uriBuilder.build()); httpPut.addHeader("Content-Type", DEFAULT_CONTENT_TYPE); httpPut.addHeader("Accepts", DEFAULT_ACCEPT); if (regServerAccessParamsDto.isUseSsl()) { httpPut.addHeader(getAuthorizationHeader()); } httpPut.setEntity(new StringEntity(sw.toString())); LOGGER.info(String.format(" HTTP POST URI: %s", httpPut.getURI().toString())); LOGGER.info(String.format(" HTTP POST Headers: %s", Arrays.toString(httpPut.getAllHeaders()))); LOGGER.info(String.format(" HTTP POST Entity Content:%n%s", sw.toString())); businessObjectDataStatusUpdateResponse = getBusinessObjectDataStatusUpdateResponse( httpClientOperations.execute(client, httpPut)); } LOGGER.info("Successfully updated status of the business object data."); return businessObjectDataStatusUpdateResponse; }
From source file:org.fosstrak.epcis.repository.query.QuerySubscription.java
/** * Marshals the given EPCIS query document into it's XML representation. * //from w ww .jav a2 s . c om * @param epcisDoc * The EPCISQueryDocumentType to marshal. * @return The marshaled EPCISQueryDocumentType XML String. */ private String marshalQueryDoc(EPCISQueryDocumentType epcisDoc) throws JAXBException { ObjectFactory objectFactory = new ObjectFactory(); JAXBContext context = JAXBContext.newInstance("org.fosstrak.epcis.model"); JAXBElement<EPCISQueryDocumentType> item = objectFactory.createEPCISQueryDocument(epcisDoc); LOG.debug("Serializing " + item + " into XML"); StringWriter writer = new StringWriter(); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(item, writer); return writer.toString(); }
From source file:org.geosdi.geoplatform.connector.jaxb.pool.factory.GPMarshallerFactory.java
@Override public Marshaller makeObject() throws Exception { Marshaller marshaller = this.jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); return marshaller; }
From source file:org.geosdi.geoplatform.jaxb.pool.factory.GPMarshallerFactory.java
@Override public Marshaller create() throws Exception { Marshaller marshaller = this.jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); return marshaller; }
From source file:org.intermine.modelviewer.jaxb.ConfigParser.java
/** * Marshalls an object of the given context to the given writer. * <p>All sorts of niceties regarding schema locations, name spaces and so forth * are set up to embellish the output and make is as correct as possible.</p> * /*from www.ja v a 2 s. c o m*/ * @param context The type of object being written. * @param object The object to marshall. * @param out The writer to marshall to. * * @throws JAXBException if JAXB marshalling fails. * @throws XMLStreamException if there is a problem with lower level XML streaming. * * @see KnownNamespacePrefixMatcher */ protected void writeFileJaxb(Context context, Object object, Writer out) throws JAXBException, XMLStreamException { String namespace = namespaces.get(context); StringBuilder schemaLocations = new StringBuilder(); /* switch (context) { case CORE: case GENOMIC: schemaLocations.append(GENOMIC_CORE_NAMESPACE).append(' '); schemaLocations.append(GENOMIC_CORE_URL).append(' '); break; } */ schemaLocations.append(namespace).append(' ').append(xsdUrls.get(context)); /* XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(out); xmlStreamWriter.setPrefix("gc", GENOMIC_CORE_NAMESPACE); xmlStreamWriter.setPrefix("core", CORE_NAMESPACE); xmlStreamWriter.setPrefix("genomic", GENOMIC_NAMESPACE); xmlStreamWriter.setPrefix("project", PROJECT_NAMESPACE); //xmlStreamWriter.setDefaultNamespace(namespace); xmlStreamWriter = new IndentingXMLStreamWriter(xmlStreamWriter); */ Marshaller marshall = jaxbContexts.get(context).createMarshaller(); //marshall.setSchema(schemas.get(context)); marshall.setProperty(PREFIX_MAPPER_PROPERTY, new KnownNamespacePrefixMatcher()); marshall.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshall.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocations.toString()); marshall.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //marshall.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, xsdUrls.get(context)); //marshall.marshal(object, xmlStreamWriter); marshall.marshal(object, out); }
From source file:org.jboss.jopr.tool.jbas5.PluginDescriptorGenerator.java
private static void writeToFile(PluginDescriptor pluginDescriptor, File file) throws Exception { LOG.info("Writing plugin descriptor to [" + file + "]..."); OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); try {/*from w ww . jav a2 s . com*/ JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new RhqNamespacePrefixMapper()); marshaller.marshal(pluginDescriptor, outputStream); } finally { outputStream.close(); } }
From source file:org.kalypso.mapserver.utils.MapFileUtilities.java
/** * This function saves a map file as XML. * * @param map/* www . j a va2 s .c o m*/ * The contents of the map file. * @param outputStream * The output stream. * @param encoding * The encoding. */ public static void saveAsXML(final Map map, final OutputStream outputStream, final String encoding) throws JAXBException { /* Create the marshaller. */ final Marshaller marshaller = JC.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new MapFileNamespacePrefixMapper()); //$NON-NLS-1$ marshaller.marshal(map, outputStream); }
From source file:org.kalypso.mapserver.utils.MapFileUtilities.java
/** * This function saves a map file in ASCII. * * @param map/* ww w . j ava 2 s . com*/ * The contents of the map file. * @param outputStream * The output stream. * @param encoding * The encoding. */ public static void saveInASCII(final Map map, final OutputStream outputStream, final String encoding) throws ParserConfigurationException, JAXBException, SAXException, IOException, TransformerException { /* the input stream. */ InputStream inputStream = null; try { /* Create the document builder factory. */ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); /* Create the document builder. */ final DocumentBuilder builder = factory.newDocumentBuilder(); /* Create a XML document. */ final Document xmlDOM = builder.newDocument(); /* Create the marshaller. */ final Marshaller marshaller = JC.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new MapFileNamespacePrefixMapper()); //$NON-NLS-1$ /* Marshal the contents of the map file into the XML document. */ marshaller.marshal(map, xmlDOM); /* Load the XLS document. */ inputStream = XSL_URL.openStream(); final Document xslDOM = builder.parse(inputStream); /* Create the transformer factory. */ final TransformerFactory transformerFactory = KalypsoCommonsPlugin.getDefault().getTransformerFactory(); /* Create the transformer using the XSL document. */ final Transformer transformer = transformerFactory.newTransformer(new DOMSource(xslDOM)); /* Transform the XML document document and write it to the output stream. */ transformer.transform(new DOMSource(xmlDOM), new StreamResult(outputStream)); } finally { /* Close the input stream. */ IOUtils.closeQuietly(inputStream); } }
From source file:org.kalypso.model.km.internal.binding.KMBindingUtils.java
public static void save(final KalininMiljukovGroupType kmGroup, final File file) throws JAXBException { final Marshaller marshaller = JaxbUtilities.createMarshaller(JC); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //$NON-NLS-1$ final NamespacePrefixMapper prefixMapper = new NamespacePrefixMapper() { @Override//from w w w. j a v a2 s.co m public String getPreferredPrefix(final String namespaceUri, final String suggestion, final boolean requirePrefix) { if (KM_NAMESPACE.equals(namespaceUri)) return ""; //$NON-NLS-1$ return null; } }; marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", prefixMapper); //$NON-NLS-1$ final JAXBElement<KalininMiljukovGroupType> element = OF.createKalininMiljukovGroup(kmGroup); marshaller.marshal(element, file); }
From source file:org.kalypso.ogc.sensor.diagview.DiagViewUtils.java
/** * Saves the given template (binding). Closes the writer. *//*w ww . jav a 2s . c o m*/ public static void saveDiagramTemplateXML(final Obsdiagview tpl, final OutputStreamWriter writer) throws JAXBException { try { final Marshaller m = createMarshaller(); String encoding = writer.getEncoding(); // HACK: rename utf8 encoding, esle xml editor will not validate if ("UTF8".equals(encoding)) //$NON-NLS-1$ encoding = "UTF-8"; //$NON-NLS-1$ m.setProperty(Marshaller.JAXB_ENCODING, encoding); m.marshal(tpl, writer); } finally { IOUtils.closeQuietly(writer); } }