org.mmbase.applications.editwizard
Class Wizard

java.lang.Object
  extended by org.mmbase.applications.editwizard.Wizard
All Implemented Interfaces:
Serializable, SizeMeasurable

public class Wizard
extends Object
implements SizeMeasurable, Serializable

EditWizard

Since:
MMBase-1.6
Version:
$Id: Wizard.java 43027 2010-08-02 13:50:39Z pierre $
Author:
Kars Veling, Michiel Meeuwissen, Pierre van Rooden, Hillebrand Gelderblom
See Also:
Serialized Form
Javadoc:

Nested Class Summary
(package private)  class Wizard.OrderByComparator
           
 
Field Summary
static String DTD_EDITWIZARD_1_0
           
static String PUBLIC_ID_EDITWIZARD_1_0
           
static String PUBLIC_ID_EDITWIZARD_1_0_FAULT
           
static String RESPONSE_KEY
           
 
Constructor Summary
Wizard(HttpServletRequest request, URIResolver uri, Config.WizardConfig wizardConfig, Cloud cloud)
          Constructor.
Wizard(HttpServletRequest request, URIResolver uri, String wizardname, String dataid, Cloud cloud)
          Deprecated. use Wizard(String, URIResolver, Config.WizardConfig, Cloud)
 
Method Summary
 void addBinaryData(Node fieldnode)
          This method stores binary data in the data, so that the information can be used by the html.
protected  boolean checkNode(String objectNumber, String operation)
          Returns true if the specified operation is valid for the node with the specified objectnumber.
 boolean committed()
          Returns whether the wizard has committed the transaction
 Document createPreHtml(Node wizardSchema, String formid, Node data, String instanceName)
          This method generated the pre-html.
 Document createPreHtml(String instanceName)
          This method generates the pre-html.
 void createPreHtmlForm(Node form, Node formdef, Node dataContext)
          This method is used by the #createPreHtml method to generate a pre-html form.
 String determineNextForm(String direction)
          This method is used to determine what form is the sequential next, previous, first etc.
 byte[] getBinary(String did)
          This method allows you to retrieve the data of a temporarily stored binary.
 String getBinaryName(String did)
          With this method you can retrieve the binaryname of a placed binary.
 String getBinaryPath(String did)
          With this method you can retrieve the binarypath of a placed binary.
 int getByteSize()
          Determines the byte-size of this object
 int getByteSize(SizeOf sizeof)
          Determines the byte-size of this object using the given SizeOf instance.
 Node getConstraints(String objecttype)
          This method gets the MMBase constraints.
 Node getConstraints(String objecttype, String fieldname)
          This method gets the MMBase constraints.
 Document getData()
           
 String getDataId()
           
 String getObjectNumber()
           
 Document getPreForm()
           
 Document getPreForm(String instanceName)
           
 Document getSchema()
           
 WizardCommand getStartWizardCommand()
          Returns the subwizard start command
protected  void loadData()
          Load data from mmbase based on the wizard schema
protected  void loadWizard(Config.WizardConfig wizardConfig, HttpServletRequest request)
          Loads the wizard schema, and a work document, and fills it with initial data.
 boolean mayBeClosed()
          Returns whether the wizard may be closed
protected  boolean mayDeleteNode(String objectNumber)
          Returns true if the node with the specified objectnumber can be deleted
protected  boolean mayEditNode(String objectNumber)
          Returns true if the node with the specified objectnumber can be edited
 void mergeConstraints(Node fieldDef, Node fieldNode)
          This method is used to merge MMBase specific constraints with the values placed in the Wizard definition.
 void processCommand(WizardCommand cmd)
          This method is usually called by #processCommands and processes one command.
 void processRequest(HttpServletRequest req)
          Processes an incoming request (usually passed on by a jsp code).
 String retrieveFieldValue(String did, String fieldName)
          Obtains the value form the right field (given by name) of the right node (given by did).
(package private)  boolean runQuery(Node list, Node query)
          This method tests if a query in a nodelist needs to be run, and runs it if needed, adding the resulting options to the optionlist.
 void setBinary(String did, byte[] bytes, String name, String path)
          With this method you can store a binary in the wizard.
 void setBinary(String did, byte[] bytes, String name, String path, String type)
          set binary data for uploaded bytes
 void setReferrer(String s)
           
 void setSessionId(String s)
           
 void setSessionKey(String s)
           
 void setTemplatesDir(String f)
           
 void setTimezone(String s)
           
 boolean startWizard()
          Returns whether a sub wizard should be started
