Coverage Report - org.apache.tapestry.contrib.ajax.Timeout
 
Classes in this File Line Coverage Branch Coverage Complexity
Timeout
0%
0/20
0%
0/4
1.077
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.contrib.ajax;
 16  
 
 17  
 import java.util.HashMap;
 18  
 import java.util.Map;
 19  
 
 20  
 import org.apache.tapestry.BaseComponent;
 21  
 import org.apache.tapestry.IRequestCycle;
 22  
 import org.apache.tapestry.web.WebRequest;
 23  
 import org.apache.tapestry.web.WebSession;
 24  
 
 25  
 /**
 26  
  * @author mb
 27  
  * @since 4.0
 28  
  */
 29  0
 public abstract class Timeout extends BaseComponent
 30  
 {
 31  
 
 32  
     public abstract int getWarningTime();
 33  
 
 34  
     public abstract int getAutoProlongTime();
 35  
 
 36  
     public abstract String getWarningMessage();
 37  
 
 38  
     public abstract String getExpirationMessage();
 39  
 
 40  
     public abstract boolean getDisableWarning();
 41  
 
 42  
     public abstract boolean getDisableAutoProlong();
 43  
 
 44  
     public abstract String getExpirationFunction();
 45  
 
 46  
     public abstract WebRequest getRequest();
 47  
     
 48  
     protected WebSession getSession()
 49  
     {
 50  0
         return getRequest().getSession(true);
 51  
     }
 52  
     
 53  
     protected int getSessionTime()
 54  
     {
 55  0
         return getSession().getMaxInactiveInterval();
 56  
     }
 57  
     
 58  
     public boolean isInSession()
 59  
     {
 60  0
         return getRequest().getSession(false) != null;
 61  
     }
 62  
 
 63  
     public Map getScriptSymbols()
 64  
     {
 65  0
         int nSessionTime = getSessionTime();
 66  0
         int nTimeToMessage = nSessionTime - getWarningTime();
 67  0
         if (nTimeToMessage < 0) nTimeToMessage = 0;
 68  0
         int nRemainingTime = nSessionTime - nTimeToMessage;
 69  0
         int nAutoProlongTime = nSessionTime - getAutoProlongTime();
 70  
         
 71  0
         Map mapSymbols = new HashMap();
 72  0
         mapSymbols.put("confirmTimeout", new Integer(nTimeToMessage * 1000));
 73  0
         mapSymbols.put("expirationTimeout", new Integer(nRemainingTime * 1000));
 74  0
         mapSymbols.put("prolongSessionPeriod", new Integer(
 75  
                 nAutoProlongTime * 1000));
 76  0
         mapSymbols.put("confirmMessage", getWarningMessage());
 77  0
         mapSymbols.put("expirationMessage", getExpirationMessage());
 78  0
         mapSymbols.put("disableWarning", new Boolean(getDisableWarning()));
 79  0
         mapSymbols.put("disableAutoProlong", new Boolean(
 80  
                 getDisableAutoProlong()));
 81  0
         mapSymbols.put("expirationFunction", getExpirationFunction());
 82  0
         return mapSymbols;
 83  
     }
 84  
 
 85  
     public void renewSession(IRequestCycle cycle)
 86  
     {
 87  
         // calling this method via the XTile service will automatically renew
 88  
         // the session
 89  
         // System.out.println("Prolonging session...");
 90  0
     }
 91  
 }