Revision 19432 branches/v10/extensions/extPublishGeoserver/src/org/gvsig/publish/geoserver/model/Geoserver.java

View differences:

Geoserver.java
40 40
 */
41 41
package org.gvsig.publish.geoserver.model;
42 42

  
43
import java.io.File;
44
import java.net.MalformedURLException;
45
import java.net.URL;
46

  
47
import org.gvsig.publish.PublishLogger;
48
import org.gvsig.publish.geoserver.conf.GSConfiguration;
49
import org.gvsig.publish.geoserver.conf.GSServer;
50
import org.gvsig.publish.serversmodel.PublishException;
43 51
import org.gvsig.publish.serversmodel.Server;
44 52

  
53
import com.iver.andami.PluginServices;
54
/**
55
 * This class represents the server Geoserver
56
 * @author jvhigon
57
 *
58
 */
45 59
public class Geoserver extends Server {
46 60
	/*
47 61
	 * Constant to identify the server
48 62
	 */
49
	public static final String SERVER_GEOSERVER = "Geoserver";
63
	public static final String REGISTER_TAG = "Geoserver";
50 64
	/*
51 65
	 * Constant to identify the version
52 66
	 * 
53 67
	 */
54 68
	public static final String VERSION="_v1";
69
	//Attributes
70
	private File configDirectory; 
71
	private GSConfiguration config;
72
	
55 73
	/**
56 74
	 * Constructor
57 75
	 */
58 76
	public Geoserver() {
59 77
		super();
78
		initialize();
60 79
	}
80
	/**
81
	 * sets default values 
82
	 */
83
	private void initialize() {
84
		//configure server
85
		getConfig().setUser("admin");
86
		getConfig().setPassword("geoserver");
87
		//configure services.global
88
		GSServer srvs = getConfig().getServices();
89
		srvs.setMaxFeatures(2000);
90
		srvs.setLoginLevel(GSServer.LOG_INFO);
91
		//srvs.setAdminPassword("geoserver");
92
		//srvs.setAdminUser("admin");
93
		srvs.setCharset("UTF-8");
94
		srvs.setImageIOCache(false);
95
		srvs.setJaiJPEGNative(true);
96
		srvs.setJaiMemoryCapacity(0.5);
97
		srvs.setJaiMemoryThreshold(0.75);
98
		srvs.setJaiPNGNative(true);
99
		srvs.setJaiRecycling(true);
100
		srvs.setJaiTilePriority(5);
101
		srvs.setJaiTileThreads(7);
102
		srvs.setLoginToFile(false);
103
		srvs.setNumDecimals(8);
104
		srvs.setVerbose(false);
105
		srvs.setVerboseExceptions(false);		
106
	}
61 107

  
62 108
	/**
63 109
	 * @return String which identifies the Server in the Extensions Point
64 110
	 */
65 111
	public String getType() {
66
		return SERVER_GEOSERVER;
112
		return REGISTER_TAG;
67 113
	}
68 114

  
69 115
	/**
......
82 128
		return this.getClass().getName() + VERSION;
83 129
	}
84 130

  
131
	public File getConfigDirectory() {
132
		return configDirectory;
133
	}
134

  
135
	public void setConfigDirectory(File configDirectory) {
136
		this.configDirectory = configDirectory;
137
	}
138

  
139
	/**
140
	 * @return geoserver configuration
141
	 */
142
	public GSConfiguration getConfig(){
143
		if (config==null){
144
			config = new GSConfiguration();
145
		}
146
		return config;
147
	}
148
	
149
	public void setConfig(GSConfiguration config) {
150
		this.config = config;
151
	}
152

  
153
	/**
154
	 * Overrides the method in order to put the correct url's on the services 
155
	 *  
156
	 * @see org.gvsig.publish.serversmodel.Server#setServerURL(java.net.URL)
157
	 *
158
	public void setServerURL(URL serverURL) {
159
		super.setServerURL(serverURL);
160
		//ading url
161
		URL url = getServerURL();
162
		URL aux_wfs=null;
163
		URL aux_wms=null;
164
		try {
165
			aux_wfs = new URL(url.toString() + "/wfs");
166
			aux_wms = new URL(url.toString() + "/wms");
167
		} catch (MalformedURLException e) {
168
			PublishLogger.getLog().error("what are you doing my friend!", e);
169
		}
170
		getConfig().getServices().getWFS().setOnlineResource(aux_wfs);
171
		getConfig().getServices().getWMS().setOnlineResource(aux_wms);		
172
	}*/
173

  
174
	/**
175
	 * 
176
	 * @see org.gvsig.publish.serversmodel.Server#publish()
177
	 */
178
	public void publish() throws PublishException {		
179
		super.publish();				
180
		checkParameters();				
181
		config.toXML(configDirectory);
182
	}
183
	/**
184
	 * check a minimum of parameters for publishing 
185
	 * 
186
	 * @throws PublishException
187
	 */
188
	private void checkParameters()throws PublishException{
189
		//check config directory
190
		//TODO: this code never is executed
191
		if (configDirectory == null){
192
			throw new PublishException("config_dir_not_defined");
193
		}
194
		//check user
195
		if (getConfig().getUser() == null){
196
			throw new PublishException("user_not_defined");
197
		}
198
		//check password
199
		if (getConfig().getPassword() == null){
200
			throw new PublishException("password_not_defined");
201
		}
202
		//check if there is anything to publish		
203
		if (getProjectInfo() == null){
204
			throw new PublishException(PluginServices.getText(this,"nothing_to_publish"));
205
		}
206
	}
85 207
}

Also available in: Unified diff