List of usage examples for javax.xml.bind Marshaller setProperty
public void setProperty(String name, Object value) throws PropertyException;
From source file:ch.algotrader.service.ib.IBFixAllocationServiceImpl.java
private String marshal(final GroupMap groups) { try {/*from www . j a va 2 s. co m*/ JAXBContext context = JAXBContext.newInstance(GroupMap.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter writer = new StringWriter(); m.marshal(groups, writer); return writer.toString(); } catch (JAXBException ex) { throw new ExternalServiceException(ex); } }
From source file:com.bitplan.jaxb.JaxbFactory.java
/** * get a marshaller for the given <T> instance * /*from w w w . j a v a2 s .c om*/ * @param instance * - the instance to get a marshaller for * @return a marshaller for <T> * @throws JAXBException */ public Marshaller getMarshaller(T instance) throws JAXBException { JAXBContext lcontext = getJAXBContext(); Marshaller marshaller = lcontext.createMarshaller(); if (this.marshalListener != null) { marshaller.setListener(marshalListener); } marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); return marshaller; }
From source file:edu.purdue.cybercenter.dm.service.VocabularyService.java
/** * Convert a vocabulary object to Xml vocabulary * * @param vocabulary: a vocabulary object * @return: an XML version of the vocabulary *//*from w w w . ja v a 2 s . c om*/ public String convertVocabularyToXml(Vocabulary vocabulary) { String xmlVocabulary = null; 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(vocabulary, os); xmlVocabulary = os.toString(); } catch (JAXBException ex) { throw new RuntimeException("Unable to generate xml vocabulary definition", ex); } catch (IOException ex) { throw new RuntimeException("UUnable to write xml vocabulary definition", ex); } return xmlVocabulary; }
From source file:gov.nih.nci.cabig.caaers.esb.client.impl.CtmsCaaersMessageConsumer.java
/** * This method is used to marshal the Response objects from Individual Services to xml format * so that it can be set as the Content of the Response JMS TextMessage * @param pObject/* w ww . j a v a 2 s . c o m*/ * @param marshaller * @return * @throws JAXBException */ public String responseAsString(Object pObject, Marshaller marshaller) throws JAXBException { StringWriter sw = new StringWriter(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(pObject, sw); return sw.toString(); }
From source file:it.cnr.icar.eric.server.interfaces.rest.QueryManagerURLHandler.java
/** Write the result set as a RegistryObjectList */ private void writeRegistryObjectList(List<? extends IdentifiableType> ebRegistryObjectTypeList) throws IOException, RegistryException { ServletOutputStream sout = null;//from w ww.j a va 2 s . c om try { sout = response.getOutputStream(); @SuppressWarnings("unchecked") RegistryObjectListType ebRegistryObjectListType = bu .getRegistryObjectListType((List<RegistryObjectType>) ebRegistryObjectTypeList); // javax.xml.bind.Marshaller marshaller = bu.rimFac.createMarshaller(); javax.xml.bind.Marshaller marshaller = bu.getJAXBContext().createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(ebRegistryObjectListType, sout); } catch (JAXBException e) { throw new RegistryException(e); } finally { if (sout != null) { sout.close(); } } }
From source file:com.jaspersoft.jasperserver.rest.utils.Utils.java
public Marshaller getMarshaller(boolean isFragment, Class... docClass) throws JAXBException { JAXBContext context = JAXBContext.newInstance(docClass); Marshaller m = context.createMarshaller(); m.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, isFragment); return m;/* www . j av a 2s. c o m*/ }
From source file:com.jaspersoft.jasperserver.rest.utils.Utils.java
public Marshaller getMarshaller(Class... docClass) throws JAXBException { JAXBContext context = JAXBContext.newInstance(docClass); Marshaller m = context.createMarshaller(); m.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, Boolean.TRUE); return m;//ww w . j av a2s . co m }
From source file:ddf.security.pdp.xacml.processor.BalanaPdp.java
/** * Marshalls the XACML request to a string. * /*from ww w . j a va 2s .c o m*/ * @param xacmlRequestType * The XACML request to marshal. * @return A string representation of the XACML request. */ private String marshal(RequestType xacmlRequestType) throws PdpException { ObjectFactory objectFactory = new ObjectFactory(); Writer writer = new StringWriter(); JAXBElement<RequestType> xacmlRequestTypeElement = objectFactory.createRequest(xacmlRequestType); Marshaller marshaller = null; String xacmlRequest = null; try { marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(xacmlRequestTypeElement, writer); xacmlRequest = writer.toString(); } catch (JAXBException e) { String message = "Unable to marshal XACML request."; LOGGER.error(message); throw new PdpException(message, e); } LOGGER.debug("\nXACML 3.0 Request:\n{}", xacmlRequest); return xacmlRequest; }
From source file:at.gv.egovernment.moa.id.configuration.struts.action.ImportExportAction.java
public String downloadXMLConfig() { try {/*from w w w . j ava 2 s .co m*/ populateBasicInformations(); } catch (BasicActionException e) { return Constants.STRUTS_ERROR; } Object formidobj = session.getAttribute(Constants.SESSION_FORMID); if (formidobj != null && formidobj instanceof String) { String formid = (String) formidobj; if (!formid.equals(formID)) { log.warn("FormIDs does not match. Some suspect Form is received from user " + authUser.getFamilyName() + authUser.getGivenName() + authUser.getUserID()); return Constants.STRUTS_ERROR; } } else { log.warn("FormIDs does not match. Some suspect Form is received from user " + authUser.getFamilyName() + authUser.getGivenName() + authUser.getUserID()); return Constants.STRUTS_ERROR; } session.setAttribute(Constants.SESSION_FORMID, null); if (authUser.isAdmin()) { log.info("Write MOA-ID 2.x xml config"); JAXBContext jc; try { jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config"); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // File test = new File(xmlconfigout); // m.marshal(moaidconfig, test); MOAIDConfiguration moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); if (moaidconfig == null) { log.info("No MOA-ID 2.x configruation available"); addActionError(LanguageHelper.getErrorString("errors.importexport.export.noconfig", request)); formID = Random.nextRandom(); session.setAttribute(Constants.SESSION_FORMID, formID); return Constants.STRUTS_ERROR_VALIDATION; } List<OnlineApplication> oaconfigs = ConfigurationDBRead.getAllOnlineApplications(); moaidconfig.setOnlineApplication(oaconfigs); StringWriter writer = new StringWriter(); m.marshal(moaidconfig, writer); fileInputStream = IOUtils.toInputStream(writer.toString(), "UTF-8"); } catch (JAXBException e) { log.info("MOA-ID 2.x configruation could not be exported into a XML file.", e); addActionError(LanguageHelper.getErrorString("errors.importexport.export", new Object[] { e.getMessage() }, request)); formID = Random.nextRandom(); session.setAttribute(Constants.SESSION_FORMID, formID); return Constants.STRUTS_ERROR_VALIDATION; } catch (IOException e) { log.info("MOA-ID 2.x configruation could not be exported into a XML file.", e); addActionError(LanguageHelper.getErrorString("errors.importexport.export", new Object[] { e.getMessage() }, request)); formID = Random.nextRandom(); session.setAttribute(Constants.SESSION_FORMID, formID); return Constants.STRUTS_ERROR_VALIDATION; } finally { ConfigurationDBUtils.closeSession(); } //set new formID formID = Random.nextRandom(); session.setAttribute(Constants.SESSION_FORMID, formID); return Constants.STRUTS_SUCCESS; } else { log.info("No access to Import/Export for User with ID" + authUser.getUserID()); addActionError(LanguageHelper.getErrorString("errors.notallowed", request)); return Constants.STRUTS_NOTALLOWED; } }
From source file:hydrograph.ui.propertywindow.widgets.customwidgets.schema.GridRowLoader.java
private void exportFile(List<GridRow> schemaGridRowList, Schema schema) throws JAXBException, PropertyException { JAXBContext jaxbContext;// ww w . ja v a2 s . c o m jaxbContext = JAXBContext.newInstance(Schema.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); for (GridRow gridRow : schemaGridRowList) { Field field = ExternalSchemaUtil.INSTANCE.convertGridRowToJaxbSchemaField(gridRow); fields.getField().add(field); } schema.setFields(fields); jaxbMarshaller.marshal(schema, schemaFile); }