annotate src/org/eclipse/jetty/util/resource/Resource.java @ 825:7fb7c1915788

remove jetty.util.B64Code
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 14 Sep 2016 16:38:33 -0600
parents 8e9db0bbf4f9
children f89abbfb3a8f
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
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
34 import java.util.Base64;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import org.eclipse.jetty.util.IO;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import org.eclipse.jetty.util.Loader;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 import org.eclipse.jetty.util.StringUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 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
39 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
40 import org.slf4j.LoggerFactory;
802
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 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 * Abstract resource class.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 public abstract class Resource implements ResourceFactory
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 {
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
49 private static final Logger LOG = LoggerFactory.getLogger(Resource.class);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
50 public static boolean __defaultUseCaches = true;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
51 volatile Object _associate;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
55 * Change the default setting for url connection caches.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 * Subsequent URLConnections will use this default.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 * @param 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 public static void setDefaultUseCaches (boolean useCaches)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 __defaultUseCaches=useCaches;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63
825
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 public static boolean getDefaultUseCaches ()
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 return __defaultUseCaches;
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 /** Construct a resource from a uri.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 * @param uri A URI.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 * @return A Resource object.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 * @throws IOException Problem accessing URI
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 public static Resource newResource(URI uri)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 throws IOException
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 return newResource(uri.toURL());
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 /** Construct a resource from a url.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 * @param url A URL.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 * @return A Resource object.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 * @throws IOException Problem accessing URL
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 public static Resource newResource(URL url)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 throws IOException
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 return newResource(url, __defaultUseCaches);
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 * Construct a resource from a url.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 * @param url the url for which to make the resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 * @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
99 * @return
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 static Resource newResource(URL url, boolean useCaches)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 return null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 String url_string=url.toExternalForm();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 if( url_string.startsWith( "file:"))
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 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 FileResource fileResource= new FileResource(url);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 return fileResource;
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 catch(Exception e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 LOG.debug("EXCEPTION",e);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 return new BadResource(url,e.toString());
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 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 else if( url_string.startsWith( "jar:file:"))
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 return new JarFileResource(url, useCaches);
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 else if( url_string.startsWith( "jar:"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 return new JarResource(url, useCaches);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 return new URLResource(url,null,useCaches);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131
825
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 /** Construct a resource from a string.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 * @param resource A URL or filename.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 * @return A Resource object.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 public static Resource newResource(String resource)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 throws MalformedURLException, IOException
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 return newResource(resource, __defaultUseCaches);
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 /** Construct a resource from a string.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 * @param resource A URL or filename.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 * @param useCaches controls URLConnection caching
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 * @return A Resource object.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 public static Resource newResource (String resource, boolean useCaches)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 throws MalformedURLException, IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 URL url=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 // Try to format as a URL?
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 url = new URL(resource);
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 catch(MalformedURLException e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 if(!resource.startsWith("ftp:") &&
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 !resource.startsWith("file:") &&
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 !resource.startsWith("jar:"))
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 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 // It's a file.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 if (resource.startsWith("./"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 resource=resource.substring(2);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 File file=new File(resource).getCanonicalFile();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 url=Resource.toURL(file);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 URLConnection connection=url.openConnection();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 connection.setUseCaches(useCaches);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 return new FileResource(url,connection,file);
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 catch(Exception e2)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 LOG.debug("EXCEPTION",e2);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 throw e;
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 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 LOG.warn("Bad Resource: "+resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 throw e;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 return newResource(url);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 public static Resource newResource (File file)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 throws MalformedURLException, IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 file = file.getCanonicalFile();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 URL url = Resource.toURL(file);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
201
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 URLConnection connection = url.openConnection();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 FileResource fileResource = new FileResource(url, connection, file);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 return fileResource;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
206
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 /** Construct a system resource from a string.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 * The resource is tried as classloader resource before being
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 * treated as a normal resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 * @param resource Resource as string representation
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 * @return The new Resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 * @throws IOException Problem accessing resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 public static Resource newSystemResource(String resource)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 URL url=null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 // Try to format as a URL?
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 ClassLoader loader=Thread.currentThread().getContextClassLoader();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 if (loader!=null)
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 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 url = loader.getResource(resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 if (url == null && resource.startsWith("/"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 url = loader.getResource(resource.substring(1));
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 catch (IllegalArgumentException e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 // 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
232 // improperly escaped, which various downstream classloaders
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 // tend to have a problem with
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 url = null;
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 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 loader=Resource.class.getClassLoader();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 if (loader!=null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 url=loader.getResource(resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 if (url==null && resource.startsWith("/"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 url=loader.getResource(resource.substring(1));
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 url=ClassLoader.getSystemResource(resource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 if (url==null && resource.startsWith("/"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 url=ClassLoader.getSystemResource(resource.substring(1));
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 return newResource(url);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
260
825
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 /** Find a classpath resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 public static Resource newClassPathResource(String resource)
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 return newClassPathResource(resource,true,false);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 /** Find a classpath resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 * 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
272 * 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
273 * 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
274 * 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
275 * @param name The relative name of the resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 * @param useCaches True if URL caches are to be used.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 * @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
278 * loaders with inverted priorities
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 * @return Resource or null
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 public static Resource newClassPathResource(String name,boolean useCaches,boolean checkParents)
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 URL url=Resource.class.getResource(name);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 url=Loader.getResource(Resource.class,name,checkParents);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 if (url==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 return newResource(url,useCaches);
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 public static boolean isContainedIn (Resource r, Resource containingResource) throws MalformedURLException
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 return r.isContainedIn(containingResource);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
297
825
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 @Override
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 protected void finalize()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 release();
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 public abstract boolean isContainedIn (Resource r) throws MalformedURLException;
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 /** Release any temporary resources held by the resource.
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 public abstract void release();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
314
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 * Returns true if the respresened resource exists.
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 public abstract boolean exists();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
321
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 * Returns true if the respresenetd resource is a container/directory.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 * 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
326 * considered directories.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 public abstract boolean isDirectory();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
329
825
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 * Returns the last modified time
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 public abstract long lastModified();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
335
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
336
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 * Return the length of the resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 public abstract long length();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
343
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 * Returns an URL representing the given resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 public abstract URL getURL();
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 URI representing the given 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 URI getURI()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 try
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 return getURL().toURI();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 catch(Exception e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 throw new RuntimeException(e);
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
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
366
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 * 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
370 * is not possible.
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 public abstract File getFile()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 throws IOException;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
375
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 * Returns the name of the resource
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 public abstract String getName();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
382
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 * Returns an input stream to the resource
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 public abstract InputStream getInputStream()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 throws java.io.IOException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
389
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 * Returns an output stream to the resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 public abstract OutputStream getOutputStream()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 throws java.io.IOException, SecurityException;
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 * Deletes the given resource
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 public abstract boolean delete()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 throws SecurityException;
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 * Rename the given resource
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 public abstract boolean renameTo( Resource dest)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 throws SecurityException;
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 * 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
414 * The resource names are not URL encoded.
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 public abstract String[] list();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
417
825
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 * Returns the resource contained inside the current resource with the
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 * given name.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 * @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
423 * encode method.
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 public abstract Resource addPath(String path)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 throws IOException,MalformedURLException;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
427
825
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 /** Get a resource from withing this resource.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 * <p>
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 * 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
432 * This method satisfied the {@link ResourceFactory} interface.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433 * @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
434 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 public Resource getResource(String path)
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 try
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 return addPath(path);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 catch(Exception e)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 LOG.debug("",e);
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
447
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 /** Encode according to this resource type.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 * The default implementation calls URI.encodePath(uri)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 * @param uri
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 * @return String encoded for this resource type.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 public String encode(String uri)
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 return URIUtil.encodePath(uri);
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 public Object getAssociate()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 return _associate;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
464
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 public void setAssociate(Object o)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 _associate=o;
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 * @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
474 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 public URL getAlias()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 return null;
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 /** Get the resource list as a HTML directory listing.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 * @param base The base URL
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 * @param parent True if the parent directory should be included
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 * @return String of HTML
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 public String getListHTML(String base,boolean parent)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 throws IOException
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 base=URIUtil.canonicalPath(base);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 if (base==null || !isDirectory())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493 String[] ls = list();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 if (ls==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495 return null;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 Arrays.sort(ls);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 String decodedBase = URIUtil.decodePath(base);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 String title = "Directory: "+deTag(decodedBase);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
500
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 StringBuilder buf=new StringBuilder(4096);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 buf.append("<HTML><HEAD>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 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
504 buf.append(title);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 buf.append("</TITLE></HEAD><BODY>\n<H1>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 buf.append(title);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 buf.append("</H1>\n<TABLE BORDER=0>\n");
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 if (parent)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 buf.append("<TR><TD><A HREF=\"");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 buf.append(URIUtil.addPaths(base,"../"));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 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
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 String encodedBase = hrefEncodeURI(base);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 DateFormat dfmt=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 DateFormat.MEDIUM);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
520 for (int i=0 ; i< ls.length ; i++)
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 Resource item = addPath(ls[i]);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 buf.append("\n<TR><TD><A HREF=\"");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 String path=URIUtil.addPaths(encodedBase,URIUtil.encodePath(ls[i]));
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 buf.append(path);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 if (item.isDirectory() && !path.endsWith("/"))
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
530 buf.append(URIUtil.SLASH);
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 // URIUtil.encodePath(buf,path);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 buf.append("\">");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
534 buf.append(deTag(ls[i]));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 buf.append("&nbsp;");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 buf.append("</A></TD><TD ALIGN=right>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 buf.append(item.length());
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 buf.append(" bytes&nbsp;</TD><TD>");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 buf.append(dfmt.format(new Date(item.lastModified())));
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 buf.append("</TD></TR>");
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 buf.append("</TABLE>\n");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
543 buf.append("</BODY></HTML>\n");
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 return buf.toString();
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 * 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
550 * 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
551 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 * 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
553 * would end the href attribute value string prematurely.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 *
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 * @param raw the raw text to encode.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 * @return the defanged text.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558 private static String hrefEncodeURI(String raw)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 StringBuffer buf = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
561
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 loop:
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 for (int i=0;i<raw.length();i++)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 char c=raw.charAt(i);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 switch(c)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 {
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 case '>':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572 buf=new StringBuffer(raw.length()<<1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 break loop;
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 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 if (buf==null)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 return raw;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
578
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 for (int i=0;i<raw.length();i++)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 char c=raw.charAt(i);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 switch(c)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 case '"':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585 buf.append("%22");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 case '\'':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 buf.append("%27");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 case '<':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 buf.append("%3C");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 case '>':
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 buf.append("%3E");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595 continue;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 default:
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 buf.append(c);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 continue;
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
601
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 return buf.toString();
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
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 private static String deTag(String raw)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 return StringUtil.replace( StringUtil.replace(raw,"<","&lt;"), ">", "&gt;");
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 /**
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 * @param out
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 * @param start First byte to write
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614 * @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
615 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 public void writeTo(OutputStream out,long start,long count)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 InputStream in = getInputStream();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
620 try
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 in.skip(start);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 if (count<0)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 IO.copy(in,out);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 else
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626 IO.copy(in,out,count);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
627 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 finally
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 in.close();
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 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 public void copyTo(File destination)
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 throws IOException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 if (destination.exists())
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639 throw new IllegalArgumentException(destination+" exists");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 writeTo(new FileOutputStream(destination),0,-1);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
642
825
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 public String getWeakETag()
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 StringBuilder b = new StringBuilder(32);
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 b.append("W/\"");
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 long lhash = lastModified() ^ getName().hashCode() ^ length();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 byte[] a = new byte[Long.BYTES];
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 for( int i=0; i<a.length; i++ ) {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 a[i] = (byte)lhash;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 lhash >>= 8;
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 b.append( Base64.getEncoder().encodeToString(a) );
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 b.append('"');
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 return b.toString();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 }
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 /* ------------------------------------------------------------ */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 /** Generate a properly encoded URL from a {@link File} instance.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 * @param file Target file.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 * @return URL of the target file.
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 * @throws MalformedURLException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 */
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 public static URL toURL(File file) throws MalformedURLException
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 {
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 return file.toURI().toURL();
7fb7c1915788 remove jetty.util.B64Code
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
671 }