cmsnewresourcefolder.java

来自「找了很久才找到到源代码」· Java 代码 · 共 692 行 · 第 1/2 页

JAVA
692
字号
            Iterator iter = availableResTypes.iterator();
            while (iter.hasNext()) {

                String entry = (String)iter.next();

                // check if the no index page is available
                if (entry.equals(NAME_NO_INDEX_PAGE)) {
                    existNoIndex = true;
                }

                // check if the entry is the default
                if (entry.startsWith(DEFAULT_MARKER)) {

                    // strip leading asterisk
                    return entry.substring(1, entry.length());
                }
            }

            // if the no index page entry exists, use this as default
            if (existNoIndex) {
                return ID_NO_INDEX_PAGE;
            }

            // now use the first entry as the default
            if (availableResTypes.size() > 0) {
                return (String)availableResTypes.get(0);
            }

            return null;
        }

        return item;
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#paramsAsHidden()
     */
    public String paramsAsHidden() {

        List exclude = new ArrayList();
        exclude.add(CmsNewResource.PARAM_NEWRESOURCEEDITPROPS);
        exclude.add(PARAM_RESOURCE);

        return paramsAsHidden(exclude);
    }

    /**
     * Sets the current folder.<p>
     *
     * @param paramCurrentFolder the current folder to set
     */
    public void setParamCurrentFolder(String paramCurrentFolder) {

        m_paramCurrentFolder = paramCurrentFolder;
    }

    /**
     * Sets the paramNewResourceEditProps.<p>
     *
     * @param paramNewResourceEditProps the paramNewResourceEditProps to set
     */
    public void setParamNewResourceEditProps(String paramNewResourceEditProps) {

        m_paramNewResourceEditProps = paramNewResourceEditProps;
    }

    /**
     * Appends the full path to the new resource name given in the resource parameter.<p>
     * 
     * @return the full path of the new resource
     */
    protected String computeFullResourceName() {

        // return the full resource name
        // get the current folder
        String currentFolder = getParamCurrentFolder();
        if (CmsStringUtil.isEmpty(currentFolder)) {
            currentFolder = computeCurrentFolder();
        }
        return currentFolder + getParamResource();
    }

    /**
     * Returns the html code to add directly before the list inside the form element.<p>
     * 
     * @return the html code to add directly before the list inside the form element
     */
    protected String customHtmlBeforeList() {

        StringBuffer result = new StringBuffer();

        result.append(dialogBlockStart(key(Messages.GUI_NEWFOLDER_OPTIONS_0)));
        result.append("<table border=\"0\" width=\"100%\">\n");
        result.append("\t<tr>\n");
        result.append("\t\t<td style=\"white-space: nowrap;\" unselectable=\"on\">");
        result.append(key(Messages.GUI_RESOURCE_NAME_0));
        result.append("</td>\n");
        result.append("\t\t<td class=\"maxwidth\"><input name=\"");
        result.append(PARAM_RESOURCE);

        result.append("\" id=\"newresfield\" type=\"text\" value=\"");
        String resource = getParamResource();
        if (resource == null) {
            resource = "";
        }
        result.append(resource);
        result.append("\" class=\"maxwidth\" onkeyup=\"checkValue();\" ></td>\n");
        result.append("\t</tr>\n");
        result.append("\t<tr>\n");
        result.append("\t\t<td>&nbsp;</td>\n");
        result.append("\t\t<td style=\"white-space: nowrap;\" unselectable=\"on\" class=\"maxwidth\">\n");
        result.append("\t\t\t<input name=\"");
        result.append(CmsNewResource.PARAM_NEWRESOURCEEDITPROPS);
        result.append("\" id=\"newresedit\" type=\"checkbox\" value=\"true\"");
        result.append(" onclick=\"toggleButtonLabel();\"");
        if (Boolean.valueOf(getParamNewResourceEditProps()).booleanValue()) {
            result.append(" checked");
        }
        result.append(">&nbsp;");
        result.append(key(Messages.GUI_NEWFOLDER_EDITPROPERTIES_0));
        result.append("\n");
        result.append("\t\t</td>\n");
        result.append("\t</tr>\n");
        result.append("</table>\n");
        result.append(dialogBlockEnd());
        result.append("<br/>\n");
        return result.toString();
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#customHtmlEnd()
     */
    protected String customHtmlEnd() {

        StringBuffer result = new StringBuffer(256);
        result.append(super.customHtmlEnd());

        // execute the javascript for de-/activating the continue button
        result.append("<script type='text/javascript'>\n");
        result.append("\ttoggleButtonLabel();\n");
        result.append("\tcheckValue();\n");
        result.append("</script>");

        return result.toString();
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#customHtmlStart()
     */
    protected String customHtmlStart() {

        StringBuffer result = new StringBuffer(256);
        result.append(super.customHtmlStart());
        result.append("<script type='text/javascript'>\n");

        result.append("function toggleButtonLabel() {\n");
        result.append("\tvar theCheckBox = document.getElementById('newresedit');\n");
        result.append("\tvar theButton = document.getElementById('nextButton');\n");
        result.append("\tif (theCheckBox.checked == true) {\n");
        result.append("\t\ttheButton.value = '" + key(Messages.GUI_BUTTON_CONTINUE_0) + "';\n");
        result.append("\t} else {\n");
        result.append("\t\ttheButton.value = '" + key(Messages.GUI_BUTTON_ENDWIZARD_0) + "';\n");
        result.append("\t}\n");
        result.append("}\n\n");

        result.append("function checkValue() {\n");
        result.append("\tvar resName = document.getElementById(\"newresfield\").value;\n");
        result.append("\tvar theButton = document.getElementById(\"nextButton\");\n");
        result.append("\tif (resName.length == 0) {\n");
        result.append("\t\tif (theButton.disabled == false) {\n");
        result.append("\t\t\ttheButton.disabled = true;\n");
        result.append("\t\t}\n");
        result.append("\t} else {\n");
        result.append("\t\tif (theButton.disabled == true) {\n");
        result.append("\t\t\ttheButton.disabled = false;\n");
        result.append("\t\t}\n");
        result.append("\t}\n");
        result.append("}\n");

        result.append("</script>");

        return result.toString();
    }

    /**
     * @see org.opencms.workplace.CmsDialog#dialogButtonsHtml(java.lang.StringBuffer, int, java.lang.String)
     */
    protected void dialogButtonsHtml(StringBuffer result, int button, String attribute) {

        switch (button) {
            case BUTTON_CONTINUE:
                result.append("<input name=\"set\" type=\"button\" value=\"");
                result.append(key(Messages.GUI_BUTTON_CONTINUE_0) + "\"");
                if (attribute.toLowerCase().indexOf("onclick") == -1) {
                    result.append(" onclick=\"submitAction('"
                        + DIALOG_CONTINUE
                        + "', form, '"
                        + getListId()
                        + "-form');\"");
                }
                result.append(" class=\"dialogbutton\"");
                result.append(" id=\"nextButton\"");
                result.append(" disabled=\"disabled\"");
                result.append(attribute);
                result.append(">\n");
                break;
            default:
                super.dialogButtonsHtml(result, button, attribute);
        }
    }

    /**
     * Returns a list with all available resource types for the index page.<p>
     * 
     * The information is first read from the property "restypes.indexpage".
     * If there nothing could be found, the global settings from the resource
     * type folder is taken. Only if there is nothing configured, the default
     * (No index page and xmlpage) will be taken.<p>
     * 
     * @return a list with all available resource types for the index page
     */
    protected List getAvailableResTypes() {

        String availableResTypes = null;

        // check for presence of property limiting the new resource types to create
        try {
            String propResTypes = getCms().readPropertyObject(
                getParamCurrentFolder(),
                PROPERTY_RESTYPES_INDEXPAGE,
                true).getValue();

            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(propResTypes)) {
                availableResTypes = propResTypes;
            }
        } catch (CmsException e) {
            // ignore this exception, this is a minor issue
        }

        // use global settings from resource type folder
        if (availableResTypes == null) {
            try {
                I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(
                    CmsResourceTypeFolder.getStaticTypeId());

                String folderResTypes = ((CmsResourceTypeFolder)resType).getIndexPageTypes();
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(folderResTypes)) {
                    availableResTypes = folderResTypes;
                }

            } catch (CmsException ex) {
                // ignore this exception, this is a minor issue
            }
        }

        // use default
        if (availableResTypes == null) {
            availableResTypes = DEFAULT_AVAILABLE;
        }

        // create list iterator of given available resource types
        return CmsStringUtil.splitAsList(availableResTypes, CmsProperty.VALUE_LIST_DELIMITER, true);
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
     */
    protected List getListItems() {

        List ret = new ArrayList();

        List newResTypes = getAvailableResTypes();
        Iterator k = newResTypes.iterator();
        while (k.hasNext()) {
            String resType = (String)k.next();

            // strip the leading asterisk for the default
            if (resType.startsWith(DEFAULT_MARKER)) {
                resType = resType.substring(1, resType.length());
            }

            // add the no index page entry
            if (resType.equals(NAME_NO_INDEX_PAGE)) {
                CmsListItem item = getList().newItem(ID_NO_INDEX_PAGE);
                item.set(LIST_COLUMN_NAME, key(Messages.GUI_NEWFOLDER_LIST_NO_INDEX_0));
                ret.add(item);
                continue;
            }

            // get settings for resource type
            CmsExplorerTypeSettings set = OpenCms.getWorkplaceManager().getExplorerTypeSetting(resType);
            if (set != null) {

                // add found setting to list
                CmsListItem item = getList().newItem(set.getName());
                item.set(LIST_COLUMN_NAME, key(set.getKey()));
                item.set(LIST_COLUMN_ICON, "<img src=\""
                    + getSkinUri()
                    + "filetypes/"
                    + set.getIcon()
                    + "\" style=\"width: 16px; height: 16px;\" />");
                ret.add(item);
            }
        }

        return ret;
    }

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

        super.initWorkplaceRequestValues(settings, request);
        if (DIALOG_CONTINUE.equals(getParamAction())) {
            setAction(ACTION_CONTINUE);
        } else if (CmsNewResource.DIALOG_NEWFORM.equals(getParamAction())) {
            CmsDefaultUserSettings userSettings = OpenCms.getWorkplaceManager().getDefaultUserSettings();
            Boolean editPropsChecked = userSettings.getNewFolderEditProperties();
            setParamNewResourceEditProps(editPropsChecked.toString());
        }

        // set title
        String title = null;
        CmsExplorerTypeSettings set = OpenCms.getWorkplaceManager().getExplorerTypeSetting(CmsResourceTypeFolder.getStaticTypeName());
        if ((set != null) && (CmsStringUtil.isNotEmptyOrWhitespaceOnly(set.getTitleKey()))) {
            title = getMessages().key(set.getTitleKey(), true);
        }
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(title)) {
            title = key(Messages.GUI_NEWRESOURCE_FOLDER_0);
        }
        setParamTitle(title);
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListResourceTypeDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
     */
    protected void setColumns(CmsListMetadata metadata) {

        super.setColumns(metadata);

        CmsListColumnDefinition def = metadata.getColumnDefinition(LIST_COLUMN_NAME);
        def.setListItemComparator(LIST_ITEM_COMPARATOR);
    }
}

⌨️ 快捷键说明

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