//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2018 Saxonica Limited. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// package net.sf.saxon.s9api; import net.sf.saxon.event.FilterFactory; import net.sf.saxon.event.ProxyReceiver; import net.sf.saxon.event.Receiver; import net.sf.saxon.event.Stripper; import net.sf.saxon.om.*; import net.sf.saxon.style.StylesheetPackage; import net.sf.saxon.trace.ExpressionPresenter; import net.sf.saxon.trans.XPathException; import net.sf.saxon.type.SchemaType; import net.sf.saxon.value.Whitespace; import java.util.function.Predicate; /** * WhitespaceStrippingPolicy is class defining the possible policies for handling * whitespace text nodes in a source document. */ public class WhitespaceStrippingPolicy { private int policy; private SpaceStrippingRule stripperRules; /** * The value NONE indicates that all whitespace text nodes are retained. This is the default * when documents are processed without validation. */ public static final WhitespaceStrippingPolicy NONE = new WhitespaceStrippingPolicy(Whitespace.NONE); /** * The value IGNORABLE indicates that whitespace text nodes in element-only content are * discarded. Content is element-only if it is defined by a schema or DTD definition that * does not allow mixed or PCDATA content. This option is in effect documentary only, since * this policy is always used when DTD or schema validation is selected for a {@link DocumentBuilder}, * and is equivalent to {@link #NONE} otherwise. */ public static final WhitespaceStrippingPolicy IGNORABLE = new WhitespaceStrippingPolicy(Whitespace.IGNORABLE); /** * The value ALL indicates that all whitespace-only text nodes are discarded. */ public static final WhitespaceStrippingPolicy ALL = new WhitespaceStrippingPolicy(Whitespace.ALL); /** * UNSPECIFIED means that no other value has been specifically requested. */ public static final WhitespaceStrippingPolicy UNSPECIFIED = new WhitespaceStrippingPolicy(Whitespace.UNSPECIFIED); /** * Create a custom whitespace stripping policy. *
Changed in 9.9 to use the standard Java 8 Predicate class in place of Saxon's version.
* @param elementTest a predicate applied to element names, which should return true if whitespace-only * text node children of the element are to be stripped, false if they are to be retained. */ public static WhitespaceStrippingPolicy makeCustomPolicy(final Predicate