1 18 package jahiatemplates.org.jahia.portlets_api; 19 20 import org.jahia.data.containers.JahiaContainer; 21 import org.jahia.data.events.JahiaEvent; 22 import org.jahia.data.events.JahiaEventListener; 23 import org.jahia.exceptions.JahiaException; 24 import org.jahia.services.pages.JahiaPage; 25 import org.jahia.services.usermanager.JahiaUser; 26 import org.jahia.utils.JahiaConsole; 27 28 29 public class PortletsEventListener extends JahiaEventListener 30 { 31 32 33 39 public void containerAdded( JahiaEvent je ) { 40 PortletsBean PB = PortletsBean.getInstance(); 41 JahiaContainer theObject = (JahiaContainer) je.getObject(); 42 int theObjectID = theObject.getID(); 43 String theContainerName = ""; 44 try { 45 theContainerName = theObject.getDefinition().getName(); 46 } catch (JahiaException e) { 47 JahiaConsole.println( "PortletsEventListener -> containerAdded", e.toString() ); 48 } 49 if (theContainerName.equals("PortletList")) { 50 int thePageID = je.getParams().getPage().getID(); 51 String theTemplatesDiskPath = je.getParams().getJahiaFilesTemplatesDiskPath(); 53 JahiaUser theUser = (JahiaUser) je.getParams().getUser(); 54 String theUserName = theUser.getUsername(); 55 56 PB.addPortlet( theObjectID, thePageID, theUserName, theTemplatesDiskPath ); 57 } 58 } 59 60 61 67 public void containerDeleted( JahiaEvent je ) { 68 PortletsBean PB = PortletsBean.getInstance(); 69 JahiaContainer theObject = (JahiaContainer) je.getObject(); 70 int theObjectID = theObject.getID(); 71 String theContainerName = ""; 72 try { 73 theContainerName = theObject.getDefinition().getName(); 74 } catch (JahiaException e) { 75 JahiaConsole.println( "PortletsEventListener -> containerDeleted", e.toString() ); 76 } 77 if (theContainerName.equals("PortletList")) { 78 int thePageID = je.getParams().getPage().getID(); 79 String theTemplatesDiskPath = je.getParams().getJahiaFilesTemplatesDiskPath(); 81 JahiaUser theUser = (JahiaUser) je.getParams().getUser(); 82 String theUserName = theUser.getUsername(); 83 84 PB.delPortlet( theObjectID, thePageID, theUserName, theTemplatesDiskPath ); 85 } 86 } 87 88 89 95 public void pageAdded( JahiaEvent je ) { 96 97 if ( je != null && je.getParams()!= null ){ 98 99 PortletsBean PB = PortletsBean.getInstance(); 100 JahiaPage theObject = (JahiaPage) je.getObject(); 101 int theObjectID = theObject.getID(); 102 103 String theTemplatesDiskPath = je.getParams().getJahiaFilesTemplatesDiskPath(); 104 JahiaUser theUser = (JahiaUser) je.getParams().getUser(); 105 String theUserName = theUser.getUsername(); 106 PB.addPortletGroup( theObjectID, theUserName, theTemplatesDiskPath ); 107 } 108 } 109 110 111 112 113 } | Popular Tags |