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

📄 cmsstaticexport.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                }catch(Exception e){
                }
            }
        }catch(Exception e){
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
                A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_STATICEXPORT, "[CmsStaticExport]  export "+link+" failed : "+Utils.getStackTrace(e));
            }
        }
    }

    /**
     * Returns the name used for the disc.
     */
    private String getExternLinkName(String link){

        String[] rules = m_cms.getStaticExportProperties().getLinkRules(C_MODUS_EXTERN);
        String startRule = OpenCms.getStaticExportProperties().getStartRule();
        if(startRule != null && !"".equals(startRule)){
            try{
                link = c_perlUtil.substitute(startRule, link);
            }catch(Exception e){
                if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                    A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_CRITICAL, "["+this.getClass().getName()+"] problems with startrule:\""+startRule+"\" (" + e + "). ");
                }
            }
        }
        if(rules == null || rules.length == 0){
            return link;
        }
        String retValue = link;
        for(int i=0; i<rules.length; i++){
            try{
                if("*dynamicRules*".equals(rules[i])){
                    // here we go trough our dynamic rules
                    Vector booleanReplace = new Vector();
                    retValue = handleDynamicRules(m_cms, link, C_MODUS_EXTERN, booleanReplace);
                    Boolean goOn =(Boolean)booleanReplace.firstElement();
                    if(goOn.booleanValue()){
                        link = retValue;
                    }else{
                        // found the match
                        return retValue;
                    }
                }else{
                    StringBuffer result = new StringBuffer();
                    int matches = c_perlUtil.substitute(result, rules[i], link);
                    if(matches != 0){
                        // found the match
                        return result.toString();
                    }
                }
            }catch(Exception e){
                if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                    A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_CRITICAL, "["+this.getClass().getName()+"] problems with rule:\""+rules[i]+"\" (" + e + "). ");
                }
            }
        }
        return retValue;
    }

    /**
     * returns a vector with all links that must be new exported .
     *
     * @return the links (vector of strings).
     */
    private Vector getChangedLinks(CmsPublishedResources changedResources) throws CmsException{

        Vector resToCheck = new Vector();
        if(changedResources == null){
            return new Vector();
        }
        Vector addVector = changedResources.getChangedModuleMasters();
        if(addVector != null){
            for(int i=0; i<addVector.size(); i++){
                resToCheck.add(addVector.elementAt(i));
            }
        }
        addVector = changedResources.getChangedResources();
        if(addVector != null){
            for(int i=0; i<addVector.size(); i++){
                resToCheck.add(addVector.elementAt(i));
            }
        }
        Vector returnValue = m_cms.getDependingExportLinks(resToCheck);
        // we also need all "new" files
        if(addVector != null){
            for(int i=0; i<addVector.size(); i++){
                String res = Utils.getAbsolutePathForResource((String)addVector.elementAt(i));
                if((!res.endsWith("/")) && (!returnValue.contains(res))){
                    returnValue.add(res);
                }
            }
        }
        return returnValue;
    }

    /**
     * returns a vector with all links in the startpoints.
     *
     * @return the links (vector of strings).
     */
    private Vector getStartLinks(){

        Vector exportLinks = new Vector();
        for(int i=0; i<m_startpoints.size(); i++){
            String cur = (String)m_startpoints.elementAt(i);
            if(cur.endsWith("/")){
                // a folder, get all files in it
                try{
                    addSubFiles(exportLinks, cur);
                }catch(CmsException e){
                    if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
                        A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_STATICEXPORT,
                            "[CmsStaticExport] error couldn't get all subfolder from startpoint "
                            + cur + ": " + e.toString());
                    }
                }
            }else{
                exportLinks.add(cur);
            }
        }
        return exportLinks;
    }

    /**
     * Adds all subfiles of a folder to the vector
     *
     * @param links The vector to add the filenames to.
     * @param folder The folder where the files are in.
     */
    private void addSubFiles(Vector links, String folder)throws CmsException{

        // the firstlevel files
        Vector files = m_cms.getFilesInFolder(folder);
        for(int i=0; i<files.size(); i++){
            links.add(((CmsFile)files.elementAt(i)).getAbsolutePath());
        }
        Vector subFolders = m_cms.getSubFolders(folder);
        for(int i=0; i<subFolders.size(); i++){
            addSubFiles(links, ((CmsFolder)subFolders.elementAt(i)).getAbsolutePath());
        }
    }

    /**
     * this method handles the dynamic rules created by opencms
     * in using the properties of resources.
     *
     * @param cms. The cms-object. used for the parameter replace.
     * @param link The link that has to be replaced.
     * @param modus The modus OpenCms runs in.
     * @param parameterOnly is set to true if only the parameters are replaced
     *          and no other rules
     */
    public static String handleDynamicRules(CmsObject cms, String link, int modus, Vector paramterOnly){
        // first get the ruleset
        Vector dynRules = null;
        Vector nameRules = null;
        if(modus == C_MODUS_EXTERN){
            dynRules = m_dynamicExportRulesExtern;
            nameRules = m_dynamicExportNameRulesExtern;
        }else{
            dynRules = m_dynamicExportRulesOnline;
            nameRules = m_dynamicExportNameRules;
        }
        String retValue = link;
        int count;
        StringBuffer result = null;
        boolean doTheParameter = false;
        if(dynRules != null){
            for(int i=0; i<dynRules.size(); i++){
                result = new StringBuffer();
                count = c_perlUtil.substitute(result, (String)dynRules.elementAt(i), link);
                if(count != 0){
                    paramterOnly.add(new Boolean(false));
                    retValue = result.toString();
                    if(cms.getStaticExportProperties().isExportDefault()){
                        return retValue;
                    }else{
                        // default is dynamic
                        if(modus == C_MODUS_EXTERN){
                            if(!link.equals(retValue)){
                                return retValue;
                            }
                        }else{
                            if(!retValue.startsWith(cms.getStaticExportProperties().getUrlPrefixArray()[0])){
                                return retValue;
                            }
                            link = retValue;
                        }
                    }
                }
            }
        }
        // here we can start the parameters if it will be exported
        if(cms.getStaticExportProperties().isExportDefault() || modus == C_MODUS_EXTERN){
            link = substituteLinkParameter(cms, link);
            retValue = link;
        }else if( link.startsWith(cms.getStaticExportProperties().getUrlPrefixArray()[0])){
            link = link.substring(cms.getStaticExportProperties().getUrlPrefixArray()[0].length());
            link = substituteLinkParameter(cms, link);
            link = cms.getStaticExportProperties().getUrlPrefixArray()[0] + link;
            retValue = link;
        }

        // now for the name replacement rules
        if(nameRules != null){
            for(int i=0; i<nameRules.size(); i++){
                retValue = c_perlUtil.substitute((String)nameRules.elementAt(i), link);
                if(!retValue.equals(link)){
                    paramterOnly.add(new Boolean(false));
                    return retValue;
                }
            }
        }
        // nothing changed
        paramterOnly.add(new Boolean(true));
        return retValue;
    }

    /**
     * fills the vector of the changed links.
     */
    private void setChangedLinkVector(Vector exportLinks){
        if(m_changedLinks != null){
            int oldMode = m_cms.getMode();
            m_cms.setMode(C_MODUS_ONLINE);
            for(int i=0; i<exportLinks.size(); i++){
                m_changedLinks.add(m_cms.getLinkSubstitution((String)exportLinks.elementAt(i)));
            }
            m_cms.setMode(oldMode);
        }
    }

    /**
     * If a link has htmlparameter this methode removes them and adds an index
     * to the link. This index is the linkId in the database where all exported
     * links are saved. i.e. /test/index.html?para1=1&para2=2&para3=3 to
     * /test/index_32.html (when 32 is the databaseId of this link).
     * If the link is not in the database this methode saves it to create the id.
     *
     * @param link The Link to process.
     *
     * @return The processed link.
     */
    private static String substituteLinkParameter(CmsObject cms, String link){
        // has it parameters?
        int paraStartPos = link.indexOf('?');
        if(paraStartPos < 0){
            // no parameter - no service
            return link;
        }
        // is the export activ? (there is a new parameter false_ssl for staticexport.enabled)
        if(!cms.getStaticExportProperties().isStaticExportEnabled()){
            return link;
        }
        // cut the parameters
        String returnValue = link.substring(0,paraStartPos);
        try{
            // get the id from the database
            CmsExportLink linkObject = cms.readExportLinkHeader(link);
            if(linkObject == null){
                // it was not written before, so we have to do it here.
                linkObject = new CmsExportLink(link, 0, null);
                cms.writeExportLink(linkObject);
            }
            int id = linkObject.getId();
            // now we put this id at the right place in the link
            int pointId = returnValue.lastIndexOf('.');
            if(pointId < 0){
                return returnValue + "_"+id;
            }
            returnValue = returnValue.substring(0, pointId)+"_"+id+returnValue.substring(pointId);

        }catch(CmsException e){
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
                A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_STATICEXPORT, "[CmsStaticExport] cant substitute the htmlparameter for link: "+link+"  "+e.toString());
            }
            return link;
        }
        return returnValue;
    }
}

⌨️ 快捷键说明

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