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

📄 cmsflexrequest.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param location URI to be (possibly) converted and then returned
     * @return the location converted to an absolut location
     */
    public String toAbsolute(String location) {

        if (DEBUG) System.err.println(getClass().getName() + " location=" + location);        
        if (location == null) return null;
        if (location.startsWith("/")) return location;

        // Construct a new absolute URL if possible (cribbed from Tomcat)
        java.net.URL url = null;
        try {
            url = new java.net.URL(location);
        } catch (java.net.MalformedURLException e1) {
            String requrl = getRequestURL().toString();
            try {
                url = new java.net.URL(new java.net.URL(requrl), location);
            } catch (java.net.MalformedURLException e2) {
                // Some other method will deal with that sooner or later
                return location;
            }
        }
        
        // Now check if this is a opencms resource and if so remove the context / servlet path
        String uri = url.getPath();
        String context = getContextPath() + getServletPath();
        if (uri.startsWith(context)) {
            uri = uri.substring(context.length());
        }
        if (url.getQuery() != null) uri += "?" + url.getQuery();                    
        
        if (DEBUG) System.err.println(getClass().getName() + " result=" + uri);                
        return uri;
    }     
            
    /**
     * Return the value of the specified request parameter, if any; otherwise,
     * return <code>null</code>.<p>
     * 
     * If there is more than one value defined,
     * return only the first one.<p>
     *
     * @param name the name of the desired request parameter
     * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
     */
    public String getParameter(String name) {

        String values[] = (String[]) m_parameters.get(name);
        if (values != null)
            return (values[0]);
        else
            return (null);
    }


    /**
     * Returns a <code>Map</code> of the parameters of this request.<p>
     * 
     * Request parameters are extra information sent with the request.
     * For HTTP servlets, parameters are contained in the query string
     * or posted form data.<p>
     *
     * @return a <code>Map</code> containing parameter names as keys
     *  and parameter values as map values
     * @see javax.servlet.ServletRequest#getParameterMap()
     */
    public Map getParameterMap() {
        return (this.m_parameters);
    }

    /**
     * Return the names of all defined request parameters for this request.<p>
     * 
     * @return the names of all defined request parameters for this request
     * @see javax.servlet.ServletRequest#getParameterNames()
     */
    public Enumeration getParameterNames() {
        java.util.Vector v = new java.util.Vector();
        v.addAll(m_parameters.keySet());
        return (v.elements());
    }

    /**
     * Returns the defined values for the specified request parameter, if any;
     * otherwise, return <code>null</code>.
     *
     * @param name Name of the desired request parameter
     * @return the defined values for the specified request parameter, if any;
     *          <code>null</code> otherwise
     * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
     */
    public String[] getParameterValues(String name) {

        String values[] = (String[]) m_parameters.get(name);
        if (values != null)
            return (values);
        else
            return (null);
    }
    
    /**
     * Adds the specified Map to the paramters of the request.<p>
     * 
     * Added parametes will not overwrite existing parameters in the 
     * request. Remember that the value for a parameter name in
     * a HttpRequest is a String array. If a parameter name already
     * exists in the HttpRequest, the values will be added to the existing
     * value array. Multiple occurences of the same value for one 
     * paramter are also possible.<p>
     * 
     * @param map the map to add
     * @return the merged map of parameters
     */
	public Map addParameterMap(Map map) {
		if (map == null)
			return m_parameters;
		if ((m_parameters == null) || (m_parameters.size() == 0)) {
            m_parameters = Collections.unmodifiableMap(map);
		} else {
            HashMap parameters = new HashMap();
            parameters.putAll(m_parameters);
            
            Iterator it = map.keySet().iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                // Check if the parameter name (key) exists
                if (parameters.containsKey(key)) {
                                
                    String[] oldValues = (String[]) parameters.get(key);
                    String[] newValues = (String[]) map.get(key);     
                               
                    String[] mergeValues = new String[oldValues.length + newValues.length];
                    System.arraycopy(newValues, 0, mergeValues, 0, newValues.length);
                    System.arraycopy(oldValues, 0, mergeValues, newValues.length, oldValues.length);
                    
                    parameters.put(key, mergeValues);
                } else {
                    // No: Add new value array
                    parameters.put(key, map.get(key));
                }                                     
			}
            m_parameters = Collections.unmodifiableMap(parameters);
		}

		return m_parameters;
	}
    
    /**
     * Sets the specified Map as paramter map of the request.<p>
     * 
     * The map set should be immutable. 
     * This will completly replace the parameter map. 
     * Use this in combination with getParameterMap() and
     * addParameterMap() in case you want to set the old status
     * of the parameter map after you have modified it for
     * a specific operation.<p>
     * 
     * @param map the map to set
     */    
    public void setParameterMap(Map map) {
        m_parameters = map;
    }
    
    /** 
     * Returns the CmsFlexCacheKey for this request,
     * the key will be calculated if neccessary.<p>
     * 
     * @return the CmsFlexCacheKey for this request
     */
    CmsFlexCacheKey getCmsCacheKey() {
        // The key for this request is only calculated if actually requested
        if (m_key == null) {
            m_key = new CmsFlexCacheKey(this, m_resource, m_isOnline);
        }
        return m_key;
    }

    /** 
     * Indicates that this request belongs to an online project.<p>
     * 
     * This is required to distinguish between online and offline
     * resources in the cache. Since the resources have the same name,
     * a suffix [online] or [offline] is added to distinguish the strings
     * when building cache keys.
     * Any resource from a request that isOnline() will be saved with
     * the [online] suffix and vice versa.<p>
     *
     * The suffixes are used so that we have a simple String name
     * for the resources in the cache. This makes it easy to
     * use a standard HashMap for storage of the resources.<p>
     *
     * @return true if an online resource was requested, false otherwise
     */
    public boolean isOnline() {
        return m_isOnline;
    }
    
    /** 
     * This is needed to decide if this request can be cached or not.<p>
     * 
     * Using the request to decide if caching is used or not
     * makes it possible to set caching to false e.g. on a per-user
     * or per-project basis.<p>
     *
     * @return true if the request is cacheable, false otherwise
     */
    boolean isCacheable() {
        return m_canCache;
    }
    
    /** 
     * Checks if JSPs should always be recompiled.<p>
     * 
     * This is useful in case directive based includes are used
     * with &lt;%@ include file="..." %&gt; on a JSP.
     * Note that this also forces the request not to be cached.<p>
     *
     * @return true if JSPs should be recompiled, false otherwise
     */
    public boolean isDoRecompile() {
        return m_doRecompile;
    }
    
    /**
     * Adds another include call to this wrapper.<p>
     * 
     * The set of include calls is maintained to dectect 
     * an endless inclusion loop.<p>
     * 
     * @param target the target name (absolute OpenCms URI) to add
     */
    void addInlucdeCall(String target) {
        m_includeCalls.add(target);
    }
    
    /**
     * Removes an include call from this wrapper.<p>
     * 
     * The set of include calls is maintained to dectect 
     * an endless inclusion loop.<p>
     * 
     * @param target the target name (absolute OpenCms URI) to remove
     */
    void removeIncludeCall(String target) {
        m_includeCalls.remove(target);
    }
    
    /**
     * Checks if a given target is already included in a top-layer of this
     * wrapped request.<p>
     * 
     * The set of include calls is maintained to dectect 
     * an endless inclusion loop.<p>
     * 
     * @param target the target name (absolute OpenCms URI) to check for
     * @return true if the target is already included, false otherwise
     */
    boolean containsIncludeCall(String target) {
        return m_includeCalls.contains(target);
    }
        
    /**
     * Returns the Set of include calls which will be passed to the next wrapping layer.<p>
     * 
     * The set of include calls is maintained to dectect 
     * an endless inclusion loop.<p>
     * 
     * @return the Set of include calls
     */
    protected Set getCmsIncludeCalls() {
        return m_includeCalls;
    }    
}

⌨️ 快捷键说明

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