diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 308dde3..5133431 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -3,7 +3,7 @@ - + uses diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/WmsRequestConverter.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/WmsRequestConverter.java index 686fe9f..5056c14 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/WmsRequestConverter.java +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/WmsRequestConverter.java @@ -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 styles; private boolean onTop = true; private ArrayList listStyles; private String wmsRequest; + private HashMap 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 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 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 noWms = urlValidator.getMapWmsNotStandardParams(); + this.noWMSParams = new HashMap(); + 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 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 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 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 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(); }