tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper Mapper.java
Date Tue, 25 Mar 2003 17:52:56 GMT
costin      2003/03/25 09:52:56

  Modified:    util/java/org/apache/tomcat/util/http/mapper Mapper.java
  Log:
  Add the host automatically. We don't really need the Host object to be anything -
  we map to Context and we get the Host object from there.
  ( well, Wrapper is the only object that needs to be mapped )
  
  Few methods to display the info ( for JMX console use )
  
  Revision  Changes    Path
  1.12      +79 -3     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Mapper.java	13 Mar 2003 06:17:53 -0000	1.11
  +++ Mapper.java	25 Mar 2003 17:52:56 -0000	1.12
  @@ -63,6 +63,8 @@
   
   import org.apache.tomcat.util.buf.CharChunk;
   import org.apache.tomcat.util.buf.MessageBytes;
  +import java.util.List;
  +import java.util.ArrayList;
   
   /**
    * Mapper, which implements the servlet API mapping rules (which are derived
  @@ -194,6 +196,14 @@
           }
       }
   
  +    public String[] getHosts() {
  +        String hostN[]=new String[ hosts.length];
  +        for( int i=0; i<hosts.length; i++ ) {
  +            hostN[i]=hosts[i].name;
  +        }
  +        return hostN;
  +    }
  +
   
       /**
        * Add a new Context to an existing Host.
  @@ -210,8 +220,13 @@
   
           Host[] hosts = this.hosts;
           int pos = find(hosts, hostName);
  -        if (pos < 0) {
  -            return;
  +        if( pos <0 ) {
  +            addHost(hostName, "");
  +            hosts = this.hosts;
  +            pos = find(hosts, hostName);
  +        }
  +        if( pos <0 ) {
  +            System.out.println("No host found " + hostName); // XXX log
           }
           Host host = hosts[pos];
           if (host.name.equals(hostName)) {
  @@ -256,6 +271,24 @@
           }
       }
   
  +    /** Return all contexts, in //HOST/PATH form
  +     *
  +     * @return
  +     */
  +    public String[] getContextNames() {
  +        List list=new ArrayList();
  +        for( int i=0; i<hosts.length; i++ ) {
  +            for( int j=0; j<hosts[i].contexts.length; j++ ) {
  +                String cname=hosts[i].contexts[j].name;
  +                list.add("//" + hosts[i].name +
  +                        (cname.startsWith("/") ? cname : "/"));
  +            }
  +        }
  +        String res[]=new String[list.size()];
  +        return (String[])list.toArray(res);
  +    }
  +
  +
   
       /**
        * Add a new Wrapper to an existing Context.
  @@ -276,7 +309,8 @@
           if (host.name.equals(hostName)) {
               Context[] contexts = host.contexts;
               int pos2 = find(contexts, contextPath);
  -            if (pos2 < 0) {
  +            if( pos2<0 ) {
  +                logger.error("Can't find context " + contextPath );
                   return;
               }
               Context context = contexts[pos2];
  @@ -382,6 +416,44 @@
           }
       }
   
  +    public String getWrappersString( String host, String context ) {
  +        String names[]=getWrapperNames(host, context);
  +        StringBuffer sb=new StringBuffer();
  +        for( int i=0; i<names.length; i++ ) {
  +            sb.append(names[i]).append(":");
  +        }
  +        return sb.toString();
  +    }
  +        
  +    public String[] getWrapperNames( String host, String context ) {
  +        List list=new ArrayList();
  +        if( host==null ) host="";
  +        if( context==null ) context="";
  +        for( int i=0; i<hosts.length; i++ ) {
  +            if( ! host.equals( hosts[i].name ))
  +                continue;
  +            for( int j=0; j<hosts[i].contexts.length; j++ ) {
  +                if( ! context.equals( hosts[i].contexts[j].name))
  +                    continue;
  +                // found the context
  +                Context ctx=hosts[i].contexts[j];
  +                list.add( ctx.defaultWrapper.path);
  +                for( int k=0; k<ctx.exactWrappers.length; k++ ) {
  +                    list.add( ctx.exactWrappers[k].path);
  +                }
  +                for( int k=0; k<ctx.wildcardWrappers.length; k++ ) {
  +                    list.add( ctx.wildcardWrappers[k].path + "*");
  +                }
  +                for( int k=0; k<ctx.extensionWrappers.length; k++ ) {
  +                    list.add( "*." + ctx.extensionWrappers[k].path);
  +                }
  +            }
  +        }
  +        String res[]=new String[list.size()];
  +        return (String[])list.toArray(res);
  +    }
  +
  +
   
       /**
        * Map the specified host name and URI, mutating the given mapping data.
  @@ -780,6 +852,10 @@
   
           // Special cases: -1 and 0
           if (b == -1) {
  +            return -1;
  +        }
  +        if( name==null || map.length ==0 ) {
  +            System.out.println("XXX Mapper: unexpected null " + name + " " + map);
               return -1;
           }
           if (name.compareTo(map[0].name) < 0) {
  
  
  

---------------------------------------------------------------------
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