KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xpath > functions > FuncExtElementAvailable


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: FuncExtElementAvailable.java,v 1.12 2004/02/17 04:34:00 minchau Exp $
18  */

19 package org.apache.xpath.functions;
20
21 import org.apache.xalan.templates.Constants;
22 import org.apache.xalan.transformer.TransformerImpl;
23 import org.apache.xml.utils.QName;
24 import org.apache.xpath.ExtensionsProvider;
25 import org.apache.xpath.XPathContext;
26 import org.apache.xpath.objects.XBoolean;
27 import org.apache.xpath.objects.XObject;
28
29 /**
30  * Execute the ExtElementAvailable() function.
31  * @xsl.usage advanced
32  */

33 public class FuncExtElementAvailable extends FunctionOneArg
34 {
35
36   /**
37    * Execute the function. The function must return
38    * a valid object.
39    * @param xctxt The current execution context.
40    * @return A valid XObject.
41    *
42    * @throws javax.xml.transform.TransformerException
43    */

44   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException JavaDoc
45   {
46
47     String JavaDoc prefix;
48     String JavaDoc namespace;
49     String JavaDoc methName;
50
51     String JavaDoc fullName = m_arg0.execute(xctxt).str();
52     int indexOfNSSep = fullName.indexOf(':');
53
54     if (indexOfNSSep < 0)
55     {
56       prefix = "";
57       namespace = Constants.S_XSLNAMESPACEURL;
58       methName = fullName;
59     }
60     else
61     {
62       prefix = fullName.substring(0, indexOfNSSep);
63       namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
64       if (null == namespace)
65         return XBoolean.S_FALSE;
66       methName= fullName.substring(indexOfNSSep + 1);
67     }
68
69     if (namespace.equals(Constants.S_XSLNAMESPACEURL)
70     || namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL))
71     {
72       try
73       {
74         TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
75         return transformer.getStylesheet().getAvailableElements().containsKey(
76                                                             new QName(namespace, methName))
77                ? XBoolean.S_TRUE : XBoolean.S_FALSE;
78       }
79       catch (Exception JavaDoc e)
80       {
81         return XBoolean.S_FALSE;
82       }
83     }
84     else
85     {
86       //dml
87
ExtensionsProvider extProvider = (ExtensionsProvider)xctxt.getOwnerObject();
88       return extProvider.elementAvailable(namespace, methName)
89              ? XBoolean.S_TRUE : XBoolean.S_FALSE;
90     }
91   }
92 }
93
Popular Tags