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

📄 newsgroupgateway.java

📁 jive 2.1.1 的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * $RCSfile: NewsgroupGateway.java,v $
 * $Revision: 1.26 $
 * $Date: 2001/09/22 17:43:18 $
 *
 * Copyright (C) 1999-2001 CoolServlets Inc. All rights reserved.
 * ===================================================================
 * The Jive Software License (based on Apache Software License, Version 1.1)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by
 *        Jive Software (http://www.jivesoftware.com)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Jive" and "CoolServlets" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please
 *    contact webmaster@coolservlets.com.
 *
 * 5. Products derived from this software may not be called "Jive",
 *    nor may "Jive" appear in their name, without prior written
 *    permission of CoolServlets.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL COOLSERVLETS INC OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 * This software consists of voluntary contributions made by many
 * individuals on behalf of Jive Software. For more information
 * on Jive Software please visit http://www.jivesoftware.com.
 */

package com.jivesoftware.forum.gateway;

import java.io.*;
import java.util.*;
import java.text.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import com.jivesoftware.forum.*;
import com.jivesoftware.util.*;
import dog.mail.nntp.*;

/**
 * A gateway for the import and export of messages to and
 * from a newsgroup
 *
 * @author Bruce Ritchie
 */
public class NewsgroupGateway implements Gateway {

    private NNTPGateway gateway;
    private int lastMessageNumberSeen = -1;

    /**
     * used to flag messages in the forum with a message id
     * specific to this gateway
     */
    public static final String GATEWAY_MESSAGE_ID = "NNTP-Message-ID";

    /**
     * used to flag messages in the forum with a parent id
     * specific to this gateway
     */
    public static final String GATEWAY_PARENT_ID = "NNTP-Parent-ID";

    /**
     * Used for defining for the nntp gateway from when to do the import
     */
    private static final SimpleDateFormat DATEFORMATTER =
            new SimpleDateFormat("yyyy.MM.dd hh:mm:ss");

    /**
     * Create an instance
     */
    public NewsgroupGateway(ForumFactory factory, Forum forum) {
        gateway = new NNTPGateway(factory, forum);
    }

    //FROM THE GATEWAY INTERFACE//

    public synchronized void importData(Date afterDate) throws GatewayException
    {
        gateway.importData(afterDate);
    }

    /**
     * Export a forum message to a newsgroup.
     *<br>
     * NOTE: It is imperative that parent messages get exported prior to
     * children messages so that the proper message headers can be set. Failure
     * to do this will result in messages that may not be threaded properly
     * when viewed using a newsreader.
     *
     * @param forumMessage message to export
     * @throws GatewayException if a connection was unable to be established
     */
    public synchronized void exportData(ForumMessage forumMessage) throws GatewayException
    {
        gateway.exportData(forumMessage);
    }

    //GATEWAY PROPERTIES//

    public String getUsername() {
        return gateway.getUsername();
    }

    public void setUsername(String username) {
        if ("".equals(username)) {
            username = null;
        }
        gateway.setUsername(username);
    }

    public String getPassword() {
        return gateway.getPassword();
    }

    public void setPassword(String password) {
        if ("".equals(password)) {
            password = null;
        }
        gateway.setPassword(password);
    }

    /** default 119 */
    public int getNNTPPort() {
        return gateway.getPort();
    }

    public synchronized void setNNTPPort(int port) {
        gateway.setPort(port);

        // Old session no longer valid so set to null.
        gateway.session = null;
    }

    public String getNNTPHost() {
        return gateway.getHost();
    }

    public synchronized void setNNTPHost(String host) {
        gateway.setHost(host);

        // Old session no longer valid so set to null.
        gateway.session = null;
    }

     public String getNewsgroup() {
        return gateway.getMailbox();
    }

    public synchronized void setNewsgroup(String newsgroup) {
        gateway.setMailbox(newsgroup);

        // Old session no longer valid so set to null.
        gateway.session = null;
    }

    /**
     * Returns the body that will be used when creating temporary parent
     * messages. It's possible with email accounts and mailing
     * lists to get a response to a message before getting the original message.
     * If this happens and only the child message is available at the time of
     * the gateway import, Jive must still have a way to establish a correct
     * parent/child relationship. Therefore, a temporary fake parent message is
     * created using an extrapolated subject from the child, and a body with the
     * value <tt>temporaryParentBody</tt>. By default, this value will be
     * the empty String. However, you may wish to create a short message that
     * explains the nature of the fake parent message to the user.<p>
     *
     * On subsequent imports when a real parent message is found, the fake
     * data will be replaced with the correct subject and body.<p>
     *
     * @return the message body that will be used for temporary fake parent
     *      messages.
     */
    public String getTemporaryParentBody() {
        return gateway.getTemporaryParentBody();
    }

    /**
     * Sets the body that will be used when creating temporary parent
     * messages. It's possible with email accounts and mailing
     * lists to get a response to a message before getting the original message.
     * If this happens and only the child message is available at the time of
     * the gateway import, Jive must still have a way to establish a correct
     * parent/child relationship. Therefore, a temporary fake parent message is
     * created using an extrapolated subject from the child, and a body with the
     * value <tt>temporaryParentBody</tt>. By default, this value will be
     * the empty String. However, you may wish to create a short message that
     * explains the nature of the fake parent message to the user.<p>
     *
     * On subsequent imports when a real parent message is found, the fake
     * data will be replaced with the correct subject and body.<p>
     *
     * @param temporaryParentBody the message body that will be used for
     *      temporary fake parent messages.
     */
    public void setTemporaryParentBody(String temporaryParentBody) {
        gateway.setTemporaryParentBody(temporaryParentBody);
    }

    /**
     * Returns true if debugging is turned on for the NNTP transport layer.
     * Debug information is written to <tt>System.out.err</tt>.
     *
     * @return true if NNTP debugging is turned on.
     */
    public boolean isDebugEnabled() {
        return gateway.isDebugEnabled();
    }

    /**
     * Toggles NNTP transport layer debugging on or off. Debug information is
     * written to <tt>System.out</tt>.
     *
     * @param debug true if NNTP debugging should be enabled.
     */
    public synchronized void setDebugEnabled(boolean debugEnabled) {
        gateway.setDebugEnabled(debugEnabled);

        // Old session no longer valid so set to null.
        gateway.session = null;
    }

    /**
     * True if a user's privacy setting on their email address should be obeyed
     * when doing an export.
     */
    public boolean isEmailPrefEnabled() {
        return gateway.isEmailPrefEnabled();
    }

    public void setEmailPrefEnabled(boolean enabled) {
        gateway.setEmailPrefEnabled(enabled);
    }

    public String getDefaultFromAddress() {
        return gateway.getDefaultFromAddress();
    }

    public void setDefaultFromAddress(String address) {
        if ("".equals(address)) {

⌨️ 快捷键说明

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