e.g. Calendar Search Help
You must enter a value before pressing Search
spring

Class: org.springframework.beans.propertyeditors.URLEditor   ©

 OK to copy?
01 /*
02  * Copyright 2002-2004 the original author or authors.
03  * 
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  * 
08  *      http://www.apache.org/licenses/LICENSE-2.0
09  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16 
17 package org.springframework.beans.propertyeditors;
18 
19 import java.beans.PropertyEditorSupport;
20 import java.io.IOException;
21 import java.net.URL;
22 
23 import org.springframework.core.io.Resource;
24 import org.springframework.core.io.ResourceEditor;
25 
26 /**
27  * Editor for java.net.URL, to directly feed a URL property
28  * instead of using a String property.
29  * @author Juergen Hoeller
30  * @since 15.12.2003
31  * @see java.net.URL
32  */
33 public class URLEditor extends PropertyEditorSupport {
34 
35     private final ResourceEditor resourceEditor;
36 
37     /**
38      * Create a new URLEditor,
39      * using the default ResourceEditor underneath.
40      */
41     public URLEditor() {
42         this.resourceEditor = new ResourceEditor();
43     }
44 
45     /**
46      * Create a new URLEditor,
47      * using the given ResourceEditor underneath.
48      * @param resourceEditor the ResourceEditor to use
49      */
50     public URLEditor(ResourceEditor resourceEditor) {
51         this.resourceEditor = resourceEditor;
52     }
53 
54     public void setAsText(String text) throws IllegalArgumentException {
55         this.resourceEditor.setAsText(text);
56         Resource resource = (Resource) this.resourceEditor.getValue();
57         try {
58             setValue(resource != null ? resource.getURL() : null);
59         }
60         catch (IOException ex) {
61             throw new IllegalArgumentException(
62                     "Could not retrieve URL for " + resource + ": " + ex.getMessage());
63         }
64     }
65 
66     public String getAsText() {
67         if (getValue() != null) {
Rate68             return ((URL) getValue()).toExternalForm();
69         }
70         else {
71             return "";
72         }
73     }
74 
75 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
68 0% of 0