protected  void storeConfigurationAttributes(Config.WizardConfig wizardConfig)
          Stores configuration variables as attributes in the variables set.
 void storeFieldValue(String did, String fieldName, String value)
          Puts the given value in the right field (given by name) of the right node (given by did) Assumes a text field.
 void writeHtmlForm(Writer out, String instanceName)
          Constructs and writes final form-html to the given out writer.
 void writeHtmlForm(Writer out, String instanceName, Map<String,Object> externParams)
          Constructs and writes final form-html to the given out writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PUBLIC_ID_EDITWIZARD_1_0

public static final String PUBLIC_ID_EDITWIZARD_1_0
See Also:
Constant Field Values

PUBLIC_ID_EDITWIZARD_1_0_FAULT

public static final String PUBLIC_ID_EDITWIZARD_1_0_FAULT
See Also:
Constant Field Values

DTD_EDITWIZARD_1_0

public static final String DTD_EDITWIZARD_1_0
See Also:
Constant Field Values

RESPONSE_KEY

public static final String RESPONSE_KEY
See Also:
Constant Field Values
Constructor Detail

Wizard

public Wizard(HttpServletRequest request,
              URIResolver uri,
              String wizardname,
              String dataid,
              Cloud cloud)
       throws WizardException
Deprecated. use Wizard(String, URIResolver, Config.WizardConfig, Cloud)

Constructor. Setup initial variables and connects to mmbase to load the data structure.

Parameters:
request - Associated servlet request, sometimes needed for URL generation
uri - the URIResolver with which the wizard schema's and the xsl's will be loaded
wizardname - name of the wizard
dataid - the objectnumber
cloud - the Cloud to use
Throws:
WizardException - when wizard creation failed

Wizard

public Wizard(HttpServletRequest request,
              URIResolver uri,
              Config.WizardConfig wizardConfig,
              Cloud cloud)
       throws WizardException
Constructor. Setup initial variables and connects to mmbase to load the data structure.

Parameters:
request - Associated servlet request, sometimes needed for URL generation
uri - the URIResolver with which the wizard schema's and the xsl's will be loaded
wizardConfig - the class containing the configuration parameters (i.e. wizard name and objectnumber)
cloud - the Cloud to use
Throws:
WizardException - when wizard creation failed
Method Detail

getByteSize

public int getByteSize()
Description copied from interface: SizeMeasurable
Determines the byte-size of this object

Specified by:
getByteSize in interface SizeMeasurable

getByteSize

public int getByteSize(SizeOf sizeof)
Description copied from interface: SizeMeasurable
Determines the byte-size of this object using the given SizeOf instance. A SizeOf instance stores a Set already counted objects. So this method is typically called by SizeOf itself (recursion).

Specified by:
getByteSize in interface SizeMeasurable

setSessionId

public void setSessionId(String s)

setSessionKey

public void setSessionKey(String s)

setReferrer

public void setReferrer(String s)

setTemplatesDir

public void setTemplatesDir(String f)

setTimezone

public void setTimezone(String s)

getObjectNumber

public String getObjectNumber()

getDataId

public String getDataId()

getData

public Document getData()

getSchema

public Document getSchema()

getPreForm

public Document getPreForm()
                    throws WizardException
Throws:
WizardException

getPreForm

public Document getPreForm(String instanceName)
                    throws WizardException
Throws:
WizardException

committed

public boolean committed()
Returns whether the wizard has committed the transaction

Returns:
true when committed

mayBeClosed

public boolean mayBeClosed()
Returns whether the wizard may be closed

Returns:
true when allowed to close

startWizard

public boolean startWizard()
Returns whether a sub wizard should be started

Returns:
true when start a sub wizard

checkNode

protected boolean checkNode(String objectNumber,
                            String operation)
                     throws WizardException
Returns true if the specified operation is valid for the node with the specified objectnumber. The operation is valid if the node has the given property set to true. To maintain backwards compatible, if the property is not given, the default value is true.

Parameters:
objectNumber - the number of the node to check
operation - a valid operation, i.e. maywrite or maydelete
Returns:
true when valid operation
Throws:
WizardException - if the object cannot be retrieved

