ResourceController

public class ResourceController

The controller responsible for serving CMS-Lite resources to users through HTTP. Handles both the grid in the cms-lite UI and REST requests for particular resources.

Methods

addContent

public void addContent(String type, String name, String language, String value, MultipartFile file)

Creates a new content in the system. Performed by the UI.

Parameters:
  • type – the type of the content, either string or stream
  • name – the name of the content
  • language – the language of the content
  • value – the value of the content in case of a string content
  • file – the file to be saved as the content in case of a stream content
Throws:
  • IOException – if there were IO issues with the uploaded file
  • CMSLiteException – if a wrong combination of parameters was passed

autocompleteField

public Set<String> autocompleteField(String field, String term)

Handles the auto-complete feature for cms-lite. Will return auto-completions for the given field.

Parameters:
  • field – the field to auto-complete, name and language are currently supported
  • term – what should be auto-complete, what the user has entered
Throws:
Returns:

a set of auto-completion values

editStreamContent

public void editStreamContent(String language, String name, MultipartFile file)

Updates an existing stream content in the CMS system. Performed by the UI.

Parameters:
  • language – the language for the content
  • name – the name of the content
  • file – the file that should be persisted as this content
Throws:
  • IOException – if there were IO issues with the uploaded file
  • ContentNotFoundException – if the content does not exist

editStringContent

public void editStringContent(String language, String name, String value)

Updates an existing string content in the CMS system. Performed by the UI.

Parameters:
  • language – the language for the content
  • name – the name of the content
  • value – the value of the content
Throws:

getAllLanguages

public Set<String> getAllLanguages()

Returns all languages associated with any content in cms-lite.

Returns:all languages from the system

getContent

public Content getContent(String type, String language, String name)

Retrieves a content of a given type for the UI.

Parameters:
  • type – the type of the content, either stream or string
  • language – the language of the content
  • name – the name of the content
Throws:
Returns:

the matching content object

getContents

public Resources getContents(GridSettings settings)

Retrieves resource entries for the jqgrid. The returned object will not contain the content, only their types, names and languages.

Parameters:
  • settings – the settings of the grid, filtering and paging information
Returns:

all resources matching the criteria

getStreamContent

public void getStreamContent(String language, String name, HttpServletResponse response)

Retrieves the given stream content in raw form. Used by external callers to retrieve the content. This writes the content to the HttpServletResponse object and also sets the mime on that response to the type of the content.

Parameters:
  • language – the language of the content
  • name – the name of the content
  • response – the http response into which the content will be written to
Throws:
  • IOException – if there was an IO error writing to the response
  • ContentNotFoundException – if the content does not exist

getStringContent

public void getStringContent(String language, String name, HttpServletResponse response)

Retrieves the given string content in raw form. Used by external callers to retrieve the content. This writes the content as text to the HttpServletResponse object and also sets the mime to text/plain.

Parameters:
  • language – the language of the content
  • name – the name of the content
  • response – the http response into which the content will be written to
Throws:
  • IOException – if there was an IO error writing to the response
  • ContentNotFoundException – if the content does not exist

handleCMSLiteException

public String handleCMSLiteException(Exception e)

Handler for the org.motechproject.cmslite.model.CMSLiteException. Will return 400 (Bad Request) as the HTTP response code and the message from the exception as the body.

Parameters:
  • e – the exception to handle
Returns:

the message from the exception, to be displayed as the response body

handleContentNotFoundException

public String handleContentNotFoundException(Exception e)

Handler for the org.motechproject.cmslite.model.ContentNotFoundException. Will return 404 (Not Found) as the HTTP response code and the message from the exception as the body.

Parameters:
  • e – the exception to handle
Returns:

the message from the exception, to be displayed as the response body

removeContent

public void removeContent(String type, String language, String name)

Removes the content of the given type from the CMS system. Performed by the UI.

Parameters:
  • type – the type of the content
  • language – the language of the content
  • name – the name of the content
Throws: