You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by pg...@apache.org on 2002/08/08 01:38:48 UTC

cvs commit: jakarta-james/src/java/org/apache/james/nntpserver/repository NNTPUtil.java NNTPRepositoryImpl.java NNTPGroupImpl.java

pgoldstein    2002/08/07 16:38:48

  Modified:    src/java/org/apache/james/nntpserver/repository
                        NNTPUtil.java NNTPRepositoryImpl.java
                        NNTPGroupImpl.java
  Log:
  Part of the String=>StringBuffer changes.  Includes some additional
  commenting, formatting fixes, and wrapping of logging calls in log
  level checks.  Also converted equalsIgnoreCase paradigm as discussed on
  mailing list.  Locale issue for both toUpperCase() and toLowerCase() was
  addressed as well.
  
  Revision  Changes    Path
  1.7       +34 -10    jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPUtil.java
  
  Index: NNTPUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPUtil.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NNTPUtil.java	28 Jul 2002 11:27:58 -0000	1.6
  +++ NNTPUtil.java	7 Aug 2002 23:38:48 -0000	1.7
  @@ -11,6 +11,7 @@
   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.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  @@ -19,6 +20,7 @@
   
   import java.io.File;
   import java.io.PrintStream;
  +import java.util.Locale;
   
   /**
    * Helper fuctions. 
  @@ -28,24 +30,39 @@
    * @author Harmeet Bedi <ha...@kodemuse.com>
    */
   public class NNTPUtil {
  +
  +    private final static int prefixLength = "file://".length();
  +
       static File getDirectory(Context context, Configuration configuration, String child)
           throws ConfigurationException
       {
           String fileName = configuration.getChild(child).getValue();
  -        if (!fileName.toLowerCase().startsWith("file://") ) {
  -            throw new ConfigurationException
  -                ("Malformed " + child + " - Must be of the format \"file://<filename>\".");
  +        if (!fileName.toLowerCase(Locale.US).startsWith("file://") ) {
  +            StringBuffer exceptionBuffer =
  +                new StringBuffer(128)
  +                        .append("Malformed ")
  +                        .append(child)
  +                        .append(" - Must be of the format \"file://<filename>\".");
  +            throw new ConfigurationException(exceptionBuffer.toString());
           }
  -        fileName = fileName.substring("file://".length());
  +        fileName = fileName.substring(prefixLength);
           if (!(fileName.startsWith("/"))) {
               fileName = ((BlockContext)context).getBaseDirectory() +
                          File.separator + fileName;
           }
           File f = new File(fileName);
           if ( f.exists() && f.isFile() )
  -            throw new NNTPException("Expecting '"+f.getAbsolutePath()+"' directory");
  -        if ( f.exists() == false )
  +        {
  +            StringBuffer exceptionBuffer =
  +                new StringBuffer(160)
  +                        .append("Expecting '")
  +                        .append(f.getAbsolutePath())
  +                        .append("' directory");
  +            throw new NNTPException(exceptionBuffer.toString());
  +        }
  +        if ( f.exists() == false ) {
               f.mkdirs();
  +        }
           return f;
       }
       public static Object createInstance(Context context, 
  @@ -72,10 +89,17 @@
       }
   
       public static void show(Configuration conf,PrintStream prt) {
  -        prt.println("conf.getClass="+conf.getClass().getName());
  -        prt.println("name="+conf.getName());
  +        prt.println("conf.getClass=" + conf.getClass().getName());
  +        prt.println("name=" + conf.getName());
           Configuration[] children = conf.getChildren();
  -        for ( int i = 0 ; i < children.length ; i++ )
  -            prt.println(i+". "+children[i].getName());
  +        for ( int i = 0 ; i < children.length ; i++ ) {
  +            
  +            StringBuffer showBuffer =
  +                new StringBuffer(64)
  +                        .append(i)
  +                        .append(". ")
  +                        .append(children[i].getName());
  +            prt.println(showBuffer.toString());
  +        }
       }
   }
  
  
  
  1.7       +8 -3      jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
  
  Index: NNTPRepositoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NNTPRepositoryImpl.java	3 Jun 2002 16:07:06 -0000	1.6
  +++ NNTPRepositoryImpl.java	7 Aug 2002 23:38:48 -0000	1.7
  @@ -55,7 +55,7 @@
       }
   
       public void configure( Configuration configuration ) throws ConfigurationException {
  -        //System.out.println(getClass().getName()+": configure");
  +        //System.out.println(getClass().getName() + ": configure");
           //NNTPUtil.show(configuration,System.out);
           readOnly = configuration.getChild("readOnly").getValueAsBoolean(false);
           rootPath = NNTPUtil.getDirectory(context, configuration, "rootPath");
  @@ -84,7 +84,7 @@
           getLogger().debug("repository configuration done");
       }
       public void initialize() throws Exception {
  -        //System.out.println(getClass().getName()+": init");
  +        //System.out.println(getClass().getName() + ": init");
           if ( rootPath.exists() == false )
               rootPath.mkdirs();
           for ( int i = 0 ; i < addGroups.length ; i++ ) {
  @@ -122,7 +122,12 @@
   //         return ( group == null ) ? null : group.getArticleFromID(name);
       }
       public void createArticle(NNTPLineReader reader) {
  -        File f = new File(tempPath,System.currentTimeMillis()+"."+Math.random());
  +        StringBuffer fileBuffer =
  +            new StringBuffer(32)
  +                    .append(System.currentTimeMillis())
  +                    .append(".")
  +                    .append(Math.random());
  +        File f = new File(tempPath, fileBuffer.toString());
           try {
               FileOutputStream fout = new FileOutputStream(f);
               PrintStream prt = new PrintStream(fout,true);
  
  
  
  1.5       +2 -2      jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java
  
  Index: NNTPGroupImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NNTPGroupImpl.java	18 Jan 2002 02:48:36 -0000	1.4
  +++ NNTPGroupImpl.java	7 Aug 2002 23:38:48 -0000	1.5
  @@ -90,7 +90,7 @@
           return getArticle(getCurrentArticleNumber());
       }
       public NNTPArticle getArticle(int number) {
  -        File f = new File(root,number+"");
  +        File f = new File(root,number + "");
           return f.exists() ? new NNTPArticleImpl(f) : null;
       }
   //     public NNTPArticle getArticleFromID(String id) {
  @@ -99,7 +99,7 @@
   //         int idx = id.indexOf('@');
   //         if ( idx != -1 )
   //             id = id.substring(0,idx);
  -//         File f = new File(root,id+".id");
  +//         File f = new File(root,id + ".id");
   //         if ( f.exists() == false )
   //             return null;
   //         try {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>