Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  *
  *
  * This file incorporates work covered by the following copyright and
  * permission notice:
  *
  * Copyright 2004 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.catalina.core;
 
 
 public class AlternateDocBase {
 
     enum UrlPatternType { EXACT, WILDCARD, EXTENSION };
 
     private String pattern;
     private UrlPatternType patternType;
     private int patternSlashCount;
     
     private String docBase;
     private String basePath;
     private String patternSuffix;
     private String wildcardPath;
     private ProxyDirContext resources;
     private DirContext webappResources;


    
Sets the url pattern of this AlternateDocBase.

Parameters:
urlPattern The url pattern of this AlternateDocBase
 
     public void setUrlPattern(String urlPattern) {
         this. = urlPattern;
 
         this. = getSlashCount(urlPattern);
         if (urlPattern.endsWith("/*")) {
             this. = .;
             this. = urlPattern.substring(
                 0, urlPattern.length()-1);
         } else if (urlPattern.startsWith("*.")) {
             this. = .;
             this. = urlPattern.substring(1);
         } else {
             this. = .;
         }
     }


    
Gets the url pattern of this AlternateDocBase.

Returns:
The url pattern of this AlternativeDocBase
    public String getUrlPattern() {
        return ;
    }


    
Gets the url pattern type (exact, wildcard, extension) of this AlternateDocBase.

Returns:
The url pattern type (exact, wildcard, extension) of this AlternativeDocBase
    public UrlPatternType getUrlPatternType() {
        return ;
    }


    
Gets the number of slashes in the url pattern of this AlternateDocBase.

Returns:
Number of slashes in the url pattern of this AlternateDocBase.
    public int getUrlPatternSlashCount() {
        return ;
    }


    
Gets the extension suffix of the url pattern of this AlternateDocBase.

Returns:
The extension suffix of the url pattern of this AlternateDocBase, or null if the url pattern is not of type 'extension'
    public String getUrlPatternSuffix() {
        return this.;
    }


    
Gets the wildcard path of this AlternateDocBase (this is the path specified by the wildcard pattern, minus the trailing '*').

Returns:
The wildcard path of this AlternateDocBase, or null if the pattern associated with this AlternateDocBase is not a wildcard pattern
 
    public String getUrlPatternWildcardPath() {
        return this.;
    }


    
Sets the (possibly relative) doc base path of this AlternateDocBase.

Parameters:
docBase The (possibly relative) doc base path of this AlternateDocBase
    public void setDocBase(String docBase) {
        this. = docBase;
    }


    
Gets the (possibly relative) doc base path of this AlternateDocBase.

Returns:
The (possibly relative) doc base path of this AlternativeDocBase
    public String getDocBase() {
        return ;
    }


    
Sets the absolute doc base path of this AlternateDocBase.

Parameters:
basePath The absolute doc base path of this AlternateDocBase
    public void setBasePath(String basePath) {
        this. = basePath;
    }


    
Gets the absolute doc base path of this AlternateDocBase.

Returns:
The absolute doc base path of this AlternativeDocBase
    public String getBasePath() {
        return ;
    }
    public class ProxyDirContext{
        public Object lookup(String sthrows NamingException{
            return null;
        }
    }
    
    public class DirContext{}

    
Sets the proxied resources of this AlternateDocBase.

Parameters:
resources The proxied resources of this AlternateDocBase
    public void setResources(ProxyDirContext resources) {
        this. = resources;
    }


    
Gets the proxied resources of this AlternateDocBase.

Returns:
The proxied resources of this AlternateDocBase
    public ProxyDirContext getResources() {
        return ;
    }


    
Sets the non-proxied resources of this AlternateDocBase.

Parameters:
resources The non-proxied resources of this AlternateDocBase
    public void setWebappResources(DirContext webappResources) {
        this. = webappResources;
    }


    
Gets the non-proxied resources of this AlternateDocBase.

Returns:
The non-proxied resources of this AlternateDocBase
    public DirContext getWebappResources() {
        return ;
    }


    
Attempts to match the given request path against one of the given alternate doc bases.

Returns:
The alternate doc base whose url pattern matches the given path, or null if no matching alternate doc base could be found
    public static AlternateDocBase findMatch(
                    String path,
                    ArrayList<AlternateDocBasealternateDocBases) {
        if (alternateDocBases == null) {
            return null;
        }
        AlternateDocBase match = null;
        AlternateDocBase wildcardMatch = null;
        AlternateDocBase extensionMatch = null;
        int maxSlashCountMatch = 0;
        int pathSlashCount = getSlashCount(path);
        for (int i=0; i<alternateDocBases.size(); i++) {
            AlternateDocBase alternateDocBase = alternateDocBases.get(i);
            String pattern = alternateDocBase.getUrlPattern();
            int patternSlashCount = alternateDocBase.getUrlPatternSlashCount();
            AlternateDocBase.UrlPatternType type =
                alternateDocBase.getUrlPatternType();
            String wildcardPath = alternateDocBase.getUrlPatternWildcardPath();
            if (type == . && path.equals(pattern)) {
                // Exact match found
                match = alternateDocBase;
                break;
            } else if (type == .
                    && pathSlashCount >= patternSlashCount
                    && patternSlashCount > maxSlashCountMatch
                    && path.startsWith(wildcardPath)) {
                // We've found a longer wildcard match
                wildcardMatch = alternateDocBase;
                maxSlashCountMatch = patternSlashCount;
            } else if (type == .
                    && path.endsWith(alternateDocBase.getUrlPatternSuffix())) {
                extensionMatch = alternateDocBase;
            }
        }
        if (match == null) {
            if (wildcardMatch != null) {
                match = wildcardMatch;
            } else {
                match = extensionMatch;
            }
        }
        return match;
    }


    
Determines the number for forward slashes in the given string.

Parameters:
s The string whose forward slashes to count
Returns:
The number of forward slashes
    private static int getSlashCount(String s) {
        int count = 0;
        if (s != null) {
            int index = s.indexOf('/');
            while (index >= 0) {
                count++;
                index = s.indexOf('/'index+1);
            }
        }
        return count;
    }
New to GrepCode? Check out our FAQ X