The following recipes show how to create simple content. As we don't want to rely on a specific installation with predefined content types we first show how to create a content type group and a simple content type within this group. Then we will create a content object of the newly created content type. The last two recipes show how to create content containing images and xml text.
Creating a content type group
This snippet creates a content type group for a given identifier (Full code here).
If this snipped is run with the same init code from recipe 1 we will get an UnauthorizedException.
The solution is described in the next recipe.
Setting the user for authorizing actions
By default the repository assumes the anonymous user is acting. To change this the following code can be executed
If the user is identified by other mechanisms the user also can be loaded by its id via the service method
Creating a content type
With this snipped a content type with two fields of type 'ezstring' is created. (Full code here).
In this recipe content is created under a given parent location. It is assumed that the loaded content type is the one created in recipe 4. (Full code here).
In this recipe the previously created content is updated with a new title and body in the same language. (Full code here)
It is the same code as for updating (see recipe 6). The initial language should be set to the translation language.
Multiple translations at once
It is possible to to make an update in content or create content with more than one language. But there is a restriction - only one language can be assigned to the newly created version (which is displayed in the 4.x admin GUI in the translations column).
Creating Content containing an image
This recipe shows how to create an content object containing an image. (Full code here)
Create Content with XML Text
This recipe shows how to create content with xml text. As content type the folder is used where the description is filled with xml. It is also shown how to embed the previously created image in the description. The image Id is given by a command line argument.