/[schmitzm]/branches/2.4.x/src/skrueger/geotools/io/GsServerSettings.java
ViewVC logotype

Annotation of /branches/2.4.x/src/skrueger/geotools/io/GsServerSettings.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1347 - (hide annotations)
Wed Dec 15 21:10:18 2010 UTC (14 years, 2 months ago) by alfonx
Original Path: trunk/src/skrueger/geotools/io/GsServerSettings.java
File MIME type: text/plain
File size: 2590 byte(s)


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 1347 @Override
26     public String toString() {
27     return "GsServerSettings [url=" + url + ", username=" + username
28     + ", password=" + password + "]";
29     }
30    
31 alfonx 1295 public GsServerSettings() {
32 alfonx 1291 }
33    
34 alfonx 1295 public GsServerSettings(String s) {
35     super(s);
36     }
37    
38 alfonx 1291 @Override
39 alfonx 1295 public boolean parsePropertiesString(String propString) {
40     if (propString == null || propString.isEmpty())
41     return false;
42     try {
43    
44     String[] split = propString.split(Pattern.quote(DELIMITER));
45    
46     int i = 0;
47     setUrl(split[i++]);
48     setTitle(split[i++]);
49     setUsername(StringUtils.stripToNull(split[i++]));
50     setPassword(split[i++]);
51    
52     return true;
53     } catch (Exception e) {
54     Log.warn("couldn't parse " + propString, e);
55     return false;
56     }
57 alfonx 1291 }
58    
59     String url;
60 alfonx 1295
61 alfonx 1291 public String getUrl() {
62     return url;
63     }
64    
65     public void setUrl(String url) {
66     this.url = url;
67     }
68    
69     public String getUsername() {
70     return username;
71     }
72    
73     public void setUsername(String username) {
74     this.username = username;
75     }
76    
77     public String getPassword() {
78     return password;
79     }
80    
81     public void setPassword(String password) {
82     this.password = password;
83     }
84    
85     String username;
86     String password;
87    
88 alfonx 1295 @Override
89     public String toPropertiesString() {
90     StringBuffer serialized = new StringBuffer(100);
91    
92     serialized.append(getUrl());
93     serialized.append(DELIMITER);
94    
95     serialized.append(getTitle());
96     serialized.append(DELIMITER);
97    
98     serialized.append(getUsername());
99     serialized.append(DELIMITER);
100    
101     serialized.append(getPassword());
102     serialized.append(DELIMITER);
103    
104     return serialized.toString();
105     }
106 alfonx 1327
107     @Override
108     public boolean isAvailable() {
109     try {
110     new URL(getUrl()).openStream().close();
111     return true;
112     } catch (IOException e) {
113     return false;
114     }
115    
116     }
117 alfonx 1291 }

Properties

Name Value
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26