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

📄 cmspublishresource.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            } catch (Exception e) {
                    throw new CmsException("Redirect fails :"
                            + getConfigFile(cms).getWorkplaceActionPath()
                            + C_WP_EXPLORER_FILELIST, CmsException.C_UNKNOWN_EXCEPTION, e);
            }
            return null;
        } else {            
            CmsResource file = readResource(cms, filename);
            String lasturl = getLastUrl(cms, parameters);
                        
            if ("check".equals(action)){
                if(file.getState() != C_STATE_DELETED){
                    if(checkLocked(cms, file)){
                        action = "ok";
                    } else {
                        // ask user if the locks should be removed
                        return startProcessing(cms, xmlTemplateDocument, elementName, parameters,"asklock");
                    }
                } else {
                    action = "ok";
                }
            } else if("rmlocks".equals(action)){
                // remove the locks and publish
                try{
                    unlockResource(cms, file);
                    action = "ok";
                } catch (CmsException exc){
                    xmlTemplateDocument.setData("details", Utils.getStackTrace(exc));
                    xmlTemplateDocument.setData("lasturl", lasturl);
                    return startProcessing(cms, xmlTemplateDocument, elementName, parameters,"errorlock");
                }
            }
            if("ok".equals(action)) {
                // publish is confirmed, let's go
                try{
                    // here is the plan: 
                    // first create a direct publish temp project (A)
                    // then start the link checker with this project (A)
                    // the link checker will delete project (A) after having checked the links
                    // if broken links where found, display a confirmation dialog
                    // if the user continues the publish (or no broken links where found)
                    // auto-create a direct publish temp project (B) and publish this directly
                    
                    int tempProjectId = cms.publishResource(file.getAbsolutePath(), true);
                    if(lasturl == null){
                        lasturl = "";
                    }
                    session.putValue(C_PUBLISH_LASTURL, lasturl);
                    // first part of the publish: check for broken links
                    A_CmsReportThread doCheck = new CmsAdminLinkmanagementThread(cms, tempProjectId, file.getAbsolutePath());
                    doCheck.start();
                    session.putValue(C_PUBLISH_LINKCHECK_THREAD, doCheck);
                    template = "showresult";
                
                } catch(CmsException e){
                    session.removeValue(C_PARA_FILE);
                    xmlTemplateDocument.setData("details", Utils.getStackTrace(e));
                    xmlTemplateDocument.setData("lasturl", lasturl);
                    return startProcessing(cms, xmlTemplateDocument, "", parameters, "error");
                }
            }
        }        
        // process the selected template
        return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
    }
    
    /**
     * Reads a named resource form the VFS.
     * 
     * @param cms the active cms context
     * @param resourceName the name of the resource to read
     * @return CmsResource the read resource, or <code>null</code> if nothing was read
     * @throws CmsException if something goes wrong reading the resource
     */
    private CmsResource readResource(CmsObject cms, String resourceName) throws CmsException {
        CmsResource resource = null;
        if(resourceName.endsWith("/")){
            resource = (CmsResource)cms.readFolder(resourceName, true);
        } else {
            resource = (CmsResource)cms.readFileHeader(resourceName, true);
        }        
        return resource;
    }

    /**
     * check if there are any locked resources in the folder
     *
     * @param cms The CmsObject for accessing system resources
     * @param resource The resource to check
     */
    private boolean checkLocked(CmsObject cms, CmsResource resource) throws CmsException{
        // do not need to check a file
        if(resource.isFile()){
            return true;
        }
        // check if the folder itself is locked
        if(resource.isLocked()){
            return false;
        }
        Vector allFiles = cms.getFilesInFolder(resource.getAbsolutePath());
        Vector allFolders = cms.getSubFolders(resource.getAbsolutePath());
        // first check if any file in the folder is locked
        for(int i=0; i<allFiles.size(); i++){
            CmsResource curFile = (CmsResource)allFiles.elementAt(i);
            if(curFile.isLocked()){
                return false;
            }
        }
        // now check all subfolders
        for(int j=0; j<allFolders.size(); j++){
            CmsResource curFolder = (CmsResource)allFolders.elementAt(j);
            if(!checkLocked(cms, curFolder)){
                return false;
            }
        }
        return true;
    }

    /**
     * Unlocks all resources in the folder
     *
     * @param cms The CmsObject for accessing system resources
     * @param resource The resource to unlock
     */
    private void unlockResource(CmsObject cms, CmsResource resource) throws CmsException{
        // if the folder itself is locked, all subresources are unlocked by unlocking the folder
        if(resource.isLocked()){
            // first lock resource to set locked by to the current user
            if(resource.isLockedBy() != cms.getRequestContext().currentUser().getId()){
                cms.lockResource(resource.getAbsolutePath(),true);
            }
            cms.unlockResource(resource.getAbsolutePath());
        } else {
            // need to unlock each resource
            Vector allFiles = cms.getFilesInFolder(resource.getAbsolutePath());
            Vector allFolders = cms.getSubFolders(resource.getAbsolutePath());
            // unlock the files
            for(int i=0; i<allFiles.size(); i++){
                CmsResource curFile = (CmsResource)allFiles.elementAt(i);
                if(curFile.isLocked()){
                    if(resource.isLockedBy() != cms.getRequestContext().currentUser().getId()){
                        cms.lockResource(curFile.getAbsolutePath(),true);
                    }
                    cms.unlockResource(curFile.getAbsolutePath());
                }
            }
            // unlock the folders
            for(int j=0; j<allFolders.size(); j++){
                CmsResource curFolder = (CmsResource)allFolders.elementAt(j);
                unlockResource(cms, curFolder);
            }
        }
    }

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */

    public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) {
        return false;
    }
}

⌨️ 快捷键说明

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