⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupxml.java

📁 java servlet著名论坛源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/GroupXML.java,v 1.4 2004/06/01 13:00:03 skoehler Exp $
 * $Author: skoehler $
 * $Revision: 1.4 $
 * $Date: 2004/06/01 13:00:03 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2004 by MyVietnam.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum MUST remain intact
 * in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the
 * footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Igor Manic   imanic@users.sourceforge.net
 */
package com.mvnforum.admin;

import java.io.IOException;
import java.util.*;

import com.mvnforum.MVNForumConstant;
import com.mvnforum.admin.importexport.XMLUtil;
import com.mvnforum.admin.importexport.XMLWriter;
import com.mvnforum.auth.MVNForumPermission;
import com.mvnforum.db.*;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import net.myvietnam.mvncore.filter.EnableHtmlTagFilter;

/**
 * @author <a href="mailto:imanic@users.sourceforge.net">Igor Manic</a>
 * @version $Revision: 1.4 $, $Date: 2004/06/01 13:00:03 $
 * <br/>
 * <code>GroupXML</code> todo Igor: enter description
 *
 */
public class GroupXML {

    private int groupID;
    /** Returns <code>GroupID</code> of this group or
      * <code>-1</code> if group is not created yet. */
    public int getGroupID() { return groupID; }

    public GroupXML() {
        super();
        groupID=-1;
    }

    public void setGroupID(String id) {
        groupID=XMLUtil.stringToIntDef(id, -1);
    }

    /**
     * Creates a group. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
     * are represented as <code>String</code>s, because of more convenient using
     * of this method for XML parsing.
     *
     * @param groupOwnerName Can be null.
     * @param groupName Name of a group to be created.
     * @param groupDesc Can be null.
     * @param groupOption Can be null.
     * @param groupCreationDate Can be null.
     * @param groupModifiedDate Can be null.
     *
     * @throws CreateException
     * @throws DuplicateKeyException
     * @throws ObjectNotFoundException
     * @throws DatabaseException
     * @throws ForeignKeyNotFoundException
     *
     */
    public void addGroup(String groupOwnerName, String groupName,
                         String groupDesc, String groupOption,
                         String groupCreationDate, String groupModifiedDate)
    throws CreateException, DuplicateKeyException, ObjectNotFoundException,
    DatabaseException, ForeignKeyNotFoundException {
        String strGroupID=null;
        if (groupID>=0) strGroupID=Integer.toString(groupID);
        addGroup(strGroupID, groupOwnerName, groupName,
                 groupDesc, groupOption, groupCreationDate, groupModifiedDate);
    }

    /**
     * Creates a group. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
     * are represented as <code>String</code>s, because of more convenient using
     * of this method for XML parsing.
     *
     * @param strGroupID Can be null, and it probably will be in most occasions,
     *                   except when you want to setup an explicit value, like
     *                   for virtual "Registered Members" groups.
     * @param groupOwnerName Can be null.
     * @param groupName Name of a group to be created.
     * @param groupDesc Can be null.
     * @param groupOption Can be null.
     * @param groupCreationDate Can be null.
     * @param groupModifiedDate Can be null.
     *
     * @throws CreateException
     * @throws DuplicateKeyException
     * @throws ObjectNotFoundException
     * @throws DatabaseException
     * @throws ForeignKeyNotFoundException
     *
     */
    public void addGroup(String strGroupID,
                         String groupOwnerName, String groupName,
                         String groupDesc, String groupOption,
                         String groupCreationDate, String groupModifiedDate)
    throws CreateException, DuplicateKeyException, ObjectNotFoundException,
    DatabaseException, ForeignKeyNotFoundException {
        if ( (groupName==null) || (groupName.equals("")) ) {
            throw new CreateException("Can't create a group with empty GroupName.");
        } else {
            int groupOption1;
            java.sql.Timestamp groupCreationDate1;
            java.sql.Timestamp groupModifiedDate1;
            try {
                if (groupOwnerName==null) groupOwnerName="";
                if (groupDesc==null) groupDesc="";
                groupOption1= XMLUtil.stringToIntDef(groupOption, 0);
                groupCreationDate1= XMLUtil.stringToSqlTimestampDefNow(groupCreationDate);
                groupModifiedDate1=XMLUtil.stringToSqlTimestampDefNow(groupModifiedDate);
            } catch (NumberFormatException e) {
                throw new CreateException("Invalid data for a group. Expected a number.");
            }

            //now ensure that strGroupID is valid number, or null
            if ( (strGroupID!=null) && (!strGroupID.equals("")) ) {
                try {
                    if (Integer.parseInt(strGroupID)<0) strGroupID=null;
                } catch (NumberFormatException e) {
                    strGroupID=null;
                }
            } else strGroupID=null;

            groupName=EnableHtmlTagFilter.filter(groupName);
            groupDesc=EnableHtmlTagFilter.filter(groupDesc);
            if (strGroupID==null) {
                //GroupsWebHelper correctly replaces empty groupOwnerName with GroupOwnerID=0
                DAOFactory.getGroupsDAO().create(
                      groupOwnerName, groupName, groupDesc,
                      groupOption1, groupCreationDate1, groupModifiedDate1);
            } else {
                int groupOwnerID=0;
                try {
                    if (!groupOwnerName.equals("")) {
                        groupOwnerID=DAOFactory.getMemberDAO().getMemberIDFromMemberName(groupOwnerName);
                    }
                } catch (ObjectNotFoundException e) {
                    groupOwnerID=0;
                }
                if (ImportWebHelper.execUpdateQuery(
                    "INSERT INTO "+ GroupsDAO.TABLE_NAME +
                    " (GroupID, GroupOwnerID, GroupOwnerName, GroupName, GroupDesc," +
                    " GroupOption, GroupCreationDate, GroupModifiedDate)" +
                    " VALUES (" +strGroupID+ ", " +groupOwnerID+ ", '"+groupOwnerName +
                    "', '" +groupName+ "', '" +groupDesc+ "', " +groupOption1+
                    ", '" +groupCreationDate1+ "', '" +groupModifiedDate1+ "')"
                   ) != 1) {
                    throw new CreateException("Error adding group \""+groupName+"\" into table '"+
                              GroupsDAO.TABLE_NAME +"'.");
                }
            }

            this.groupID=DAOFactory.getGroupsDAO().getGroupIDFromGroupName(groupName);
        }
    }

    /**
     * Adds a permission to this group. In order to know which group we are
     * reffering to, this method is supposed to be called after {@link #setGroupID(String)},
     * {@link #addGroup(String, String, String, String, String, String, String)}
     * or {@link #addGroup(String, String, String, String, String, String)}
     * have been called. Otherwise, this permission will be simply ignored.
     *
     * @param permission Permission to be added to this group.
     *
     * @throws CreateException
     * @throws DatabaseException
     * @throws ForeignKeyNotFoundException
     *
     */
    public void addGroupPermission(String permission)
    throws CreateException, DatabaseException, ForeignKeyNotFoundException {
        if (groupID<0) {
            throw new CreateException("Found group permission that is not assigned to any known group.");
        }
        int permission1;
        try {
            permission1=XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
        } catch (NumberFormatException e) {
            throw new CreateException("Invalid data for a group permission. Expected a number.");
        }
        try {
            DAOFactory.getGroupPermissionDAO().create(groupID, permission1);
        } catch (DuplicateKeyException e) {
            //ignore if already had that permission
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -