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