pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.service.request
Class Command

java.lang.Object
  extended by org.torweg.pulse.service.request.Command
All Implemented Interfaces:
java.io.Serializable, JDOMable

public final class Command
extends java.lang.Object
implements JDOMable, java.io.Serializable

implements a Command used to control the pulse container.

It is initialised by the init(StringBuilder,ServiceRequest) method where it parses the request string and thereof derives the current locale, mode, bundle, action and the parameters of the current request. New instances of the command should be created by the newInstance or createCopy methods.

The pulse command URIs are structured as follows:

path to servlet parsable URI part suffix and request parameters
http://some.server.com/webapp/ServletName/ {locale}.{bundle}.{action}.{sitemapID}.{pulseParameters}/ {suffix}?{httpParameters}

Below the parsable part is explained in more detail:

In the case of file uploads, via multipart/form-data an UploadProgress can be added by adding the pulseParameter addUploadProgress with an per-session unique identifier as the value.

Version:
$Revision: 2038 $
Author:
Thomas Weber, Christian Schatt, Daniel Dietz
See Also:
Serialized Form

Constructor Summary
Command()
          raw constructor for pulse internal purposes.
 
Method Summary
 Command addHttpParameter(Parameter p)
          adds an HTTP Parameter to the Command.
 Command addHttpParameter(java.lang.String name, java.util.List<java.lang.String> values)
          adds an HTTP Parameter to the Command.
 Command addHttpParameter(java.lang.String name, java.lang.String value)
          adds an HTTP Parameter to the Command.
 Command addPulseParameter(Parameter p)
          adds an HTTP Parameter to the Command.
 Command addPulseParameter(java.lang.String name, java.util.List<java.lang.String> values)
          adds a Parameter to the Command.
 Command addPulseParameter(java.lang.String name, java.lang.String value)
          adds an HTTP Parameter to the Command.
 Command clearParameters()
          clears all parameters of the Command.
 Command createCopy()
          returns a deep copy of the Command.
 Command createCopy(boolean withParams)
          returns a copy of the Command either with or without its parameters.
 org.jdom.Element deserializeToJDOM()
          this will deserialize the state of the JDOMable as a JDOM Element.
 boolean equals(java.lang.Object obj)
          returns whether the given object is equal to the Command.
static Command fromParsable(java.lang.String parsable, ServiceRequest sr)
          utility method to build a Command from a parsable fragment.
protected  java.lang.String generateParsableCommandURI(java.util.Locale localeParam, ServiceSession session)
          generates an URL fragment containing the locale, mode, bundle, action and pulse-parameters.
 java.lang.String getAction()
           
 java.lang.String getBundle()
           
 long getETagValue()
          returns the ETag value for this command.
 Parameter getHttpParameter(java.lang.String name)
          gets a pulse parameter by name.
 java.util.List<Parameter> getHttpParameters()
          returns the HTTP parameters of the Command.
 java.util.Locale getLocale()
           
 Parameter getParameter(java.lang.String name)
           
 java.util.List<java.lang.String> getParameterNames()
           
 java.util.Set<Parameter> getParameters()
           
protected  java.util.Set<Parameter> getParametersJAXB()
          For JAXB only.
 Parameter getPulseParameter(java.lang.String name)
          gets a pulse parameter by name.
 java.util.List<Parameter> getPulseParameters()
          returns the pulse parameters of the Command.
 Action.Security getSecurity()
          returns the current security setting of the command.
 java.lang.Long getSitemapID()
           
 java.lang.String getSuffix()
          returns the suffix that is added after the parsable command URI.
 int hashCode()
          returns the hash code for the Command.
 Command init(java.lang.StringBuilder parsable, ServiceRequest sr)
          initialises the command from the given parsable part and updates the service request where necessary.
 boolean isTokenValid(ServiceSession session)
          checks whether the current Command requires a token and if the token is valid.
 Command newInstance(java.util.Locale newLocale, java.lang.String newBundle, java.lang.String newAction, java.util.List<Parameter> pulseParams, java.util.List<Parameter> httpParams)
           
 Command newInstance(java.util.Locale newLocale, java.lang.String newBundle, java.lang.String newAction, java.util.Set<Parameter> params)
           
 Command removeHttpParameter(java.lang.String name)
          removes a pulse parameter by name.
 Command removeParameter(Parameter parameter)
          Removes the Parameter parameter from the Command.
 Command removeParameter(java.lang.String name)
          removes the Parameter with the given name from the Command.
 Command removePulseParameter(java.lang.String name)
          removes a pulse parameter by name.
 Command setAction(java.lang.String act)
          Use for testing only.
 Command setBundle(java.lang.String name)
          sets the name of the Bundle.
 Command setHttpParameters(java.util.Map<java.lang.String,Parameter> hp)
          sets the HttpParameters of the Command.
 Command setLocale(java.util.Locale loc)
          sets the Locale of the Command.
 Command setLocaleFormString(java.lang.String localeString)
          set the locale for the Command from a locale string.
 Command setPulseParameters(java.util.Map<java.lang.String,Parameter> pp)
          sets the Parameters of the Command.
 Command setSecurity(Action.Security s)
          sets the level of security to be used when generating the command.
 Command setSitemapID(java.lang.Long id)
          sets the id of the SitemapNode referenced by the Command.
 Command setSuffix(java.lang.String s)
          sets the suffix that is added after the parsable command URI (default: index.html).
 java.lang.String toCommandURL(ServiceRequest request)
           
 java.lang.String toCommandURL(ServiceRequest request, java.util.Locale localeParam)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Command

public Command()
raw constructor for pulse internal purposes.

Method Detail

generateParsableCommandURI

protected java.lang.String generateParsableCommandURI(java.util.Locale localeParam, ServiceSession session)
generates an URL fragment containing the locale, mode, bundle, action and pulse-parameters.

Parameters:
localeParam - the Locale as parameter.
session - the service session for access to the token secret
Returns:
the encoded URL-fragment.

init

public Command init(java.lang.StringBuilder parsable, ServiceRequest sr)
initialises the command from the given parsable part and updates the service request where necessary.

Parameters:
parsable - the parsable part of the URL
sr - the service request
Returns:
the initialised command
Throws:
UnparsableRequestException - on errors extracting the command

isTokenValid

public boolean isTokenValid(ServiceSession session)
checks whether the current Command requires a token and if the token is valid.

Parameters:
session - the current session to access the secret
Returns:
false, if and only if, the current Command is requiring a token for execution and the given token is wrong. Otherwise true.

getSecurity

public Action.Security getSecurity()
returns the current security setting of the command.

Returns:
the current security setting of the command

setSecurity

public Command setSecurity(Action.Security s)
sets the level of security to be used when generating the command.

Parameters:
s - the level of security to be used when generating the command.
Returns:
the current command for method chaining

getLocale

public java.util.Locale getLocale()
Returns:
the locale of the command.
See Also:
getLocale()

setLocale

public Command setLocale(java.util.Locale loc)
sets the Locale of the Command.

Parameters:
loc - the locale to set
Returns:
the modified command

setLocaleFormString

public Command setLocaleFormString(java.lang.String localeString)
set the locale for the Command from a locale string.

Parameters:
localeString - the locale string
Returns:
the command

getBundle

public java.lang.String getBundle()
Returns:
the application of the command
See Also:
getBundle()

setBundle

public Command setBundle(java.lang.String name)
sets the name of the Bundle.

Parameters:
name - the name of the Bundle to set
Returns:
the modified command

getAction

public java.lang.String getAction()
Returns:
the action of the command
See Also:
getAction()

setAction

public Command setAction(java.lang.String act)
Use for testing only.

Parameters:
act - the action to set
Returns:
the modified command

getSitemapID

public java.lang.Long getSitemapID()
Returns:
the ID of the SitemapNode reference by the Command or null, if no SitemapNode is referenced.

setSitemapID

public Command setSitemapID(java.lang.Long id)
sets the id of the SitemapNode referenced by the Command.

Parameters:
id - the id of the SitemapNode referenced by the Command or null, if no SitemapNode is referenced.
Returns:
the modified command

getPulseParameters

public java.util.List<Parameter> getPulseParameters()
returns the pulse parameters of the Command.

Returns:
the pulse parameters of the Command

setPulseParameters

public Command setPulseParameters(java.util.Map<java.lang.String,Parameter> pp)
sets the Parameters of the Command.

Parameters:
pp - the pulse parameters to set
Returns:
the modified command

getHttpParameters

public java.util.List<Parameter> getHttpParameters()
returns the HTTP parameters of the Command.

Returns:
the HTTP parameters of the Command

setHttpParameters

public Command setHttpParameters(java.util.Map<java.lang.String,Parameter> hp)
sets the HttpParameters of the Command.

Parameters:
hp - the HTTP parameters to set
Returns:
the modified command

getParameter

public Parameter getParameter(java.lang.String name)
Parameters:
name - the name of the parameter to fetch
Returns:
the named parameter of the command or null, if no such parameter exists
See Also:
getParameter(java.lang.String)

getParameterNames

public java.util.List<java.lang.String> getParameterNames()
Returns:
a list of all parameter names of the command
See Also:
getParameterNames()

getParameters

public java.util.Set<Parameter> getParameters()
Returns:
a list of all parameters of the command
See Also:
getParameters()

getParametersJAXB

protected java.util.Set<Parameter> getParametersJAXB()
For JAXB only.

Returns:
the parameters of the Command

addPulseParameter

public Command addPulseParameter(java.lang.String name,
                                 java.util.List<java.lang.String> values)
adds a Parameter to the Command.

Parameters:
name - the name
values - the values
Returns:
the Command

addPulseParameter

