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