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

📄 forumxml.java

📁 java servlet著名论坛源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    throws CreateException, DatabaseException,
    ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
        if (forumID<0) {
            throw new CreateException("Found member's forum-specific permission that is not assigned to any known forum.");
        }
        if ( (memberName==null) || (memberName.equals("")) ) {
            throw new CreateException("Can't create a member's forum-specific permission for a member with empty MemberName.");
        }

        int permission1;
        try {
            permission1=XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
        } catch (NumberFormatException e) {
            throw new CreateException("Invalid data for a member forum-specific permission. Expected a number.");
        }
        int memberID=DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
        try {
            DAOFactory.getMemberForumDAO().create(memberID, forumID, permission1);
        } catch (DuplicateKeyException e) {
            //ignore if already had that permission
        }
    }

    /**
     * Adds a forum-specific permission to a group. In order to know which forum we are
     * reffering to, this method is supposed to be called after {@link #setForumID(String)} or
     * {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
     * have been called. Otherwise, this permission will be simply ignored.
     *
     * @param groupName Group we are assigning permissions to.
     * @param permission Permission to be added.
     *
     * @throws CreateException
     * @throws DatabaseException
     * @throws ObjectNotFoundException
     * @throws DuplicateKeyException
     * @throws ForeignKeyNotFoundException
     *
     */
    public void addGroupForumPermission(String groupName, String permission)
        throws CreateException, DatabaseException,
        ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
        if (forumID < 0) {
            throw new CreateException("Found group's forum-specific permission that is not assigned to any known forum.");
        }
        if ( (groupName == null) || (groupName.equals(""))) {
            throw new CreateException("Can't create a group's forum-specific permission for a group with empty GroupName.");
        }

        int permission1;
        try {
            permission1 = XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
        } catch (NumberFormatException e) {
            throw new CreateException("Invalid data for a group forum-specific permission. Expected a number.");
        }
        int groupID = DAOFactory.getGroupsDAO().getGroupIDFromGroupName(groupName);
        try {
            DAOFactory.getGroupForumDAO().create(groupID, forumID, permission1);
        } catch (DuplicateKeyException e) {
            //ignore if already had that permission
        }
    }

    public void addGuestMemberForumPermission(String permission)
    throws CreateException, DatabaseException,
    ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
        if (forumID<0) {
            throw new CreateException("Found guest's forum-specific permission that is not assigned to any known forum.");
        }
        int permission1;
        try {
            permission1=XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
        } catch (NumberFormatException e) {
            throw new CreateException("Invalid data for a guest member forum-specific permission. Expected a number.");
        }
        try {
            DAOFactory.getMemberForumDAO().create(MVNForumConstant.MEMBER_ID_OF_GUEST,
                                                   forumID, permission1);
        } catch (DuplicateKeyException e) {
            //ignore if already had that permission
        }
    }

    public void addRegisteredMembersGroupForumPermission(String permission)
    throws CreateException, DatabaseException,
    ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
        if (forumID<0) {
            throw new CreateException("Found group's forum-specific permission that is not assigned to any known forum.");
        }
        int permission1;
        try {
            permission1=XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
        } catch (NumberFormatException e) {
            throw new CreateException("Invalid data for a group forum-specific permission. Expected a number.");
        }
        try {
            DAOFactory.getGroupForumDAO().create(MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS,
                                              forumID, permission1);
        } catch (DuplicateKeyException e) {
            //ignore if already had that permission
        }
    }

    /**
     * Creates a forum watch for this forum. In order to know which forum we are
     * reffering to, this method is supposed to be called after {@link #setForumID(String)}
     * or {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
     * have been called. Otherwise, this watch will be simply ignored.
     *
     * @param memberName
     * @param watchType Can be null.
     * @param watchOption Can be null.
     * @param watchStatus Can be null.
     * @param watchCreationDate Can be null.
     * @param watchLastSentDate Can be null.
     * @param watchEndDate Can be null.
     *
     * @throws BadInputException
     * @throws CreateException
     * @throws DatabaseException
     * @throws ObjectNotFoundException
     * @throws DuplicateKeyException
     * @throws ForeignKeyNotFoundException
     *
     */
    public void addForumWatch(String memberName,
                String watchType, String watchOption,
                String watchStatus, String watchCreationDate,
                String watchLastSentDate, String watchEndDate)
    throws BadInputException, CreateException, DatabaseException,
    ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
        if (forumID<0) {
            throw new CreateException("Found forum watch that is not assigned to any known forum.");
        }

        int watchType1;
        int watchOption1;
        int watchStatus1;
        java.sql.Timestamp watchCreationDate1;
        java.sql.Timestamp watchLastSentDate1;
        java.sql.Timestamp watchEndDate1;

        try {
            if (memberName==null) memberName="";
            watchType1= XMLUtil.stringToIntDef(watchType, 0);
            watchOption1= XMLUtil.stringToIntDef(watchOption, 0);
            watchStatus1= XMLUtil.stringToIntDef(watchStatus, 0);
            watchCreationDate1= XMLUtil.stringToSqlTimestampDefNow(watchCreationDate);
            watchLastSentDate1= XMLUtil.stringToSqlTimestampDefNull(watchLastSentDate);
            watchEndDate1= XMLUtil.stringToSqlTimestampDefNull(watchEndDate);
        } catch (NumberFormatException e) {
            throw new CreateException("Invalid data for a forum. Expected a number.");
        }

        //todo Igor: Shoud I allow memberID==0 here?
        int memberID=0;
        if (!memberName.equals("")) {
            memberID=DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
        }
        DAOFactory.getWatchDAO().create(
              memberID, 0/*categoryID*/, forumID, 0/*threadID*/,
              watchType1, watchOption1, watchStatus1,
              watchCreationDate1, watchLastSentDate1, watchEndDate1);
    }


    public void updateLastPostMemberName(String value)
    throws ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException {
        if (forumID<0) {
            throw new ObjectNotFoundException("Can't update ForumLastPostMemberName on forum that is not created yet.");
        }
        DAOFactory.getForumDAO().updateLastPostMemberName(forumID, value);
    }

    public void updateLastPostDate(Timestamp value)
    throws ObjectNotFoundException, DatabaseException {
        if (forumID<0) {
            throw new ObjectNotFoundException("Can't update ForumLastPostDate on forum that is not created yet.");
        }
        DAOFactory.getForumDAO().updateLastPostDate(forumID, value);
    }

    public void increaseThreadCount()
    throws ObjectNotFoundException, DatabaseException {
        if (forumID<0) {
            throw new ObjectNotFoundException("Can't update ForumThreadCount on forum that is not created yet.");
        }
        DAOFactory.getForumDAO().increaseThreadCount(forumID);
    }

    public void increasePostCount()
    throws ObjectNotFoundException, DatabaseException {
        if (forumID<0) {
            throw new ObjectNotFoundException("Can't update ForumPostCount on forum that is not created yet.");
        }
        DAOFactory.getForumDAO().increasePostCount(forumID);
    }


// ===============================================================
// ==================== STATIC EXPORT METHODS ====================
// ===============================================================

    public static void exportForumWatchesForForum(XMLWriter xmlWriter, int forumID)
    throws IOException, ExportException, NumberFormatException, ObjectNotFoundException,
    DatabaseException {
        Collection forumWatches=ExportWebHelper.execSqlQuery(
                   "SELECT MemberID, WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate, WatchEndDate"+
                   " FROM "+WatchDAO.TABLE_NAME+
                   " WHERE ThreadID=0"+ //AND CategoryID=0
                   " AND ForumID="+Integer.toString(forumID));
        Iterator iter=forumWatches.iterator();
        String[] forumWatch=null;
        //try {
            xmlWriter.startElement("ForumWatchList");
            try {
                while ( (forumWatch=(String[])iter.next()) !=null) {
                    if (forumWatch.length!=7) {
                        throw new ExportException("Error while retrieving data about forum watch for forumID=="+forumID);

⌨️ 快捷键说明

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