costin      01/06/12 08:06:09

  Modified:    jasper34/generator/org/apache/jasper34/core Mangler.java
                        Options.java
  Log:
  Transformed Mangler and Options into classes.
  
  Moved all the duplicated code from the 3 options implementations in Options,
  with a PropertyAdapter interface to plug Properties, ServletConfig or
  other similar option repositories.
  
  This will cut a lot of duplicated code and simplify the code.
  
  Revision  Changes    Path
  1.2       +43 -5     
jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/Mangler.java
  
  Index: Mangler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/Mangler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Mangler.java      2001/06/06 05:44:58     1.1
  +++ Mangler.java      2001/06/12 15:06:05     1.2
  @@ -67,24 +67,62 @@
    *
    * @author Anil K. Vijendran
    */
  -public interface Mangler {
  +public abstract class Mangler {
  +    protected String baseDir;
  +    protected String classDir;
  +    protected String srcFile;
       
  +
  +    public void init( String classDir, String baseDir, String srcFile ) {
  +     this.srcFile=srcFile;
  +     this.baseDir=baseDir;
  +     this.classDir=classDir;
  +    }
  +    
  +    
       /** The class name ( without package ) of the
        *  generated servlet, including the version number
        */
  -    String getClassName();
  +    public abstract String getClassName();
   
       /** The package name. It is based on the .jsp path, with
        *  all unsafe components escaped.
        */
  -    String getPackageName();
  +    public abstract String getPackageName();
   
       /** The full name of the .java file, including
        *  version number ( based on className and outputDir )
        */
  -    String getJavaFileName();
  +    public abstract String getJavaFileName();
   
       /** The full name of the .class file ( without version number)
        */
  -    String getClassFileName();
  +    public abstract String getClassFileName();
  +
  +    // -------------------- Utils --------------------
  +
  +    /** The class name ( package + class + versioning ) of the
  +     *  compilation result
  +     */
  +    public String getServletClassName() {
  +     if( getPackageName() !=null ) {
  +         return getPackageName()  + "." + getClassName();
  +     } else {
  +         return getClassName();
  +     }
  +    }
  +    
  +    // -------------------- Versioning support --------------------
  +
  +    public int getVersion() {
  +     return 0;
  +    }
  +
  +    public void nextVersion() {
  +    }
  +
  +    // -------------------- Utils --------------------
  +
  +    
  +    
   }
  
  
  
  1.4       +128 -34   
jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/Options.java
  
  Index: Options.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/core/Options.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Options.java      2001/06/09 21:23:31     1.3
  +++ Options.java      2001/06/12 15:06:06     1.4
  @@ -62,6 +62,10 @@
   import javax.servlet.ServletConfig;
   import javax.servlet.ServletContext;
   
  +// Made it a base class, backed by a simple properties-like adapter interface.
  +// This should work for both Properties and ServletConfig ( or other apis )
  +// Added static final strings with all the known properties.
  +
   /**
    * A class to hold all init parameters specific to the JSP engine.
    *
  @@ -73,72 +77,162 @@
    * @author Anil K. Vijendran
    * @author Hans Bergsten
    */
  -public interface Options {
  -    /**
  -     * Are we keeping generated code around?
  -     */
  -    public boolean getKeepGenerated();
  +public class Options {
  +
  +    public static interface PropertyAdapter {
  +     public String getProperty( String key, String defaultValue );
  +     public void setProperty( String key, String value );
  +    }
       
  -    /**
  -     * Are we supporting large files?
  -     */
  -    public boolean getLargeFile();
  +    PropertyAdapter args;
  +    
  +    public Options(PropertyAdapter args) {
  +     this.args=args;
  +    }
  +    // -------------------- Access to repository --------------------
  +
  +    public PropertyAdapter getPropertyAdapter() {
  +     return args;
  +    }
  +
  +    // -------------------- Known properties --------------------
  +    
  +    public static final String KEEP_GENERATED="keepgenerated";
  +    public static final String SEND_ERROR_TO_CLIENT="sendErrToClient";
  +    public static final String CLASS_DEBUG_INFO="classDebugInfo";
  +    public static final String CLASS_PATH="classpath";
  +    public static final String SCRATCH_DIR="scratchdir";    
  +    public static final String MAPPED_FILE="mappedfile";
   
  +    static final String DEFAULT_IE_CLASS_ID =
  +     "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
  +
  +
  +    // -------------------- Getter methods --------------------
  +    
       /**
  -     * Are we supporting HTML mapped servlets?
  +     * Are we keeping generated code around?
        */
  -    public boolean getMappedFile();
  +    public boolean getKeepGenerated() {
  +     return s2b( args.getProperty(KEEP_GENERATED, "true") );
  +    }
       
  +    /**
  +     * Do you want support for "large" files? What this essentially
  +     * means is that we generated code so that the HTML data in a JSP
  +     * file is stored separately as opposed to those constant string
  +     * data being used literally in the generated servlet. 
  +     */
  +    public boolean getLargeFile() {
  +        return s2b( args.getProperty("largefile", "false"));
  +    }
  +
  +    /**
  +     * Do you want support for "mapped" files? This will generate
  +     * servlet that has a print statement per line of the JSP file.
  +     * This seems like a really nice feature to have for debugging.
  +     */
  +    public boolean getMappedFile() {
  +        return s2b( args.getProperty(MAPPED_FILE, "false"));
  +    }
       
       /**
  -     * Should errors be sent to client or thrown into stderr?
  -     */
  -    public boolean getSendErrorToClient();
  +     * Do you want stack traces and such displayed in the client's
  +     * browser? If this is false, such messages go to the standard
  +     * error or a log file if the standard error is redirected. 
  +     */
  +    public boolean getSendErrorToClient() {
  +     return s2b( args.getProperty( SEND_ERROR_TO_CLIENT, "false" ));
  +    }
    
       /**
        * Should we include debug information in compiled class?
  -     */
  -    public boolean getClassDebugInfo();
  -
  -    /**
  -     * Class ID for use in the plugin tag when the browser is IE. 
        */
  -    public String getIeClassId();
  -    
  -    /**
  -     * What is my scratch dir?
  -     */
  -    public File getScratchDir();
  +    public boolean getClassDebugInfo() {
  +        return s2b( args.getProperty( CLASS_DEBUG_INFO, "false" ));
  +    }
  +
  +    /**
  +     * Need to have this as is for versions 4 and 5 of IE. Can be set from
  +     * the initParams so if it changes in the future all that is needed is
  +     * to have a jsp initParam of type ieClassId="<value>"
  +     */
  +    public String getIeClassId() {
  +     return args.getProperty( "ieClassId" , DEFAULT_IE_CLASS_ID);
  +    }
  +
  +    // Validation should be done by the caller.
  +    /**
  +     * I want to see my generated servlets. Which directory are they
  +     * in?
  +     */
  +    public File getScratchDir() {
  +     return new File( args.getProperty( SCRATCH_DIR, null ));
  +
  +     /* XXX integrate ( from Embeded )
  +     scratchDir = (File) context.getAttribute(Constants.TMP_DIR);
  +     if (scratchDir == null) {
  +     dir = System.getProperty("java.io.tmpdir");
  +     if (dir != null)
  +     scratchDir = new File(dir);
  +     */
  +
  +     /*
  +       if (!(scratchDir.exists() && scratchDir.canRead() &&
  +       scratchDir.canWrite() && scratchDir.isDirectory()))
  +     */
  +    }
   
       /**
        * What classpath should I use while compiling the servlets
        * generated from JSP files?
        */
  -    public String getClassPath();
  +    public String getClassPath() {
  +     return args.getProperty( CLASS_PATH , null );
  +    }
   
  +    // Used to be Class - keep this simple, the caller should be able to
  +    // handle
       /**
        * What compiler plugin should I use to compile the servlets
        * generated from JSP files?
        */
  -    public Class getJspCompilerPlugin();
  +    public String getJspCompilerPlugin() {
  +     String type=args.getProperty( "jspCompilerPlugin", null );
  +     return type;
  +    }
   
       /**
        * Path of the compiler to use for compiling JSP pages.
        */
  -    public String getJspCompilerPath();
  +    public String getJspCompilerPath() {
  +     return args.getProperty( "jspCompilerPath", null );
  +    }
       
  -    /**
  -     * ProtectionDomain for this JSP Context when using a SecurityManager
  -     */
  -    public Object getProtectionDomain();
  +//     /**
  +//      * ProtectionDomain for this JSP Context when using a SecurityManager
  +//      */
  +//     public Object getProtectionDomain();
   
       /**
        * Java platform encoding to generate the JSP
        * page servlet.
        */
  -    public String getJavaEncoding();
  +    public String getJavaEncoding() {
  +     return args.getProperty("javaEncoding", "UTF8");
  +    }
   
       /** Generate comment-style line number mappings
        */
  -    public boolean getGenerateCommentMapping();
  +    public boolean getGenerateCommentMapping() {
  +     return s2b(args.getProperty( "generateCommentMapping", "false"));
  +    }
  +
  +    // -------------------- Helpers --------------------
  +
  +    protected boolean s2b( String s ) {
  +     return new Boolean( s ).booleanValue();
  +     // XXX Add validation
  +    }
  +
   }
  
  
  

Reply via email to