FileDocCategorySizeDatePackage
DynamicContent.javaAPI DocGlassfish v2 API10819Fri May 04 22:34:12 BST 2007com.sun.enterprise.appclient.jws

DynamicContent

public class DynamicContent extends Content
Represents dynamic content in template form.

This class also keeps track of the most recent times the object's template was used to generated different content from the previous time. This information is used in responding to HTTP HEAD requests. Java Web Start uses HEAD requests to find out if a document on the server is more recent than the locally cached copy on the client. If so, then Java Web Start will request the updated version with a routine GET request.

To avoid incorrectly reporting obsolete cached documents as correct, this class keeps track of when the content generated by the template is different from the previous generation.

The generated content can depend on request-time information (such as command line arguments passed in the query string of the HTTP request). We save and track only a few individual response instances, because the assumption is that requests that carry query strings (which are converted into command line arguments passed to ACC and on through to the app client) are likely to change frequently and not necessarily be reused often. Keeping a few allows caching the different content resulting from a small number of different argument value settings, but avoids the problems of caching every single response which could become a large memory drain if each request specified a different set of argument (for instance, one of the arguments could be a timestamp that would change every time).

Fields Summary
private static final int
MAX_INSTANCES
maximum number of instances of content to keep for each template
protected static final String
ALL_PERMISSIONS_JNLP_SETTING
JNLP element to request full permissions - used if the app client jar is signed
protected static final String
NO_PERMISSIONS_JNLP_SETTING
JNLP element to request no permissions - used if the app client jar is not signed - no perms is the JNLP default
private String
template
the template which will be used at runtime to create the actual response to the HTTP request
protected String
mimeType
the MIME type of the data represented by this DynamicContent instance
private LinkedList
instances
content instances resulting from previous HTTP GET requests
private boolean
requiresElevatedPermissions
records whether this content should request elevated permissions
Constructors Summary
public DynamicContent(ContentOrigin origin, String contentKey, String path, String template, String mimeType)
Returns a new instance of DynamicContent.

param
origin the ContentOrigin for the new content instance
param
contentKey the content key used to store and retrieve the content
param
path the path relative to the subcategory in which this document is addressable
param
mimeType the MIME type of data represented by the content generated by this object.
return
new DynamicContent object

    
                                                              
               
        this(origin, contentKey, path, template, mimeType, false /* requiresElevatedPermissions */);
    
public DynamicContent(ContentOrigin origin, String contentKey, String path, String template, String mimeType, boolean requiresElevatedPermissions)
Returns a new instance of DynamicContent.

param
origin the ContentOrigin for the new content instance
param
contentKey the content key used to store and retrieve the content
param
path the path relative to the subcategory in which this document is addressable
param
mimeType the MIME type of data represented by the content generated by this object.
return
new DynamicContent object

        super(origin, contentKey, path);
        this.template = template;
        this.mimeType = mimeType;
        this.requiresElevatedPermissions = requiresElevatedPermissions;
     
Methods Summary
private voidaddInstance(com.sun.enterprise.appclient.jws.DynamicContent$Instance newInstance)
Adds a new content instance to this dynamic content. If adding the instance makes the cache too long, discards the oldest instance.

param
newInstance the new instance to be added to the cache

        synchronized (instances) {
            instances.addFirst(newInstance);
            if (instances.size() > MAX_INSTANCES) {
                instances.removeLast();
            }
        }
    
protected voidclearInstances()
Clears the cached instances.

        instances.clear();
    
public com.sun.enterprise.appclient.jws.DynamicContent$InstancefindInstance(java.util.Properties tokenValues, boolean createIfAbsent)
Returns the DynamicContent.Instance for this template corresponding to the specified substitution token values.

param
tokenValues the name/value pairs to be substituted in the template
param
createIfAbsent selects whether a new DynamicContent.Instance should be created for the resulting text if the content text resulting from the substitution is not already cached by this DynamicContent.
return
the instance corresponding to the content generated by the tokenValues; null if no such instance already exists for this DynamicContent and createIfAbsent was false.

        Instance result = null;
        String textWithPlaceholdersReplaced = Util.replaceTokens(template, tokenValues);
        
        /*
         *Look for an instance with its text matching the just-computed replacement text.
         */
        synchronized (instances) {
            for (Instance i : instances) {
                if (i.textEquals(textWithPlaceholdersReplaced)) {
                    result = i;
                    break;
                }
            }
            if (result == null && createIfAbsent) {
                result = new Instance(textWithPlaceholdersReplaced);
                addInstance(result);
            }
        }
        return result;
    
public java.lang.StringgetJNLPSecuritySetting()
Returns the appropriate JNLP security setting for this content, based on whether it requires elevated permissions or not.

return
the JNLP element string or an empty string if no privs are needed

        return requiresElevatedPermissions ? ALL_PERMISSIONS_JNLP_SETTING : NO_PERMISSIONS_JNLP_SETTING;
    
public java.lang.StringgetMimeType()
Returns the MIME type associated with this content.

return
the MIME type for this content

        return mimeType;
    
public booleanrequiresElevatedPermissions()
Returns whether this dynamic content requires elevated permissions.

return
true if the related static content does require elevated permissions

        return requiresElevatedPermissions;
    
public java.lang.StringtoString()
Returns a string representation of the DynamicContent.

        return super.toString() + ", template=" + template + ", MIME type=" + mimeType;// + ", most recent change in generated content=" + timestamp;