Search in sources :

Example 46 with Resource

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

the class XMLConfigServerFactory method reloadInstance.

/**
 * reloads the Config Object
 * @param configServer
 * @throws SAXException
 * @throws ClassNotFoundException
 * @throws PageException
 * @throws IOException
 * @throws TagLibException
 * @throws FunctionLibException
 * @throws BundleException
 */
public static void reloadInstance(CFMLEngine engine, ConfigServerImpl configServer) throws SAXException, ClassException, PageException, IOException, TagLibException, FunctionLibException, BundleException {
    Resource configFile = configServer.getConfigFile();
    if (configFile == null)
        return;
    if (second(configServer.getLoadTime()) > second(configFile.lastModified()))
        return;
    int iDoNew = doNew(engine, configServer.getConfigDir(), false).updateType;
    boolean doNew = iDoNew != NEW_NONE;
    load(configServer, loadDocument(configFile), true, doNew);
    ((CFMLEngineImpl) ConfigWebUtil.getEngine(configServer)).onStart(configServer, true);
}
Also used : CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource)

Example 47 with Resource

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

the class XMLConfigServerFactory method newInstance.

/**
 * creates a new ServletConfig Impl Object
 * @param engine
 * @param initContextes
 * @param contextes
 * @param configDir
 * @return new Instance
 * @throws SAXException
 * @throws ClassNotFoundException
 * @throws PageException
 * @throws IOException
 * @throws TagLibException
 * @throws FunctionLibException
 * @throws BundleException
 */
public static ConfigServerImpl newInstance(CFMLEngineImpl engine, Map<String, CFMLFactory> initContextes, Map<String, CFMLFactory> contextes, Resource configDir) throws SAXException, ClassException, PageException, IOException, TagLibException, FunctionLibException, BundleException {
    boolean isCLI = SystemUtil.isCLICall();
    if (isCLI) {
        Resource logs = configDir.getRealResource("logs");
        logs.mkdirs();
        Resource out = logs.getRealResource("out");
        Resource err = logs.getRealResource("err");
        ResourceUtil.touch(out);
        ResourceUtil.touch(err);
        if (logs instanceof FileResource) {
            SystemUtil.setPrintWriter(SystemUtil.OUT, new PrintWriter((FileResource) out));
            SystemUtil.setPrintWriter(SystemUtil.ERR, new PrintWriter((FileResource) err));
        } else {
            SystemUtil.setPrintWriter(SystemUtil.OUT, new PrintWriter(IOUtil.getWriter(out, "UTF-8")));
            SystemUtil.setPrintWriter(SystemUtil.ERR, new PrintWriter(IOUtil.getWriter(err, "UTF-8")));
        }
    }
    SystemOut.print(SystemUtil.getPrintWriter(SystemUtil.OUT), "===================================================================\n" + "SERVER CONTEXT\n" + "-------------------------------------------------------------------\n" + "- config:" + configDir + "\n" + "- loader-version:" + SystemUtil.getLoaderVersion() + "\n" + "- core-version:" + engine.getInfo().getVersion() + "\n" + "===================================================================\n");
    int iDoNew = doNew(engine, configDir, false).updateType;
    boolean doNew = iDoNew != NEW_NONE;
    Resource configFile = configDir.getRealResource("lucee-server.xml");
    if (!configFile.exists()) {
        configFile.createFile(true);
        // InputStream in = new TextFile("").getClass().getResourceAsStream("/resource/config/server.xml");
        createFileFromResource("/resource/config/server.xml", configFile.getAbsoluteResource(), "tpiasfap");
    }
    Document doc = loadDocumentCreateIfFails(configFile, "server");
    // get version
    Element luceeConfiguration = doc.getDocumentElement();
    String strVersion = luceeConfiguration.getAttribute("version");
    double version = Caster.toDoubleValue(strVersion, 1.0d);
    boolean cleanupDatasources = version < 5.0D;
    ConfigServerImpl config = new ConfigServerImpl(engine, initContextes, contextes, configDir, configFile);
    load(config, doc, false, doNew);
    createContextFiles(configDir, config, doNew, cleanupDatasources);
    ((CFMLEngineImpl) ConfigWebUtil.getEngine(config)).onStart(config, false);
    return config;
}
Also used : CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) Element(org.w3c.dom.Element) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) FileResource(lucee.commons.io.res.type.file.FileResource) Document(org.w3c.dom.Document) PrintWriter(java.io.PrintWriter)

Example 48 with Resource

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

the class XMLConfigServerFactory method createContextFiles.

