/[schmitzm]/trunk/src/skrueger/geotools/io/GsServerSettings.java
ViewVC logotype

Annotation of /trunk/src/skrueger/geotools/io/GsServerSettings.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1327 - (hide annotations)
Sun Dec 5 17:23:22 2010 UTC (14 years, 3 months ago) by alfonx
File MIME type: text/plain
File size: 2442 byte(s)
added "isAvailable" to ServerSettings interface
1 alfonx 1291 package skrueger.geotools.io;
2    
3 alfonx 1327 import java.io.IOException;
4     import java.net.URL;
5 alfonx 1291 import java.util.HashMap;
6 alfonx 1295 import java.util.regex.Pattern;
7 alfonx 1291
8 alfonx 1295 import org.apache.commons.lang.StringUtils;
9     import org.jfree.util.Log;
10    
11 alfonx 1291 /**
12 alfonx 1295 * This class describes all settings needed to connect to a Geoserver server via
13     * REST configuration. This class extends a {@link HashMap} and contains two
14     * groups of keys:<br/>
15     * The first group of keys, are all keys provided by Geotools to create a WFS <br/>
16 alfonx 1291 * This class can serialize all important parameters needed to define the
17     * connection into a {@link String} with {@link #toPropertiesString()} and
18     * re-import the String with {@link #parsePropertiesString(String)}.
19 alfonx 1312 *
20     * TODO THis is wrong, should not extend AbstractGTServerSettings since it is
21     * not a GeoTools specific server setting
22 alfonx 1291 */
23 alfonx 1295 public class GsServerSettings extends AbstractGTServerSettings<Void, Void> {
24 alfonx 1291
25 alfonx 1295 public GsServerSettings() {
26 alfonx 1291 }
27    
28 alfonx 1295 public GsServerSettings(String s) {
29     super(s);
30     }
31    
32 alfonx 1291 @Override
33 alfonx 1295 public boolean parsePropertiesString(String propString) {
34     if (propString == null || propString.isEmpty())
35     return false;
36     try {
37    
38     String[] split = propString.split(Pattern.quote(DELIMITER));
39    
40     int i = 0;
41     setUrl(split[i++]);
42     setTitle(split[i++]);
43     setUsername(StringUtils.stripToNull(split[i++]));
44     setPassword(split[i++]);
45    
46     return true;
47     } catch (Exception e) {
48     Log.warn("couldn't parse " + propString, e);
49     return false;
50     }
51 alfonx 1291 }
52    
53     String url;
54 alfonx 1295
55 alfonx 1291 public String getUrl() {
56     return url;
57     }
58    
59     public void setUrl(String url) {
60     this.url = url;
61     }
62    
63     public String getUsername() {
64     return username;
65     }
66    
67     public void setUsername(String username) {
68     this.username = username;
69     }
70    
71     public String getPassword() {
72     return password;
73     }
74    
75     public void setPassword(String password) {
76     this.password = password;
77     }
78    
79     String username;
80     String password;
81    
82 alfonx 1295 @Override
83     public String toPropertiesString() {
84     StringBuffer serialized = new StringBuffer(100);
85    
86     serialized.append(getUrl());
87     serialized.append(DELIMITER);
88    
89     serialized.append(getTitle());
90     serialized.append(DELIMITER);
91    
92     serialized.append(getUsername());
93     serialized.append(DELIMITER);
94    
95     serialized.append(getPassword());
96     serialized.append(DELIMITER);
97    
98     return serialized.toString();
99     }
100 alfonx 1327
101     @Override
102     public boolean isAvailable() {
103     try {
104     new URL(getUrl()).openStream().close();
105     return true;
106     } catch (IOException e) {
107     return false;
108     }
109    
110     }
111 alfonx 1291 }

Properties

Name Value
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26