⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resourceutil.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.web.event;

import org.apache.log4j.Logger;

import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.WebContext;
import com.esri.solutions.jitk.common.resources.TextResources;
import com.esri.solutions.jitk.datasources.ogc.ows.ServiceIdentification;
import com.esri.solutions.jitk.datasources.ogc.wfs.WFSCapabilities;
import com.esri.solutions.jitk.datasources.ogc.wfs.WFSClient;
import com.esri.solutions.jitk.web.tasks.resources.ResourceAdder;


public class ResourceUtil {
    private static Logger logger = Logger.getLogger(ResourceUtil.class.getName());

    public static boolean addMapResource(WebContext webContext, ResourceObject resourceObj) {
        
    	ResourceAdder resourceAdder = new ResourceAdder();
    	resourceAdder.setWebContext(webContext);
    	
        GISResource resource = null;

        try {
            
        	if(((resourceObj.getResourceType() != null) && resourceObj.getResourceType().equalsIgnoreCase("ags")) || (resourceObj.getResourceType() == null)) {
        		
        		if (resourceObj.getLocation().indexOf("http") < 0) {
                    int pos = resourceObj.getLocation().indexOf("/", 6);

                    if (pos < 0) {
                        return false;
                    }

                    String host = resourceObj.getLocation().substring(6, pos);
                    String svcObj = resourceObj.getLocation().substring(pos + 1, resourceObj.getLocation().length());
                    
                    resource = resourceAdder.addAgsSource(	host,
                    										resourceObj.getDomain(),
                    										resourceObj.getUsername(),
                    										resourceObj.getPassword(),
                    										resourceObj.getEncrypted(),
                    										svcObj,
                    										resourceObj.getTransparent(),
                    										resourceObj.getProjectMap(),
                    										resourceObj.getZoomMap());

                    if (resourceObj.getResourceType() != null || resource != null) {
                        return true;
                    }
                    
                } else {
                    
                	int pos = resourceObj.getLocation().indexOf("/services");
                    int pos1 = resourceObj.getLocation().indexOf("/", pos + 10);

                    if ((pos >= 0) && (pos1 >= 0)) {
                        String service = resourceObj.getLocation().substring(pos + 10, pos1);
                        
                        resource = resourceAdder.addAGSWSSource(resourceObj.getLocation(),
                                								service,
                                								resourceObj.getTransparent(),
                                								resourceObj.getProjectMap(),
                                								resourceObj.getZoomMap());

                        if((resourceObj.getResourceType() != null) || (resource != null)) {
                            return true;
                        }
                    }
                }
            }

            if (((resourceObj.getResourceType() != null) && resourceObj.getResourceType().equalsIgnoreCase("aims")) || (resourceObj.getResourceType() == null)) {
                
            	String username = resourceObj.getUsername();
                String password = resourceObj.getPassword();

                if (resourceObj.getResourceType() == null) {
                    username = null;
                    password = null;
                }

                if (resourceObj.getLocation().indexOf("http") < 0) {
                    int pos = resourceObj.getLocation().indexOf("/", 6);
                    if (pos < 0) {
                        return false;
                    }

                    String host = resourceObj.getLocation().substring(6, pos);
                    String service = resourceObj.getLocation().substring(pos + 1, resourceObj.getLocation().length());
                    String[] hostInfo = host.split(":");
                    String portNum = "5300";

                    if (hostInfo.length > 1) {
                        portNum = hostInfo[1];
                    }

                    host = hostInfo[0];

                    resource = resourceAdder.addAIMSSource(host, portNum, username, password, service, resourceObj.getTransparent(), resourceObj.getProjectMap(), resourceObj.getZoomMap());

                    if ((resourceObj.getResourceType() != null) || (resource != null)) {
                        return true;
                    }
                    
                } else {
                	
                    int pos = resourceObj.getLocation().lastIndexOf("/");
                    if (pos < 0) {
                        return false;
                    }

                    String host = resourceObj.getLocation().substring(0, pos);
                    String service = resourceObj.getLocation().substring(pos + 1, resourceObj.getLocation().length());
                    
                    resource = resourceAdder.addAIMSSource(host, "0", username, password, service, resourceObj.getTransparent(), resourceObj.getProjectMap(), resourceObj.getZoomMap());

                    if ((resourceObj.getResourceType() != null) || (resource != null)) {
                        return true;
                    }
                }
            }

            if (((resourceObj.getResourceType() != null) && resourceObj.getResourceType().equalsIgnoreCase("wms")) || (resourceObj.getResourceType() == null)) {
                
            	if (resourceObj.getLocation().indexOf("http") < 0) {
                    return false;
                }

                String wmsParam = resourceObj.getLocation();
                resource = resourceAdder.addWMSSource(wmsParam, resourceObj.getTransparent(), resourceObj.getProjectMap(), resourceObj.getZoomMap());

                if ((resourceObj.getResourceType() != null) || (resource != null)) {
                    return true;
                }
            }

            if (((resourceObj.getResourceType() != null) && resourceObj.getResourceType().equalsIgnoreCase("wcs")) || (resourceObj.getResourceType() == null)) {
                
            	if (resourceObj.getLocation().indexOf("http") < 0) {
                    return false;
                }

                String wcsParam = resourceObj.getLocation();
                resource = resourceAdder.addWCSSource(wcsParam, resourceObj.getTransparent(), resourceObj.getProjectMap(), resourceObj.getZoomMap());

                if ((resourceObj.getResourceType() != null) || (resource != null)) {
                    return true;
                }
            }
            
            // If the resource is a WFS
            if (((resourceObj.getResourceType() != null) && resourceObj.getResourceType().equalsIgnoreCase("wfs")) || (resourceObj.getResourceType() == null)) {
                
            	if (resourceObj.getLocation().indexOf("http") < 0) {
                    return false;
                }
                
                String url = resourceObj.getLocation();
            	WFSClient wfs = new WFSClient(url);
            	ServiceIdentification servId = null;
            	String title = null;
            	
            	// Get service title
            	try {
            		WFSCapabilities caps = wfs.getCapabilities();
            		servId = caps.getServiceIdentification();
            		
            		// If service has no service ID or title, use the service URL
            		title = servId != null ? servId.getTitle() : TextResources.getResourceString("servicePropsTask.ui.value.param.serviceType.wfs");
            		title = title.equalsIgnoreCase("") ? TextResources.getResourceString("servicePropsTask.ui.value.param.serviceType.wfs") : title;
            	
            	} catch (Exception ex) {
            		logger.warn("Could not get service title from WFS, using url", ex);
            	}
            	
            	title = (title != null) ? title : url;                
                resource = resourceAdder.addWFSSource(url, title, resourceObj.getProjectMap(), resourceObj.getZoomMap());

                if ((resourceObj.getResourceType() != null) || (resource != null)) {
                    return true;
                }
            }
        
        } catch (Exception e) {
            logger.error("Error in " + ResourcePhaseListener.class.getClass().getName(), e);
        }

        return false;
    }

    public static String checkResource(String resource, WebContext webContext, boolean zoom) throws Exception {
        
    	ResourceObject resourceObj = new ResourceObject(resource);
        resourceObj.setZoomMap(zoom);

        if (resourceObj.getFunctionalityType().equalsIgnoreCase("map")) {
            if (addMapResource(webContext, resourceObj)) {
                return "";
            }
        }

        return resourceObj.getLocation();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -