2020-10-23 18:18:06 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataviewer.server;
|
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2020-10-26 12:24:23 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerService;
|
2020-10-27 16:04:34 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoInformationForWMSRequest;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.Styles;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.ZAxis;
|
|
|
|
import org.gcube.spatial.data.geoutility.GeoNcWMSMetadataUtility;
|
|
|
|
import org.gcube.spatial.data.geoutility.bean.LayerStyles;
|
|
|
|
import org.gcube.spatial.data.geoutility.bean.LayerZAxis;
|
|
|
|
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2020-10-23 18:18:06 +02:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
2020-10-26 12:24:23 +01:00
|
|
|
public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet implements
|
|
|
|
GeoportalDataViewerService {
|
2020-10-27 16:04:34 +01:00
|
|
|
|
|
|
|
/** The Constant LOG. */
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerServiceImpl.class);
|
2020-10-23 18:18:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Escape an html string. Escaping data received from the client helps to
|
|
|
|
* prevent cross-site script vulnerabilities.
|
|
|
|
*
|
|
|
|
* @param html the html string to escape
|
|
|
|
* @return the escaped string
|
|
|
|
*/
|
|
|
|
private String escapeHtml(String html) {
|
|
|
|
if (html == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return html.replaceAll("&", "&").replaceAll("<", "<").replaceAll(
|
|
|
|
">", ">");
|
|
|
|
}
|
2020-10-27 16:04:34 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public GeoInformationForWMSRequest parseWmsRequest(String wmsRequest, String layerName) throws Exception{
|
|
|
|
return loadGeoInfoForWmsRequest(wmsRequest, layerName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load geo info for wms request.
|
|
|
|
*
|
|
|
|
* @param wmsRequest the wms request
|
|
|
|
* @param layerName the layer name
|
|
|
|
* @return the gis viewer wms valid parameters
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public static GeoInformationForWMSRequest loadGeoInfoForWmsRequest(String wmsRequest, String layerName) throws Exception{
|
|
|
|
try {
|
|
|
|
WMSUrlValidator validator = new WMSUrlValidator(wmsRequest, layerName);
|
|
|
|
String wmsServiceHost = validator.getWmsServiceHost();
|
|
|
|
String validWMSRequest = validator.parseWMSRequest(true, true);
|
|
|
|
layerName = validator.getLayerName();
|
|
|
|
String versionWms = validator.getValueOfParsedWMSParameter(WmsParameters.VERSION);
|
|
|
|
String crs = validator.getValueOfParsedWMSParameter(WmsParameters.CRS);
|
|
|
|
//
|
|
|
|
HashMap<String, String> mapWmsNotStandard = new HashMap<String, String>();
|
|
|
|
|
|
|
|
if(validator.getMapWmsNoStandardParams()!=null){
|
|
|
|
mapWmsNotStandard.putAll(validator.getMapWmsNoStandardParams());
|
|
|
|
}
|
|
|
|
//
|
|
|
|
GeoNcWMSMetadataUtility geoGS = new GeoNcWMSMetadataUtility(validWMSRequest, 4000);
|
|
|
|
//STYLES
|
|
|
|
LayerStyles layerStyle = geoGS.loadStyles();
|
|
|
|
Map<String,String> mapNcWmsStyles = layerStyle.getMapNcWmsStyles()==null?new HashMap<String, String>(1):layerStyle.getMapNcWmsStyles();
|
|
|
|
mapWmsNotStandard.putAll(mapNcWmsStyles);
|
|
|
|
//MAP STYLES INTO GWT-SERIALIZABLE OBJECT
|
|
|
|
Styles styles = new Styles(layerStyle.getGeoStyles(), layerStyle.getMapNcWmsStyles(), layerStyle.isNcWms());
|
|
|
|
//ZAxis
|
|
|
|
LayerZAxis layerZAxis = geoGS.loadZAxis();
|
|
|
|
//MAP ZAXIS INTO GWT-SERIALIZABLE OBJECT
|
|
|
|
ZAxis zAxis = layerZAxis!=null?new ZAxis(layerZAxis.getUnits(), layerZAxis.isPositive(), layerZAxis.getValues()):null;
|
|
|
|
|
|
|
|
return new GeoInformationForWMSRequest(wmsServiceHost, validWMSRequest, layerName, versionWms, crs, mapWmsNotStandard, styles, styles.isNcWms(), zAxis);
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
String msg = "An error occurred during wms request validation for layer: "+layerName;
|
|
|
|
LOG.error(msg,e);
|
|
|
|
throw new Exception(msg);
|
|
|
|
}
|
|
|
|
}
|
2020-10-23 18:18:06 +02:00
|
|
|
}
|