Package org.opencms.ugc
Class CmsUgcSession
- java.lang.Object
-
- org.opencms.ugc.CmsUgcSession
-
- All Implemented Interfaces:
I_CmsSessionDestroyHandler
public class CmsUgcSession extends java.lang.Object implements I_CmsSessionDestroyHandler
A form editing session is required to create and edit contents from the web front-end.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsUgcSession.PathComparator
Compares XPaths.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CmsUgcSession(CmsObject cms)
Constructor.CmsUgcSession(CmsObject adminCms, CmsObject cms, CmsUgcConfiguration configuration)
Constructor.CmsUgcSession(CmsObject cms, CmsUgcConfiguration configuration)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addContentValue(CmsXmlContent content, java.util.Locale locale, java.lang.String path, java.lang.String value)
Adds the given value to the content document.protected CmsXmlContent
addContentValues(CmsFile file, java.util.Map<java.lang.String,java.lang.String> contentValues)
Adds the given values to the content document.protected void
addContentValues(CmsXmlContent content, java.util.Locale locale, java.util.Map<java.lang.String,java.lang.String> contentValues)
Adds the given values to the content document.CmsResource
createUploadResource(java.lang.String fieldName, java.lang.String rawFileName, byte[] content)
Creates a new resource from upload data.CmsResource
createXmlContent()
Creates a new edit resource.protected void
deleteContentValue(CmsXmlContent content, java.util.Locale locale, java.lang.String path)
Deletes the given value path from the content document.void
disableCleanup()
Disables auto-cleanup on session destruction.void
finish()
Finishes the session and publishes the changed resources if necessary.CmsObject
getCmsObject()
Gets the CMS context used by this session.protected java.util.Map<java.lang.String,java.lang.String>
getContentValues(CmsXmlContent content, java.util.Locale locale)
Returns the content values of the requested locale.CmsUgcUploadHelper
getFormUploadHelper()
Gets the form upload helper belonging to this session.CmsUUID
getId()
Returns the session id.java.util.Locale
getMessageLocale()
Returns the locale to use for messages generated by the form session which are intended to be displayed on the client.CmsProject
getProject()
Returns the edit project.CmsResource
getResource()
Returns the edit resource.java.util.Map<java.lang.String,java.lang.String>
getValues()
Returns the content values.boolean
isFinished()
Returns true if the session is finished.CmsResource
loadXmlContent(java.lang.String fileName)
Loads the existing edit resource.void
onSessionDestroyed()
This method is called when the session in which this object is stored as an attribute is destroyed.CmsXmlContentErrorHandler
saveContent(java.util.Map<java.lang.String,java.lang.String> contentValues)
Saves the content values to the sessions edit resource.CmsXmlContentErrorHandler
validateContent(java.util.Map<java.lang.String,java.lang.String> contentValues)
Validates the content values.
-
-
-
Constructor Detail
-
CmsUgcSession
public CmsUgcSession(CmsObject adminCms, CmsObject cms, CmsUgcConfiguration configuration) throws CmsException
Constructor.- Parameters:
adminCms
- the cms context with admin privilegescms
- the cms contextconfiguration
- the form configuration- Throws:
CmsException
- if creating the session project fails
-
CmsUgcSession
public CmsUgcSession(CmsObject cms, CmsUgcConfiguration configuration) throws CmsException
Constructor.- Parameters:
cms
- the cms contextconfiguration
- the form configuration- Throws:
CmsException
- if creating the session project fails
-
CmsUgcSession
protected CmsUgcSession(CmsObject cms)
Constructor. For test purposes only.- Parameters:
cms
- the cms context
-
-
Method Detail
-
createUploadResource
public CmsResource createUploadResource(java.lang.String fieldName, java.lang.String rawFileName, byte[] content) throws CmsUgcException
Creates a new resource from upload data.- Parameters:
fieldName
- the name of the form field for the uploadrawFileName
- the file namecontent
- the file content- Returns:
- the newly created resource
- Throws:
CmsUgcException
- if creating the resource fails
-
createXmlContent
public CmsResource createXmlContent() throws CmsUgcException
Creates a new edit resource.- Returns:
- the newly created resource
- Throws:
CmsUgcException
- if creating the resource fails
-
disableCleanup
public void disableCleanup()
Disables auto-cleanup on session destruction.
-
finish
public void finish() throws CmsException
Finishes the session and publishes the changed resources if necessary.- Throws:
CmsException
- if something goes wrong
-
getCmsObject
public CmsObject getCmsObject()
Gets the CMS context used by this session.- Returns:
- the CMS context used by this session
-
getFormUploadHelper
public CmsUgcUploadHelper getFormUploadHelper()
Gets the form upload helper belonging to this session.- Returns:
- the form upload helper belonging to this session
-
getMessageLocale
public java.util.Locale getMessageLocale()
Returns the locale to use for messages generated by the form session which are intended to be displayed on the client.- Returns:
- the locale to use for messages
-
getProject
public CmsProject getProject()
Returns the edit project.- Returns:
- the edit project
-
getResource
public CmsResource getResource()
Returns the edit resource.- Returns:
- the edit resource
-
getValues
public java.util.Map<java.lang.String,java.lang.String> getValues() throws CmsException
Returns the content values.- Returns:
- the content values
- Throws:
CmsException
- if reading the content fails
-
isFinished
public boolean isFinished()
Returns true if the session is finished.- Returns:
- true if the session is finished
-
loadXmlContent
public CmsResource loadXmlContent(java.lang.String fileName) throws CmsUgcException
Loads the existing edit resource.- Parameters:
fileName
- the resource file name- Returns:
- the edit resource
- Throws:
CmsUgcException
- if reading the resource fails
-
onSessionDestroyed
public void onSessionDestroyed()
Description copied from interface:I_CmsSessionDestroyHandler
This method is called when the session in which this object is stored as an attribute is destroyed.- Specified by:
onSessionDestroyed
in interfaceI_CmsSessionDestroyHandler
- See Also:
I_CmsSessionDestroyHandler.onSessionDestroyed()
-
saveContent
public CmsXmlContentErrorHandler saveContent(java.util.Map<java.lang.String,java.lang.String> contentValues) throws CmsUgcException
Saves the content values to the sessions edit resource.- Parameters:
contentValues
- the content values by XPath- Returns:
- the validation handler
- Throws:
CmsUgcException
- if writing the content fails
-
validateContent
public CmsXmlContentErrorHandler validateContent(java.util.Map<java.lang.String,java.lang.String> contentValues) throws CmsUgcException
Validates the content values.- Parameters:
contentValues
- the content values to validate- Returns:
- the validation handler
- Throws:
CmsUgcException
- if reading the content file fails
-
addContentValue
protected void addContentValue(CmsXmlContent content, java.util.Locale locale, java.lang.String path, java.lang.String value)
Adds the given value to the content document.- Parameters:
content
- the content documentlocale
- the content localepath
- the value XPathvalue
- the value
-
addContentValues
protected CmsXmlContent addContentValues(CmsFile file, java.util.Map<java.lang.String,java.lang.String> contentValues) throws CmsException
Adds the given values to the content document.- Parameters:
file
- the content filecontentValues
- the values to add- Returns:
- the content document
- Throws:
CmsException
- if writing the XML fails
-
addContentValues
protected void addContentValues(CmsXmlContent content, java.util.Locale locale, java.util.Map<java.lang.String,java.lang.String> contentValues) throws CmsXmlException
Adds the given values to the content document.- Parameters:
content
- the content documentlocale
- the content localecontentValues
- the values- Throws:
CmsXmlException
- if writing the XML fails
-
deleteContentValue
protected void deleteContentValue(CmsXmlContent content, java.util.Locale locale, java.lang.String path)
Deletes the given value path from the content document.- Parameters:
content
- the content documentlocale
- the content localepath
- the value XPath
-
getContentValues
protected java.util.Map<java.lang.String,java.lang.String> getContentValues(CmsXmlContent content, java.util.Locale locale)
Returns the content values of the requested locale.- Parameters:
content
- the content documentlocale
- the content locale- Returns:
- the values
-
-