merge to allign to the master branch

This commit is contained in:
ccancellieri 2011-11-08 09:28:02 +01:00
commit 352e241e0b
23 changed files with 1428 additions and 338 deletions

View File

@ -220,7 +220,7 @@ public class GeoServerRESTPublisher {
try {
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.addDefaultStyle(defaultStyle);
configureLayer(layerEncoder, layerName);
configureLayer(workspace, layerName, layerEncoder);
} catch (Exception e) {
LOGGER.warn("Error in publishing shapefile " + e.getMessage(), e);
sent = false;
@ -271,6 +271,7 @@ public class GeoServerRESTPublisher {
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
fte.addName(layername);
fte.addSRS(srs);
fte.addProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
String configuredResult = HTTPUtils.putXml(postUrl.toString(), fte.toString(), this.gsuser, this.gspass);
boolean shpConfigured = configuredResult != null;
@ -326,7 +327,7 @@ public class GeoServerRESTPublisher {
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.addDefaultStyle(defaultStyle);
configured = configureLayer(layerEncoder, layername);
configured = configureLayer(workspace, layername, layerEncoder);
if (!configured) {
LOGGER.warn("Error in configuring (" + configuredResult + ") "
@ -393,13 +394,13 @@ public class GeoServerRESTPublisher {
GSCoverageEncoder coverageEncoder = new GSCoverageEncoder();
coverageEncoder.addName(FilenameUtils.getBaseName(geotiff.getName()));
coverageEncoder.addSRS(srs);
coverageEncoder.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
coverageEncoder.addProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
configureCoverage(coverageEncoder, workspace, storeName, coverageName);
// config layer props (style, ...)
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.addDefaultStyle(defaultStyle);
configureLayer(layerEncoder, coverageName);
configureLayer(workspace, coverageName, layerEncoder);
} catch (Exception e) {
LOGGER.warn("Could not configure external GEOTiff:" + storeName, e);
@ -510,7 +511,7 @@ public class GeoServerRESTPublisher {
String coverageName = covList.get(0).getName();
configureCoverage(coverageEncoder, store.getWorkspaceName(), storeName, coverageName);
configureLayer(layerEncoder, storeName);
configureLayer(workspace, storeName, layerEncoder);
} catch (Exception e) {
LOGGER.warn("Could not configure external mosaic:" + storeName, e);
@ -726,26 +727,44 @@ public class GeoServerRESTPublisher {
//===
//==========================================================================
/**
* @deprecated please use {@link configureLayer(String workspace, String layerName, GSLayerEncoder layer) }
*/
public boolean configureLayer(final GSLayerEncoder layer, final String layerName)
{
return configureLayer(null, layerName, layer);
}
/**
* Allows to configure some layer attributes such as WmsPath and DefaultStyle
*
*/
protected boolean configureLayer(final GSLayerEncoder layer, final String layerName) {
public boolean configureLayer(final String workspace, final String layerName, final GSLayerEncoder layer) {
// TODO: check this usecase, layer should always be defined
if (layer.isEmpty()) {
LOGGER.warn("Null layer name while configuring layer -- This behavior is suspicious.");
return true;
}
final String url = restURL + "/rest/layers/" + layerName;
String fqLayerName = workspace + ":" + layerName;
// this null check is here only for backward compatibility. workspace shall be mandatory.
if(workspace == null) {
LOGGER.warn("Null workspace while configuring layer : " + layerName + " -- This behavior is deprecated.");
fqLayerName = layerName;
}
final String url = restURL + "/rest/layers/" + fqLayerName;
String layerXml = layer.toString();
String sendResult = HTTPUtils.putXml(url, layerXml, gsuser, gspass);
if (sendResult != null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Layer successfully configured: " + layerName);
LOGGER.info("Layer successfully configured: " + fqLayerName);
}
} else {
LOGGER.warn("Error configuring layer " + layerName + " (" + sendResult + ")");
LOGGER.warn("Error configuring layer " + fqLayerName + " (" + sendResult + ")");
}
return sendResult != null;

View File

@ -32,17 +32,41 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
* @author ETj (etj at geo-solutions.it)
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*
* The layer encoder is enabled by default
*
*/
public class GSLayerEncoder extends PropertyXMLEncoder {
public GSLayerEncoder() {
super("layer");
// enable layer
addEnabled();
}
protected void addEnabled(){
add("enabled","true");
}
/**
* @param enable true if layer should be set to enabled
*/
public void setEnabled(boolean enable){
if (enable)
set("enabled","true");
else
set("enabled","false");
}
/**
*
* @param defaultStyle
* @deprecated will be set to protected in the next release, please use setDefaultStyle
*
*/
public void addDefaultStyle(String defaultStyle) {
add("defaultStyle", defaultStyle);
}
public void setDefaultStyle(String defaultStyle) {
set("defaultStyle", defaultStyle);
}
}

View File

@ -39,7 +39,6 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
private NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters");
public GSPostGISDatastoreEncoder() {
super("dataStore");
addType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)"
@ -61,105 +60,266 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
* </ul>
*/
public void defaultInit() {
addMinConnections(1);
addMaxConnections(10);
addFetchSize(1000);
addConnectionTimeout(20);
addLooseBBox(true);
addPreparedStatements(false);
addMaxOpenPreparedStatements(50);
setMinConnections(1);
setMaxConnections(10);
setFetchSize(1000);
setConnectionTimeout(20);
setLooseBBox(true);
setPreparedStatements(false);
setMaxOpenPreparedStatements(50);
}
public void addName(String name) {
/**
* @deprecated will be set to protected in the next release
*/
public void addName(String name) {
add("name", name);
}
public void setName(String name) {
set("name", name);
}
public void addDescription(String description) {
/**
* @deprecated will be set to protected in the next release
*/
public void addDescription(String description) {
add("description", description);
}
public void addType(String type) {
add("type", type);
public void setDescription(String description) {
set("description", description);
}
public void addEnabled(boolean enabled) {
/**
* @deprecated will be set to protected in the next release
*/
public void addType(String type) {
add("type", type);
}
public void setType(String type) {
set("type", type);
}
/**
* @deprecated will be set to protected in the next release
*/
public void addEnabled(boolean enabled) {
add("enabled", Boolean.toString(enabled));
}
public void addNamespace(String namespace) {
public void setEnabled(boolean enabled) {
set("enabled", Boolean.toString(enabled));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addNamespace(String namespace) {
connectionParameters.add("namespace", namespace);
}
public void addHost(String host) {
public void setNamespace(String namespace) {
connectionParameters.set("namespace", namespace);
}
/**
* @deprecated will be set to protected in the next release
*/
public void addHost(String host) {
connectionParameters.add("host", host);
}
public void setHost(String host) {
connectionParameters.set("host", host);
}
public void addPort(int port) {
/**
* @deprecated will be set to protected in the next release
*/
public void addPort(int port) {
connectionParameters.add("port", Integer.toString(port));
}
public void setPort(int port) {
connectionParameters.set("port", Integer.toString(port));
}
public void addDatabase(String database) {
/**
* @deprecated will be set to protected in the next release
*/
public void addDatabase(String database) {
connectionParameters.add("database", database);
}
public void setDatabase(String database) {
connectionParameters.set("database", database);
}
public void addSchema(String schema) {
/**
* @deprecated will be set to protected in the next release
*/
public void addSchema(String schema) {
connectionParameters.add("schema", schema);
}
public void setSchema(String schema) {
connectionParameters.set("schema", schema);
}
public void addUser(String user) {
/**
* @deprecated will be set to protected in the next release
*/
public void addUser(String user) {
connectionParameters.add("user", user);
}
public void addPassword(String password) {
connectionParameters.add("passwd", password);
public void setUser(String user) {
connectionParameters.set("user", user);
}
public void addDatabaseType(String dbtype) {
/**
* @deprecated will be set to protected in the next release
*/
public void addPassword(String password) {
connectionParameters.add("passwd", password);
}
public void setPassword(String password) {
connectionParameters.set("passwd", password);
}
/**
* @deprecated will be set to protected in the next release
*/
public void addDatabaseType(String dbtype) {
connectionParameters.add("dbtype", dbtype);
}
public void addJndiReferenceName(String jndiReferenceName) {
connectionParameters.add("jndiReferenceName", jndiReferenceName);
public void setDatabaseType(String dbtype) {
connectionParameters.set("dbtype", dbtype);
}
public void addExposePrimaryKeys(boolean exposePrimaryKeys) {
/**
* @deprecated will be set to protected in the next release
*/
public void addJndiReferenceName(String jndiReferenceName) {
connectionParameters.add("jndiReferenceName", jndiReferenceName);
}
public void setJndiReferenceName(String jndiReferenceName) {
connectionParameters.set("jndiReferenceName", jndiReferenceName);
}
/**
* @deprecated will be set to protected in the next release
*/
public void addExposePrimaryKeys(boolean exposePrimaryKeys) {
connectionParameters.add("Expose primary keys", Boolean.toString(exposePrimaryKeys));
}
public void addMaxConnections(int maxConnections) {
public void setExposePrimaryKeys(boolean exposePrimaryKeys) {
connectionParameters.set("Expose primary keys", Boolean.toString(exposePrimaryKeys));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addMaxConnections(int maxConnections) {
connectionParameters.add("max connections", Integer.toString(maxConnections));
}
public void addMinConnections(int minConnections) {
public void setMaxConnections(int maxConnections) {
connectionParameters.set("max connections", Integer.toString(maxConnections));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addMinConnections(int minConnections) {
connectionParameters.add("min connections", Integer.toString(minConnections));
}
public void addFetchSize(int fetchSize) {
public void setMinConnections(int minConnections) {
connectionParameters.set("min connections", Integer.toString(minConnections));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addFetchSize(int fetchSize) {
connectionParameters.add("fetch size", Integer.toString(fetchSize));
}
public void addConnectionTimeout(int seconds) {
public void setFetchSize(int fetchSize) {
connectionParameters.set("fetch size", Integer.toString(fetchSize));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addConnectionTimeout(int seconds) {
connectionParameters.add("Connection timeout", Integer.toString(seconds));
}
public void addValidateConnections(boolean validateConnections) {
public void setConnectionTimeout(int seconds) {
connectionParameters.set("Connection timeout", Integer.toString(seconds));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addValidateConnections(boolean validateConnections) {
connectionParameters.add("validate connections", Boolean.toString(validateConnections));
}
public void addPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
public void setValidateConnections(boolean validateConnections) {
connectionParameters.set("validate connections", Boolean.toString(validateConnections));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
connectionParameters.add("Primary key metadata table", primaryKeyMetadataTable);
}
public void addLooseBBox(boolean looseBBox) {
public void setPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
connectionParameters.set("Primary key metadata table", primaryKeyMetadataTable);
}
/**
* @deprecated will be set to protected in the next release
*/
public void addLooseBBox(boolean looseBBox) {
connectionParameters.add("Loose bbox", Boolean.toString(looseBBox));
}
public void addPreparedStatements(boolean preparedStatements) {
public void setLooseBBox(boolean looseBBox) {
connectionParameters.set("Loose bbox", Boolean.toString(looseBBox));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addPreparedStatements(boolean preparedStatements) {
connectionParameters.add("preparedStatements", Boolean.toString(preparedStatements));
}
public void addMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
public void setPreparedStatements(boolean preparedStatements) {
connectionParameters.set("preparedStatements", Boolean.toString(preparedStatements));
}
/**
* @deprecated will be set to protected in the next release
*/
public void addMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
connectionParameters.add("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
}
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
connectionParameters.set("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
}
}

View File

@ -33,6 +33,7 @@ import it.geosolutions.geoserver.rest.encoder.metadata.GSMetadataEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
import org.jdom.Element;
import org.jdom.filter.Filter;
/**
*
@ -47,6 +48,7 @@ import org.jdom.Element;
*/
public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
extends PropertyXMLEncoder {
private final static String NAME="name";
final private GSMetadataEncoder<T> metadata = new GSMetadataEncoder<T>();
final private Element keywordsListEncoder = new Element("keywords");
@ -64,11 +66,31 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
addContent(metadata.getRoot());
addContent(keywordsListEncoder);
}
public void setEnabled(boolean enabled){
set("enabled",(enabled)?"true":"false");
}
/**
* @param key
* @param dimensionInfo
* @deprecated will be set to protected in the next release
*/
public void addMetadata(String key, T dimensionInfo) {
metadata.add(key, dimensionInfo.getRoot());
}
/**
* @param key the name of the metadata to add (f.e.: elevation, time)
* @return true if something is removed, false otherwise
*/
public boolean delMetadata(String key) {
return metadata.remove(key);
}
public void setMetadata(String key, T dimensionInfo) {
metadata.set(key, dimensionInfo.getRoot());
}
public void addKeyword(String keyword) {
@ -76,6 +98,25 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
el.setText(keyword);
keywordsListEncoder.addContent(el);
}
/**
* delete a keyword from the list
* @param keyword
* @return true if something is removed, false otherwise
*/
public boolean delKeyword(final String keyword) {
final Element el = new Element("string");
el.setText(keyword);
return (keywordsListEncoder.removeContent(new Filter() {
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (((Element)obj).getText().equals(keyword)){
return true;
}
return false;
}
})).size()==0?false:true;
}
/**
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
@ -89,7 +130,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
*
* @deprecated use the setProjectionPolicy. <br>
* This method will be set as private in the next release
* This method will be set as protected in the next release
*/
public void addProjectionPolicy(ProjectionPolicy policy) {
add(PROJECTIONPOLICY, policy.toString());
@ -102,13 +143,12 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
set(PROJECTIONPOLICY, policy.toString());
}
private final static String NAME="name";
/**
* Add the 'name' node with a text value from 'name'
*
* @note REQUIRED to configure a resource
* @deprecated use the setName. <br>
* This method will be set as private in the next release
* This method will be set as protected in the next release
*/
public void addName(final String name) {
add(NAME, name);
@ -127,7 +167,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
* Add the 'title' node with a text value from 'title'
*
* @deprecated use the setTitle. <br>
* This method will be set as private in the next release
* This method will be set as protected in the next release
*/
public void addTitle(final String title) {
add(TITLE, title);
@ -145,7 +185,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
* Add the 'SRS' node with a text value from 'srs'
*
* @deprecated use the setSRS. <br>
* This method will be set as private in the next release
* This method will be set as protected in the next release
*/
public void addSRS(final String srs) {
add(SRS, srs);
@ -166,7 +206,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
/**
* @deprecated use the setSRS. <br>
* This method will be set as private in the next release
* This method will be set as protected in the next release
*
* @param minx
* @param maxy
@ -200,7 +240,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
/**
* @deprecated use the setSRS. <br>
* This method will be set as private in the next release
* This method will be set as protected in the next release
*
* @param minx
* @param maxy

View File

@ -27,6 +27,7 @@ package it.geosolutions.geoserver.rest.encoder;
import org.jdom.Element;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
/**
@ -35,13 +36,15 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/
public class GSWorkspaceEncoder extends PropertyXMLEncoder {
public final static String WORKSPACE="workspace";
public final static String NAME="name";
public GSWorkspaceEncoder() {
super("workspace");
super(WORKSPACE);
}
public GSWorkspaceEncoder(String name) {
super("workspace");
super(WORKSPACE);
addName(name);
}
@ -49,11 +52,12 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
* Add the name to this workspace
* @param name
* @throws IllegalStateException if name is already set
* @deprecated will be set to protected in the next release
*/
public void addName(String name) {
final Element el=contains("name");
final Element el=ElementUtils.contains(getRoot(),NAME);
if (el==null)
add("name", name);
add(NAME, name);
else
throw new IllegalStateException("Workspace name is already set: "+el.getText());
}
@ -63,15 +67,15 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
* @param name
*/
public void setName(String name) {
final Element el=contains("name");
final Element el=ElementUtils.contains(getRoot(),NAME);
if (el==null)
add("name", name);
add(NAME, name);
else
el.setText(name);
}
public String getName(){
final Element el=contains("name");
final Element el=ElementUtils.contains(getRoot(),NAME);
if (el!=null)
return el.getTextTrim();
else

View File

@ -28,8 +28,6 @@ package it.geosolutions.geoserver.rest.encoder.coverage;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import org.jdom.Element;
/**
* Creates an XML

View File

@ -24,9 +24,13 @@
*/
package it.geosolutions.geoserver.rest.encoder.coverage;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
import java.util.Iterator;
import org.jdom.Element;
import org.jdom.filter.Filter;
/**
*
@ -35,70 +39,191 @@ import org.jdom.Element;
*/
public class GSImageMosaicEncoder extends GSCoverageEncoder {
final private static String STRING="string";
final private static String ENTRY="entry";
final private NestedElementEncoder parameters=new NestedElementEncoder("parameters");
public GSImageMosaicEncoder() {
// Link members to the parent
addContent(parameters.getRoot());
}
static class parametersFilter implements Filter {
final String name;
public parametersFilter(final String name){
this.name=name;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (obj instanceof Element) {
if (((Element)obj).getName().equals(ENTRY)){
final Element el=((Element)obj).getChild(STRING);
if (el.getText().equals(this.name)){
return true;
}
}
}
return false;
}
};
private final boolean removeParameter(final Filter filter){
final Iterator<Element> it=ElementUtils.search(getRoot(), filter).iterator();
if (it.hasNext()){
final Element el=it.next();
// if (it.hasNext())
// return false;
// else
return ElementUtils.remove(el,el);
}
return false;
}
private final static String allowMultithreading="AllowMultithreading";
/**
* @deprecated will be set to protected in the next release
* @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"));
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);
}
private final static Filter allowMultithreadingFilter=new parametersFilter(allowMultithreading);
public void setAllowMultithreading(final boolean val){
removeParameter(allowMultithreadingFilter);
addAllowMultithreading(val);
}
private final static String filter="Filter";
/**
* @deprecated will be set to protected in the next release
* @param val
*/
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));
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(filter));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
}
private final static Filter filterFilter=new parametersFilter(filter);
public void setFilter(final String val){
removeParameter(filterFilter);
addFilter(val);
}
private final static String maxAllowedTiles="MaxAllowedTiles";
/**
* @deprecated will be set to protected in the next release
* @param val
*/
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)));
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);
}
private final static Filter maxAllowedTilesFilter=new parametersFilter(maxAllowedTiles);
public void setMaxAllowedTiles(final int val){
removeParameter(maxAllowedTilesFilter);
addMaxAllowedTiles(val);
}
private final static String inputTransparentColor="InputTransparentColor";
/**
* @deprecated will be set to protected in the next release
* @param val
*/
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));
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(inputTransparentColor));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
}
private final static Filter inputTransparentColorFilter=new parametersFilter(inputTransparentColor);
public void setInputTransparentColor(final String val){
removeParameter(inputTransparentColorFilter);
addInputTransparentColor(val);
}
private final static String outputTransparentColor="OutputTransparentColor";
/**
* @deprecated will be set to protected in the next release
* @param val
*/
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));
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(outputTransparentColor));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
}
private final static Filter outputTransparentColorFilter=new parametersFilter(outputTransparentColor);
public void setOutputTransparentColor(final String val){
removeParameter(outputTransparentColorFilter);
addInputTransparentColor(val);
}
private final static String SUGGESTED_TILE_SIZE="SUGGESTED_TILE_SIZE";
/**
*
* @param val
* @deprecated will be set to protected in the next release
*/
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));
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);
}
private final static Filter SUGGESTED_TILE_SIZEFilter=new parametersFilter(SUGGESTED_TILE_SIZE);
public void setSUGGESTED_TILE_SIZE(final String val){
removeParameter(SUGGESTED_TILE_SIZEFilter);
addSUGGESTED_TILE_SIZE(val);
}
private final static String USE_JAI_IMAGEREAD="USE_JAI_IMAGEREAD";
/**
* @deprecated will be set to protected in the next release
* @param val
*/
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"));
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);
}
private final static Filter USE_JAI_IMAGEREADFilter=new parametersFilter(USE_JAI_IMAGEREAD);
public void setUSE_JAI_IMAGEREAD(final boolean val){
removeParameter(USE_JAI_IMAGEREADFilter);
addUSE_JAI_IMAGEREAD(val);
}
private final static String backgroundValues="BackgroundValues";
/**
* @deprecated will be set to protected in the next release
* @param val
*/
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));
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(backgroundValues));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
}
private final static Filter backgroundValuesFilter=new parametersFilter(backgroundValues);
public void setBackgroundValues(final String val){
removeParameter(backgroundValuesFilter);
addBackgroundValues(val);
}
}

View File

@ -28,15 +28,25 @@ package it.geosolutions.geoserver.rest.encoder.feature;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
public class GSFeatureDimensionInfoEncoder extends GSDimensionInfoEncoder {
public final static String ATTRIBUTE="attribute";
/**
* if this dimension is enabled this constructor should be called.
* @param attribute the attribute to use as dimension
* @param attribute the attribute field name to use as dimension
*/
public GSFeatureDimensionInfoEncoder(final String attribute){
super(true);
add("attribute", attribute);
add(ATTRIBUTE, attribute);
}
/**
* Change the attribute used as dimension
* @param attribute the attribute to use as dimension
*/
public void setAttribute(final String attribute){
set(ATTRIBUTE, attribute);
}
}

View File

@ -29,15 +29,18 @@ import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
import java.math.BigDecimal;
import org.jdom.Element;
/**
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*
*/
public class GSDimensionInfoEncoder extends XmlElement{
final boolean enabled;
public final static String DIMENSIONINFO="dimensionInfo";
public final static String RESOLUTION="resolution";
public final static String PRESENTATION="presentation";
private boolean enabled;
/**
* Enum for presentation mode
@ -59,7 +62,7 @@ public class GSDimensionInfoEncoder extends XmlElement{
* @note a enabled dimension also need a presentation mode set.
*/
public GSDimensionInfoEncoder(final boolean enabled) {
super("dimensionInfo");
super(DIMENSIONINFO);
add("enabled", (enabled)?"true":"false");
this.enabled=enabled;
}
@ -68,30 +71,51 @@ public class GSDimensionInfoEncoder extends XmlElement{
* build an not enabled dimension
*/
public GSDimensionInfoEncoder() {
super("dimensionInfo");
super(DIMENSIONINFO);
add("enabled", "false");
this.enabled=Boolean.FALSE;
}
public void setEnabled(final boolean enabled){
set("enabled", "true");
this.enabled=Boolean.TRUE;
}
/**
* @deprecated will be set to protected in the next release {@link setPresentation(final Presentation pres)}
* @param pres
*/
public void addPresentation(final Presentation pres){
if (enabled){
add("presentation",pres.toString());
add(PRESENTATION,pres.toString());
}
}
public void setPresentation(final Presentation pres){
if (enabled){
set(PRESENTATION,pres.toString());
remove(RESOLUTION);
}
}
/**
* @param pres
* @param interval
* @deprecated will be set to protected in the next release {@link setPresentation(final PresentationDiscrete pres, final BigDecimal interval)}
*/
public void addPresentation(final PresentationDiscrete pres, final BigDecimal interval){
if (enabled){
add("presentation",pres.toString());
add("resolution",String.valueOf(interval));
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);
}
public void setPresentation(final PresentationDiscrete pres, final BigDecimal interval){
if (enabled){
set(PRESENTATION,pres.toString());
set(RESOLUTION,String.valueOf(interval));
}
}
}

View File

@ -29,12 +29,14 @@ import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
public class GSMetadataEncoder <T extends GSDimensionInfoEncoder> extends NestedElementEncoder{
public final static String METADATA="metadata";
public GSMetadataEncoder() {
super("metadata");
super(METADATA);
}
public void addMetadata(final String key, final T value) {
this.add(key, value.getRoot());
}
// public void addMetadata(final String key, final T value) {
// this.add(key, value.getRoot());
// }
}

View File

@ -25,72 +25,148 @@
package it.geosolutions.geoserver.rest.encoder.utils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import org.jdom.Element;
import org.jdom.filter.Filter;
/**
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*
*
*/
public abstract class ElementUtils {
/**
* Default logger
*/
private final static Logger LOGGER = Logger.getLogger(ElementUtils.class);
/**
*
* @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.
* @param root the root where to start searching to element to remove
* @param el the element to remove (will be set to null since this node is unusable after removal)
* @return true if the element EQUALS to the 'el' starting from root
* (including) is found, false if object 'el' is not found
*
*/
public static boolean remove(Element root, final Element el) {
public static boolean remove(final Element root, Element el) throws IllegalArgumentException {
if (root == null || el == null) {
throw new IllegalArgumentException("Bad arguments: root=" + root
+ " element=" + el);
}
// root is the element to remove
// note: equals checks references on Element type
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;
// detach
el.detach();
// removing all child
el.removeContent();
el=null;
return true;
}
return true;
// search for the element to remove
final Element search = ElementUtils.contains(root, el);
if (search != null) {
return remove(search, el);
}
return false;
}
/**
*
* @param root
* @param el
* @return the FIRST element EQUALS to the 'el' starting from root or null
* @param filter
* @param depth
* the max depth to search. Use {@link contains(final Element
* root, final Filter filter)} for an infinite depth search
* @return
* @throws IllegalArgumentException
*/
public static Element contains(final Element root, final Element el) {
public static List<Element> search(final Element root,
final Filter filter, final int depth)
throws IllegalArgumentException {
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;
if (root == null || filter == null || depth < 0) {
throw new IllegalArgumentException("Bad arguments: root=" + root
+ " filter=" + filter + " depth=" + depth);
}
final List<Element> ret = new ArrayList<Element>();
// if match add myself
if (filter.matches(root)) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("LOCATED-> name:" + root.getName() + " text:"
+ root.getText());
ret.add(root);
}
// check my children
if (depth > 1) {
final List<?> childrenList = root.getContent();
final Iterator<?> it = childrenList.iterator();
while (it.hasNext()) {
final Object obj = it.next();
if (obj instanceof Element) {
final Element childEl = (Element) obj;
ret.addAll(search(childEl, filter, depth - 1));
}
}
}
return null;
return ret;
}
public static List<Element> search(final Element root, final Filter filter) {
if (root == null || filter == null) {
throw new IllegalArgumentException("Bad arguments: root=" + root
+ " filter=" + filter);
}
final List<Element> ret = new ArrayList<Element>();
// if match add myself
if (filter.matches(root)) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("LOCATED-> name:" + root.getName() + " text:"
+ root.getText());
ret.add(root);
}
// navigate through children
final Iterator<?> it = root.getDescendants(filter);
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof Element) {
Element el = (Element) obj;
if (LOGGER.isDebugEnabled())
LOGGER.debug("LOCATED-> name:" + el.getName() + " text:"
+ el.getText());
ret.add(el);
}
}
return ret;
}
/**
* @param root
* @param name
* @param val
* @return the FIRST element matching the passed filter or null
*/
public static Element contains(final Element root, final Filter filter) throws IllegalArgumentException {
if (root == null || filter == null ) {
throw new IllegalArgumentException("Bad arguments: root=" + root
+ " name=" + filter);
}
final Iterator<Element> it = search(root, filter).iterator();
if (it.hasNext())
return it.next();
else
return null;
}
/**
* @param root
* @param name
@ -99,22 +175,29 @@ public abstract class ElementUtils {
* 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;
}
}
final String val) throws IllegalArgumentException {
if (root == null || name == null || val == null) {
throw new IllegalArgumentException("Bad arguments: root=" + root
+ " name=" + name + " val=" + val);
}
return null;
final Filter filter = new Filter() {
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (obj instanceof Element) {
final Element el = ((Element) obj);
if (el.getName().equals(name) && el.getText().equals(val)) {
return true;
}
}
return false;
}
};
final Iterator<Element> it = search(root, filter).iterator();
if (it.hasNext())
return it.next();
else
return null;
}
/**
@ -124,22 +207,67 @@ public abstract class ElementUtils {
* @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;
}
}
public static Element contains(final Element root, final String name)
throws IllegalArgumentException {
if (root == null || name == null) {
throw new IllegalArgumentException("Bad arguments: root=" + root
+ " name=" + name);
}
return null;
final Filter filter = new Filter() {
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (obj instanceof Element) {
final Element el = ((Element) obj);
if (el.getName().equals(name)) {
return true;
}
}
return false;
}
};
final Iterator<Element> it = search(root, filter).iterator();
if (it.hasNext())
return it.next();
else
return null;
}
/**
* @param root
* @param el
* @return the FIRST element EQUALS to the 'el' starting from root or null
* This tests for equality of this Content object to the supplied
* object. Content items are considered equal only if they are
* referentially equal (i.e. the same object).
*/
public static Element contains(final Element root, final Element el)
throws IllegalArgumentException {
if (root == null || el == null) {
throw new IllegalArgumentException("Bad arguments: root=" + root
+ " element=" + el);
}
final Filter filter = new Filter() {
/**
*
*/
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (obj instanceof Element) {
final Element element = ((Element) obj);
if (element.equals(el)) {
return true;
}
}
return false;
}
};
final Iterator<Element> it = search(root, filter).iterator();
if (it.hasNext())
return it.next();
else
return null;
}
}

View File

@ -25,7 +25,9 @@
package it.geosolutions.geoserver.rest.encoder.utils;
import org.jdom.Content;
import org.jdom.Element;
import org.jdom.filter.Filter;
/**
* Encodes lists of entries with key attribute. <br/>
@ -68,63 +70,102 @@ import org.jdom.Element;
*
*/
public class NestedElementEncoder extends XmlElement {
public final static String ENTRY = "entry";
public final static String KEY = "key";
static class NestedElementFilter implements Filter {
private static final long serialVersionUID = 1L;
private final String key;
private final Element root;
public NestedElementFilter(Element root, String key) {
this.key=key;
this.root=root;
}
public boolean matches(Object obj) {
if (obj instanceof Element) {
final Element el = ((Element) obj);
if (root.isAncestor(el)){
if (el.getName().equals(ENTRY)/* && el.getText().equals(value) */) {
if (key != null) {
if (el.getAttribute(KEY).getValue().equals(key))
return true;
else
return false;
}
return true;
}
}
}
return false;
}
};
public NestedElementEncoder(String listName) {
super(listName);
}
public void set(final String key, final String value) {
final Element entryElem = new Element("entry");
// public void set(final String key, final String value) {
// // if some previous similar object is found
// final Element search;
// if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
// // remove it
// ElementUtils.remove(getRoot(), search);
// }
// // add the new entry
// add(key,value);
// }
if (key != null) {
entryElem.setAttribute("key", key);
}
entryElem.setText(value);
final Element el = contains(entryElem);
if (el != null) {
addContent(entryElem);
}
// public void add(final String key, final Element value) {
// final Element entryElem = new Element(ENTRY);
// if (key != null)
// entryElem.setAttribute(KEY, key);
//
// entryElem.addContent(value);
//
// this.addContent(entryElem);
// }
// public void add(final String key, final String value) {
// final Element entryElem = new Element(ENTRY);
//
// if (key != null)
// entryElem.setAttribute(KEY, key);
//
// entryElem.setText(value);
//
// this.addContent(entryElem);
// }
public void add(final String key, final Content value) {
final Element entryElem = new Element(ENTRY);
if (key != null)
entryElem.setAttribute(KEY, key);
entryElem.setContent(value);
this.addContent(entryElem);
}
public void set(final String key, final Element value) {
final Element entryElem = new Element("entry");
if (key != null) {
entryElem.setAttribute("key", key);
public void set(final String key, final Content value) {
// if some previous similar object is found
final Element search;
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
// remove it
ElementUtils.remove(search, search);
}
entryElem.addContent(value);
final Element el = contains(entryElem);
if (el != null) {
addContent(entryElem);
} else {
if (remove(el))
addContent(entryElem);
// add the new entry
add(key,value);
}
public boolean remove(final String key){
// if some previous similar object is found
final Element search;
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
return ElementUtils.remove(search,search);
}
}
public void add(final String key, final String value) {
final Element entryElem = new Element("entry");
if (key != null)
entryElem.setAttribute("key", key);
entryElem.setText(value);
this.addContent(entryElem);
}
public void add(final String key, final Element value) {
final Element entryElem = new Element("entry");
if (key != null)
entryElem.setAttribute("key", key);
entryElem.addContent(value);
this.addContent(entryElem);
else
return false;
}
}

View File

@ -57,6 +57,7 @@ public class PropertyXMLEncoder extends XmlElement {
super(rootName);
}
public void set(final String key, final String value) {
if (key != null && value != null) {
set(getRoot(), key, value);
@ -64,15 +65,7 @@ public class PropertyXMLEncoder extends XmlElement {
}
private void set(final Element e, final String key, final String value){
if (!key.contains("/")) {
Element pp = null;
if ((pp = contains(key)) == null)
add(e,key, value);
else {
remove(pp);
add(e,key, value);
}
} else {
if (key.contains("/")) {
final int i = key.indexOf("/");
final String childName = key.substring(0, i);
final String newkey = key.substring(i + 1);
@ -83,7 +76,15 @@ public class PropertyXMLEncoder extends XmlElement {
e.addContent(child);
add(child,newkey,value);
}
set(child, newkey, value);
set(child, newkey, value);
} else {
Element pp = null;
if ((pp = ElementUtils.contains(e,key)) == null)
add(e,key, value);
else {
ElementUtils.remove(e,pp);
add(e,key, value);
}
}
}
@ -94,9 +95,7 @@ public class PropertyXMLEncoder extends XmlElement {
}
private void add(Element e, String key, String value) {
if (!key.contains("/")) {
e.addContent(new Element(key).setText(value));
} else {
if (key.contains("/")) {
final int i = key.indexOf("/");
final String childName = key.substring(0, i);
final String newkey = key.substring(i + 1);
@ -108,8 +107,66 @@ public class PropertyXMLEncoder extends XmlElement {
}
add(child, newkey, value);
} else {
e.addContent(new Element(key).setText(value));
}
}
// public void set(final String key, final String value) {
// if (key != null && value != null) {
// set(getRoot(), key, value);
// }
// }
//
// private void set(final Element e, final String key, final String value){
// if (!key.contains("/")) {
// Element pp = null;
// if ((pp = contains(key)) == null)
// add(e,key, value);
// else {
// remove(pp);
// add(e,key, value);
// }
// } else {
// final int i = key.indexOf("/");
// final String childName = key.substring(0, i);
// final 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);
// }
// set(child, newkey, value);
// }
// }
//
// public void add(final String key, final String value) {
// if (key != null && value != null) {
// add(this.getRoot(), key, value);
// }
// }
//
// 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);
//
// Element child = e.getChild(childName);
// if (child == null) {
// child = new Element(childName);
// e.addContent(child);
// }
//
// add(child, newkey, value);
// }
//
// }
}

View File

@ -28,6 +28,7 @@ package it.geosolutions.geoserver.rest.encoder.utils;
import org.jdom.Content;
import org.jdom.Element;
import org.jdom.Text;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
@ -40,9 +41,6 @@ public class XmlElement{
private final Element root;
/**
*
*/
private static final long serialVersionUID = 1L;
private final static XMLOutputter OUTPUTTER = new XMLOutputter(Format.getCompactFormat());
@ -55,9 +53,33 @@ public class XmlElement{
return root;
}
@SuppressWarnings("unused")
private XmlElement(){root=null;};
public void add(final String nodename, final String nodetext) {
add(nodename,new Text(nodetext));
}
public void add(final String nodename, final Content nodetext) {
final Element el=new Element(nodename);
el.setContent(nodetext);
this.addContent(el);
}
public void set(final String nodename, final String nodetext) {
set(nodename,new Text(nodetext));
}
public void set(final String nodename, final Content nodeContent) {
final Element el=ElementUtils.contains(getRoot(),nodename);
if (el==null){
add(nodename,nodeContent);
}
else {
el.setContent(nodeContent);
}
}
public Element addContent(Content child){
return root.addContent(child);
}
@ -66,20 +88,13 @@ public class XmlElement{
return root.getChildren().isEmpty();
}
public boolean remove(final Element el){
return ElementUtils.remove(root,el);
}
public Element contains(final Element el){
return ElementUtils.contains(root,el);
}
public Element contains(final String key, final String val){
return ElementUtils.contains(root,key,val);
}
public Element contains(final String key){
return ElementUtils.contains(root,key);
public boolean remove(final String key){
final Element el=ElementUtils.contains(root,key);
if (el!=null){
return ElementUtils.remove(root,el);
}
else
return false;
}
/**

View File

@ -110,6 +110,8 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
assertTrue(publisher.createWorkspace(wsName));
assertTrue(publisher.createWorkspace(wsName));
// creation test
boolean created = publisher.createPostGISDatastore(wsName, datastoreEncoder);

View File

@ -27,6 +27,8 @@ package it.geosolutions.geoserver.rest;
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -34,6 +36,8 @@ import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.jdom.Element;
import org.jdom.Namespace;
import org.springframework.core.io.ClassPathResource;
/**
@ -46,7 +50,6 @@ import org.springframework.core.io.ClassPathResource;
public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTPublisherTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
public GeoserverRESTPublisherTest(String testName) {
super(testName);
@ -84,7 +87,21 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
String sld = reader.getSLD(styleName);
assertNotNull(sld);
assertEquals(1475, sld.length());
Element styleEl = JDOMBuilder.buildElement(sld);
assertNotNull(styleEl);
Namespace SLDNS = Namespace.getNamespace("sld", "http://www.opengis.net/sld");
try{
assertEquals(styleName, styleEl.getChild("NamedLayer", SLDNS).getChild("Name",SLDNS).getText());
assertEquals("STYLE FOR TESTING PURPOSES", styleEl.getChild("NamedLayer", SLDNS).getChild("UserStyle", SLDNS).getChild("Title", SLDNS).getText());
} catch(NullPointerException npe) {
fail("Error in SLD");
}
// assertEquals(1475, sld.length());
assertEquals(1, reader.getStyles().size());
}
@ -134,6 +151,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
if (publisher.removeDatastore(ns, storeName)) {
LOGGER.info("Cleared stale datastore " + storeName);
}
assertFalse("Cleanup failed", existsLayer(layerName));
}
@ -154,18 +172,20 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
return;
}
// Assume.assumeTrue(enabled);
deleteAllWorkspaces();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
String ns = "it.geosolutions";
// String ns = "it.geosolutions";
String storeName = "resttestshp";
String layerName = "cities";
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
// known state?
cleanupTestFT(layerName, ns, storeName);
cleanupTestFT(layerName, DEFAULT_WS, storeName);
// test insert
boolean published = publisher.publishShp(ns, storeName, layerName, zipFile);
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile);
assertTrue("publish() failed", published);
assertTrue(existsLayer(layerName));
@ -174,12 +194,12 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
LOGGER.info("Layer style is " + layer.getDefaultStyle());
//test delete
boolean ok = publisher.unpublishFeatureType(ns, storeName, layerName);
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
assertTrue("Unpublish() failed", ok);
assertFalse(existsLayer(layerName));
// remove also datastore
boolean dsRemoved = publisher.removeDatastore(ns, storeName);
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
assertTrue("removeDatastore() failed", dsRemoved);
}
@ -190,7 +210,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
}
// Assume.assumeTrue(enabled);
String ns = "it.geosolutions";
String ns = "geosolutions";
String storeName = "resttestshp";
String layerName = "cities";
@ -320,6 +340,68 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
assertFalse("removed not existing datastore", ok);
}
public void testUpdateDefaultStyle() throws FileNotFoundException, IOException {
if (!enabled()) {
return;
}
String storeName = "resttestshp";
String layerName = "cities";
final String styleName = "restteststyle";
{
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
cleanupTestStyle(styleName);
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
assertTrue("style publish() failed", sldpublished);
assertTrue(reader.existsStyle(styleName));
}
final String styleName2 = "restteststyle2";
{
File sldFile = new ClassPathResource("testdata/restteststyle2.sld").getFile();
cleanupTestStyle(styleName2);
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
assertTrue("style publish() failed", sldpublished);
assertTrue(reader.existsStyle(styleName2));
}
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
// known state?
cleanupTestFT(layerName, DEFAULT_WS, storeName);
// test insert
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile, "EPSG:4326", styleName);
assertTrue("publish() failed", published);
assertTrue(existsLayer(layerName));
{
RESTLayer layer = reader.getLayer(layerName);
LOGGER.info("Layer style is " + layer.getDefaultStyle());
assertEquals(styleName, layer.getDefaultStyle());
}
GSLayerEncoder le = new GSLayerEncoder();
le.addDefaultStyle(styleName2);
publisher.configureLayer(DEFAULT_WS, layerName, le);
{
RESTLayer layer = reader.getLayer(layerName);
LOGGER.info("Layer style is " + layer.getDefaultStyle());
assertEquals(styleName2, layer.getDefaultStyle());
}
// remove layer and datastore
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
assertFalse(existsLayer(layerName));
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
assertTrue("removeDatastore() failed", dsRemoved);
}
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
// String wsName = "this_ws_does_not_exist";
// String storeName = "this_store_does_not_exist";

View File

@ -56,6 +56,8 @@ import org.apache.log4j.Logger;
public abstract class GeoserverRESTTest extends TestCase {
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTTest.class);
protected static final String DEFAULT_WS = "geosolutions";
public static final String RESTURL;
public static final String RESTUSER;
public static final String RESTPW;
@ -65,14 +67,15 @@ public abstract class GeoserverRESTTest extends TestCase {
public static final GeoServerRESTPublisher publisher;
private static boolean enabled = false;
private static Boolean existgs = null;
static {
RESTURL = System.getProperty("resturl", "http://localhost:8080/geoserver");
RESTUSER = System.getProperty("restuser", "admin");
RESTPW = System.getProperty("restpw", "geoserver");
RESTURL = getenv("gsmgr_resturl", "http://localhost:8080/geoserver");
RESTUSER = getenv("gsmgr_restuser", "admin");
RESTPW = getenv("gsmgr_restpw", "geoserver");
// These tests will destroy data, so let's make sure we do want to run them
enabled = System.getProperty("resttest", "false").equalsIgnoreCase("true");
enabled = getenv("gsmgr_resttest", "false").equalsIgnoreCase("true");
if( ! enabled )
LOGGER.warn("Tests are disabled. Please read the documentation to enable them.");
@ -87,6 +90,13 @@ public abstract class GeoserverRESTTest extends TestCase {
publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW);
}
private static String getenv(String envName, String envDefault) {
String env = System.getenv(envName);
String ret = System.getProperty(envName, env);
LOGGER.debug("env var " + envName + " is " + ret);
return ret != null? ret : envDefault;
}
public GeoserverRESTTest(String testName) {
super(testName);
}
@ -97,18 +107,23 @@ public abstract class GeoserverRESTTest extends TestCase {
super.setUp();
if(enabled) {
if( ! reader.existGeoserver()) {
System.out.println(getClass().getSimpleName() + ": TESTS WILL BE SKIPPED SINCE NO GEOSERVER WAS FOUND AT " + RESTURL + " ("+ RESTUSER+":"+RESTPW+")");
enabled = false;
} else {
System.out.println(getClass().getSimpleName() + ": using geoserver instance " + RESTUSER+":"+RESTPW+ " @ " + RESTURL);
if(existgs == null) {
existgs = reader.existGeoserver();
if ( ! existgs ) {
LOGGER.error("TESTS WILL FAIL BECAUSE NO GEOSERVER WAS FOUND AT " + RESTURL + " ("+ RESTUSER+":"+RESTPW+")");
} else {
LOGGER.info("Using geoserver instance " + RESTUSER+":"+RESTPW+ " @ " + RESTURL);
}
}
}
if(enabled)
if ( ! existgs ) {
System.out.println("Failing test " + this.getClass().getSimpleName() + "::" + this.getName() + " : geoserver not found");
fail("GeoServer not found");
}
System.out.println("\n-------------------> RUNNING TEST " + this.getName());
else
} else {
System.out.println("Skipping test " + this.getClass().getSimpleName() + "::" + this.getName());
}
}
protected boolean enabled() {
@ -201,7 +216,7 @@ public abstract class GeoserverRESTTest extends TestCase {
}
}
private void deleteAllWorkspaces() {
protected void deleteAllWorkspaces() {
List<String> workspaces = reader.getWorkspaceNames();
for (String workspace : workspaces) {
LOGGER.warn("Deleting Workspace " + workspace );

View File

@ -23,7 +23,9 @@ import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSMetadataEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import junit.framework.TestCase;
import org.apache.log4j.Logger;
@ -53,11 +55,11 @@ public class GSCoverageEncoderTest extends TestCase {
GSResourceEncoder<GSDimensionInfoEncoder> re=new GSCoverageEncoder();
re.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
Assert.assertNotNull(re.contains("projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString()));
Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString()));
re.setProjectionPolicy(ProjectionPolicy.NONE);
Assert.assertNull(re.contains("projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString()));
Assert.assertNotNull(re.contains("projectionPolicy",ProjectionPolicy.NONE.toString()));
Assert.assertNull(ElementUtils.contains(re.getRoot(),"projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString()));
Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"projectionPolicy",ProjectionPolicy.NONE.toString()));
}
/**
@ -68,12 +70,12 @@ public class GSCoverageEncoderTest extends TestCase {
GSResourceEncoder<GSDimensionInfoEncoder> re=new GSCoverageEncoder();
re.setLatLonBoundingBox(-180d, 90d, 180d, -90d, null);
Assert.assertNotNull(re.contains("minx","-180.0"));
Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"minx","-180.0"));
re.setLatLonBoundingBox(-90d, 45d, 180d, -90d, null);
Assert.assertNull(re.contains("minx","-180.0"));
Assert.assertNotNull(re.contains("minx","-90.0"));
Assert.assertNull(ElementUtils.contains(re.getRoot(),"minx","-180.0"));
Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"minx","-90.0"));
}
@Test
@ -83,33 +85,42 @@ public class GSCoverageEncoderTest extends TestCase {
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);
final GSDimensionInfoEncoder timeDimension=new GSDimensionInfoEncoder(true);
timeDimension.setPresentation(Presentation.CONTINUOUS_INTERVAL);
encoder.setMetadata("time", timeDimension);
if (LOGGER.isInfoEnabled())
LOGGER.info(encoder.toString());
final Element el=ElementUtils.contains(encoder.getRoot(),GSMetadataEncoder.METADATA);
Assert.assertNotNull(el);
LOGGER.info("contains_key:"+el.toString());
final GSDimensionInfoEncoder elevationDimension=new GSDimensionInfoEncoder(true);
elevationDimension.setPresentation(Presentation.LIST);
encoder.setMetadata("elevation", elevationDimension);
if (LOGGER.isInfoEnabled())
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");
final Element el2=ElementUtils.contains(encoder.getRoot(),GSDimensionInfoEncoder.PRESENTATION);
Assert.assertNotNull(el2);
LOGGER.info("contains_key:"+el2.toString());
final Element el3=encoder.contains(encoder.contains("metadata"));
encoder.delMetadata("time");
if (LOGGER.isInfoEnabled())
LOGGER.info(encoder.toString());
final Element el3=ElementUtils.contains(encoder.getRoot(),GSMetadataEncoder.METADATA);
Assert.assertNotNull(el3);
LOGGER.info("contains_by_node:"+el3.toString());
final boolean removed=encoder.remove(el3);
final boolean removed=ElementUtils.remove(encoder.getRoot(),el3);
LOGGER.info("remove:"+removed);
Assert.assertTrue(removed);
final Element el4=encoder.contains("metadata");
final Element el4=ElementUtils.contains(encoder.getRoot(),GSMetadataEncoder.METADATA);
Assert.assertNull(el4);
if (el4==null)
LOGGER.info("REMOVED");

View File

@ -19,13 +19,9 @@
*/
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;
/**
@ -45,41 +41,20 @@ public class GSImageMosaicEncoderTest extends TestCase {
@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());
encoder.setAllowMultithreading(false);
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());
encoder.addSUGGESTED_TILE_SIZE("512,512");
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");
}

View File

@ -0,0 +1,71 @@
package it.geosolutions.geoserver.rest.encoder.feature;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import java.math.BigDecimal;
import java.util.List;
import org.jdom.Element;
import org.jdom.filter.Filter;
import org.junit.Assert;
import org.junit.Test;
public class GSFeatureDimensionInfoEncoderTest {
@Test
public void dimensionTest() {
final GSFeatureDimensionInfoEncoder elevationDimension = new GSFeatureDimensionInfoEncoder(
"elevation_field");
// if (LOGGER.isInfoEnabled())
// LOGGER.info(encoder.toString());
elevationDimension.setPresentation(
PresentationDiscrete.DISCRETE_INTERVAL, BigDecimal.valueOf(10));
elevationDimension.setPresentation(
PresentationDiscrete.DISCRETE_INTERVAL, BigDecimal.valueOf(12));
List<Element> elList = ElementUtils.search(
elevationDimension.getRoot(), new Filter() {
public boolean matches(Object obj) {
if (obj instanceof Element) {
final Element el = ((Element) obj);
if (el.getName().equals(
GSDimensionInfoEncoder.DIMENSIONINFO)) {
return true;
}
}
return false;
}
});
// using set we get only one element called
// PresentationDiscrete.DISCRETE_INTERVAL
Assert.assertEquals(Integer.valueOf(elList.size()), Integer.valueOf(1));
elevationDimension.setPresentation(Presentation.LIST);
// this kind of presentation do not support a resolution parameter
elList = ElementUtils.search(
elevationDimension.getRoot(), new Filter() {
public boolean matches(Object obj) {
if (obj instanceof Element) {
final Element el = ((Element) obj);
if (el.getName().equals(
GSDimensionInfoEncoder.RESOLUTION)) {
return true;
}
}
return false;
}
});
Assert.assertEquals(Integer.valueOf(elList.size()), Integer.valueOf(0));
}
}

View File

@ -19,14 +19,21 @@
*/
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;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
import it.geosolutions.geoserver.rest.encoder.metadata.GSMetadataEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import java.math.BigDecimal;
import java.util.List;
import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.jdom.Element;
import org.jdom.filter.Filter;
import org.junit.Assert;
import org.junit.Test;
/**
@ -35,24 +42,103 @@ import org.junit.Test;
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/
public class GSFeatureEncoderTest extends TestCase {
protected final static Logger LOGGER = Logger.getLogger(GSFeatureEncoderTest.class);
public GSFeatureEncoderTest() {
}
@Test
public void testAll() {
GSFeatureTypeEncoder feature = new GSFeatureTypeEncoder();
feature.addKeyword("KEYWORD_1");
feature.addKeyword("KEYWORD_2");
feature.addKeyword("...");
feature.addKeyword("KEYWORD_N");
GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder(
"ELE");
GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder();
encoder.addKeyword("KEYWORD_1");
encoder.addKeyword("KEYWORD_2");
encoder.addKeyword("...");
encoder.addKeyword("KEYWORD_N");
GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder("ELE");
if (LOGGER.isInfoEnabled())
LOGGER.info(encoder.toString());
encoder.addMetadata("elevation", dim2);
dim2.addPresentation(PresentationDiscrete.DISCRETE_INTERVAL,
BigDecimal.valueOf(10));
feature.addMetadata("elevation", dim2);
Element el=ElementUtils.contains(encoder.getRoot(),GSDimensionInfoEncoder.PRESENTATION);
Assert.assertNotNull(el);
LOGGER.info("contains_key:"+el.toString());
dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL,
BigDecimal.valueOf(12));
el=ElementUtils.contains(encoder.getRoot(),GSDimensionInfoEncoder.RESOLUTION);
Assert.assertNotNull(el);
Assert.assertEquals("12", el.getText());
dim2.setPresentation(Presentation.CONTINUOUS_INTERVAL);
encoder.setMetadata("time", new GSFeatureDimensionInfoEncoder("time"));
el=ElementUtils.contains(encoder.getRoot(),GSDimensionInfoEncoder.PRESENTATION);
Assert.assertNotNull(el);
el=ElementUtils.contains(encoder.getRoot(),GSDimensionInfoEncoder.RESOLUTION);
Assert.assertNull(el);
// TODO TESTS
el=ElementUtils.contains(encoder.getRoot(),GSMetadataEncoder.METADATA);
Assert.assertNotNull(el);
LOGGER.info("contains_key:"+el.toString());
final boolean removed=ElementUtils.remove(encoder.getRoot(),el);
LOGGER.info("remove:"+removed);
Assert.assertTrue(removed);
el=ElementUtils.contains(encoder.getRoot(),"metadata");
Assert.assertNull(el);
if (el==null)
LOGGER.info("REMOVED");
}
@Test
public void testModifyFeature() {
GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder();
encoder.addKeyword("KEYWORD_1");
encoder.addKeyword("KEYWORD_2");
encoder.addKeyword("...");
encoder.addKeyword("KEYWORD_N");
Assert.assertTrue(encoder.delKeyword("KEYWORD_2"));
Assert.assertFalse(encoder.delKeyword("KEYWORD_M"));
final GSFeatureDimensionInfoEncoder elevationDimension = new GSFeatureDimensionInfoEncoder("elevation_field");
// if (LOGGER.isInfoEnabled())
// LOGGER.info(encoder.toString());
final String metadata="elevation";
encoder.setMetadata(metadata, elevationDimension);
elevationDimension.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL,
BigDecimal.valueOf(10));
if (LOGGER.isInfoEnabled())
LOGGER.info(encoder.toString());
Assert.assertTrue(encoder.delMetadata(metadata));
if (LOGGER.isInfoEnabled())
LOGGER.info(encoder.toString());
final Element el=ElementUtils.contains(encoder.getRoot(),GSDimensionInfoEncoder.DIMENSIONINFO);
Assert.assertNull(el);
if (el==null)
LOGGER.info("REMOVED");
}
}

View File

@ -0,0 +1,166 @@
package it.geosolutions.geoserver.rest.encoder.utils;
import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoderTest;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import org.jdom.Content;
import org.jdom.Element;
import org.jdom.filter.Filter;
import org.jdom.output.XMLOutputter;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class ElementUtilsTest {
/**
* Default logger
*/
protected final static Logger LOGGER = Logger.getLogger(ElementUtilsTest.class);
final static String NAME="TEST";
final Element root=new Element(NAME);
final int maxDepth=5;
final Filter filter=new Filter(){
public boolean matches(Object obj) {
if (obj instanceof Element){
if (((Element)obj).getName().equals(NAME)){
return true;
}
}
return false;
}
};
@Before
public void setUp() throws Exception {
root.addContent("1");
final Element child1=new Element(NAME);
child1.addContent("2");
final Element child2=new Element(NAME);
child2.addContent("3");
final Element child3=new Element(NAME);
child3.addContent("4");
final Element child4=new Element(NAME);
child4.addContent("5");
root.addContent(child1);
child1.addContent(child2);
child2.addContent(child3);
child3.addContent(child4);
}
@After
public void tearDown() throws Exception {
}
@Test
public void containsFilterDepthTest(){
LOGGER.info("STARTING-> containsFilterDepthTest");
final List<Element> list=ElementUtils.search(this.root, filter, 1);
Assert.assertEquals(1,list.size());
final List<Element> list2=ElementUtils.search(this.root, filter, 6);
Assert.assertEquals(maxDepth,list2.size());
final Filter myFilter=new Filter() {
public boolean matches(Object obj) {
if (obj instanceof Element){
final Element el=((Element)obj);
if (el.getName().equals(NAME)){
if (el.getText().equals("1") || el.getText().equals("3"))
return true;
}
}
return false;
}
};
final List<Element> list3=ElementUtils.search(this.root, myFilter, 3);
Assert.assertEquals(2,list3.size());
final Iterator<?> it=list3.iterator();
while (it.hasNext()){
final Object obj=it.next();
if (obj instanceof Element){
final Element el=(Element)obj;
LOGGER.info("LOCATED-> "+el.getName()+" level "+el.getText());
}
}
}
@Test
public void containsFilterTest(){
LOGGER.info("STARTING-> containsFilterTest");
final Iterator<?> it=ElementUtils.search(this.root, filter).iterator();
Assert.assertTrue("Elements found", it.hasNext());
int nFound=0;
while (it.hasNext()){
final Object obj=it.next();
if (obj instanceof Element){
nFound++;
Element el=(Element)obj;
LOGGER.info("LOCATED-> "+el.getName()+" level "+el.getText());
}
}
Assert.assertEquals(maxDepth,nFound);
}
@Test
public void containsWrappersTest(){
LOGGER.info("STARTING-> containsWrapperTest");
Element el=ElementUtils.contains(this.root, root);
Assert.assertNotNull(el);
el=ElementUtils.contains(this.root, new Element(NAME));
Assert.assertNull(el);
el=ElementUtils.contains(this.root, NAME);
Assert.assertNotNull(el);
el=ElementUtils.contains(this.root, "NOTFOUND");
Assert.assertNull(el);
el=ElementUtils.contains(this.root, NAME, "3");
Assert.assertNotNull(el);
el=ElementUtils.contains(this.root, NAME, "NOTFOUND");
Assert.assertNull(el);
}
@Test
public void removeTest(){
LOGGER.info("STARTING-> removeTest");
// contains
Element el=ElementUtils.contains(this.root, NAME, "4");
Assert.assertNotNull(el);
// remove
Assert.assertTrue(ElementUtils.remove(this.root, el));
// do not contains
el=ElementUtils.contains(this.root, el);
Assert.assertNull(el);
// XMLOutputter o=new XMLOutputter();
// try {
// o.output(root, System.out);
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
Assert.assertTrue(ElementUtils.remove(this.root, root));
}
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
<sld:NamedLayer>
<sld:Name>country</sld:Name>
<sld:UserStyle>
<sld:Name>restteststyle2</sld:Name>
<sld:Title>STYLE2 FOR TESTING PURPOSES</sld:Title>
<sld:Abstract>A sample style that just draws out a solid gray interior with a black 1px outline</sld:Abstract>
<sld:FeatureTypeStyle>
<sld:Name>name2</sld:Name>
<sld:FeatureTypeName>Feature</sld:FeatureTypeName>
<sld:SemanticTypeIdentifier>SemanticType[ANY]</sld:SemanticTypeIdentifier>
<sld:Rule>
<sld:Title>Polygon</sld:Title>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">
<ogc:Literal>#C8B679</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="fill-opacity">
<ogc:Literal>1.0</ogc:Literal>
</sld:CssParameter>
</sld:Fill>
<sld:Stroke>
<sld:CssParameter name="stroke">
<ogc:Literal>#000000</ogc:Literal>
</sld:CssParameter>
</sld:Stroke>
</sld:PolygonSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>