350634 Cleanup FileResource construction

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@3434 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Michael Gorovoy 2011-06-29 00:59:41 +00:00
parent 0b9f348132
commit 95ff9d73f0
4 changed files with 32 additions and 45 deletions

View File

@ -16,8 +16,9 @@ jetty-7.4.3-SNAPSHOT
+ 349896 SCEP supports zero maxIdleTime
+ 349897 draft -09 websockets
+ 349997 MBeanContainer uses weak references
+ JETTY-1342 Recreate selector in change task
+ 350533 Add "Origin" to the list of allowed headers in CrossOriginFilter
+ 350634 Cleanup FileResource construction
+ JETTY-1342 Recreate selector in change task
jetty-7.4.2.v20110526
+ 334443 Improve the ability to specify extra class paths using the Jetty Maven Plugin

View File

@ -66,6 +66,16 @@ public class FileResource extends URLResource
{
return __checkAliases;
}
/* -------------------------------------------------------- */
public FileResource(File file) throws MalformedURLException
{
super(file.toURI().toURL(),null);
_file=file;
fixUrlString();
}
/* -------------------------------------------------------- */
public FileResource(URL url)
@ -73,35 +83,24 @@ public class FileResource extends URLResource
{
super(url,null);
try
{
// Try standard API to convert URL to file.
_file =new File(new URI(url.toString()));
}
catch (Exception e)
{
Log.ignore(e);
try
{
// Assume that File.toURL produced unencoded chars. So try
// encoding them.
String file_url="file:"+URIUtil.encodePath(url.toString().substring(5));
URI uri = new URI(file_url);
if (uri.getAuthority()==null)
_file = new File(uri);
else
_file = new File("//"+uri.getAuthority()+URIUtil.decodePath(url.getFile()));
}
catch (Exception e2)
{
Log.ignore(e2);
_file =new File(url.toURI());
// Still can't get the file. Doh! try good old hack!
checkConnection();
Permission perm = _connection.getPermission();
_file = new File(perm==null?url.getFile():perm.getName());
}
}
fixUrlString();
}
/* -------------------------------------------------------- */
FileResource(URL url, URLConnection connection, File file)
{
super(url,connection);
_file=file;
fixUrlString();
}
/* -------------------------------------------------------- */
private void fixUrlString()
{
if (_file.isDirectory())
{
if (!_urlString.endsWith("/"))
@ -112,16 +111,6 @@ public class FileResource extends URLResource
if (_urlString.endsWith("/"))
_urlString=_urlString.substring(0,_urlString.length()-1);
}
}
/* -------------------------------------------------------- */
FileResource(URL url, URLConnection connection, File file)
{
super(url,connection);
_file=file;
if (_file.isDirectory() && !_urlString.endsWith("/"))
_urlString=_urlString+"/";
}
/* -------------------------------------------------------- */

View File

@ -160,12 +160,7 @@ public abstract class Resource implements ResourceFactory
resource=resource.substring(2);
File file=new File(resource).getCanonicalFile();
url=file.toURI().toURL();
URLConnection connection=url.openConnection();
connection.setUseCaches(useCaches);
FileResource fileResource= new FileResource(url,connection,file);
return fileResource;
return new FileResource(file);
}
catch(Exception e2)
{

View File

@ -120,9 +120,11 @@ public class ResourceTest
__userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar;
__relDir = "src/test/java/org/eclipse/jetty/util/resource/".replace('/', File.separatorChar);
/*
System.err.println("User Dir="+__userDir);
System.err.println("Rel Dir="+__relDir);
System.err.println("User URL="+__userURL);
*/
tmpFile=File.createTempFile("test",null).getCanonicalFile();
tmpFile.deleteOnExit();