1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.geronimo.common.propertyeditor;
18
19 import java.io.File;
20 import java.net.MalformedURLException;
21 import java.net.URL;
22
23 /**
24 * A property editor for URL typed properties.
25 *
26 * @version $Rev: 356022 $
27 */
28 public class URLEditor extends TextPropertyEditorSupport {
29 /**
30 * Convert the text value of the property into a URL object instance.
31 *
32 * @return a URL object constructed from the property text value.
33 */
34 public Object getValue() {
35 try {
36
37 URL url = new URL(getAsText().trim());
38
39
40
41 try {
42 if (url.getProtocol().equals("file")) {
43
44
45
46 return new File(url.getFile()).toURI().toURL();
47 }
48 } catch (Exception e) {
49
50 throw new PropertyEditorException(e);
51 }
52
53 return url;
54 } catch (MalformedURLException e) {
55
56
57 }
58
59 try {
60
61
62
63 return new File(getAsText()).toURI().toURL();
64 } catch (MalformedURLException e) {
65
66 throw new PropertyEditorException(e);
67 }
68 }
69 }