KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jahiatemplates > org > jahia > portlets_api > 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
// Jerome Bedat 18.01.2001
16
//--------------------------
17

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

39     public void containerAdded( JahiaEvent je ) {
40         PortletsBean PB = PortletsBean.getInstance();
41         JahiaContainer theObject = (JahiaContainer) je.getObject();
42         int theObjectID = theObject.getID();
43         String JavaDoc 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().settings().getJahiaFilesTemplatesDiskPath();
52
String JavaDoc theTemplatesDiskPath = je.getParams().getJahiaFilesTemplatesDiskPath();
53             JahiaUser theUser = (JahiaUser) je.getParams().getUser();
54             String JavaDoc theUserName = theUser.getUsername();
55     
56             PB.addPortlet( theObjectID, thePageID, theUserName, theTemplatesDiskPath );
57         }
58     }
59
60
61     /***
62         * triggered when Jahia delete a container
63         *
64         * @param je the associated JahiaEvent
65         *
66         */

67     public void containerDeleted( JahiaEvent je ) {
68         PortletsBean PB = PortletsBean.getInstance();
69         JahiaContainer theObject = (JahiaContainer) je.getObject();
70         int theObjectID = theObject.getID();
71         String JavaDoc 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().settings().getJahiaFilesTemplatesDiskPath();
80
String JavaDoc theTemplatesDiskPath = je.getParams().getJahiaFilesTemplatesDiskPath();
81             JahiaUser theUser = (JahiaUser) je.getParams().getUser();
82             String JavaDoc theUserName = theUser.getUsername();
83
84             PB.delPortlet( theObjectID, thePageID, theUserName, theTemplatesDiskPath );
85         }
86     }
87
88
89     /***
90         * triggered when Jahia adds a page
91         *
92         * @param je the associated JahiaEvent
93         *
94         */

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 JavaDoc theTemplatesDiskPath = je.getParams().getJahiaFilesTemplatesDiskPath();
104             JahiaUser theUser = (JahiaUser) je.getParams().getUser();
105             String JavaDoc theUserName = theUser.getUsername();
106             PB.addPortletGroup( theObjectID, theUserName, theTemplatesDiskPath );
107         }
108     }
109
110
111
112
113 } // end PortletsEventListener
114
Popular Tags