Mercurial Hosting > luan
annotate src/org/eclipse/jetty/util/resource/Resource.java @ 1011:4e7208df7741
remove PooledBuffers
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 23 Oct 2016 23:59:08 -0600 |
parents | 7c737c376bc3 |
children | 6939226e0ac4 |
rev | line source |
---|---|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.util.resource; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import java.io.File; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import java.io.FileOutputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.io.IOException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.io.InputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.io.OutputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import java.net.MalformedURLException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import java.net.URI; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import java.net.URL; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 import java.net.URLConnection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import java.text.DateFormat; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 import java.util.Arrays; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import java.util.Date; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import org.eclipse.jetty.util.IO; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import org.eclipse.jetty.util.StringUtil; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 import org.eclipse.jetty.util.URIUtil; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
37 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
38 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 /* ------------------------------------------------------------ */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 * Abstract resource class. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 public abstract class Resource implements ResourceFactory |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 { |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
47 private static final Logger LOG = LoggerFactory.getLogger(Resource.class); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
48 public static boolean __defaultUseCaches = true; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
49 volatile Object _associate; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
51 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
52 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
53 * Change the default setting for url connection caches. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
54 * Subsequent URLConnections will use this default. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
55 * @param useCaches |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
56 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
57 public static void setDefaultUseCaches (boolean useCaches) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
58 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
59 __defaultUseCaches=useCaches; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
60 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
61 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
62 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
63 public static boolean getDefaultUseCaches () |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
64 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
65 return __defaultUseCaches; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
66 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
67 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
68 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
69 /** Construct a resource from a uri. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
70 * @param uri A URI. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
71 * @return A Resource object. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
72 * @throws IOException Problem accessing URI |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
73 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
74 public static Resource newResource(URI uri) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
75 throws IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
76 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
77 return newResource(uri.toURL()); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
78 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
79 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
80 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
81 /** Construct a resource from a url. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
82 * @param url A URL. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
83 * @return A Resource object. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
84 * @throws IOException Problem accessing URL |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
85 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
86 public static Resource newResource(URL url) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
87 throws IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
88 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
89 return newResource(url, __defaultUseCaches); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
90 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
91 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
92 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
93 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
94 * Construct a resource from a url. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
95 * @param url the url for which to make the resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
96 * @param useCaches true enables URLConnection caching if applicable to the type of resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
97 * @return |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
98 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
99 static Resource newResource(URL url, boolean useCaches) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
100 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
101 if (url==null) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
102 return null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
103 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
104 String url_string=url.toExternalForm(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
105 if( url_string.startsWith( "file:")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
106 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
107 try |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
108 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
109 FileResource fileResource= new FileResource(url); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
110 return fileResource; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
111 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
112 catch(Exception e) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
113 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
114 LOG.debug("EXCEPTION",e); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
115 return new BadResource(url,e.toString()); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
116 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
117 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
118 else if( url_string.startsWith( "jar:file:")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
119 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
120 return new JarFileResource(url, useCaches); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
121 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
122 else if( url_string.startsWith( "jar:")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
123 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
124 return new JarResource(url, useCaches); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
125 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
126 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
127 return new URLResource(url,null,useCaches); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
128 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
129 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
130 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
131 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
132 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
133 /** Construct a resource from a string. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
134 * @param resource A URL or filename. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
135 * @return A Resource object. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
136 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
137 public static Resource newResource(String resource) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
138 throws MalformedURLException, IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
139 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
140 return newResource(resource, __defaultUseCaches); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
141 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
142 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
143 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
144 /** Construct a resource from a string. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
145 * @param resource A URL or filename. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
146 * @param useCaches controls URLConnection caching |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
147 * @return A Resource object. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
148 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
149 public static Resource newResource (String resource, boolean useCaches) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
150 throws MalformedURLException, IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
151 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
152 URL url=null; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
153 try |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
154 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
155 // Try to format as a URL? |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
156 url = new URL(resource); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
157 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
158 catch(MalformedURLException e) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
159 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
160 if(!resource.startsWith("ftp:") && |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
161 !resource.startsWith("file:") && |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
162 !resource.startsWith("jar:")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
163 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
164 try |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
165 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
166 // It's a file. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
167 if (resource.startsWith("./")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
168 resource=resource.substring(2); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
169 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
170 File file=new File(resource).getCanonicalFile(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
171 url=Resource.toURL(file); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
172 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
173 URLConnection connection=url.openConnection(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
174 connection.setUseCaches(useCaches); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
175 return new FileResource(url,connection,file); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
176 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
177 catch(Exception e2) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
178 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
179 LOG.debug("EXCEPTION",e2); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
180 throw e; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
181 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
182 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
183 else |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
184 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
185 LOG.warn("Bad Resource: "+resource); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
186 throw e; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
187 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
188 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
189 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
190 return newResource(url); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
191 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
192 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
193 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
194 public static Resource newResource (File file) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
195 throws MalformedURLException, IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
196 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
197 file = file.getCanonicalFile(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
198 URL url = Resource.toURL(file); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
199 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
200 URLConnection connection = url.openConnection(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
201 FileResource fileResource = new FileResource(url, connection, file); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
202 return fileResource; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
203 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
204 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
205 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
206 /** Construct a system resource from a string. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
207 * The resource is tried as classloader resource before being |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
208 * treated as a normal resource. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
209 * @param resource Resource as string representation |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
210 * @return The new Resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
211 * @throws IOException Problem accessing resource. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
212 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
213 public static Resource newSystemResource(String resource) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
214 throws IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
215 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
216 URL url=null; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
217 // Try to format as a URL? |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
218 ClassLoader loader=Thread.currentThread().getContextClassLoader(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
219 if (loader!=null) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
220 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
221 try |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
222 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
223 url = loader.getResource(resource); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
224 if (url == null && resource.startsWith("/")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
225 url = loader.getResource(resource.substring(1)); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
226 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
227 catch (IllegalArgumentException e) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
228 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
229 // Catches scenario where a bad Windows path like "C:\dev" is |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
230 // improperly escaped, which various downstream classloaders |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
231 // tend to have a problem with |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
232 url = null; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
233 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
234 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
235 if (url==null) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
236 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
237 loader=Resource.class.getClassLoader(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
238 if (loader!=null) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
239 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
240 url=loader.getResource(resource); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
241 if (url==null && resource.startsWith("/")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
242 url=loader.getResource(resource.substring(1)); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
243 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
244 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
245 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
246 if (url==null) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
247 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
248 url=ClassLoader.getSystemResource(resource); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
249 if (url==null && resource.startsWith("/")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
250 url=ClassLoader.getSystemResource(resource.substring(1)); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
251 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
252 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
253 if (url==null) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
254 return null; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
255 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
256 return newResource(url); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
257 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
258 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
259 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
260 public static boolean isContainedIn (Resource r, Resource containingResource) throws MalformedURLException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
261 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
262 return r.isContainedIn(containingResource); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
263 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
264 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
265 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
266 @Override |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
267 protected void finalize() |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
268 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
269 release(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
270 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
271 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
272 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
273 public abstract boolean isContainedIn (Resource r) throws MalformedURLException; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
274 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
275 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
276 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
277 /** Release any temporary resources held by the resource. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
278 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
279 public abstract void release(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
280 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
281 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
282 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
283 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
284 * Returns true if the respresened resource exists. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
285 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
286 public abstract boolean exists(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
287 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
288 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
289 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
290 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
291 * Returns true if the respresenetd resource is a container/directory. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
292 * If the resource is not a file, resources ending with "/" are |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
293 * considered directories. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
294 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
295 public abstract boolean isDirectory(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
296 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
297 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
298 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
299 * Returns the last modified time |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
300 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
301 public abstract long lastModified(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
302 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
303 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
304 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
305 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
306 * Return the length of the resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
307 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
308 public abstract long length(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
309 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
310 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
311 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
312 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
313 * Returns an URL representing the given resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
314 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
315 public abstract URL getURL(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
316 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
317 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
318 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
319 * Returns an URI representing the given resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
320 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
321 public URI getURI() |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
322 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
323 try |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
324 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
325 return getURL().toURI(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
326 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
327 catch(Exception e) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
328 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
329 throw new RuntimeException(e); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
330 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
331 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
332 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
333 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
334 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
335 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
336 * Returns an File representing the given resource or NULL if this |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
337 * is not possible. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
338 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
339 public abstract File getFile() |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
340 throws IOException; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
341 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
342 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
343 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
344 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
345 * Returns the name of the resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
346 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
347 public abstract String getName(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
348 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
349 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
350 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
351 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
352 * Returns an input stream to the resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
353 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
354 public abstract InputStream getInputStream() |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
355 throws java.io.IOException; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
356 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
357 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
358 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
359 * Returns an output stream to the resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
360 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
361 public abstract OutputStream getOutputStream() |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
362 throws java.io.IOException, SecurityException; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
363 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
364 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
365 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
366 * Deletes the given resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
367 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
368 public abstract boolean delete() |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
369 throws SecurityException; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
370 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
371 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
372 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
373 * Rename the given resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
374 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
375 public abstract boolean renameTo( Resource dest) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
376 throws SecurityException; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
377 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
378 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
379 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
380 * Returns a list of resource names contained in the given resource |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
381 * The resource names are not URL encoded. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
382 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
383 public abstract String[] list(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
384 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
385 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
386 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
387 * Returns the resource contained inside the current resource with the |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
388 * given name. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
389 * @param path The path segment to add, which should be encoded by the |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
390 * encode method. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
391 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
392 public abstract Resource addPath(String path) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
393 throws IOException,MalformedURLException; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
394 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
395 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
396 /** Get a resource from withing this resource. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
397 * <p> |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
398 * This method is essentially an alias for {@link #addPath(String)}, but without checked exceptions. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
399 * This method satisfied the {@link ResourceFactory} interface. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
400 * @see org.eclipse.jetty.util.resource.ResourceFactory#getResource(java.lang.String) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
401 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
402 public Resource getResource(String path) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
403 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
404 try |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
405 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
406 return addPath(path); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
407 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
408 catch(Exception e) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
409 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
410 LOG.debug("",e); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
411 return null; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
412 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
413 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
414 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
415 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
416 /** Encode according to this resource type. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
417 * The default implementation calls URI.encodePath(uri) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
418 * @param uri |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
419 * @return String encoded for this resource type. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
420 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
421 public String encode(String uri) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
422 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
423 return URIUtil.encodePath(uri); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
424 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
425 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
426 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
427 public Object getAssociate() |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
428 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
429 return _associate; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
430 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
431 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
432 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
433 public void setAssociate(Object o) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
434 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
435 _associate=o; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
436 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
437 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
438 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
439 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
440 * @return The canonical Alias of this resource or null if none. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
441 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
442 public URL getAlias() |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
443 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
444 return null; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
445 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
446 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
447 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
448 /** Get the resource list as a HTML directory listing. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
449 * @param base The base URL |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
450 * @param parent True if the parent directory should be included |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
451 * @return String of HTML |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
452 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
453 public String getListHTML(String base,boolean parent) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
454 throws IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
455 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
456 base=URIUtil.canonicalPath(base); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
457 if (base==null || !isDirectory()) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
458 return null; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
459 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
460 String[] ls = list(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
461 if (ls==null) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
462 return null; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
463 Arrays.sort(ls); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
464 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
465 String decodedBase = URIUtil.decodePath(base); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
466 String title = "Directory: "+deTag(decodedBase); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
467 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
468 StringBuilder buf=new StringBuilder(4096); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
469 buf.append("<HTML><HEAD>"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
470 buf.append("<LINK HREF=\"").append("jetty-dir.css").append("\" REL=\"stylesheet\" TYPE=\"text/css\"/><TITLE>"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
471 buf.append(title); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
472 buf.append("</TITLE></HEAD><BODY>\n<H1>"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
473 buf.append(title); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
474 buf.append("</H1>\n<TABLE BORDER=0>\n"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
475 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
476 if (parent) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
477 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
478 buf.append("<TR><TD><A HREF=\""); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
479 buf.append(URIUtil.addPaths(base,"../")); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
480 buf.append("\">Parent Directory</A></TD><TD></TD><TD></TD></TR>\n"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
481 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
482 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
483 String encodedBase = hrefEncodeURI(base); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
484 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
485 DateFormat dfmt=DateFormat.getDateTimeInstance(DateFormat.MEDIUM, |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
486 DateFormat.MEDIUM); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
487 for (int i=0 ; i< ls.length ; i++) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
488 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
489 Resource item = addPath(ls[i]); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
490 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
491 buf.append("\n<TR><TD><A HREF=\""); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
492 String path=URIUtil.addPaths(encodedBase,URIUtil.encodePath(ls[i])); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
493 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
494 buf.append(path); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
495 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
496 if (item.isDirectory() && !path.endsWith("/")) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
497 buf.append(URIUtil.SLASH); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
498 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
499 // URIUtil.encodePath(buf,path); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
500 buf.append("\">"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
501 buf.append(deTag(ls[i])); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
502 buf.append(" "); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
503 buf.append("</A></TD><TD ALIGN=right>"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
504 buf.append(item.length()); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
505 buf.append(" bytes </TD><TD>"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
506 buf.append(dfmt.format(new Date(item.lastModified()))); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
507 buf.append("</TD></TR>"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
508 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
509 buf.append("</TABLE>\n"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
510 buf.append("</BODY></HTML>\n"); |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
511 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
512 return buf.toString(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
513 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
514 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
515 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
516 * Encode any characters that could break the URI string in an HREF. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
517 * Such as <a href="/path/to;<script>Window.alert("XSS"+'%20'+"here");</script>">Link</a> |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
518 * |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
519 * The above example would parse incorrectly on various browsers as the "<" or '"' characters |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
520 * would end the href attribute value string prematurely. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
521 * |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
522 * @param raw the raw text to encode. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
523 * @return the defanged text. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
524 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
525 private static String hrefEncodeURI(String raw) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
526 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
527 StringBuffer buf = null; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
528 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
529 loop: |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
530 for (int i=0;i<raw.length();i++) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
531 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
532 char c=raw.charAt(i); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
533 switch(c) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
534 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
535 case '\'': |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
536 case '"': |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
537 case '<': |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
538 case '>': |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
539 buf=new StringBuffer(raw.length()<<1); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
540 break loop; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
541 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
542 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
543 if (buf==null) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
544 return raw; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
545 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
546 for (int i=0;i<raw.length();i++) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
547 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
548 char c=raw.charAt(i); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
549 switch(c) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
550 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
551 case '"': |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
552 buf.append("%22"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
553 continue; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
554 case '\'': |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
555 buf.append("%27"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
556 continue; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
557 case '<': |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
558 buf.append("%3C"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
559 continue; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
560 case '>': |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
561 buf.append("%3E"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
562 continue; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
563 default: |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
564 buf.append(c); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
565 continue; |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
566 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
567 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
568 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
569 return buf.toString(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
570 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
571 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
572 private static String deTag(String raw) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
573 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
574 return StringUtil.replace( StringUtil.replace(raw,"<","<"), ">", ">"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
575 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
576 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
577 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
578 /** |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
579 * @param out |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
580 * @param start First byte to write |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
581 * @param count Bytes to write or -1 for all of them. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
582 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
583 public void writeTo(OutputStream out,long start,long count) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
584 throws IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
585 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
586 InputStream in = getInputStream(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
587 try |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
588 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
589 in.skip(start); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
590 if (count<0) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
591 IO.copy(in,out); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
592 else |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
593 IO.copy(in,out,count); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
594 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
595 finally |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
596 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
597 in.close(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
598 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
599 } |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
600 |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
601 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
602 public void copyTo(File destination) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
603 throws IOException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
604 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
605 if (destination.exists()) |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
606 throw new IllegalArgumentException(destination+" exists"); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
607 writeTo(new FileOutputStream(destination),0,-1); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
608 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
609 |
825
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
610 /* ------------------------------------------------------------ */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
611 /** Generate a properly encoded URL from a {@link File} instance. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
612 * @param file Target file. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
613 * @return URL of the target file. |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
614 * @throws MalformedURLException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
615 */ |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
616 public static URL toURL(File file) throws MalformedURLException |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
617 { |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
618 return file.toURI().toURL(); |
7fb7c1915788
remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
619 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
620 } |