tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper Mapper.java
Date Sat, 17 May 2003 20:55:37 GMT
remm        2003/05/17 13:55:37

  Modified:    util/java/org/apache/tomcat/util/http/mapper Mapper.java
  Log:
  - Refactor very slightly the mapping algorithm and the mapper so that
    it can do context level mapping.
  
  Revision  Changes    Path
  1.18      +98 -38    jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper/Mapper.java
  
  Index: Mapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper/Mapper.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Mapper.java	24 Apr 2003 14:40:11 -0000	1.17
  +++ Mapper.java	17 May 2003 20:55:37 -0000	1.18
  @@ -99,6 +99,7 @@
        */
       protected boolean processWelcomeResources = true;
   
  +
       /**
        * Flag indicating that we should redirect to a directory when the URL
        * doesn't end in a '/'.  It overrided the Authenticator, so the redirect 
  @@ -106,6 +107,13 @@
        */
       protected boolean redirectDirectories = false;
   
  +
  +    /**
  +     * Context associated with this wrapper, used for wrapper mapping.
  +     */
  +    protected Context context = null;
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -206,6 +214,24 @@
   
   
       /**
  +     * Set context, used for wrapper mapping (request dispatcher).
  +     * 
  +     * @param path Context path
  +     * @param context Context object
  +     * @param welcomeResources Welcome files defined for this context
  +     * @param resources Static resources of the context
  +     */
  +    public void setContext(String path, String[] welcomeResources, 
  +                           javax.naming.Context resources) {
  +        context = new Context();
  +        context.name = path;
  +        //context.object = context; // Likely useless
  +        context.welcomeResources = welcomeResources;
  +        context.resources = resources;
  +    }
  +
  +
  +    /**
        * Add a new Context to an existing Host.
        * 
        * @param hostName Virtual host name this context belongs to
  @@ -274,7 +300,9 @@
           }
       }
   
  -    /** Return all contexts, in //HOST/PATH form
  +
  +    /** 
  +     * Return all contexts, in //HOST/PATH form
        *
        * @return
        */
  @@ -287,12 +315,11 @@
                           (cname.startsWith("/") ? cname : "/"));
               }
           }
  -        String res[]=new String[list.size()];
  +        String res[] = new String[list.size()];
           return (String[])list.toArray(res);
       }
   
   
  -
       /**
        * Add a new Wrapper to an existing Context.
        * 
  @@ -318,41 +345,54 @@
               }
               Context context = contexts[pos2];
               if (context.name.equals(contextPath)) {
  -                synchronized (context) {
  -                    Wrapper newWrapper = new Wrapper();
  -                    newWrapper.object = wrapper;
  -                    if (path.endsWith("/*")) {
  -                        // Wildcard wrapper
  -                        newWrapper.name = path.substring(0, path.length() - 2);
  -                        Wrapper[] oldWrappers = context.wildcardWrappers;
  -                        Wrapper[] newWrappers = 
  -                            new Wrapper[oldWrappers.length + 1];
  -                        if (insertMap(oldWrappers, newWrappers, newWrapper)) {
  -                            context.wildcardWrappers = newWrappers;
  -                        }
  -                    } else if (path.startsWith("*.")) {
  -                        // Extension wrapper
  -                        newWrapper.name = path.substring(2);
  -                        Wrapper[] oldWrappers = context.extensionWrappers;
  -                        Wrapper[] newWrappers = 
  -                            new Wrapper[oldWrappers.length + 1];
  -                        if (insertMap(oldWrappers, newWrappers, newWrapper)) {
  -                            context.extensionWrappers = newWrappers;
  -                        }
  -                    } else if (path.equals("/")) {
  -                        // Default wrapper
  -                        newWrapper.name = "";
  -                        context.defaultWrapper = newWrapper;
  -                    } else {
  -                        // Exact wrapper
  -                        newWrapper.name = path;
  -                        Wrapper[] oldWrappers = context.exactWrappers;
  -                        Wrapper[] newWrappers = 
  -                            new Wrapper[oldWrappers.length + 1];
  -                        if (insertMap(oldWrappers, newWrappers, newWrapper)) {
  -                            context.exactWrappers = newWrappers;
  -                        }
  -                    }
  +                addWrapper(context, path, wrapper);
  +            }
  +        }
  +    }
  +
  +
  +    /**
  +     * Add a wrapper to the context associated with this wrapper.
  +     */
  +    public void addWrapper(String path, Object wrapper) {
  +        addWrapper(context, path, wrapper);
  +    }
  +
  +
  +    protected void addWrapper(Context context, String path, Object wrapper) {
  +        synchronized (context) {
  +            Wrapper newWrapper = new Wrapper();
  +            newWrapper.object = wrapper;
  +            if (path.endsWith("/*")) {
  +                // Wildcard wrapper
  +                newWrapper.name = path.substring(0, path.length() - 2);
  +                Wrapper[] oldWrappers = context.wildcardWrappers;
  +                Wrapper[] newWrappers = 
  +                    new Wrapper[oldWrappers.length + 1];
  +                if (insertMap(oldWrappers, newWrappers, newWrapper)) {
  +                    context.wildcardWrappers = newWrappers;
  +                }
  +            } else if (path.startsWith("*.")) {
  +                // Extension wrapper
  +                newWrapper.name = path.substring(2);
  +                Wrapper[] oldWrappers = context.extensionWrappers;
  +                Wrapper[] newWrappers = 
  +                    new Wrapper[oldWrappers.length + 1];
  +                if (insertMap(oldWrappers, newWrappers, newWrapper)) {
  +                    context.extensionWrappers = newWrappers;
  +                }
  +            } else if (path.equals("/")) {
  +                // Default wrapper
  +                newWrapper.name = "";
  +                context.defaultWrapper = newWrapper;
  +            } else {
  +                // Exact wrapper
  +                newWrapper.name = path;
  +                Wrapper[] oldWrappers = context.exactWrappers;
  +                Wrapper[] newWrappers = 
  +                    new Wrapper[oldWrappers.length + 1];
  +                if (insertMap(oldWrappers, newWrappers, newWrapper)) {
  +                    context.exactWrappers = newWrappers;
                   }
               }
           }
  @@ -475,6 +515,26 @@
           }
           uri.toChars();
           internalMap(host.getCharChunk(), uri.getCharChunk(), mappingData);
  +
  +    }
  +
  +
  +    /**
  +     * Map the specified URI relative to the context, 
  +     * mutating the given mapping data.
  +     * 
  +     * @param uri URI
  +     * @param mappingData This structure will contain the result of the mapping
  +     *                    operation
  +     */
  +    public void map(MessageBytes uri, MappingData mappingData)
  +        throws Exception {
  +
  +        uri.toChars();
  +        CharChunk uricc = uri.getCharChunk();
  +        uricc.setLimit(-1);
  +        mappingData.contextPath.setString(context.path);
  +        internalMapWrapper(context, uricc, mappingData);
   
       }
   
  
  
  

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


Mime
View raw message