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:se.jguru.nazgul.tools.visualization.model.jaxb.PlainJaxbContextRule.java
/** * Default constructor, setting up a clean internal state. *//*from w w w .j a v a 2s . co m*/ public PlainJaxbContextRule() { this.jaxbAnnotatedClasses = new TreeSet<>(CLASS_COMPARATOR); this.classPatternsToIgnore = new TreeSet<>(); this.classPatternsToIgnore.addAll(STD_IGNORED_CLASSPATTERNS); // Assign standard properties for the Marshaller marshallerProperties = new TreeMap<>(); marshallerProperties.put(Marshaller.JAXB_ENCODING, "UTF-8"); marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, true); // Assign standard properties for the Unmarshaller unMarshallerProperties = new TreeMap<>(); }
From source file:se.mithlond.services.shared.test.entity.PlainJaxbContextRule.java
/** * Default constructor, setting up a clean internal state. *//*from w w w . j ava 2 s.c om*/ public PlainJaxbContextRule() { this.jaxbAnnotatedClasses = new TreeSet<>(CLASS_COMPARATOR); this.namespacePrefixResolver = new JaxbNamespacePrefixResolver(); this.classPatternsToIgnore = new TreeSet<>(); this.classPatternsToIgnore.addAll(STD_IGNORED_CLASSPATTERNS); // Assign standard properties for the Marshaller marshallerProperties = new TreeMap<>(); marshallerProperties.put(Marshaller.JAXB_ENCODING, "UTF-8"); marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshallerProperties.put(RI_NAMESPACE_PREFIX_MAPPER_PROPERTY, namespacePrefixResolver); marshallerProperties.put(MarshallerProperties.JSON_INCLUDE_ROOT, false); marshallerProperties.put(MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); marshallerProperties.put(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, true); // Assign standard properties for the Unmarshaller unMarshallerProperties = new TreeMap<>(); unMarshallerProperties.put(RI_NAMESPACE_PREFIX_MAPPER_PROPERTY, namespacePrefixResolver); unMarshallerProperties.put(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); unMarshallerProperties.put(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true); }
From source file:sernet.verinice.service.XmlRightsService.java
/** * For debugging only!/*from ww w. j a va2s .c om*/ */ private void logAuth(Auth auth) { try { if (log.isDebugEnabled()) { Marshaller marshaller = getContext().createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter sw = new StringWriter(); marshaller.marshal(auth, sw); log.debug(sw.toString()); } } catch (Exception e) { log.error("Error while logging auth", e); } }
From source file:sernet.verinice.service.XmlRightsService.java
/** * Updates the configuration defined in <code>auth</code>. * // w w w . ja va 2s .c o m * Content of <code>authNew</code> is saved in file: verinice-auth.xml * if origin of profiles and userprofiles is "modification". * * Before writing the content the implementation checks * if user is allowed to change the configuration. * * @see sernet.verinice.interfaces.IRightsService#updateConfiguration(sernet.verinice.model.auth.Auth) */ @Override public void updateConfiguration(Auth authNew) { try { if (!isReferenced(ActionRightIDs.EDITPROFILE, authNew)) { log.warn("Right id: " + ActionRightIDs.EDITPROFILE + " is not referenced in the auth configuration. No user is able to change the configuration anymore."); } Profiles profilesMod = new Profiles(); for (Profile profile : authNew.getProfiles().getProfile()) { // add profile if origin is "modification" if (!OriginType.DEFAULT.equals(profile.getOrigin())) { profilesMod.getProfile().add(profile); } } authNew.setProfiles(profilesMod); Userprofiles userprofilesMod = new Userprofiles(); for (Userprofile userprofile : authNew.getUserprofiles().getUserprofile()) { if (!OriginType.DEFAULT.equals(userprofile.getOrigin())) { userprofilesMod.getUserprofile().add(userprofile); } } authNew.setUserprofiles(userprofilesMod); // Block all other threads before writing the file writeLock.lock(); try { checkWritePermission(); //throws sernet.gs.service.SecurityException // create a backup of the old configuration backupConfigurationFile(); // write the new configuration Marshaller marshaller = getContext().createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setSchema(getSchema()); marshaller.marshal(authNew, new FileOutputStream(getAuthConfiguration().getFile().getPath())); // set auth to null, // next call of getCofiguration will read the new configuration from disk this.auth = null; } finally { writeLock.unlock(); } fireChangeEvent(); } catch (sernet.gs.service.SecurityException e) { log.error(e.getMessage(), e); throw e; } catch (Exception e) { String message = "Error while updating authorization configuration."; log.error(message, e); // Big Problem: writing of configuration failed! // Restore it from backup // Block all other threads before writing the file writeLock.lock(); try { log.error("Trying to restore the authorization configuration from backup file now..."); restoreConfigurationFile(); log.error("Authorization configuration restored from backup file."); } finally { writeLock.unlock(); } throw new RuntimeException(message); } }
From source file:uta.ak.usttmp.common.util.UsttmpXmlUtil.java
public static final String objectToXmlStr(Object obj, Class cls, boolean removeXmlHead) throws JAXBException { JAXBContext context = JAXBContext.newInstance(cls); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FRAGMENT, removeXmlHead); // CharacterEscapeHandler escapeHandler = new JaxbNoEscapeCharacterHandler(); // m.setProperty("com.sun.xml.bind.characterEscapeHandler", escapeHandler); m.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); StringWriter sw = new StringWriter(); m.marshal(obj, sw);/* www . j a v a 2 s.c om*/ String xmlstr = sw.toString(); // String xmlstr=StringEscapeUtils.unescapeXml(sw.toString()); logger.log(Level.FINE, "Converted to XML: {0}", xmlstr); return xmlstr; }