Package org.opencms.ugc
Class CmsUgcSession
java.lang.Object
org.opencms.ugc.CmsUgcSession
- All Implemented Interfaces:
I_CmsSessionDestroyHandler
A form editing session is required to create and edit contents from the web front-end.
-
Nested Class Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
CmsUgcSession
(CmsObject cms) Constructor.CmsUgcSession
(CmsObject adminCms, CmsObject cms, CmsUgcConfiguration configuration) Constructor.CmsUgcSession
(CmsObject cms, CmsUgcConfiguration configuration) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addContentValue
(CmsXmlContent content, Locale locale, String path, String value) Adds the given value to the content document.protected CmsXmlContent
addContentValues
(CmsFile file, Map<String, String> contentValues) Adds the given values to the content document.protected void
addContentValues
(CmsXmlContent content, Locale locale, Map<String, String> contentValues) Adds the given values to the content document.createUploadResource
(String fieldName, String rawFileName, byte[] content) Creates a new resource from upload data.Creates a new edit resource.protected void
deleteContentValue
(CmsXmlContent content, Locale locale, String path) Deletes the given value path from the content document.void
Disables auto-cleanup on session destruction.void
finish()
Finishes the session and publishes the changed resources if necessary.Gets the CMS context used by this session.getContentValues
(CmsXmlContent content, Locale locale) Returns the content values of the requested locale.Gets the form upload helper belonging to this session.getId()
Returns the session id.Returns the locale to use for messages generated by the form session which are intended to be displayed on the client.Returns the edit project.Returns the edit resource.Returns the content values.boolean
Returns true if the session is finished.loadXmlContent
(String fileName) Loads the existing edit resource.void
This method is called when the session in which this object is stored as an attribute is destroyed.saveContent
(Map<String, String> contentValues) Saves the content values to the sessions edit resource.validateContent
(Map<String, String> contentValues) Validates the content values.
-
Constructor Details
-
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
Constructor.- Parameters:
cms
- the cms contextconfiguration
- the form configuration- Throws:
CmsException
- if creating the session project fails
-
CmsUgcSession
Constructor. For test purposes only.- Parameters:
cms
- the cms context
-
-
Method Details
-
createUploadResource
public CmsResource createUploadResource(String fieldName, 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
Creates a new edit resource.- Returns:
- the newly created resource
- Throws:
CmsUgcException
- if creating the resource fails
-
disableCleanup
Disables auto-cleanup on session destruction. -
finish
Finishes the session and publishes the changed resources if necessary.- Throws:
CmsException
- if something goes wrong
-
getCmsObject
Gets the CMS context used by this session.- Returns:
- the CMS context used by this session
-
getFormUploadHelper
Gets the form upload helper belonging to this session.- Returns:
- the form upload helper belonging to this session
-
getId
Returns the session id.- Returns:
- the session id
-
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
Returns the edit project.- Returns:
- the edit project
-
getResource
Returns the edit resource.- Returns:
- the edit resource
-
getValues
Returns the content values.- Returns:
- the content values
- Throws:
CmsException
- if reading the content fails
-
isFinished
Returns true if the session is finished.- Returns:
- true if the session is finished
-
loadXmlContent
Loads the existing edit resource.- Parameters:
fileName
- the resource file name- Returns:
- the edit resource
- Throws:
CmsUgcException
- if reading the resource fails
-
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:
-
saveContent
public CmsXmlContentErrorHandler saveContent(Map<String, String> contentValues) throws CmsUgcExceptionSaves 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(Map<String, String> contentValues) throws CmsUgcExceptionValidates the content values.- Parameters:
contentValues
- the content values to validate- Returns:
- the validation handler
- Throws:
CmsUgcException
- if reading the content file fails
-
addContentValue
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, Map<String, String> contentValues) throws CmsExceptionAdds 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, Locale locale, Map<String, String> contentValues) throws CmsXmlExceptionAdds 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
Deletes the given value path from the content document.- Parameters:
content
- the content documentlocale
- the content localepath
- the value XPath
-
getContentValues
Returns the content values of the requested locale.- Parameters:
content
- the content documentlocale
- the content locale- Returns:
- the values
-