shawn       01/09/19 22:22:30

  Modified:    jsptl    README build.xml
               jsptl/doc/web GettingStarted.html index.html
  Added:       jsptl/lib commons-JXPath-0.1-dev.jar
               jsptl/src/org/apache/taglibs/jsptl/lang/jxpath
                        JXPathExpressionEvaluator.java
  Log:
  Integration of JXPath as an alternative expression language.
  Submitted by: Dmitri Plotnikov, Pierre Delisle
  Reviewed by: Shawn Bayern
  
  Revision  Changes    Path
  1.2       +1 -0      jakarta-taglibs/jsptl/README
  
  Index: README
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/jsptl/README,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- README    2001/07/08 16:25:41     1.1
  +++ README    2001/09/20 05:22:30     1.2
  @@ -57,6 +57,7 @@
         .support  ExpressionEvaluator, ExpressionEvaluatorManager
         .spel     SPEL
         .jpath JPath
  +      .jxpath   JXPath
   
   
   Enjoy!
  
  
  
  1.3       +40 -3     jakarta-taglibs/jsptl/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/jsptl/build.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.xml 2001/07/08 17:53:34     1.2
  +++ build.xml 2001/09/20 05:22:30     1.3
  @@ -31,16 +31,16 @@
       <property name="dist-jr.tld"    
value="${dist.dir}/${taglib.name}/${taglib.name}-jr.tld"/>
       <property name="dist-jx.tld"    
value="${dist.dir}/${taglib.name}/${taglib.name}-jx.tld"/>
       <property name="dist-scriptfree.tld"    
value="${dist.dir}/${taglib.name}/${taglib.name}-scriptfree.tld"/>
  +    <property name="jxpath.jar"          value="lib/commons-JXPath-0.1-dev.jar"/>
   
     <!-- ********************** Destination Preparation ********************* -->
   
     <target name="prepare">
  -    <!-- Make sure the servlet23.jar is available -->
  +    <!-- Make sure required dependencies are available -->
       <antcall target="checkRequiredFile">
          <param name="file" value="${servlet23.jar}"/>
          <param name="fail.message" value="A jar file containing the Servlet 2.3 and 
JSP1.2 classes is required to compile the jsptl taglib. please define the property 
servlet23.jar in your build.properties file and ensure that the file exists."/>
       </antcall>
  -    <!-- Make sure that jaxp.jar and crimson.jar are available -->
       <antcall target="checkRequiredFile">
          <param name="file" value="${jaxp.jar}"/>
          <param name="fail.message" value="The jsptl taglib required the JAXP 1.1 
jaxp.jar file, please define the property jaxp.jar in your build.properties file and 
ensure that the file exists."/>
  @@ -49,6 +49,13 @@
          <param name="file" value="${crimson.jar}"/>     
          <param name="fail.message" value="The jsptl taglib required the JAXP 1.1 
crimson.jar file, please define the property crimson.jar in your build.properties file 
and ensure that the file exists."/>
       </antcall>
  +    <!--
  +    <antcall target="checkOptionalFile">
  +       <param name="file" value="${jxpath.jar}"/>
  +       <param name="warn.message" value="The jsptl taglib requires that you provide 
