Coverage Report - org.seasar.teeda.core.util.NavigationHandlerUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
NavigationHandlerUtil
75%
21/28
100%
4/4
2
 
 1  
 /*
 2  
  * Copyright 2004-2011 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.teeda.core.util;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.faces.FacesException;
 24  
 import javax.faces.application.NavigationHandler;
 25  
 import javax.faces.context.ExternalContext;
 26  
 import javax.faces.context.FacesContext;
 27  
 import javax.faces.internal.scope.RedirectScope;
 28  
 
 29  
 import org.seasar.teeda.core.exception.AlreadyRedirectingException;
 30  
 
 31  
 public class NavigationHandlerUtil {
 32  
 
 33  2
     private static final String KEY = NavigationHandlerUtil.class.getName();
 34  
 
 35  0
     private NavigationHandlerUtil() {
 36  0
     }
 37  
 
 38  
     public static void handleNavigation(FacesContext context,
 39  
             String fromAction, String outCome) {
 40  1
         NavigationHandler handler = context.getApplication()
 41  
                 .getNavigationHandler();
 42  1
         handler.handleNavigation(context, fromAction, outCome);
 43  1
     }
 44  
 
 45  
     public static void handleNoNavigation(FacesContext context) {
 46  0
         NavigationHandler handler = context.getApplication()
 47  
                 .getNavigationHandler();
 48  0
         handler.handleNavigation(context, null, null);
 49  0
     }
 50  
 
 51  
     public static void redirect(FacesContext context, String path) {
 52  1
         RedirectScope.setRedirectingPath(context, path);
 53  1
         ExternalContext externalContext = context.getExternalContext();
 54  
         try {
 55  1
             externalContext.redirect(externalContext.encodeActionURL(path));
 56  0
         } catch (IOException e) {
 57  0
             throw new FacesException(e.getMessage(), e);
 58  1
         }
 59  1
         context.responseComplete();
 60  1
         context.renderResponse();
 61  1
     }
 62  
 
 63  
     //For S2JSF redirect, we do not need this check.
 64  
     public static void assertNotAlreadyRedirect(FacesContext context) {
 65  3
         Map scope = RedirectScope.getOrCreateContext(context);
 66  3
         List list = (List) scope.get(KEY);
 67  3
         if (list == null) {
 68  1
             list = new ArrayList();
 69  1
             scope.put(KEY, list);
 70  
         }
 71  3
         String viewId = context.getViewRoot().getViewId();
 72  3
         if (list.contains(viewId)) {
 73  1
             throw new AlreadyRedirectingException();
 74  
         }
 75  2
         list.add(viewId);
 76  2
     }
 77  
 }