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 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  String cleanLineBreaks(String valueStr, int isRichEditValue)
          Clean up the linebreaks and ,
tags returned by the rich text editors
protected  String cleanupLinkPrefix(Content filesNode, String link, String prefixRepo)
           
 ItemType getCollectionNodeCreationItemType()
           
 ItemType getCreationItemType()
          Defines the node type to create if isCreate is true
protected  MultipartForm getForm()
           
 String getNodeCollectionName()
           
 String getNodeName()
           
protected  Content getPageNode(HierarchyManager hm)
          Returns the page.
 String getParagraph()
           
 String getPath()
           
 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(String s)
          Get a string value
 javax.jcr.Value getValue(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, String name)
          Process binary data.
protected  void processCommon(Content node, String name, int type, int valueType, int encoding, String[] values)
          Process a common value
protected  void processDate(Content node, String name, int type, int valueType, int encoding, String[] values)
           
protected  void processMultiple(Content node, String name, int type, String[] values)
          Process a multiple value field
protected  void processRemoveCommon(Content node, String name)
          Remove the specified property on the node.
protected  void processRichEdit(Content node, String name, int type, int isRichEditValue, int encoding, String[] values)
          Parse the value returned by a rich text editor and update the links and linebreaks.
protected  void processSaveInfo(Content node, String saveInfo)
          This method cares about one mgnlSaveInfo.
protected  void processString(Content node, String name, int type, int encoding, String[] values, String valueStr)
          Process a string.
protected  void processWriteCommon(Content node, String name, String valueStr, int type)
          Writes a property value.
protected static String replacePByBr(String value, String tagName)
           
 boolean save()
          Save the data passed by init.
static void saveDocument(Content node, Document doc, String name, String fileName, String template)
          Saves a uploaded file in the magnolia way.
 void setCollectionNodeCreationItemType(ItemType collectionNodeCreationItemType)
           
 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(String nodeCollectionName)
           
 void setNodeName(String nodeName)
           
 void setParagraph(String paragraph)
           
 void setPath(String path)
           
 void setRepository(String repository)
          set the name of the repository saving to
protected  String updateLinks(Content node, String name, 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,
                               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,
                           String name,
                           int type,
                           int valueType,
                           int encoding,
                           String[] values)

processRichEdit

protected void processRichEdit(Content node,
                               String name,
                               int type,
                               int isRichEditValue,
                               int encoding,
                               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 String cleanLineBreaks(String valueStr,
                                 int isRichEditValue)
Clean up the linebreaks and

,
tags returned by the rich text editors

Parameters:
valueStr -
Returns:
the cleaned string

updateLinks

protected String updateLinks(Content node,
                             String name,
                             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

cleanupLinkPrefix

protected String cleanupLinkPrefix(Content filesNode,
                                   String link,
                                   String prefixRepo)

processCommon

protected void processCommon(Content node,
                             String name,
                             int type,
                             int valueType,
                             int encoding,
                             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,
                             String name,
                             int type,
                             int encoding,
                             String[] values,
                             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,
                                   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,
                                  String name,
                                  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,
                               String name,
                               int type,
                               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,
                             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(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(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 String replacePByBr(String value,
                                     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)

getCollectionNodeCreationItemType

public ItemType getCollectionNodeCreationItemType()
Specified by:
getCollectionNodeCreationItemType in interface SaveHandler

setCollectionNodeCreationItemType

public void setCollectionNodeCreationItemType(ItemType collectionNodeCreationItemType)
Specified by:
setCollectionNodeCreationItemType in interface SaveHandler

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(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 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,
                                String name,
                                String fileName,
                                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 or default title is used
template - can be empty
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

getNodeCollectionName

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

setNodeCollectionName

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

getNodeName

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

setNodeName

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

getParagraph

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

setParagraph

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

getPath

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

setPath

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


Copyright © 2003–2014 Magnolia International Ltd.. All rights reserved.