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

📄 cmsnewresourcexmlpage.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

            // eventually append ".html" suffix to new file if not present
            boolean forceSuffix = false;
            if (CmsStringUtil.isEmpty(getParamSuffixCheck())) {
                // backward compatibility: append suffix every time
                forceSuffix = true;
            }
            fullResourceName = appendSuffixHtml(fullResourceName, forceSuffix);

            // get the body file content
            byte[] bodyFileBytes = null;
            if (CmsStringUtil.isEmpty(getParamBodyFile())) {
                // body file not specified, use empty body
                bodyFileBytes = ("").getBytes();
            } else {
                // get the specified body file
                bodyFileBytes = getCms().readFile(getParamBodyFile(), CmsResourceFilter.IGNORE_EXPIRATION).getContents();
            }

            // create the xml page   
            List properties = new ArrayList(4);
            // add the template property to the new file
            properties.add(new CmsProperty(CmsPropertyDefinition.PROPERTY_TEMPLATE, getParamTemplate(), null));
            properties.addAll(createResourceProperties(
                fullResourceName,
                CmsResourceTypeXmlPage.getStaticTypeName(),
                title));
            getCms().createResource(
                fullResourceName,
                CmsResourceTypeXmlPage.getStaticTypeId(),
                bodyFileBytes,
                properties);

            // set the resource parameter to full path for property dialog 
            setParamResource(fullResourceName);
            setResourceCreated(true);
        } catch (Throwable e) {
            // error creating folder, show error dialog
            includeErrorpage(this, e);
        }
    }

    /**
     * Forwards to the property dialog if the resourceeditprops parameter is true.<p>
     * 
     * If the parameter is not true, the dialog will be closed.<p>
     * 
     * @throws IOException if forwarding to the property dialog fails
     * @throws ServletException if forwarding to the property dialog fails
     * @throws JspException if an inclusion fails
     */
    public void actionEditProperties() throws IOException, JspException, ServletException {

        boolean editProps = Boolean.valueOf(getParamNewResourceEditProps()).booleanValue();
        if (editProps) {
            // edit properties checkbox checked, forward to property dialog
            Map params = new HashMap();
            params.put(PARAM_RESOURCE, getParamResource());
            if (isCreateIndexMode()) {
                params.put(CmsPropertyAdvanced.PARAM_DIALOGMODE, CmsPropertyAdvanced.MODE_WIZARD_INDEXCREATED);
            } else {
                params.put(CmsPropertyAdvanced.PARAM_DIALOGMODE, CmsPropertyAdvanced.MODE_WIZARD);
            }
            sendForward(CmsPropertyAdvanced.URI_PROPERTY_DIALOG_HANDLER, params);
        } else {
            // edit properties not checked, close the dialog
            actionCloseDialog();
        }
    }

    /**
     * Builds the html for the page body file select box.<p>
     * 
     * @param attributes optional attributes for the &lt;select&gt; tag
     * @return the html for the page body file select box
     */
    public String buildSelectBodyFile(String attributes) {

        List options = new ArrayList();
        List values = new ArrayList();
        TreeMap bodies = null;
        try {
            // get all available body files
            bodies = getBodies(getCms(), getParamCurrentFolder(), false);
        } catch (CmsException e) {
            // can usually be ignored
            if (LOG.isInfoEnabled()) {
                LOG.info(e);
            }
        }
        if (bodies == null) {
            // no body files found, return empty String
            return "";
        } else {
            // body files found, create option and value lists
            Iterator i = bodies.keySet().iterator();
            int counter = 0;
            while (i.hasNext()) {
                String key = (String)i.next();
                String path = (String)bodies.get(key);

                options.add(key);
                values.add(path);
                counter++;
            }
        }
        return buildSelect(attributes, options, values, -1, false);
    }

    /**
     * Builds the html for the page template select box.<p>
     * 
     * @param attributes optional attributes for the &lt;select&gt; tag
     * @return the html for the page template select box
     */
    public String buildSelectTemplates(String attributes) {

        List options = new ArrayList();
        List values = new ArrayList();
        TreeMap templates = null;
        try {
            // get all available templates
            templates = getTemplates(getCms(), getParamCurrentFolder(), false);
        } catch (CmsException e) {
            // can usually be ignored
            if (LOG.isInfoEnabled()) {
                LOG.info(e);
            }
        }
        if (templates == null) {
            // no templates found, return empty String
            return "";
        } else {
            // templates found, create option and value lists
            Iterator i = templates.keySet().iterator();
            int counter = 0;
            while (i.hasNext()) {
                String key = (String)i.next();
                String path = (String)templates.get(key);

                options.add(key);
                values.add(path);
                counter++;
            }
        }
        return buildSelect(attributes, options, values, -1, false);
    }

    /**
     * Returns the body file parameter value.<p>
     * 
     * @return the body file parameter value
     */
    public String getParamBodyFile() {

        return m_paramBodyFile;
    }

    /**
     * Returns the value of the dialogmode parameter, 
     * or null if this parameter was not provided.<p>
     * 
     * The dialogmode parameter stores the different modes of the property dialog,
     * e.g. for displaying other buttons in the new resource wizard.<p>
     * 
     * @return the value of the usetempfileproject parameter
     */
    public String getParamDialogmode() {

        return m_paramDialogMode;
    }

    /**
     * Returns the request parameter flag inidicating if the suffix field is present or not.<p>
     * 
     * @return the request parameter flag inidicating if the suffix field is present or not
     */
    public String getParamSuffixCheck() {

        return m_paramSuffixCheck;
    }

    /**
     * Returns the template parameter value.<p>
     * 
     * @return the template parameter value
     */
    public String getParamTemplate() {

        return m_paramTemplate;
    }

    /**
     * Returns true if the current mode is: create an index page in a newly created folder.<p>
     * 
     * @return true if we are in wizard mode to create an index page, otherwise false
     */
    public boolean isCreateIndexMode() {

        return CmsPropertyAdvanced.MODE_WIZARD_CREATEINDEX.equals(getParamDialogmode());
    }

    /**
     * Overrides the super implementation to avoid problems with double reqource input fields.<p>
     * 
     * @see org.opencms.workplace.CmsWorkplace#paramsAsHidden()
     */
    public String paramsAsHidden() {

        String resourceName = getParamResource();
        // remove resource parameter from hidden params to avoid problems with double input fields in form
        setParamResource(null);
        String params = super.paramsAsHidden();
        // set resource parameter to stored value
        setParamResource(resourceName);
        return params;
    }

    /**
     * Sets the body file parameter value.<p>
     * 
     * @param bodyFile the body file parameter value
     */
    public void setParamBodyFile(String bodyFile) {

        m_paramBodyFile = bodyFile;
    }

    /**
     * Sets the value of the dialogmode parameter.<p>
     * 
     * @param value the value to set
     */
    public void setParamDialogmode(String value) {

        m_paramDialogMode = value;
    }

    /**
     * Sets the request parameter flag inidicating if the suffix field is present or not.<p>
     * 
     * @param paramSuffixCheck he request parameter flag inidicating if the suffix field is present or not
     */
    public void setParamSuffixCheck(String paramSuffixCheck) {

        m_paramSuffixCheck = paramSuffixCheck;
    }

    /**
     * Sets the template parameter value.<p>
     * 
     * @param template the template parameter value
     */
    public void setParamTemplate(String template) {

        m_paramTemplate = template;
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
     */
    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {

        // fill the parameter values in the get/set methods
        fillParamValues(request);
        // set the dialog type
        setParamDialogtype(DIALOG_TYPE);
        // set the action for the JSP switch 
        if (DIALOG_OK.equals(getParamAction())) {
            setAction(ACTION_OK);
        } else if (DIALOG_CANCEL.equals(getParamAction())) {
            setAction(ACTION_CANCEL);
        } else {
            // set resource name if we are in new folder wizard mode
            setInitialResourceName();
            setAction(ACTION_DEFAULT);
            // build title for new resource dialog     
            setParamTitle(key(Messages.GUI_NEWRESOURCE_XMLPAGE_0));
        }
    }

    /**
     * Sets the initial resource name of the new page.<p>
     * 
     * This is used for the "new" wizard after creating a new folder followed
     * by the "create index file" procedure.<p> 
     */
    private void setInitialResourceName() {

        if (isCreateIndexMode()) {
            // creation of an index file in a new folder, use default file name
            String defaultFile = "";
            try {
                defaultFile = (String)OpenCms.getDefaultFiles().get(0);
            } catch (IndexOutOfBoundsException e) {
                // list is empty, ignore    
            }
            if (CmsStringUtil.isEmpty(defaultFile)) {
                // make sure that the default file name is not empty
                defaultFile = "index.html";
            }
            setParamResource(defaultFile);
        } else {
            setParamResource("");
        }
    }

}

⌨️ 快捷键说明

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