Example usage for org.w3c.dom.ls LSSerializer setFilter

List of usage examples for org.w3c.dom.ls LSSerializer setFilter

Introduction

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

Prototype

public void setFilter(LSSerializerFilter filter);

Source Link

Document

When the application provides a filter, the serializer will call out to the filter before serializing each Node.

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 ww  w  .j  a  v  a  2  s  .  c  o 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;
}