1 23 24 package com.sun.enterprise.appclient.jws; 25 26 import java.util.Date ; 27 import java.util.LinkedList ; 28 import java.util.Properties ; 29 30 34 60 public class DynamicContent extends Content { 61 62 63 private static final int MAX_INSTANCES = 4; 64 65 66 protected static final String ALL_PERMISSIONS_JNLP_SETTING = "<security><all-permissions/></security>"; 67 68 69 protected static final String NO_PERMISSIONS_JNLP_SETTING = ""; 70 71 75 private String template; 76 77 78 protected String mimeType; 79 80 81 private LinkedList <Instance> instances = new LinkedList <Instance>(); 82 83 84 private boolean requiresElevatedPermissions; 85 86 95 public DynamicContent(ContentOrigin origin, String contentKey, String path, String template, String mimeType) { 96 this(origin, contentKey, path, template, mimeType, false ); 97 } 98 99 108 public DynamicContent(ContentOrigin origin, String contentKey, String path, String template, String mimeType, boolean requiresElevatedPermissions) { 109 super(origin, contentKey, path); 110 this.template = template; 111 this.mimeType = mimeType; 112 this.requiresElevatedPermissions = requiresElevatedPermissions; 113 } 114 115 126 public Instance findInstance(Properties tokenValues, boolean createIfAbsent) { 127 Instance result = null; 128 String textWithPlaceholdersReplaced = Util.replaceTokens(template, tokenValues); 129 130 133 synchronized (instances) { 134 for (Instance i : instances) { 135 if (i.textEquals(textWithPlaceholdersReplaced)) { 136 result = i; 137 break; 138 } 139 } 140 if (result == null && createIfAbsent) { 141 result = new Instance(textWithPlaceholdersReplaced); 142 addInstance(result); 143 } 144 } 145 return result; 146 } 147 148 153 private void addInstance(Instance newInstance) { 154 synchronized (instances) { 155 instances.addFirst(newInstance); 156 if (instances.size() > MAX_INSTANCES) { 157 instances.removeLast(); 158 } 159 } 160 } 161 162 163 167 public String getMimeType() { 168 return mimeType; 169 } 170 171 176 public String getJNLPSecuritySetting() { 177 return requiresElevatedPermissions ? ALL_PERMISSIONS_JNLP_SETTING : NO_PERMISSIONS_JNLP_SETTING; 178 } 179 180 184 public boolean requiresElevatedPermissions() { 185 return requiresElevatedPermissions; 186 } 187 188 191 protected void clearInstances() { 192 instances.clear(); 193 } 194 195 198 public String toString() { 199 return super.toString() + ", template=" + template + ", MIME type=" + mimeType; } 201 202 206 public class Instance { 207 208 209 private Date timestamp; 210 211 212 private String text; 213 214 219 private Instance(String text) { 220 this.text = text; 221 timestamp = new Date (); 222 } 223 224 229 private boolean textEquals(String other) { 230 return text.equals(other); 231 } 232 233 237 public Date getTimestamp() { 238 return timestamp; 239 } 240 241 245 public String getText() { 246 return text; 247 } 248 } 249 } | Popular Tags |