info.magnolia.module.admininterface
Class SaveHandlerImpl

java.lang.Object
  extended by info.magnolia.module.admininterface.SaveHandlerImpl
All Implemented Interfaces:
SaveHandler
Direct Known Subclasses:
MultiValueSaveHandler, UUIDSaveHandler

public class SaveHandlerImpl
extends java.lang.Object
implements SaveHandler

This class handles the saving in the dialogs. It uses the mgnlSaveInfo parameters sent from the browser to store the data in the node.The structure of the parameter is the following:
name, type, valueType, isRichEditValue, encoding

To find the consts see ControlImpl

name the name of the field
type string, boolean, ...
valueType single, multiple
isRichEditValue value from an editor
encoding base64, unix, none

You can specify a custom save handled (a class that implements info.magnolia.module.admininterface.CustomSaveHandler) by adding a "saveHandler" property to a dialog field configuration.

Version:
2.0
Author:
Vinzenz Wyser

Field Summary
static org.slf4j.Logger log
          Logger
 
Constructor Summary
SaveHandlerImpl()
          Call init to initialize the object
 
Method Summary
protected  java.lang.String cleanLineBreaks(java.lang.String valueStr, int isRichEditValue)
          Clean up the linebreaks and
 ItemType getCreationItemType()
          Defines the node type to create if isCreate is true
protected  MultipartForm getForm()
           
 java.lang.String getNodeCollectionName()
           
 java.lang.String getNodeName()
           
protected  Content getPageNode(HierarchyManager hm)
          Returns the page.
 java.lang.String getParagraph()
           
 java.lang.String getPath()
           
 java.lang.String getRepository()
          get the name of thre repository saving to
protected  Content getSaveNode(HierarchyManager hm, Content rootNode)
          Gets or creates the node saving to.
 javax.jcr.Value getValue(long l)
          Get the long value
 javax.jcr.Value getValue(java.lang.String s)
          Get a string value
 javax.jcr.Value getValue(java.lang.String valueStr, int type)
          Get the value for saving in jcr
 void init(MultipartForm form)
          Initialize the SaveHandlerImpl control.
 boolean isCreate()
          True if a not existing path should get created during the save process
protected  void processBinary(Content node, java.lang.String name)
          Process binary data.
protected  void processCommon(Content node, java.lang.String name, int type, int valueType, int encoding, java.lang.String[] values)
          Process a common value
protected  void processDate(Content node, java.lang.String name, int type, int valueType, int encoding, java.lang.String[] values)
           
protected  void processMultiple(Content node, java.lang.String name, int type, java.lang.String[] values)
          Process a multiple value field
protected  void processRemoveCommon(Content node, java.lang.String name)
          Remove the specified property on the node.
protected  void processRichEdit(Content node, java.lang.String name, int type, int isRichEditValue, int encoding, java.lang.String[] values)
          Parse the value returned by a rich text editor and update the links and linebreaks.
protected  void processSaveInfo(Content node, java.lang.String saveInfo)
          This method cares about one mgnlSaveInfo.
protected  void processString(Content node, java.lang.String name, int type, int encoding, java.lang.String[] values, java.lang.String valueStr)
          Process a string.
protected  void processWriteCommon(Content node, java.lang.String name, java.lang.String valueStr, int type)
          Writes a property value.
protected static java.lang.String replacePByBr(java.lang.String value, java.lang.String tagName)
           
 boolean save()
          Save the data passed by init.
static void saveDocument(Content node, Document doc, java.lang.String name, java.lang.String fileName, java.lang.String template)
          Saves a uploaded file in the magnolia way.
 void setCreate(boolean create)
          Set true if a not existing node should get created during the save process
 void setCreationItemType(ItemType creationItemType)
          Defines the node type to create if isCreate is true
protected  void setForm(MultipartForm form)
          set the from
 void setNodeCollectionName(java.lang.String nodeCollectionName)
           
 void setNodeName(java.lang.String nodeName)
           
 void setParagraph(java.lang.String paragraph)
           
 void setPath(java.lang.String path)
           
 void setRepository(java.lang.String repository)
          set the name of the repository saving to
protected  java.lang.String updateLinks(Content node, java.lang.String name, java.lang.String valueStr)
          Update the links in a string returned by a rich text editor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static org.slf4j.Logger log
Logger

Constructor Detail

SaveHandlerImpl

public SaveHandlerImpl()
Call init to initialize the object

Method Detail

init

public void init(MultipartForm form)
Initialize the SaveHandlerImpl control.

Specified by:
init in interface SaveHandler
Parameters:
form - the form generated from the request due to handle multipart forms

save

public boolean save()
Description copied from interface: SaveHandler
Save the data passed by init. Returns true if the save method succeeded

Specified by:
save in interface SaveHandler
See Also:
SaveHandler.save()

processSaveInfo

