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

📄 categoryxml.java

📁 java servlet著名论坛源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/CategoryXML.java,v 1.4 2004/05/19 19:11:56 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.4 $
 * $Date: 2004/05/19 19:11:56 $
 *
 * ====================================================================
 *
 * 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.admin.importexport.XMLUtil;
import com.mvnforum.admin.importexport.XMLWriter;
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/05/19 19:11:56 $
 * <br/>
 * <code>CategoryXML</code> todo Igor: enter description
 *
 */
public class CategoryXML {

    private int categoryID;
    /** Returns <code>CategoryID</code> of this category or
      * <code>-1</code> if category is not created yet. */
    public int getCategoryID() { return categoryID; }

    private int parentCategoryID;
    /** Returns <code>ThreadID</code> of this category's parent category or
      * <code>0</code> if this category is not created yet or has no parent category. */
    public int getParentCategoryID() { return parentCategoryID; }

    public CategoryXML() {
        super();
        categoryID=-1;
        parentCategoryID=0;
    }

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

    public void setParentCategory(CategoryXML parentCategory)
    throws ForeignKeyNotFoundException {
        parentCategoryID=parentCategory.getCategoryID();
    }

    public void setParentCategoryID(int value) {
        if (value<0) parentCategoryID=-1;
        else parentCategoryID=value;
    }

    /**
     * Creates a category. 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 categoryName Name of a category to be created.
     * @param categoryDesc Can be null.
     * @param categoryCreationDate Can be null.
     * @param categoryModifiedDate Can be null.
     * @param categoryOrder Can be null.
     * @param categoryOption Can be null.
     * @param categoryStatus Can be null.
     *
     * @throws CreateException
     * @throws DuplicateKeyException
     * @throws ObjectNotFoundException
     * @throws DatabaseException
     * @throws ForeignKeyNotFoundException
     *
     */
    public void addCategory(String categoryName,
                            String categoryDesc, String categoryCreationDate,
                            String categoryModifiedDate, String categoryOrder,
                            String categoryOption, String categoryStatus)
    throws CreateException, DuplicateKeyException, ObjectNotFoundException,
    DatabaseException, ForeignKeyNotFoundException {
        //parentCategoryID can be 0, and don't need to check if it's set or not
        if ( (categoryName==null) || (categoryName.equals("")) ) {
            throw new CreateException("Can't create a category with empty CategoryName.");
        } else {
            java.sql.Timestamp categoryCreationDate1;
            java.sql.Timestamp categoryModifiedDate1;
            int categoryOrder1;
            int categoryOption1;
            int categoryStatus1;

            try {
                if (categoryDesc==null) categoryDesc="";
                categoryCreationDate1= XMLUtil.stringToSqlTimestampDefNow(categoryCreationDate);
                categoryModifiedDate1= XMLUtil.stringToSqlTimestampDefNow(categoryModifiedDate);
                categoryOrder1= XMLUtil.stringToIntDef(categoryOrder, 0);
                categoryOption1= XMLUtil.stringToIntDef(categoryOption, 0);
                categoryStatus1= XMLUtil.stringToIntDef(categoryStatus, 0);
            } catch (NumberFormatException e) {
                throw new CreateException("Invalid data for a category. Expected a number.");
            }

            categoryName=EnableHtmlTagFilter.filter(categoryName);
            categoryDesc=EnableHtmlTagFilter.filter(categoryDesc);

            DAOFactory.getCategoryDAO().create(
                parentCategoryID, categoryName, categoryDesc,
                categoryCreationDate1, categoryModifiedDate1,
                categoryOrder1, categoryOption1, categoryStatus1);

            //todo Igor: Minh, you could move next piece of code into CategoryWebHelper.getCategoryIDFromPrimaryKey method
            Collection categories=DAOFactory.getCategoryDAO().getBeans();
            Iterator iter=categories.iterator();
            try {
                CategoryBean cat=null;
                categoryID=-1;
                while ( (cat=(CategoryBean)iter.next() )!=null) {
                    if ((cat.getCategoryName().equals(categoryName)) &&
                        (cat.getParentCategoryID()==parentCategoryID)) {
                        categoryID=cat.getCategoryID();
                        break;
                    }
                }
                if (categoryID<0) {
                    throw new ObjectNotFoundException("Can't find category I've just added.");
                }
            } catch (NoSuchElementException e) {
                throw new ObjectNotFoundException("Can't find category I've just added.");
            }

        }
    }

    /**
     * Creates a category watch for this category. In order to know which category we are
     * reffering to, this method is supposed to be called after {@link #setCategoryID(String)}
     * or {@link #addCategory(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

⌨️ 快捷键说明

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