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

📄 cmsworkplace.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * checking the workplace default resources and all module bundles.<p>
     * 
     * If the key was not found, the return value is
     * <code>"??? " + keyName + " ???"</code>.<p>
     * 
     * If the key starts with <code>"help."</code> and is not found,
     * the value <code>"index.html"</code> is returned.<p>
     * 
     * @param keyName the key for the desired string 
     * @return the resource string for the given key 
     * 
     * @see CmsMessages#key(String)
     */
    public String key(String keyName) {

        return getMessages().key(keyName);
    }

    /**
     * Returns the localized resource string for a given message key,
     * with the provided replacement parameters.<p>
     * 
     * If the key was found in the bundle, it will be formatted using
     * a <code>{@link java.text.MessageFormat}</code> using the provided parameters.<p>
     * 
     * If the key was not found in the bundle, the return value is
     * <code>"??? " + keyName + " ???"</code>. This will also be returned 
     * if the bundle was not properly initialized first.
     * 
     * @param keyName the key for the desired string 
     * @param params the parameters to use for formatting
     * @return the resource string for the given key
     * 
     * @see CmsMessages#key(String) 
     */
    public String key(String keyName, Object[] params) {

        return getMessages().key(keyName, params);
    }

    /**
     * Returns the localized resource string for the given message key, 
     * checking the workplace default resources and all module bundles.<p>
     * 
     * If the key was not found, the provided default value 
     * is returned.<p>
     * 
     * @param keyName the key for the desired string 
     * @param defaultValue the default value in case the key does not exist in the bundle
     * @return the resource string for the given key it it exists, or the given default if not 
     * 
     * @see CmsMessages#keyDefault(String, String)
     */
    public String keyDefault(String keyName, String defaultValue) {

        return getMessages().keyDefault(keyName, defaultValue);
    }

    /**
     * Returns the empty String "" if the provided value is null, otherwise just returns 
     * the provided value.<p>
     * 
     * Use this method in forms if a getParamXXX method is used, but a String (not null)
     * is required.
     * 
     * @param value the String to check
     * @return the empty String "" if the provided value is null, otherwise just returns 
     * the provided value
     */
    public String nullToEmpty(String value) {

        if (value != null) {
            return value;
        }
        return "";
    }

    /**
     * Builds the html of the body.<p>
     * 
     * @param segment the HTML segment (START / END)
     * @param className optional class attribute to add to the body tag
     * @param parameters optional parameters to add to the body tag
     * @return the html of the body
     */
    public String pageBody(int segment, String className, String parameters) {

        if (segment == HTML_START) {
            StringBuffer result = new StringBuffer(128);
            result.append("</head>\n<body unselectable=\"on\"");
            if (getSettings().isViewAdministration()) {
                if (className == null || "dialog".equals(className)) {
                    className = "dialogadmin";
                }
                if (parameters == null) {
                    result.append(" onLoad=\"window.top.body.admin_head.location.href='");
                    result.append(getJsp().link(CmsWorkplace.VFS_PATH_WORKPLACE + "action/administration_head.html"));
                    result.append("';\"");
                }
            }
            if (className != null) {
                result.append(" class=\"");
                result.append(className);
                result.append("\"");
            }
            if (CmsStringUtil.isNotEmpty(parameters)) {
                result.append(" ");
                result.append(parameters);
            }
            result.append(">\n");
            return result.toString();
        } else {
            return "</body>";
        }
    }

    /**
     * Returns the default html for a workplace page, including setting of DOCTYPE and 
     * inserting a header with the content-type.<p>
     * 
     * @param segment the HTML segment (START / END)
     * @param title the title of the page, if null no title tag is inserted
     * @return the default html for a workplace page
     */
    public String pageHtml(int segment, String title) {

        return pageHtmlStyle(segment, title, null);
    }

    /**
     * Returns the default html for a workplace page, including setting of DOCTYPE and 
     * inserting a header with the content-type, allowing the selection of an individual style sheet.<p>
     * 
     * @param segment the HTML segment (START / END)
     * @param title the title of the page, if null no title tag is inserted
     * @param stylesheet the used style sheet, if null the default stylesheet 'workplace.css' is inserted
     * @return the default html for a workplace page
     */
    public String pageHtmlStyle(int segment, String title, String stylesheet) {

        if (segment == HTML_START) {
            StringBuffer result = new StringBuffer(512);
            result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
            result.append("<html>\n<head>\n");
            if (title != null) {
                result.append("<title>");
                result.append(title);
                result.append("</title>\n");
            }
            result.append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=");
            result.append(getEncoding());
            result.append("\">\n");
            result.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");

            result.append(getStyleUri(getJsp(), stylesheet == null ? "workplace.css" : stylesheet));
            result.append("\">\n");
            return result.toString();
        } else {
            return "</html>";
        }
    }

    /**
     * Returns all initialized parameters of the current workplace class 
     * as hidden field tags that can be inserted in a form.<p>
     * 
     * @return all initialized parameters of the current workplace class
     * as hidden field tags that can be inserted in a html form
     */
    public String paramsAsHidden() {

        return paramsAsHidden(null);
    }

    /**
     * Returns all initialized parameters of the current workplace class 
     * that are not in the given exclusion list as hidden field tags that can be inserted in a form.<p>
     * 
     * @param excludes the parameters to exclude 
     * 
     * @return all initialized parameters of the current workplace class
     * that are not in the given exclusion list as hidden field tags that can be inserted in a form
     */
    public String paramsAsHidden(Collection excludes) {

        StringBuffer result = new StringBuffer(512);
        Map params = paramValues();
        Iterator i = params.keySet().iterator();
        while (i.hasNext()) {
            String param = (String)i.next();
            if ((excludes == null) || (!excludes.contains(param))) {
                Object value = params.get(param);
                result.append("<input type=\"hidden\" name=\"");
                result.append(param);
                result.append("\" value=\"");
                String encoded = CmsEncoder.encode(value.toString(), getCms().getRequestContext().getEncoding());
                result.append(encoded);
                result.append("\">\n");
            }
        }
        return result.toString();
    }

    /**
     * Returns all initialized parameters of the current workplace class in the
     * form of a parameter map, i.e. the values are arrays.<p>
     * 
     * @return all initialized parameters of the current workplace class in the
     * form of a parameter map
     */
    public Map paramsAsParameterMap() {

        return CmsRequestUtil.createParameterMap(paramValues());
    }

    /**
     * Returns all initialized parameters of the current workplace class 
     * as request parameters, i.e. in the form <code>key1=value1&key2=value2</code> etc.
     *  
     * @return all initialized parameters of the current workplace class 
     * as request parameters
     */
    public String paramsAsRequest() {

        StringBuffer result = new StringBuffer(512);
        Map params = paramValues();
        Iterator i = params.keySet().iterator();
        while (i.hasNext()) {
            String param = (String)i.next();
            Object value = params.get(param);
            result.append(param);
            result.append("=");
            result.append(CmsEncoder.encode(value.toString(), getCms().getRequestContext().getEncoding()));
            if (i.hasNext()) {
                result.append("&");
            }
        }
        return result.toString();
    }

    /**
     * Resolves the macros in the given String and replaces them by their localized keys.<p>
     * 
     * The following macro contexts are available in the Workplace:<ul>
     * <li>Macros based on the current users OpenCms context (obtained from the current <code>{@link CmsObject}</code>).</li>
     * <li>Localized key macros (obtained from the current <code>{@link CmsMessages}</code>).</li>
     * <li>Macros from the current JSP page context (obtained by <code>{@link #getJsp()}</code>).</li>
     * </ul>
     * 
     * @param input the input String containing the macros
     * @return the resolved String
     * 
     * @see CmsMacroResolver#resolveMacros(String)
     */
    public String resolveMacros(String input) {

        // resolve the macros
        return getMacroResolver().resolveMacros(input);
    }

    /**
     * Sends a http redirect to the specified URI in the OpenCms VFS.<p>
     *
     * @param location the location the response is redirected to
     * @throws IOException in case redirection fails
     */
    public void sendCmsRedirect(String location) throws IOException {

        // IBM Websphere patch: use forward here
        int todo = 0;
        getJsp().getResponse().sendRedirect(OpenCms.getSystemInfo().getOpenCmsContext() + location);
    }

    /**
     * Forwards to the specified location in the OpenCms VFS.<p>
     *
     * @param location the location the response is redirected to
     * @param params the map of parameters to use for the forwarded request
     * 
     * @throws IOException in case the forward fails
     * @throws ServletException in case the forward fails
     */
    public void sendForward(String location, Map params) throws IOException, ServletException {

        setForwarded(true);
        // params must be arrays of String, ensure this is the case
        params = CmsRequestUtil.createParameterMap(params);
        CmsRequestUtil.forwardRequest(getJsp().link(location), params, getJsp().getRequest(), getJsp().getResponse());
    }

    /**
     * Sets the forwarded flag.<p>
     *
     * @param forwarded the forwarded flag to set
     */
    public void setForwarded(boolean forwarded) {

        m_forwarded = forwarded;
    }

    /**
     * Get a localized short key value for the workplace.<p>
     * 
     * @param keyName name of the key
     * @return a localized short key value
     */
    public String shortKey(String keyName) {

        String value = keyDefault(keyName + CmsMessages.KEY_SHORT_SUFFIX, (String)null);
        if (value == null) {
            // short key value not found, return "long" key value
            return key(keyName);
        }
        return value;
    }

    /**
     * Auxiliary method for initialization of messages.<p>
     * 
     * @param messages the {@link CmsMessages} to add
     */
    protected void addMessages(CmsMessages messages) {

        if (messages != null) {
            m_messages.addMessages(messages);
        }
    }

    /**
     * Auxiliary method for initialization of messages.<p>
     * 
     * @param bundleName the resource bundle name to add
     */
    protected void addMessages(String bundleName) {

        addMessages(new CmsMessages(bundleName, getLocale()));
    }

    /**
     * Returns the values of all parameter methods of this workplace class instance.<p>
     * 
     * @return the values of all parameter methods of this workplace class instance
     */
    protected Map 

⌨️ 快捷键说明

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