Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #47 from agueganno/sld-styles
Browse files Browse the repository at this point in the history
Fix the management of external SLD styles
  • Loading branch information
Bocher committed Jul 5, 2013
2 parents 7a3f5c3 + ea7d51d commit f64d7a0
Show file tree
Hide file tree
Showing 9 changed files with 483 additions and 238 deletions.
2 changes: 1 addition & 1 deletion app/wms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.orbisgis.server</groupId>
<artifactId>orbiswms-lib</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<name>orbiswms-lib</name>
<url>http://www.orbisgis.org</url>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.cts.crs.CRSException;
import org.cts.crs.CoordinateReferenceSystem;
import org.cts.registry.RegistryException;

/**
* Creates the answer to a getCapabilities request and writes it into the output
Expand Down Expand Up @@ -364,8 +363,11 @@ public void sourceAdded(SourceEvent e) {
}
layerMap.put(name, layer);
} catch (NoSuchTableException ex) {
LOGGER.error("Cannot find the data "+ name, ex);
} catch (DataSourceCreationException ex) {
LOGGER.error("Cannot find the data "+ name, ex);
} catch (DriverException ex) {
LOGGER.error("Cannot acces to the data "+ name, ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,20 @@ public void getFeatureInfo(GetFeatureInfoParameters params, OutputStream output,
params.getSld(), params.getExceptionsFormat(), output, wmsResponse, serverStyles);
int width = params.getWidth();
int height = params.getHeight();
int i = params.getI();
int j = params.getJ();

if(i<=0 || i>=width){
throw new WMSException("GetFeatureInfo request contains invalid I value. ");
}

if(j<=0 || j>=height){
throw new WMSException("GetFeatureInfo request contains invalid J value. ");
}

double[] bBox = params.getbBox();
DataSourceFactory dsf = Services.getService(DataManager.class).getDataSourceFactory();
Envelope env = getEnvelopeRequest(bBox,width, height, params.getI(), params.getJ());
Envelope env = getEnvelopeRequest(bBox,width, height, i, j);
ILayer[] children = layers.getChildren();
IndexManager im = dsf.getIndexManager();
for(ILayer c : children){
Expand Down
101 changes: 87 additions & 14 deletions app/wms/src/main/java/org/orbisgis/server/wms/GetMapParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,76 @@
* @author Alexis Guéganno.
*/
public class GetMapParameters {
/**
* Mandatory
*/
public static final String VERSION = "VERSION";
/**
* Mandatory
*/
public static final String REQUEST = "REQUEST";
/**
* Shall be present if SLD is absent, and absent if SLD is present
*/
public static final String LAYERS = "LAYERS";
/**
* Shall be present if SLD is absent, and absent if SLD is present
*/
public static final String STYLES = "STYLES";
/**
* Shall be present if STYLES and LAYERS are absent, and absent if STYLES and LAYERS are present
*/
public static final String SLD = "SLD";
/**
* Mandatory
*/
public static final String CRS = "CRS";
/**
* Mandatory
*/
public static final String BBOX = "BBOX";
/**
* Mandatory
*/
public static final String WIDTH = "WIDTH";
/**
* Mandatory
*/
public static final String HEIGHT = "HEIGHT";
/**
* Mandatory
*/
public static final String FORMAT = "FORMAT";
/**
* Optional
*/
public static final String TRANSPARENT = "TRANSPARENT";
/**
* Optional
*/
public static final String BGCOLOR = "BGCOLOR";
/**
* Optional
*/
public static final String EXCEPTIONS = "EXCEPTIONS";
/**
* Optional
*/
public static final String TIME = "TIME";
public static final String ELEVATION = "ELEVATION";
public static final Set<String> MANDATORY_PARAMETERS;

static {
Set<String> temp = new HashSet<String>();
temp.add(LAYERS);
temp.add(STYLES);
temp.add(BBOX);
temp.add(WIDTH);
temp.add(HEIGHT);
temp.add(FORMAT);
temp.add(CRS);
MANDATORY_PARAMETERS = Collections.unmodifiableSet(temp);
for(String s : MANDATORY_PARAMETERS){
System.out.println("Mandatory : "+s);
}
}


Expand Down Expand Up @@ -97,26 +140,53 @@ public GetMapParameters(Map<String, String[]> queryParameters) throws WMSExcepti
throw new WMSException("The following parameter is mandatory: "+s);
}
}
if(!qp.containsKey(SLD)){
if(!qp.containsKey(LAYERS) || !qp.containsKey(STYLES)){
throw new WMSException("Both layers and styles must be defined when SLD is absent");
}
} else {
if(qp.containsKey(LAYERS) || qp.containsKey(STYLES)){
throw new WMSException("Both layers and styles must not be defined when SLD is present");
}
}

