KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > UnparsedEntity


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.expr.StaticContext;
4 import net.sf.saxon.expr.XPathContext;
5 import net.sf.saxon.om.DocumentInfo;
6 import net.sf.saxon.om.Item;
7 import net.sf.saxon.trans.XPathException;
8 import net.sf.saxon.value.StringValue;
9
10 /**
11 * Implements the unparsed-entity-uri() function defined in XSLT 1.0
12 * and the unparsed-entity-public-id() function defined in XSLT 2.0
13 */

14
15
16 public class UnparsedEntity extends SystemFunction implements XSLTFunction {
17
18     public static int URI = 0;
19     public static int PUBLIC_ID = 1;
20
21     /**
22     * Simplify: add a second implicit argument, the context document
23     */

24
25      public Expression simplify(StaticContext env) throws XPathException {
26         UnparsedEntity f = (UnparsedEntity)super.simplify(env);
27         f.addContextDocumentArgument(1, (operation==URI ? "unparsed-entity-uri_9999_": "unparsed-entity-public-id_9999_"));
28         return f;
29     }
30
31     /**
32     * preEvaluate: this method suppresses compile-time evaluation by doing nothing
33     */

34
35     public Expression preEvaluate(StaticContext env) {
36         return this;
37     }
38
39     /**
40     * Evaluate the expression
41     */

42
43     public Item evaluateItem(XPathContext context) throws XPathException {
44         String JavaDoc arg0 = argument[0].evaluateItem(context).getStringValue();
45         Item doc = argument[1].evaluateItem(context);
46         if (!(doc instanceof DocumentInfo)) {
47             String JavaDoc code = (operation==URI ? "XTDE1370" : "XTDE1380");
48             dynamicError("In function " + getDisplayName(context.getController().getNamePool()) +
49                             ", the context node must be in a tree whose root is a document node", code, context);
50         }
51         String JavaDoc[] ids = ((DocumentInfo)doc).getUnparsedEntity(arg0);
52         if (ids==null) return StringValue.EMPTY_STRING;
53         return new StringValue(ids[operation]);
54     }
55
56 }
57
58
59
60
61 //
62
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
63
// you may not use this file except in compliance with the License. You may obtain a copy of the
64
// License at http://www.mozilla.org/MPL/
65
//
66
// Software distributed under the License is distributed on an "AS IS" basis,
67
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
68
// See the License for the specific language governing rights and limitations under the License.
69
//
70
// The Original Code is: all this file.
71
//
72
// The Initial Developer of the Original Code is Michael H. Kay.
73
//
74
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
75
//
76
// Contributor(s): none.
77
//
78
Popular Tags