private static void createContextFiles(Resource configDir, ConfigServer config, boolean doNew, boolean cleanupDatasources) {
    Resource contextDir = configDir.getRealResource("context");
    Resource adminDir = contextDir.getRealResource("admin");
    // Debug
    Resource debug = adminDir.getRealResource("debug");
    create("/resource/context/admin/debug/", new String[] { "Debug.cfc", "Field.cfc", "Group.cfc", "Classic.cfc", "Modern.cfc", "Comment.cfc" }, debug, doNew);
    // DB Drivers types
    Resource dbDir = adminDir.getRealResource("dbdriver");
    Resource typesDir = dbDir.getRealResource("types");
    create("/resource/context/admin/dbdriver/types/", new String[] { "IDriver.cfc", "Driver.cfc", "IDatasource.cfc", "IDriverSelector.cfc", "Field.cfc" }, typesDir, doNew);
    create("/resource/context/admin/dbdriver/", new String[] { "Other.cfc" }, dbDir, doNew);
    // Cache Drivers
    Resource cDir = adminDir.getRealResource("cdriver");
    create("/resource/context/admin/cdriver/", new String[] { "Cache.cfc", "RamCache.cfc", // ,"EHCache.cfc"
    "Field.cfc", "Group.cfc" }, cDir, doNew);
    Resource wcdDir = configDir.getRealResource("web-context-deployment/admin");
    Resource cdDir = wcdDir.getRealResource("cdriver");
    try {
        ResourceUtil.deleteEmptyFolders(wcdDir);
    } catch (IOException e) {
        SystemOut.printDate(e);
    }
    // Mail Server Drivers
    Resource msDir = adminDir.getRealResource("mailservers");
    create("/resource/context/admin/mailservers/", new String[] { "Other.cfc", "GMail.cfc", "GMX.cfc", "iCloud.cfc", "Yahoo.cfc", "Outlook.cfc", "MailServer.cfc" }, msDir, doNew);
    // Gateway Drivers
    Resource gDir = adminDir.getRealResource("gdriver");
    create("/resource/context/admin/gdriver/", new String[] { "TaskGatewayDriver.cfc", "DirectoryWatcher.cfc", "MailWatcher.cfc", "Gateway.cfc", "Field.cfc", "Group.cfc" }, gDir, doNew);
    // Logging/appender
    Resource app = adminDir.getRealResource("logging/appender");
    create("/resource/context/admin/logging/appender/", new String[] { "ConsoleAppender.cfc", "ResourceAppender.cfc", "Appender.cfc", "Field.cfc", "Group.cfc" }, app, doNew);
    // Logging/layout
    Resource lay = adminDir.getRealResource("logging/layout");
    create("/resource/context/admin/logging/layout/", new String[] { "ClassicLayout.cfc", "HTMLLayout.cfc", "PatternLayout.cfc", "XMLLayout.cfc", "Layout.cfc", "Field.cfc", "Group.cfc" }, lay, doNew);
    // Security
    Resource secDir = configDir.getRealResource("security");
    if (!secDir.exists())
        secDir.mkdirs();
    Resource res = create("/resource/security/", "cacerts", secDir, false);
    System.setProperty("javax.net.ssl.trustStore", res.toString());
    // ESAPI
    Resource propDir = configDir.getRealResource("properties");
    if (!propDir.exists())
        propDir.mkdirs();
    create("/resource/properties/", "ESAPI.properties", propDir, doNew);
    System.setProperty("org.owasp.esapi.resources", propDir.toString());
    // Jacob
    if (SystemUtil.isWindows()) {
        Resource binDir = configDir.getRealResource("bin");
        if (binDir != null) {
            if (!binDir.exists())
                binDir.mkdirs();
            String name = (SystemUtil.getJREArch() == SystemUtil.ARCH_64) ? "jacob-x64.dll" : "jacob-i586.dll";
            Resource jacob = binDir.getRealResource(name);
            if (!jacob.exists()) {
                createFileFromResourceEL("/resource/bin/windows" + ((SystemUtil.getJREArch() == SystemUtil.ARCH_64) ? "64" : "32") + "/" + name, jacob);
            }
            // SystemOut.printDate(SystemUtil.PRINTWRITER_OUT,"set-property -> "+LibraryLoader.JACOB_DLL_PATH+":"+jacob.getAbsolutePath());
            System.setProperty(LibraryLoader.JACOB_DLL_PATH, jacob.getAbsolutePath());
            // SystemOut.printDate(SystemUtil.PRINTWRITER_OUT,"set-property -> "+LibraryLoader.JACOB_DLL_NAME+":"+name);
            System.setProperty(LibraryLoader.JACOB_DLL_NAME, name);
        }
    }
}
Also used : Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) IOException(java.io.IOException)

Example 49 with Resource

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

the class XMLConfigWebFactory method loadTempDirectory.

private static void loadTempDirectory(ConfigServerImpl configServer, ConfigImpl config, Document doc, boolean isReload) throws ExpressionException {
    Resource configDir = config.getConfigDir();
    boolean hasCS = configServer != null;
    Element fileSystem = getChildByName(doc.getDocumentElement(), "file-system");
    if (fileSystem == null)
        fileSystem = getChildByName(doc.getDocumentElement(), "filesystem");
    String strTempDirectory = null;
    if (fileSystem != null)
        strTempDirectory = ConfigWebUtil.translateOldPath(fileSystem.getAttribute("temp-directory"));
    Resource cst = null;
    // Temp Dir
    if (!StringUtil.isEmpty(strTempDirectory))
        cst = ConfigWebUtil.getFile(configDir, strTempDirectory, null, configDir, FileUtil.TYPE_DIR, config);
    if (cst == null && hasCS)
        cst = configServer.getTempDirectory();
    if (cst == null)
        cst = ConfigWebUtil.getFile(configDir, "temp", null, configDir, FileUtil.TYPE_DIR, config);
    config.setTempDirectory(cst, !isReload);
}
Also used : Element(org.w3c.dom.Element) Resource(lucee.commons.io.res.Resource)

Example 50 with Resource

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

the class XMLConfigWebFactory method getNewResources.

private static Resource[] getNewResources(Resource[] srcs, Resource[] trgs) {
    Resource trg;
    java.util.List<Resource> list = new ArrayList<Resource>();
    outer: for (int i = 0; i < trgs.length; i++) {
        trg = trgs[i];
        for (int y = 0; y < srcs.length; y++) {
            if (trg.equals(srcs[y]))
                continue outer;
        }
        list.add(trg);
    }
    return list.toArray(new Resource[list.size()]);
}
Also used : Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList)

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