Example Actionclass

From OpenCms Wiki
Revision as of 10:24, 22 July 2009 by Marcjohnen (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
public class EventListener implements I_CmsModuleAction {
        private CmsObject cmsObject;
 
        public EventListener() {
        // intentionally left blank
        }
 
        public void initialize(CmsObject adminCms, CmsConfigurationManager configurationManager, CmsModule module) {
                int[] eventTypes = {I_CmsEventListener.EVENT_PUBLISH_PROJECT, I_CmsEventListener.EVENT_BEFORE_PUBLISH_PROJECT, I_CmsEventListener.EVENT_RESOURCE_MODIFIED};
                OpenCms.addCmsEventListener(this, eventTypes);
                this.cmsObject = adminCms;
        }
 
        /**
         * Implements the CmsEvent interface.
         * <p>
         *
         * @param event CmsEvent that has occurred
         */
        public void cmsEvent(CmsEvent event) {
 
                // den Report holen, um etwas ausgeben zu koennen
                I_CmsReport report = (I_CmsReport) event.getData().get("report");
 
                Map m_eventData = event.getData();
 
                switch (event.getType()) {
 
 
                        // ****************************************************
                        // a resource was changed
                        // ****************************************************
                        case I_CmsEventListener.EVENT_RESOURCE_MODIFIED:
 
                                if (o_eventRes.getRootPath().equals("/sites/mysite/index.html")) {
                                        if (LOG.isInfoEnabled()) {LOG.info("Starting touching RSS-Feed");}
                                        try {
                                                CmsRequestContext context = cmsObject.getRequestContext();
                                      // Projekt setzen (muss Offline sein)
                                      CmsProject o_offlineProject = cmsObject.readProject("Offline");
                                      context.setCurrentProject(o_offlineProject);
 
                                                String folder = "/system/modules/mytemplate/resources/feed.rss";
                                                cmsObject.lockResource(folder);
                                                cmsObject.setDateLastModified(folder,System.currentTimeMillis(),true);
                                                cmsObject.unlockResource(folder);
                                                } catch (Exception e4) {
                                                        LOG.warn("Error touching RSS-Feed" , e4);
                                                }
                                }
 
                                break;
 
 
                        // ****************************************************
                        // something was published
                        // ****************************************************
                        case I_CmsEventListener.EVENT_PUBLISH_PROJECT:
                        if (o_eventRes.getRootPath().equals("/sites/mysite/index.html")) {
                           cmsObject.publishResource("/system/modules/mytemplate/resources/feed.rss");
                        }
                                break;
 
                        default:
                                // no operation
                } // end switch
        }
 
        public void moduleUninstall(CmsModule module) {
                // intentionally left blank
        }
 
        public void moduleUpdate(CmsModule module) {
                // intentionally left blank
        }
 
        public void publishProject(CmsObject cms, CmsPublishList publishList, int backupTagId, I_CmsReport report) {
                // intentionally left blank
        }
 
        public void shutDown(CmsModule module) {
                // intentionally left blank
        }
 
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox