Search in sources :

Example 56 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class AjaxFactory method deployTags.

/**
 * this functions deploy all ajax tags to the Lucee enviroment and the helper files
 * @param dir tag directory
 * @param doNew redeploy even the file exist, this is set to true when a new version is started
 */
public static void deployTags(Resource dir, boolean doNew) {
    // tags
    Resource f = dir.getRealResource("AjaxImport." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/AjaxImport." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("AjaxProxy." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/AjaxProxy." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("Div." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/Div." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("Map." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/Map." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("MapItem." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/MapItem." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("Layout." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/Layout." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("LayoutArea." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/LayoutArea." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("Window." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew) {
        // String md5 = ConfigWebUtil.createMD5FromResource(f);
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/Window." + COMPONENT_EXTENSION, f);
    }
    // helper files
    dir = dir.getRealResource("lucee/core/ajax/");
    if (!dir.isDirectory())
        dir.mkdirs();
    f = dir.getRealResource("AjaxBase." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/AjaxBase." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("AjaxBinder." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/AjaxBinder." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("AjaxProxyHelper." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/AjaxProxyHelper." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("JSLoader." + COMPONENT_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/JSLoader." + COMPONENT_EXTENSION, f);
    f = dir.getRealResource("LuceeJs." + COMPONENT_EXTENSION);
    if (f.exists())
        f.delete();
    // js
    Resource jsDir = dir.getRealResource("js");
    if (!jsDir.isDirectory())
        jsDir.mkdirs();
    f = jsDir.getRealResource("LuceeAjax.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/LuceeAjax.js", f);
    f = jsDir.getRealResource("LuceeMap.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/LuceeMap.js", f);
    f = jsDir.getRealResource("LuceeWindow.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/LuceeWindow.js", f);
    f = jsDir.getRealResource("LuceeLayout.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/LuceeLayout.js", f);
    // delete wrong directory comes with 3.1.2.015
    Resource gDir = dir.getRealResource("google");
    if (gDir.isDirectory())
        ResourceUtil.removeEL(gDir, true);
    // create google/... again
    gDir = jsDir.getRealResource("google");
    if (!gDir.isDirectory())
        gDir.mkdirs();
    f = gDir.getRealResource("google-map.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/google/google-map.js", f);
    // jquery resources
    Resource jqDir = jsDir.getRealResource("jquery");
    if (!jqDir.isDirectory())
        jqDir.mkdirs();
    f = jqDir.getRealResource("jquery-1.4.2.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/jquery/jquery-1.4.2.js", f);
    f = jqDir.getRealResource("jquery-ui-1.8.2.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/jquery/jquery-ui-1.8.2.js", f);
    f = jqDir.getRealResource("jquery.layout.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/jquery/jquery.layout.js", f);
    f = jqDir.getRealResource("jquery.window.js");
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/js/jquery/jquery.window.js", f);
    // css Skin
    Resource cssDir = dir.getRealResource("css/jquery");
    if (!cssDir.isDirectory())
        cssDir.mkdirs();
    f = cssDir.getRealResource("LuceeSkin.css." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/LuceeSkin.css." + TEMPLATE_EXTENSION, f);
    // css images
    Resource imgDir = cssDir.getRealResource("images");
    if (!imgDir.isDirectory())
        imgDir.mkdirs();
    f = imgDir.getRealResource("ui-anim_basic_16x16.gif." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-anim_basic_16x16.gif." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-bg_flat_0_aaaaaa_40x100.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-bg_flat_0_aaaaaa_40x100.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-bg_flat_75_ffffff_40x100.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-bg_flat_75_ffffff_40x100.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-bg_glass_55_fbf9ee_1x400.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-bg_glass_55_fbf9ee_1x400.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-bg_glass_65_ffffff_1x400.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-bg_glass_65_ffffff_1x400.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-bg_glass_75_dadada_1x400.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-bg_glass_75_dadada_1x400.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-bg_glass_75_e6e6e6_1x400.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-bg_glass_75_e6e6e6_1x400.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-bg_glass_95_fef1ec_1x400.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-bg_glass_95_fef1ec_1x400.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-bg_highlight-soft_75_cccccc_1x100.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-bg_highlight-soft_75_cccccc_1x100.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-icons_222222_256x240.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-icons_222222_256x240.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-icons_2e83ff_256x240.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-icons_2e83ff_256x240.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-icons_454545_256x240.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-icons_454545_256x240.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-icons_888888_256x240.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-icons_888888_256x240.png." + TEMPLATE_EXTENSION, f);
    f = imgDir.getRealResource("ui-icons_cd0a0a_256x240.png." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/css/jquery/images/ui-icons_cd0a0a_256x240.png." + TEMPLATE_EXTENSION, f);
    // image loader
    dir = dir.getRealResource("loader");
    if (!dir.isDirectory())
        dir.mkdirs();
    f = dir.getRealResource("loading.gif." + TEMPLATE_EXTENSION);
    if (!f.exists() || doNew)
        XMLConfigFactory.createFileFromResourceEL("/resource/library/tag/lucee/core/ajax/loader/loading.gif." + TEMPLATE_EXTENSION, f);
}
Also used : Resource(lucee.commons.io.res.Resource)

Example 57 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class CFMLEngineImpl method deployBundledExtension.

private void deployBundledExtension(ConfigServerImpl cs) {
    Resource dir = cs.getLocalExtensionProviderDirectory();
    List<ExtensionDefintion> existing = DeployHandler.getLocalExtensions(cs);
    Map<String, ExtensionDefintion> existingMap = new HashMap<String, ExtensionDefintion>();
    {
        Iterator<ExtensionDefintion> it = existing.iterator();
        ExtensionDefintion ed;
        while (it.hasNext()) {
            ed = it.next();
            try {
                existingMap.put(ed.getSource().getName(), ed);
            } catch (ApplicationException e) {
            }
        }
    }
    Log log = cs.getLog("deploy");
    // get the index
    ClassLoader cl = CFMLEngineFactory.getInstance().getCFMLEngineFactory().getClass().getClassLoader();
    InputStream is = cl.getResourceAsStream("extensions/.index");
    if (is == null)
        is = cl.getResourceAsStream("/extensions/.index");
    if (is == null)
        is = SystemUtil.getResourceAsStream(null, "/extensions/.index");
    if (is == null) {
        log.error("extract-extension", "could not found [/extensions/.index] defined in the index in the lucee.jar");
        return;
    }
    try {
        String index = IOUtil.toString(is, CharsetUtil.UTF8);
        log.info("extract-extension", "the following extensions are bundled with the lucee.jar [" + index + "]");
        String[] names = lucee.runtime.type.util.ListUtil.listToStringArray(index, ';');
        String name;
        Resource temp = null;
        RHExtension rhe;
        ExtensionDefintion exist;
        Iterator<ExtensionDefintion> it;
        for (int i = 0; i < names.length; i++) {
            name = names[i];
            if (StringUtil.isEmpty(name, true))
                continue;
            name = name.trim();
            // does it already exist?
            if (existingMap.containsKey(name)) {
                continue;
            }
            is = cl.getResourceAsStream("extensions/" + name);
            if (is == null)
                is = cl.getResourceAsStream("/extensions/" + name);
            if (is == null) {
                log.error("extract-extension", "could not found extension [" + name + "] defined in the index in the lucee.jar");
                continue;
            }
            try {
                temp = SystemUtil.getTempDirectory().getRealResource(name);
                ResourceUtil.touch(temp);
                Util.copy(is, temp.getOutputStream(), false, true);
                rhe = new RHExtension(cs, temp, false);
                ExtensionDefintion alreadyExists = null;
                it = existing.iterator();
                while (it.hasNext()) {
                    exist = it.next();
                    if (exist.equals(rhe)) {
                        alreadyExists = exist;
                        break;
                    }
                }
                String trgName = rhe.getId() + "-" + rhe.getVersion() + ".lex";
                if (alreadyExists == null) {
                    temp.moveTo(dir.getRealResource(trgName));
                    log.info("extract-extension", "added [" + name + "] to [" + dir + "]");
                } else if (!alreadyExists.getSource().getName().equals(trgName)) {
                    log.info("extract-extension", "rename [" + alreadyExists.getSource() + "] to [" + trgName + "]");
                    alreadyExists.getSource().moveTo(alreadyExists.getSource().getParentResource().getRealResource(trgName));
                }
                // now we check all extension name (for extension no longer delivered by lucee)
                it = existing.iterator();
                while (it.hasNext()) {
                    exist = it.next();
                    trgName = exist.getId() + "-" + exist.getVersion() + ".lex";
                    if (!trgName.equals(exist.getSource().getName())) {
                        exist.getSource().moveTo(exist.getSource().getParentResource().getRealResource(trgName));
                        log.info("extract-extension", "rename [" + exist.getSource() + "] to [" + trgName + "]");
                    }
                }
            } finally {
                if (temp != null && temp.exists())
                    temp.delete();
            }
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        log.error("extract-extension", t);
    }
    return;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Log(lucee.commons.io.log.Log) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) RHExtension(lucee.runtime.extension.RHExtension) ApplicationException(lucee.runtime.exp.ApplicationException) ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) Iterator(java.util.Iterator)

Example 58 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class CFMLEngineImpl method cli.

@Override
public void cli(Map<String, String> config, ServletConfig servletConfig) throws IOException, JspException, ServletException {
    ServletContext servletContext = servletConfig.getServletContext();
    HTTPServletImpl servlet = new HTTPServletImpl(servletConfig, servletContext, servletConfig.getServletName());
    // webroot
    String strWebroot = config.get("webroot");
    if (StringUtil.isEmpty(strWebroot, true))
        throw new IOException("missing webroot configuration");
    Resource root = ResourcesImpl.getFileResourceProvider().getResource(strWebroot);
    root.mkdirs();
    // serverName
    String serverName = config.get("server-name");
    if (StringUtil.isEmpty(serverName, true))
        serverName = "localhost";
    // uri
    String strUri = config.get("uri");
    if (StringUtil.isEmpty(strUri, true))
        throw new IOException("missing uri configuration");
    URI uri;
    try {
        uri = lucee.commons.net.HTTPUtil.toURI(strUri);
    } catch (URISyntaxException e) {
        throw Caster.toPageException(e);
    }
    // cookie
    Cookie[] cookies;
    String strCookie = config.get("cookie");
    if (StringUtil.isEmpty(strCookie, true))
        cookies = new Cookie[0];
    else {
        Map<String, String> mapCookies = HTTPUtil.parseParameterList(strCookie, false, null);
        int index = 0;
        cookies = new Cookie[mapCookies.size()];
        Entry<String, String> entry;
        Iterator<Entry<String, String>> it = mapCookies.entrySet().iterator();
        Cookie c;
        while (it.hasNext()) {
            entry = it.next();
            c = ReqRspUtil.toCookie(entry.getKey(), entry.getValue(), null);
            if (c != null)
                cookies[index++] = c;
            else
                throw new IOException("cookie name [" + entry.getKey() + "] is invalid");
        }
    }
    // header
    Pair[] headers = new Pair[0];
    // parameters
    Pair[] parameters = new Pair[0];
    // attributes
    StructImpl attributes = new StructImpl();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    HttpServletRequestDummy req = new HttpServletRequestDummy(root, serverName, uri.getPath(), uri.getQuery(), cookies, headers, parameters, attributes, null, null);
    req.setProtocol("CLI/1.0");
    HttpServletResponse rsp = new HttpServletResponseDummy(os);
    serviceCFML(servlet, req, rsp);
    String res = os.toString(ReqRspUtil.getCharacterEncoding(null, rsp).name());
    System.out.println(res);
}
Also used : Cookie(javax.servlet.http.Cookie) Resource(lucee.commons.io.res.Resource) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(java.net.URI) ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) HttpServletRequestDummy(lucee.runtime.net.http.HttpServletRequestDummy) ServletContext(javax.servlet.ServletContext) HttpServletResponseDummy(lucee.runtime.net.http.HttpServletResponseDummy) HTTPServletImpl(lucee.cli.servlet.HTTPServletImpl) Pair(lucee.commons.lang.Pair)

Example 59 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class CFMLEngineImpl method getConfigDirectory.

/**
 * loads Configuration File from System, from init Parameter from web.xml
 *
 * @param sg
 * @param configServer
 * @param countExistingContextes
 * @return return path to directory
 */
private Resource getConfigDirectory(ServletConfig sg, ConfigServerImpl configServer, int countExistingContextes, RefBoolean isCustomSetting) throws PageServletException {
    isCustomSetting.setValue(true);
    ServletContext sc = sg.getServletContext();
    String strConfig = sg.getInitParameter("configuration");
    if (StringUtil.isEmpty(strConfig))
        strConfig = sg.getInitParameter("lucee-web-directory");
    if (StringUtil.isEmpty(strConfig))
        strConfig = System.getProperty("lucee.web.dir");
    if (StringUtil.isEmpty(strConfig)) {
        isCustomSetting.setValue(false);
        strConfig = "{web-root-directory}/WEB-INF/lucee/";
    } else // only for backward compatibility
    if (strConfig.startsWith("/WEB-INF/lucee/"))
        strConfig = "{web-root-directory}" + strConfig;
    strConfig = StringUtil.removeQuotes(strConfig, true);
    // static path is not allowed
    if (countExistingContextes > 1 && strConfig != null && strConfig.indexOf('{') == -1) {
        String text = "static path [" + strConfig + "] for servlet init param [lucee-web-directory] is not allowed, path must use a web-context specific placeholder.";
        System.err.println(text);
        throw new PageServletException(new ApplicationException(text));
    }
    strConfig = SystemUtil.parsePlaceHolder(strConfig, sc, configServer.getLabels());
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    Resource root = frp.getResource(ReqRspUtil.getRootPath(sc));
    Resource res;
    Resource configDir = ResourceUtil.createResource(res = root.getRealResource(strConfig), FileUtil.LEVEL_PARENT_FILE, FileUtil.TYPE_DIR);
    if (configDir == null) {
        configDir = ResourceUtil.createResource(res = frp.getResource(strConfig), FileUtil.LEVEL_GRAND_PARENT_FILE, FileUtil.TYPE_DIR);
    }
    if (configDir == null && !isCustomSetting.toBooleanValue()) {
        try {
            res.createDirectory(true);
            configDir = res;
        } catch (IOException e) {
            throw new PageServletException(Caster.toPageException(e));
        }
    }
    if (configDir == null) {
        throw new PageServletException(new ApplicationException("path [" + strConfig + "] is invalid"));
    }
    if (!configDir.exists() || ResourceUtil.isEmptyDirectory(configDir, null)) {
        Resource railoRoot;
        // there is a railo directory
        if (configDir.getName().equals("lucee") && (railoRoot = configDir.getParentResource().getRealResource("railo")).isDirectory()) {
            try {
                copyRecursiveAndRename(railoRoot, configDir);
            } catch (IOException e) {
                try {
                    configDir.createDirectory(true);
                } catch (IOException ioe) {
                }
                return configDir;
            }
            // zip the railo-server di and delete it (optional)
            try {
                Resource p = railoRoot.getParentResource();
                CompressUtil.compress(CompressUtil.FORMAT_ZIP, railoRoot, p.getRealResource("railo-web-context-old.zip"), false, -1);
                ResourceUtil.removeEL(railoRoot, true);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        } else {
            try {
                configDir.createDirectory(true);
            } catch (IOException e) {
            }
        }
    }
    return configDir;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) ResourceProvider(lucee.commons.io.res.ResourceProvider) Resource(lucee.commons.io.res.Resource) ServletContext(javax.servlet.ServletContext) PageServletException(lucee.runtime.exp.PageServletException) IOException(java.io.IOException)

Example 60 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class Controler method checkSize.

private void checkSize(ConfigWeb config, Resource dir, long maxSize, ResourceFilter filter) {
    if (!dir.exists())
        return;
    Resource res = null;
    int count = ArrayUtil.size(filter == null ? dir.list() : dir.list(filter));
    long size = ResourceUtil.getRealSize(dir, filter);
    PrintWriter out = config.getOutWriter();
    SystemOut.printDate(out, "check size of directory [" + dir + "]");
    SystemOut.printDate(out, "- current size	[" + size + "]");
    SystemOut.printDate(out, "- max size 	[" + maxSize + "]");
    int len = -1;
    while (count > 100000 || size > maxSize) {
        Resource[] files = filter == null ? dir.listResources() : dir.listResources(filter);
        // protect from inifinti loop
        if (len == files.length)
            break;
        len = files.length;
        for (int i = 0; i < files.length; i++) {
            if (res == null || res.lastModified() > files[i].lastModified()) {
                res = files[i];
            }
        }
        if (res != null) {
            size -= res.length();
            try {
                res.remove(true);
                count--;
            } catch (IOException e) {
                SystemOut.printDate(out, "cannot remove resource " + res.getAbsolutePath());
                break;
            }
        }
        res = null;
    }
}
Also used : Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

Resource (lucee.commons.io.res.Resource)309 IOException (java.io.IOException)100 ApplicationException (lucee.runtime.exp.ApplicationException)54 PageException (lucee.runtime.exp.PageException)40 ArrayList (java.util.ArrayList)31 Struct (lucee.runtime.type.Struct)28 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 ExpressionException (lucee.runtime.exp.ExpressionException)19 StructImpl (lucee.runtime.type.StructImpl)18 MalformedURLException (java.net.MalformedURLException)17 PageContextImpl (lucee.runtime.PageContextImpl)17 PageSource (lucee.runtime.PageSource)16 FileResource (lucee.commons.io.res.type.file.FileResource)15 SecurityException (lucee.runtime.exp.SecurityException)15 BundleException (org.osgi.framework.BundleException)15 ZipEntry (java.util.zip.ZipEntry)13 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)13 Array (lucee.runtime.type.Array)13 File (java.io.File)12