KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > extensions > ExpressionVisitor


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: ExpressionVisitor.java,v 1.7 2004/02/11 05:26:23 minchau Exp $
18  */

19 package org.apache.xalan.extensions;
20
21 import org.apache.xalan.templates.StylesheetRoot;
22 import org.apache.xpath.ExpressionOwner;
23 import org.apache.xpath.XPathVisitor;
24 import org.apache.xpath.functions.FuncExtFunction;
25 import org.apache.xpath.functions.FuncExtFunctionAvailable;
26 import org.apache.xpath.functions.Function;
27
28 /**
29  * When {@link org.apache.xalan.processor.StylesheetHandler} creates
30  * an {@link org.apache.xpath.XPath}, the ExpressionVisitor
31  * visits the XPath expression. For any extension functions it
32  * encounters, it instructs StylesheetRoot to register the
33  * extension namespace.
34  *
35  * This mechanism is required to locate extension functions
36  * that may be embedded within an expression.
37  */

38 public class ExpressionVisitor extends XPathVisitor
39 {
40   private StylesheetRoot m_sroot;
41   
42   /**
43    * The constructor sets the StylesheetRoot variable which
44    * is used to register extension namespaces.
45    * @param sroot the StylesheetRoot that is being constructed.
46    */

47   public ExpressionVisitor (StylesheetRoot sroot)
48   {
49     m_sroot = sroot;
50   }
51   
52   /**
53    * If the function is an extension function, register the namespace.
54    *
55    * @param owner The current XPath object that owns the expression.
56    * @param function The function currently being visited.
57    *
58    * @return true to continue the visit in the subtree, if any.
59    */

60   public boolean visitFunction(ExpressionOwner owner, Function func)
61   {
62     if (func instanceof FuncExtFunction)
63     {
64       String JavaDoc namespace = ((FuncExtFunction)func).getNamespace();
65       m_sroot.getExtensionNamespacesManager().registerExtension(namespace);
66     }
67     else if (func instanceof FuncExtFunctionAvailable)
68     {
69       String JavaDoc arg = ((FuncExtFunctionAvailable)func).getArg0().toString();
70       if (arg.indexOf(":") > 0)
71       {
72         String JavaDoc prefix = arg.substring(0,arg.indexOf(":"));
73         String JavaDoc namespace = this.m_sroot.getNamespaceForPrefix(prefix);
74         m_sroot.getExtensionNamespacesManager().registerExtension(namespace);
75       }
76     }
77     return true;
78   }
79
80 }
81
Popular Tags