crs = qp.get(CRS)[0];
bBox = parseBBox(qp.get(BBOX)[0]);
width = parseInteger(qp.get(WIDTH)[0]);
height = parseInteger(qp.get(HEIGHT)[0]);
layerList = parseLayers(qp.get(LAYERS)[0]);
if (!qp.get(STYLES)[0].isEmpty()) {
styleList = qp.get(STYLES)[0].split(",");
} else {
styleList = new String[0];
if(width<=0 || height<=0){
throw new WMSException("The width and the height must be greater than 0.");
}
if(qp.containsKey(LAYERS)){
layerList = parseLayers(qp.get(LAYERS)[0]);
}
if(qp.containsKey(STYLES)){
if (!qp.get(STYLES)[0].isEmpty()) {
styleList = qp.get(STYLES)[0].split(",");
} else {
styleList = new String[0];
}
}

if (qp.containsKey("PIXELSIZE")) {
pixelSize = Double.valueOf(qp.get("PIXELSIZE")[0]);
try{
pixelSize = Double.valueOf(qp.get("PIXELSIZE")[0]);
} catch(NumberFormatException nfe){
throw new WMSException("The pixel size must be a double value.", nfe);
}
}
if (pixelSize<=0){
throw new WMSException("The pixel siz must be greater than 0.");
}

imageFormat = qp.get(FORMAT)[0];

if (qp.containsKey(TRANSPARENT)) {
transparent = Boolean.valueOf(qp.get(TRANSPARENT)[0]);
try {
transparent = Boolean.valueOf(qp.get(TRANSPARENT)[0]);
} catch (NumberFormatException nfe) {
throw new WMSException("The transparent parameter must be expressed with true or false terms.", nfe);
}
}

if (qp.containsKey(BGCOLOR)) {
Expand Down Expand Up @@ -164,12 +234,15 @@ protected final int parseInteger(String s) throws WMSException{
} catch (NumberFormatException nfe){
throw new WMSException("The given int value is not valid: "+s, nfe);
}
}
}


/**
* Parses s as an array of comma separated doubles, transforming the potential NumberFormatException in a WMSException
* We want a BBOx, so there shall be exactly four double values.
* Parses s as an array of comma separated doubles, transforming the potential
* NumberFormatException in a WMSException
* We want a BBox, so there shall be exactly four double values
* that represent minx, miny, maxx, maxy.
*
* @param s The input String
* @return The parsed array of double values
* @throws WMSException
Expand All @@ -195,15 +268,15 @@ private double[] parseBBox(String s) throws WMSException{
* @return A copy of the array of layers that must be queried
*/
public String[] getLayerList() {
return Arrays.copyOf(layerList, layerList.length);
return layerList != null ? Arrays.copyOf(layerList, layerList.length) : new String[0];
}

/**
* Gets a copy of the array of style used to draw the layers that must be queried
* @return A copy of the array of style used to draw the layers that must be queried
*/
public String[] getStyleList() {
return Arrays.copyOf(styleList, styleList.length);
return styleList!= null ? Arrays.copyOf(styleList, styleList.length) : new String[0];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ public void testComputeEnvelope() throws Exception {
//Upper left corner as geographic coordinate (20,50)
System.out.println(envelope);
assertTrue(envelope.equals(new Envelope(27,28,43,42)));
}
}

}
31 changes: 31 additions & 0 deletions app/wms/src/test/java/org/orbisgis/server/wms/ParametersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,27 @@ public void testInvalidWidth() throws Exception {
map.put("WIDTH", new String[]{"potato"});
mapBuildFail(map);
}

@Test
public void testInvalidWidth2() throws Exception {
Map<String, String[]> map= getMapMap();
map.put("WIDTH", new String[]{"0"});
mapBuildFail(map);
}

@Test
public void testInvalidHeight() throws Exception {
Map<String, String[]> map= getMapMap();
map.put("HEIGHT", new String[]{"potato"});
mapBuildFail(map);
}

@Test
public void testInvalidHeight2() throws Exception {
Map<String, String[]> map= getMapMap();
map.put("HEIGHT", new String[]{"0"});
mapBuildFail(map);
}

@Test
public void testInvalidLayerList() throws Exception {
Expand All @@ -199,6 +213,23 @@ public void testInvalidLayerList() throws Exception {
mapBuildFail(map);
}

@Test
public void testMapSLDAndStyles(){
Map<String, String[]> map= getMapMap();
map.put(GetMapParameters.SLD,new String[]{"sld"});
mapBuildFail(map);
}

@Test
public void testMapSLDAlone() throws Exception {
Map<String, String[]> map= getMapMap();
map.put(GetMapParameters.SLD,new String[]{"sld"});
map.remove(GetMapParameters.LAYERS);
map.remove(GetMapParameters.STYLES);
GetMapParameters params = new GetMapParameters(map);
assertTrue(params.getSld().equals("sld"));
}

private void missingMapParameter(String param){
Map<String, String[]> map= getMapMap();
map.remove(param);
Expand Down
Loading

0 comments on commit f64d7a0

Please sign in to comment.