Example usage for org.w3c.dom.ls LSSerializerFilter LSSerializerFilter

List of usage examples for org.w3c.dom.ls LSSerializerFilter LSSerializerFilter

Introduction

In this page you can find the example usage for org.w3c.dom.ls LSSerializerFilter LSSerializerFilter.

Prototype

LSSerializerFilter

Source Link

Usage

From source file:Main.java

/**
 * Obtain a the DOM, level 3, Load/Save serializer {@link LSSerializer} instance from the
 * given {@link DOMImplementationLS} instance.
 * /*from w ww . ja v a 2  s.co m*/
 * <p>
 * The serializer instance will be configured with the parameters passed as the <code>serializerParams</code>
 * argument. It will also be configured with an {@link LSSerializerFilter} that shows all nodes to the filter, 
 * and accepts all nodes shown.
 * </p>
 * 
 * @param domImplLS the DOM Level 3 Load/Save implementation to use
 * @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
 *         instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
 *         
 * @return a new LSSerializer instance
 */
public static LSSerializer getLSSerializer(DOMImplementationLS domImplLS,
        Map<String, Object> serializerParams) {
    LSSerializer serializer = domImplLS.createLSSerializer();

    serializer.setFilter(new LSSerializerFilter() {

        public short acceptNode(Node arg0) {
            return FILTER_ACCEPT;
        }

        public int getWhatToShow() {
            return SHOW_ALL;
        }
    });

    if (serializerParams != null) {
        DOMConfiguration serializerDOMConfig = serializer.getDomConfig();
        for (String key : serializerParams.keySet()) {
            serializerDOMConfig.setParameter(key, serializerParams.get(key));
        }
    }

    return serializer;
}