Page History
Retrieve an IContentManager
The IPortalContext has an IContentManagerFactory which can be used to create an IContentManager. To retrieve an IContentManager based on a connection, see the following code snippet for an example:
...
Which connectionName to use depends on your project's configuration.
Creating new content
The following code snippet shows how to create new content based on a given string.
...
The properties object may be used to store additional properties with the content. The contentId will be required to read, update or delete this content at a later time.
Read content
The following code snippet shows how to retrieve the string that was created in the previous example.
...
Code Block | ||
---|---|---|
| ||
IContentMetadata metadata = contentManager.readMetadata(contentId, context.getSessionScope().getActiveUser()); StringValue propertyValue = metadata.getProperties().getProperty("customProperty"); |
Update existing content
It is possible to update only the data, only properties or both. The following code snippet shows how to update all at once, overloads exists which do not require all arguments:
Code Block | ||
---|---|---|
| ||
InputStream stream = new ByteArrayInputStream(newContentString.getBytes("UTF-8")); CustomContentProperties properties = new CustomContentProperties(); properties.setProperty("customProperty", new StringValue("newValue")); String contentName = "new content name"; String contentType = "text/plain"; contentManager.update(contentId, stream, contentName, contentType, properties, context.getSessionScope().getActiveUser()); |
Delete content
The following example shows how to delete the content made in the previous example:
...