[opencms-dev] Editting code

Christoph Schönfeld cschoenfeld at sylphen.com
Thu Jan 18 09:39:33 CET 2007


Hi,

1. The preview can be configured in the XML schema file of your resource 
type like shown in this example:

    <xsd:annotation>
        <xsd:appinfo>
            <resourcebundle/>
            <preview uri="${previewtempfile}" />
            <mappings/>
            <layouts/>
            <defaults/>
        </xsd:appinfo>
    </xsd:annotation>

The XML Editor will then show a preview icon in the top right corner.

2. You can OpenCms.publishResource() to publish a file. It is executed 
when the publish button is pressed. I cannot tell you  how the button is 
wired to the call.

 From my theoretical understanding of the OpenCms API I would say that 
in order to publish a resource after it is saved your module action 
class should register a CmsEventListener with the CmsEventManager. The 
listener will be notified of any event that occurs . It should watch for 
events with a type (CmsEvent.getType()) of 
I_CmsEventListener.EVENT_RESOURCE_MODIFIED and the desired resource type.

Here is some code that should get you started:

public class ModuleStartupAction implements I_CmsModuleAction {

    /**
     * @see 
org.opencms.module.I_CmsModuleAction#initialize(org.opencms.file.CmsObject,
     *      org.opencms.configuration.CmsConfigurationManager,
     *      org.opencms.module.CmsModule)
     */
    public void initialize(CmsObject obj, CmsConfigurationManager manager,
            CmsModule module) {
        // ...
        OpenCms.getEventManager().addCmsEventListener(this);
        // ...
    }

    // ...

    /**
     * @see 
org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent)
     */
    public void cmsEvent(CmsEvent event) {
        switch (event.getType()) {
            case 
org.opencms.main.I_CmsEventListener.EVENT_RESOURCE_MODIFIED:
                log.info("Resource modified event: " + event.getData());
                break;
            default:
                break;
        }
    }

}


In the example the module action class itself implements the 
CmsEventListener interface. It would certainly be advisable to put the 
event code into a separate listener class.

I have attached a small section of my log file which shows resource 
change events that were logged by the above code when I used the 
synchronize function. Each log line shows the Map which is a property of 
the event class. You can see that there is an entry with the key 
"resource" and the CmsResource object as its value.

Some events appear to be duplicate for a single resource. I have no 
explanation for this yet.

Best regards,
Christoph


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: resourcechangeevents.log
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20070118/26902278/attachment.ksh>


More information about the opencms-dev mailing list