Site Manager Developer Manual / Version 2204
Table Of ContentsInitializers fill the fields of a newly created document with default values.
Interface to implement
For own initializers you need to implement the interface
hox.corem.editor.initialization.Initializer
with the method getInitialValue
.
Parameters to use
The getInitialValue
method gets the following parameters:
Parameter |
Type |
Description |
---|---|---|
document |
DocumentModel |
The document which contains the property to initialize. |
|
|
The property to initialize. |
Table 4.1. Parameters of the getInitialValue method
Return Type
Depending on the property type for which the initializer is intended to use the method may return the following
values (return type is Object
):
Property |
Default PropertyModel |
Value |
---|---|---|
String |
|
String |
Integer |
|
Integer |
Date |
|
Calendar |
LinkList |
|
|
SgmlText |
|
|
Blob |
|
byte[] |
Table 4.2. Return values of the getInitialValue method
Integrate your Initializer into the Site Manager using editor.xml
You can integrate your Initializer into the Site Manager using the element
Initializer
of the editor.xml
file as shown in example.
<DocumentTypes> <DocumentType name="SomeType"> <PropertyType name="SomeProperty"> <Initializer class="com.customer.example.editor.SimpleInitializer"/> </PropertyType> </DocumentType> </DocumentTypes>
Example 4.1. Integrate Initializer in editor.xml
Example:
The next example shows a simple Initializer which checks whether the property to initialize is of type String or not. If it is, the property will get the name of the creator of the document as the initial setting.
import hox.corem.editor.initialization.Initializer; import hox.corem.editor.proxy.*; public class SimpleInitializer implements Initializer { public Object getInitialValue(DocumentModel doc, PropertyTypeModel p) { String result = ""; try { int ver = doc.getLatestVersion(); PropertyModel pm = doc.getPropertyModel(ver, p.getName()); if (pm instanceof StringModel) { result = doc.getCreator().getName(); } } catch (Exception e) { } return result; } }
Example 4.2. Example of an Initializer