CKFinder 自定义文件路径扩展ConfigurationPathBuilder

CKFinder 自定义文件路径扩展ConfigurationPathBuilder

打开config.xml当中可以看到如下配置

 

<basePathBuilderImpl>com.ckfinder.connector.configuration.ConfigurationPathBuilder</basePathBuilderImpl>

 

打开这个类的源代码

/*

 * CKFinder

 * ========

 * http://cksource.com/ckfinder

 * Copyright (C) 2007-2014, CKSource - Frederico Knabben. All rights reserved.

 *

 * The software, this file and its contents are subject to the CKFinder

 * License. Please read the license.txt file before using, installing, copying,

 * modifying or distribute this file or part of its contents. The contents of

 * this file is part of the Source Code of CKFinder.

 */

package com.ckfinder.connector.configuration;



import javax.servlet.http.HttpServletRequest;



import com.ckfinder.connector.utils.PathUtils;



/**

 * Path builder that creates default values of baseDir and baseURL.

 */

public class ConfigurationPathBuilder extends DefaultPathBuilder {



    /**

     * Gets configuration value of baseUrl. When config value is not set, then

     * return default value.

     *

     * @param request request

     * @return default baseDir value

     */

    @Override

    public String getBaseUrl(final HttpServletRequest request) {

        String baseURL = null;

        try {

            IConfiguration conf = ConfigurationFactory.getInstace().getConfiguration();

            baseURL = conf.getBaseURL();

        } catch (Exception e) {

            baseURL = null;

        }

        if (baseURL == null || baseURL.equals("")) {

            baseURL = super.getBaseUrl(request);

        }



        return PathUtils.addSlashToBeginning(PathUtils.addSlashToEnd(baseURL));

    }



    /**

     * Gets configuration value of baseDir. When config value is not set, then

     * return default value.

     *

     * @param request request

     * @return default baseDir value

     */

    @Override

    public String getBaseDir(final HttpServletRequest request) {

        String baseDir = null;

        try {

            IConfiguration conf = ConfigurationFactory.getInstace().getConfiguration();

            baseDir = conf.getBaseDir();

        } catch (Exception e) {

            baseDir = null;

        }

        if (baseDir == null || baseDir.equals("")) {

            return super.getBaseDir(request);

        } else {

            return baseDir;

        }

    }

}

 

一共俩个方法,一个是获取资源URL的,一个是获取服务器端文件路径的,所以我们复写这俩个方法实现我们自己的逻辑就可以了。

public class MyConfigurationPathBuilder extends ConfigurationPathBuilder {



    private String getCustomPath(HttpServletRequest request) {

        return request.getSession().getAttribute("bathPath").toString();

        //return "EP/";

    }

    

    

    /**

     * Gets configuration value of baseUrl. When config value is not set, then

     * return default value.

     *

     * @param request request

     * @return default baseDir value

     */

    @Override

    public String getBaseUrl(final HttpServletRequest request) {

        return super.getBaseUrl(request)+ getCustomPath(request);

    }



    /**

     * Gets configuration value of baseDir. When config value is not set, then

     * return default value.

     *

     * @param request request

     * @return default baseDir value

     */

    @Override

    public String getBaseDir(final HttpServletRequest request) {

        return super.getBaseDir(request) + getCustomPath(request);

    }

}

 

 

你可能感兴趣的:(configuration)