mayEditNode

protected boolean mayEditNode(String objectNumber)
                       throws WizardException
Returns true if the node with the specified objectnumber can be edited

Parameters:
objectNumber - number of the object to check
Returns:
true when allowed to edit
Throws:
WizardException - if the object cannot be retrieved

mayDeleteNode

protected boolean mayDeleteNode(String objectNumber)
                         throws WizardException
Returns true if the node with the specified objectnumber can be deleted

Parameters:
objectNumber - number of the object to check
Returns:
true when allowed to delete
Throws:
WizardException - if the object cannot be retrieved

getStartWizardCommand

public WizardCommand getStartWizardCommand()
Returns the subwizard start command

Returns:
wizard command

storeConfigurationAttributes

protected void storeConfigurationAttributes(Config.WizardConfig wizardConfig)
Stores configuration variables as attributes in the variables set.

Parameters:
wizardConfig - the config with the parameters

loadWizard

protected void loadWizard(Config.WizardConfig wizardConfig,
                          HttpServletRequest request)
                   throws WizardException
Loads the wizard schema, and a work document, and fills it with initial data.

Parameters:
wizardConfig - the class containing the configuration parameters (i.e. wizard name and objectnumber)
Throws:
WizardException - when wizard loading failed

loadData

protected void loadData()
                 throws WizardException
Load data from mmbase based on the wizard schema

Throws:
WizardException - when data loading failed
Since:
MMBase-1.7

processRequest

public void processRequest(HttpServletRequest req)
                    throws WizardException
Processes an incoming request (usually passed on by a jsp code). First, all given values are stored in the current datatree, Second, all given commands are processed sequentially.

Parameters:
req - the ServletRequest contains the name-value pairs received through the http connection
Throws:
WizardException - when request processing failed

writeHtmlForm

public void writeHtmlForm(Writer out,
                          String instanceName)
                   throws WizardException,
                          TransformerException
Constructs and writes final form-html to the given out writer. You can specify an instancename, so that the wizard is able to start another wizard in the same session. The jsp pages and in the html the instancenames are used to keep track of one and another.

Parameters:
out - The writer where the output (html) should be written to.
instanceName - name of the current instance
Throws:
WizardException - when building the current state of the wizard xml failed
TransformerException - when transforming the wizard xml failed

writeHtmlForm

public void writeHtmlForm(Writer out,
                          String instanceName,
                          Map<String,Object> externParams)
                   throws WizardException,
                          TransformerException
Constructs and writes final form-html to the given out writer. You can specify an instancename, so that the wizard is able to start another wizard in the same session. The jsp pages and in the html the instancenames are used to keep track of one and another.

Parameters:
out - The writer where the output (html) should be written to.
instanceName - name of the current instance
externParams - sending parameters to the stylesheet which are not from the editwizards itself
Throws:
WizardException - when building the current state of the wizard xml failed
TransformerException - when transforming the wizard xml failed

determineNextForm

public String determineNextForm(String direction)
This method is used to determine what form is the sequential next, previous, first etc. You can use the parameter to indicate what you want to know:

Parameters:
direction - indicates what you wanna know. Possibilities: - first (default) - last - previous - next
Returns:
name of next form

createPreHtml

public Document createPreHtml(String instanceName)
                       throws WizardException
This method generates the pre-html. See the full-spec method for more details.

Parameters:
instanceName - The instancename of this wizard
Returns:
xml representation of the wizard data ready to be transformed
Throws:
WizardException - thrown when something failed in generating the xml
See Also:
createPreHtml(Node, String, Node, String)

createPreHtml

public Document createPreHtml(Node wizardSchema,
                              String formid,
                              Node data,
                              String instanceName)
                       throws WizardException
This method generated the pre-html. Pre-html is a temporarily datatree (xml of course) which is used to generate the final html from. Is uses the wizardschema, the current formid, the current datatree and the instancename to generate the pre-html. Mainly, the pre-html contains all data needed to make a nice htmlform. The XSL's use the pre-html to generate html (thats why pre-html)

Parameters:
wizardSchema - the main node of the schema to be used. Includes should already be resolved.
formid - The id of the current form
data - The main node of the data tree to be used
instanceName - The instancename of this wizard
Returns:
xml representation of the wizard data ready to be transformed
Throws:
WizardException - thrown when something failed in generating the xml

