1624: GeoExplorer: update "Add External WMS Layer"

Task-Url: https://support.d4science.org/issues/show/1624



git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gis-viewer-app@121756 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-12-10 15:12:46 +00:00
parent 257d0c89fb
commit 3ce40bcb6e
2 changed files with 138 additions and 54 deletions

View File

@ -3,7 +3,7 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<dependent-module archiveName="gis-viewer-3.6.2-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gis-viewer-PRIVATE/gis-viewer-PRIVATE"> <dependent-module archiveName="gis-viewer-3.9.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gis-viewer-TRUNK/gis-viewer-TRUNK">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/> <property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

View File

@ -4,18 +4,21 @@
package org.gcube.portlets.user.gisviewerapp.client; package org.gcube.portlets.user.gisviewerapp.client;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level; import java.util.HashMap;
import java.util.Map;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel; import org.gcube.portlets.user.gisviewer.client.GisViewerPanel;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel.LayerType; import org.gcube.portlets.user.gisviewer.client.GisViewerPanel.LayerType;
import org.gcube.portlets.user.gisviewerapp.shared.WmsParameters; import org.gcube.portlets.user.gisviewer.client.commons.utils.WmsUrlValidator;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
/** /**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * The Class WmsRequestConverter.
* @Oct 9, 2014
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Dec 10, 2015
*/ */
public class WmsRequestConverter { public class WmsRequestConverter {
@ -28,17 +31,27 @@ public class WmsRequestConverter {
private boolean isExternal = false; private boolean isExternal = false;
private boolean isBase = false; private boolean isBase = false;
private boolean displayInLayerSwitcher = false; private boolean displayInLayerSwitcher = false;
private ArrayList<String> styles;
private boolean onTop = true; private boolean onTop = true;
private ArrayList<String> listStyles; private ArrayList<String> listStyles;
private String wmsRequest; private String wmsRequest;
private HashMap<String, String> noWMSParams;
/** /**
* Instantiates a new wms request converter.
* *
* @param gisViewerPanel the gis viewer panel
*/ */
public WmsRequestConverter(GisViewerPanel gisViewerPanel) { public WmsRequestConverter(GisViewerPanel gisViewerPanel) {
this.gisViewer = gisViewerPanel; this.gisViewer = gisViewerPanel;
} }
/**
* Parses the request.
*
* @param wmsRequest the wms request
* @param displayName the display name
* @throws Exception the exception
*/
public void parseRequest(String wmsRequest, String displayName) throws Exception{ public void parseRequest(String wmsRequest, String displayName) throws Exception{
this.wmsRequest = wmsRequest; this.wmsRequest = wmsRequest;
@ -52,133 +65,202 @@ public class WmsRequestConverter {
// throw new Exception("Bad server request '?' not found!"); // throw new Exception("Bad server request '?' not found!");
} }
//FIND LAYERS NAME (AND TITLE) WmsUrlValidator urlValidator = new WmsUrlValidator(wmsRequest);
String value = getValueOfParameter(WmsParameters.LAYERS, wmsRequest); String layerName = urlValidator.getValueOfParsedWMSParameter(org.gcube.portlets.user.gisviewer.client.commons.utils.WmsParameters.LAYERS);
if(value==null || value.isEmpty()){
if(layerName==null || layerName.isEmpty()){
Window.alert("Bad wms request LAYER parameter not found!"); Window.alert("Bad wms request LAYER parameter not found!");
throw new Exception("Layer name not found!"); throw new Exception("Layer name not found!");
}else{ }else{
displayLayerName = value; displayLayerName = layerName;
title = value; title = layerName;
if(displayName!=null && !displayName.isEmpty()) if(displayName!=null && !displayName.isEmpty())
displayLayerName = displayName; displayLayerName = displayName;
} }
//FIND STILE this.listStyles = new ArrayList<String>();
listStyles = new ArrayList<String>(); String style = urlValidator.getValueOfParsedWMSParameter(org.gcube.portlets.user.gisviewer.client.commons.utils.WmsParameters.STYLES);
String style = getValueOfParameter(WmsParameters.STYLES, wmsRequest); this.listStyles.add(style);
listStyles.add(style);
Map<String, String> noWms = urlValidator.getMapWmsNotStandardParams();
this.noWMSParams = new HashMap<String, String>();
if(noWms!=null && noWms.size()>0){
this.noWMSParams.putAll(noWms);
}
} }
/**
* Adds the request to gis viewer.
*/
public void addRequestToGisViewer(){ public void addRequestToGisViewer(){
gisViewer.addLayerByWms(GisViewerPanel.LayerType.FEATURETYPE, displayLayerName, title, url, isExternal, isBase, displayInLayerSwitcher, listStyles, wmsRequest, onTop); gisViewer.addLayerByWms(GisViewerPanel.LayerType.FEATURETYPE, displayLayerName, title, url, isExternal, isBase, displayInLayerSwitcher, listStyles, wmsRequest, onTop, noWMSParams);
}
private String getValueOfParameter(WmsParameters wmsParam, String url){
ConstantGisViewerApp.logger.log(Level.INFO, "finding: "+wmsParam +" into "+url);
String urlLower = url.toLowerCase();
int index = urlLower.indexOf(wmsParam.getParameter().toLowerCase());
// 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 = url.substring(start, url.length());
int indexOfSeparator = sub.indexOf("&");
int end = indexOfSeparator!=-1?indexOfSeparator:sub.length();
value = sub.substring(0, end);
}
ConstantGisViewerApp.logger.log(Level.INFO, "return value: "+value);
return value;
} }
/**
* Gets the layer type.
*
* @return the layer type
*/
public LayerType getLayerType() { public LayerType getLayerType() {
return layerType; return layerType;
} }
/**
* Gets the title.
*
* @return the title
*/
public String getTitle() { public String getTitle() {
return title; return title;
} }
/**
* Gets the layer name.
*
* @return the layer name
*/
public String getLayerName() { public String getLayerName() {
return displayLayerName; return displayLayerName;
} }
/**
* Gets the url.
*
* @return the url
*/
public String getUrl() { public String getUrl() {
return url; return url;
} }
/**
* Checks if is external.
*
* @return true, if is external
*/
public boolean isExternal() { public boolean isExternal() {
return isExternal; return isExternal;
} }
/**
* Checks if is base.
*
* @return true, if is base
*/
public boolean isBase() { public boolean isBase() {
return isBase; return isBase;
} }
/**
* Checks if is display in layer switcher.
*
* @return true, if is display in layer switcher
*/
public boolean isDisplayInLayerSwitcher() { public boolean isDisplayInLayerSwitcher() {
return displayInLayerSwitcher; return displayInLayerSwitcher;
} }
public ArrayList<String> getStyles() { /**
return styles; * Checks if is on top.
} *
* @return true, if is on top
*/
public boolean isOnTop() { public boolean isOnTop() {
return onTop; return onTop;
} }
/**
* Gets the list styles.
*
* @return the list styles
*/
public ArrayList<String> getListStyles() { public ArrayList<String> getListStyles() {
return listStyles; return listStyles;
} }
/**
* Sets the layer type.
*
* @param layerType the new layer type
*/
public void setLayerType(LayerType layerType) { public void setLayerType(LayerType layerType) {
this.layerType = layerType; this.layerType = layerType;
} }
/**
* Sets the title.
*
* @param title the new title
*/
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }
/**
* Sets the layer name.
*
* @param layerName the new layer name
*/
public void setLayerName(String layerName) { public void setLayerName(String layerName) {
this.displayLayerName = layerName; this.displayLayerName = layerName;
} }
/**
* Sets the url.
*
* @param url the new url
*/
public void setUrl(String url) { public void setUrl(String url) {
this.url = url; this.url = url;
} }
/**
* Sets the external.
*
* @param isExternal the new external
*/
public void setExternal(boolean isExternal) { public void setExternal(boolean isExternal) {
this.isExternal = isExternal; this.isExternal = isExternal;
} }
/**
* Sets the base.
*
* @param isBase the new base
*/
public void setBase(boolean isBase) { public void setBase(boolean isBase) {
this.isBase = isBase; this.isBase = isBase;
} }
/**
* Sets the display in layer switcher.
*
* @param displayInLayerSwitcher the new display in layer switcher
*/
public void setDisplayInLayerSwitcher(boolean displayInLayerSwitcher) { public void setDisplayInLayerSwitcher(boolean displayInLayerSwitcher) {
this.displayInLayerSwitcher = displayInLayerSwitcher; this.displayInLayerSwitcher = displayInLayerSwitcher;
} }
public void setStyles(ArrayList<String> styles) { /**
this.styles = styles; * Sets the on top.
} *
* @param onTop the new on top
*/
public void setOnTop(boolean onTop) { public void setOnTop(boolean onTop) {
this.onTop = onTop; this.onTop = onTop;
} }
/**
* Sets the list styles.
*
* @param listStyles the new list styles
*/
public void setListStyles(ArrayList<String> listStyles) { public void setListStyles(ArrayList<String> listStyles) {
this.listStyles = listStyles; this.listStyles = listStyles;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -188,7 +270,7 @@ public class WmsRequestConverter {
builder.append(layerType); builder.append(layerType);
builder.append(", title="); builder.append(", title=");
builder.append(title); builder.append(title);
builder.append(", layerName="); builder.append(", displayLayerName=");
builder.append(displayLayerName); builder.append(displayLayerName);
builder.append(", url="); builder.append(", url=");
builder.append(url); builder.append(url);
@ -198,12 +280,14 @@ public class WmsRequestConverter {
builder.append(isBase); builder.append(isBase);
builder.append(", displayInLayerSwitcher="); builder.append(", displayInLayerSwitcher=");
builder.append(displayInLayerSwitcher); builder.append(displayInLayerSwitcher);
builder.append(", styles=");
builder.append(styles);
builder.append(", onTop="); builder.append(", onTop=");
builder.append(onTop); builder.append(onTop);
builder.append(", listStyles="); builder.append(", listStyles=");
builder.append(listStyles); builder.append(listStyles);
builder.append(", wmsRequest=");
builder.append(wmsRequest);
builder.append(", noWMSParams=");
builder.append(noWMSParams);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }