newsgroupexporter.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 713 行 · 第 1/2 页
JAVA
713 行
/** * $RCSfile: NewsgroupExporter.java,v $ * $Revision: 1.6 $ * $Date: 2002/05/24 22:45:30 $ * * Copyright (C) 1999-2002 CoolServlets, Inc. All Rights Reserved. * * This software is the proprietary information of CoolServlets, Inc. * Use is subject to license terms. */package com.jivesoftware.forum.gateway;import com.jivesoftware.forum.*;import dog.mail.nntp.NNTPTransport;import javax.activation.DataHandler;import javax.mail.*;import javax.mail.internet.*;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.util.Iterator;import java.util.Properties;/** * A gateway for the export of messages to a newsgroup. * * @author Bruce Ritchie */public class NewsgroupExporter implements GatewayExporter { private NNTPGateway gateway; private int lastMessageNumberSeen = -1; private boolean stopFlag = false; /** * 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"; /** * Create an instance. */ public NewsgroupExporter(ForumFactory factory, Forum forum) { gateway = new NNTPGateway(factory, forum); } //FROM THE GATEWAYEXPORTER INTERFACE// /** * Export a forum message to a newsgroup.<p> * * 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); } /** * Export an array of forum messages to a newsgroup.<p> * * 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. Therefore, parent messages should be * first in the list. * * @param forumMessage array of messages to export, sorted parents first. * @throws GatewayException if a connection was unable to be established. */ public synchronized void exportData(ForumMessage[] forumMessage) throws GatewayException { for (int x=0; x < forumMessage.length; x++) { // stop if we've been told to if (stopFlag) { break; } exportData(forumMessage[x]); } } public void stop() throws GatewayException { stopFlag = true; } //GATEWAY PROPERTIES// /** * Retrieves the username set for this gateway. Default is null. * * @return username the username to be used in connecting to the NNTP server. */ public String getUsername() { return gateway.getUsername(); } /** * Sets the username to be used in connecting to the NNTP server. * * @param username the username to be used in connecting to the NNTP server. */ public void setUsername(String username) { if ("".equals(username)) { username = null; } gateway.setUsername(username); } /** * Retrieves the password to be used in connecting to the NNTP server. * Default is null. * * @return the password to be used in connecting to the NNTP server. */ public String getPassword() { return gateway.getPassword(); } /** * Sets the password to be used in connecting to the NNTP server. * * @param password the password to use be used in connecting to the * NNTP server. */ public void setPassword(String password) { if ("".equals(password)) { password = null; } gateway.setPassword(password); } /** * Returns the port number that will be used when connecting to the NNTP * server. The default is 119, the standard NNTP port number. * * @return the port number that will be used when connecting to the NNTP * server. */ public int getPort() { return gateway.getPort(); } /** * Set the port to use when connecting to the NNTP server. The default is * port 119; for ssl the normal port to use is 993. * * @param port the port to use when connecting to the NNTP server. The * default is port 119. */ public void setPort(int port) { gateway.setPort(port); // Old session no longer valid so set to null. gateway.session = null; } /** * Returns the NNTP host (eg news.example.com). The host is null by * default, but must be set before gateway exports can execute. * * @return the NNTP host (eg news.example.com). */ public String getHost() { return gateway.getHost(); } /** * Sets the NNTP host (eg news.example.com). The host is null by * default, but must be set before gateway exports can execute. * * @param host the NNTP host (eg news.example.com) to use. */ public void setHost(String host) { gateway.setHost(host); // Old session no longer valid so set to null. gateway.session = null; } /** * Retrieves the newsgroup that the gateway is going to use. * * @return the newsgroup that the gateway will use. */ public String getNewsgroup() { return gateway.getMailbox(); } /** * Sets the newsgroup that this gateway is going to use. * * @param newsgroup the newsgroup the gateway is going to use. */ public void setNewsgroup(String newsgroup) { gateway.setMailbox(newsgroup); // Old session no longer valid so set to null. gateway.session = null; } /** * 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, false otherwise. */ public boolean isDebugEnabled() { return gateway.isDebugEnabled(); } /** * Toggles NNTP transport layer debugging on or off. Debug information is * written to <tt>System.out<p> * * @param debugEnabled true if NNTP debugging should be enabled, false otherwise. */ public 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. * * @return true if a user's privacy setting on their email address should * be obeyed when doing an export. */ public boolean isEmailPrefEnabled() { return gateway.isEmailPrefEnabled(); } /** * Sets whether the user's privacy setting on their email address should be * obeyed when doing an export. * * @param enabled true if a user's privacy setting on their email address * should be obeyed when doing an export. */ public void setEmailPrefEnabled(boolean enabled) { gateway.setEmailPrefEnabled(enabled); } /** * From email address to send mail from for export. Used in the case * of anonymous users and users who hide their information. * * @return the current sender. */ public String getDefaultFromAddress() { return gateway.getDefaultFromAddress(); } /** * Set the from email address for message export to be used in the case * of anonymous users and users who hide their information. * * @param address the from email address. */ public void setDefaultFromAddress(String address) { if ("".equals(address)) { address = null; } gateway.setDefaultFromAddress(address); } /** * Retrieves the Organization header for outbound NNTP messages. * Default is null. * * @return the current organization header. */ public String getOrganization() { return gateway.getOrganization(); } /** * Sets the Organization header for outbound NNTP messages. * * @param organization the string to set the * organization header to. */ public void setOrganization(String organization) { gateway.setOrganization(organization); } /** * Used by the gateway to keep track of the last message seen. * This allows for fast updates since we can ask the NNTP * server for only the messages newer than the message associated * with this message number.<p> * * It is *highly* recommended not to set this yourself. * * @param messageNumber the last message number seen by this gateway. */ public void setLastMessageNumberSeen(int messageNumber) { if (messageNumber > 0) { lastMessageNumberSeen = messageNumber; } } /** * Used by the gateway to keep track of the last message seen. * This allows for fast updates since we can ask the NNTP * server for only the messages newer than the message associated * with this message number.<p> * * It is *highly* recommended not to set this but rather let the * gateway handle it itself. * * @return the last message number seen by this gateway. */ public int getLastMessageNumberSeen() { return lastMessageNumberSeen; } /** * Retrieve whether the gateway will update the messageID * message property stored in Jive upon export of a message. * By default, the messageID is stored in Jive so that the * message won't be reexported accidentally.<p> * * Note: This setting has no effect unless accompanied by * setAllowExportAgain(true). * * @return true if the gateway will update Jive with the messageID * on export, false otherwise. */ public boolean isUpdateMessageIDOnExport() { return gateway.isUpdateMessageID(); } /** * Sets whether the gateway will update the messageID * message property stored in Jive upon export of a message.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?