Coverage Report - org.apache.tapestry.contrib.table.model.simple.SimpleTableStateAdaptor
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleTableStateAdaptor
0%
0/26
0%
0/10
2.25
 
 1  
 // Copyright 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  
 /*
 16  
  * Created on Jul 6, 2005
 17  
  */
 18  
 package org.apache.tapestry.contrib.table.model.simple;
 19  
 
 20  
 import java.util.StringTokenizer;
 21  
 
 22  
 import org.apache.hivemind.ApplicationRuntimeException;
 23  
 import org.apache.tapestry.contrib.table.components.TableMessages;
 24  
 import org.apache.tapestry.services.DataSqueezer;
 25  
 import org.apache.tapestry.util.io.SqueezeAdaptor;
 26  
 
 27  
 /**
 28  
  * 
 29  
  * @author mb
 30  
  */
 31  0
 public class SimpleTableStateAdaptor implements SqueezeAdaptor
 32  
 {
 33  
 
 34  
     private static final String PREFIX = "t";
 35  
 
 36  
     /**
 37  
      * @see SqueezeAdaptor#getPrefix()
 38  
      */
 39  
     public String getPrefix()
 40  
     {
 41  0
         return PREFIX;
 42  
     }
 43  
 
 44  
     /**
 45  
      * @see SqueezeAdaptor#getDataClass()
 46  
      */
 47  
     public Class getDataClass()
 48  
     {
 49  0
         return SimpleTableState.class;
 50  
     }
 51  
 
 52  
     public String squeeze(DataSqueezer squeezer, Object data)
 53  
     {
 54  0
         SimpleTableState objState = (SimpleTableState) data;
 55  
 
 56  0
         StringBuffer buf = new StringBuffer();
 57  0
         buf.append(objState.getPagingState().getPageSize());
 58  0
         buf.append(":");
 59  0
         buf.append(objState.getPagingState().getCurrentPage());
 60  0
         buf.append(":");
 61  0
         String strSortColumn = objState.getSortingState().getSortColumn();
 62  0
         if (strSortColumn == null)
 63  0
             strSortColumn = "";
 64  0
         buf.append(strSortColumn);
 65  0
         buf.append(":");
 66  0
         buf.append(objState.getSortingState().getSortOrder() ? 'T' : 'F');
 67  
 
 68  0
         return buf.toString();
 69  
     }
 70  
 
 71  
     public Object unsqueeze(DataSqueezer squeezer, String string)
 72  
     {
 73  0
         StringTokenizer strTok = new StringTokenizer(string, ":");
 74  0
         if (strTok.countTokens() != 4)
 75  0
             throw new ApplicationRuntimeException(TableMessages.invalidTableStateFormat(string));
 76  0
         int nPageSize = Integer.parseInt(strTok.nextToken());
 77  0
         int nCurrentPage = Integer.parseInt(strTok.nextToken());
 78  0
         String strSortColumn = strTok.nextToken();
 79  0
         if (strSortColumn.equals(""))
 80  0
             strSortColumn = null;
 81  0
         boolean bSortOrder = strTok.nextToken().equals("T");
 82  
 
 83  0
         return new SimpleTableState(nPageSize, nCurrentPage, strSortColumn, bSortOrder);
 84  
     }
 85  
 
 86  
 }