1 18 package org.jahia.layout; 19 20 import org.jahia.data.containers.JahiaContainer; 21 import org.jahia.data.containers.JahiaContainerDefinition; 22 import org.jahia.data.events.JahiaEvent; 23 import org.jahia.data.events.JahiaEventListener; 24 import org.jahia.exceptions.JahiaException; 25 import org.jahia.services.pages.JahiaPage; 26 import org.jahia.services.usermanager.JahiaUser; 27 import org.jahia.utils.JahiaConsole; 28 29 30 public class PortletsEventListener extends JahiaEventListener 31 { 32 33 34 40 public void containerAdded( JahiaEvent je ) { 41 JahiaConsole.println("LayoutEventListener", "containerAdded called"); 42 PortletsPersistanceManager PM = PortletsPersistanceManager.getInstance(false); 43 JahiaContainer theObject = (JahiaContainer) je.getObject(); 44 int theObjectID = theObject.getID(); 45 String theContainerName = ""; 46 try { 47 theContainerName = theObject.getDefinition().getName(); 48 JahiaConsole.println("LayoutEventListener", "container name=[" + theContainerName + "]"); 49 } catch (JahiaException e) { 50 JahiaConsole.printe( "LayoutEventListener.containerAdded", e); 51 } 52 if (theContainerName.startsWith("PortletContentList")) { 53 JahiaConsole.println("LayoutEventListener.containerAdded", 54 "Adding portlet metadata entry..."); 55 int thePageID = je.getParams().getPage().getID(); 56 String theTemplatesDiskPath = je.getParams().settings().getJahiaFilesTemplatesDiskPath(); 57 JahiaUser theUser = (JahiaUser) je.getParams().getUser(); 58 String theUserName = theUser.getUsername(); 59 60 try { 61 65 PortletSetPersistanceManager PSPM = PortletSetPersistanceManager.getInstance(false); 66 JahiaContainerDefinition containerDef = theObject.getDefinition(); 67 String portletGroupName = containerDef.getName(); 68 PortletBeanSpanningGrid portletSpanningGrid = new PortletBeanSpanningGrid( PSPM.getPortletSet(je.getParams(), je.getJahiaData(), portletGroupName) ); 69 portletSpanningGrid.add(new PortletBean(theObject.getID())); 70 PSPM.setPortletSet(portletSpanningGrid, portletGroupName, je.getParams(), je.getJahiaData()); 71 } catch (JahiaException e) { 72 JahiaConsole.printe("LayoutEventListener.containerAdded", e); 73 } 74 } 75 } 76 77 78 84 public void containerDeleted( JahiaEvent je ) { 85 JahiaConsole.println("LayoutEventListener", "containerDeleted called"); 86 PortletsPersistanceManager PM = PortletsPersistanceManager.getInstance(false); 87 JahiaContainer theObject = (JahiaContainer) je.getObject(); 88 int theObjectID = theObject.getID(); 89 String theContainerName = ""; 90 try { 91 theContainerName = theObject.getDefinition().getName(); 92 JahiaConsole.println("LayoutEventListener", "container name=[" + theContainerName + "]"); 93 } catch (JahiaException e) { 94 JahiaConsole.printe( "LayoutEventListener -> containerDeleted", e ); 95 } 96 if (theContainerName.startsWith("PortletContentList")) { 97 JahiaConsole.println("LayoutEventListener.containerAdded", 98 "Adding portlet metadata entry..."); 99 int thePageID = je.getParams().getPage().getID(); 100 String theTemplatesDiskPath = je.getParams().settings().getJahiaFilesTemplatesDiskPath(); 101 JahiaUser theUser = (JahiaUser) je.getParams().getUser(); 102 String theUserName = theUser.getUsername(); 103 104 try { 105 PM.delPortlet( je.getParams(), je.getJahiaData(), theObject, thePageID, theUserName, 106 theTemplatesDiskPath ); 107 } catch (JahiaException e) { 108 JahiaConsole.printe("LayoutEventListener.containerDeleted", e); 109 } 110 } 111 } 112 113 114 120 public void pageAdded( JahiaEvent je ) { 121 122 if ( je.getParams()!= null ){ 123 124 JahiaConsole.println("LayoutEventListener", "pageAdded called"); 125 PortletsPersistanceManager PM = PortletsPersistanceManager.getInstance(false); 126 JahiaPage theObject = (JahiaPage) je.getObject(); 127 int theObjectID = theObject.getID(); 128 129 String theTemplatesDiskPath = je.getParams().settings().getJahiaFilesTemplatesDiskPath(); 130 JahiaUser theUser = (JahiaUser) je.getParams().getUser(); 131 String theUserName = theUser.getUsername(); 132 133 try { 134 PM.addPortletGroup( je.getParams(), theObjectID, theUserName, theTemplatesDiskPath ); 135 } catch (JahiaException e) { 136 JahiaConsole.printe("LayoutEventListener.pageAdded", e); 137 } 138 } 139 } 140 141 142 } | Popular Tags |