james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabriel Bucher <gabriel.buc...@razor.ch>
Subject [PATCH] fix dir context in nntp repository
Date Tue, 11 Sep 2001 20:49:00 GMT
Last patch for today! :-)))

Fixed context dir in nntp repository!

Buchi


Index: 
src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java,v
retrieving revision 1.1
diff -u -r1.1 NNTPRepositoryImpl.java
--- src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java	2001/05/15 14:41:40
1.1
+++ src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java	2001/09/11 20:45:46
@@ -14,6 +14,9 @@
  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.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.excalibur.io.AndFileFilter;
  import org.apache.avalon.excalibur.io.DirectoryFileFilter;
@@ -23,8 +26,9 @@
  import org.apache.avalon.phoenix.Block;

  public class NNTPRepositoryImpl extends AbstractLoggable
-    implements NNTPRepository, Configurable, Initializable, Block
+    implements NNTPRepository, Contextualizable, Configurable, 
Initializable, Block
  {
+    private Context context;
      private boolean readOnly;
      // the groups are located under this path.
      private File rootPath;
@@ -33,18 +37,25 @@
      private NNTPSpooler spool;
      private ArticleIDRepository articleIDRepo;
      private String[] addGroups = null;
+
+
+    public void contextualize(Context context)
+            throws ContextException {
+        this.context = context;
+    }
+
      public void configure( Configuration configuration ) throws 
ConfigurationException {
          //System.out.println(getClass().getName()+": configure");
          //NNTPUtil.show(configuration,System.out);
          readOnly = 
configuration.getChild("readOnly").getValueAsBoolean(false);
-        rootPath = NNTPUtil.getDirectory(configuration,"rootPath");
-        tempPath = NNTPUtil.getDirectory(configuration,"tempPath");
-        File articleIDPath = 
NNTPUtil.getDirectory(configuration,"articleIDPath");
+        rootPath = NNTPUtil.getDirectory(context, configuration, 
"rootPath");
+        tempPath = NNTPUtil.getDirectory(context, configuration, 
"tempPath");
+        File articleIDPath = NNTPUtil.getDirectory(context, 
configuration, "articleIDPath");
          String articleIDDomainSuffix = 
configuration.getChild("articleIDDomainSuffix")
              .getValue("foo.bar.sho.boo");
          articleIDRepo = new 
ArticleIDRepository(articleIDPath,articleIDDomainSuffix);
          spool = (NNTPSpooler)NNTPUtil.createInstance
-            (configuration.getChild("spool"),getLogger(),
+            (context,configuration.getChild("spool"),getLogger(),
               "org.apache.james.nntpserver.repository.NNTPSpooler");
          spool.setRepository(this);
          spool.setArticleIDRepository(articleIDRepo);
Index: src/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPSpooler.java,v
retrieving revision 1.1
diff -u -r1.1 NNTPSpooler.java
--- src/java/org/apache/james/nntpserver/repository/NNTPSpooler.java	2001/05/15 14:41:40	1.1
+++ src/java/org/apache/james/nntpserver/repository/NNTPSpooler.java	2001/09/11 20:45:47
@@ -14,6 +14,9 @@
  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.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.logger.Loggable;
  import org.apache.avalon.excalibur.io.IOUtil;
@@ -21,13 +24,22 @@

  // processes entries and sends to appropriate groups.
  // eats up inappropriate entries.
-class NNTPSpooler extends AbstractLoggable implements Configurable, 
Initializable {
+class NNTPSpooler extends AbstractLoggable
+        implements Contextualizable, Configurable, Initializable {
+
+    private Context context;
      private Worker[] worker;
      private File spoolPath;
+
+    public void contextualize(final Context context)
+            throws ContextException {
+        this.context = context;
+    }
+
      public void configure( Configuration configuration ) throws 
ConfigurationException {
          //System.out.println(getClass().getName()+": configure");
          //NNTPUtil.show(configuration,System.out);
-        spoolPath = NNTPUtil.getDirectory(configuration,"spoolPath");
+        spoolPath = NNTPUtil.getDirectory(context, configuration, 
"spoolPath");
          int threadCount = 
configuration.getChild("threadCount").getValueAsInteger(1);
          int threadIdleTime = 
configuration.getChild("threadIdleTime").getValueAsInteger(1000);
          //String 
tgName=configuration.getChild("threadGroupName").getValue("NNTPSpooler");
Index: src/java/org/apache/james/nntpserver/repository/NNTPUtil.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPUtil.java,v
retrieving revision 1.1
diff -u -r1.1 NNTPUtil.java
--- src/java/org/apache/james/nntpserver/repository/NNTPUtil.java	2001/05/15 14:41:40	1.1
+++ src/java/org/apache/james/nntpserver/repository/NNTPUtil.java	2001/09/11 20:45:48
@@ -12,19 +12,27 @@
  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.context.Context;
+import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.Loggable;
+import org.apache.avalon.phoenix.BlockContext;
  import org.apache.james.nntpserver.NNTPException;
  import org.apache.log.Logger;

  // processes entries and sends to appropriate groups.
  // eats up inappropriate entries.
  public class NNTPUtil {
-    static File getDirectory(Configuration configuration,String child)
+    static File getDirectory(Context context, Configuration 
configuration, String child)
          throws ConfigurationException
      {
          String str = configuration.getChild(child).getValue();
-        if ( str.toLowerCase().startsWith("file://") )
-            str = str.substring("file://".length());
+        if (!str.toLowerCase().startsWith("file://") ) {
+            throw new ConfigurationException
+                ("Malformed " + child + " - Must be of the format 
\"file://<filename>\".");
+        }
+        str = str.substring("file://".length());
+        str = ((BlockContext)context).getBaseDirectory() +
+                File.separator + str;
          File f = new File(str);
          if ( f.exists() && f.isFile() )
              throw new NNTPException("Expecting 
'"+f.getAbsolutePath()+"' directory");
@@ -32,8 +40,11 @@
              f.mkdirs();
          return f;
      }
-    public static Object createInstance(Configuration 
configuration,Logger logger,
-                                        String clsName) throws 
ConfigurationException
+    public static Object createInstance(Context context,
+                                        Configuration configuration,
+                                        Logger logger,
+                                        String clsName)
+            throws ConfigurationException
      {
          try { clsName = configuration.getAttribute("class");
          } catch(ConfigurationException ce) { }
@@ -41,6 +52,8 @@
              Object obj = Class.forName(clsName).newInstance();
              if ( obj instanceof Loggable )
                  ((Loggable)obj).setLogger( logger );
+            if (obj instanceof Contextualizable)
+                ((Contextualizable)obj).contextualize(context);
              if ( obj instanceof Configurable )
 
((Configurable)obj).configure(configuration.getChild("configuration"));
              return obj;


---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org


Mime
View raw message