KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > model > simple > SimpleTableStateAdaptor


1 /*
2  * Created on Jul 6, 2005
3  */

4 package org.apache.tapestry.contrib.table.model.simple;
5
6
7 import java.io.IOException JavaDoc;
8 import java.util.StringTokenizer JavaDoc;
9
10 import org.apache.tapestry.contrib.table.components.TableMessages;
11 import org.apache.tapestry.services.DataSqueezer;
12 import org.apache.tapestry.util.io.ISqueezeAdaptor;
13
14 public class SimpleTableStateAdaptor implements ISqueezeAdaptor {
15
16     private static final String JavaDoc PREFIX = "t";
17     
18     public String JavaDoc squeeze(DataSqueezer squeezer, Object JavaDoc data)
19             throws IOException JavaDoc {
20         SimpleTableState objState = (SimpleTableState) data;
21         
22         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
23         buf.append(objState.getPagingState().getPageSize());
24         buf.append(":");
25         buf.append(objState.getPagingState().getCurrentPage());
26         buf.append(":");
27         String JavaDoc strSortColumn = objState.getSortingState().getSortColumn();
28         if (strSortColumn == null)
29             strSortColumn = "";
30         buf.append(strSortColumn);
31         buf.append(":");
32         buf.append(objState.getSortingState().getSortOrder() ? 'T' : 'F');
33         
34         return buf.toString();
35     }
36
37     public Object JavaDoc unsqueeze(DataSqueezer squeezer, String JavaDoc string)
38             throws IOException JavaDoc {
39         StringTokenizer JavaDoc strTok = new StringTokenizer JavaDoc(string, ":");
40         if (strTok.countTokens() != 4)
41             throw new IOException JavaDoc(TableMessages.invalidTableStateFormat(string));
42         int nPageSize = Integer.parseInt(strTok.nextToken());
43         int nCurrentPage = Integer.parseInt(strTok.nextToken());
44         String JavaDoc strSortColumn = strTok.nextToken();
45         if (strSortColumn.equals(""))
46             strSortColumn = null;
47         boolean bSortOrder = strTok.nextToken().equals("T");
48         
49         return new SimpleTableState(nPageSize, nCurrentPage, strSortColumn, bSortOrder);
50     }
51
52     public void register(DataSqueezer squeezer) {
53         squeezer.register(PREFIX, SimpleTableState.class, this);
54     }
55
56 }
57
Popular Tags