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

📄 servicepropertiestask.java

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

import com.esri.adf.web.ags.data.AGSLocalMapResource;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.aims.data.AIMSMapResource;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.TocNode;
import com.esri.adf.web.data.TocNodeContent;
import com.esri.adf.web.data.TocResourceContent;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.geometry.WebSpatialReference;
import com.esri.adf.web.data.graphics.GraphicsResource;
import com.esri.adf.web.faces.event.TocEvent;
import com.esri.adf.web.wms.data.WMSMapResource;

import com.esri.solutions.jitk.common.contextmenus.ContextMenuItemTaskManager;
import com.esri.solutions.jitk.common.contextmenus.IContextMenuItemTask;
import com.esri.solutions.jitk.common.contextmenus.IResourceContextMenuItem;
import com.esri.solutions.jitk.common.resources.TextResources;
import com.esri.solutions.jitk.web.tasks.RenderControlledTask;
import com.esri.solutions.jitk.web.wcs.data.WCSMapResource;
import com.esri.solutions.jitk.web.wfs.data.WFSMapResource;

import org.apache.log4j.Logger;

import java.io.Serializable;

import java.util.List;
import java.util.ResourceBundle;

import javax.faces.model.SelectItem;


/**
 * Task to view the properties of a GIS Resource.  The Properties displayed
 * include an image preview, alias, type, connection info, spatial reference,
 * and username (if authentication is required).
 */
