Debian Codegraph @

net/sf/saxon/style/XSLBreakOrContinue.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.om.AttributeCollection;
11 import net.sf.saxon.om.AxisInfo;
12 import net.sf.saxon.om.NodeInfo;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.tree.iter.AxisIterator;
15
16 /**
17 * Abstract class containing functionality common to xsl:break and xsl:next-iteration
18 */
19 public abstract class XSLBreakOrContinue extends StyleElement {
20
21 /*@Nullable*/ protected XSLIterate xslIterate = null;
22
23 /**
24 * Determine whether this node is an instruction.
25 *
26 * @return true - it is an instruction
27 */
28
29 public boolean isInstruction() {
30 return true;
31 }
32
33 /**
34 * Set the attribute list for the element. This is called to process the attributes (note
35 * the distinction from processAttributes in the superclass).
36 * Must be supplied in a subclass
37 */
38
39 public void prepareAttributes() throws XPathException {
40 AttributeCollection atts = getAttributeList();
41 for (int a = 0; a < atts.getLength(); a++) {
42 checkUnknownAttribute(atts.getNodeName(a));
43 }
44 }
45
46 /**
47 * Test that this xsl:next-iteration or xsl:break instruction appears in a valid position
48 *
49 * @throws net.sf.saxon.trans.XPathException
50 *
51 */
52
53 protected void validatePosition() throws XPathException {
54 NodeInfo inst = this;
55 boolean isLast = true;
56 while (true) {
57 if (!(inst instanceof XSLWhen)) {
58 AxisIterator sibs = inst.iterateAxis(AxisInfo.FOLLOWING_SIBLING);
59 while (true) {
60 NodeInfo sib = sibs.next();
61 if (sib == null) {
62 break;
63 }
64 if (sib instanceof XSLFallback || sib instanceof XSLCatch) {
65 continue;
66 }
67 isLast = false;
68 }
69 }
70 inst = inst.getParent();
71 if (inst instanceof XSLIterate) {
72 xslIterate = (XSLIterate) inst;
73 break;
74 } else if (inst instanceof XSLTry || inst instanceof XSLCatch) {
75 //compilable = false;
76 } else if (inst instanceof XSLWhen || inst instanceof XSLOtherwise
77 || inst instanceof XSLIf || inst instanceof XSLChoose) {
78 // continue;
79 } else if (inst == null) {
80 compileError(getDisplayName() + " is not allowed at outermost level", "XTSE3120");//XTSE0010
81 return;
82 } else {
83 compileError(getDisplayName() + " is not allowed within " + inst.getDisplayName(), "XTSE3120");//XTSE0010
84 return;
85 }
86 }
87 if (!isLast) {
88 compileError(getDisplayName() + " must be the last instruction in the xsl:iterate loop", "XTSE3120");
89 }
90 }
91 }