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

📄 cmslink.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            // if we have a local link, leave it unchanged
            // cms may be null for unit tests
            if ((cms == null) || (m_uri.length() == 0) || (m_uri.charAt(0) == '#')) {
                return m_uri;
            }

            checkConsistency(cms);

            CmsObjectWrapper wrapper = (CmsObjectWrapper)cms.getRequestContext().getAttribute(
                CmsObjectWrapper.ATTRIBUTE_NAME);
            if (wrapper != null) {
                // if an object wrapper is used, rewrite the URI
                m_uri = wrapper.rewriteLink(m_uri);
            }

            if ((cms.getRequestContext().getSiteRoot().length() == 0)
                && (cms.getRequestContext().getAttribute(CmsRequestContext.ATTRIBUTE_EDITOR) == null)) {
                // Explanation why this check is required:
                // If the site root name length is 0, this means that a user has switched
                // the site root to the root site "/" in the Workplace. 
                // In this case the workplace site must also be the active site. 
                // If the editor is opened in the root site, because of this code the links are 
                // always generated _with_ server name / port so that the source code looks identical to code
                // that would normally be created when running in a regular site.                
                // If normal link processing would be used, the site information in the link
                // would be lost.
                return OpenCms.getLinkManager().substituteLink(cms, m_uri);
            }

            // get the site root for this URI / link
            // if there is no site root, we either have a /system link, or the site was deleted,
            // return the full URI prefixed with the opencms context
            String siteRoot = getSiteRoot();
            if (siteRoot == null) {
                return OpenCms.getLinkManager().substituteLink(cms, m_uri);
            }

            if (cms.getRequestContext().getAttribute(CmsRequestContext.ATTRIBUTE_FULLLINKS) != null) {
                // full links should be generated even if we are in the same site
                return OpenCms.getLinkManager().getServerLink(cms, m_uri);
            }

            // return the link with the server prefix, if necessary 
            return OpenCms.getLinkManager().substituteLink(cms, getVfsUri(), siteRoot);
        } else {

            // don't touch external links
            return m_uri;
        }
    }

    /**
     * Returns the processed link.<p>
     * 
     * @param cms the current OpenCms user context, can be <code>null</code>
     * @param processEditorLinks this parameter is not longer used
     * 
     * @return the processed link
     * 
     * @deprecated use {@link #getLink(CmsObject)} instead, 
     *      the process editor option is set using the OpenCms request context attributes
     */
    public String getLink(CmsObject cms, boolean processEditorLinks) {

        return getLink(cms);
    }

    /**
     * Returns the macro name of this link.<p>
     * 
     * @return the macro name name of this link
     */
    public String getName() {

        return m_name;
    }

    /**
     * Returns the first parameter value for the given parameter name.<p>
     * 
     * @param name the name of the parameter
     * @return the first value for this name or <code>null</code>
     */
    public String getParameter(String name) {

        String[] p = (String[])getParameterMap().get(name);
        if (p != null) {
            return p[0];
        }

        return null;
    }

    /**
     * Returns the map of parameters of this link.<p>
     * 
     * @return the map of parameters (<code>Map(String[])</code>)
     */
    public Map getParameterMap() {

        if (m_parameters == null) {
            m_parameters = CmsRequestUtil.createParameterMap(m_query);
        }
        return m_parameters;
    }

    /**
     * Returns the set of available parameter names for this link.<p>
     * 
     * @return a <code>Set</code> of parameter names
     */
    public Set getParameterNames() {

        return getParameterMap().keySet();
    }

    /**
     * Returns all parameter values for the given name.<p>
     * 
     * @param name the name of the parameter
     * @return a <code>String[]</code> of all parameter values or <code>null</code>
     */
    public String[] getParameterValues(String name) {

        return (String[])getParameterMap().get(name);
    }

    /**
     * Returns the query of this link.<p>
     * 
     * @return the query or null if undefined
     */
    public String getQuery() {

        return m_query;
    }

    /**
     * Return the site root if the target of this link is internal, or <code>null</code> otherwise.<p>
     * 
     * @return the site root if the target of this link is internal, or <code>null</code> otherwise
     */
    public String getSiteRoot() {

        if (m_internal && (m_siteRoot == null)) {
            m_siteRoot = OpenCms.getSiteManager().getSiteRoot(m_target);
            if (m_siteRoot == null) {
                m_siteRoot = "";
            }
        }
        return m_siteRoot;
    }

    /**
     * The structure id of the linked resource.<p>
     * 
     * @return structure id of the linked resource
     */
    public CmsUUID getStructureId() {

        return m_structureId;
    }

    /**
     * Returns the target (destination) of this link.<p>
     * 
     * @return the target the target (destination) of this link
     */
    public String getTarget() {

        return m_target;
    }

    /**
     * Returns the type of this link.<p>
     * 
     * @return the type of this link
     */
    public CmsRelationType getType() {

        return m_type;
    }

    /**
     * Returns the raw uri of this link.<p>
     * 
     * @return the uri
     */
    public String getUri() {

        return m_uri;
    }

    /**
     * Returns the vfs link of the target if it is internal.<p>
     * 
     * @return the full link destination or null if the link is not internal.
     */
    public String getVfsUri() {

        if (m_internal) {
            String siteRoot = getSiteRoot();
            if (siteRoot != null) {
                return m_uri.substring(siteRoot.length());
            } else {
                return m_uri;
            }
        }

        return null;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {

        int result = m_type.hashCode();
        if (m_target != null) {
            result += m_target.hashCode();
        }
        return result;
    }

    /**
     * Returns if the link is internal.<p>
     * 
     * @return true if the link is a local link
     */
    public boolean isInternal() {

        return m_internal;
    }

    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {

        return m_uri;
    }

    /**
     * Updates the uri of this link with a new value.<p>
     * 
     * Also updates the structure of the underlying XML page document this link belongs to.<p> 
     * 
     * Note that you can <b>not</b> update the "internal" or "type" values of the link,
     * so the new link must be of same type (A, IMG) and also remain either an internal or external link.<p>
     * 
     * @param uri the uri to update this link with <code>scheme://authority/path#anchor?query</code>
     */
    public void updateLink(String uri) {

        // set the uri
        m_uri = uri;

        // update the components
        setComponents();

        // update the xml
        CmsLinkUpdateUtil.updateXml(this, m_element, true);
    }

    /**
     * Updates the uri of this link with a new target, anchor and query.<p>
     * 
     * If anchor and/or query are <code>null</code>, this features are not used.<p>
     * 
     * Note that you can <b>not</b> update the "internal" or "type" values of the link,
     * so the new link must be of same type (A, IMG) and also remain either an internal or external link.<p>
     * 
     * Also updates the structure of the underlying XML page document this link belongs to.<p> 
     * 
     * @param target the target (destination) of this link
     * @param anchor the anchor or null if undefined
     * @param query the query or null if undefined
     */
    public void updateLink(String target, String anchor, String query) {

        // set the components
        m_target = target;
        m_anchor = anchor;
        setQuery(query);

        // create the uri from the components
        setUri();

        // update the xml
        CmsLinkUpdateUtil.updateXml(this, m_element, true);
    }

    /**
     * Sets the component member variables (target, anchor, query) 
     * by splitting the uri <code>scheme://authority/path#anchor?query</code>.<p>
     */
    private void setComponents() {

        CmsUriSplitter splitter = new CmsUriSplitter(m_uri, true);
        m_target = splitter.getPrefix();
        m_anchor = splitter.getAnchor();
        setQuery(splitter.getQuery());
    }

    /**
     * Sets the query of the link.<p>
     * 
     * @param query the query to set.
     */
    private void setQuery(String query) {

        m_query = CmsLinkProcessor.unescapeLink(query);
        m_parameters = null;
    }

    /**
     * Joins the internal target, anchor and query components 
     * to one uri string, setting the internal uri and parameters fields.<p>
     */
    private void setUri() {

        StringBuffer uri = new StringBuffer(64);
        uri.append(m_target);
        if (m_query != null) {
            uri.append('?');
            uri.append(m_query);
        }
        if (m_anchor != null) {
            uri.append('#');
            uri.append(m_anchor);
        }
        m_uri = uri.toString();
    }
}

⌨️ 快捷键说明

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