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

📄 nntprepositoryimpl.java

📁 邮件服务器系统 支持SMTP POP3 是著名的Apache写 有一定的参考价值
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************** * Copyright (c) 2000-2004 The Apache Software Foundation.             * * All rights reserved.                                                * * ------------------------------------------------------------------- * * Licensed under the Apache License, Version 2.0 (the "License"); you * * may not use this file except in compliance with the License. You    * * may obtain a copy of the License at:                                * *                                                                     * *     http://www.apache.org/licenses/LICENSE-2.0                      * *                                                                     * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS,   * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     * * implied.  See the License for the specific language governing       * * permissions and limitations under the License.                      * ***********************************************************************/package org.apache.james.nntpserver.repository;import org.apache.avalon.excalibur.io.AndFileFilter;import org.apache.avalon.excalibur.io.DirectoryFileFilter;import org.apache.avalon.framework.activity.Initializable;import org.apache.avalon.framework.configuration.Configurable;import org.apache.avalon.framework.configuration.Configuration;import org.apache.avalon.framework.configuration.ConfigurationException;import org.apache.avalon.framework.container.ContainerUtil;import org.apache.avalon.framework.context.Context;import org.apache.avalon.framework.context.ContextException;import org.apache.avalon.framework.context.Contextualizable;import org.apache.avalon.framework.logger.AbstractLogEnabled;import org.apache.avalon.framework.logger.LogEnabled;import org.apache.james.context.AvalonContextUtilities;import org.apache.james.nntpserver.DateSinceFileFilter;import org.apache.james.nntpserver.NNTPException;import org.apache.oro.io.GlobFilenameFilter;import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.io.IOException;import java.io.PrintStream;import java.util.ArrayList;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Set;/** * NNTP Repository implementation. */public class NNTPRepositoryImpl extends AbstractLogEnabled     implements NNTPRepository, Contextualizable, Configurable, Initializable {    /**     * The context employed by this repository     */    private Context context;    /**     * The configuration employed by this repository     */    private Configuration configuration;    /**     * Whether the repository is read only     */    private boolean readOnly;    /**     * The groups are located under this path.     */    private File rootPath;    /**     * Articles are temporarily written here and then sent to the spooler.     */    private File tempPath;    /**     * The spooler for this repository.     */    private NNTPSpooler spool;    /**     * The article ID repository associated with this NNTP repository.     */    private ArticleIDRepository articleIDRepo;    /**     * A map to allow lookup of valid newsgroup names     */    private HashMap groupNameMap = null;    /**     * Restrict use to newsgroups specified in config only     */    private boolean definedGroupsOnly = false;    /**     * The root path as a String.     */    private String rootPathString = null;    /**     * The temp path as a String.     */    private String tempPathString = null;    /**     * The article ID path as a String.     */    private String articleIdPathString = null;    /**     * The domain suffix used for files in the article ID repository.     */    private String articleIDDomainSuffix = null;    /**     * The ordered list of fields returned in the overview format for     * articles stored in this repository.     */    private String[] overviewFormat = { "Subject:",                                        "From:",                                        "Date:",                                        "Message-ID:",                                        "References:",                                        "Bytes:",                                        "Lines:"                                      };    /**     * This is a mapping of group names to NNTP group objects.     *     * TODO: This needs to be addressed so it scales better     */    private HashMap repositoryGroups = new HashMap();    /**     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(Context)     */    public void contextualize(Context context)            throws ContextException {        this.context = context;    }    /**     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)     */    public void configure( Configuration aConfiguration ) throws ConfigurationException {        configuration = aConfiguration;        readOnly = configuration.getChild("readOnly").getValueAsBoolean(false);        articleIDDomainSuffix = configuration.getChild("articleIDDomainSuffix")            .getValue("foo.bar.sho.boo");        rootPathString = configuration.getChild("rootPath").getValue(null);        if (rootPathString == null) {            throw new ConfigurationException("Root path URL is required.");        }        tempPathString = configuration.getChild("tempPath").getValue(null);        if (tempPathString == null) {            throw new ConfigurationException("Temp path URL is required.");        }        articleIdPathString = configuration.getChild("articleIDPath").getValue(null);        if (articleIdPathString == null) {            throw new ConfigurationException("Article ID path URL is required.");        }        if (getLogger().isDebugEnabled()) {            if (readOnly) {                getLogger().debug("NNTP repository is read only.");            } else {                getLogger().debug("NNTP repository is writeable.");            }            getLogger().debug("NNTP repository root path URL is " + rootPathString);            getLogger().debug("NNTP repository temp path URL is " + tempPathString);            getLogger().debug("NNTP repository article ID path URL is " + articleIdPathString);        }        Configuration newsgroupConfiguration = configuration.getChild("newsgroups");        definedGroupsOnly = newsgroupConfiguration.getAttributeAsBoolean("only", false);        groupNameMap = new HashMap();        if ( newsgroupConfiguration != null ) {            Configuration[] children = newsgroupConfiguration.getChildren("newsgroup");            if ( children != null ) {                for ( int i = 0 ; i < children.length ; i++ ) {                    String groupName = children[i].getValue();                    groupNameMap.put(groupName, groupName);                }            }        }        getLogger().debug("Repository configuration done");    }    /**     * @see org.apache.avalon.framework.activity.Initializable#initialize()     */    public void initialize() throws Exception {        getLogger().debug("Starting initialize");        File articleIDPath = null;        try {            rootPath = AvalonContextUtilities.getFile(context, rootPathString);            tempPath = AvalonContextUtilities.getFile(context, tempPathString);            articleIDPath = AvalonContextUtilities.getFile(context, articleIdPathString);        } catch (Exception e) {            getLogger().fatalError(e.getMessage(), e);            throw e;        }        if ( articleIDPath.exists() == false ) {            articleIDPath.mkdirs();        }        articleIDRepo = new ArticleIDRepository(articleIDPath, articleIDDomainSuffix);        spool = (NNTPSpooler)createSpooler();        spool.setRepository(this);        spool.setArticleIDRepository(articleIDRepo);        if (getLogger().isDebugEnabled()) {            getLogger().debug("repository:readOnly=" + readOnly);            getLogger().debug("repository:rootPath=" + rootPath.getAbsolutePath());            getLogger().debug("repository:tempPath=" + tempPath.getAbsolutePath());        }        if ( rootPath.exists() == false ) {            rootPath.mkdirs();        } else if (!(rootPath.isDirectory())) {            StringBuffer errorBuffer =                new StringBuffer(128)                    .append("NNTP repository root directory is improperly configured.  The specified path ")                    .append(rootPathString)                    .append(" is not a directory.");            throw new ConfigurationException(errorBuffer.toString());        }        Set groups = groupNameMap.keySet();        Iterator groupIterator = groups.iterator();        while( groupIterator.hasNext() ) {            String groupName = (String)groupIterator.next();            File groupFile = new File(rootPath,groupName);            if ( groupFile.exists() == false ) {                groupFile.mkdirs();            } else if (!(groupFile.isDirectory())) {                StringBuffer errorBuffer =

⌨️ 快捷键说明

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