commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf ScriptTag.java BSFTagLibrary.java
Date Thu, 20 Feb 2003 18:56:16 GMT
jstrachan    2003/02/20 10:56:16

  Modified:    jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf
                        BSFTagLibrary.java
  Added:       jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf
                        ScriptTag.java
  Log:
  Added an initial version of a <script> tag to the BSF library which should be usable
in JavaScript, Jython, PNuts etc
  
  Revision  Changes    Path
  1.2       +41 -3     jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java
  
  Index: BSFTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BSFTagLibrary.java	8 Jan 2003 05:02:47 -0000	1.1
  +++ BSFTagLibrary.java	20 Feb 2003 18:56:16 -0000	1.2
  @@ -61,8 +61,15 @@
    */
   package org.apache.commons.jelly.tags.bsf;
   
  +import org.apache.commons.jelly.JellyException;
  +import org.apache.commons.jelly.Tag;
   import org.apache.commons.jelly.expression.ExpressionFactory;
  +import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.tags.core.CoreTagLibrary;
  +import org.xml.sax.Attributes;
  +
  +import com.ibm.bsf.BSFEngine;
  +import com.ibm.bsf.BSFException;
   
   
   /** Describes the Taglib. This class could be generated by XDoclet
  @@ -74,6 +81,18 @@
   
       private BSFExpressionFactory expressionFactory = new BSFExpressionFactory();
       
  +    public BSFTagLibrary() {
  +        registerTagFactory(
  +			"script", 
  +			new TagFactory() {
  +                public Tag createTag(String name, Attributes attributes)
  +                    throws JellyException {
  +                    return createScriptTag(name, attributes);
  +                }
  +			}
  +		);	
  +    }
  +
       public void setLanguage(String language) {
           expressionFactory.setLanguage(language);
       }
  @@ -83,4 +102,23 @@
           return expressionFactory;
       }
   
  +	protected BSFEngine getBSFEngine() throws BSFException {
  +	    return expressionFactory.getBSFEngine();
  +	}
  +        
  +    /**
  +     * Factory method to create a new ScriptTag with a BSFEngine
  +     * 
  +     * @param name is the name of the tag (typically 'script')
  +     * @param attributes the attributes of the tag
  +     * @return Tag
  +     */
  +    protected Tag createScriptTag(String name, Attributes attributes) throws JellyException
{
  +        try {
  +            return new ScriptTag( expressionFactory.getBSFEngine() );
  +        }
  +        catch (BSFException e) {
  +            throw new JellyException("Failed to create BSFEngine: " + e, e);
  +        }
  +    }
   }
  
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/ScriptTag.java
  
  Index: ScriptTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/ScriptTag.java,v
1.1 2003/02/20 18:56:16 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/02/20 18:56:16 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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", "Commons", 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 apache@apache.org.
   *
   * 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/>.
   * 
   * $Id: ScriptTag.java,v 1.1 2003/02/20 18:56:16 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.bsf;
  
  import org.apache.commons.jelly.JellyTagException;
  import org.apache.commons.jelly.LocationAware;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import com.ibm.bsf.BSFEngine;
  import com.ibm.bsf.BSFException;
  
  /** 
   * A tag which evaluates its body using the current scripting language
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class ScriptTag extends TagSupport implements LocationAware {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(ScriptTag.class.getName() + ".evaluating");
  	
      private BSFEngine engine;
      private String elementName;
      private String fileName;
      private int columnNumber;
      private int lineNumber;
      
      public ScriptTag(BSFEngine engine) {
          this.engine = engine;
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException
{
          String text = getBodyText();
  
  		log.debug(text);        
          
          try {
              engine.eval(fileName, lineNumber, columnNumber, text);
          }
          catch (BSFException e) {
              throw new JellyTagException("Error occurred with script: " + e, e);
          }
          
      }
      
      // Properties
      //-------------------------------------------------------------------------        
       
      /**
       * @return int
       */
      public int getColumnNumber() {
          return columnNumber;
      }
  
      /**
       * @return String
       */
      public String getElementName() {
          return elementName;
      }
  
      /**
       * @return BSFEngine
       */
      public BSFEngine getEngine() {
          return engine;
      }
  
      /**
       * @return String
       */
      public String getFileName() {
          return fileName;
      }
  
      /**
       * @return int
       */
      public int getLineNumber() {
          return lineNumber;
      }
  
      /**
       * Sets the columnNumber.
       * @param columnNumber The columnNumber to set
       */
      public void setColumnNumber(int columnNumber) {
          this.columnNumber = columnNumber;
      }
  
      /**
       * Sets the elementName.
       * @param elementName The elementName to set
       */
      public void setElementName(String elementName) {
          this.elementName = elementName;
      }
  
      /**
       * Sets the engine.
       * @param engine The engine to set
       */
      public void setEngine(BSFEngine engine) {
          this.engine = engine;
      }
  
      /**
       * Sets the fileName.
       * @param fileName The fileName to set
       */
      public void setFileName(String fileName) {
          this.fileName = fileName;
      }
  
      /**
       * Sets the lineNumber.
       * @param lineNumber The lineNumber to set
       */
      public void setLineNumber(int lineNumber) {
          this.lineNumber = lineNumber;
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message