public Command addPulseParameter(java.lang.String name,
                                 java.lang.String value)
adds an HTTP Parameter to the Command.

Parameters:
name - the name
value - the value
Returns:
the Command

addPulseParameter

public Command addPulseParameter(Parameter p)
adds an HTTP Parameter to the Command.

Parameters:
p - the parameter
Returns:
the Command

getPulseParameter

public Parameter getPulseParameter(java.lang.String name)
gets a pulse parameter by name.

Parameters:
name - the name of the parameter
Returns:
the parameter

removePulseParameter

public Command removePulseParameter(java.lang.String name)
removes a pulse parameter by name.

Parameters:
name - the name of the parameter
Returns:
the Command

addHttpParameter

public Command addHttpParameter(java.lang.String name,
                                java.util.List<java.lang.String> values)
adds an HTTP Parameter to the Command.

Parameters:
name - the name
values - the values
Returns:
the Command

addHttpParameter

public Command addHttpParameter(java.lang.String name,
                                java.lang.String value)
adds an HTTP Parameter to the Command.

Parameters:
name - the name
value - the value
Returns:
the Command

addHttpParameter

public Command addHttpParameter(Parameter p)
adds an HTTP Parameter to the Command.

Parameters:
p - the parameter
Returns:
the Command

getHttpParameter

public Parameter getHttpParameter(java.lang.String name)
gets a pulse parameter by name.

Parameters:
name - the name of the parameter
Returns:
the parameter

removeHttpParameter

public Command removeHttpParameter(java.lang.String name)
removes a pulse parameter by name.

Parameters:
name - the name of the parameter
Returns:
the Command

removeParameter

public Command removeParameter(Parameter parameter)
Removes the Parameter parameter from the Command.

Parameters:
parameter - the Parameter to be removed from the Command
Returns:
the Command

removeParameter

public Command removeParameter(java.lang.String name)
removes the Parameter with the given name from the Command.

Parameters:
name - the name of the Parameter to be removed
Returns:
the modified Command

clearParameters

public Command clearParameters()
clears all parameters of the Command.

Returns:
the Command

getSuffix

public java.lang.String getSuffix()
returns the suffix that is added after the parsable command URI.

Returns:
the suffix that is added after the parsable command URI

setSuffix

public Command setSuffix(java.lang.String s)
sets the suffix that is added after the parsable command URI (default: index.html).

Parameters:
s - the suffix to be added
Returns:
this command for method chaining

newInstance

public Command newInstance(java.util.Locale newLocale,
                           java.lang.String newBundle,
                           java.lang.String newAction,
                           java.util.Set<Parameter> params)
Parameters:
newLocale - the Locale for the new command
newBundle - the application of the new command
newAction - the action of the new command
params - the parameters to add to the new command
Returns:
the new command

newInstance

public Command newInstance(java.util.Locale newLocale,
                           java.lang.String newBundle,
                           java.lang.String newAction,
                           java.util.List<Parameter> pulseParams,
                           java.util.List<Parameter> httpParams)
Parameters:
newLocale - the Locale for the new command
newBundle - the application of the new command
newAction - the action of the new command
pulseParams - the pulse parameters to add to the new command
httpParams - the HTTP parameters to add to the new command
Returns:
the new command

toCommandURL

public java.lang.String toCommandURL(ServiceRequest request)
Parameters:
request - the service request
Returns:
the URL representing the command with the current locale

toCommandURL

public java.lang.String toCommandURL(ServiceRequest request,
                                     java.util.Locale localeParam)
Parameters:
request - the service request
localeParam - the local for the command
Returns:
the URL representing the command with the given locale

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
Returns a String representation of the Command.

hashCode

public int hashCode()
returns the hash code for the Command.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

getETagValue

public long getETagValue()
returns the ETag value for this command.

Returns:
the ETag value

equals

public boolean equals(java.lang.Object obj)
returns whether the given object is equal to the Command.

The given object is considered equal, if and only if, it is also a Command with the same locale, bundle, action, sitemap ID and parameters.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare against
Returns:
true, if and only if, the given object is equal to this command. Otherwise false.

deserializeToJDOM

public org.jdom.Element deserializeToJDOM()
Description copied from interface: JDOMable
this will deserialize the state of the JDOMable as a JDOM Element.

Specified by:
deserializeToJDOM in interface JDOMable
Returns:
a JDOM Element representing the Command .

createCopy

public Command createCopy()
returns a deep copy of the Command.

Returns:
a deep copy of the Command

createCopy

public Command createCopy(boolean withParams)
returns a copy of the Command either with or without its parameters.

Parameters:
withParams - a flag indicating whether or not to copy the parameters as well
Returns:
a copy of the Command either with or without its parameters

fromParsable

public static Command fromParsable(java.lang.String parsable, ServiceRequest sr)
utility method to build a Command from a parsable fragment.

Parameters:
parsable - the fragment
sr - the current request
Returns:
the Command