Coverage Report - org.apache.myfaces.flow.util.FlowUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
FlowUtils
0%
0/22
0%
0/10
3
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.flow.util;
 20  
 
 21  
 import java.util.List;
 22  
 import javax.faces.context.FacesContext;
 23  
 import javax.faces.flow.Flow;
 24  
 import org.apache.myfaces.flow.FlowHandlerImpl;
 25  
 import org.apache.myfaces.flow.FlowReference;
 26  
 
 27  
 /**
 28  
  *
 29  
  */
 30  0
 public class FlowUtils
 31  
 {
 32  
     public static String getFlowMapKey(FacesContext facesContext, FlowReference flowReference)
 33  
     {
 34  0
         Flow flow = null;
 35  0
         if (flowReference.getDocumentId() == null)
 36  
         {
 37  0
             flow = facesContext.getApplication().getFlowHandler().getFlow(
 38  
                 facesContext, "", flowReference.getId());
 39  
         }
 40  
         else
 41  
         {
 42  0
             flow = facesContext.getApplication().getFlowHandler().getFlow(
 43  
                 facesContext, flowReference.getDocumentId(), flowReference.getId());
 44  
         }
 45  0
         if (flow != null)
 46  
         {
 47  0
             return FlowUtils.getFlowMapKey(facesContext, flow);
 48  
         }
 49  0
         return null;
 50  
     }    
 51  
     
 52  
     public static String getFlowMapKey(FacesContext facesContext, Flow flow)
 53  
     {
 54  0
         String flowMapKey = flow.getClientWindowFlowId(
 55  
             facesContext.getExternalContext().getClientWindow());
 56  0
         int flowIndex = getFlowIndex(facesContext, flow);
 57  0
         if (flowIndex > 0)
 58  
         {
 59  0
             flowMapKey = flowMapKey + "_" + flowIndex;
 60  
         }
 61  0
         return flowMapKey;
 62  
     }
 63  
     
 64  
     private static int getFlowIndex(FacesContext facesContext, Flow flow)
 65  
     {
 66  0
         List<Flow> list = FlowHandlerImpl.getActiveFlows(facesContext, 
 67  
                 facesContext.getApplication().getFlowHandler());
 68  0
         FlowReference flowRef = new FlowReference(flow.getDefiningDocumentId(), flow.getId());
 69  0
         int flowIndex = 0;
 70  0
         for (Flow f : list)
 71  
         {
 72  0
             FlowReference fr = new FlowReference(f.getDefiningDocumentId(), f.getId());
 73  0
             if (flowRef.equals(fr))
 74  
             {
 75  0
                 flowIndex++;
 76  
             }
 77  0
         }
 78  0
         return flowIndex;
 79  
     }
 80  
 
 81  
 }