1 14 package org.wings.resource; 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 import org.wings.RequestURL; 19 import org.wings.Resource; 20 import org.wings.SFrame; 21 import org.wings.SimpleURL; 22 import org.wings.externalizer.ExternalizeManager; 23 import org.wings.session.PropertyService; 24 import org.wings.session.SessionManager; 25 import org.wings.util.StringUtil; 26 27 import java.util.Collection ; 28 import java.util.Set ; 29 30 39 public abstract class DynamicResource 40 extends Resource { 41 private final transient static Log log = LogFactory.getLog(DynamicResource.class); 42 43 47 private int epoch = 0; 48 49 55 private String epochCache = "W" + StringUtil.toShortestAlphaNumericString(epoch); 56 57 60 private SFrame frame; 61 62 protected DynamicResource(String extension, String mimeType) { 63 super(extension, mimeType); 64 } 65 66 67 public DynamicResource(SFrame frame) { 68 this(frame, "", ""); 69 } 70 71 72 public DynamicResource(SFrame frame, String extension, String mimeType) { 73 super(extension, mimeType); 74 this.frame = frame; 75 } 76 77 80 public final SFrame getFrame() { 81 return frame; 82 } 83 84 public String getId() { 85 if (id == null) { 86 ExternalizeManager ext = SessionManager.getSession().getExternalizeManager(); 87 id = ext.getId(ext.externalize(this)); 88 log.debug("new " + getClass().getName() + " with id " + id); 89 } 90 return id; 91 } 92 93 98 public final void invalidate() { 99 epochCache = "W" + StringUtil.toShortestAlphaNumericString(++epoch); 100 if (log.isDebugEnabled()) { 101 String name = getClass().getName(); 102 name = name.substring(name.lastIndexOf(".") + 1); 103 log.debug("[" + name + "] " + 104 "invalidate - epoch: " + epochCache); 105 } 106 107 } 108 109 110 public final String getEpoch() { 111 return epochCache; 112 } 113 114 public SimpleURL getURL() { 115 RequestURL requestURL = (RequestURL) getPropertyService().getProperty("request.url"); 116 if (requestURL != null) { 117 requestURL = (RequestURL) requestURL.clone(); 118 requestURL.setEpoch(getEpoch()); 119 requestURL.setResource(getId()); 120 } 121 return requestURL; 122 } 123 124 private PropertyService propertyService; 125 126 protected PropertyService getPropertyService() { 127 if (propertyService == null) 128 propertyService = (PropertyService) SessionManager.getSession(); 129 return propertyService; 130 } 131 132 133 public String toString() { 134 return getId() + " " + getEpoch(); 135 } 136 137 138 144 public Collection getHeaders() { 145 return null; 146 } 147 148 154 public Set getCookies() { 155 return null; 156 } 157 } 158 159 160 | Popular Tags |