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

📄 adddatatask.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        super.requestTaskRender();

        this.errorMessage = ResourceProps.SUCCESS_MESSAGE;
        this.addServiceErrorMessage = null;

        Map<String, String> minfo = parseParams(getAddGISServerInfo());
        String mode = minfo.get("mode");

        if (mode.equalsIgnoreCase("AGSInternet")) {
            getAGSInternetServiceList(minfo);
        } else if (mode.equalsIgnoreCase("AGSLocal")) {
            getAGSLocalServiceList(minfo);
        } else if (mode.equalsIgnoreCase("AIMS")) {
            getAIMSServiceList(minfo);
        } else if (mode.equalsIgnoreCase("AWS")) {
            getAWSServiceList(minfo);
        } else if (mode.equalsIgnoreCase("WMS")) {
            getWMSServiceList(minfo);
        } else if (mode.equalsIgnoreCase("WFS")) {
            getWFSServiceList(minfo);
        } else if (mode.equalsIgnoreCase("WCS")) {
            getWCSServiceList(minfo);
        }
    }

    private Map<String, String> parseService(String service) {
        Map<String, String> serviceMap = new LinkedHashMap<String, String>();

        if ((service != null) && (service.length() > 0)) {
            String[] entries = service.split("!");

            for (int i = 0; i < entries.length; i++) {
                String[] entry = entries[i].split("\\*");

                if (entry.length == 2) {
                    serviceMap.put(entry[0], entry[1]);
                } else if (entry.length == 1) {
                    serviceMap.put(entry[0], "");
                }
            }
        }

        return serviceMap;
    }

    private String sort(String service) {
        if ((service.indexOf("!") != -1) && (service.indexOf("!") != service.lastIndexOf("!"))) {
            StringBuffer sb = new StringBuffer();
            Map<String, String> serviceMap = sort(parseService(service));

            for (java.util.Iterator<String> i = serviceMap.keySet().iterator(); i.hasNext();) {
                String sKey = i.next();
                sb.append(sKey);

                String sVal = serviceMap.get(sKey);

                if ((sVal != null) && (sVal.length() > 0)) {
                    sb.append("*").append(sVal);
                }

                sb.append("!");
            }

            return sb.toString();
        }

        return service;
    }

    private Map<String, String> sort(Map<String, String> unsortedMap) {
        Map<String, String> sortedMap = new LinkedHashMap<String, String>();

        if ((unsortedMap != null) && (unsortedMap.size() > 0)) {
            try {
                List<String> keys = new ArrayList<String>(unsortedMap.keySet());
                Collections.sort(keys);

                for (java.util.Iterator<String> i = keys.iterator(); i.hasNext();) {
                    String sKey = i.next();
                    sortedMap.put(sKey, sort(unsortedMap.get(sKey)));
                }
            } catch (Exception e) {
                _logger.warn("Unable to sort the service list.", e);

                return unsortedMap;
            }
        }

        return sortedMap;
    }

    public boolean isWCSServiceAddable(String svc) {
        boolean ret = false;

        String[] wcsArray = svc.split("\\*");
        URLBuilder wcsURL = null;

        if (wcsArray.length > 1) {
            wcsURL = new URLBuilder(wcsArray[0]);
        } else {
            wcsURL = new URLBuilder(svc);
        }

        String coverageName = wcsURL.getParam("coverage");
        wcsURL.removeParam("coverage");

        try {
            WCSMapResource wcsResource = (WCSMapResource) this.m_wcsMapResourceFactory.createResource();
            wcsResource.setWCSCapabilities(getWcsCapabilities(wcsURL.toString()));
            //wcsResource.setEndPointURL(wcsURL.toString());
            wcsResource.setCoverage(coverageName);
            wcsResource.initResource();
            ret = true;
        } catch (Exception e) {
            _logger.warn(TextResources.getResourceString(ResourceProps.ERROR_MESSAGE) + " WCS service " + wcsURL.toString() + ".", e);
            this.renderMessage(TextResources.getResourceString(ResourceProps.ERROR_MESSAGE) + " WCS service. " + e.getMessage());
        }

        return ret;
    }

    /**
     * Add services.
     */
    public void addServices(TaskEvent event) {
        _logger.info("Adding service to list of services to be added");
        super.requestTaskRender();

        this.errorMessage = ResourceProps.SUCCESS_MESSAGE;
        this.addServiceErrorMessage = null;

        String svcs = getAvailableServices();

        // svcList = host#service#checked!host#service#checked!...
        String[] svcList = svcs.split("!");

        for (int i = 0; i < svcList.length; i++) {
            String[] svcInfo = svcList[i].split("#");

            if (svcInfo.length > 2) {
                String host = svcInfo[0];
                String svc = svcInfo[1];

                if (host.indexOf("-OGC (WCS) Service") > 0) {
                    if (!isWCSServiceAddable(svc)) {
                        return;
                    }
                }

                if (selectedServiceList == null) {
                    selectedServiceList = new LinkedHashMap<String, String>();
                }

                String selSvcList = selectedServiceList.get(host);

                if (selSvcList == null) {
                    selSvcList = "";
                }

                selSvcList += (svc + "!");
                selectedServiceList.put(host, selSvcList);

                String avaSvcList = availableServiceList.get(host);
                int pos = avaSvcList.indexOf(svc);
                int lpos = avaSvcList.indexOf("!", pos + 1);

                String tstr = avaSvcList.substring(0, pos);

                if (lpos >= 0) {
                    tstr += avaSvcList.substring(lpos + 1, avaSvcList.length());
                }

                avaSvcList = tstr;

                if (avaSvcList.length() == 0) {
                    availableServiceList.remove(host);
                } else {
                    availableServiceList.put(host, avaSvcList);
                }
            }
        }
    }

    /**
     * Remove services.
     */
    public void removeServices(TaskEvent event) {
        super.requestTaskRender();
        _logger.info("Removing service from list of services to be added");

        this.errorMessage = ResourceProps.SUCCESS_MESSAGE;
        this.addServiceErrorMessage = null;

        String svcs = getSelectedServices();
        String[] svcList = svcs.split("!");

        for (int i = 0; i < svcList.length; i++) {
            String[] svcInfo = svcList[i].split("#");

            if (svcInfo.length > 2) {
                String host = svcInfo[0];
                String svc = svcInfo[1];

                if (availableServiceList == null) {
                    availableServiceList = new LinkedHashMap<String, String>();
                }

                String avaSvcList = availableServiceList.get(host);

                if (avaSvcList == null) {
                    avaSvcList = "";
                }

                avaSvcList += (svc + "!");
                availableServiceList.put(host, avaSvcList);

                String selSvcList = selectedServiceList.get(host);
                int pos = selSvcList.indexOf(svc);
                int lpos = selSvcList.indexOf("!", pos + 1);
                String tstr = selSvcList.substring(0, pos);

                if (lpos >= 0) {
                    tstr += selSvcList.substring(lpos + 1, selSvcList.length());
                }

                selSvcList = tstr;

                if (selSvcList.length() == 0) {
                    selectedServiceList.remove(host);
                } else {
                    selectedServiceList.put(host, selSvcList);
                }
            }
        }
    }

    private String[] parseHostInfoParams(String hostInfo) {
        int pos = hostInfo.indexOf("*");
        String params = hostInfo.substring(pos + 1, hostInfo.length());

        return params.split("&");
    }

    /*
     * avoid getting "=" as the parameter
     */
    private String[] splitParams(String param) {
        String[] params = new String[2];
        params[0] = param;
        params[1] = null;

        int pos = param.indexOf("=");

        if (pos >= 0) {
            params[0] = param.substring(0, pos);
            params[1] = param.substring(pos + 1, param.length());

            if (params[1].equals("")) {
                params[1] = null;
            }
        }

        return params;
    }

    private void restoreAvailableServices() {
        if ((this.selectedServiceList != null) && (this.selectedServiceList.size() > 0)) {
            for (java.util.Iterator<String> i = this.selectedServiceList.keySet().iterator(); i.hasNext();) {
                String url = i.next();

                String sServices = this.selectedServiceList.get(url);
                String aServices = this.availableServiceList.get(url);

                if (aServices == null) {
                    aServices = sServices;
                } else {
                    aServices += sServices;
                }

                this.availableServiceList.put(url, aServices);
            }

            this.selectedServiceList = null;
        }
    }

    private void addArcIMSResource(String svc, String[] paramArray) {
        String host = "";
        String port = "";
        String user = "";
        String pswd = "";

        for (int j = 0; j < paramArray.length; j++) {
            String[] param = splitParams(paramArray[j]);

            if (param[0].equalsIgnoreCase("host")) {
                host = param[1];
            }

            if (param[0].equalsIgnoreCase("port")) {
                port = param[1];
            }

            if (param[0].equalsIgnoreCase("user")) {
                user = param[1];
            }

            if (param[0].equalsIgnoreCase("pswd")) {
                pswd = param[1];
            }
        }

        if ((user != null) && user.equalsIgnoreCase("null")) {
            user = null;
        }

        if ((pswd != null) && pswd.equalsIgnoreCase("null")) {
            pswd = null;
        }

        AIMSMapResource aimsResource = (AIMSMapResource) m_aimsMapResourceFactory.createResource();
        aimsResource.setAlias(svc);
        aimsResource.setHostName(host);

        if (port != null) {
            aimsResource.setPort(Integer.valueOf(port).intValue());
        }

        aimsResource.setServiceName(svc);
        aimsResource.setUserName(user);
        aimsResource.setPassword(pswd);

        try {

⌨️ 快捷键说明

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