Debian Codegraph @

net/sf/saxon/event/NoOpenStartTagException.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.event;
9
10 import net.sf.saxon.Configuration;
11 import net.sf.saxon.expr.parser.Location;
12 import net.sf.saxon.lib.StandardErrorListener;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.type.Type;
15
16 /**
17 * Exception indicating that an attribute or namespace node has been written when
18 * there is no open element to write it to
19 */
20
21 public class NoOpenStartTagException extends XPathException {
22
23 /**
24 * Static factory method to create the exception
25 *
26 * @param nodeKind the kind of node being created (attribute or namespace)
27 * @param name the name of the node being created
28 * @param hostLanguage XSLT or XQuery (error codes are different in the two cases)
29 * @param parentIsDocument true if the nodes are being added to a document node (rather than an element)
30 * @param startElementLocationId integer that can be passed to the location provider to get the location
31 * of the offending instruction that created the element node
32 * @return the constructed exception object
33 */
34
35 public static NoOpenStartTagException makeNoOpenStartTagException(
36 int nodeKind, String name, int hostLanguage, boolean parentIsDocument,
37 /*@Nullable*/ Location startElementLocationId) {
38 String message;
39 String errorCode;
40 if (parentIsDocument) {
41 String kind = nodeKind == Type.ATTRIBUTE ? "an attribute" : "a namespace";
42 message = "Cannot create " + kind + " node (" + name + ") whose parent is a document node";
43 errorCode = hostLanguage == Configuration.XSLT ? "XTDE0420" : "XPTY0004";
44 } else {
45 String kind = nodeKind == Type.ATTRIBUTE ? "An attribute" : "A namespace";
46 message = kind + " node (" + name + ") cannot be created after a child of the containing element";
47 errorCode = hostLanguage == Configuration.XSLT ? "XTDE0410" : "XQTY0024";
48 }
49 if (startElementLocationId != null && startElementLocationId.getLineNumber() != -1) {
50 message += ". Most recent element start tag was output at line " +
51 startElementLocationId.getLineNumber() + " of module " +
52 StandardErrorListener.abbreviatePath(startElementLocationId.getSystemId());
53 }
54 NoOpenStartTagException err = new NoOpenStartTagException(message);
55 err.setErrorCode(errorCode);
56 return err;
57 }
58
59 public NoOpenStartTagException(String message) {
60 super(message);
61 }
62
63
64 }
65