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:com.wsun.seap.common.mapper.JaxbMapper.java
/** * Marshallerencoding(?null).//from w w w . j ava2s . 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); } return marshaller; } catch (JAXBException e) { throw ExceptionUtil.unchecked(e); } }
From source file:org.biopax.validator.api.ValidatorUtils.java
/** * Gets the results Marshaller (for validation results.) * @return/*from w ww . j av a 2s. c om*/ */ public static Marshaller getMarshaller() { //return resultsMarshaller; try { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); return marshaller; } catch (JAXBException e) { throw new RuntimeException("Failed to create Marshaller", e); } }
From source file:cn.newtouch.util.utils.encode.JaxbBinder.java
/** * Marshaller, encoding(?Null)./*from w w w. j a v a2 s .c om*/ */ public Marshaller createMarshaller(String encoding) { try { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (StringUtils.isNotBlank(encoding)) { marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); } return marshaller; } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterTibjmsImpl.java
/** * Set given <code>message</code> encoding with Tibco proprietary APIs. * /*from w w w . j a v a 2 s. c om*/ * @see com.tibco.tibjms.Tibjms#setMessageEncoding(javax.jms.Message, String) * @see fr.xebia.springframework.jms.support.converter.JaxbMessageConverter#postProcessResponseMessage(Message) */ @Override protected void postProcessResponseMessage(Message textMessage) throws JMSException { super.postProcessResponseMessage(textMessage); String encoding = this.marshallerProperties == null ? null : (String) this.marshallerProperties.get(Marshaller.JAXB_ENCODING); encoding = encoding == null ? "UTF-8" : encoding; try { this.setMessageEncodingMethod.invoke(null, new Object[] { textMessage, encoding }); } catch (Exception e) { MessageConversionException jmse = new MessageConversionException( NestedExceptionUtils.buildMessage("Exception setting message encoding", e), e); throw jmse; } }
From source file:com.sportpm.mapper.JaxbMapper.java
/** * Marshallerencoding(?null)./*www .j ava 2 s. c om*/ * ???pooling */ @SuppressWarnings("rawtypes") 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); } return marshaller; } catch (JAXBException e) { throw Exceptions.unchecked(e); } }
From source file:Main.java
/** * @param m// w w w . jav a 2 s.c o m * @param encoding * @return * @throws PropertyException */ private static Marshaller setMarshallerProperty(Marshaller m) throws PropertyException { m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // set Output charset to project's charset; m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); return m; }
From source file:com.faceye.feature.util.JaxbMapper.java
/** * Marshallerencoding(?null)./*from ww w.j av a 2 s.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:com.tangfan.test.UserServiceTest.java
/** * add jaxws-ri???//from www.j a v a2 s .co m */ @Test public void add() { try { //1.?xml JAXBContext jaxb = JAXBContext.newInstance(LicenseInfo.class); User lu = new User(); lu.setId(0); lu.setNickname(""); lu.setUsername("admin"); lu.setPassword("123"); LicenseInfo info = new LicenseInfo(); info.setLoginUser(lu); QName qName = new QName(ns, "licenseInfo"); JAXBElement<LicenseInfo> jele = new JAXBElement<LicenseInfo>(qName, LicenseInfo.class, info); Marshaller mars = jaxb.createMarshaller(); mars.setProperty(Marshaller.JAXB_FRAGMENT, true);//xml mars.setProperty(Marshaller.JAXB_ENCODING, "utf-8");//? //2.?dom Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); mars.marshal(jele, doc); //3.Headers.create?header WSBindingProvider wsb = (WSBindingProvider) port; wsb.setOutboundHeaders(Headers.create(doc.getDocumentElement())); User u = new User(); u.setId(2); u.setUsername("master"); u.setNickname("jboss?"); u.setPassword("123456"); port.add(u); } catch (UserException_Exception e) { System.out.println(e.getMessage()); } catch (JAXBException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } }
From source file:net.cloudkit.enterprises.infrastructure.utilities.JaxbMapperHelper.java
/** * Marshallerencoding(?null). ???pooling *///from w ww. j a v a 2s .c om 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); } return marshaller; } catch (JAXBException e) { throw ExceptionHelper.unchecked(e); } }
From source file:$.JaxbMapper.java
/** * Marshallerencoding(?null).// w ww .j a va2s . co 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); } return marshaller; } catch (JAXBException e) { throw Exceptions.unchecked(e); } }