Class CmsEditor

Direct Known Subclasses:
CmsDefaultPageEditor, CmsEditorFrameset, CmsSimpleEditor, CmsXmlContentEditor

public abstract class CmsEditor extends CmsEditorBase
Provides basic methods for building the file editors of OpenCms.

The editor classes have to extend this class and implement action methods for common editor actions.

Since:
6.0.0
  • Field Details

  • Constructor Details

  • Method Details

    • actionClear

      public abstract void actionClear(boolean forceUnlock)
      Unlocks the edited resource when in direct edit mode or when the resource was not modified.

      Parameters:
      forceUnlock - if true, the resource will be unlocked anyway
    • actionExit

      public abstract void actionExit() throws CmsException, IOException, javax.servlet.ServletException, javax.servlet.jsp.JspException
      Performs the exit editor action.

      Throws:
      CmsException - if something goes wrong
      IOException - if a forward fails
      javax.servlet.ServletException - if a forward fails
      javax.servlet.jsp.JspException - if including an element fails
    • actionSave

      public abstract void actionSave() throws IOException, javax.servlet.jsp.JspException
      Performs the save content action.

      Throws:
      IOException - if a redirection fails
      javax.servlet.jsp.JspException - if including an element fails
    • buildSelectElementLanguage

      public String buildSelectElementLanguage(String attributes, String resourceName, Locale selectedLocale)
      Builds the html String for the element language selector.

      Parameters:
      attributes - optional attributes for the <select> tag
      resourceName - the name of the resource to edit
      selectedLocale - the currently selected Locale
      Returns:
      the html for the element language selectbox
    • button

      public String button(String href, String target, String image, String label, int type, boolean useCustomImage)
      Generates a button for the OpenCms editor.

      Parameters:
      href - the href link for the button, if none is given the button will be disabled
      target - the href link target for the button, if none is given the target will be same window
      image - the image name for the button, skin path will be automatically added as prefix
      label - the label for the text of the button
      type - 0: image only (default), 1: image and text, 2: text only
      useCustomImage - if true, the button has to be placed in the editors "custom pics" folder
      Returns:
      a button for the OpenCms editor
    • buttonActionCancel

      Returns the editor action for a "cancel" button.

      This overwrites the cancel method of the CmsDialog class.

      Always use this value, do not write anything directly in the html page.

      Returns:
      the default action for a "cancel" button
    • buttonActionDirectEdit

      public String buttonActionDirectEdit(String jsFunction, int type)
      Builds the html to display the special action button for the direct edit mode of the editor.

      Parameters:
      jsFunction - the JavaScript function which will be executed on the mouseup event
      type - 0: image only (default), 1: image and text, 2: text only
      Returns:
      the html to display the special action button
    • checkLock

      public void checkLock(String resource, CmsLockType type) throws CmsException
      Description copied from class: CmsWorkplace
      Checks the lock state of the resource and locks it if the autolock feature is enabled.

      Overrides:
      checkLock in class CmsWorkplace
      Parameters:
      resource - the resource name which is checked
      type - indicates the mode CmsLockType.EXCLUSIVE or CmsLockType.TEMPORARY
      Throws:
      CmsException - if reading or locking the resource fails
      See Also:
    • deleteLocaleButton

      public String deleteLocaleButton(String href, String target, String image, String label, int type)
      Generates a button for delete locale.

      Parameters:
      href - the href link for the button, if none is given the button will be disabled
      target - the href link target for the button, if none is given the target will be same window
      image - the image name for the button, skin path will be automatically added as prefix
      label - the label for the text of the button
      type - 0: image only (default), 1: image and text, 2: text only
      Returns:
      a button for the OpenCms workplace
    • getEditorDisplayOptions

      Returns the instantiated editor display option class from the workplace manager.

      This is a convenience method to be used on editor JSPs.

      Returns:
      the instantiated editor display option class
    • getEditorResourceUri

      public abstract String getEditorResourceUri()
      Returns the URI to the editor resource folder where button images and javascripts are located.

      Returns:
      the URI to the editor resource folder
    • getOpenCmsContext

      Returns the OpenCms request context path.

      This is a convenience method to use in the editor.

      Returns:
      the OpenCms request context path
    • getParamBacklink

      Returns the back link when closing the editor.

      Returns:
      the back link
    • getParamContent

      Returns the content of the editor.

      Returns:
      the content of the editor
    • getParamDirectedit

      Returns the direct edit flag parameter.

      Returns:
      the direct edit flag parameter
    • getParamEditastext

      Returns the edit as text parameter.

      Returns:
      the edit as text parameter
    • getParamEditormode

      Returns the editor mode parameter.

      Returns:
      the editor mode parameter
    • getParamElementlanguage

      Returns the current element language.

      Returns:
      the current element language
    • getParamLoaddefault

      Returns the "loaddefault" parameter to determine if the default editor should be loaded.

      Returns:
      the "loaddefault" parameter
    • getParamModified

      Returns the modified parameter indicating if the resource has been saved.

      Returns:
      the modified parameter indicating if the resource has been saved
    • getParamOldelementlanguage

      Returns the old element language.

      Returns:
      the old element language
    • getParamTempfile

      Returns the name of the temporary file.

      Returns:
      the name of the temporary file
    • getPicsUri

      public String getPicsUri()
      Returns the path to the images used by this editor.

      Returns:
      the path to the images used by this editor
    • setParamBacklink

      public void setParamBacklink(String backLink)
      Sets the back link when closing the editor.

      Parameters:
      backLink - the back link
    • setParamContent

      public void setParamContent(String content)
      Sets the content of the editor.

      Parameters:
      content - the content of the editor
    • setParamDirectedit

      public void setParamDirectedit(String direct)
      Sets the direct edit flag parameter.

      Parameters:
      direct - the direct edit flag parameter
    • setParamEditastext

      public void setParamEditastext(String editAsText)
      Sets the edit as text parameter.

      Parameters:
      editAsText - "true" if the resource should be handled like a text file
    • setParamEditormode

      public void setParamEditormode(String mode)
      Sets the editor mode parameter.

      Parameters:
      mode - the editor mode parameter
    • setParamElementlanguage

      public void setParamElementlanguage(String elementLanguage)
      Sets the current element language.

      Parameters:
      elementLanguage - the current element language
    • setParamLoaddefault

      public void setParamLoaddefault(String loadDefault)
      Sets the "loaddefault" parameter to determine if the default editor should be loaded.

      Parameters:
      loadDefault - the "loaddefault" parameter
    • setParamModified

      public void setParamModified(String modified)
      Sets the modified parameter indicating if the resource has been saved.

      Parameters:
      modified - the modified parameter indicating if the resource has been saved
    • setParamOldelementlanguage

      public void setParamOldelementlanguage(String oldElementLanguage)
      Sets the old element language.

      Parameters:
      oldElementLanguage - the old element language
    • setParamTempfile

      public void setParamTempfile(String fileName)
      Sets the name of the temporary file.

      Parameters:
      fileName - the name of the temporary file
    • actionClose

      protected void actionClose() throws IOException, javax.servlet.jsp.JspException, javax.servlet.ServletException
      Closes the editor and forwards to the workplace or the resource depending on the editor mode.

      Throws:
      IOException - if forwarding fails
      javax.servlet.ServletException - if forwarding fails
      javax.servlet.jsp.JspException - if including a JSP fails
    • clearEditorSessionInfo

      protected void clearEditorSessionInfo()
      Clears the editor session info bean.

    • commitTempFile

      protected void commitTempFile() throws CmsException
      Writes the content of a temporary file back to the original file.

      Throws:
      CmsException - if something goes wrong
    • createTempFile

      protected String createTempFile() throws CmsException
      Creates a temporary file which is needed while working in an editor with preview option.

      Returns:
      the file name of the temporary file
      Throws:
      CmsException - if something goes wrong
    • decodeContent

      protected String decodeContent(String content)
      Decodes the given content the same way the client would do it.

      Content is decoded as if it was encoded using the JavaScript "encodeURIComponent()" function.

      Parameters:
      content - the content to decode
      Returns:
      the decoded content
    • decodeParamValue

      protected String decodeParamValue(String paramName, String paramValue)
      Decodes an individual parameter value, ensuring the content is always decoded in UTF-8.

      For editors the content is always encoded using the JavaScript encodeURIComponent() method on the client, which always encodes in UTF-8.

      Overrides:
      decodeParamValue in class CmsWorkplace
      Parameters:
      paramName - the name of the parameter
      paramValue - the unencoded value of the parameter
      Returns:
      the encoded value of the parameter
    • deleteTempFile

      protected void deleteTempFile()
      Deletes a temporary file from the OpenCms VFS, needed when exiting an editor.

    • encodeContent

      protected String encodeContent(String content)
      Encodes the given content so that it can be transfered to the client.

      Content is encoded so that it is compatible with the JavaScript "decodeURIComponent()" function.

      Parameters:
      content - the content to encode
      Returns:
      the encoded content
    • getCloneCms

      protected CmsObject getCloneCms() throws CmsException
      Returns a cloned cms instance that prevents the time range resource filter check.

      Use it always for unmarshalling and file writing.

      Returns:
      a cloned cms instance that prevents the time range resource filter check
      Throws:
      CmsException - if something goes wrong
    • getEditorSessionInfo

      Returns the editor session info bean.

      Returns:
      the editor session info bean
    • getFileEncoding

      protected String getFileEncoding()
      Returns the encoding parameter.

      Returns:
      the encoding parameter
    • getFileEncoding

      protected String getFileEncoding(CmsObject cms, String filename)
      Helper method to determine the encoding of the given file in the VFS, which must be set using the "content-encoding" property.

      Parameters:
      cms - the CmsObject
      filename - the name of the file which is to be checked
      Returns:
      the encoding for the file
    • initContent

      protected abstract void initContent()
      Initializes the editor content when openening the editor for the first time.

    • initMessages

      protected void initMessages()
      Description copied from class: CmsWorkplace
      Initializes the message object.

      By default the CmsWorkplaceMessages are initialized.

      You SHOULD override this method for setting the bundles you really need, using the CmsWorkplace.addMessages(CmsMessages) or CmsWorkplace.addMessages(String) method.

      Overrides:
      initMessages in class CmsWorkplace
      See Also:
    • initSessionInfo

      protected void initSessionInfo()
      Initializes the editor session info bean.

    • setFileEncoding

      protected void setFileEncoding(String value)
      Sets the encoding parameter.

      Parameters:
      value - the encoding value to set
    • showErrorPage

      protected void showErrorPage(Exception exception) throws javax.servlet.jsp.JspException
      Shows the selected error page in case of an exception.

      Parameters:
      exception - the current exception
      Throws:
      javax.servlet.jsp.JspException - if inclusion of the error page fails
    • showErrorPage

      protected void showErrorPage(Object editor, Exception exception) throws javax.servlet.jsp.JspException
      Shows the selected error page in case of an exception.

      Parameters:
      editor - initialized instance of the editor class
      exception - the current exception
      Throws:
      javax.servlet.jsp.JspException - if inclusion of the error page fails