glenn       02/04/30 19:40:37

  Modified:    jasper2/src/share/org/apache/jasper JspEngineContext.java
               jasper2/src/share/org/apache/jasper/servlet JspServlet.java
                        JspServletWrapper.java
  Log:
  Reformat code to more closely match coding conventions
  
  Revision  Changes    Path
  1.5       +22 -29    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java
  
  Index: JspEngineContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JspEngineContext.java     1 May 2002 01:33:42 -0000       1.4
  +++ JspEngineContext.java     1 May 2002 02:40:37 -0000       1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v
 1.4 2002/05/01 01:33:42 glenn Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/05/01 01:33:42 $
  + * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v
 1.5 2002/05/01 02:40:37 glenn Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/01 02:40:37 $
    *
    * ====================================================================
    * 
  @@ -92,6 +92,7 @@
    * @author Anil K. Vijendran
    * @author Harish Prabandham
    * @author Pierre Delisle
  + * @author Glenn Nielsen
    */
   public class JspEngineContext implements JspCompilationContext {
       private JspReader reader;
  @@ -112,13 +113,12 @@
   
       public JspEngineContext(URLClassLoader loader, String classpath, 
                               ServletContext context, String jspUri,
  -                            boolean isErrPage, Options options)
  -    {
  +                            boolean isErrPage, Options options) {
           this.loader = loader;
           this.classpath = classpath;
           this.context = context;
           this.jspUri = jspUri;
  -        baseURI = jspUri.substring(0, jspUri.lastIndexOf('/'));
  +        baseURI = jspUri.substring(0, jspUri.lastIndexOf('/') + 1);
           this.isErrPage = isErrPage;
           this.options = options;
           createOutdir();
  @@ -129,12 +129,13 @@
           try {
               URL outURL = options.getScratchDir().toURL();
               String outURI = outURL.toString();           
  -            if( outURI.endsWith("/") )                   
  +            if( outURI.endsWith("/") ) {
                   outURI = outURI +             
                            jspUri.substring(1,jspUri.lastIndexOf("/")+1);
  -            else                                                       
  +            } else {
                   outURI = outURI +                                      
                            jspUri.substring(0,jspUri.lastIndexOf("/")+1);;
  +            }
               outURL = new URL(outURI);                                   
               outDir = new File(outURL.getFile());                        
               if( !outDir.exists() ) {
  @@ -312,8 +313,9 @@
        */
       public Compiler createCompiler() throws JasperException {
   
  -        if (jspCompiler != null)
  +        if (jspCompiler != null) {
               return jspCompiler;
  +        }
   
        String compilerPath = options.getJspCompilerPath();
        Class jspCompilerPlugin = options.getJspCompilerPlugin();
  @@ -332,8 +334,9 @@
               javac = new SunJavaCompiler();
        }
   
  -        if (compilerPath != null)
  +        if (compilerPath != null) {
               javac.setCompilerPath(compilerPath);
  +        }
   
           jspCompiler = new JspCompiler(this);
        jspCompiler.setJavaCompiler(javac);
  @@ -345,14 +348,12 @@
       /** 
        * Get the full value of a URI relative to this compilations context
        */
  -    public String resolveRelativeUri(String uri)
  -    {
  -        if (uri.charAt(0) == '/')
  -        {
  +    public String resolveRelativeUri(String uri) {
  +        if (uri.charAt(0) == '/') {
               return uri;
           }
  -        return baseURI + '/' + uri;
  -    }    
  +        return baseURI + uri;
  +    }
   
       /**
        * Gets a resource as a stream, relative to the meanings of this
  @@ -360,14 +361,11 @@
        * @return a null if the resource cannot be found or represented 
        *         as an InputStream.
        */
  -    public java.io.InputStream getResourceAsStream(String res)
  -    {
  +    public java.io.InputStream getResourceAsStream(String res) {
           return context.getResourceAsStream(res);
       }
   
  -    public URL getResource(String res)
  -     throws MalformedURLException
  -    {
  +    public URL getResource(String res) throws MalformedURLException {
           return context.getResource(res);
       }
   
  @@ -375,16 +373,11 @@
        * Gets the actual path of a URI relative to the context of
        * the compilation.
        */
  -    public String getRealPath(String path)
  -    {
  -        if (context != null)
  -        {
  +    public String getRealPath(String path) {
  +        if (context != null) {
               return context.getRealPath(path);
           }
  -        else
  -        {
  -            return path;
  -        }
  +        return path;
       }
   
       public String[] getTldLocation(String uri) throws JasperException {
  
  
  
  1.10      +77 -49    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServlet.java
  
  Index: JspServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServlet.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JspServlet.java   1 May 2002 01:33:42 -0000       1.9
  +++ JspServlet.java   1 May 2002 02:40:37 -0000       1.10
  @@ -1,4 +1,8 @@
   /*
  + * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServlet.java,v
 1.10 2002/05/01 02:40:37 glenn Exp $
  + * $Revision: 1.10 $
  + * $Date: 2002/05/01 02:40:37 $
  + *
    * The Apache Software License, Version 1.1
    *
    * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  @@ -111,7 +115,7 @@
   
       private Logger.Helper loghelper;
   
  -    private ServletContext context = null;
  +    private ServletContext context;
       private Map jsps = new FastHashMap();
       private ServletConfig config;
       private Options options;
  @@ -125,15 +129,14 @@
       static boolean firstTime = true;
   
       public void init(ServletConfig config)
  -     throws ServletException
  -    {
  +     throws ServletException {
  +
        super.init(config);
        this.config = config;
        this.context = config.getServletContext();
           this.serverInfo = context.getServerInfo();
           
        // Setup logging 
  -        //        Constants.jasperLog = new JasperLogger(this.context);
           Constants.jasperLog = new DefaultLogger(this.context);
        Constants.jasperLog.setName("JASPER_LOG");
        Constants.jasperLog.setTimestamp("false");
  @@ -155,15 +158,16 @@
        // Get the parent class loader
        parentClassLoader =
            (URLClassLoader) Thread.currentThread().getContextClassLoader();
  -        if (parentClassLoader == null)
  -            parentClassLoader = (URLClassLoader)this.getClass().getClassLoader();
  +        if (parentClassLoader == null) {
  +            parentClassLoader =
  +                (URLClassLoader)this.getClass().getClassLoader();
  +        }
           if (parentClassLoader != null) {
               Constants.message("jsp.message.parent_class_loader_is",
                                 new Object[] {
                                     parentClassLoader.toString()
                                 }, Logger.DEBUG);
  -            }
  -        else {
  +        } else {
               Constants.message("jsp.message.parent_class_loader_is",
                                 new Object[] {
                                     "<none>"  
  @@ -179,17 +183,19 @@
               try {          
                // Get the permissions for the web app context
                   String contextDir = context.getRealPath("/");
  -                if( contextDir == null )
  +                if( contextDir == null ) {
                       contextDir = options.getScratchDir().toString();
  +                }
                URL url = new URL("file:" + contextDir);
                codeSource = new CodeSource(url,null);
                permissionCollection = policy.getPermissions(codeSource);
                // Create a file read permission for web app context directory
  -             if (contextDir.endsWith(File.separator))
  +             if (contextDir.endsWith(File.separator)) {
                    contextDir = contextDir + "-";
  -             else
  +                } else {
                    contextDir = contextDir + File.separator + "-";
  -             permissionCollection.add( new FilePermission(contextDir,"read") );
  +                }
  +             permissionCollection.add(new FilePermission(contextDir,"read"));
                // Allow the JSP to access org.apache.jasper.runtime.HttpJspBase
                permissionCollection.add( new RuntimePermission(
                    "accessClassInPackage.org.apache.jasper.runtime") );
  @@ -198,21 +204,28 @@
                       String jarUrl = null;
                       String jndiUrl = null;
                       for (int i=0; i<urls.length; i++) {
  -                        if (jndiUrl == null && 
urls[i].toString().startsWith("jndi:") ) {
  +                        if (jndiUrl == null
  +                                && urls[i].toString().startsWith("jndi:") ) {
                               jndiUrl = urls[i].toString() + "-";
                           }
  -                        if (jarUrl == null && 
urls[i].toString().startsWith("jar:jndi:") ) {
  +                        if (jarUrl == null
  +                                && urls[i].toString().startsWith("jar:jndi:")
  +                                ) {
                               jarUrl = urls[i].toString();
                               jarUrl = jarUrl.substring(0,jarUrl.length() - 2);
  -                            jarUrl = jarUrl.substring(0,jarUrl.lastIndexOf('/')) + 
"/-";
  +                            jarUrl = jarUrl.substring(0,
  +                                     jarUrl.lastIndexOf('/')) + "/-";
                           }
                       }
                       if (jarUrl != null) {
  -                        permissionCollection.add( new FilePermission(jarUrl,"read") 
);
  -                        permissionCollection.add( new 
FilePermission(jarUrl.substring(4),"read") );
  +                        permissionCollection.add(
  +                                new FilePermission(jarUrl,"read"));
  +                        permissionCollection.add(
  +                                new FilePermission(jarUrl.substring(4),"read"));
                       }
                       if (jndiUrl != null)
  -                        permissionCollection.add( new 
FilePermission(jndiUrl,"read") );
  +                        permissionCollection.add(
  +                                new FilePermission(jndiUrl,"read") );
                   }
            } catch(MalformedURLException mfe) {
            }
  @@ -248,7 +261,8 @@
                              new Object[] { 
                                  options.getScratchDir().toString() 
                              }, Logger.INFORMATION );
  -         Constants.message("jsp.message.dont.modify.servlets", Logger.INFORMATION);
  +         Constants.message("jsp.message.dont.modify.servlets",
  +                    Logger.INFORMATION);
            JspFactory.setDefaultFactory(new JspFactoryImpl());
        }
       }
  @@ -256,8 +270,7 @@
       private void serviceJspFile(HttpServletRequest request, 
                                        HttpServletResponse response, String jspUri, 
                                Throwable exception, boolean precompile) 
  -     throws ServletException, IOException
  -    {
  +     throws ServletException, IOException {
   
        JspServletWrapper wrapper;
        synchronized (this) {
  @@ -265,8 +278,9 @@
            if (wrapper == null) {
                   // First check if the requested JSP page exists, to avoid
                   // creating unnecessary directories and files.
  -                if (context.getResourceAsStream(jspUri) == null)
  +                if (context.getResourceAsStream(jspUri) == null) {
                       throw new FileNotFoundException(jspUri);
  +                }
                   boolean isErrorPage = exception != null;
                wrapper = new JspServletWrapper(config, options, jspUri,
                                                   isErrorPage, classpath,
  @@ -294,37 +308,42 @@
        * @exception ServletException if an invalid parameter value for the
        *  <code>jsp_precompile</code> parameter name is specified
        */
  -    boolean preCompile(HttpServletRequest request) 
  -        throws ServletException 
  -    {
  +    boolean preCompile(HttpServletRequest request) throws ServletException {
   
           String queryString = request.getQueryString();
  -        if (queryString == null)
  +        if (queryString == null) {
               return (false);
  +        }
           int start = queryString.indexOf(Constants.PRECOMPILE);
  -        if (start < 0)
  +        if (start < 0) {
               return (false);
  +        }
           queryString =
               queryString.substring(start + Constants.PRECOMPILE.length());
  -        if (queryString.length() == 0)
  +        if (queryString.length() == 0) {
               return (true);             // ?jsp_precompile
  -        if (queryString.startsWith("&"))
  +        }
  +        if (queryString.startsWith("&")) {
               return (true);             // ?jsp_precompile&foo=bar...
  -        if (!queryString.startsWith("="))
  +        }
  +        if (!queryString.startsWith("=")) {
               return (false);            // part of some other name or value
  +        }
           int limit = queryString.length();
           int ampersand = queryString.indexOf("&");
  -        if (ampersand > 0)
  +        if (ampersand > 0) {
               limit = ampersand;
  +        }
           String value = queryString.substring(1, limit);
  -        if (value.equals("true"))
  +        if (value.equals("true")) {
               return (true);             // ?jsp_precompile=true
  -        else if (value.equals("false"))
  +        } else if (value.equals("false")) {
               return (true);             // ?jsp_precompile=false
  -        else
  +        } else {
               throw new ServletException("Cannot have request parameter " +
                                          Constants.PRECOMPILE + " set to " +
                                          value);
  +        }
   
       }
       
  @@ -332,41 +351,48 @@
   
       public void service (HttpServletRequest request, 
                         HttpServletResponse response)
  -     throws ServletException, IOException
  -    {
  +     throws ServletException, IOException {
  +
        try {
               String includeUri 
                   = (String) request.getAttribute(Constants.INC_SERVLET_PATH);
   
               String jspUri;
   
  -            if (includeUri == null)
  +            if (includeUri == null) {
                jspUri = request.getServletPath();
  -            else
  +            } else {
                   jspUri = includeUri;
  +            }
               String jspFile = (String) request.getAttribute(Constants.JSP_FILE);
  -            if (jspFile != null)
  +            if (jspFile != null) {
                   jspUri = jspFile;
  +            }
   
               boolean precompile = preCompile(request);
   
            Logger jasperLog = Constants.jasperLog;
            
  -            if (jasperLog != null &&
  -             jasperLog.matchVerbosityLevel(Logger.INFORMATION))
  +            if (jasperLog != null
  +                 && jasperLog.matchVerbosityLevel(Logger.INFORMATION))
                {
                    jasperLog.log("JspEngine --> "+jspUri);
  -                 jasperLog.log("\t     ServletPath: "+request.getServletPath());
  -                 jasperLog.log("\t        PathInfo: "+request.getPathInfo());
  -                 jasperLog.log("\t        RealPath: "
  -                               
+getServletConfig().getServletContext().getRealPath(jspUri));
  -                 jasperLog.log("\t      RequestURI: "+request.getRequestURI());
  -                 jasperLog.log("\t     QueryString: "+request.getQueryString());
  +                 jasperLog.log("\t     ServletPath: " +
  +                                  request.getServletPath());
  +                 jasperLog.log("\t        PathInfo: " +
  +                                  request.getPathInfo());
  +                 jasperLog.log("\t        RealPath: " +
  +                                  context.getRealPath(jspUri));
  +                 jasperLog.log("\t      RequestURI: " +
  +                                  request.getRequestURI());
  +                 jasperLog.log("\t     QueryString: " +
  +                                  request.getQueryString());
                    jasperLog.log("\t  Request Params: ");
                    Enumeration e = request.getParameterNames();
                    while (e.hasMoreElements()) {
                        String name = (String) e.nextElement();
  -                     jasperLog.log("\t\t "+name+" = "+request.getParameter(name));
  +                     jasperLog.log("\t\t " + name + " = " +
  +                                      request.getParameter(name));
                    }
                }
               serviceJspFile(request, response, jspUri, null, precompile);
  @@ -383,12 +409,14 @@
       }
   
       public void destroy() {
  +
        if (Constants.jasperLog != null)
            Constants.jasperLog.log("JspServlet.destroy()", Logger.INFORMATION);
   
        Iterator servlets = jsps.values().iterator();
  -     while (servlets.hasNext()) 
  +     while (servlets.hasNext()) {
            ((JspServletWrapper) servlets.next()).destroy();
  +        }
       }
   
   }
  
  
  
  1.2       +31 -15    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java
  
  Index: JspServletWrapper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JspServletWrapper.java    1 May 2002 01:33:42 -0000       1.1
  +++ JspServletWrapper.java    1 May 2002 02:40:37 -0000       1.2
  @@ -1,4 +1,8 @@
   /*
  + * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java,v
 1.2 2002/05/01 02:40:37 glenn Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/05/01 02:40:37 $
  + *
    * The Apache Software License, Version 1.1
    *
    * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  @@ -121,8 +125,8 @@
                         boolean isErrorPage, String classpath,
                         URLClassLoader parentClassLoader,
                         PermissionCollection permissionCollection,
  -                      CodeSource codeSource)
  -            throws JasperException {
  +                      CodeSource codeSource) throws JasperException {
  +
           this.jspUri = jspUri;
           this.theServlet = null;
           this.config = config;
  @@ -137,6 +141,7 @@
       }
   
       private void load() throws JasperException, ServletException {
  +
           try {
               // This is to maintain the original protocol.
               destroy();
  @@ -165,8 +170,9 @@
               }
   
               // If a page is to only to be precompiled return.
  -            if (precompile)
  +            if (precompile) {
                   return;
  +            }
   
               if (theServlet instanceof SingleThreadModel) {
                  // sync on the wrapper so that the freshness
  @@ -188,8 +194,9 @@
                   throw ex;
               } else {
                   int unavailableSeconds = ex.getUnavailableSeconds();
  -                if (unavailableSeconds <= 0)
  +                if (unavailableSeconds <= 0) {
                       unavailableSeconds = 60;        // Arbitrary default
  +                }
                   available = System.currentTimeMillis() +
                       (unavailableSeconds * 1000L);
                   response.sendError
  @@ -219,8 +226,9 @@
       }
   
       public void destroy() {
  -        if (theServlet != null)
  +        if (theServlet != null) {
               theServlet.destroy();
  +        }
       }
   
   
  @@ -231,8 +239,7 @@
        *  @return true if JSP has been recompiled
        */
       boolean loadJSP(HttpServletRequest req, HttpServletResponse res) 
  -     throws JasperException, FileNotFoundException 
  -    {
  +     throws JasperException, FileNotFoundException {
   
        boolean outDated = false; 
           
  @@ -244,8 +251,9 @@
                       // compilations of different pages, but not the 
                       // same page.
                       outDated = compiler.isOutDated();
  -                    if (outDated)
  +                    if (outDated) {
                           compiler.compile();
  +                    }
   
                       if ((servletClass == null) || outDated) {
                           URL [] urls = new URL[1];
  @@ -294,22 +302,26 @@
        */
       protected String normalize(String path) {
   
  -        if (path == null)
  +        if (path == null) {
               return null;
  +        }
   
           String normalized = path;
           
        // Normalize the slashes and add leading slash if necessary
  -     if (normalized.indexOf('\\') >= 0)
  +     if (normalized.indexOf('\\') >= 0) {
            normalized = normalized.replace('\\', '/');
  -     if (!normalized.startsWith("/"))
  +        }
  +     if (!normalized.startsWith("/")) {
            normalized = "/" + normalized;
  +        }
   
        // Resolve occurrences of "//" in the normalized path
        while (true) {
            int index = normalized.indexOf("//");
  -         if (index < 0)
  +         if (index < 0) {
                break;
  +            }
            normalized = normalized.substring(0, index) +
                normalized.substring(index + 1);
        }
  @@ -317,8 +329,9 @@
        // Resolve occurrences of "/./" in the normalized path
        while (true) {
            int index = normalized.indexOf("/./");
  -         if (index < 0)
  +         if (index < 0) {
                break;
  +            }
            normalized = normalized.substring(0, index) +
                normalized.substring(index + 2);
        }
  @@ -326,10 +339,12 @@
        // Resolve occurrences of "/../" in the normalized path
        while (true) {
            int index = normalized.indexOf("/../");
  -         if (index < 0)
  +         if (index < 0) {
                break;
  -         if (index == 0)
  +            }
  +         if (index == 0) {
                return (null);  // Trying to go outside our context
  +            }
            int index2 = normalized.lastIndexOf('/', index - 1);
            normalized = normalized.substring(0, index2) +
                normalized.substring(index + 3);
  @@ -339,4 +354,5 @@
        return (normalized);
   
       }
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to