001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/auth/MVNCmsPermissionWebHelper.java,v 1.3 2007/10/09 11:09:12 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.3 $
005: * $Date: 2007/10/09 11:09:12 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Phuong, Pham Dinh Duy
039: */
040: package com.mvnforum.auth;
041:
042: import java.sql.*;
043: import java.util.ArrayList;
044:
045: import net.myvietnam.mvncore.db.DBUtils;
046: import net.myvietnam.mvncore.exception.DatabaseException;
047:
048: import org.apache.commons.logging.Log;
049: import org.apache.commons.logging.LogFactory;
050:
051: import com.mvnforum.MVNForumConstant;
052: import com.mvnforum.db.MemberGroupDAO;
053:
054: public class MVNCmsPermissionWebHelper {
055:
056: private static Log log = LogFactory
057: .getLog(MVNCmsPermissionWebHelper.class);
058:
059: private static final String MemberGroup = MemberGroupDAO.TABLE_NAME;
060:
061: //TODO: change here later
062: private static final String GROUP_CHANNEL_STEP = "mvncmsGroupChannelStepPerm";
063:
064: static ArrayList getGroupPermissionsInStepWithChannel(int memberID)
065: throws DatabaseException {
066:
067: Connection connection = null;
068: PreparedStatement statement = null;
069: ResultSet resultSet = null;
070: ArrayList retValue = new ArrayList();
071:
072: StringBuffer sql = new StringBuffer(512);
073: sql.append("SELECT DISTINCT StepID, ChannelID, Permission");// belong to table GroupForum
074: sql.append(" FROM ").append(GROUP_CHANNEL_STEP).append(
075: " groupchannelstep, ").append(MemberGroup).append(
076: " memgroup");
077: sql
078: .append(" WHERE ( (groupchannelstep.GroupID = memgroup.GroupID) AND (memgroup.MemberID = ?) )");
079: if ((memberID != 0)
080: && (memberID != MVNForumConstant.MEMBER_ID_OF_GUEST)) {
081: sql.append(" OR groupchannelstep.GroupID = ").append(
082: MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS);
083: }
084:
085: try {
086: connection = DBUtils.getConnection();
087: statement = connection.prepareStatement(sql.toString());
088: statement.setInt(1, memberID);
089: resultSet = statement.executeQuery();
090: while (resultSet.next()) {
091: CmsPermission cmsPermission = new CmsPermission();
092: cmsPermission.setStepID(resultSet.getInt("StepID"));
093: cmsPermission.setChannelID(resultSet
094: .getInt("ChannelID"));
095: cmsPermission.setPermission(resultSet
096: .getInt("Permission"));
097: retValue.add(cmsPermission);
098: }
099: return retValue;
100: } catch (SQLException sqle) {
101: log.error("Sql Execution Error!", sqle);
102: throw new DatabaseException(
103: "Error executing SQL in MVNCmsPermissionWebHelper.getGroupPermissionsInStepWithChannel.");
104: } finally {
105: DBUtils.closeResultSet(resultSet);
106: DBUtils.closeStatement(statement);
107: DBUtils.closeConnection(connection);
108: }
109: }
110:
111: }
|