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

📄 cmsmergepages.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }

    /**
     * Sets the first folder to merge.<p>
     *
     * @param folder1 the first folder name to set
     */
    public void setParamFolder1(String folder1) {

        m_paramFolder1 = folder1;
    }

    /**
     * Sets the second folder to merge.<p>
     *
     * @param folder2 the second folder name to set
     */
    public void setParamFolder2(String folder2) {

        m_paramFolder2 = folder2;
    }

    /**
     * Does validate the request parameters and returns a buffer with error messages.<p>
     * @param cms the current cms object
     * If there were no error messages, the buffer is empty.<p>
     */
    public void validateParameters(CmsObject cms) {

        CmsMessages messages = Messages.get().getBundle(getLocale());
        StringBuffer validationErrors = new StringBuffer();
        if (CmsStringUtil.isEmpty(getParamFolder1())) {
            validationErrors.append(messages.key(Messages.GUI_MERGE_PAGES_VALIDATE_FIRST_FOLDER_0)).append("<br>");
        } else {
            try {
                cms.readResource(getParamFolder1());
            } catch (CmsException e) {
                validationErrors.append(
                    messages.key(Messages.GUI_MERGE_PAGES_VALIDATE_FIRST_FOLDER_1, getParamFolder1())).append("<br>");
            }
        }
        if (CmsStringUtil.isEmpty(getParamFolder2())) {
            validationErrors.append(messages.key(Messages.GUI_MERGE_PAGES_VALIDATE_SECOND_FOLDER_0)).append("<br>");
        } else {
            try {
                cms.readResource(getParamFolder2());
            } catch (CmsException e) {
                validationErrors.append(
                    messages.key(Messages.GUI_MERGE_PAGES_VALIDATE_SECOND_FOLDER_1, getParamFolder2())).append("<br>");
            }
        }
        if (getParamFolder1().equals(getParamFolder2())) {
            validationErrors.append(messages.key(Messages.GUI_MERGE_PAGES_VALIDATE_SAME_FOLDER_0)).append("<br>");
        }

        setErrorMessage(validationErrors.toString());
    }

    /**
     * @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 
        // set the action for the JSP switch 
        if (DIALOG_CONFIRMED.equals(getParamAction())) {
            setAction(ACTION_CONFIRMED);
        } else if (DIALOG_OK.equals(getParamAction())) {
            setAction(ACTION_OK);
        } else if (DIALOG_CANCEL.equals(getParamAction())) {
            setAction(ACTION_CANCEL);
        } else if (REPORT_UPDATE.equals(getParamAction())) {
            setAction(ACTION_REPORT_UPDATE);
        } else if (REPORT_BEGIN.equals(getParamAction())) {
            setAction(ACTION_REPORT_BEGIN);
        } else if (REPORT_END.equals(getParamAction())) {
            setAction(ACTION_REPORT_END);
        } else {
            setAction(ACTION_DEFAULT);
            // add the title for the dialog 
            setParamTitle(Messages.get().getBundle(getLocale()).key(Messages.GUI_TITLE_MERGEPAGES_0));
        }
    }

    /**
     * Analyses a page in the source morge folder and tests if a resouce with the same name exists in the target merge folder.<p>
     * 
     * The method then calcualtes a action for further processing of this page, possible values are:
     * <ul>
     * <li>C_FOLDER1_EXCLUSIVE: exclusivly found in folder 1</li>
     * <li>C_FOLDER2_EXCLUSIVE: exclusivly found in folder 2</li>
     * <li>C_FOLDERS_SIBLING: found in both folders as siblings of each other </li>
     * <li>C_FOLDERS_EQUALNAMES: found in both folders as individual resources</li>
     * <li>C_FOLDERS_DIFFERENTTYPES: found in both folders as different types</li>    
     * </ul>
     * @param res the resource to test
     * @param sourceMergeFolder the path to the source merge folder
     * @param targetMergefolder the path to the target merge folder
     * @param currentFolder integer value (1 or 2) showing if the source folder is folder 1 or folder 2
     * @return value of the action to do with this page
     */
    private int analyse(CmsResource res, String sourceMergeFolder, String targetMergefolder, int currentFolder) {

        int retValue = -1;
        String resourcenameOther = getResourceNameInOtherFolder(
            m_cms.getSitePath(res),
            sourceMergeFolder,
            targetMergefolder);
        try {
            CmsResource otherRes = m_cms.readResource(resourcenameOther, CmsResourceFilter.IGNORE_EXPIRATION);
            // there was a resource with the same name in the other merge folder
            // now check if it is already a sibling of the current resource
            if (res.getResourceId().equals(otherRes.getResourceId())) {
                // it is a sibling, so set the action to "sibling already";
                retValue = FOLDERS_SIBLING;
            } else {
                // it is no sibling, now test if it has the same resource type than the oringinal resource
                if (res.getTypeId() == otherRes.getTypeId()) {
                    // both resources have the same type, so set the action to  "same name". Only those resources can be merged
                    retValue = FOLDERS_EQUALNAMES;
                } else {
                    // both resources have different types, so set the action to "different types"
                    retValue = FOLDERS_DIFFERENTTYPES;
                }
            }
        } catch (CmsException e) {
            // the resource was not found, so set the action mode to "found only in the source folder"
            if (currentFolder == 1) {
                retValue = FOLDER1_EXCLUSIVE;
            } else {
                retValue = FOLDER2_EXCLUSIVE;
            }
        }

        return retValue;
    }

    /**
     * Cleanup all internal storages.<p>    *
     */
    private void cleanup() {

        m_folder1Exclusive = null;
        m_folder2Exclusive = null;
        m_foldersSibling = null;
        m_foldersEqualnames = null;
        m_foldersDifferenttypes = null;
    }

    /**
     * Collect all pages in a folders and sort them depending on the required action to do.<p>
     * 
     * @param sourceMergeFolder the source merge folder to collect all pages from
     * @param targetMergefolder the target merge folder to compare to
     * @param currentFolder integer value (1 or 2) showing if the source folder is folder 1 or folder 2
     * @throws CmsException if something goes wrong
     */
    private void collectFolder(String sourceMergeFolder, String targetMergefolder, int currentFolder)
    throws CmsException {

        //get the list of all resources in the source merge folder
        CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(CmsResourceTypeXmlPage.getStaticTypeId());
        List folderResources = m_cms.readResources(sourceMergeFolder, filter, true);
        Iterator i = folderResources.iterator();
        int size = folderResources.size();
        // now loop through all resources and check them against those in the target merge folder
        m_report.println(Messages.get().container(
            Messages.RPT_SCAN_PAGES_IN_FOLDER_BEGIN_2,
            sourceMergeFolder,
            new Integer(size)), I_CmsReport.FORMAT_HEADLINE);
        int count = 1;
        while (i.hasNext()) {
            CmsResource res = (CmsResource)i.next();
            String resName = m_cms.getSitePath(res);

            m_report.print(org.opencms.report.Messages.get().container(
                org.opencms.report.Messages.RPT_SUCCESSION_2,
                String.valueOf(count++),
                String.valueOf(size)), I_CmsReport.FORMAT_NOTE);
            m_report.println(Messages.get().container(Messages.RPT_PROCESS_1, resName), I_CmsReport.FORMAT_NOTE);

            // now analyse the page and calculate the action to do
            int action = analyse(res, sourceMergeFolder, targetMergefolder, currentFolder);
            // add the name of the resource to the correct list
            switch (action) {
                case FOLDER1_EXCLUSIVE:
                    m_folder1Exclusive.add(resName);
                    m_report.println(
                        Messages.get().container(Messages.RPT_FOLDER1_EXCLUSIVE_0),
                        I_CmsReport.FORMAT_OK);
                    break;
                case FOLDER2_EXCLUSIVE:
                    m_folder2Exclusive.add(resName);
                    m_report.println(
                        Messages.get().container(Messages.RPT_FOLDER2_EXCLUSIVE_0),
                        I_CmsReport.FORMAT_OK);
                    break;
                case FOLDERS_SIBLING:
                    if (!m_foldersSibling.contains(getResourceNameInOtherFolder(
                        resName,
                        sourceMergeFolder,
                        targetMergefolder))) {
                        m_foldersSibling.add(resName);
                    }
                    m_report.println(Messages.get().container(Messages.RPT_FOLDERS_SIBLING_0), I_CmsReport.FORMAT_OK);
                    break;
                case FOLDERS_EQUALNAMES:
                    if (!m_foldersEqualnames.contains(getResourceNameInOtherFolder(
                        resName,
                        sourceMergeFolder,
                        targetMergefolder))) {
                        m_foldersEqualnames.add(resName);
                    }
                    m_report.println(
                        Messages.get().container(Messages.RPT_FOLDERS_EQUALNAMES_0),
                        I_CmsReport.FORMAT_OK);
                    break;
                case FOLDERS_DIFFERENTTYPES:
                    if (!m_foldersDifferenttypes.contains(getResourceNameInOtherFolder(
                        resName,
                        sourceMergeFolder,
                        targetMergefolder))) {
                        m_foldersDifferenttypes.add(resName);
                    }
                    m_report.println(
                        Messages.get().container(Messages.RPT_FOLDERS_DIFFERENTTYPES_0),
                        I_CmsReport.FORMAT_OK);
                    break;
                default:
                    break;
            }
            res = null;
        }
        folderResources = null;
        m_report.println(
            Messages.get().container(Messages.RPT_SCAN_PAGES_IN_FOLDER_END_0),
            I_CmsReport.FORMAT_HEADLINE);

    }

    /**
     * Collect all pages in the folders to merge and sort them depending on the required action to do.<p>
     * 
     * The method will create several lists. Each list contains the resource names of pages
     * and will be used in further steps of the merging process.
     * <ul>
     * <li>List m_folder1Exclusive: contains all pages which are exclusivly found in folder 1</li>
     * <li>List m_folder2Exclusive: contains all pages which are exclusivly found in folder 2</li>
     * <li>List m_foldersSibling: contains all pages which can be found in both folders and are siblings of each other </li>
     * <li>List m_foldersEqualnames: contains all pages which can be found in both folders and are no siblings of each other</li>
     * <li>List m_foldersDifferenttypes: contains all pages which can be found in both folders but are of different types</li>
     * </ul>
     * 
     * @throws CmsException if something goes wrong
     */
    private void collectResources() throws CmsException {

⌨️ 快捷键说明

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