KickJava   Java API By Example, From Geeks To Geeks.

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


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
// PortletWidgetsDBSerializer
14
//--------------------------
15
// J�r�me B�dat 18.12.2000
16
//--------------------------
17

18 package org.jahia.layout;
19
20 import java.sql.Connection JavaDoc;
21 import java.sql.ResultSet JavaDoc;
22 import java.sql.SQLException JavaDoc;
23 import java.sql.Statement JavaDoc;
24
25 import org.jahia.exceptions.JahiaException;
26 import org.jahia.utils.JahiaConsole;
27
28 /**
29  * This class takes care of serializing the various layout widgets to the Jahia
30  * database system.
31  * @author Jerome Bedat
32  */

33
34 public class PortletWidgetsDBSerializer {
35
36     private static PortletWidgetsDBSerializer theObject = null;
37     private DesktopBean theDesktop;
38     private PortletBean thePortlet;
39     private SkinBean theSkin;
40     private int thePortletsCount;
41     private int theDesktopsCount;
42
43
44
45     /**
46      * PortletWidgetsDBSerializer
47      *
48      * @author J�r�me B�dat
49      *
50      */

51     private PortletWidgetsDBSerializer()
52     {
53         JahiaConsole.println( "PortletWidgetsDBSerializer", "***** Starting the Portlets DataBase Manager *****" );
54     } // end constructor
55

56
57     /**
58      * getInstance
59      *
60      * @author J�r�me B�dat
61      *
62      */

63     public static synchronized PortletWidgetsDBSerializer getInstance()
64     {
65         if (theObject == null) {
66             theObject = new PortletWidgetsDBSerializer();
67         }
68         return theObject;
69     } // end getInstance
70

71
72     /**
73      * load_portlet_skin
74      *
75      * @author J�r�me B�dat
76      *
77      */

78     public SkinBean load_portlet_skin(int theID)
79     throws JahiaException
80     {
81         Connection JavaDoc dbConn = null;
82         Statement JavaDoc stmt = null;
83         ResultSet JavaDoc rs = null;
84
85         try {
86             String JavaDoc sqlQuery = "SELECT * FROM jahiatemplates_portet_skin WHERE (skin_id=" + theID + ")";
87
88             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
89             stmt = dbConn.createStatement();
90               rs = stmt.executeQuery( sqlQuery );
91             theSkin = null;
92             while (rs.next()) {
93                 theSkin = new SkinBean(rs.getInt("skin_id"),
94                                       rs.getString("skin_name"),
95                                       rs.getString("skin_url"));
96             }
97         } catch (SQLException JavaDoc se) {
98             theSkin = null;
99             String JavaDoc errorMsg = "Error in load_portlet_skin : " + se.getMessage();
100             JahiaConsole.println( "JahiaDBManager", errorMsg + " -> BAILING OUT" );
101             throw new JahiaException( "Cannot load portlet skin data from the database",
102                                         errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY );
103         } finally {
104             try {
105
106                 if ( stmt != null ) stmt.close();
107                 //if ( rs != null ) rs.close();
108
} catch ( SQLException JavaDoc ex ) {
109                 JahiaException je = new JahiaException( "Cannot free resources",
110                                         "load_portlet_skin : cannot free resources",
111                                         JahiaException.DATABASE_ERROR, JahiaException.WARNING_SEVERITY );
112             }
113         }
114         return theSkin;
115
116     } // end load_portlet_skin
117

118
119     /**
120      * load_desktop_skin
121      *
122      * @author J�r�me B�dat
123      *
124      */

125     public SkinBean load_desktop_skin(int theID)
126     throws JahiaException
127     {
128         Connection JavaDoc dbConn = null;
129         Statement JavaDoc stmt = null;
130         ResultSet JavaDoc rs = null;
131
132         try {
133             String JavaDoc sqlQuery = "SELECT * FROM jahiatemplates_desktop_skin WHERE (skin_id=" + theID + ")";
134
135             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
136             stmt = dbConn.createStatement();
137               rs = stmt.executeQuery( sqlQuery );
138             theSkin = null;
139             while (rs.next()) {
140                 theSkin = new SkinBean(rs.getInt("skin_id"),
141                                       rs.getString("skin_name"),
142                                       rs.getString("skin_url"));
143             }
144         } catch (SQLException JavaDoc se) {
145             theSkin = null;
146             String JavaDoc errorMsg = "Error in load_desktop_skin : " + se.getMessage();
147             JahiaConsole.println( "JahiaDBManager", errorMsg + " -> BAILING OUT" );
148             throw new JahiaException( "Cannot load desktop skin data from the database",
149                                         errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY );
150         } finally {
151             try {
152
153                 if ( stmt != null ) stmt.close();
154                 //if ( rs != null ) rs.close();
155
} catch ( SQLException JavaDoc ex ) {
156                 JahiaException je = new JahiaException( "Cannot free resources",
157                                         "load_desktop_skin : cannot free resources",
158                                         JahiaException.DATABASE_ERROR, JahiaException.WARNING_SEVERITY );
159             }
160         }
161         return theSkin;
162
163     } // end load_desktop_skin
164

165 }
166
Popular Tags