📄 resourceadder.java
字号:
package com.esri.solutions.jitk.web.tasks.resources;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import org.apache.axis.types.UnsignedByte;
import org.apache.log4j.Logger;
import com.esri.adf.web.ags.data.AGSLocalMapResource;
import com.esri.adf.web.ags.data.AGSMapFunctionality;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.ags.data.AGSUser;
import com.esri.adf.web.ags.data.query.AGSQueryFunctionality;
import com.esri.adf.web.ags.util.AGSUtil;
import com.esri.adf.web.aims.data.AIMSMapFunctionality;
import com.esri.adf.web.aims.data.AIMSMapResource;
import com.esri.adf.web.aims.data.query.AIMSQueryFunctionality;
import com.esri.adf.web.aws.data.AWSMapResource;
import com.esri.adf.web.aws.data.query.AWSQueryFunctionality;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebSpatialReference;
import com.esri.adf.web.wms.data.WMSMapResource;
import com.esri.arcgis.carto.IMap;
import com.esri.arcgis.carto.MapServer;
import com.esri.arcgis.geometry.ISpatialReference;
import com.esri.arcgisws.MapServerInfo;
import com.esri.arcgisws.MapServerPort;
import com.esri.arcgisws.RgbColor;
import com.esri.arcgisws.SpatialReference;
import com.esri.solutions.jitk.datasources.ogc.wcs.WCSHTTPClientBase;
import com.esri.solutions.jitk.datasources.ogc.wcs.info.WCSCapabilities;
import com.esri.solutions.jitk.datasources.ogc.wms.IWMSClient;
import com.esri.solutions.jitk.datasources.ogc.wms.WMSClient;
import com.esri.solutions.jitk.web.tasks.WebContextHolder;
import com.esri.solutions.jitk.web.wcs.data.WCSMapResource;
import com.esri.solutions.jitk.web.wfs.data.WFSMapResource;
public class ResourceAdder extends WebContextHolder {
private static final Logger _logger = Logger.getLogger(ResourceAdder.class);
public static String agsDomainParam = null;
public static String agsUsernameParam = null;
public static String agsPasswordParam = null;
public static String agsPasswordEncryptedParam = null;
public static String backgroundTransparentParam = null;
public static String projectMapToNewServiceParam = null;
public static String zoomToNewServiceExtentParam = null;
public ResourceAdder() {}
public void setWebContext(WebContext webContext){
super.setContext(webContext);
}
private boolean isWebContextInit() {
return (getContext() != null);
}
private String chkStr(String s, String defaultVal) {
s = (s == null) ? "" : s.trim();
return (s.length() == 0) ? defaultVal : s;
}
public GISResource addAgsSource(String agsHost,
String agsDomain,
String agsUsername,
String agsPassword,
boolean passwordEncrypted,
String agsServerObject,
boolean transparent,
boolean projectMap,
boolean zoomMap) {
List<String> hosts = new ArrayList<String>();
hosts.add(agsHost);
return addAgsSource(hosts, agsDomain, agsUsername, agsPassword, passwordEncrypted, agsServerObject, transparent, projectMap, zoomMap);
}
public GISResource addAgsSource(List<String> agsHosts,
String agsDomain,
String agsUsername,
String agsPassword,
boolean passwordEncrypted,
String agsServerObject,
boolean transparent,
boolean projectMap,
boolean zoomMap) {
AGSLocalMapResource resource = null;
FacesContext fc = null;
ValueBinding vb = null;
MapServer mapServer = null;
IMap map = null;
ISpatialReference ispatialRef = null;
WebSpatialReference webSpatialRef = null;
AGSMapFunctionality mapFunc = null;
if (!isWebContextInit()) {
throw new IllegalStateException("Before invoking this method, a web context must be set");
}
if (chkStr(agsServerObject, null) == null) {
_logger.warn("AGS Server Object cannot be null or empty - cannot add AGS Source. Returning null...");
return null;
}
if (agsHosts == null) {
_logger.warn("AGS Host cannot be null - cannot add AGS Source. Returning null...");
return null;
}
try {
fc = FacesContext.getCurrentInstance();
vb = fc.getApplication().createValueBinding("#{ags}");
resource = (AGSLocalMapResource) vb.getValue(fc);
resource.setUser(new AGSUser(chkStr(agsDomain, "*"), chkStr(agsUsername, null), chkStr(agsPassword, null), passwordEncrypted));
resource.setServerObjectName(agsServerObject);
resource.setHosts(agsHosts);
resource.setAlias(agsServerObject);
resource.addFunctionality("query", new AGSQueryFunctionality());
_webContext.addResource("agsJITK" + java.util.UUID.randomUUID().toString(), resource, 0);
// ADF issue. Only can get the MapServer after adding the resource to webcontext
mapServer = resource.getLocalMapServer();
map = mapServer.getMap(mapServer.getDefaultMapName());
ispatialRef = map.getSpatialReference();
int id = ispatialRef.getFactoryCode();
webSpatialRef = WebSpatialReference.getWebSpatialReference(id);
if (_webContext.getSpatialReference() == null) {
projectMap = true;
}
if ((webSpatialRef != null) && projectMap) {
_webContext.setSpatialReference(webSpatialRef);
}
mapFunc = (AGSMapFunctionality) resource.getFunctionality("map");
if(transparent) {
mapFunc.getMapDescription().setTransparentColor(mapFunc.getMapServerInfo().getBackgroundColor());
}
agsServerObject = "";
return resource;
} catch (Exception ex) {
agsServerObject = "";
_logger.warn("Unable to add AGS Local Resource", ex);
if (resource != null) {
_webContext.removeResource(resource);
}
return null;
}
}
public GISResource addArcWebSource( String awsAuthenticationURL,
String awsMapURL,
String awsDataSource,
String awsUserName,
String awsPassword,
boolean transparent,
boolean projectMap,
boolean zoomMap) {
AWSMapResource resource = null;
FacesContext fc = null;
ValueBinding vb = null;
if (!isWebContextInit()) {
throw new IllegalStateException("Before invoking this method, a web context must be set");
}
if (chkStr(awsAuthenticationURL, null) == null) {
_logger.warn("Authentication URL cannot be null - cannot add Arc Web Source - returning null");
return null;
}
if (chkStr(awsUserName, null) == null) {
_logger.warn("User name cannot be null - cannot add Arc Web Source - returning null");
return null;
}
try {
fc = FacesContext.getCurrentInstance();
vb = fc.getApplication().createValueBinding("#{arcweb}");
resource = (AWSMapResource) vb.getValue(fc);
resource.setAuthenticationEndPointURL(awsAuthenticationURL);
resource.setUserName(awsUserName);
resource.setPassword(awsPassword);
resource.setAlias(awsAuthenticationURL);
resource.setMapImageEndPointURL(awsMapURL);
resource.setDataSource(awsDataSource);
resource.addFunctionality("query", new AWSQueryFunctionality());
_webContext.addResource("arcWebJITK" + java.util.UUID.randomUUID().toString(), resource, 0);
return resource;
} catch (Exception ex) {
_logger.warn("Unable to add arcweb source", ex);
if (resource != null) {
_webContext.removeResource(resource);
}
return null;
}
}
public GISResource addAGSWSSource( String agswsURL,
String agswsName,
boolean transparent,
boolean projectMap,
boolean zoomMap) {
AGSMapResource resource = null;
FacesContext fc = null;
ValueBinding vb = null;
MapServerPort mapServer = null;
MapServerInfo mapServerInfo = null;
SpatialReference spatialRef = null;
WebSpatialReference webSpatialRef = null;
if (!isWebContextInit()) {
throw new IllegalStateException("Before invoking this method, a web context must be set");
}
if (chkStr(agswsURL, null) == null) {
_logger.warn("AGS URL cannot be null - cannot add AGS source - returning null");
return null;
}
try {
fc = FacesContext.getCurrentInstance();
vb = fc.getApplication().createValueBinding("#{agsweb}");
resource = (AGSMapResource) vb.getValue(fc);
resource.setEndPointURL(agswsURL);
resource.setAlias(agswsName);
resource.addFunctionality("query", new AGSQueryFunctionality());
_webContext.addResource("agsWebJITK" + java.util.UUID.randomUUID().toString(), resource, 0);
// ADF issue. Only can get the MapServerPort after adding the resource to webcontext
mapServer = resource.getMapServer();
mapServerInfo = mapServer.getServerInfo(mapServer.getDefaultMapName());
spatialRef = mapServerInfo.getSpatialReference();
webSpatialRef = AGSUtil.fromAGSSpatialReference(spatialRef);
if (_webContext.getSpatialReference() == null) {
projectMap = true;
}
if ((webSpatialRef != null) && projectMap) {
_webContext.setSpatialReference(webSpatialRef);
}
AGSMapFunctionality mapFunc = (AGSMapFunctionality) resource.getFunctionality("map");
if (transparent) {
RgbColor color = new RgbColor();
color.setRed(new UnsignedByte(255));
color.setGreen(new UnsignedByte(255));
color.setBlue(new UnsignedByte(255));
mapServerInfo.setBackgroundColor(color);
mapFunc.getMapDescription().setTransparentColor(color);
}
return resource;
} catch (Exception ex) {
_logger.warn("Unable to add AGS internet source", ex);
if (resource != null) {
_webContext.removeResource(resource);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -