Debian Codegraph @

net/sf/saxon/style/XSLOverride.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.style;
9
10 import net.sf.saxon.expr.Component;
11 import net.sf.saxon.functions.FunctionLibraryList;
12 import net.sf.saxon.om.*;
13 import net.sf.saxon.trans.Mode;
14 import net.sf.saxon.trans.SymbolicName;
15 import net.sf.saxon.trans.Visibility;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.tree.iter.AxisIterator;
18 import net.sf.saxon.type.Type;
19
20 /**
21 * Represents an xsl:override element in a package manifest.
22 */
23 public class XSLOverride extends StyleElement {
24
25 @Override
26 public void prepareAttributes() throws XPathException {
27 AttributeCollection atts = getAttributeList();
28 for (int a = 0; a < atts.getLength(); a++) {
29 checkUnknownAttribute(atts.getNodeName(a));
30 }
31 }
32
33 /**
34 * Validate this element
35 *
36 * @param decl Not used
37 */
38
39 @Override
40 public void validate(ComponentDeclaration decl) throws XPathException {
41 iterateAxis(AxisInfo.CHILD).forEachOrFail(curr -> {
42 if (curr.getNodeKind() == Type.TEXT) {
43 compileError("Character content is not allowed as a child of xsl:override", "XTSE0010");
44 } else if (curr instanceof XSLFunction || curr instanceof XSLTemplate || curr instanceof XSLGlobalVariable
45 || curr instanceof XSLAttributeSet) {
46 // OK
47 } else {
48 ((StyleElement) curr).compileError(
49 "Element " + curr.getDisplayName() + " is not allowed as a child of xsl:override", "XTSE0010");
50 }
51 });
52 }
53
54 @Override
55 public void postValidate() throws XPathException {
56 XSLUsePackage parent = (XSLUsePackage)getParent();
57 assert parent != null;
58 if (parent.getUsedPackage() != null) {
59 AxisIterator kids = iterateAxis(AxisInfo.CHILD);
60 NodeInfo curr;
61 while ((curr = kids.next()) != null) {
62 if (curr instanceof XSLFunction || curr instanceof XSLTemplate || curr instanceof XSLGlobalVariable
63 || curr instanceof XSLAttributeSet) {
64 StylesheetComponent procedure = (StylesheetComponent) curr;
65 SymbolicName name = procedure.getSymbolicName();
66 if (name == null) {
67 if (curr instanceof XSLTemplate) {
68 XSLTemplate decl = (XSLTemplate)curr;
69 if (decl.getMatch() == null) {
70 decl.compileError("An overriding template with no name must have a match pattern");
71 }
72 StructuredQName[] modeNames = decl.getModeNames();
73 for (StructuredQName modeName : modeNames) {
74 if (modeName.equals(Mode.OMNI_MODE)) {
75 ((StyleElement) curr).compileError(
76 "An overriding template rule must not specify mode=\"#all\"", "XTSE3440");
77 } else if (modeName.equals(Mode.UNNAMED_MODE_NAME)) {
78 modeName = decl.getDefaultMode();
79 if (modeName.equals(Mode.UNNAMED_MODE_NAME)) {
80 ((StyleElement) curr).compileError(
81 "An overriding template rule must not belong to the unnamed mode", "XTSE3440");
82 }
83 }
84 }
85 } else {
86 ((StyleElement) curr).compileError(
87 "An overriding component (other than a template rule) must have a name", "XTSE3440");
88 return;
89 }
90 } else {
91
92 Component overridden = parent.getUsedPackage().getComponent(name);
93 if (overridden == null) {
94 ((StyleElement) curr).compileError("There is no " + StandardNames.getLocalName(name.getComponentKind()) +
95 " named " + name.getShortName() +
96 " in the used package", "XTSE3058");
97 return;
98 }
99 Visibility overriddenVis = overridden.getVisibility();
100 if (overriddenVis == null) {
101 overriddenVis = Visibility.PRIVATE;
102 }
103 if (overriddenVis == Visibility.FINAL || overriddenVis == Visibility.PRIVATE) {
104 ((StyleElement) curr).compileError(
105 "The " + StandardNames.getLocalName(name.getComponentKind()) +
106 " named " + name.getShortName() +
107 " in the used package cannot be overridden because its visibility is " + overriddenVis.show(),
108 "XTSE3060");
109 return;
110 }
111 procedure.checkCompatibility(overridden);
112 }
113 }
114 }
115 }
116 }
117
118 /**
119 * Add a function library that recognizes the function call xsl:original, which is permitted
120 * within a function that overrides another
121 *
122 * @param list the function library list to which the new function library should be added
123 */
124
125 public void addXSLOverrideFunctionLibrary(FunctionLibraryList list){
126 list.addFunctionLibrary(XSLOriginalLibrary.getInstance());
127 }
128 }