Coverage Report - org.seasar.cubby.routing.impl.RouterImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RouterImpl
74%
14/19
38%
3/8
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.routing.impl;
 17  
 
 18  
 import java.util.Collections;
 19  
 import java.util.List;
 20  
 import java.util.regex.Matcher;
 21  
 import java.util.regex.Pattern;
 22  
 
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 import javax.servlet.http.HttpServletResponse;
 25  
 
 26  
 import org.seasar.cubby.routing.InternalForwardInfo;
 27  
 import org.seasar.cubby.routing.PathResolver;
 28  
 import org.seasar.cubby.routing.Router;
 29  
 import org.seasar.cubby.util.CubbyUtils;
 30  
 import org.seasar.framework.log.Logger;
 31  
 
 32  
 /**
 33  
  * ルーターの実装です。
 34  
  * 
 35  
  * @author baba
 36  
  * @since 1.0.0
 37  
  */
 38  32
 public class RouterImpl implements Router {
 39  
 
 40  
         /** ロガー */
 41  1
         private static final Logger logger = Logger.getLogger(RouterImpl.class);
 42  
 
 43  
         /** 空の対象外パターンのリスト */
 44  1
         private static final List<Pattern> EMPTY_IGNORE_PATH_PATTERNS = Collections
 45  
                         .emptyList();
 46  
 
 47  
         /** フォワードするための情報を抽出するクラス。 */
 48  
         private PathResolver pathResolver;
 49  
 
 50  
         /**
 51  
          * フォワードするための情報を抽出するクラスを設定します。
 52  
          * 
 53  
          * @param pathResolver
 54  
          *            フォワードするための情報を抽出するクラス
 55  
          */
 56  
         public void setPathResolver(final PathResolver pathResolver) {
 57  32
                 this.pathResolver = pathResolver;
 58  32
         }
 59  
 
 60  
         /**
 61  
          * {@inheritDoc}
 62  
          */
 63  
         public InternalForwardInfo routing(final HttpServletRequest request,
 64  
                         final HttpServletResponse response) {
 65  1
                 return routing(request, response, EMPTY_IGNORE_PATH_PATTERNS);
 66  
         }
 67  
 
 68  
         /**
 69  
          * {@inheritDoc}
 70  
          */
 71  
         public InternalForwardInfo routing(final HttpServletRequest request,
 72  
                         final HttpServletResponse response, List<Pattern> ignorePathPatterns) {
 73  1
                 final String path = CubbyUtils.getPath(request);
 74  1
                 if (logger.isDebugEnabled()) {
 75  1
                         logger.log("DCUB0006", new Object[] { path });
 76  
                 }
 77  
 
 78  1
                 if (isIgnorePath(path, ignorePathPatterns)) {
 79  0
                         return null;
 80  
                 }
 81  
 
 82  1
                 final InternalForwardInfo internalForwardInfo = pathResolver
 83  
                                 .getInternalForwardInfo(path, request.getMethod(), null);
 84  1
                 return internalForwardInfo;
 85  
         }
 86  
 
 87  
         /**
 88  
          * 指定された path が ignorePathPatterns にマッチするかを示します。
 89  
          * 
 90  
          * @param path
 91  
          *            パス
 92  
          * @param ignorePathPatterns
 93  
          *            対象外パターンのリスト
 94  
          * @return path が ignorePathPatterns にマッチする場合は <code>true</code>、そうでない場合は
 95  
          *         <code>false</code>
 96  
          */
 97  
         private boolean isIgnorePath(final String path,
 98  
                         List<Pattern> ignorePathPatterns) {
 99  1
                 for (final Pattern pattern : ignorePathPatterns) {
 100  0
                         final Matcher matcher = pattern.matcher(path);
 101  0
                         if (matcher.matches()) {
 102  0
                                 return true;
 103  
                         }
 104  0
                 }
 105  1
                 return false;
 106  
         }
 107  
 
 108  
 }