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

📄 categoryxml.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @throws ForeignKeyNotFoundException
     *
     */
    public void addCategoryWatch(String memberName,
                String watchType, String watchOption,
                String watchStatus, String watchCreationDate,
                String watchLastSentDate, String watchEndDate)
        throws CreateException, DatabaseException, ObjectNotFoundException,
        DuplicateKeyException, ForeignKeyNotFoundException {

        if (categoryID < 0) {
            throw new CreateException("Found category watch that is not assigned to any known category.");
        }

        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 category. 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, categoryID, 0/*forumId*/, 0/*threadId*/,
             watchType1, watchOption1, watchStatus1,
             watchCreationDate1, watchLastSentDate1, watchEndDate1);
    }

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

    public static void exportCategoryWatchesForCategory(XMLWriter xmlWriter, int categoryID)
        throws IOException, ExportException, NumberFormatException,
        ObjectNotFoundException, DatabaseException {

        Collection categoryWatches=ExportWebHelper.execSqlQuery(
                   "SELECT MemberID, WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate, WatchEndDate"+
                   " FROM "+WatchDAO.TABLE_NAME+
                   " WHERE ForumID=0 AND ThreadID=0"+
                   " AND CategoryID="+Integer.toString(categoryID));
        Iterator iter=categoryWatches.iterator();
        String[] categoryWatch=null;
        //try {
            xmlWriter.startElement("CategoryWatchList");
            try {
                while ( (categoryWatch=(String[])iter.next()) !=null) {
                    if (categoryWatch.length!=7) {
                        throw new ExportException("Error while retrieving data about category watch for categoryID=="+categoryID);
                    }
                    String memberName=DAOFactory.getMemberDAO().getMember_forPublic(Integer.parseInt(categoryWatch[0])).getMemberName();
                    xmlWriter.startElement("CategoryWatch");
                    xmlWriter.startElement("MemberName");
                    xmlWriter.writeData(memberName);
                    xmlWriter.endElement("MemberName");
                    xmlWriter.startElement("WatchType");
                    xmlWriter.writeData(categoryWatch[1]);
                    xmlWriter.endElement("WatchType");
                    xmlWriter.startElement("WatchOption");
                    xmlWriter.writeData(categoryWatch[2]);
                    xmlWriter.endElement("WatchOption");
                    xmlWriter.startElement("WatchStatus");
                    xmlWriter.writeData(categoryWatch[3]);
                    xmlWriter.endElement("WatchStatus");
                    xmlWriter.startElement("WatchCreationDate");
                    xmlWriter.writeData(categoryWatch[4]);
                    xmlWriter.endElement("WatchCreationDate");
                    xmlWriter.startElement("WatchLastSentDate");
                    xmlWriter.writeData(categoryWatch[5]);
                    xmlWriter.endElement("WatchLastSentDate");
                    xmlWriter.startElement("WatchEndDate");
                    xmlWriter.writeData(categoryWatch[6]);
                    xmlWriter.endElement("WatchEndDate");
                    xmlWriter.endElement("CategoryWatch");
                }
            } catch (NoSuchElementException e) {
                //no more database records
            }
            xmlWriter.endElement("CategoryWatchList");
         //} catch throw exportexception
    }

    public static void exportCategory(XMLWriter xmlWriter, int categoryID)
        throws NumberFormatException, IOException, ExportException, ObjectNotFoundException, DatabaseException {

        Collection category1=ExportWebHelper.execSqlQuery(
                   "SELECT CategoryName, CategoryDesc,"+
                   " CategoryCreationDate, CategoryModifiedDate, CategoryOrder,"+
                   " CategoryOption, CategoryStatus FROM "+CategoryDAO.TABLE_NAME+
                   " WHERE CategoryID="+Integer.toString(categoryID));
        Iterator iter = category1.iterator();
        String[] category = null;
        //try {
            try {
                if ((category = (String[]) iter.next()) == null) {
                    throw new ExportException("Can't find data for categoryID==" + categoryID);
                }
                if (category.length != 7) {
                    throw new ExportException("Error while retrieving data about category with categoryID==" + categoryID);
                }
            } catch (NoSuchElementException e) {
                throw new ExportException("Can't find data for categoryID=="+categoryID);
            }

            //if I am here, that means I now have correct object category
            xmlWriter.startElement("Category");
            xmlWriter.startElement("CategoryName");
            xmlWriter.writeData(DisableHtmlTagFilter.filter(category[0]));
            xmlWriter.endElement("CategoryName");
            xmlWriter.startElement("CategoryDesc");
            xmlWriter.writeData(DisableHtmlTagFilter.filter(category[1]));
            xmlWriter.endElement("CategoryDesc");
            xmlWriter.startElement("CategoryCreationDate");
            xmlWriter.writeData(category[2]);
            xmlWriter.endElement("CategoryCreationDate");
            xmlWriter.startElement("CategoryModifiedDate");
            xmlWriter.writeData(category[3]);
            xmlWriter.endElement("CategoryModifiedDate");
            xmlWriter.startElement("CategoryOrder");
            xmlWriter.writeData(category[4]);
            xmlWriter.endElement("CategoryOrder");
            xmlWriter.startElement("CategoryOption");
            xmlWriter.writeData(category[5]);
            xmlWriter.endElement("CategoryOption");
            xmlWriter.startElement("CategoryStatus");
            xmlWriter.writeData(category[6]);
            xmlWriter.endElement("CategoryStatus");
            exportCategoryWatchesForCategory(xmlWriter, categoryID);
            ForumXML.exportForumList(xmlWriter, categoryID);
            exportSubCategoryList(xmlWriter, categoryID);
            xmlWriter.endElement("Category");
         //} catch throw exportexception
    }

    public static void exportSubCategoryList(XMLWriter xmlWriter, int parentCategoryID)
        throws IOException, ExportException, ObjectNotFoundException, DatabaseException {

        Collection categoryIDs=ExportWebHelper.execSqlQuery(
                   "SELECT CategoryID"+
                   " FROM "+CategoryDAO.TABLE_NAME+
                   " WHERE ParentCategoryID="+Integer.toString(parentCategoryID));
        Iterator iter = categoryIDs.iterator();
        String[] categoryID = null;
        //try {
            xmlWriter.startElement("CategoryList");
            try {
                while ((categoryID = (String[]) iter.next()) != null) {
                    if (categoryID.length != 1) {
                        throw new ExportException("Error while retrieving list of categories.");
                    }
                    try {
                        int i = Integer.parseInt(categoryID[0]);
                        exportCategory(xmlWriter, i);
                    } catch (NumberFormatException e) {
                        throw new ExportException("Error while retrieving list of categories.");
                    }
                }
            } catch (NoSuchElementException e) {
                //no more database records
            }
            xmlWriter.endElement("CategoryList");
         //} catch throw exportexception
    }

    public static void exportCategoryList(XMLWriter xmlWriter)
        throws IOException, ExportException, ObjectNotFoundException, DatabaseException {

        exportSubCategoryList(xmlWriter, 0/*parentCategoryID*/);
    }

}

⌨️ 快捷键说明

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