cancel
Showing results for 
Search instead for 
Did you mean: 

Which class is responsible for setting default value?

raweck
Champ on-the-rise
Champ on-the-rise
Which class is responsible for setting default value for property?
I mean property defined for example in contentModel.xml

            <property name="cm:initialVersion">
               <title>Initial Version</title>
               <type>d:boolean</type>
               <default>true</default>
            </property>
1 REPLY 1

rivarola
Champ on-the-rise
Champ on-the-rise
Hello,

You can have a look at AbstractNodeServiceImpl :

    /**
     * Sets the default property values
     *
     * @param classDefinition       the model type definition for which to get defaults
     * @param properties            the properties of the node
     */
    protected void addDefaultPropertyValues(ClassDefinition classDefinition, Map<QName, Serializable> properties)
    {
        for (Map.Entry<QName, Serializable> entry : classDefinition.getDefaultValues().entrySet())
        {
            if (properties.containsKey(entry.getKey()))
            {
                // property is present
                continue;
            }
            Serializable value = entry.getValue();
           
            // Check the type of the default property
            PropertyDefinition prop = this.dictionaryService.getProperty(entry.getKey());
            if (prop == null)
            {
                // dictionary doesn't have a default value present
                continue;
            }

            // TODO: what other conversions are necessary here for other types of default values ?
           
            // ensure that we deliver the property in the correct form
            if (DataTypeDefinition.BOOLEAN.equals(prop.getDataType().getName()) == true)
            {
                if (value instanceof String)
                {
                    if (((String)value).toUpperCase().equals("TRUE") == true)
                    {
                        value = Boolean.TRUE;
                    }
                    else if (((String)value).toUpperCase().equals("FALSE") == true)
                    {
                        value = Boolean.FALSE;
                    }
                }
            }
           
            // Set the default value of the property
            properties.put(entry.getKey(), value);
        }
    }