Debian Codegraph @

net/sf/saxon/trans/rules/RuleSetWithWarnings.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.trans.rules;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.expr.instruct.ParameterSet;
12 import net.sf.saxon.expr.parser.Location;
13 import net.sf.saxon.om.Item;
14 import net.sf.saxon.om.NodeInfo;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.tree.util.Navigator;
17
18
19 /**
20 * A set of built-in template rules that performs the same action as an underlying set of rules,
21 * but with the addition of a warning message saying that no user-defined template rules was found.
22 * <p>XSLT 3.0 feature</p>
23 */
24 public class RuleSetWithWarnings implements BuiltInRuleSet {
25
26
27 private BuiltInRuleSet baseRuleSet;
28
29 public RuleSetWithWarnings(BuiltInRuleSet baseRuleSet) {
30 this.baseRuleSet = baseRuleSet;
31 }
32
33 public BuiltInRuleSet getBaseRuleSet() {
34 return baseRuleSet;
35 }
36
37 /**
38 * Perform the built-in template action for a given item.
39 * @param item the item to be matched
40 * @param parameters the parameters supplied to apply-templates
41 * @param tunnelParams the tunnel parameters to be passed through
42 * @param context the dynamic evaluation context
43 * @param locationId location of the instruction (apply-templates, apply-imports etc) that caused
44 * the built-in template to be invoked @throws net.sf.saxon.trans.XPathException
45 */
46
47 public void process(Item item, ParameterSet parameters,
48 ParameterSet tunnelParams, XPathContext context,
49 Location locationId) throws XPathException {
50
51 outputWarning(item, context);
52 baseRuleSet.process(item, parameters, tunnelParams, context, locationId);
53
54 }
55
56
57 /**
58 * Identify this built-in rule set
59 *
60 * @return the base name plus "with warnings"
61 */
62
63 @Override
64 public String getName() {
65 return baseRuleSet + " with warnings";
66 }
67
68 public void outputWarning(Item item, XPathContext context) {
69 String id = item instanceof NodeInfo ?
70 "the node " + Navigator.getPath((NodeInfo) item) :
71 "the atomic value " + item.getStringValue();
72 XPathException warning = new XPathException("No user-defined template rule matches " + id, "XTDE0555");
73 context.getController().getErrorListener().warning(warning);
74 }
75
76 /**
77 * Get the default action for unmatched nodes
78 *
79 * @param nodeKind the node kind
80 * @return the default action for unmatched element nodes: one of DEEP_COPY, APPLY_TEMPLATES, DEEP_SKIP, FAIL
81 */
82 public int[] getActionForParentNodes(int nodeKind) {
83 return baseRuleSet.getActionForParentNodes(nodeKind);
84 }
85 }