annotate src/org/eclipse/jetty/util/resource/Resource.java @ 827:f89abbfb3a8f

remove Resource.getWeakETag()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 15 Sep 2016 16:21:56 -0600
parents 7fb7c1915788
children 7c737c376bc3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.Loader;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import org.eclipse.jetty.util.StringUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 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
38 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
39 import org.slf4j.LoggerFactory;
802
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 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 * Abstract resource class.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 public abstract class Resource implements ResourceFactory
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 {
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
48 private static final Logger LOG = LoggerFactory.getLogger(Resource.class);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
49 public static boolean __defaultUseCaches = true;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
50 volatile Object _associate;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54 * Change the default setting for url connection caches.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
55 * Subsequent URLConnections will use this default.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 * @param useCaches
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 public static void setDefaultUseCaches (boolean useCaches)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
59 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 __defaultUseCaches=useCaches;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 public static boolean getDefaultUseCaches ()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 return __defaultUseCaches;
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 /** Construct a resource from a uri.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 * @param uri A URI.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 * @return A Resource object.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 * @throws IOException Problem accessing URI
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 public static Resource newResource(URI uri)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 return newResource(uri.toURL());
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 /** Construct a resource from a url.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 * @param url A URL.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 * @return A Resource object.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 * @throws IOException Problem accessing URL
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 public static Resource newResource(URL url)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 return newResource(url, __defaultUseCaches);
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 * Construct a resource from a url.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 * @param url the url for which to make the resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 * @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
98 * @return
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 static Resource newResource(URL url, boolean useCaches)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 return null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 String url_string=url.toExternalForm();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 if( url_string.startsWith( "file:"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 FileResource fileResource= new FileResource(url);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 return fileResource;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 catch(Exception e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 LOG.debug("EXCEPTION",e);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 return new BadResource(url,e.toString());
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 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 else if( url_string.startsWith( "jar:file:"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 return new JarFileResource(url, useCaches);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 else if( url_string.startsWith( "jar:"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 return new JarResource(url, useCaches);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 return new URLResource(url,null,useCaches);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130
825
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 /** Construct a resource from a string.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 * @param resource A URL or filename.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 * @return A Resource object.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 public static Resource newResource(String resource)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 throws MalformedURLException, IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 return newResource(resource, __defaultUseCaches);
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 /** Construct a resource from a string.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 * @param resource A URL or filename.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 * @param useCaches controls URLConnection caching
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 * @return A Resource object.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 public static Resource newResource (String resource, boolean useCaches)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 throws MalformedURLException, IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 URL url=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 // Try to format as a URL?
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 url = new URL(resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 catch(MalformedURLException e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 if(!resource.startsWith("ftp:") &&
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 !resource.startsWith("file:") &&
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 !resource.startsWith("jar:"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 // It's a file.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 if (resource.startsWith("./"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 resource=resource.substring(2);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 File file=new File(resource).getCanonicalFile();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 url=Resource.toURL(file);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 URLConnection connection=url.openConnection();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 connection.setUseCaches(useCaches);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 return new FileResource(url,connection,file);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 catch(Exception e2)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 LOG.debug("EXCEPTION",e2);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 throw e;
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 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 LOG.warn("Bad Resource: "+resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 throw e;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 return newResource(url);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 public static Resource newResource (File file)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 throws MalformedURLException, IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 file = file.getCanonicalFile();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 URL url = Resource.toURL(file);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
200
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 URLConnection connection = url.openConnection();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 FileResource fileResource = new FileResource(url, connection, file);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 return fileResource;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 /** Construct a system resource from a string.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 * The resource is tried as classloader resource before being
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 * treated as a normal resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 * @param resource Resource as string representation
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 * @return The new Resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 * @throws IOException Problem accessing resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 public static Resource newSystemResource(String resource)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 URL url=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 // Try to format as a URL?
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 ClassLoader loader=Thread.currentThread().getContextClassLoader();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 if (loader!=null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 url = loader.getResource(resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 if (url == null && resource.startsWith("/"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 url = loader.getResource(resource.substring(1));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 catch (IllegalArgumentException e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 // 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
231 // improperly escaped, which various downstream classloaders
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 // tend to have a problem with
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 url = null;
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 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 loader=Resource.class.getClassLoader();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 if (loader!=null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 url=loader.getResource(resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 if (url==null && resource.startsWith("/"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 url=loader.getResource(resource.substring(1));
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 url=ClassLoader.getSystemResource(resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 if (url==null && resource.startsWith("/"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 url=ClassLoader.getSystemResource(resource.substring(1));
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 return newResource(url);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 /** Find a classpath resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 public static Resource newClassPathResource(String resource)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 return newClassPathResource(resource,true,false);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267
825
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 /** Find a classpath resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 * The {@link java.lang.Class#getResource(String)} method is used to lookup the resource. If it is not
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 * found, then the {@link Loader#getResource(Class, String, boolean)} method is used.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 * If it is still not found, then {@link ClassLoader#getSystemResource(String)} is used.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 * Unlike {@link ClassLoader#getSystemResource(String)} this method does not check for normal resources.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 * @param name The relative name of the resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 * @param useCaches True if URL caches are to be used.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 * @param checkParents True if forced searching of parent Classloaders is performed to work around
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 * loaders with inverted priorities
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 * @return Resource or null
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 public static Resource newClassPathResource(String name,boolean useCaches,boolean checkParents)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 URL url=Resource.class.getResource(name);
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 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 url=Loader.getResource(Resource.class,name,checkParents);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 return newResource(url,useCaches);
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 public static boolean isContainedIn (Resource r, Resource containingResource) throws MalformedURLException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 return r.isContainedIn(containingResource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 }
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 @Override
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 protected void finalize()
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 release();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303
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 public abstract boolean isContainedIn (Resource r) throws MalformedURLException;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 /** Release any temporary resources held by the resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 public abstract void release();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
313
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 * Returns true if the respresened resource exists.
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 public abstract boolean exists();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
320
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 /* ------------------------------------------------------------ */
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 * Returns true if the respresenetd resource is a container/directory.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 * 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
325 * considered directories.
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 public abstract boolean isDirectory();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
328
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 /* ------------------------------------------------------------ */
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 * Returns the last modified time
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 public abstract long lastModified();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
334
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
335
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 * Return the length of the resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 public abstract long length();
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 an URL representing the given 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 URL getURL();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
348
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 /* ------------------------------------------------------------ */
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 * Returns an URI representing the given resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 public URI getURI()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 return getURL().toURI();
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 catch(Exception e)
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 throw new RuntimeException(e);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 }
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
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
365
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 /* ------------------------------------------------------------ */
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 * 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
369 * is not possible.
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 public abstract File getFile()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 throws IOException;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
374
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 * Returns the name of the resource
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 public abstract String getName();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
381
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 * Returns an input stream to the resource
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 public abstract InputStream getInputStream()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 throws java.io.IOException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
388
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 * Returns an output stream to the resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 public abstract OutputStream getOutputStream()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 throws java.io.IOException, SecurityException;
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 * Deletes the given resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 public abstract boolean delete()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 throws SecurityException;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 * Rename the given resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 public abstract boolean renameTo( Resource dest)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 throws SecurityException;
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 * 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
413 * The resource names are not URL encoded.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
415 public abstract String[] list();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
416
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 * Returns the resource contained inside the current resource with the
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 * given name.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 * @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
422 * encode method.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 public abstract Resource addPath(String path)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 throws IOException,MalformedURLException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
426
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 /** Get a resource from withing this resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 * <p>
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 * 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
431 * This method satisfied the {@link ResourceFactory} interface.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 * @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
433 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 public Resource getResource(String path)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 try
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 return addPath(path);
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 catch(Exception e)
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 LOG.debug("",e);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
446
825
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 /** Encode according to this resource type.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 * The default implementation calls URI.encodePath(uri)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 * @param uri
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 * @return String encoded for this resource type.
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 encode(String uri)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 return URIUtil.encodePath(uri);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 public Object getAssociate()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 return _associate;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
463
825
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 public void setAssociate(Object o)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 _associate=o;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 * @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
473 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 public URL getAlias()
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 return null;
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 /** Get the resource list as a HTML directory listing.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 * @param base The base URL
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 * @param parent True if the parent directory should be included
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 * @return String of HTML
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 public String getListHTML(String base,boolean parent)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 base=URIUtil.canonicalPath(base);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 if (base==null || !isDirectory())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 String[] ls = list();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 if (ls==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 Arrays.sort(ls);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 String decodedBase = URIUtil.decodePath(base);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 String title = "Directory: "+deTag(decodedBase);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
499
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 StringBuilder buf=new StringBuilder(4096);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 buf.append("<HTML><HEAD>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 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
503 buf.append(title);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 buf.append("</TITLE></HEAD><BODY>\n<H1>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 buf.append(title);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 buf.append("</H1>\n<TABLE BORDER=0>\n");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 if (parent)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 buf.append("<TR><TD><A HREF=\"");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 buf.append(URIUtil.addPaths(base,"../"));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 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
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 String encodedBase = hrefEncodeURI(base);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 DateFormat dfmt=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 DateFormat.MEDIUM);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 for (int i=0 ; i< ls.length ; i++)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 Resource item = addPath(ls[i]);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 buf.append("\n<TR><TD><A HREF=\"");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 String path=URIUtil.addPaths(encodedBase,URIUtil.encodePath(ls[i]));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 buf.append(path);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 if (item.isDirectory() && !path.endsWith("/"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 buf.append(URIUtil.SLASH);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 // URIUtil.encodePath(buf,path);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 buf.append("\">");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 buf.append(deTag(ls[i]));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 buf.append("&nbsp;");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 buf.append("</A></TD><TD ALIGN=right>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 buf.append(item.length());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 buf.append(" bytes&nbsp;</TD><TD>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 buf.append(dfmt.format(new Date(item.lastModified())));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 buf.append("</TD></TR>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 buf.append("</TABLE>\n");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
542 buf.append("</BODY></HTML>\n");
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 return buf.toString();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546
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 * 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
549 * 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
550 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 * 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
552 * would end the href attribute value string prematurely.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 * @param raw the raw text to encode.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 * @return the defanged text.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 private static String hrefEncodeURI(String raw)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 StringBuffer buf = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
560
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 loop:
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 for (int i=0;i<raw.length();i++)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 char c=raw.charAt(i);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 switch(c)
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 case '\'':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 case '"':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 case '<':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 case '>':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 buf=new StringBuffer(raw.length()<<1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 break loop;
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 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 if (buf==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 return raw;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
577
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 for (int i=0;i<raw.length();i++)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 char c=raw.charAt(i);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 switch(c)
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 case '"':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 buf.append("%22");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 case '\'':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 buf.append("%27");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 case '<':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 buf.append("%3C");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 case '>':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 buf.append("%3E");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 default:
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 buf.append(c);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 continue;
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
600
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 return buf.toString();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 private static String deTag(String raw)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 return StringUtil.replace( StringUtil.replace(raw,"<","&lt;"), ">", "&gt;");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 /* ------------------------------------------------------------ */
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 * @param out
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 * @param start First byte to write
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 * @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
614 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 public void writeTo(OutputStream out,long start,long count)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 throws IOException
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 InputStream in = getInputStream();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 in.skip(start);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 if (count<0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 IO.copy(in,out);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 IO.copy(in,out,count);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 finally
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 in.close();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634 public void copyTo(File destination)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 if (destination.exists())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 throw new IllegalArgumentException(destination+" exists");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 writeTo(new FileOutputStream(destination),0,-1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
641
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 /** Generate a properly encoded URL from a {@link File} instance.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 * @param file Target file.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 * @return URL of the target file.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 * @throws MalformedURLException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 public static URL toURL(File file) throws MalformedURLException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 return file.toURI().toURL();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
652 }