KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > layout > PortletsEventListener


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//--------------------------
13
// PortletsEventListener
14
//--------------------------
15
// J�r�me B�dat 18.01.2001
16
//--------------------------
17

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     /***
35         * triggered when Jahia adds a container
36         *
37         * @param je the associated JahiaEvent
38         *
39         */

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 JavaDoc 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 JavaDoc theTemplatesDiskPath = je.getParams().settings().getJahiaFilesTemplatesDiskPath();
57             JahiaUser theUser = (JahiaUser) je.getParams().getUser();
58             String JavaDoc theUserName = theUser.getUsername();
59
60             try {
61                 /** @todo the problem here is that this assumes we are using a type of grid, which we might not be
62                  * doing. It is still unclear how listener fit in with the parameter we must pass to them. Loading
63                  * and storing portlet sets is also a heavy operation which needs to be optimized...
64                  */

65                 PortletSetPersistanceManager PSPM = PortletSetPersistanceManager.getInstance(false);
66                 JahiaContainerDefinition containerDef = theObject.getDefinition();
67                 String JavaDoc 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     /***
79         * triggered when Jahia delete a container
80         *
81         * @param je the associated JahiaEvent
82         *
83         */

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 JavaDoc 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 JavaDoc theTemplatesDiskPath = je.getParams().settings().getJahiaFilesTemplatesDiskPath();
101             JahiaUser theUser = (JahiaUser) je.getParams().getUser();
102             String JavaDoc 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     /***
115         * triggered when Jahia adds a page
116         *
117         * @param je the associated JahiaEvent
118         *
119         */

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 JavaDoc theTemplatesDiskPath = je.getParams().settings().getJahiaFilesTemplatesDiskPath();
130             JahiaUser theUser = (JahiaUser) je.getParams().getUser();
131             String JavaDoc 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 } // end PortletsEventListener
143
Popular Tags