runQuery

boolean runQuery(Node list,
                 Node query)
This method tests if a query in a nodelist needs to be run, and runs it if needed, adding the resulting options to the optionlist.

Parameters:
list - the node of the optionlist in which the query is defined
query - the node of the query definition

createPreHtmlForm

public void createPreHtmlForm(Node form,
                              Node formdef,
                              Node dataContext)
                       throws WizardException
This method is used by the #createPreHtml method to generate a pre-html form.

Parameters:
form - The node of the pre-html form which is to be generated
formdef - the node of the wizardschema form definition
dataContext - Points to the datacontext node which should be used for this form.
Throws:
WizardException - when form generation failed

storeFieldValue

public void storeFieldValue(String did,
                            String fieldName,
                            String value)
                     throws WizardException
Puts the given value in the right field (given by name) of the right node (given by did) Assumes a text field.

Parameters:
did - The data id of the node
fieldName - The name of the field
value - The (String) value what should be stored in the data.
Throws:
WizardException - when failed to store field data

retrieveFieldValue

public String retrieveFieldValue(String did,
                                 String fieldName)
                          throws WizardException
Obtains the value form the right field (given by name) of the right node (given by did). Assumes a text field.

Parameters:
did - The data id of the node
fieldName - The name of the field
Returns:
value of field
Throws:
WizardException - when failed to read field

processCommand

public void processCommand(WizardCommand cmd)
                    throws WizardException
This method is usually called by #processCommands and processes one command. Possible wizard commands are:

Parameters:
cmd - The command to be processed
Throws:
WizardException - when failed to process command

setBinary

public void setBinary(String did,
                      byte[] bytes,
                      String name,
                      String path)
With this method you can store a binary in the wizard.

Parameters:
did - This is the dataid what points to in what field the binary should be stored, once commited.
bytes - This is a bytearray with the data to be stored.
name - This is the name which will be used to show what file is uploaded.
path - The (local) path of the file placed.

setBinary

public void setBinary(String did,
                      byte[] bytes,
                      String name,
                      String path,
                      String type)
set binary data for uploaded bytes

Parameters:
did - This is the dataid what points to in what field the binary should be stored, once commited.
bytes - This is a bytearray with the data to be stored.
name - This is the name which will be used to show what file is uploaded.
path - The (local) path of the file placed.
type - Content-type of the byte (or null). If not null, then the fields 'mimetype', 'size' and 'filename' are filled as well.
Since:
MMBase-1.7.2

getBinary

public byte[] getBinary(String did)
This method allows you to retrieve the data of a temporarily stored binary.

Parameters:
did - The dataid of the binary you want.
Returns:
the binary data, if found.

getBinaryName

public String getBinaryName(String did)
With this method you can retrieve the binaryname of a placed binary.

Parameters:
did - The dataid of the binary you want.
Returns:
The name as set when #setBinary was used.

getBinaryPath

public String getBinaryPath(String did)
With this method you can retrieve the binarypath of a placed binary.

Parameters:
did - The dataid of the binary you want.
Returns:
The path as set when #setBinary was used.

addBinaryData

public void addBinaryData(Node fieldnode)
This method stores binary data in the data, so that the information can be used by the html. This method is called from the form creating code.

Parameters:
fieldnode - the fieldnode where the binary data information should be stored.

mergeConstraints

public void mergeConstraints(Node fieldDef,
                             Node fieldNode)
This method is used to merge MMBase specific constraints with the values placed in the Wizard definition. For now, it checks requiredness and datatypes. It connects to the Dove, gets the constraints (from cache or not) and merges the values.

Parameters:
fieldDef - the fielddefinition as placed in the wizardschema (==definition)
fieldNode - The fieldnode points to the datanode. (This is needed to find out what datatype this field is about).

getConstraints

public Node getConstraints(String objecttype)
This method gets the MMBase constraints.

Parameters:
objecttype - The name of the object, eg. images, jumpers, urls, news
Returns:
constrainra from mmbase

getConstraints

public Node getConstraints(String objecttype,
                           String fieldname)
This method gets the MMBase constraints. It also handles the internal constraints cache.

Parameters:
objecttype - The name of the object, eg. images, jumpers, urls, news
fieldname - The name of the field, eg. title, body, start
Returns:
constrainra from mmbase


MMBase 2.0-SNAPSHOT - null