protected void processSaveInfo(Content node,
                               java.lang.String saveInfo)
                        throws javax.jcr.PathNotFoundException,
                               javax.jcr.RepositoryException,
                               AccessDeniedException
This method cares about one mgnlSaveInfo. It adds the value to the node

Parameters:
node - node to add data
saveInfo - name, type, valueType, isRichEditValue, encoding
Throws:
javax.jcr.PathNotFoundException - exception
javax.jcr.RepositoryException - exception
AccessDeniedException - no access

processDate

protected void processDate(Content node,
                           java.lang.String name,
                           int type,
                           int valueType,
                           int encoding,
                           java.lang.String[] values)

processRichEdit

protected void processRichEdit(Content node,
                               java.lang.String name,
                               int type,
                               int isRichEditValue,
                               int encoding,
                               java.lang.String[] values)
                        throws javax.jcr.PathNotFoundException,
                               javax.jcr.RepositoryException,
                               AccessDeniedException
Parse the value returned by a rich text editor and update the links and linebreaks.

Parameters:
node -
name -
type -
isRichEditValue -
encoding -
values -
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

cleanLineBreaks

protected java.lang.String cleanLineBreaks(java.lang.String valueStr,
                                           int isRichEditValue)
Clean up the linebreaks and

,
tags returned by the rich text editors

Parameters:
valueStr -
Returns:
the cleaned string

updateLinks

protected java.lang.String updateLinks(Content node,
                                       java.lang.String name,
                                       java.lang.String valueStr)
                                throws AccessDeniedException,
                                       javax.jcr.RepositoryException,
                                       javax.jcr.PathNotFoundException
Update the links in a string returned by a rich text editor. If there are links to temporary files created due the fckeditor upload mechanism those filese are written to the node.

Parameters:
node - node saving to. used to save the files and fileinfod to
name - the name of the field. used to make a subnode for the files
valueStr - the value containing the links
Returns:
the cleaned value
Throws:
AccessDeniedException
javax.jcr.RepositoryException
javax.jcr.PathNotFoundException

processCommon

protected void processCommon(Content node,
                             java.lang.String name,
                             int type,
                             int valueType,
                             int encoding,
                             java.lang.String[] values)
                      throws javax.jcr.PathNotFoundException,
                             javax.jcr.RepositoryException,
                             AccessDeniedException
Process a common value

Parameters:
node - node where the data must be stored
name - name of the field
type - type
valueType - internal value type (according to ControlImpl)
encoding - must we encode (base64)
values - all values belonging to this field
Throws:
javax.jcr.PathNotFoundException - exception
javax.jcr.RepositoryException - exception
AccessDeniedException - exception

processString

protected void processString(Content node,
                             java.lang.String name,
                             int type,
                             int encoding,
                             java.lang.String[] values,
                             java.lang.String valueStr)
                      throws javax.jcr.PathNotFoundException,
                             javax.jcr.RepositoryException,
                             AccessDeniedException
Process a string. This method will encode it

Parameters:
node -
name -
type -
encoding -
values -
valueStr -
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

processRemoveCommon

protected void processRemoveCommon(Content node,
                                   java.lang.String name)
                            throws javax.jcr.PathNotFoundException,
                                   javax.jcr.RepositoryException
Remove the specified property on the node.

Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

processWriteCommon

protected void processWriteCommon(Content node,
                                  java.lang.String name,
                                  java.lang.String valueStr,
                                  int type)
                           throws AccessDeniedException,
                                  javax.jcr.RepositoryException
Writes a property value.

Parameters:
node - the node
name - the property name to be written
valueStr - the value of the property
Throws:
AccessDeniedException - thrown if the write access is not granted
javax.jcr.RepositoryException - thrown if other repository exception is thrown

processMultiple

protected void processMultiple(Content node,
                               java.lang.String name,
                               int type,
                               java.lang.String[] values)
                        throws javax.jcr.RepositoryException,
                               javax.jcr.PathNotFoundException,
                               AccessDeniedException
Process a multiple value field

Parameters:
node -
name -
type -
values -
Throws:
javax.jcr.RepositoryException
javax.jcr.PathNotFoundException
AccessDeniedException

processBinary

protected void processBinary(Content node,
                             java.lang.String name)
                      throws javax.jcr.PathNotFoundException,
                             javax.jcr.RepositoryException,
                             AccessDeniedException
Process binary data. File- or imageupload.

Parameters:
node -
name -
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

getValue

public javax.jcr.Value getValue(java.lang.String s)
Get a string value

Parameters:
s -
Returns:
the value

getValue

public javax.jcr.Value getValue(long l)
Get the long value

Parameters:
l -
Returns:
the value

getValue

public javax.jcr.Value getValue(java.lang.String valueStr,
                                int type)
Get the value for saving in jcr

Parameters:
valueStr - string representation of the value
type - type of the value
Returns:
the value

