📄 jahiapageutilsdb.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//package org.jahia.services.pages;import java.sql.*; // ResultSetimport java.util.*; // Vectorimport org.jahia.data.*; // JahiaDataimport org.jahia.params.*; // ParamBeanimport org.jahia.services.pages.JahiaPage;import org.jahia.data.fields.*; // JahiaFieldimport org.jahia.utils.*; // JahiaConsoleimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.exceptions.JahiaException;import org.jahia.exceptions.database.JahiaDatabaseException;import org.jahia.data.JahiaDOMObject;import org.jahia.data.JahiaDBDOMObject;class JahiaPageUtilsDB{ private static JahiaPageUtilsDB mObject = null; //------------------------------------------------------------------------- /** * */ private JahiaPageUtilsDB () { } //------------------------------------------------------------------------- public static JahiaPageUtilsDB getInstance () { if (mObject == null) { mObject = new JahiaPageUtilsDB (); } return mObject; } //------------------------------------------------------------------------- /** * gets all the page ids in a site * * @param jahiaID the jahia site id * @return a Vector of pages ids * */ public Vector getPageIDsInSite (int jahiaID) throws JahiaException { Connection dbConn = null; Statement stmt = null; ResultSet rs = null; Vector theList = new Vector(); try { String sqlQuery = "SELECT id_jahia_pages_data FROM jahia_pages_data "; sqlQuery += "WHERE jahiaid_jahia_pages_data=" + jahiaID ; dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(74); stmt = dbConn.createStatement(); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt,sqlQuery ); while (rs.next()) { theList.add( new Integer( rs.getInt("id_jahia_pages_data") ) ); } } catch (SQLException se) { String errorMsg = "Error in db_get_page_ids_in_site : " + se.getMessage(); JahiaConsole.println( "JahiaPageUtilsDB", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot load page data from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { try { ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn); if ( stmt != null ) stmt.close(); } catch ( SQLException ex ) { JahiaException je = new JahiaException( "Cannot free resources", "db_get_page_ids_in_site : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } return theList; } //------------------------------------------------------------------------- /** * Get the jahia page id in a site corresponding to a specified link type. * * @param jahiaID the jahia site id * @param pageType One of these TYPE_DIRECT, TYPE_LINK, TYPE_URL links. * @return a Vector of pages ids * */ public Vector getPageIDsInSite (int jahiaID, int linkType) throws JahiaException { Connection dbConn = null; Statement stmt = null; ResultSet rs = null; Vector theList = new Vector(); try { StringBuffer sqlQuery = new StringBuffer("SELECT id_jahia_pages_data FROM jahia_pages_data "); sqlQuery.append("WHERE jahiaid_jahia_pages_data="); sqlQuery.append(jahiaID); sqlQuery.append(" AND pagetype_jahia_pages_data="); sqlQuery.append(linkType); dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(74); stmt = dbConn.createStatement(); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt,sqlQuery.toString()); while (rs.next()) { theList.add( new Integer( rs.getInt("id_jahia_pages_data") ) ); } } catch (SQLException se) { String errorMsg = "Error in db_get_page_ids_in_site : " + se.getMessage(); JahiaConsole.println( "JahiaPageUtilsDB", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot load page data from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { try { ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn); if ( stmt != null ) stmt.close(); } catch ( SQLException ex ) { JahiaException je = new JahiaException( "Cannot free resources", "db_get_page_ids_in_site : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } return theList; } /** * Returns a list of all the pageIDs that are using a specific template ID. * @param templateID the identifier of the template * @returns a Vector containing Integer object that correspond to pageIDs. * @throws JahiaException if an SQL exception is raised or if there is a * problem freeing the ressources... * @author Serge Huber */ public Vector getPageIDsWithTemplate ( int templateID ) throws JahiaException { Connection dbConn = null; Statement stmt = null; ResultSet rs = null; Vector theList = new Vector(); try { String sqlQuery = "SELECT id_jahia_pages_data FROM jahia_pages_data "; sqlQuery += "WHERE pagedefid_jahia_pages_data=" + templateID ; dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(75); stmt = dbConn.createStatement(); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt,sqlQuery ); while (rs.next()) { theList.add( new Integer( rs.getInt("id_jahia_pages_data") ) ); } } catch (SQLException se) { String errorMsg = "Error : " + se.getMessage(); JahiaConsole.println( "JahiaPageUtilsDB.getPageIDsWithTemplate", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot load page data from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL, se ); } finally { try { ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn); if ( stmt != null ) stmt.close(); } catch ( SQLException ex ) { JahiaException je = new JahiaException( "JahiaPageUtilsDB.getPageIDsWithTemplate", "Cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING, ex ); } } return theList; } //------------------------------------------------------------------------- /** * gets all the fields linking on a specific page * * @param pageID the page id * @return a Vector of page ids * */ public Vector getPageIDsPointingOnPage (int pageID) throws JahiaException { Connection dbConn = null; Statement stmt = null; ResultSet rs = null; Vector pageList = new Vector(); try { // creates the connection String sqlQuery = ""; dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection(76); stmt = dbConn.createStatement(); // gets the pages ids sqlQuery = "SELECT id_jahia_pages_data FROM jahia_pages_data "; sqlQuery += "WHERE ((pagetype_jahia_pages_data=1) AND "; sqlQuery += "(pagelinkid_jahia_pages_data=" + pageID + "))"; rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( stmt,sqlQuery ); while (rs.next()) { pageList.add( new Integer( rs.getInt("id_jahia_pages_data") ) ); } } catch (SQLException se) { String errorMsg = "Error in db_get_page_ids_pointing_on_page : " + se.getMessage(); JahiaConsole.println( "JahiaPageUtilsDB", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot load page data from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { try { ServicesRegistry.getInstance().getDBPoolService().freeConnection(dbConn); if ( stmt != null ) stmt.close(); } catch ( SQLException ex ) { JahiaException je = new JahiaException( "Cannot free resources", "db_get_page_ids_pointing_on_page : cannot free resources", JahiaException.DATABASE_ERROR, JahiaException.WARNING ); } } return pageList; } //------------------------------------------------------------------------- /** * gets the page's field parent * * @param pageID the page id * @return a field object * */ public JahiaField getPageField (int pageID) throws JahiaException { // get the DB connection Connection dbConn = getDBConnection (76); if (dbConn == null) { return null; } Statement statement = null; JahiaField theField = null; try { // creates the connection dbConn = ServicesRegistry.getInstance().getDBPoolService().getConnection (76); statement = dbConn.createStatement(); // gets the pages ids String sqlQuery = "SELECT id_jahia_fields_data FROM jahia_fields_data "+ "WHERE value_jahia_fields_data='" + pageID + "'"; ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery ); if (rs != null) { if (rs.next()) { int fieldID = rs.getInt ("id_jahia_fields_data"); theField = ServicesRegistry.getInstance().getJahiaFieldService().loadField( fieldID ); } } } catch (SQLException se) { String errorMsg = "Error in db_get_page_field : " + se.getMessage(); JahiaConsole.println( "JahiaPageUtilsDB", errorMsg + " -> BAILING OUT" ); throw new JahiaException( "Cannot load page data from the database", errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL ); } finally { closeDBConnection (dbConn); closeStatement (statement); } return theField; } //------------------------------------------------------------------------- /** * */ public Vector getPageChildIDs (int pageID) throws JahiaException { Vector result = new Vector (); // get the DB connection Connection dbConn = getDBConnection (76); if (dbConn == null) { return result; } Statement statement = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -