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

📄 groupxml.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public static void addRegisteredMembersGroupPermission(String permission)
    throws CreateException, DatabaseException, DuplicateKeyException,
    ForeignKeyNotFoundException {
        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.");
        }
        DAOFactory.getGroupPermissionDAO().create(MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS, permission1);
    }

    public static void addGroupPermission(String groupname, String permission)
    throws CreateException, DatabaseException, DuplicateKeyException,
    ForeignKeyNotFoundException, ObjectNotFoundException {
        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.");
        }
        DAOFactory.getGroupPermissionDAO().create(DAOFactory.getGroupsDAO().getGroupIDFromGroupName(groupname), permission1);
    }

    /**
     * Adds a member 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 member assignment will be simply ignored.
     *
     * @param memberName MemberName of a meber to be added to this group.
     * @param privilege Can be null.
     * @param creationDate Can be null.
     * @param modifiedDate Can be null.
     *
     * @throws CreateException
     * @throws DatabaseException
     * @throws DuplicateKeyException
     * @throws ForeignKeyNotFoundException
     *
     */
    public void addMemberGroup(String memberName, String privilege,
                String creationDate, String modifiedDate)
    throws CreateException, DatabaseException, DuplicateKeyException, ForeignKeyNotFoundException {
        if (groupID<0) {
            throw new CreateException("Found group member that is not assigned to any known group.");
        }
        if ( (memberName==null) || (memberName.equals("")) ) {
            throw new CreateException("Can't create a group member with empty MemberName.");
        }

        int privilege1;
        java.sql.Timestamp creationDate1;
        java.sql.Timestamp modifiedDate1;
        try {
            privilege1= XMLUtil.stringToIntDef(privilege, 0);
            creationDate1= XMLUtil.stringToSqlTimestampDefNow(creationDate);
            modifiedDate1= XMLUtil.stringToSqlTimestampDefNow(modifiedDate);
        } catch (NumberFormatException e) {
            throw new CreateException("Invalid data for a group member. Expected a number.");
        }
        DAOFactory.getMemberGroupDAO().create(this.groupID, memberName,
                             privilege1, creationDate1, modifiedDate1);
    }

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

    public static void exportGlobalPermissionsForGroup(XMLWriter xmlWriter, int groupID)
    throws IOException, DatabaseException, ExportException {
        Collection globalPermissions=ExportWebHelper.execSqlQuery(
                   "SELECT Permission"+
                   " FROM "+GroupPermissionDAO.TABLE_NAME+
                   " WHERE GroupID="+Integer.toString(groupID));
        Iterator iter=globalPermissions.iterator();
        String[] globalPermission=null;
        //try {
            xmlWriter.startElement("GlobalPermissionList");
            try {
                while ( (globalPermission=(String[])iter.next()) !=null) {
                    if (globalPermission.length!=1) {
                        throw new ExportException("Error while retrieving data about global permissions for groupID=="+groupID);
                    }
                    xmlWriter.startElement("GlobalPermission");
                    xmlWriter.writeData(globalPermission[0]);
                    xmlWriter.endElement("GlobalPermission");
                }
            } catch (NoSuchElementException e) {
                //no more database records
            }
            xmlWriter.endElement("GlobalPermissionList");
         //} catch throw exportexception
    }

    public static void exportGroupMembersForGroup(XMLWriter xmlWriter, int groupID)
    throws IOException, DatabaseException, ExportException {
        Collection groupMembers=ExportWebHelper.execSqlQuery(
                   "SELECT MemberName, Privilege, CreationDate, ModifiedDate"+
                   " FROM "+MemberGroupDAO.TABLE_NAME+
                   " WHERE GroupID="+Integer.toString(groupID));
        //todo Igor: I am using MemberName, but nobody can guarantee it will be consistent with MemberID
        Iterator iter=groupMembers.iterator();
        String[] groupMember=null;
        //try {
            xmlWriter.startElement("GroupMemberList");
            try {
                while ( (groupMember=(String[])iter.next()) !=null) {
                    if (groupMember.length!=4) {
                        throw new ExportException("Error while retrieving data about group member for groupID=="+groupID);
                    }
                    xmlWriter.startElement("GroupMember");
                    xmlWriter.startElement("MemberName");
                    xmlWriter.writeData(groupMember[0]);
                    xmlWriter.endElement("MemberName");
                    xmlWriter.startElement("Privilege");
                    xmlWriter.writeData(groupMember[1]);
                    xmlWriter.endElement("Privilege");
                    xmlWriter.startElement("CreationDate");
                    xmlWriter.writeData(groupMember[2]);
                    xmlWriter.endElement("CreationDate");
                    xmlWriter.startElement("ModifiedDate");
                    xmlWriter.writeData(groupMember[3]);
                    xmlWriter.endElement("ModifiedDate");
                    xmlWriter.endElement("GroupMember");
                }
            } catch (NoSuchElementException e) {
                //no more database records
            }
            xmlWriter.endElement("GroupMemberList");
         //} catch throw exportexception
    }

    public static void exportGroup(XMLWriter xmlWriter, int groupID)
    throws IOException, DatabaseException, ExportException {
        Collection group1=ExportWebHelper.execSqlQuery(
                   "SELECT GroupOwnerName, GroupName,"+
                   " GroupDesc, GroupOption, GroupCreationDate, GroupModifiedDate"+
                   " FROM "+GroupsDAO.TABLE_NAME+
                   " WHERE GroupID="+Integer.toString(groupID));
        Iterator iter=group1.iterator();
        String[] group=null;
        //try {
            try {
                if ( (group=(String[])iter.next()) ==null) {
                    throw new ExportException("Can't find data for groupID=="+groupID);
                }
                if (group.length!=6) {
                    throw new ExportException("Error while retrieving data about group with groupID=="+groupID);
                }
            } catch (NoSuchElementException e) {
                throw new ExportException("Can't find data for groupID=="+groupID);
            }

            //if I am here, that means I now have correct object group
            if (groupID==MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS) {
                xmlWriter.startElement("Group", new String[]{"class", "RegisteredMembers"});
            } else {
                xmlWriter.startElement("Group");
            }
            xmlWriter.startElement("GroupOwnerName");
            xmlWriter.writeData(group[0]);
            xmlWriter.endElement("GroupOwnerName");
            xmlWriter.startElement("GroupName");
            xmlWriter.writeData(DisableHtmlTagFilter.filter(group[1]));
            xmlWriter.endElement("GroupName");
            xmlWriter.startElement("GroupDesc");
            xmlWriter.writeData(DisableHtmlTagFilter.filter(group[2]));
            xmlWriter.endElement("GroupDesc");
            xmlWriter.startElement("GroupOption");
            xmlWriter.writeData(group[3]);
            xmlWriter.endElement("GroupOption");
            xmlWriter.startElement("GroupCreationDate");
            xmlWriter.writeData(group[4]);
            xmlWriter.endElement("GroupCreationDate");
            xmlWriter.startElement("GroupModifiedDate");
            xmlWriter.writeData(group[5]);
            xmlWriter.endElement("GroupModifiedDate");
            exportGlobalPermissionsForGroup(xmlWriter, groupID);
            exportGroupMembersForGroup(xmlWriter, groupID);
            xmlWriter.endElement("Group");
         //} catch throw exportexception
    }

    public static void exportGroupList(XMLWriter xmlWriter)
    throws IOException, DatabaseException, ExportException {
        Collection groupIDs=ExportWebHelper.execSqlQuery(
                   "SELECT GroupID"+
                   " FROM "+GroupsDAO.TABLE_NAME);
        Iterator iter=groupIDs.iterator();
        String[] groupID=null;
        //try {
            xmlWriter.startElement("GroupList");
            /* First, I'll export Registered Members group. If it doesn't exist, just continue. */
            try {
                exportGroup(xmlWriter, MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS);
            } catch (Exception e) {
                //doesn't exist => ignore
            }
            try {
                while ( (groupID=(String[])iter.next()) !=null) {
                    if (groupID.length!=1) {
                        throw new ExportException("Error while retrieving list of groups.");
                    }
                    try {
                        int i=Integer.parseInt(groupID[0]);
                        if (i!=MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS) {
                            exportGroup(xmlWriter, i);
                        }
                    } catch (NumberFormatException e) {
                        throw new ExportException("Error while retrieving list of groups.");
                    }
                }
            } catch (NoSuchElementException e) {
                //no more database records
            }
            xmlWriter.endElement("GroupList");
         //} catch throw exportexception
    }


}

⌨️ 快捷键说明

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