svn-gvsig-desktop / branches / v10 / extensions / extPublishGeoserver / src / org / gvsig / publish / geoserver / conf / GSFeature.java @ 22616
History | View | Annotate | Download (8.08 KB)
1 |
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ibañez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
package org.gvsig.publish.geoserver.conf; |
43 |
|
44 |
import java.io.File; |
45 |
import java.io.FileOutputStream; |
46 |
import java.io.IOException; |
47 |
|
48 |
import javax.xml.parsers.DocumentBuilder; |
49 |
import javax.xml.parsers.DocumentBuilderFactory; |
50 |
import javax.xml.parsers.ParserConfigurationException; |
51 |
|
52 |
import org.gvsig.publish.PublishLogger; |
53 |
import org.gvsig.publish.geoserver.model.GeoserverFeature; |
54 |
import org.w3c.dom.Document; |
55 |
import org.w3c.dom.Element; |
56 |
import org.w3c.dom.Text; |
57 |
|
58 |
import com.sun.org.apache.xml.internal.serialize.OutputFormat; |
59 |
import com.sun.org.apache.xml.internal.serialize.XMLSerializer; |
60 |
|
61 |
/**
|
62 |
* This class represents a feturetype in the Geoserver Configuration
|
63 |
*
|
64 |
* @author jvhigon (josevicente.higon@iver.es)
|
65 |
*/
|
66 |
public class GSFeature { |
67 |
|
68 |
//associations
|
69 |
private GSStyle style;
|
70 |
private GSDatastore datastore;
|
71 |
private GSNamespace namespace;
|
72 |
private GeoserverFeature remoteresource;
|
73 |
private String id; |
74 |
|
75 |
|
76 |
//Start of user code for the default constructor
|
77 |
/**
|
78 |
* Default constructor
|
79 |
*
|
80 |
*/
|
81 |
public GSFeature (GeoserverFeature remoteresource){
|
82 |
this.remoteresource = remoteresource;
|
83 |
this.id = remoteresource.getId();
|
84 |
} |
85 |
/**
|
86 |
*
|
87 |
* @return default featureType style
|
88 |
*/
|
89 |
public GSStyle getStyle(){
|
90 |
return this.style; |
91 |
} |
92 |
/**
|
93 |
*
|
94 |
* @return the featureType datastore
|
95 |
*/
|
96 |
public GSDatastore getDatastore(){
|
97 |
return this.datastore; |
98 |
} |
99 |
/**
|
100 |
*
|
101 |
* @return the featureType datastore
|
102 |
*/
|
103 |
public GSNamespace getNamespace(){
|
104 |
return this.namespace; |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Set the value of myStyle
|
109 |
* @param myStyle
|
110 |
*/
|
111 |
public void setStyle(GSStyle myStyle){ |
112 |
this.style = myStyle;
|
113 |
} |
114 |
/**
|
115 |
* Set the value of myDatastore
|
116 |
* @param myDatastore
|
117 |
*/
|
118 |
public void setDatastore(GSDatastore myDatastore){ |
119 |
this.datastore = myDatastore;
|
120 |
} |
121 |
/**
|
122 |
* Set the value of myNamespace
|
123 |
* @param myNamespace
|
124 |
*/
|
125 |
public void setNamespace(GSNamespace myNamespace){ |
126 |
this.namespace = myNamespace;
|
127 |
} |
128 |
|
129 |
|
130 |
/**
|
131 |
* Serialize the featureType information into a info.xml.
|
132 |
* It creates a directory with the name "datastore_feature" and puts the info.xml inside of it.
|
133 |
*
|
134 |
* @param dir directory where are placed all the feature's configurations
|
135 |
*
|
136 |
*
|
137 |
*/
|
138 |
public void toXML(File dir){ |
139 |
String aux = getId();
|
140 |
//String aux = getDatastore().getId() + "_" + getId();
|
141 |
//String aux = getNamespace().getPrefix() + "_" + getId();
|
142 |
//creates the directory
|
143 |
File dir_info = new File(dir.getAbsolutePath() + File.separator + aux); |
144 |
dir_info.mkdirs(); |
145 |
//creates the file
|
146 |
File info_xml = new File(dir_info.getAbsoluteFile() + File.separator + "info.xml"); |
147 |
Document dom=null; |
148 |
//get an instance of factory
|
149 |
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
150 |
try {
|
151 |
//get an instance of builder
|
152 |
DocumentBuilder db = dbf.newDocumentBuilder();
|
153 |
|
154 |
//create an instance of DOM
|
155 |
dom = db.newDocument(); |
156 |
|
157 |
}catch(ParserConfigurationException pce) { |
158 |
PublishLogger.getLog().error("ERROR " + getClass().getName() + ":Error while trying to instantiate DocumentBuilder " + pce); |
159 |
} |
160 |
//create the root element <featureType>
|
161 |
Element rootEle = dom.createElement("featureType"); |
162 |
rootEle.setAttribute("datastore", this.getDatastore().getId()); |
163 |
dom.appendChild(rootEle); |
164 |
//name
|
165 |
Element paramEle = dom.createElement("name"); |
166 |
Text txt = dom.createTextNode(remoteresource.getName()); |
167 |
paramEle.appendChild(txt); |
168 |
rootEle.appendChild(paramEle); |
169 |
//title
|
170 |
paramEle = dom.createElement("title");
|
171 |
txt = dom.createTextNode(remoteresource.getTitle()); |
172 |
paramEle.appendChild(txt); |
173 |
rootEle.appendChild(paramEle); |
174 |
//abstract
|
175 |
paramEle = dom.createElement("abstract");
|
176 |
txt = dom.createTextNode(remoteresource.getAbstract()); |
177 |
paramEle.appendChild(txt); |
178 |
rootEle.appendChild(paramEle); |
179 |
//numDecimals
|
180 |
paramEle = dom.createElement("numDecimals");
|
181 |
txt = dom.createTextNode(new Integer(remoteresource.getNumDecimals()).toString()); |
182 |
paramEle.appendChild(txt); |
183 |
rootEle.appendChild(paramEle); |
184 |
//keywords
|
185 |
paramEle = dom.createElement("keywords");
|
186 |
txt = dom.createTextNode("Not yet implemented");
|
187 |
paramEle.appendChild(txt); |
188 |
rootEle.appendChild(paramEle); |
189 |
//SRS
|
190 |
paramEle = dom.createElement("SRS");
|
191 |
txt = dom.createTextNode(new Integer(remoteresource.getLayerInfo().getSRID()).toString()); |
192 |
paramEle.appendChild(txt); |
193 |
rootEle.appendChild(paramEle); |
194 |
//latLonBoundingBox
|
195 |
paramEle = dom.createElement("latLonBoundingBox");
|
196 |
paramEle.setAttribute("dynamic", "false"); |
197 |
paramEle.setAttribute("minx", new Double(remoteresource.getLayerInfo().getDataSource().getLatLonBBox().getMinX()).toString() ); |
198 |
paramEle.setAttribute("miny", new Double(remoteresource.getLayerInfo().getDataSource().getLatLonBBox().getMinY()).toString() ); |
199 |
paramEle.setAttribute("maxx", new Double(remoteresource.getLayerInfo().getDataSource().getLatLonBBox().getMaxX()).toString() ); |
200 |
paramEle.setAttribute("maxy", new Double(remoteresource.getLayerInfo().getDataSource().getLatLonBBox().getMaxY()).toString() ); |
201 |
rootEle.appendChild(paramEle); |
202 |
//nativeBBox
|
203 |
paramEle = dom.createElement("nativeBBox");
|
204 |
paramEle.setAttribute("dynamic", "false"); |
205 |
paramEle.setAttribute("minx", new Double(remoteresource.getLayerInfo().getDataSource().getNativeBBox().getMinX()).toString() ); |
206 |
paramEle.setAttribute("miny", new Double(remoteresource.getLayerInfo().getDataSource().getNativeBBox().getMinY()).toString() ); |
207 |
paramEle.setAttribute("maxx", new Double(remoteresource.getLayerInfo().getDataSource().getNativeBBox().getMaxX()).toString() ); |
208 |
paramEle.setAttribute("maxy", new Double(remoteresource.getLayerInfo().getDataSource().getNativeBBox().getMaxY()).toString() ); |
209 |
rootEle.appendChild(paramEle); |
210 |
//cacheinfo
|
211 |
paramEle = dom.createElement("cacheinfo");
|
212 |
paramEle.setAttribute("enabled", new Boolean(remoteresource.isCacheEnabled()).toString()); |
213 |
paramEle.setAttribute("maxage", new Integer(remoteresource.getCacheMaxage()).toString()); |
214 |
rootEle.appendChild(paramEle); |
215 |
//style default
|
216 |
paramEle = dom.createElement("styles");
|
217 |
paramEle.setAttribute("default", this.getStyle().getId()); |
218 |
rootEle.appendChild(paramEle); |
219 |
|
220 |
//write info.xml
|
221 |
try
|
222 |
{ |
223 |
OutputFormat format = new OutputFormat(dom);
|
224 |
format.setIndenting(true);
|
225 |
XMLSerializer serializer = new XMLSerializer(
|
226 |
new FileOutputStream(info_xml), format); |
227 |
serializer.serialize(dom); |
228 |
} catch(IOException ioe) { |
229 |
PublishLogger.getLog().error("ERROR " + getClass().getName() + ": I can't generate the catlog.xml", ioe); |
230 |
} |
231 |
|
232 |
this.getStyle().writeSLD(dir.getParentFile());
|
233 |
|
234 |
} |
235 |
/**
|
236 |
* @return the id
|
237 |
*/
|
238 |
public String getId() { |
239 |
return id;
|
240 |
} |
241 |
/**
|
242 |
*
|
243 |
* @param id unique identifier of the feature. It must be composed by the namespace plus "_" plus table or filename
|
244 |
*/
|
245 |
public void setId(String id){ |
246 |
this.id = id;
|
247 |
} |
248 |
|
249 |
} |