1 15 package org.apache.tapestry.util.io; 16 17 import java.io.IOException ; 18 19 import org.apache.tapestry.Tapestry; 20 import org.apache.tapestry.services.DataSqueezer; 21 import org.apache.tapestry.util.ComponentAddress; 22 23 29 30 public class ComponentAddressAdaptor implements ISqueezeAdaptor 31 { 32 private static final String PREFIX = "A"; 33 34 private static final char SEPARATOR = ','; 35 36 public String squeeze(DataSqueezer squeezer, Object data) throws IOException 37 { 38 ComponentAddress address = (ComponentAddress) data; 39 40 String idPath = address.getIdPath(); 42 if (idPath == null) 43 idPath = ""; 44 45 return PREFIX + address.getPageName() + SEPARATOR + idPath; 46 } 47 48 public Object unsqueeze(DataSqueezer squeezer, String string) throws IOException 49 { 50 int separator = string.indexOf(SEPARATOR); 51 if (separator < 0) 52 throw new IOException (Tapestry.getMessage("ComponentAddressAdaptor.no-separator")); 53 54 String pageName = string.substring(1, separator); 55 String idPath = string.substring(separator + 1); 56 if (idPath.equals("")) 57 idPath = null; 58 59 return new ComponentAddress(pageName, idPath); 60 } 61 62 public void register(DataSqueezer squeezer) 63 { 64 squeezer.register(PREFIX, ComponentAddress.class, this); 65 } 66 67 } | Popular Tags |