Search in sources :

Example 1 with XML

use of grails.converters.XML in project grails-core by grails.

the class ConvertersConfigurationInitializer method initXMLConfiguration.

private void initXMLConfiguration() {
    LOG.debug("Initializing default XML Converters Configuration...");
    List<ObjectMarshaller<XML>> marshallers = new ArrayList<ObjectMarshaller<XML>>();
    marshallers.addAll(getPreviouslyConfiguredMarshallers(XML.class));
    marshallers.add(new org.grails.web.converters.marshaller.xml.Base64ByteArrayMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.ArrayMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.CollectionMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.MapMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.EnumMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.DateMarshaller());
    marshallers.add(new ProxyUnwrappingMarshaller<XML>());
    marshallers.add(new org.grails.web.converters.marshaller.xml.ToStringBeanMarshaller());
    ProxyHandler proxyHandler = getProxyHandler();
    Config grailsConfig = getGrailsConfig();
    boolean includeDomainVersion = includeDomainVersionProperty(grailsConfig, "xml");
    if (grailsConfig.getProperty(SETTING_CONVERTERS_XML_DEEP, Boolean.class, false)) {
        marshallers.add(new org.grails.web.converters.marshaller.xml.DeepDomainClassMarshaller(includeDomainVersion, proxyHandler, grailsApplication));
    } else {
        marshallers.add(new org.grails.web.converters.marshaller.xml.DomainClassMarshaller(includeDomainVersion, proxyHandler, grailsApplication));
    }
    marshallers.add(new org.grails.web.converters.marshaller.xml.GroovyBeanMarshaller());
    marshallers.add(new org.grails.web.converters.marshaller.xml.GenericJavaBeanMarshaller());
    DefaultConverterConfiguration<XML> cfg = new DefaultConverterConfiguration<XML>(marshallers, proxyHandler);
    cfg.setEncoding(grailsConfig.getProperty(SETTING_CONVERTERS_ENCODING, "UTF-8"));
    String defaultCirRefBehaviour = grailsConfig.getProperty(SETTING_CONVERTERS_CIRCULAR_REFERENCE_BEHAVIOUR, "DEFAULT");
    cfg.setCircularReferenceBehaviour(Converter.CircularReferenceBehaviour.valueOf(grailsConfig.getProperty("grails.converters.xml.circular.reference.behaviour", String.class, defaultCirRefBehaviour, Converter.CircularReferenceBehaviour.allowedValues())));
    Boolean defaultPrettyPrint = grailsConfig.getProperty(SETTING_CONVERTERS_PRETTY_PRINT, Boolean.class, false);
    Boolean prettyPrint = grailsConfig.getProperty("grails.converters.xml.pretty.print", Boolean.class, defaultPrettyPrint);
    cfg.setPrettyPrint(prettyPrint);
    cfg.setCacheObjectMarshallerByClass(grailsConfig.getProperty("grails.converters.xml.cacheObjectMarshallerSelectionByClass", Boolean.class, true));
    registerObjectMarshallersFromApplicationContext(cfg, XML.class);
    ConvertersConfigurationHolder.setDefaultConfiguration(XML.class, new ChainedConverterConfiguration<XML>(cfg, proxyHandler));
}
Also used : Config(grails.config.Config) PropertySourcesConfig(org.grails.config.PropertySourcesConfig) ArrayList(java.util.ArrayList) DefaultProxyHandler(grails.core.support.proxy.DefaultProxyHandler) ProxyHandler(grails.core.support.proxy.ProxyHandler) ObjectMarshaller(org.grails.web.converters.marshaller.ObjectMarshaller) XML(grails.converters.XML)

Aggregations

Config (grails.config.Config)1 XML (grails.converters.XML)1 DefaultProxyHandler (grails.core.support.proxy.DefaultProxyHandler)1 ProxyHandler (grails.core.support.proxy.ProxyHandler)1 ArrayList (java.util.ArrayList)1 PropertySourcesConfig (org.grails.config.PropertySourcesConfig)1 ObjectMarshaller (org.grails.web.converters.marshaller.ObjectMarshaller)1