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/10/04 05:38:52 UTC
cvs commit: jakarta-james/src/java/org/apache/james/context AvalonContextUtilities.java AvalonContextConstants.java
pgoldstein 2002/10/03 20:38:52
Modified: src/java/org/apache/james/context
AvalonContextConstants.java
Added: src/java/org/apache/james/context
AvalonContextUtilities.java
Log:
Adding the license to AvalonContextConstants.
Adding another class to localize File lookup logic.
Revision Changes Path
1.2 +7 -0 jakarta-james/src/java/org/apache/james/context/AvalonContextConstants.java
Index: AvalonContextConstants.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/context/AvalonContextConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AvalonContextConstants.java 14 Aug 2002 02:11:00 -0000 1.1
+++ AvalonContextConstants.java 4 Oct 2002 03:38:52 -0000 1.2
@@ -1,3 +1,10 @@
+/*
+ * Copyright (C) The Apache Software Foundation. All rights reserved.
+ *
+ * This software is published under the terms of the Apache Software License
+ * version 1.1, a copy of which has been included with this distribution in
+ * the LICENSE file.
+ */
package org.apache.james.context;
/**
1.1 jakarta-james/src/java/org/apache/james/context/AvalonContextUtilities.java
Index: AvalonContextUtilities.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.james.context;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import java.io.File;
import java.io.IOException;
/**
* This class is essentially a set of static functions for
* extracting information from the Avalon context. This class
* should never be instantiated. Each function takes the context
* as a first argument.
*/
public class AvalonContextUtilities {
/**
* The file URL prefix
*/
private static String filePrefix = "file://";
/**
* The file URL prefix length
*/
private static int filePrefixLength = filePrefix.length();
/**
* Gets the file or directory described by the argument file URL.
*
* @param context the Avalon context
* @param fileURL an appropriately formatted URL describing a file on
* the filesystem on which the server is running. The
* URL is evaluated as a location relative to the
* application home, unless it begins with a slash. In
* the latter case the file location is evaluated relative
* to the underlying file system root.
*
* @throws IllegalArgumentException if the arguments are null or the file
* URL is not appropriately formatted.
* @throws ContextException if the underlying context generates a
* ContextException, if the application home is
* not correct, or if an IOException is generated
* while accessing the file.
*/
public static File getFile(Context context, String fileURL)
throws Exception {
if ((context == null) || (fileURL == null)) {
throw new IllegalArgumentException("The getFile method doesn't allow null arguments.");
}
String internalFileURL = fileURL.trim();
if (!(internalFileURL.startsWith(filePrefix))) {
throw new IllegalArgumentException("The fileURL argument to getFile doesn't start with the required file prefix - " + filePrefix);
}
String fileName = fileURL.substring(filePrefixLength);
if (!(fileName.startsWith("/"))) {
String baseDirectory = "";
try {
File applicationHome =
(File)context.get(AvalonContextConstants.APPLICATION_HOME);
baseDirectory = applicationHome.toString();
} catch (ContextException ce) {
throw new ContextException("Encountered exception when resolving application home in Avalon context.", ce);
} catch (ClassCastException cce) {
throw new ContextException("Application home object stored in Avalon context was not of type java.io.File.", cce);
}
StringBuffer fileNameBuffer =
new StringBuffer(128)
.append(baseDirectory)
.append(File.separator)
.append(fileName);
fileName = fileNameBuffer.toString();
}
try {
File returnValue = (new File(fileName)).getCanonicalFile();
return returnValue;
} catch (IOException ioe) {
throw new ContextException("Encountered an unexpected exception while retrieving file.", ioe);
}
}
/**
* Private constructor to ensure that instances of this class aren't
* instantiated.
*/
private AvalonContextUtilities() {};
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>