fixed bug: double STYLES in wms request
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gis-viewer@122519 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d231400d59
commit
7bc46f05e1
|
@ -872,7 +872,8 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
|
|||
String styles="";
|
||||
|
||||
if(layerItem.getStyle()!=null && !layerItem.getStyle().isEmpty()){
|
||||
styles = "&STYLES="+layerItem.getStyle();
|
||||
// styles = "&STYLES="+layerItem.getStyle();
|
||||
styles = layerItem.getStyle();
|
||||
}
|
||||
|
||||
String bbox = mapViewInfo.getLowerLeftX()
|
||||
|
@ -1172,14 +1173,14 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the layer by wms.
|
||||
* Extension of addLayerByWms, with input parameter is external layer
|
||||
*
|
||||
* by Francesco M.
|
||||
* @author Francesco Mangiacrapa
|
||||
*
|
||||
* @param layerType the layer type
|
||||
* @param layerTitle the title
|
||||
* @param layerTitle the layer title
|
||||
* @param layerName the layer name
|
||||
* @param wmsServiceBaseUrl the wms service base url
|
||||
* @param isExternal the is external
|
||||
|
@ -1235,7 +1236,6 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
|
|||
GWT.log("styles "+styles);
|
||||
|
||||
if(styles!=null && styles.size()>0){
|
||||
GWT.log("styles qui");
|
||||
l.setHasLegend(true);
|
||||
l.setDefaultStyle(styles.get(0));
|
||||
l.setStyle(styles.get(0));
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.google.gwt.core.shared.GWT;
|
|||
* Dec 4, 2015
|
||||
*/
|
||||
public class WmsUrlValidator {
|
||||
|
||||
|
||||
private HashMap<String, String> parametersValue = new HashMap<String, String>();
|
||||
private String wmsRequest;
|
||||
private String baseWmsServiceUrl;
|
||||
|
@ -49,91 +49,91 @@ public class WmsUrlValidator {
|
|||
*
|
||||
* @param returnEmptyParameter the return empty parameter
|
||||
* @param fillEmptyParameterAsDefaultValue the fill empty parameter as default
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public String parseWmsRequest(boolean returnEmptyParameter, boolean fillEmptyParameterAsDefaultValue) throws Exception{
|
||||
|
||||
|
||||
if(wmsParameters==null || wmsParameters.isEmpty()){
|
||||
String msg = "IT IS NOT POSSIBLE TO PARSE WMS URL, 'WMS PARAMETERS' not found!";
|
||||
GWT.log(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
|
||||
for (WmsParameters wmsParam : WmsParameters.values()) {
|
||||
|
||||
if(wmsParam.equals(WmsParameters.BBOX)){
|
||||
String value = validateValueOfParameter(WmsParameters.BBOX, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), value);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.FORMAT)){
|
||||
String value = validateValueOfParameter(WmsParameters.FORMAT, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), value);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.HEIGHT)){
|
||||
String value = validateValueOfParameter( WmsParameters.HEIGHT, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), value);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.CRS)){
|
||||
String crs = validateValueOfParameter(WmsParameters.CRS, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), crs);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.WIDTH)){
|
||||
String value = validateValueOfParameter(WmsParameters.WIDTH, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), value);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.REQUEST)){
|
||||
String value = validateValueOfParameter(WmsParameters.REQUEST, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), value);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.SERVICE)){
|
||||
String value = validateValueOfParameter(WmsParameters.SERVICE, wmsParameters,fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), value);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.SRS)){
|
||||
String value = validateValueOfParameter(WmsParameters.SRS, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), value);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.STYLES)){
|
||||
String styles = validateValueOfParameter(WmsParameters.STYLES, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), styles);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.VERSION)){
|
||||
String version = validateValueOfParameter(WmsParameters.VERSION, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), version);
|
||||
}
|
||||
|
||||
|
||||
if(wmsParam.equals(WmsParameters.LAYERS)){
|
||||
String layers = validateValueOfParameter(WmsParameters.LAYERS, wmsParameters, fillEmptyParameterAsDefaultValue);
|
||||
parametersValue.put(wmsParam.getParameter(), layers);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String parsedWmsRequest = baseWmsServiceUrl+"?";
|
||||
|
||||
|
||||
String[] params = wmsParameters.split("&");
|
||||
|
||||
|
||||
//CREATING MAP TO RETURN WMS PARAMETERS NOT STANDARD
|
||||
mapWmsNotStandardParams = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
||||
for (String param : params) {
|
||||
String key = param.substring(0, param.indexOf("="));
|
||||
String value = param.substring(param.indexOf("=")+1, param.length());
|
||||
mapWmsNotStandardParams.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
//CREATE WMS REQUEST
|
||||
for (String key : parametersValue.keySet()) {
|
||||
|
||||
|
||||
String value = parametersValue.get(key);
|
||||
if(returnEmptyParameter && value.isEmpty()){
|
||||
parsedWmsRequest+=key+"="+value;
|
||||
|
@ -142,23 +142,23 @@ public class WmsUrlValidator {
|
|||
parsedWmsRequest+=key+"="+value;
|
||||
parsedWmsRequest+="&";
|
||||
String exist = mapWmsNotStandardParams.get(key);
|
||||
|
||||
|
||||
if(exist!=null)
|
||||
mapWmsNotStandardParams.remove(key); //REMOVE WMS STANDARD PARAMETER FROM MAP
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (String key : mapWmsNotStandardParams.keySet()) {
|
||||
wmsNotStandardParameters+=key+"="+mapWmsNotStandardParams.get(key) + "&";
|
||||
}
|
||||
|
||||
|
||||
if(wmsNotStandardParameters.length()>0)
|
||||
wmsNotStandardParameters = wmsNotStandardParameters.substring(0, wmsNotStandardParameters.length()-1); //REMOVE LAST &
|
||||
|
||||
|
||||
GWT.log("wmsNotStandardParameters: "+wmsNotStandardParameters);
|
||||
|
||||
|
||||
String fullWmsUrlBuilded;
|
||||
|
||||
|
||||
if(!wmsNotStandardParameters.isEmpty()){
|
||||
fullWmsUrlBuilded = parsedWmsRequest + wmsNotStandardParameters; //remove last &
|
||||
GWT.log("full wms url builded + not wms standard parameters: "+fullWmsUrlBuilded);
|
||||
|
@ -166,10 +166,10 @@ public class WmsUrlValidator {
|
|||
fullWmsUrlBuilded = parsedWmsRequest.substring(0, parsedWmsRequest.length()-1); //remove last &
|
||||
GWT.log("full wms url builded: "+fullWmsUrlBuilded);
|
||||
}
|
||||
|
||||
|
||||
return fullWmsUrlBuilded;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the wmsRequest
|
||||
|
@ -177,7 +177,7 @@ public class WmsUrlValidator {
|
|||
public String getWmsRequest() {
|
||||
return wmsRequest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the baseWmsServiceUrl
|
||||
*/
|
||||
|
@ -215,13 +215,13 @@ public class WmsUrlValidator {
|
|||
* @return the string
|
||||
*/
|
||||
public static String validateValueOfParameter(WmsParameters wmsParam, String valueOfParameter, boolean fillEmptyParameterAsDefaultValue){
|
||||
|
||||
|
||||
try{
|
||||
|
||||
|
||||
String value = getValueOfParameter(wmsParam, valueOfParameter);
|
||||
|
||||
|
||||
if(fillEmptyParameterAsDefaultValue && (value==null || value.isEmpty())){
|
||||
GWT.log("setting empty value to wms parameter: "+wmsParam.getParameter() +", as default value: "+wmsParam.getValue());
|
||||
GWT.log("setting empty value for parameter: "+wmsParam.getParameter() +", as default value: "+wmsParam.getValue());
|
||||
value = wmsParam.getValue();
|
||||
}
|
||||
return value;
|
||||
|
@ -230,7 +230,7 @@ public class WmsUrlValidator {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value of parameter.
|
||||
*
|
||||
|
@ -244,15 +244,15 @@ public class WmsUrlValidator {
|
|||
// logger.trace("start index of "+wmsParam+ " is: "+index);
|
||||
String value = "";
|
||||
if(index > -1){
|
||||
|
||||
|
||||
int start = index + wmsParam.getParameter().length()+1; //add +1 for char '='
|
||||
String sub = wmsRequestParamaters.substring(start, wmsRequestParamaters.length());
|
||||
String sub = wmsRequestParamaters.substring(start, wmsRequestParamaters.length());
|
||||
int indexOfSeparator = sub.indexOf("&");
|
||||
int end = indexOfSeparator!=-1?indexOfSeparator:sub.length();
|
||||
value = sub.substring(0, end);
|
||||
}else
|
||||
return null;
|
||||
|
||||
|
||||
// logger.trace("return value: "+value);
|
||||
return value;
|
||||
}
|
||||
|
@ -270,10 +270,10 @@ public class WmsUrlValidator {
|
|||
public static String setValueOfParameter(WmsParameters wmsParam, String wmsRequestParameters, String newValue, boolean addIfNotExists){
|
||||
String toLowerWmsUrlParameters = wmsRequestParameters.toLowerCase();
|
||||
String toLowerWmsParam = wmsParam.getParameter().toLowerCase();
|
||||
|
||||
int index = toLowerWmsUrlParameters.indexOf(toLowerWmsParam+"="); //+ "=" SECURE TO BE PARAMETER
|
||||
|
||||
int index = toLowerWmsUrlParameters.indexOf(toLowerWmsParam+"="); //+ "=" SECURE TO BE PARAMETER
|
||||
// logger.trace("start index of "+wmsParam+ " is: "+index);
|
||||
if(index > -1){
|
||||
if(index > -1){
|
||||
int indexStartValue = index + toLowerWmsParam.length()+1; //add +1 for char '='
|
||||
int indexOfSeparator = toLowerWmsUrlParameters.indexOf("&", indexStartValue); //GET THE FIRST "&" STARTING FROM INDEX VALUE
|
||||
// logger.trace("indexOfSeparator index of "+wmsParam+ " is: "+indexOfSeparator);
|
||||
|
@ -286,28 +286,28 @@ public class WmsUrlValidator {
|
|||
// logger.trace("return value: "+value);
|
||||
return wmsRequestParameters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the styles as list.
|
||||
*
|
||||
* @return the styles as list
|
||||
*/
|
||||
public List<String> getStylesAsList() {
|
||||
|
||||
|
||||
List<String> listStyles = new ArrayList<String>();
|
||||
String styles = getValueOfParsedWMSParameter(WmsParameters.STYLES);
|
||||
|
||||
|
||||
if(styles!=null && !styles.isEmpty()){
|
||||
|
||||
|
||||
String[] arrayStyle = styles.split(",");
|
||||
for (String style : arrayStyle) {
|
||||
if(style!=null && !style.isEmpty())
|
||||
listStyles.add(style);
|
||||
}
|
||||
}
|
||||
}
|
||||
return listStyles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the map wms not standard params.
|
||||
*
|
||||
|
@ -317,15 +317,15 @@ public class WmsUrlValidator {
|
|||
return mapWmsNotStandardParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
|
||||
|
||||
// String baseGeoserverUrl = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows";
|
||||
// String baseGeoserverUrl = "http://www.fao.org/figis/geoserver/species";
|
||||
// String fullPath = "http://www.fao.org/figis/geoserver/species?SERVICE=WMS&BBOX=-176.0,-90.0,180.0,90&styles=Species_prob, puppa&layers=layerName&FORMAT=image/gif";
|
||||
|
@ -339,21 +339,19 @@ public class WmsUrlValidator {
|
|||
// logger.trace("style: "+validator.getStyles());
|
||||
// logger.trace("not standard parameter: "+validator.getWmsNotStandardParameters());
|
||||
// String[] arrayStyle = validator.getStyles().split(",");
|
||||
//
|
||||
//
|
||||
// if(arrayStyle!=null && arrayStyle.length>0){
|
||||
//
|
||||
//
|
||||
// for (String style : arrayStyle) {
|
||||
// if(style!=null && !style.isEmpty())
|
||||
//
|
||||
//
|
||||
// System.out.println("Style: "+style.trim());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
String fullPath = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
|
||||
// fullPath = WmsUrlValidator.setValueOfParameter(WmsParameters.STYLES, fullPath, "123", true);
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue