View Javadoc

1   /*
2    * Copyright 2002,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  package org.apache.commons.jelly.tags.jsl;
17  
18  import org.apache.commons.jelly.JellyContext;
19  import org.apache.commons.jelly.expression.ExpressionSupport;
20  import org.dom4j.rule.Pattern;
21  import org.jaxen.VariableContext;
22  
23  /*** An expression which returns an XPath based Pattern (like an XSLT pattern).
24    *
25    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
26    * @version $Revision: 155420 $
27    */
28  public class XPathPatternExpression extends ExpressionSupport implements VariableContext {
29  
30      private String text;
31      private Pattern pattern;
32      private JellyContext context;
33  
34      public XPathPatternExpression(String text, Pattern pattern) {
35          this.text = text;
36          this.pattern = pattern;
37      }
38  
39      // Expression interface
40      //-------------------------------------------------------------------------
41      public String getExpressionText() {
42          return text;
43      }
44  
45      public Object evaluate(JellyContext context) {
46          this.context = context;
47          //pattern.setVariableContext(this);
48          return pattern;
49      }
50  
51      // VariableContext interface
52      //-------------------------------------------------------------------------
53      public Object getVariableValue(
54          String namespaceURI,
55          String prefix,
56          String localName) {
57  
58          Object value = context.getVariable(localName);
59  
60          //log.info( "Looking up XPath variable of name: " + localName + " value is: " + value );
61  
62          return value;
63      }
64  }