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.Resource; 19 import org.wings.SFrame; 20 import org.wings.io.Device; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.Date ; 27 28 35 public class DynamicCodeResource extends DynamicResource { 36 private final transient static Log log = LogFactory.getLog(DynamicCodeResource.class); 37 38 private static final ArrayList DEFAULT_CODE_HEADER = new ArrayList (); 39 static { 40 DEFAULT_CODE_HEADER.add(new Resource.HeaderEntry("Expires", new Date (1000))); 41 DEFAULT_CODE_HEADER.add(new Resource.HeaderEntry("Cache-Control", "no-store, no-cache, must-revalidate")); 42 DEFAULT_CODE_HEADER.add(new Resource.HeaderEntry("Cache-Control", "post-check=0, pre-check=0")); 43 DEFAULT_CODE_HEADER.add(new Resource.HeaderEntry("Pragma", "no-cache")); 44 } 45 46 47 51 public DynamicCodeResource(SFrame f) { 52 super(f, null, provideMimeType(f)); 53 } 54 55 60 private static String provideMimeType(SFrame frame) { 61 return "text/html; charset=" + frame.getSession().getCharacterEncoding(); 62 } 63 64 67 public void write(Device out) throws IOException { 68 try { 69 getFrame().write(out); 70 } catch (IOException e) { 71 throw e; 72 } catch (Exception e) { 73 log.fatal("resource: " + getId(), e); 74 throw new IOException (e.getMessage()); } 76 } 77 78 86 public Collection getHeaders() { 87 if (getFrame().isNoCaching()) 88 return DEFAULT_CODE_HEADER; 89 else 90 return Collections.EMPTY_SET; 91 } 92 } 93 94 95 | Popular Tags |