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.junit;
17  
18  import org.apache.commons.jelly.TagLibrary;
19  
20  import org.apache.commons.jelly.JellyException;
21  import org.apache.commons.jelly.TagLibrary;
22  import org.apache.commons.jelly.expression.Expression;
23  import org.apache.commons.jelly.expression.ExpressionFactory;
24  import org.apache.commons.jelly.impl.TagScript;
25  import org.apache.commons.jelly.expression.xpath.XPathExpression;
26  
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  
30  import org.jaxen.JaxenException;
31  
32  /*** Describes the Taglib. This class could be generated by XDoclet
33    *
34    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
35    * @version $Revision: 345796 $
36    */
37  public class JUnitTagLibrary extends TagLibrary {
38  
39      /*** The Log to which logging calls will be made. */
40      private Log log = LogFactory.getLog(JUnitTagLibrary.class);
41  
42      public JUnitTagLibrary() {
43          registerTag("assert", AssertTag.class);
44          registerTag("assertEquals", AssertEqualsTag.class);
45          registerTag("assertFileContains", AssertFileContainsTag.class);
46          registerTag("assertFileExists", AssertFileExistsTag.class);
47          registerTag("assertFileNotFound", AssertFileNotFoundTag.class);
48          registerTag("assertThrows", AssertThrowsTag.class);
49          registerTag("fail", FailTag.class);
50          registerTag("run", RunTag.class );
51          registerTag("case", CaseTag.class );
52          registerTag("suite", SuiteTag.class );
53      }
54  
55      public Expression createExpression(
56          ExpressionFactory factory,
57          TagScript tagScript,
58          String attributeName,
59          String attributeValue) throws JellyException {
60  
61          // #### may need to include some namespace URI information in the XPath instance?
62  
63          if (attributeName.equals("xpath")) {
64              if ( log.isDebugEnabled() ) {
65                  log.debug( "Parsing XPath expression: " + attributeValue );
66              }
67  
68              // XPath xpath = new Dom4jXPath(attributeValue);
69              Expression xpathExpr = super.createExpression( factory,
70                                                                 tagScript,
71                                                                 attributeName,
72                                                                 attributeValue );
73  
74              return new XPathExpression(attributeValue, xpathExpr, tagScript);
75          }
76  
77          // will use the default expression instead
78          return super.createExpression(factory, tagScript, attributeName, attributeValue);
79      }
80  }