replacePByBr

protected static java.lang.String replacePByBr(java.lang.String value,
                                               java.lang.String tagName)
Parameters:
value -
tagName -

isCreate

public boolean isCreate()
Description copied from interface: SaveHandler
True if a not existing path should get created during the save process

Specified by:
isCreate in interface SaveHandler
Returns:
boolean
See Also:
SaveHandler.isCreate()

setCreate

public void setCreate(boolean create)
Description copied from interface: SaveHandler
Set true if a not existing node should get created during the save process

Specified by:
setCreate in interface SaveHandler
See Also:
SaveHandler.setCreate(boolean)

getCreationItemType

public ItemType getCreationItemType()
Description copied from interface: SaveHandler
Defines the node type to create if isCreate is true

Specified by:
getCreationItemType in interface SaveHandler
Returns:
the ItemType
See Also:
SaveHandler.getCreationItemType()

setCreationItemType

public void setCreationItemType(ItemType creationItemType)
Description copied from interface: SaveHandler
Defines the node type to create if isCreate is true

Specified by:
setCreationItemType in interface SaveHandler
See Also:
SaveHandler.setCreationItemType(info.magnolia.cms.core.ItemType)

getForm

protected MultipartForm getForm()
Returns:
the form containing the values passed

setForm

protected void setForm(MultipartForm form)
set the from

Parameters:
form - containing the sended values

setRepository

public void setRepository(java.lang.String repository)
set the name of the repository saving to

Specified by:
setRepository in interface SaveHandler
Parameters:
repository - the name of the repository

getRepository

public java.lang.String getRepository()
get the name of thre repository saving to

Specified by:
getRepository in interface SaveHandler
Returns:
name

getPageNode

protected Content getPageNode(HierarchyManager hm)
                       throws javax.jcr.RepositoryException,
                              AccessDeniedException,
                              javax.jcr.PathNotFoundException
Returns the page. The page is created if not yet existing depending on the property create

Parameters:
hm -
Returns:
the node
Throws:
javax.jcr.RepositoryException
AccessDeniedException
javax.jcr.PathNotFoundException

getSaveNode

protected Content getSaveNode(HierarchyManager hm,
                              Content rootNode)
                       throws AccessDeniedException,
                              javax.jcr.RepositoryException
Gets or creates the node saving to.

Parameters:
hm -
rootNode - the node containing the saving node. If both the nodeCollectionName and the nodeName are empty this is the returned node.
Returns:
the node to which the content is saved
Throws:
AccessDeniedException
javax.jcr.RepositoryException

saveDocument

public static void saveDocument(Content node,
                                Document doc,
                                java.lang.String name,
                                java.lang.String fileName,
                                java.lang.String template)
                         throws javax.jcr.PathNotFoundException,
                                javax.jcr.RepositoryException,
                                AccessDeniedException
Saves a uploaded file in the magnolia way. It creates a subnode name_properties where all the information like the mime type is stored.

Parameters:
node - the node under which the data is stored
name - the name of the nodedata to store the data into
fileName - If empty the original filename is used
template - can be empty
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

getNodeCollectionName

public java.lang.String getNodeCollectionName()
Specified by:
getNodeCollectionName in interface SaveHandler
Returns:
Returns the nodeCollectionName.
See Also:
SaveHandler.getNodeCollectionName()

setNodeCollectionName

public void setNodeCollectionName(java.lang.String nodeCollectionName)
Specified by:
setNodeCollectionName in interface SaveHandler
Parameters:
nodeCollectionName - The nodeCollectionName to set.
See Also:
SaveHandler.setNodeCollectionName(java.lang.String)

getNodeName

public java.lang.String getNodeName()
Specified by:
getNodeName in interface SaveHandler
Returns:
Returns the nodeName.
See Also:
SaveHandler.getNodeName()

setNodeName

public void setNodeName(java.lang.String nodeName)
Specified by:
setNodeName in interface SaveHandler
Parameters:
nodeName - The nodeName to set.
See Also:
SaveHandler.setNodeName(java.lang.String)

getParagraph

public java.lang.String getParagraph()
Specified by:
getParagraph in interface SaveHandler
Returns:
Returns the paragraph.
See Also:
SaveHandler.getParagraph()

setParagraph

public void setParagraph(java.lang.String paragraph)
Specified by:
setParagraph in interface SaveHandler
Parameters:
paragraph - The paragraph to set.
See Also:
SaveHandler.setParagraph(java.lang.String)

getPath

public java.lang.String getPath()
Specified by:
getPath in interface SaveHandler
Returns:
Returns the path.
See Also:
SaveHandler.getPath()

setPath

public void setPath(java.lang.String path)
Specified by:
setPath in interface SaveHandler
Parameters:
path - The path to set.
See Also:
SaveHandler.setPath(java.lang.String)


Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.