List of usage examples for javax.xml.bind Marshaller JAXB_SCHEMA_LOCATION
String JAXB_SCHEMA_LOCATION
To view the source code for javax.xml.bind Marshaller JAXB_SCHEMA_LOCATION.
Click Source Link
From source file:edu.purdue.cybercenter.dm.service.TermService.java
public String convertTermToXml(Term term) { String xmlTerm = null;/*from w w w . j av a 2 s.c om*/ try (OutputStream os = new ByteArrayOutputStream()) { Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(CharacterEscapeHandler.class.getName(), CDataEscapeHandler.theInstance); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, VOCABULARY_SCHEMA_LOCATION); marshaller.marshal(term, os); xmlTerm = os.toString(); } catch (JAXBException ex) { throw new RuntimeException("Unable to generate xml term definition", ex); } catch (IOException ex) { throw new RuntimeException("Unable to write xml term definition", ex); } return xmlTerm; }
From source file:fr.cls.atoll.motu.processor.wps.framework.WPSFactory.java
/** * Marshall execute.//from www . j a v a2 s.c om * * @param execute the execute * @param writer the writer * @param schemaLocation the schema location * * @throws MotuMarshallException the motu marshall exception */ public static void marshallExecute(Execute execute, Writer writer, String schemaLocation) throws MotuMarshallException { if (LOG.isDebugEnabled()) { LOG.debug("marshallExecute(Execute, Writer, String) - entering"); } if (writer == null) { if (LOG.isDebugEnabled()) { LOG.debug("marshallExecute(Execute, Writer, String) - exiting"); } return; } try { synchronized (WPSFactory.marshallerWPS) { WPSFactory.marshallerWPS.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, ""); if (!WPSUtils.isNullOrEmpty(schemaLocation)) { WPSFactory.marshallerWPS.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation); } WPSFactory.marshallerWPS.marshal(execute, writer); writer.flush(); writer.close(); } } catch (JAXBException e) { LOG.error("marshallExecute(Execute, Writer, String)", e); throw new MotuMarshallException("Error in WPSFactory - marshallExecute", e); } catch (IOException e) { LOG.error("marshallExecute(Execute, Writer, String)", e); throw new MotuMarshallException("Error in WPSFactory - marshallExecute", e); } if (LOG.isDebugEnabled()) { LOG.debug("marshallExecute(Execute, Writer, String) - exiting"); } }
From source file:fr.cls.atoll.motu.processor.wps.framework.WPSFactory.java
/** * Marshall execute response.// ww w . j a v a2 s .c o m * * @param executeResponse the execute response * @param writer the writer * @param schemaLocation the schema location * * @throws MotuMarshallException the motu marshall exception */ public static void marshallExecuteResponse(ExecuteResponse executeResponse, Writer writer, String schemaLocation) throws MotuMarshallException { if (LOG.isDebugEnabled()) { LOG.debug("marshallExecuteResponse(ExecuteResponse, Writer, String) - entering"); } if (writer == null) { if (LOG.isDebugEnabled()) { LOG.debug("marshallExecuteResponse(ExecuteResponse, Writer, String) - exiting"); } return; } try { synchronized (WPSFactory.marshallerWPS) { WPSFactory.marshallerWPS.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, ""); if (!WPSUtils.isNullOrEmpty(schemaLocation)) { WPSFactory.marshallerWPS.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation); } WPSFactory.marshallerWPS.marshal(executeResponse, writer); writer.flush(); writer.close(); } } catch (JAXBException e) { LOG.error("marshallExecuteResponse(ExecuteResponse, Writer, String)", e); throw new MotuMarshallException("Error in WPSFactory - marshallExecute", e); } catch (IOException e) { LOG.error("marshallExecuteResponse(ExecuteResponse, Writer, String)", e); throw new MotuMarshallException("Error in WPSFactory - marshallExecute", e); } if (LOG.isDebugEnabled()) { LOG.debug("marshallExecuteResponse(ExecuteResponse, Writer, String) - exiting"); } }
From source file:io.github.jeddict.jpa.modeler.initializer.JPAModelerUtil.java
private static void saveFile(EntityMappings entityMappings, File file) { try {/*from ww w .j a v a 2 s. com*/ if (MODELER_MARSHALLER == null) { MODELER_MARSHALLER = MODELER_CONTEXT.createMarshaller(); MODELER_MARSHALLER.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); MODELER_MARSHALLER.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://java.sun.com/xml/ns/persistence/orm orm_2_1.xsd"); MODELER_MARSHALLER.setEventHandler(new ValidateJAXB()); } MODELER_MARSHALLER.marshal(entityMappings, file); } catch (JAXBException ex) { ExceptionUtils.printStackTrace(ex); } }
From source file:io.github.jeddict.jpa.modeler.initializer.JPAModelerUtil.java
public String getContent(EntityMappings entityMappings) { StringWriter sw = new StringWriter(); try {/*from w w w . j av a2 s .co m*/ if (MODELER_MARSHALLER == null) { MODELER_MARSHALLER = MODELER_CONTEXT.createMarshaller(); MODELER_MARSHALLER.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); MODELER_MARSHALLER.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://java.sun.com/xml/ns/persistence/orm orm_2_1.xsd"); MODELER_MARSHALLER.setEventHandler(new ValidateJAXB()); } MODELER_MARSHALLER.marshal(entityMappings, sw); } catch (JAXBException ex) { ExceptionUtils.printStackTrace(ex); } return sw.toString(); }
From source file:io.github.jeddict.jpa.modeler.initializer.JPAModelerUtil.java
public <T extends Object> T cloneElement(T element) { T clonedElement = null;/*from ww w . j a v a2 s. co m*/ try { if (MODELER_MARSHALLER == null) { MODELER_MARSHALLER = MODELER_CONTEXT.createMarshaller(); MODELER_MARSHALLER.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); MODELER_MARSHALLER.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://java.sun.com/xml/ns/persistence/orm orm_2_1.xsd"); MODELER_MARSHALLER.setEventHandler(new ValidateJAXB()); } StringWriter sw = new StringWriter(); QName qName = new QName(element.getClass().getSimpleName()); JAXBElement<T> root = new JAXBElement<>(qName, (Class<T>) element.getClass(), (T) element); MODELER_MARSHALLER.marshal(root, sw); if (MODELER_UNMARSHALLER == null) { MODELER_UNMARSHALLER = MODELER_CONTEXT.createUnmarshaller(); } StringReader reader = new StringReader(sw.toString()); clonedElement = (T) MODELER_UNMARSHALLER .unmarshal(new StreamSource(reader), (Class<T>) element.getClass()).getValue(); MODELER_UNMARSHALLER = null; } catch (JAXBException ex) { ExceptionUtils.printStackTrace(ex); } return clonedElement; }
From source file:org.apache.cayenne.dbimport.DefaultReverseEngineeringWriter.java
@Override public Resource write(ReverseEngineering reverseEngineering, Writer writer) throws CayenneRuntimeException { try {/*ww w . j ava 2s . c o m*/ JAXBContext context = JAXBContext.newInstance(reverseEngineering.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://cayenne.apache.org/schema/8/reverseEngineering http://cayenne.apache.org/schema/8/reverseEngineering.xsd"); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.marshal(reverseEngineering, writer); writer.close(); return reverseEngineering.getConfigurationSource(); } catch (JAXBException | IOException e) { LOGGER.error(e.getMessage(), e); throw new CayenneRuntimeException(e); } }
From source file:org.apli.modelbeans.facturacion.cfdi.CFDv32.java
@Override public void guardar(OutputStream out) throws Exception { Marshaller m = context.createMarshaller(); m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(localPrefixes)); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.sat.gob.mx/cfd/3 " + "http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd"); byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8"); out.write(xmlHeaderBytes);/*from w w w. ja v a2s. com*/ m.marshal(document, out); }
From source file:org.artifactory.jaxb.JaxbHelper.java
public void write(OutputStream stream, T object) { try {/*www. j a v a 2s . co m*/ JAXBContext context = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); XmlSchema schemaAnnotation = object.getClass().getPackage().getAnnotation(XmlSchema.class); if (schemaAnnotation != null && schemaAnnotation.location() != null) { marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaAnnotation.location()); // TODO: May just this ArtifactoryConfigVersion.getCurrent().getXsdLocation()); } marshaller.marshal(object, stream); } catch (Exception e) { throw new RuntimeException("Failed to write object to stream.", e); } finally { IOUtils.closeQuietly(stream); } }
From source file:org.betaconceptframework.astroboa.model.jaxb.AstroboaMarshaller.java
@Override public void setProperty(String arg0, Object arg1) throws PropertyException { if (StringUtils.isNotBlank(arg0)) { if (CMS_PROPERTIES_TO_BE_MARSHALLED.equals(arg0)) { if (!(arg1 instanceof List)) { throw new PropertyException("Marshaller property " + CMS_PROPERTIES_TO_BE_MARSHALLED + " must be of type List<String>"); }//from w ww. j ava2 s . com cmsPropertiesToBeMarshalled = (List<String>) arg1; } else if (Marshaller.JAXB_SCHEMA_LOCATION.equals(arg0) && outputTypeIsJSON()) { //Do not provide schema location when marshaling to JSON } else { marshaller.setProperty(arg0, arg1); } } }