Search in sources :

Example 56 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class XMLConfigAdmin method updateRHExtension.

public void updateRHExtension(Config config, RHExtension rhext, boolean reload) throws PageException {
    ConfigImpl ci = (ConfigImpl) config;
    Log logger = ci.getLog("deploy");
    String type = ci instanceof ConfigWeb ? "web" : "server";
    // load already installed previous version and uninstall the parts no longer needed
    RHExtension existingRH = getRHExtension(ci, rhext.getId(), null);
    if (existingRH != null) {
        // same version
        if (existingRH.getVersion().compareTo(rhext.getVersion()) == 0) {
            removeRHExtension(config, existingRH, rhext, false);
        } else
            removeRHExtension(config, existingRH, rhext, true);
    }
    // INSTALL
    try {
        // boolean clearTags=false,clearFunction=false;
        boolean reloadNecessary = false;
        // store to xml
        BundleDefinition[] existing = _updateExtension(ci, rhext);
        // _storeAndReload();
        // this must happen after "store"
        // clean after populating the new ones
        cleanBundles(rhext, ci, existing);
        // ConfigWebAdmin.updateRHExtension(ci,rhext);
        ZipInputStream zis = new ZipInputStream(IOUtil.toBufferedInputStream(rhext.getExtensionFile().getInputStream()));
        ZipEntry entry;
        String path;
        String fileName;
        while ((entry = zis.getNextEntry()) != null) {
            path = entry.getName();
            fileName = fileName(entry);
            // jars
            if (!entry.isDirectory() && (startsWith(path, type, "jars") || startsWith(path, type, "jar") || startsWith(path, type, "bundles") || startsWith(path, type, "bundle") || startsWith(path, type, "lib") || startsWith(path, type, "libs")) && StringUtil.endsWithIgnoreCase(path, ".jar")) {
                Object obj = XMLConfigAdmin.installBundle(config, zis, fileName, rhext.getVersion(), false, false);
                // jar is not a bundle, only a regular jar
                if (!(obj instanceof BundleFile)) {
                    Resource tmp = (Resource) obj;
                    Resource tmpJar = tmp.getParentResource().getRealResource(ListUtil.last(path, "\\/"));
                    tmp.moveTo(tmpJar);
                    XMLConfigAdmin.updateJar(config, tmpJar, false);
                }
            }
            // flds
            if (!entry.isDirectory() && startsWith(path, type, "flds") && (StringUtil.endsWithIgnoreCase(path, ".fld") || StringUtil.endsWithIgnoreCase(path, ".fldx"))) {
                logger.log(Log.LEVEL_INFO, "extension", "deploy fld " + fileName);
                updateFLD(zis, fileName, false);
                reloadNecessary = true;
            }
            // tlds
            if (!entry.isDirectory() && startsWith(path, type, "tlds") && (StringUtil.endsWithIgnoreCase(path, ".tld") || StringUtil.endsWithIgnoreCase(path, ".tldx"))) {
                logger.log(Log.LEVEL_INFO, "extension", "deploy tld/tldx " + fileName);
                updateTLD(zis, fileName, false);
                reloadNecessary = true;
            }
            // tags
            if (!entry.isDirectory() && startsWith(path, type, "tags")) {
                String sub = subFolder(entry);
                logger.log(Log.LEVEL_INFO, "extension", "deploy tag " + sub);
                updateTag(zis, sub, false);
                // clearTags=true;
                reloadNecessary = true;
            }
            // functions
            if (!entry.isDirectory() && startsWith(path, type, "functions")) {
                String sub = subFolder(entry);
                logger.log(Log.LEVEL_INFO, "extension", "deploy function " + sub);
                updateFunction(zis, sub, false);
                // clearFunction=true;
                reloadNecessary = true;
            }
            // mappings
            if (!entry.isDirectory() && (startsWith(path, type, "archives") || startsWith(path, type, "mappings"))) {
                String sub = subFolder(entry);
                logger.log(Log.LEVEL_INFO, "extension", "deploy mapping " + sub);
                updateArchive(zis, sub, false);
                reloadNecessary = true;
            // clearFunction=true;
            }
            // event-gateway
            if (!entry.isDirectory() && (startsWith(path, type, "event-gateways") || startsWith(path, type, "eventGateways")) && (StringUtil.endsWithIgnoreCase(path, "." + Constants.getCFMLComponentExtension()) || StringUtil.endsWithIgnoreCase(path, "." + Constants.getLuceeComponentExtension()))) {
                String sub = subFolder(entry);
                logger.log(Log.LEVEL_INFO, "extension", "deploy event-gateway " + sub);
                updateEventGateway(zis, sub, false);
            }
            // context
            String realpath;
            if (!entry.isDirectory() && startsWith(path, type, "context") && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(8);
                logger.log(Log.LEVEL_INFO, "extension", "deploy context " + realpath);
                updateContext(zis, realpath, false, false);
            }
            // web contextS
            boolean first;
            if (!entry.isDirectory() && ((first = startsWith(path, type, "webcontexts")) || startsWith(path, type, "web.contexts")) && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(first ? 12 : 13);
                logger.log(Log.LEVEL_INFO, "extension", "deploy webcontext " + realpath);
                updateWebContexts(zis, realpath, false, false);
            }
            // applications
            if (!entry.isDirectory() && (startsWith(path, type, "applications") || startsWith(path, type, "web.applications") || startsWith(path, type, "web")) && !StringUtil.startsWith(fileName(entry), '.')) {
                int index;
                if (startsWith(path, type, "applications"))
                    index = 13;
                else if (startsWith(path, type, "web.applications"))
                    index = 17;
                else
                    // web
                    index = 4;
                realpath = path.substring(index);
                logger.log(Log.LEVEL_INFO, "extension", "deploy application " + realpath);
                updateApplication(zis, realpath, false);
            }
            // configs
            if (!entry.isDirectory() && (startsWith(path, type, "config")) && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(7);
                logger.log(Log.LEVEL_INFO, "extension", "deploy config " + realpath);
                updateConfigs(zis, realpath, false, false);
            }
            // components
            if (!entry.isDirectory() && (startsWith(path, type, "components")) && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(11);
                logger.log(Log.LEVEL_INFO, "extension", "deploy component " + realpath);
                updateComponent(zis, realpath, false, false);
            }
            // plugins
            if (!entry.isDirectory() && (startsWith(path, type, "plugins")) && !StringUtil.startsWith(fileName(entry), '.')) {
                realpath = path.substring(8);
                logger.log(Log.LEVEL_INFO, "extension", "deploy plugin " + realpath);
                updatePlugin(zis, realpath, false);
            }
            zis.closeEntry();
        }
        // load the bundles
        if (rhext.getStartBundles()) {
            rhext.deployBundles(ci);
            BundleInfo[] bfs = rhext.getBundles();
            for (BundleInfo bf : bfs) {
                OSGiUtil.loadBundleFromLocal(bf.getSymbolicName(), bf.getVersion(), false, null);
            }
        }
        // update cache
        if (!ArrayUtil.isEmpty(rhext.getCaches())) {
            Iterator<Map<String, String>> itl = rhext.getCaches().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.isBundle()) {
                    _updateCache(cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update cache [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update cache handler
        if (!ArrayUtil.isEmpty(rhext.getCacheHandlers())) {
            Iterator<Map<String, String>> itl = rhext.getCacheHandlers().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String _id = map.get("id");
                if (!StringUtil.isEmpty(_id) && cd != null && cd.hasClass()) {
                    _updateCacheHandler(_id, cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update cache handler [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update AMF
        if (!ArrayUtil.isEmpty(rhext.getAMFs())) {
            Iterator<Map<String, String>> itl = rhext.getAMFs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _updateAMFEngine(cd, map.get("caster"), map.get("configuration"));
                    reloadNecessary = true;
                }
                logger.info("extension", "update AMF engine [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update Search
        if (!ArrayUtil.isEmpty(rhext.getSearchs())) {
            Iterator<Map<String, String>> itl = rhext.getSearchs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _updateSearchEngine(cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update search engine [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update Resource
        if (!ArrayUtil.isEmpty(rhext.getResources())) {
            Iterator<Map<String, String>> itl = rhext.getResources().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String scheme = map.get("scheme");
                if (cd != null && cd.hasClass() && !StringUtil.isEmpty(scheme)) {
                    Struct args = new StructImpl();
                    copyButIgnoreClassDef(map, args);
                    args.remove("scheme");
                    _updateResourceProvider(scheme, cd, args);
                    reloadNecessary = true;
                }
                logger.info("extension", "update resource provider [" + scheme + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update orm
        if (!ArrayUtil.isEmpty(rhext.getOrms())) {
            Iterator<Map<String, String>> itl = rhext.getOrms().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _updateORMEngine(cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update orm engine [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update monitor
        if (!ArrayUtil.isEmpty(rhext.getMonitors())) {
            Iterator<Map<String, String>> itl = rhext.getMonitors().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                if (cd != null && cd.hasClass()) {
                    _updateMonitorEnabled(true);
                    _updateMonitor(cd, map.get("type"), map.get("name"), true);
                    reloadNecessary = true;
                }
                logger.info("extension", "update monitor engine [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update jdbc
        if (!ArrayUtil.isEmpty(rhext.getJdbcs())) {
            Iterator<Map<String, String>> itl = rhext.getJdbcs().iterator();
            Map<String, String> map;
            while (itl.hasNext()) {
                map = itl.next();
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                String _label = map.get("label");
                if (cd != null && cd.isBundle()) {
                    _updateJDBCDriver(_label, cd);
                    reloadNecessary = true;
                }
                logger.info("extension", "update JDBC Driver [" + _label + ":" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // update mapping
        if (!ArrayUtil.isEmpty(rhext.getMappings())) {
            Iterator<Map<String, String>> itl = rhext.getMappings().iterator();
            Map<String, String> map;
            String virtual, physical, archive, primary;
            short inspect;
            int lmode, ltype;
            boolean toplevel, readonly;
            while (itl.hasNext()) {
                map = itl.next();
                virtual = map.get("virtual");
                physical = map.get("physical");
                archive = map.get("archive");
                primary = map.get("primary");
                inspect = ConfigWebUtil.inspectTemplate(map.get("inspect"), Config.INSPECT_UNDEFINED);
                lmode = ConfigWebUtil.toListenerMode(map.get("listener-mode"), -1);
                ltype = ConfigWebUtil.toListenerType(map.get("listener-type"), -1);
                toplevel = Caster.toBooleanValue(map.get("toplevel"), false);
                readonly = Caster.toBooleanValue(map.get("readonly"), false);
                _updateMapping(virtual, physical, archive, primary, inspect, toplevel, lmode, ltype, readonly);
                reloadNecessary = true;
                logger.info("extension", "update Mapping [" + virtual + "]");
            }
        }
        if (!ArrayUtil.isEmpty(rhext.getEventGatewayInstances())) {
            Iterator<Map<String, Object>> itl = rhext.getEventGatewayInstances().iterator();
            Map<String, Object> map;
            while (itl.hasNext()) {
                map = itl.next();
                // id
                String id = Caster.toString(map.get("id"), null);
                // class
                ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
                // component path
                String cfcPath = Caster.toString(map.get("cfc-path"), null);
                if (StringUtil.isEmpty(cfcPath))
                    cfcPath = Caster.toString(map.get("component-path"), null);
                // listener component path
                String listenerCfcPath = Caster.toString(map.get("listener-cfc-path"), null);
                if (StringUtil.isEmpty(listenerCfcPath))
                    listenerCfcPath = Caster.toString(map.get("listener-component-path"), null);
                // startup mode
                String strStartupMode = Caster.toString(map.get("startup-mode"), "automatic");
                int startupMode = GatewayEntryImpl.toStartup(strStartupMode, GatewayEntryImpl.STARTUP_MODE_AUTOMATIC);
                // read only
                boolean readOnly = Caster.toBooleanValue(map.get("read-only"), false);
                // custom
                Struct custom = Caster.toStruct(map.get("custom"), null);
                if (!StringUtil.isEmpty(id) && (!StringUtil.isEmpty(cfcPath) || (cd != null && cd.hasClass()))) {
                    _updateGatewayEntry(id, cd, cfcPath, listenerCfcPath, startupMode, custom, readOnly);
                }
                logger.info("extension", "update event gateway entry [" + id + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
            }
        }
        // reload
        // if(reloadNecessary){
        reloadNecessary = true;
        if (reload && reloadNecessary)
            _storeAndReload();
        else
            _store();
    // }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        DeployHandler.moveToFailedFolder(rhext.getExtensionFile().getParentResource(), rhext.getExtensionFile());
        try {
            XMLConfigAdmin.removeRHExtension((ConfigImpl) config, rhext.getId(), false);
        } catch (Throwable t2) {
            ExceptionUtil.rethrowIfNecessary(t2);
        }
        throw Caster.toPageException(t);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) BundleInfo(lucee.runtime.osgi.BundleInfo) BundleFile(lucee.runtime.osgi.BundleFile) Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) RHExtension(lucee.runtime.extension.RHExtension) ZipInputStream(java.util.zip.ZipInputStream) StructImpl(lucee.runtime.type.StructImpl) CreateObject(lucee.runtime.functions.other.CreateObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class XMLConfigWebFactory method toStruct.

private static Struct toStruct(String str) {
    Struct sct = new StructImpl();
    try {
        String[] arr = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(str, '&'));
        String[] item;
        for (int i = 0; i < arr.length; i++) {
            item = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(arr[i], '='));
            if (item.length == 2)
                sct.setEL(KeyImpl.init(URLDecoder.decode(item[0], true).trim()), URLDecoder.decode(item[1], true));
            else if (item.length == 1)
                sct.setEL(KeyImpl.init(URLDecoder.decode(item[0], true).trim()), "");
        }
    } catch (PageException ee) {
    }
    return sct;
}
Also used : PageException(lucee.runtime.exp.PageException) StructImpl(lucee.runtime.type.StructImpl) lucee.aprint(lucee.aprint) Struct(lucee.runtime.type.Struct)

Example 58 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadDumpWriter.

private static void loadDumpWriter(ConfigServerImpl configServer, ConfigImpl config, Document doc) throws ClassException {
    boolean hasCS = configServer != null;
    Element coll = getChildByName(doc.getDocumentElement(), "dump-writers");
    Element[] writers = getChildren(coll, "dump-writer");
    Struct sct = new StructImpl();
    boolean hasPlain = false;
    boolean hasRich = false;
    if (hasCS) {
        DumpWriterEntry[] entries = configServer.getDumpWritersEntries();
        if (entries != null)
            for (int i = 0; i < entries.length; i++) {
                if (entries[i].getDefaultType() == HTMLDumpWriter.DEFAULT_PLAIN)
                    hasPlain = true;
                if (entries[i].getDefaultType() == HTMLDumpWriter.DEFAULT_RICH)
                    hasRich = true;
                sct.put(entries[i].getName(), entries[i]);
            }
    }
    if (writers != null && writers.length > 0) {
        ClassDefinition cd;
        String strName;
        String strDefault;
        Class clazz;
        int def = HTMLDumpWriter.DEFAULT_NONE;
        for (int i = 0; i < writers.length; i++) {
            cd = getClassDefinition(writers[i], "", config.getIdentification());
            strName = getAttr(writers[i], "name");
            strDefault = getAttr(writers[i], "default");
            clazz = cd.getClazz(null);
            if (clazz != null && !StringUtil.isEmpty(strName)) {
                if (StringUtil.isEmpty(strDefault))
                    def = HTMLDumpWriter.DEFAULT_NONE;
                else if ("browser".equalsIgnoreCase(strDefault))
                    def = HTMLDumpWriter.DEFAULT_RICH;
                else if ("console".equalsIgnoreCase(strDefault))
                    def = HTMLDumpWriter.DEFAULT_PLAIN;
                sct.put(strName, new DumpWriterEntry(def, strName, (DumpWriter) ClassUtil.loadInstance(clazz)));
            }
        }
    } else {
        // print.err("yep");
        if (!hasRich)
            sct.setEL(KeyConstants._html, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_RICH, "html", new HTMLDumpWriter()));
        if (!hasPlain)
            sct.setEL(KeyConstants._text, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_PLAIN, "text", new TextDumpWriter()));
        sct.setEL(KeyConstants._classic, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_NONE, "classic", new ClassicHTMLDumpWriter()));
        sct.setEL(KeyConstants._simple, new DumpWriterEntry(HTMLDumpWriter.DEFAULT_NONE, "simple", new SimpleHTMLDumpWriter()));
    }
    Iterator<Object> it = sct.valueIterator();
    java.util.List<DumpWriterEntry> entries = new ArrayList<DumpWriterEntry>();
    while (it.hasNext()) {
        entries.add((DumpWriterEntry) it.next());
    }
    config.setDumpWritersEntries(entries.toArray(new DumpWriterEntry[entries.size()]));
}
Also used : ClassicHTMLDumpWriter(lucee.runtime.dump.ClassicHTMLDumpWriter) SimpleHTMLDumpWriter(lucee.runtime.dump.SimpleHTMLDumpWriter) Element(org.w3c.dom.Element) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) ArrayList(java.util.ArrayList) ClassDefinition(lucee.runtime.db.ClassDefinition) lucee.aprint(lucee.aprint) Struct(lucee.runtime.type.Struct) SimpleHTMLDumpWriter(lucee.runtime.dump.SimpleHTMLDumpWriter) HTMLDumpWriter(lucee.runtime.dump.HTMLDumpWriter) ClassicHTMLDumpWriter(lucee.runtime.dump.ClassicHTMLDumpWriter) StructImpl(lucee.runtime.type.StructImpl) SimpleHTMLDumpWriter(lucee.runtime.dump.SimpleHTMLDumpWriter) HTMLDumpWriter(lucee.runtime.dump.HTMLDumpWriter) TextDumpWriter(lucee.runtime.dump.TextDumpWriter) ClassicHTMLDumpWriter(lucee.runtime.dump.ClassicHTMLDumpWriter) DumpWriter(lucee.runtime.dump.DumpWriter) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) TextDumpWriter(lucee.runtime.dump.TextDumpWriter)

Example 59 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadDataSources.

/**
 * loads datasource settings from XMl DOM
 *
 * @param configServer
 * @param config
 * @param doc
 * @throws BundleException
 * @throws ClassNotFoundException
 */
private static void loadDataSources(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) {
    // load JDBC Driver defintion
    {
        Element jdbc = getChildByName(doc.getDocumentElement(), "jdbc");
        Element[] drivers = getChildren(jdbc, "driver");
        Map<String, JDBCDriver> map = new HashMap<String, JDBCDriver>();
        // first add the server drivers, so they can be overwritten
        if (configServer != null) {
            JDBCDriver[] sds = configServer.getJDBCDrivers();
            for (JDBCDriver sd : sds) {
                map.put(sd.cd.toString(), sd);
            }
        }
        ClassDefinition cd;
        String label;
        for (Element driver : drivers) {
            cd = getClassDefinition(driver, "", config.getIdentification());
            label = getAttr(driver, "label");
            // check if label exists
            if (StringUtil.isEmpty(label)) {
                log.error("Datasource", "missing label for jdbc driver [" + cd.getClassName() + "]");
                continue;
            }
            // check if it is a bundle
            if (!cd.isBundle()) {
                log.error("Datasource", "jdbc driver [" + label + "] does not describe a bundle");
                continue;
            }
            map.put(cd.toString(), new JDBCDriver(label, cd));
        }
        config.setJDBCDrivers(map.values().toArray(new JDBCDriver[map.size()]));
    }
    // When set to true, makes JDBC use a representation for DATE data that
    // is compatible with the Oracle8i database.
    System.setProperty("oracle.jdbc.V8Compatible", "true");
    boolean hasCS = configServer != null;
    Map<String, DataSource> datasources = new HashMap<String, DataSource>();
    // Copy Parent datasources as readOnly
    if (hasCS) {
        Map<String, DataSource> ds = configServer.getDataSourcesAsMap();
        Iterator<Entry<String, DataSource>> it = ds.entrySet().iterator();
        Entry<String, DataSource> entry;
        while (it.hasNext()) {
            entry = it.next();
            if (!entry.getKey().equals(QOQ_DATASOURCE_NAME))
                datasources.put(entry.getKey(), entry.getValue().cloneReadOnly());
        }
    }
    // Default query of query DB
    try {
        setDatasource(config, datasources, QOQ_DATASOURCE_NAME, new ClassDefinitionImpl("org.hsqldb.jdbcDriver", "hsqldb", "1.8.0", config.getIdentification()), "hypersonic-hsqldb", "", -1, "jdbc:hsqldb:.", "sa", "", DEFAULT_MAX_CONNECTION, -1, 60000, true, true, DataSource.ALLOW_ALL, false, false, null, new StructImpl(), "", ParamSyntax.DEFAULT, false, false);
    } catch (Exception e) {
        log.error("Datasource", e);
    }
    SecurityManager sm = config.getSecurityManager();
    short access = sm.getAccess(SecurityManager.TYPE_DATASOURCE);
    int accessCount = -1;
    if (access == SecurityManager.VALUE_YES)
        accessCount = -1;
    else if (access == SecurityManager.VALUE_NO)
        accessCount = 0;
    else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10) {
        accessCount = access - SecurityManager.NUMBER_OFFSET;
    }
    // Databases
    Element databases = getChildByName(doc.getDocumentElement(), "data-sources");
    // if(databases==null)databases=doc.createElement("data-sources");
    // PSQ
    String strPSQ = getAttr(databases, "psq");
    if (StringUtil.isEmpty(strPSQ)) {
        // prior version was buggy, was the opposite
        strPSQ = getAttr(databases, "preserve-single-quote");
        if (!StringUtil.isEmpty(strPSQ)) {
            Boolean b = Caster.toBoolean(strPSQ, null);
            if (b != null)
                strPSQ = b.booleanValue() ? "false" : "true";
        }
    }
    if (access != SecurityManager.VALUE_NO && !StringUtil.isEmpty(strPSQ)) {
        config.setPSQL(toBoolean(strPSQ, true));
    } else if (hasCS)
        config.setPSQL(configServer.getPSQL());
    // Data Sources
    Element[] dataSources = getChildren(databases, "data-source");
    if (accessCount == -1)
        accessCount = dataSources.length;
    if (dataSources.length < accessCount)
        accessCount = dataSources.length;
    // if(hasAccess) {
    ClassDefinition cd;
    for (int i = 0; i < accessCount; i++) {
        Element dataSource = dataSources[i];
        if (dataSource.hasAttribute("database")) {
            try {
                cd = getClassDefinition(dataSource, "", config.getIdentification());
                if (!cd.isBundle()) {
                    JDBCDriver jdbc = config.getJDBCDriverByClassName(cd.getClassName(), null);
                    if (jdbc != null)
                        cd = jdbc.cd;
                }
                setDatasource(config, datasources, getAttr(dataSource, "name"), cd, getAttr(dataSource, "host"), getAttr(dataSource, "database"), Caster.toIntValue(getAttr(dataSource, "port"), -1), getAttr(dataSource, "dsn"), getAttr(dataSource, "username"), ConfigWebUtil.decrypt(getAttr(dataSource, "password")), Caster.toIntValue(getAttr(dataSource, "connectionLimit"), DEFAULT_MAX_CONNECTION), Caster.toIntValue(getAttr(dataSource, "connectionTimeout"), -1), Caster.toLongValue(getAttr(dataSource, "metaCacheTimeout"), 60000), toBoolean(getAttr(dataSource, "blob"), true), toBoolean(getAttr(dataSource, "clob"), true), Caster.toIntValue(getAttr(dataSource, "allow"), DataSource.ALLOW_ALL), toBoolean(getAttr(dataSource, "validate"), false), toBoolean(getAttr(dataSource, "storage"), false), getAttr(dataSource, "timezone"), toStruct(getAttr(dataSource, "custom")), getAttr(dataSource, "dbdriver"), ParamSyntax.toParamSyntax(dataSource, ParamSyntax.DEFAULT), toBoolean(getAttr(dataSource, "literal-timestamp-with-tsoffset"), false), toBoolean(getAttr(dataSource, "always-set-timeout"), false));
            } catch (Exception e) {
                log.error("Datasource", e);
            }
        }
    }
    // }
    config.setDataSources(datasources);
}
Also used : SecurityManager(lucee.runtime.security.SecurityManager) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) ClassDefinition(lucee.runtime.db.ClassDefinition) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) ClassException(lucee.commons.lang.ClassException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) lucee.aprint(lucee.aprint) DataSource(lucee.runtime.db.DataSource) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) Entry(java.util.Map.Entry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) StructImpl(lucee.runtime.type.StructImpl) JDBCDriver(lucee.runtime.db.JDBCDriver) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 60 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class ClientScopeConverter method main.

public static void main(String[] args) throws ConverterException {
    Struct sct = new StructImpl();
    sct.setEL("a", "b");
    sct.setEL("pe#=ter", "ab##c");
    sct.setEL("susi", Boolean.TRUE);
    sct.setEL("peter", "abc");
    sct.setEL("x", "");
    /*sct.setEL("abc=def", "abc");
		sct.setEL("abc#def", "ab#=c");
		*/
    String str;
    aprint.out(sct);
    aprint.out(str = ClientScopeConverter.serialize(sct));
    aprint.out(ClientScopeConverter.unserialize(str));
// aprint.out(new ScriptConverter().serialize(sct));
}
Also used : StructImpl(lucee.runtime.type.StructImpl) ParserString(lucee.commons.lang.ParserString) Struct(lucee.runtime.type.Struct)

Aggregations

StructImpl (lucee.runtime.type.StructImpl)251 Struct (lucee.runtime.type.Struct)216 PageException (lucee.runtime.exp.PageException)40 Entry (java.util.Map.Entry)34 Key (lucee.runtime.type.Collection.Key)28 Array (lucee.runtime.type.Array)25 ArrayImpl (lucee.runtime.type.ArrayImpl)24 ApplicationException (lucee.runtime.exp.ApplicationException)21 IOException (java.io.IOException)19 Map (java.util.Map)19 Resource (lucee.commons.io.res.Resource)18 Iterator (java.util.Iterator)17 PageContextImpl (lucee.runtime.PageContextImpl)14 QueryImpl (lucee.runtime.type.QueryImpl)13 Collection (lucee.runtime.type.Collection)11 Query (lucee.runtime.type.Query)11 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)11 HashMap (java.util.HashMap)9 PageSource (lucee.runtime.PageSource)8 Element (org.w3c.dom.Element)8