public class ServicePropertiesTask extends RenderControlledTask
    implements Serializable, IContextMenuItemTask, IResourceContextMenuItem {
    private static final Logger _logger = Logger.getLogger(ServicePropertiesTask.class);
    private static final long serialVersionUID = 2975681924435269858L;

    /**
     * Reference to the Context Menu Item Task Manager.  Will be used
     * to open the Task UI when the Context Menu Item is selected.
     */
    private ContextMenuItemTaskManager m_mgr;

    /**
     * Reference to the GIS Resource in which to display properties.
     */
    private GISResource m_res;

    /**
     * ID of the Task.  Needed for the implementation of
     * {@link IContextMenuItemTask}.
     */
    private String m_taskId;

    /**
     * Constructs a new <code>ServicePropertiesTask</code> and initialize
     * the Task Info bean.
     *
     * @see ServicePropertiesTaskInfo
     */
    public ServicePropertiesTask() {
        setTaskInfo(new ServicePropertiesTaskInfo());
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.contextmenus.IContextMenuItem#createSelectItem()
     */
    public SelectItem createSelectItem() {
        SelectItem item = new SelectItem();

        item.setLabel(TextResources.getResourceString(
                "servicePropsTask.ui.label.contextmenu"));
        item.setValue("serviceProperties");

        return item;
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.contextmenus.IContextMenuItem#handleContextMenuEvent(com.esri.adf.web.faces.event.TocEvent)
     */
    public void handleContextMenuEvent(TocEvent event) {
        _logger.debug("Context menu event received");
        this.requestTaskRender();

        TocNode node = event.getNode();
        TocNodeContent content = node.getContent();

        if ((content != null) && content instanceof TocResourceContent) {
            GISResource res = ((TocResourceContent) content).getResource();
            m_res = res;
            m_mgr.setOpen(this);
        }
    }

    /**
     * Returns the alias of the GIS Resource.  If the GIS Resource has
     * not been initialized, then a blank string will be returned.
     *
     * @return        Alias of GIS Resource
     */
    public String getGisResourceName() {
        if (m_res != null) {
            return m_res.getAlias();
        }

        return "";
    }

    /**
     * Returns the ID of the GIS Resource within the current
     * {@link WebContext}.  If the GIS Resource has not been
     * initialized or if it does not exist within the WebContext,
     * then <code>null</code> will be returned.
     *
     * @return        ID of GIS Resource.
     */
    public String getGisResourceId() {
        String id = this._context.getResourceId(m_res);

        return id;
    }

    /**
     * Sets the GIS Resource ID parameter.  Currently not implemented.
     *
     * @param id        ID of GIS Resource.
     */
    public void setGisResourceId(String id) {
    }

    /**
     * Returns the name property value of the current {@link WebContext}.
     * This value is needed for building a URL for the preview image.
     *
     * @return        Name property value of current {@link WebContext}.
     */
    public String getWebContextName() {
        return this._context.getName();
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.contextmenus.IContextMenuItemTask#getTaskId()
     */
    public String getTaskId() {
        return m_taskId;
    }

    /**
     * Sets the Task ID of this task.  This value must match the ID value
     * of the Task tag in the JSP page.  The Task ID is needed by the
     * Context Menu Item Task Manager in order to open the correct
     * Task Window.
     *
     * @param id        ID of the Task within the JSP page.
     */
    public void setTaskId(String id) {
        m_taskId = id;
    }

    /**
     * Sets the Context Menu Item Task Manager within this object.  The
     * Context Menu Item Task Manager is needed in order to set the
     * Task Window to open in the renderer.
     *
     * @param mgr        Context Menu Item Task Manager object.
     */
    public void setContextMenuItemTaskManager(ContextMenuItemTaskManager mgr) {
        m_mgr = mgr;
    }

    /**
     * Returns the connection string parameter for the GIS Resource.
     * The Connection String varies depending on the GIS Resource.  The
     * following table desribes the contents of the Connection String
     * for the various GIS Resources.
     *
     * <table border="1">
     *         <tr>
     *                 <th>GIS Resource Type</th>
     *                 <th>Connection String Contents</th>
     *         </tr>
     *         <tr>
     *                 <td>AGSLocalMapResource</td>
     *                 <td>Comma-delimited string of hosts value.</td>
     *  </tr>
     *  <tr>
     *          <td>AGSMapResource</td>
     *          <td>Endpoint URL of SOAP service</td>
     *  </tr>
     *  <tr>
     *          <td>AIMSMapResource (HTTP)</td>
     *          <td>Connector URL</td>
     *  </tr>
     *  <tr>
     *          <td>AIMSMapResource (TCP)</td>
     *          <td>hostname:port</td>
     *  </tr>
     *  <tr>
     *          <td>WMSMapResource</td>
     *          <td>GetCapabilities URL</td>
     *  </tr>
     *  <tr>
     *          <td>WCSMapResource</td>
     *          <td>GetCapabilities URL</td>
     *  </tr>
     *  <tr>
     *          <td>WFSMapResource</td>
     *          <td>GetCapabilities URL</td>
     *  </tr>
     * </table>
     *
     * @return        Connection String value.
     */
    public String getConnectionString() {
        StringBuilder sb = new StringBuilder();

        if (m_res instanceof AGSLocalMapResource) {
            AGSLocalMapResource agsRes = (AGSLocalMapResource) m_res;
            List<String> hosts = agsRes.getHosts();

            for (String host : hosts) {
                sb.append(host);
                sb.append(",");
            }

            sb.deleteCharAt(sb.length() - 1);
        } else if (m_res instanceof AGSMapResource) {
            AGSMapResource agsRes = (AGSMapResource) m_res;
            sb.append(agsRes.getEndPointURL());
        } else if (m_res instanceof AIMSMapResource) {
            AIMSMapResource aimsRes = (AIMSMapResource) m_res;

            if (aimsRes.getHostName().startsWith("http://")) {
                sb.append(aimsRes.getHostName());
            } else {
                sb.append(aimsRes.getHostName());
                sb.append(":");
                sb.append(aimsRes.getPort());
            }
        } else if (m_res instanceof WMSMapResource) {
            WMSMapResource wmsRes = (WMSMapResource) m_res;
            sb.append(wmsRes.getWmsURL());
        } else if (m_res instanceof WCSMapResource) {
            WCSMapResource wcsRes = (WCSMapResource) m_res;
            sb.append(wcsRes.getEndPointURL());
        } else if (m_res instanceof WFSMapResource) {
            WFSMapResource wfsRes = (WFSMapResource) m_res;
            sb.append(wfsRes.getEndPointURL());
        }

        return sb.toString();
    }

    /**
     * If the GIS Resource is an AIMSMapResource, this method returns
     * the Service Name value, otherwise, an empty string is returned.
     *
     * @return        ArcIMS Service Name or blank string.
     */
    public String getServiceName() {
        if (m_res instanceof AIMSMapResource) {
            AIMSMapResource aimsRes = (AIMSMapResource) m_res;

            return aimsRes.getServiceName();
        }

        return " ";
    }

    /**
     * Returns the formatted spatial reference description string of the GIS Resource.
     * Only the description is returned and not the full spatial reference WKT string.
     *
     * @return Spatial Reference Description string
     */
    public String getSpatialReference() {
        if ((m_res != null) && (m_res.getDefaultSpatialReference() != null)) {
            WebSpatialReference sr = m_res.getDefaultSpatialReference();

            String def = sr.getDefinitionString();
            String vstart = "\"";
            String[] vs = def.split(vstart);

            return vs[1];
        }

        return " ";
    }

    /**
     * Returns the human-readable type of GIS Resource.
     *
     * @return        Human-readable type of GIS Resource.
     */
    public String getServiceType() {
        ResourceBundle rb = _taskInfo.getResourceBundle();

        if (m_res instanceof AGSLocalMapResource) {
            return rb.getString(
                "servicePropsTask.ui.value.param.serviceType.agsLocal");
        } else if (m_res instanceof AGSMapResource) {
            return rb.getString(
                "servicePropsTask.ui.value.param.serviceType.ags");
        } else if (m_res instanceof AIMSMapResource) {
            AIMSMapResource aimsRes = (AIMSMapResource) m_res;

            if (aimsRes.getHostName().toLowerCase().startsWith("http://")) {
                return rb.getString(
                    "servicePropsTask.ui.value.param.serviceType.aims");
            }

            return rb.getString(
                "servicePropsTask.ui.value.param.serviceType.aimsTcp");
        } else if (m_res instanceof WMSMapResource) {
            return rb.getString(
                "servicePropsTask.ui.value.param.serviceType.wms");
        } else if (m_res instanceof WCSMapResource) {
            return rb.getString(
                "servicePropsTask.ui.value.param.serviceType.wcs");
        } else if (m_res instanceof WFSMapResource) {
            return rb.getString(
                "servicePropsTask.ui.value.param.serviceType.wfs");
        } else {
            return rb.getString(
                "servicePropsTask.ui.value.param.serviceType.unknown");
        }
    }

    /**
     * Returns the username used to connect to the GIS Resource if a username
     * was used.  If a username was not used, then a blank string is returned.
     *
     * @return Username used to connect to the GIS Resource or blank string.
     */
    public String getUser() {
        if (m_res instanceof AGSMapResource) {
            AGSMapResource agsRes = (AGSMapResource) m_res;

            if (agsRes.getUser() != null) {
                String userName = "";

                if ((agsRes.getUser().getDomain() != null) &&
                        !agsRes.getUser().getDomain().equalsIgnoreCase("null")) {
                    userName += (agsRes.getUser().getDomain() + "\\");
                }

                userName += agsRes.getUser().getUserName();

                return userName;
            }

            return " ";
        } else if (m_res instanceof AIMSMapResource) {
            AIMSMapResource aimsRes = (AIMSMapResource) m_res;

            return aimsRes.getUserName();
        } else {
            return " ";
        }
    }

    /*
     * (non-Javadoc)
     * @see com.esri.solutions.jitk.common.contextmenus.IResourceContextMenuItem#shouldDisplay(com.esri.adf.web.data.GISResource)
     */
    public boolean shouldDisplay(GISResource resource) {
        if (resource instanceof GraphicsResource) {
            return false;
        }

        return true;
    }
}

⌨️ 快捷键说明

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