changes implementing enhancement 8 and code review 10, 11
This commit is contained in:
parent
99104c13cb
commit
e3ab87857d
@ -38,6 +38,7 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
@ -217,7 +218,7 @@ public class GeoServerRESTPublisher {
|
||||
|
||||
try {
|
||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||
layerEncoder.setDefaultStyle(defaultStyle);
|
||||
layerEncoder.addDefaultStyle(defaultStyle);
|
||||
configureLayer(layerEncoder, layerName);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Error in publishing shapefile " + e.getMessage(), e);
|
||||
@ -267,8 +268,8 @@ public class GeoServerRESTPublisher {
|
||||
.append("/featuretypes/").append(layername);
|
||||
|
||||
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
|
||||
fte.setName(layername);
|
||||
fte.setSRS(srs);
|
||||
fte.addName(layername);
|
||||
fte.addSRS(srs);
|
||||
|
||||
String configuredResult = HTTPUtils.putXml(postUrl.toString(), fte.toString(), this.gsuser, this.gspass);
|
||||
boolean shpConfigured = configuredResult != null;
|
||||
@ -308,8 +309,8 @@ public class GeoServerRESTPublisher {
|
||||
.append("/featuretypes");
|
||||
|
||||
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
|
||||
fte.setName(layername);
|
||||
fte.setSRS(srs); // srs=null?"EPSG:4326":srs);
|
||||
fte.addName(layername);
|
||||
fte.addSRS(srs); // srs=null?"EPSG:4326":srs);
|
||||
String ftypeXml = fte.toString();
|
||||
|
||||
String configuredResult = HTTPUtils.postXml(postUrl.toString(), ftypeXml, this.gsuser, this.gspass);
|
||||
@ -323,7 +324,7 @@ public class GeoServerRESTPublisher {
|
||||
LOGGER.info("DB layer successfully added (layer:" + layername + ")");
|
||||
|
||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||
layerEncoder.setDefaultStyle(defaultStyle);
|
||||
layerEncoder.addDefaultStyle(defaultStyle);
|
||||
configured = configureLayer(layerEncoder, layername);
|
||||
|
||||
if (!configured) {
|
||||
@ -385,16 +386,17 @@ public class GeoServerRESTPublisher {
|
||||
LOGGER.error("No coverages found in new coveragestore " + storeName);
|
||||
return null;
|
||||
}
|
||||
String coverageName = covList.get(0).getName();
|
||||
final String coverageName = covList.get(0).getName();
|
||||
|
||||
// config coverage props (srs)
|
||||
GSCoverageEncoder coverageEncoder = new GSCoverageEncoder();
|
||||
coverageEncoder.setSRS(srs);
|
||||
coverageEncoder.addName(FilenameUtils.getBaseName(geotiff.getName()));
|
||||
coverageEncoder.addSRS(srs);
|
||||
configureCoverage(coverageEncoder, workspace, storeName, coverageName);
|
||||
|
||||
// config layer props (style, ...)
|
||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||
layerEncoder.setDefaultStyle(defaultStyle);
|
||||
layerEncoder.addDefaultStyle(defaultStyle);
|
||||
configureLayer(layerEncoder, coverageName);
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -452,10 +454,10 @@ public class GeoServerRESTPublisher {
|
||||
*/
|
||||
public RESTCoverageStore publishExternalMosaic(String workspace, String storeName, File mosaicDir, String srs, String defaultStyle) throws FileNotFoundException {
|
||||
GSCoverageEncoder coverageEncoder = new GSCoverageEncoder();
|
||||
coverageEncoder.setSRS(srs);
|
||||
|
||||
coverageEncoder.addSRS(srs);
|
||||
coverageEncoder.addName(FilenameUtils.getBaseName(mosaicDir.getName()));
|
||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||
layerEncoder.setDefaultStyle(defaultStyle);
|
||||
layerEncoder.addDefaultStyle(defaultStyle);
|
||||
|
||||
return publishExternalMosaic(workspace, storeName, mosaicDir, coverageEncoder, layerEncoder);
|
||||
}
|
||||
@ -754,6 +756,11 @@ public class GeoServerRESTPublisher {
|
||||
}
|
||||
|
||||
protected String encode(String s) {
|
||||
return URLEncoder.encode(s);
|
||||
// try {
|
||||
// return URLEncoder.encode(s,"UTF-8");
|
||||
// } catch (UnsupportedEncodingException e) {
|
||||
// LOGGER.warn("Error encoding :"+s+" with UTF-8: "+e.getLocalizedMessage());
|
||||
return URLEncoder.encode(s);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.EntryKeyListEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.TextNodeListEncoder;
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* Creates an XML
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
*/
|
||||
public class GSCoverageEncoder extends GSResourceEncoder {
|
||||
|
||||
private EntryKeyListEncoder metadataEncoder = new EntryKeyListEncoder("metadata");
|
||||
private TextNodeListEncoder keywordsListEncoder = new TextNodeListEncoder("keywords");
|
||||
|
||||
|
||||
public GSCoverageEncoder() {
|
||||
super("coverage");
|
||||
set("enabled", "true");
|
||||
}
|
||||
|
||||
public void addMetadata(String key, String value) {
|
||||
metadataEncoder.add(key, value);
|
||||
}
|
||||
|
||||
public void addKeyword(String keyword) {
|
||||
keywordsListEncoder.add("string", keyword);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addNodesBeforeOutput(Element e) {
|
||||
super.addNodesBeforeOutput(e);
|
||||
keywordsListEncoder.attachList(e);
|
||||
metadataEncoder.attachList(e);
|
||||
}
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
*/
|
||||
public class GSFeatureTypeEncoder extends GSResourceEncoder {
|
||||
|
||||
public GSFeatureTypeEncoder() {
|
||||
super("featureType");
|
||||
set("enabled", "true");
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
setOrRemove("name", name);
|
||||
}
|
||||
}
|
||||
@ -30,6 +30,8 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
/**
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||
|
||||
@ -38,12 +40,8 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||
// enable layer
|
||||
add("enabled","true");
|
||||
}
|
||||
|
||||
// public void setWmsPath(String wmspath) {
|
||||
// add("wmspath", wmspath);
|
||||
// }
|
||||
|
||||
public void setDefaultStyle(String defaultStyle) {
|
||||
public void addDefaultStyle(String defaultStyle) {
|
||||
add("defaultStyle", defaultStyle);
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.EntryKeyListEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
|
||||
/**
|
||||
@ -33,16 +33,17 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
*
|
||||
* @author Eric Grosso
|
||||
* @author ETj
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
||||
|
||||
private EntryKeyListEncoder<String> connectionParameters = new EntryKeyListEncoder<String>("connectionParameters");
|
||||
private NestedElementEncoder<String> connectionParameters = new NestedElementEncoder<String>("connectionParameters");
|
||||
|
||||
|
||||
public GSPostGISDatastoreEncoder() {
|
||||
super("dataStore");
|
||||
setType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)"
|
||||
setDatabaseType("postgis");
|
||||
addType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)"
|
||||
addDatabaseType("postgis");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,104 +60,104 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
||||
* </ul>
|
||||
*/
|
||||
public void defaultInit() {
|
||||
setMinConnections(1);
|
||||
setMaxConnections(10);
|
||||
setFetchSize(1000);
|
||||
setConnectionTimeout(20);
|
||||
setLooseBBox(true);
|
||||
setPreparedStatements(false);
|
||||
setMaxOpenPreparedStatements(50);
|
||||
addMinConnections(1);
|
||||
addMaxConnections(10);
|
||||
addFetchSize(1000);
|
||||
addConnectionTimeout(20);
|
||||
addLooseBBox(true);
|
||||
addPreparedStatements(false);
|
||||
addMaxOpenPreparedStatements(50);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
public void addName(String name) {
|
||||
add("name", name);
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
public void addDescription(String description) {
|
||||
add("description", description);
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
public void addType(String type) {
|
||||
add("type", type);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
public void addEnabled(boolean enabled) {
|
||||
add("enabled", Boolean.toString(enabled));
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
public void addNamespace(String namespace) {
|
||||
connectionParameters.add("namespace", namespace);
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
public void addHost(String host) {
|
||||
connectionParameters.add("host", host);
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
public void addPort(int port) {
|
||||
connectionParameters.add("port", Integer.toString(port));
|
||||
}
|
||||
|
||||
public void setDatabase(String database) {
|
||||
public void addDatabase(String database) {
|
||||
connectionParameters.add("database", database);
|
||||
}
|
||||
|
||||
public void setSchema(String schema) {
|
||||
public void addSchema(String schema) {
|
||||
connectionParameters.add("schema", schema);
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
public void addUser(String user) {
|
||||
connectionParameters.add("user", user);
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
public void addPassword(String password) {
|
||||
connectionParameters.add("passwd", password);
|
||||
}
|
||||
|
||||
public void setDatabaseType(String dbtype) {
|
||||
public void addDatabaseType(String dbtype) {
|
||||
connectionParameters.add("dbtype", dbtype);
|
||||
}
|
||||
|
||||
public void setJndiReferenceName(String jndiReferenceName) {
|
||||
public void addJndiReferenceName(String jndiReferenceName) {
|
||||
connectionParameters.add("jndiReferenceName", jndiReferenceName);
|
||||
}
|
||||
|
||||
public void setExposePrimaryKeys(boolean exposePrimaryKeys) {
|
||||
public void addExposePrimaryKeys(boolean exposePrimaryKeys) {
|
||||
connectionParameters.add("Expose primary keys", Boolean.toString(exposePrimaryKeys));
|
||||
}
|
||||
|
||||
public void setMaxConnections(int maxConnections) {
|
||||
public void addMaxConnections(int maxConnections) {
|
||||
connectionParameters.add("max connections", Integer.toString(maxConnections));
|
||||
}
|
||||
|
||||
public void setMinConnections(int minConnections) {
|
||||
public void addMinConnections(int minConnections) {
|
||||
connectionParameters.add("min connections", Integer.toString(minConnections));
|
||||
}
|
||||
|
||||
public void setFetchSize(int fetchSize) {
|
||||
public void addFetchSize(int fetchSize) {
|
||||
connectionParameters.add("fetch size", Integer.toString(fetchSize));
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(int seconds) {
|
||||
public void addConnectionTimeout(int seconds) {
|
||||
connectionParameters.add("Connection timeout", Integer.toString(seconds));
|
||||
}
|
||||
|
||||
public void setValidateConnections(boolean validateConnections) {
|
||||
public void addValidateConnections(boolean validateConnections) {
|
||||
connectionParameters.add("validate connections", Boolean.toString(validateConnections));
|
||||
}
|
||||
|
||||
public void setPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
|
||||
public void addPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
|
||||
connectionParameters.add("Primary key metadata table", primaryKeyMetadataTable);
|
||||
}
|
||||
|
||||
public void setLooseBBox(boolean looseBBox) {
|
||||
public void addLooseBBox(boolean looseBBox) {
|
||||
connectionParameters.add("Loose bbox", Boolean.toString(looseBBox));
|
||||
}
|
||||
|
||||
public void setPreparedStatements(boolean preparedStatements) {
|
||||
public void addPreparedStatements(boolean preparedStatements) {
|
||||
connectionParameters.add("preparedStatements", Boolean.toString(preparedStatements));
|
||||
}
|
||||
|
||||
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
|
||||
public void addMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
|
||||
connectionParameters.add("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
|
||||
}
|
||||
|
||||
|
||||
@ -25,26 +25,55 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSMetadataEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.TextNodeListEncoder;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
*
|
||||
* Encode a GeoServer resouce.
|
||||
* The <T> type regards the GDSDimensionInfoEncoder metadata Type which has
|
||||
* different specialization for Features.
|
||||
*
|
||||
* @see GSDimensionInfoEncoder
|
||||
* @see GSFeatureDimensionInfoEncoder
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extends PropertyXMLEncoder {
|
||||
|
||||
/**
|
||||
* @param rootName Actually 'feature' or 'coverage'
|
||||
* @see GSFeatureTypeEncoder
|
||||
* @see GSCoverageEncoder
|
||||
*/
|
||||
protected GSResourceEncoder(final String rootName) {
|
||||
super(rootName);
|
||||
add("enabled", "true");
|
||||
|
||||
// Link members to the parent
|
||||
addContent(metadata);
|
||||
addContent(keywordsListEncoder);
|
||||
}
|
||||
|
||||
final private GSMetadataEncoder<T> metadata=new GSMetadataEncoder<T>();
|
||||
|
||||
|
||||
public void addMetadata(String key, T dimensionInfo) {
|
||||
metadata.add(key, dimensionInfo);
|
||||
}
|
||||
|
||||
private TextNodeListEncoder keywordsListEncoder = new TextNodeListEncoder("keywords");
|
||||
final private Element keywordsListEncoder = new Element("keywords");
|
||||
|
||||
public void addKeyword(String keyword) {
|
||||
final Element el=new Element("string");
|
||||
el.setText(keyword);
|
||||
keywordsListEncoder.addContent(el);
|
||||
}
|
||||
|
||||
/**
|
||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||
@ -52,29 +81,32 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extend
|
||||
public enum ProjectionPolicy {
|
||||
REPROJECT_TO_DECLARED, FORCE_DECLARED, NONE
|
||||
}
|
||||
|
||||
protected GSResourceEncoder(final String rootName) {
|
||||
super(rootName);
|
||||
add("enabled", "true");
|
||||
|
||||
// Link members to the parent
|
||||
addContent(metadata.getElement());
|
||||
addContent(keywordsListEncoder.getElement());
|
||||
/**
|
||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||
*/
|
||||
public void addProjectionPolicy(ProjectionPolicy policy) {
|
||||
add("projectionPolicy", policy.toString());
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
/**
|
||||
* Add the 'name' node with a text value from 'name'
|
||||
* @note REQUIRED to configure a resource
|
||||
*
|
||||
*/
|
||||
public void addName(final String name) {
|
||||
add("name", name);
|
||||
}
|
||||
|
||||
public void setTitle(final String title) {
|
||||
public void addTitle(final String title) {
|
||||
add("title", title);
|
||||
}
|
||||
|
||||
public void setSRS(final String srs) {
|
||||
public void addSRS(final String srs) {
|
||||
add("srs", srs);
|
||||
}
|
||||
|
||||
public void setLatLonBoundingBox(double minx, double maxy, double maxx,
|
||||
public void addLatLonBoundingBox(double minx, double maxy, double maxx,
|
||||
double miny, final String crs) {
|
||||
add("latLonBoundingBox/minx", String.valueOf(minx));
|
||||
add("latLonBoundingBox/maxy", String.valueOf(maxy));
|
||||
@ -83,7 +115,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extend
|
||||
add("latLonBoundingBox/crs", crs);
|
||||
}
|
||||
|
||||
public void setNativeBoundingBox(double minx, double maxy, double maxx,
|
||||
public void addNativeBoundingBox(double minx, double maxy, double maxx,
|
||||
double miny, final String crs) {
|
||||
add("nativeBoundingBox/minx", String.valueOf(minx));
|
||||
add("nativeBoundingBox/maxy", String.valueOf(maxy));
|
||||
@ -92,16 +124,5 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder> extend
|
||||
add("nativeBoundingBox/crs", crs);
|
||||
}
|
||||
|
||||
/**
|
||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||
*/
|
||||
public void setProjectionPolicy(ProjectionPolicy policy) {
|
||||
add("projectionPolicy", policy.toString());
|
||||
}
|
||||
|
||||
|
||||
public void addKeyword(String keyword) {
|
||||
keywordsListEncoder.add("string", keyword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,15 +42,15 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
||||
|
||||
public GSWorkspaceEncoder(String name) {
|
||||
this();
|
||||
setName(name);
|
||||
addName(name);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
public void addName(String name) {
|
||||
add("name", name);
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
final Element el=get("name");
|
||||
final Element el=contains("name");
|
||||
if (el!=null)
|
||||
return el.getName();
|
||||
else
|
||||
|
||||
@ -39,73 +39,9 @@ import org.jdom.Element;
|
||||
*
|
||||
*/
|
||||
public class GSCoverageEncoder extends GSResourceEncoder<GSDimensionInfoEncoder> {
|
||||
|
||||
|
||||
final private Element parameters=new Element("parameters");
|
||||
|
||||
public GSCoverageEncoder() {
|
||||
super("coverage");
|
||||
// Link members to the parent
|
||||
addContent(parameters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param val
|
||||
*/
|
||||
public void setAllowMultithreading(final boolean val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("AllowMultithreading"));
|
||||
param.addContent(new Element("string").setText((val)?"true":"false"));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setFilter(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("Filter"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setMaxAllowedTiles(final int val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("MaxAllowedTiles"));
|
||||
param.addContent(new Element("string").setText(String.valueOf(val)));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setInputTransparentColor(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("InputTransparentColor"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setOutputTransparentColor(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("OutputTransparentColor"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setSUGGESTED_TILE_SIZE(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("SUGGESTED_TILE_SIZE"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setUSE_JAI_IMAGEREAD(final boolean val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("USE_JAI_IMAGEREAD"));
|
||||
param.addContent(new Element("string").setText((val)?"true":"false"));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void setBackgroundValues(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("BackgroundValues"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
|
||||
final private NestedElementEncoder<Element> parameters=new NestedElementEncoder<Element>("parameters");
|
||||
|
||||
public GSImageMosaicEncoder() {
|
||||
// Link members to the parent
|
||||
addContent(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param val
|
||||
*/
|
||||
public void addAllowMultithreading(final boolean val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("AllowMultithreading"));
|
||||
param.addContent(new Element("string").setText((val)?"true":"false"));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void addFilter(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("Filter"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void addMaxAllowedTiles(final int val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("MaxAllowedTiles"));
|
||||
param.addContent(new Element("string").setText(String.valueOf(val)));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void addInputTransparentColor(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("InputTransparentColor"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void addOutputTransparentColor(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("OutputTransparentColor"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void addSUGGESTED_TILE_SIZE(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("SUGGESTED_TILE_SIZE"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void addUSE_JAI_IMAGEREAD(final boolean val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("USE_JAI_IMAGEREAD"));
|
||||
param.addContent(new Element("string").setText((val)?"true":"false"));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
public void addBackgroundValues(final String val){
|
||||
final Element param=new Element("entry");
|
||||
param.addContent(new Element("string").setText("BackgroundValues"));
|
||||
param.addContent(new Element("string").setText(val));
|
||||
parameters.addContent(param);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,3 +1,28 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.feature;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
|
||||
@ -28,6 +28,8 @@ package it.geosolutions.geoserver.rest.encoder.feature;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* Encode a GeoServer resource as FeatureType
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
|
||||
@ -1,45 +1,97 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.metadata;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.TextNodeListEncoder;
|
||||
import org.jdom.Element;
|
||||
|
||||
public class GSDimensionInfoEncoder extends TextNodeListEncoder {
|
||||
/**
|
||||
*
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public class GSDimensionInfoEncoder extends XmlElement{
|
||||
final boolean enabled;
|
||||
|
||||
/**
|
||||
* Enum for presentation mode
|
||||
*/
|
||||
public enum Presentation{
|
||||
LIST,
|
||||
CONTINUOUS_INTERVAL
|
||||
}
|
||||
|
||||
public enum DiscretePresentation{
|
||||
/**
|
||||
* Enum for presentation mode which needs arguments
|
||||
*/
|
||||
public enum PresentationDiscrete{
|
||||
DISCRETE_INTERVAL
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a dimension
|
||||
* @param enabled enable dimension if true
|
||||
* @note a enabled dimension also need a presentation mode set.
|
||||
*/
|
||||
public GSDimensionInfoEncoder(final boolean enabled) {
|
||||
super("dimensionInfo");
|
||||
add("enabled", (enabled)?"true":"false");
|
||||
this.enabled=enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* build an not enabled dimension
|
||||
*/
|
||||
public GSDimensionInfoEncoder() {
|
||||
super("dimensionInfo");
|
||||
add("enabled", "false");
|
||||
this.enabled=Boolean.FALSE;
|
||||
}
|
||||
|
||||
public void setPresentation(final Presentation pres){
|
||||
public void addPresentation(final Presentation pres){
|
||||
if (enabled){
|
||||
add("presentation",pres.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void setPresentation(final DiscretePresentation pres, final BigDecimal interval){
|
||||
public void addPresentation(final PresentationDiscrete pres, final BigDecimal interval){
|
||||
if (enabled){
|
||||
add("presentation",pres.toString());
|
||||
add("resolution",String.valueOf(interval));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void add(String nodename, String nodetext) {
|
||||
final Element el=new Element(nodename);
|
||||
el.setText(nodetext);
|
||||
this.addContent(el);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,33 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.metadata;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.EntryKeyListEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||
|
||||
public class GSMetadataEncoder <T extends GSDimensionInfoEncoder> extends EntryKeyListEncoder<T>{
|
||||
public class GSMetadataEncoder <T extends GSDimensionInfoEncoder> extends NestedElementEncoder<T>{
|
||||
|
||||
public GSMetadataEncoder() {
|
||||
super("metadata");
|
||||
|
||||
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public abstract class ElementUtils {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param root
|
||||
* @param el
|
||||
* @return true if the FIRST element EQUALS to the 'el' starting from root
|
||||
* is found AND can be deleted. If it is the root true is returned
|
||||
* and all of its child are removed.
|
||||
*
|
||||
*/
|
||||
public static boolean remove(Element root, final Element el) {
|
||||
if (root.equals(el)) {
|
||||
if (!el.isRootElement()) {
|
||||
root = el.getParentElement();
|
||||
// removing all child
|
||||
el.removeContent();
|
||||
root.removeContent(el);
|
||||
} else {
|
||||
// log warn this is root!
|
||||
// removing all child
|
||||
el.removeContent();
|
||||
}
|
||||
} else if ((root = ElementUtils.contains(root, el)) != null) {
|
||||
return remove(root, el);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root
|
||||
* @param el
|
||||
* @return the FIRST element EQUALS to the 'el' starting from root or null
|
||||
*/
|
||||
public static Element contains(final Element root, final Element el) {
|
||||
|
||||
if (root != null && el != null) {
|
||||
if (root.equals(el))
|
||||
return root;
|
||||
|
||||
final List<Element> childrenList = root.getChildren();
|
||||
if (childrenList.size() > 0) {
|
||||
Iterator<Element> it = childrenList.iterator();
|
||||
while (it.hasNext()) {
|
||||
final Element ret;
|
||||
if ((ret = contains(it.next(), el)) != null)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param root
|
||||
* @param name
|
||||
* @param val
|
||||
* @return the FIRST element EQUALS to a node with name and a text value
|
||||
* starting from root or null
|
||||
*/
|
||||
public static Element contains(final Element root, final String name,
|
||||
final String val) {
|
||||
if (root != null && name != null && val != null) {
|
||||
if (root.getName().equals(name) && root.getText().equals(val))
|
||||
return root;
|
||||
|
||||
final List<Element> childrenList = root.getChildren();
|
||||
if (childrenList.size() > 0) {
|
||||
Iterator<Element> it = childrenList.iterator();
|
||||
while (it.hasNext()) {
|
||||
final Element ret;
|
||||
if ((ret = contains(it.next(), name, val)) != null)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the FIRST element with name equals to the passed key
|
||||
*
|
||||
* @param root
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static Element contains(final Element root, final String name) {
|
||||
if (root != null && name != null) {
|
||||
if (root.getName().equals(name))
|
||||
return root;
|
||||
|
||||
final List<Element> childrenList = root.getChildren();
|
||||
if (childrenList.size() > 0) {
|
||||
Iterator<Element> it = childrenList.iterator();
|
||||
while (it.hasNext()) {
|
||||
final Element ret;
|
||||
if ((ret = contains(it.next(), name)) != null)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -25,8 +25,6 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
@ -43,9 +41,7 @@ import org.jdom.Element;
|
||||
*
|
||||
* <PRE>
|
||||
*
|
||||
* This can be also used in compounded to the PropertyXMLEncoder
|
||||
* or other objects overriding the toString() method
|
||||
* <br/>
|
||||
* This can be also add compounded Elements <br/>
|
||||
* e.g.:
|
||||
*
|
||||
* <PRE>
|
||||
@ -71,40 +67,26 @@ import org.jdom.Element;
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public class EntryKeyListEncoder <T> extends XMLSerializer{
|
||||
public class NestedElementEncoder<T> extends XmlElement {
|
||||
|
||||
private final Element root;
|
||||
|
||||
public EntryKeyListEncoder(String listName) {
|
||||
root=new Element(listName);
|
||||
public NestedElementEncoder(String listName) {
|
||||
super(listName);
|
||||
}
|
||||
|
||||
public void add(String key, T value) {
|
||||
final Element entryElem = new Element("entry");
|
||||
entryElem.setAttribute("key", key);
|
||||
if (value instanceof String)
|
||||
entryElem.setText((String)value);
|
||||
else if (value instanceof Element)
|
||||
entryElem.addContent((Element)value);
|
||||
else if (value instanceof GSDimensionInfoEncoder)
|
||||
entryElem.addContent(((GSDimensionInfoEncoder)value).getElement());
|
||||
else
|
||||
throw new IllegalArgumentException("Unable to add entry: unrecognized object");
|
||||
|
||||
root.addContent(entryElem);
|
||||
}
|
||||
|
||||
if (key != null)
|
||||
entryElem.setAttribute("key", key);
|
||||
|
||||
/**
|
||||
* add a node to the root
|
||||
*
|
||||
* @param el the node to add
|
||||
*/
|
||||
public void addContent(final Element el){
|
||||
root.addContent(el);
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
return root;
|
||||
if (value instanceof String)
|
||||
entryElem.setText((String) value);
|
||||
else if (value instanceof Element)
|
||||
entryElem.addContent((Element) value);
|
||||
else
|
||||
throw new IllegalArgumentException(
|
||||
"Unable to add entry: unrecognized object");
|
||||
|
||||
this.addContent(entryElem);
|
||||
}
|
||||
|
||||
}
|
||||
@ -29,98 +29,57 @@ import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* Creates an XML document by mapping properties to XML nodes.<br/>
|
||||
* You can set the root element name in the constructor.
|
||||
* Any key/value pair will be encoded as {@code <key>value</key>} node. <br/><br/>
|
||||
* You can set the root element name in the constructor. Any key/value pair will
|
||||
* be encoded as {@code <key>value</key>} node. <br/>
|
||||
* <br/>
|
||||
*
|
||||
* <h4>Nested nodes</h4>
|
||||
* Any key containing one or more slash ("/") will be encoded as nested nodes;
|
||||
* <br/>e.g.:
|
||||
* <PRE> {@code
|
||||
* key = "k1/k2/k3", value = "value" }</pre> will be encoded as
|
||||
* <PRE> {@code <k1><k2><k3>value</k3></k2></k1> }</pre>
|
||||
* <h4>Nested nodes</h4> Any key containing one or more slash ("/") will be
|
||||
* encoded as nested nodes; <br/>
|
||||
* e.g.:
|
||||
*
|
||||
* <PRE>
|
||||
* {@code
|
||||
* key = "k1/k2/k3", value = "value" }
|
||||
* </pre>
|
||||
*
|
||||
* will be encoded as
|
||||
*
|
||||
* <PRE>
|
||||
* {@code <k1><k2><k3>value</k3></k2></k1> }
|
||||
* </pre>
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class PropertyXMLEncoder extends XMLSerializer{
|
||||
public class PropertyXMLEncoder extends XmlElement {
|
||||
|
||||
// private final Map<String, String> configElements = new HashMap<String, String>();
|
||||
private final Element root;
|
||||
public PropertyXMLEncoder(final String rootName) {
|
||||
super(rootName);
|
||||
}
|
||||
|
||||
public PropertyXMLEncoder(final String rootName) {
|
||||
root=new Element(rootName);
|
||||
}
|
||||
|
||||
/**
|
||||
* add a node (as child) to the root node
|
||||
*
|
||||
* @param el the node to add
|
||||
*/
|
||||
@Override
|
||||
public void addContent(final Element el){
|
||||
root.addContent(el);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Deprecated use add()
|
||||
*/
|
||||
@Deprecated
|
||||
protected void setOrRemove(String key, String value) {
|
||||
final Element e=root.getChild(key);
|
||||
if (value != null && e==null) {
|
||||
add(root, key, value);
|
||||
} else {
|
||||
root.removeChild(key);
|
||||
}
|
||||
}
|
||||
|
||||
protected void add(String key, String value) {
|
||||
final Element e=root.getChild(key);
|
||||
if (value != null && e==null) {
|
||||
add(root, key, value);
|
||||
}
|
||||
}
|
||||
protected void add(String key, String value) {
|
||||
if (key != null && value != null) {
|
||||
add(this, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
// return configElements.isEmpty();
|
||||
return root.getChildren().isEmpty();
|
||||
}
|
||||
private void add(Element e, String key, String value) {
|
||||
if (!key.contains("/")) {
|
||||
e.addContent(new Element(key).setText(value));
|
||||
} else {
|
||||
final int i = key.indexOf("/");
|
||||
final String childName = key.substring(0, i);
|
||||
final String newkey = key.substring(i + 1);
|
||||
|
||||
public Element get(final String key){
|
||||
return root.getChild(key);
|
||||
// return configElements.get(key);
|
||||
}
|
||||
Element child = e.getChild(childName);
|
||||
if (child == null) {
|
||||
child = new Element(childName);
|
||||
e.addContent(child);
|
||||
}
|
||||
|
||||
add(child, newkey, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may need to override this method if some more info in the XML
|
||||
* string are needed when calling {@link #encodeXml() encodeXml()}.
|
||||
*
|
||||
* @param root the root element that will be converted into String by encodeXml
|
||||
*/
|
||||
@Override
|
||||
public Element getElement(){
|
||||
return root;
|
||||
}
|
||||
|
||||
private void add(Element e, String key, String value) {
|
||||
if( ! key.contains("/") ) {
|
||||
e.addContent(new Element(key).setText(value));
|
||||
} else {
|
||||
int i = key.indexOf("/");
|
||||
String childName = key.substring(0,i);
|
||||
String newkey = key.substring(i+1);
|
||||
|
||||
Element child = e.getChild(childName);
|
||||
if(child == null) {
|
||||
child = new Element(childName);
|
||||
e.addContent(child);
|
||||
}
|
||||
|
||||
add(child, newkey, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* Encodes lists of simple text nodes.
|
||||
* <br/>e.g.:
|
||||
* <PRE>
|
||||
* {@code
|
||||
* <parentnodename>
|
||||
* <nodename1>nodetext1</nodename1>
|
||||
* <nodename2>nodetext2</nodename2>
|
||||
* <nodename3>nodetext3</nodename3>
|
||||
* </parentnodename>}
|
||||
* <PRE>
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class TextNodeListEncoder extends XMLSerializer{
|
||||
|
||||
private final Element root;
|
||||
public TextNodeListEncoder(String listName) {
|
||||
root=new Element(listName);
|
||||
}
|
||||
|
||||
public void add(String nodename, String nodetext) {
|
||||
final Element el=new Element(nodename);
|
||||
el.setText(nodetext);
|
||||
root.addContent(el);
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public void addContent(final Element el){
|
||||
root.addContent(el);
|
||||
}
|
||||
|
||||
}
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jdom.output.Format;
|
||||
import org.jdom.output.XMLOutputter;
|
||||
@ -34,24 +35,45 @@ import org.jdom.output.XMLOutputter;
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*
|
||||
*/
|
||||
public abstract class XMLSerializer {
|
||||
public abstract class XmlElement extends Element {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final static XMLOutputter OUTPUTTER = new XMLOutputter(Format.getCompactFormat());
|
||||
|
||||
public XMLSerializer(){}
|
||||
|
||||
public abstract Element getElement();
|
||||
public XmlElement(final String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
public abstract void addContent(final Element el);
|
||||
private XmlElement(){};
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getChildren().isEmpty();
|
||||
}
|
||||
|
||||
public boolean remove(final Element el){
|
||||
return ElementUtils.remove(this,el);
|
||||
}
|
||||
|
||||
public Element contains(final Element el){
|
||||
return ElementUtils.contains(this,el);
|
||||
}
|
||||
|
||||
public Element contains(final String key, final String val){
|
||||
return ElementUtils.contains(this,key,val);
|
||||
}
|
||||
|
||||
public Element contains(final String key){
|
||||
return ElementUtils.contains(this,key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an xml String
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
final Element root= getElement();
|
||||
if (root!=null)
|
||||
return OUTPUTTER.outputString(root);
|
||||
else
|
||||
return "";
|
||||
return OUTPUTTER.outputString(this);
|
||||
}
|
||||
}
|
||||
@ -94,18 +94,18 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
|
||||
|
||||
GSPostGISDatastoreEncoder datastoreEncoder = new GSPostGISDatastoreEncoder();
|
||||
datastoreEncoder.defaultInit();
|
||||
datastoreEncoder.setName(datastoreName);
|
||||
datastoreEncoder.setDescription(description);
|
||||
datastoreEncoder.setNamespace(dsNamespace);
|
||||
datastoreEncoder.setHost(pgHost);
|
||||
datastoreEncoder.setPort(pgPort);
|
||||
datastoreEncoder.setDatabase(pgDatabase);
|
||||
datastoreEncoder.setSchema(pgSchema);
|
||||
datastoreEncoder.setUser(pgUser);
|
||||
datastoreEncoder.setPassword(pgPassword);
|
||||
datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys);
|
||||
datastoreEncoder.setValidateConnections(validateConnections);
|
||||
datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable);
|
||||
datastoreEncoder.addName(datastoreName);
|
||||
datastoreEncoder.addDescription(description);
|
||||
datastoreEncoder.addNamespace(dsNamespace);
|
||||
datastoreEncoder.addHost(pgHost);
|
||||
datastoreEncoder.addPort(pgPort);
|
||||
datastoreEncoder.addDatabase(pgDatabase);
|
||||
datastoreEncoder.addSchema(pgSchema);
|
||||
datastoreEncoder.addUser(pgUser);
|
||||
datastoreEncoder.addPassword(pgPassword);
|
||||
datastoreEncoder.addExposePrimaryKeys(exposePrimaryKeys);
|
||||
datastoreEncoder.addValidateConnections(validateConnections);
|
||||
datastoreEncoder.addPrimaryKeyMetadataTable(primaryKeyMetadataTable);
|
||||
|
||||
// creation test
|
||||
boolean created = publisher.createPostGISDatastore(wsName, datastoreEncoder);
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
@ -25,11 +25,12 @@ import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Pr
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class GSCoverageEncoderTest extends TestCase {
|
||||
@ -44,21 +45,40 @@ public class GSCoverageEncoderTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testAll() {
|
||||
GSCoverageEncoder encoder=new GSCoverageEncoder();
|
||||
final GSCoverageEncoder encoder=new GSCoverageEncoder();
|
||||
encoder.addKeyword("KEYWORD_1");
|
||||
encoder.addKeyword("KEYWORD_2");
|
||||
encoder.addKeyword("...");
|
||||
encoder.addKeyword("KEYWORD_N");
|
||||
GSDimensionInfoEncoder dim=new GSDimensionInfoEncoder(true);
|
||||
dim.setPresentation(Presentation.CONTINUOUS_INTERVAL);
|
||||
final GSDimensionInfoEncoder dim=new GSDimensionInfoEncoder(true);
|
||||
dim.addPresentation(Presentation.CONTINUOUS_INTERVAL);
|
||||
encoder.addMetadata("time", dim);
|
||||
GSDimensionInfoEncoder dim2=new GSDimensionInfoEncoder(true);
|
||||
dim2.setPresentation(Presentation.LIST);
|
||||
final GSDimensionInfoEncoder dim2=new GSDimensionInfoEncoder(true);
|
||||
dim2.addPresentation(Presentation.LIST);
|
||||
encoder.addMetadata("elev", dim2);
|
||||
encoder.setAllowMultithreading(true);
|
||||
|
||||
|
||||
LOGGER.info(encoder.toString());
|
||||
// TODO TESTS
|
||||
|
||||
final Element el=encoder.contains("metadata");
|
||||
Assert.assertNotNull(el);
|
||||
LOGGER.info("contains_key:"+el.toString());
|
||||
|
||||
final Element el2=encoder.contains("presentation");
|
||||
Assert.assertNotNull(el2);
|
||||
LOGGER.info("contains_key:"+el2.toString());
|
||||
|
||||
final Element el3=encoder.contains(encoder.contains("metadata"));
|
||||
Assert.assertNotNull(el3);
|
||||
LOGGER.info("contains_by_node:"+el3.toString());
|
||||
|
||||
final boolean removed=encoder.remove(el3);
|
||||
LOGGER.info("remove:"+removed);
|
||||
Assert.assertTrue(removed);
|
||||
|
||||
final Element el4=encoder.contains("metadata");
|
||||
Assert.assertNull(el4);
|
||||
if (el4==null)
|
||||
LOGGER.info("REMOVED");
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* GPLv3 + Classpath exception
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class GSImageMosaicEncoderTest extends TestCase {
|
||||
|
||||
public GSImageMosaicEncoderTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default logger
|
||||
*/
|
||||
protected final static Logger LOGGER = Logger.getLogger(GSImageMosaicEncoderTest.class);
|
||||
|
||||
@Test
|
||||
public void testAll() {
|
||||
final GSImageMosaicEncoder encoder=new GSImageMosaicEncoder();
|
||||
encoder.addKeyword("KEYWORD_1");
|
||||
encoder.addKeyword("KEYWORD_2");
|
||||
encoder.addKeyword("...");
|
||||
encoder.addKeyword("KEYWORD_N");
|
||||
final GSDimensionInfoEncoder dim=new GSDimensionInfoEncoder(true);
|
||||
dim.addPresentation(Presentation.CONTINUOUS_INTERVAL);
|
||||
encoder.addMetadata("time", dim);
|
||||
final GSDimensionInfoEncoder dim2=new GSDimensionInfoEncoder(true);
|
||||
dim2.addPresentation(Presentation.LIST);
|
||||
encoder.addMetadata("elev", dim2);
|
||||
encoder.addAllowMultithreading(true);
|
||||
encoder.addSUGGESTED_TILE_SIZE("512,512");
|
||||
|
||||
LOGGER.info(encoder.toString());
|
||||
|
||||
final Element el=encoder.contains("metadata");
|
||||
Assert.assertNotNull(el);
|
||||
LOGGER.info("contains_key:"+el.toString());
|
||||
|
||||
final Element el2=encoder.contains("presentation");
|
||||
Assert.assertNotNull(el2);
|
||||
LOGGER.info("contains_key:"+el2.toString());
|
||||
|
||||
final Element el3=encoder.contains(encoder.contains("metadata"));
|
||||
Assert.assertNotNull(el3);
|
||||
LOGGER.info("contains_by_node:"+el3.toString());
|
||||
|
||||
final boolean removed=encoder.remove(el3);
|
||||
LOGGER.info("remove:"+removed);
|
||||
Assert.assertTrue(removed);
|
||||
|
||||
final Element el4=encoder.contains("metadata");
|
||||
Assert.assertNull(el4);
|
||||
if (el4==null)
|
||||
LOGGER.info("REMOVED");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -17,11 +17,11 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
package it.geosolutions.geoserver.rest.encoder.feature;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.DiscretePresentation;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@ -48,7 +48,7 @@ public class GSFeatureEncoderTest extends TestCase {
|
||||
feature.addKeyword("KEYWORD_N");
|
||||
GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder(
|
||||
"ELE");
|
||||
dim2.setPresentation(DiscretePresentation.DISCRETE_INTERVAL,
|
||||
dim2.addPresentation(PresentationDiscrete.DISCRETE_INTERVAL,
|
||||
BigDecimal.valueOf(10));
|
||||
feature.addMetadata("elevation", dim2);
|
||||
|
||||
@ -36,13 +36,13 @@ public class EntryKeyListEncoderTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testAll() {
|
||||
EntryKeyListEncoder ekle = new EntryKeyListEncoder("EKL");
|
||||
NestedElementEncoder ekle = new NestedElementEncoder("EKL");
|
||||
ekle.add("k1", "v1");
|
||||
ekle.add("k2", "v2");
|
||||
ekle.add("k3", "v3");
|
||||
|
||||
Element root = new Element("root");
|
||||
root.addContent(ekle.getElement());
|
||||
root.addContent(ekle);
|
||||
|
||||
assertEquals(1, root.getChildren().size());
|
||||
assertNotNull(root.getChild("EKL"));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user