1 18 package org.jahia.layout; 19 20 import java.sql.Connection ; 21 import java.sql.ResultSet ; 22 import java.sql.SQLException ; 23 import java.sql.Statement ; 24 25 import org.jahia.exceptions.JahiaException; 26 import org.jahia.utils.JahiaConsole; 27 28 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 51 private PortletWidgetsDBSerializer() 52 { 53 JahiaConsole.println( "PortletWidgetsDBSerializer", "***** Starting the Portlets DataBase Manager *****" ); 54 } 56 57 63 public static synchronized PortletWidgetsDBSerializer getInstance() 64 { 65 if (theObject == null) { 66 theObject = new PortletWidgetsDBSerializer(); 67 } 68 return theObject; 69 } 71 72 78 public SkinBean load_portlet_skin(int theID) 79 throws JahiaException 80 { 81 Connection dbConn = null; 82 Statement stmt = null; 83 ResultSet rs = null; 84 85 try { 86 String 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 se) { 98 theSkin = null; 99 String 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 } catch ( SQLException 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 } 118 119 125 public SkinBean load_desktop_skin(int theID) 126 throws JahiaException 127 { 128 Connection dbConn = null; 129 Statement stmt = null; 130 ResultSet rs = null; 131 132 try { 133 String 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 se) { 145 theSkin = null; 146 String 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 } catch ( SQLException 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 } 165 } 166 | Popular Tags |