1 14 package org.wings.resource; 15 16 import org.wings.RequestURL; 17 import org.wings.Resource; 18 import org.wings.SimpleURL; 19 import org.wings.externalizer.ExternalizeManager; 20 import org.wings.io.Device; 21 import org.wings.session.PropertyService; 22 import org.wings.session.SessionManager; 23 24 import java.io.IOException ; 25 26 30 public class StringResource 31 extends Resource { 32 private final String string; 33 34 private String id; 35 36 39 protected int externalizerFlags; 40 41 public StringResource(String string) { 42 this(string, "txt", "text/plain"); 43 } 44 45 public StringResource(String string, String extension, String mimeType) { 46 this(string, extension, mimeType, ExternalizeManager.FINAL); 47 } 48 49 public StringResource(String string, String extension, String mimeType, 50 int externalizerFlags) { 51 super(extension, mimeType); 52 53 this.string = string; 54 this.externalizerFlags = externalizerFlags; 55 } 56 57 58 public int getLength() { 59 return string.length(); 60 } 61 62 68 public String getId() { 69 if (id == null) { 70 ExternalizeManager ext = SessionManager.getSession().getExternalizeManager(); 71 id = ext.getId(ext.externalize(this, externalizerFlags)); 72 } 73 return id; 74 } 75 76 public SimpleURL getURL() { 77 String name = getId(); 78 79 if ((externalizerFlags & ExternalizeManager.GLOBAL) > 0) { 81 return new SimpleURL(name); 82 } else { 83 RequestURL requestURL = (RequestURL) getPropertyService().getProperty("request.url"); 84 requestURL = (RequestURL) requestURL.clone(); 85 requestURL.setResource(name); 86 return requestURL; 87 } 88 } 89 90 public final void write(Device out) throws IOException { 91 out.print(string); 92 } 93 94 public int getExternalizerFlags() { 95 return externalizerFlags; 96 } 97 98 private PropertyService propertyService; 99 100 protected PropertyService getPropertyService() { 101 if (propertyService == null) 102 propertyService = (PropertyService) SessionManager.getSession(); 103 return propertyService; 104 } 105 106 } 107 108 109 110 111 112 113 | Popular Tags |