Debian Codegraph @

net/sf/saxon/style/XSLNamespaceAlias.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.Expression;
11 import net.sf.saxon.om.AttributeCollection;
12 import net.sf.saxon.om.NamespaceBinding;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.value.Whitespace;
15
16
17 /**
18 * An xsl:namespace-alias element in the stylesheet. <br>
19 */
20
21 public class XSLNamespaceAlias extends StyleElement {
22
23 private String stylesheetURI;
24 private NamespaceBinding resultNamespaceBinding;
25
26 /**
27 * Ask whether this node is a declaration, that is, a permitted child of xsl:stylesheet
28 * (including xsl:include and xsl:import).
29 *
30 * @return true for this element
31 */
32
33 @Override
34 public boolean isDeclaration() {
35 return true;
36 }
37
38 public void prepareAttributes() throws XPathException {
39
40 String stylesheetPrefix = null;
41 String resultPrefix = null;
42
43 AttributeCollection atts = getAttributeList();
44
45 for (int a = 0; a < atts.getLength(); a++) {
46 String f = atts.getQName(a);
47 if (f.equals("stylesheet-prefix")) {
48 stylesheetPrefix = Whitespace.trim(atts.getValue(a));
49 } else if (f.equals("result-prefix")) {
50 resultPrefix = Whitespace.trim(atts.getValue(a));
51 } else {
52 checkUnknownAttribute(atts.getNodeName(a));
53 }
54 }
55 if (stylesheetPrefix == null) {
56 reportAbsence("stylesheet-prefix");
57 stylesheetPrefix = "";
58 }
59 if (stylesheetPrefix.equals("#default")) {
60 stylesheetPrefix = "";
61 }
62 if (resultPrefix == null) {
63 reportAbsence("result-prefix");
64 resultPrefix = "";
65 }
66 if (resultPrefix.equals("#default")) {
67 resultPrefix = "";
68 }
69 stylesheetURI = getURIForPrefix(stylesheetPrefix, true);
70 if (stylesheetURI == null) {
71 compileError("stylesheet-prefix " + stylesheetPrefix + " has not been declared", "XTSE0812");
72 // recovery action
73 stylesheetURI = "";
74 resultNamespaceBinding = NamespaceBinding.DEFAULT_UNDECLARATION;
75 return;
76 }
77 String resultURI = getURIForPrefix(resultPrefix, true);
78 if (resultURI == null) {
79 compileError("result-prefix " + resultPrefix + " has not been declared", "XTSE0812");
80 // recovery action
81 stylesheetURI = "";
82 resultURI = "";
83 }
84 resultNamespaceBinding = new NamespaceBinding(resultPrefix, resultURI);
85 }
86
87 public void validate(ComponentDeclaration decl) throws XPathException {
88 checkTopLevel("XTSE0010", false);
89 }
90
91 /*@Nullable*/
92 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
93 return null;
94 }
95
96 public void index(ComponentDeclaration decl, PrincipalStylesheetModule top) throws XPathException {
97 top.addNamespaceAlias(decl);
98 }
99
100 public String getStylesheetURI() {
101 return stylesheetURI;
102 }
103
104 public NamespaceBinding getResultNamespaceBinding() {
105 return resultNamespaceBinding;
106 }
107
108 }
109