the JXPath JAR if you desire support of the JXPath Expression Language.  Since the 
property jxpath.jar in your build.properties file does not point to a valid file or is 
not defined, JXPath support will not be included in the compilation or the 'example' 
application."/>
  +    </antcall>
  +    -->
  +
       <!-- Set up build directories -->
       <mkdir dir="${build.dir}"/>
       <mkdir dir="${build.doc}"/>
  @@ -95,6 +102,10 @@
       <copy todir="${build.examples}">
         <fileset dir="${examples.src}/web"/>
       </copy>
  +    <!-- Copy implementation-detail jar files -->
  +    <copy todir="${build.examples}/WEB-INF/lib">
  +      <fileset dir="lib" includes="*.jar"/>
  +    </copy>
       <!-- Copy required external API jar files -->
       <copy file="${jaxp.jar}"
             tofile="${build.examples}/WEB-INF/lib/jaxp.jar"/>
  @@ -125,10 +136,29 @@
            <include name="**/*.properties"/>
        </fileset>
       </copy>
  +<!--
  +    - [ for optional JXPath (versus integrated JXPath) ... ] -
  +    <javac srcdir="${library.src}" destdir="${build.library}"
  +           classpath="${servlet23.jar}"
  +        excludes="org/apache/taglibs/jsptl/lang/jxpath/**"
  +        debug="on"/>
  +    <available file="${jxpath.jar}" property="jxpath.available"/>
  +    <antcall target="libraryJXPath"/>
  +  </target>
  +
  +  <target name="libraryJXPath" if="jxpath.available">
       <javac srcdir="${library.src}" destdir="${build.library}"
  -           classpath="${servlet23.jar}" debug="on"/>
  +     classpath="${servlet23.jar}"
  +     includes="org/apache/taglibs/jsptl/lang/jxpath/**"
  +     debug="on"/>
     </target>
  +-->
   
  +    <javac srcdir="${library.src}" destdir="${build.library}"
  +           classpath="${servlet23.jar}:${jxpath.jar}"
  +        debug="on"/>
  +  </target>
  +
     <!-- Compile the library as well as the associated applications -->
     <target name="main" depends="library,documentation,examples"/>
   
  @@ -184,8 +214,15 @@
       <available file="${file}" property="requirement.satisfied"/>
       <antcall target="checkRequired.fail"/>
     </target>
  +  <target name="checkOptionalFile">
  +    <available file="${file}" property="requirement.satisfied"/>
  +    <antcall target="checkRequired.warn"/>
  +  </target>
     <target name="checkRequired.fail" unless="requirement.satisfied">
       <fail message="${fail.message}"/>
  +  </target>
  +  <target name="checkRequired.warn" unless="requirement.satisfied">
  +    <echo message="WARNING: ${warn.message}"/>
     </target>
   
   </project>
  
  
  
  1.6       +9 -7      jakarta-taglibs/jsptl/doc/web/GettingStarted.html
  
  Index: GettingStarted.html
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/jsptl/doc/web/GettingStarted.html,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GettingStarted.html       2001/09/11 01:13:20     1.5
  +++ GettingStarted.html       2001/09/20 05:22:30     1.6
  @@ -123,19 +123,21 @@
   expression languages you wish to use.  (JSPTL EA1 supports "pluggable"
   expression languages to facilitate experimentation.)  We recommend
   beginning with the <a href="spel">"simplest possible expression language"
  -(SPEL)</a> and determining if it meets your needs.  If you want to experiment
  -with more complex expressions, you can also use the provide "JPath"
  -language.  And you can always plug in your own expressions using the
  -mechanisms described below.</p>
  +(SPEL)</a> and determining if it meets your needs.  If you want to
  +experiment with more complex expressions, you can also use either of the
  +provided "JPath" or "JXPath" languages.  And you can always plug in your
  +own expressions using the mechanisms described below.</p>
   
   <p>The default expression language for a web application is configured by
   setting the servlet context parameter
   <tt>javax.servlet.jsptl.ExpressionEvaluatorClass</tt> to the class
   containing the expression-evaluation logic you wish to use. In
   <tt>jsptl.jar</tt>, the SPEL is identified by the class
  -<tt>org.apache.taglibs.jsptl.lang.spel.Evaluator</tt>, and JPath is
  -identified by the class
  -<tt>org.apache.taglibs.jsptl.lang.jpath.JPathExpressionEvaluator</tt>.
  +<tt>org.apache.taglibs.jsptl.lang.spel.Evaluator</tt>, JPath is identified
  +by the class
  +<tt>org.apache.taglibs.jsptl.lang.jpath.JPathExpressionEvaluator</tt>, and
  +JXPath's evaluator is
  +<tt>org.apache.taglibs.jsptl.lang.jxpath.JXPathExpressionEvaluator</tt>
   (For an example of how this context parameter is set, see the
   <tt>web.xml</tt> file that comes with the <tt>jsptl-examples</tt>
   application.)</p>
  
  
  
  1.4       +1 -0      jakarta-taglibs/jsptl/doc/web/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/jsptl/doc/web/index.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- index.html        2001/07/24 00:12:56     1.3
  +++ index.html        2001/09/20 05:22:30     1.4
  @@ -88,6 +88,7 @@
         .support  ExpressionEvaluator, ExpressionEvaluatorManager
         .spel     SPEL
         .jpath JPath
  +      .jxpath   JXPath
   </pre>
   
   <p>Enjoy!</p>
  
  
  
  1.1                  jakarta-taglibs/jsptl/lib/commons-JXPath-0.1-dev.jar
  
        <<Binary file>>
  
  
  1.1                  
jakarta-taglibs/jsptl/src/org/apache/taglibs/jsptl/lang/jxpath/JXPathExpressionEvaluator.java
  
  Index: JXPathExpressionEvaluator.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.taglibs.jsptl.lang.jxpath;
  
  import org.apache.commons.jxpath.JXPathContext;
  import org.apache.commons.jxpath.servlet.JXPathServletContexts;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import org.apache.taglibs.jsptl.lang.support.*;
  import javax.servlet.jsptl.IteratorTag;
  import java.util.*;
  
  /**
   * <p>An ExpressionEvaluation that evaluates expressions against the JXPath
   * implementation of the XPath language.  JXPath is found in Jakarta
   * Commons.</p>
   *
   * <p>NOTE: The current version of this expression-language interpreter
   * does not support translation-time validation of requests.</p>
   * 
   * @author Dmitri Plotnikov
   * @author Shawn Bayern
   */
  public class JXPathExpressionEvaluator implements ExpressionEvaluator {
  
      /**
       * Translation time validation of an expression.
       * This method will return a null String if the expression
       * is valid; otherwise an error message.
       */
      public String validate(String attributeName,
                                 String expression) {
          String result = null;
          // TBD
          return result;
      }
  
      /**
       * Evaluates the expression at request time.
       */
      public Object evaluate(String attributeName,
                             String expression,
                             Class expectedType,
                             Tag tag,
                             PageContext pageContext)
                             throws JspException {
          try {
              // System.err.println("TAG: " + tag + " " + attributeName);
              JXPathContext context =
                JXPathServletContexts.getPageContext(pageContext);
              Object result = null;
              if ((tag instanceof IteratorTag) && attributeName.equals("items")) {
                  List list = context.eval(expression);
                  if (list.size() == 1)
                      if (list.get(0) instanceof Map)
                          result = list.get(0);
                  if (result == null)
                      result = list;
              }
              else
                  result = context.getValue(expression, expectedType);
              return ((result != null) ? result : "");
          }
          catch (Exception ex) {
              // ex.printStackTrace();
              throw new JspException(ex.getMessage());
          }
      }
  }
  
  
  

Reply via email to