1 4 package org.apache.tapestry.contrib.table.model.simple; 5 6 7 import java.io.IOException ; 8 import java.util.StringTokenizer ; 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 PREFIX = "t"; 17 18 public String squeeze(DataSqueezer squeezer, Object data) 19 throws IOException { 20 SimpleTableState objState = (SimpleTableState) data; 21 22 StringBuffer buf = new StringBuffer (); 23 buf.append(objState.getPagingState().getPageSize()); 24 buf.append(":"); 25 buf.append(objState.getPagingState().getCurrentPage()); 26 buf.append(":"); 27 String 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 unsqueeze(DataSqueezer squeezer, String string) 38 throws IOException { 39 StringTokenizer strTok = new StringTokenizer (string, ":"); 40 if (strTok.countTokens() != 4) 41 throw new IOException (TableMessages.invalidTableStateFormat(string)); 42 int nPageSize = Integer.parseInt(strTok.nextToken()); 43 int nCurrentPage = Integer.parseInt(strTok.nextToken()); 44 String 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 |