Debian Codegraph @

net/sf/saxon/om/IgnorableSpaceStrippingRule.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.om;
9
10
11 import net.sf.saxon.event.IgnorableWhitespaceStripper;
12 import net.sf.saxon.event.ProxyReceiver;
13 import net.sf.saxon.event.Receiver;
14 import net.sf.saxon.event.Stripper;
15 import net.sf.saxon.trace.ExpressionPresenter;
16 import net.sf.saxon.type.ComplexType;
17 import net.sf.saxon.type.SchemaType;
18 import net.sf.saxon.type.Untyped;
19
20 /**
21 * A whitespace stripping rule that strips whitespace text node children from all elements having an element-only content
22 * model, regardless of the value of the xml:space attribute
23 */
24
25 public class IgnorableSpaceStrippingRule implements SpaceStrippingRule {
26
27 private final static IgnorableSpaceStrippingRule THE_INSTANCE = new IgnorableSpaceStrippingRule();
28
29 public static IgnorableSpaceStrippingRule getInstance() {
30 return THE_INSTANCE;
31 }
32
33 /**
34 * Decide whether an element is in the set of white-space preserving element types
35 *
36 * @param name identifies the name of the element being tested
37 * @param schemaType the type annotation of the element being tested
38 * @return STRIP_DEFAULT: strip spaces unless xml:space tells you not to.
39 */
40
41 public int isSpacePreserving(NodeName name, SchemaType schemaType) {
42 if (schemaType != Untyped.getInstance() && schemaType.isComplexType() &&
43 !((ComplexType) schemaType).isSimpleContent() &&
44 !((ComplexType) schemaType).isMixedContent()) {
45 return Stripper.ALWAYS_STRIP;
46 } else {
47 return Stripper.ALWAYS_PRESERVE;
48 }
49 }
50
51 /**
52 * Make a filter to implement these space-stripping rules, or null if no filtering
53 * is necessary
54 *
55 * @return a filter in the form of a ProxyReceiver, or null
56 */
57 @Override
58 public ProxyReceiver makeStripper(Receiver next) {
59 return new IgnorableWhitespaceStripper(next);
60 }
61
62
63 /**
64 * Export this rule as part of an exported stylesheet
65 *
66 * @param presenter the output handler
67 */
68 public void export(ExpressionPresenter presenter) {
69 presenter.startElement("strip.ignorable");
70 presenter.endElement();
71 }
72 }
73