Search in sources :

Example 11 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class XMLConfigAdmin method getResourceProviders.

private void getResourceProviders(ResourceProvider[] providers, Query qry, Element p, int row, Boolean def) throws PageException {
    Array support = new ArrayImpl();
    String cn = p.getAttribute("class");
    String name = p.getAttribute("bundle-name");
    String version = p.getAttribute("bundle-version");
    ClassDefinition cd = new ClassDefinitionImpl(cn, name, version, ThreadLocalPageContext.getConfig().getIdentification());
    qry.setAt("scheme", row, p.getAttribute("scheme"));
    qry.setAt("arguments", row, p.getAttribute("arguments"));
    qry.setAt("class", row, cd.getClassName());
    qry.setAt("bundleName", row, cd.getName());
    qry.setAt("bundleVersion", row, cd.getVersionAsString());
    for (int i = 0; i < providers.length; i++) {
        if (providers[i].getClass().getName().equals(cd.getClassName())) {
            if (providers[i].isAttributesSupported())
                support.append("attributes");
            if (providers[i].isModeSupported())
                support.append("mode");
            qry.setAt("support", row, ListUtil.arrayToList(support, ","));
            qry.setAt("scheme", row, providers[i].getScheme());
            qry.setAt("caseSensitive", row, Caster.toBoolean(providers[i].isCaseSensitive()));
            qry.setAt("default", row, def);
            break;
        }
    }
}
Also used : Array(lucee.runtime.type.Array) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) ClassDefinition(lucee.runtime.db.ClassDefinition)

Example 12 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class XMLConfigAdmin method updateVideoExecuterClass.

public void updateVideoExecuterClass(ClassDefinition cd) throws PageException {
    if (cd.getClassName() == null)
        cd = new ClassDefinitionImpl(VideoExecuterNotSupported.class.getName());
    Element app = _getRootElement("video");
    setClass(app, VideoExecuter.class, "video-executer-", cd);
}
Also used : VideoExecuterNotSupported(lucee.runtime.video.VideoExecuterNotSupported) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) Element(org.w3c.dom.Element)

Example 13 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadSearch.

/**
 * @param configServer
 * @param config
 * @param doc
 * @throws PageException
 */
private static void loadSearch(ConfigServer configServer, ConfigImpl config, Document doc) {
    Element search = getChildByName(doc.getDocumentElement(), "search");
    // class
    ClassDefinition<SearchEngine> cd = getClassDefinition(search, "engine-", config.getIdentification());
    if (!cd.hasClass() || "lucee.runtime.search.lucene.LuceneSearchEngine".equals(cd.getClassName())) {
        if (configServer != null)
            cd = ((ConfigImpl) configServer).getSearchEngineClassDefinition();
        else
            cd = new ClassDefinitionImpl(DummySearchEngine.class);
    }
    // directory
    String dir = search.getAttribute("directory");
    if (StringUtil.isEmpty(dir)) {
        if (configServer != null)
            dir = ((ConfigImpl) configServer).getSearchEngineDirectory();
        else
            dir = "{lucee-web}/search/";
    }
    config.setSearchEngine(cd, dir);
// directory=
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) SearchEngine(lucee.runtime.search.SearchEngine) DummySearchEngine(lucee.runtime.search.DummySearchEngine) Element(org.w3c.dom.Element)

Example 14 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadCache.

/*private static ClassDefinition matchJDBCBundle(Config config, ClassDefinition cd) {
		if(!cd.isBundle()) {
			if("org.hsqldb.jdbcDriver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "hypersonic.hsqldb", null, config.getIdentification());
			if("org.gjt.mm.mysql.Driver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "com.mysql.jdbc", null, config.getIdentification());
			if("org.h2.Driver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "org.h2", null, config.getIdentification());
			if("net.sourceforge.jtds.jdbc.Driver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "jtds", null, config.getIdentification());
			if("com.microsoft.jdbc.sqlserver.SQLServerDriver".equals(cd.getClassName())) 
				return new ClassDefinitionImpl<>(cd.getClassName(), "microsoft.sqljdbc", null, config.getIdentification());
		
		}
		return cd;
	}*/
/**
 * @param configServer
 * @param config
 * @param doc
 */
/**
 * @param configServer
 * @param config
 * @param doc
 */
private static void loadCache(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) {
    boolean hasCS = configServer != null;
    // load Cache info
    {
        Element parent = getChildByName(doc.getDocumentElement(), "caches");
        Element[] children = getChildren(parent, "cache");
        Map<String, ClassDefinition> map = new HashMap<String, ClassDefinition>();
        // first add the server drivers, so they can be overwritten
        if (configServer != null) {
            Iterator<ClassDefinition> it = configServer.getCacheDefinitions().values().iterator();
            ClassDefinition cd;
            while (it.hasNext()) {
                cd = it.next();
                map.put(cd.getClassName(), cd);
            }
        }
        ClassDefinition cd;
        String label;
        for (Element child : children) {
            cd = getClassDefinition(child, "", config.getIdentification());
            // check if it is a bundle
            if (!cd.isBundle()) {
                log.error("Datasource", "[" + cd + "] does not have bundle info");
                continue;
            }
            map.put(cd.getClassName(), cd);
        }
        config.setCacheDefinitions(map);
    }
    Map<String, CacheConnection> caches = new HashMap<String, CacheConnection>();
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_CACHE);
    // print.o("LOAD CACHE:"+hasAccess+":"+hasCS);
    Element eCache = getChildByName(doc.getDocumentElement(), "cache");
    // has changes
    String md5 = getMD5(eCache, hasCS ? configServer.getCacheMD5() : "");
    if (md5.equals(config.getCacheMD5()))
        return;
    config.setCacheMD5(md5);
    String[] typeNames = new String[] { "resource", "function", "include", "query", "template", "object", "file", "http", "webservice" };
    int[] types = new int[] { ConfigImpl.CACHE_TYPE_RESOURCE, ConfigImpl.CACHE_TYPE_FUNCTION, ConfigImpl.CACHE_TYPE_INCLUDE, ConfigImpl.CACHE_TYPE_QUERY, ConfigImpl.CACHE_TYPE_TEMPLATE, ConfigImpl.CACHE_TYPE_OBJECT, ConfigImpl.CACHE_TYPE_FILE, ConfigImpl.CACHE_TYPE_HTTP, ConfigImpl.CACHE_TYPE_WEBSERVICE };
    // default cache
    for (int i = 0; i < types.length; i++) {
        String def = getAttr(eCache, "default-" + typeNames[i]);
        if (hasAccess && !StringUtil.isEmpty(def)) {
            config.setCacheDefaultConnectionName(types[i], def);
        } else if (hasCS) {
            if (eCache.hasAttribute("default-" + typeNames[i]))
                config.setCacheDefaultConnectionName(types[i], "");
            else
                config.setCacheDefaultConnectionName(types[i], configServer.getCacheDefaultConnectionName(types[i]));
        } else
            config.setCacheDefaultConnectionName(+types[i], "");
    }
    // cache connections
    Element[] eConnections = getChildren(eCache, "connection");
    // if(hasAccess) {
    ClassDefinition cd;
    String name;
    CacheConnection cc;
    // caches
    if (hasAccess)
        for (int i = 0; i < eConnections.length; i++) {
            Element eConnection = eConnections[i];
            name = getAttr(eConnection, "name");
            cd = getClassDefinition(eConnection, "", config.getIdentification());
            if (!cd.isBundle()) {
                ClassDefinition _cd = config.getCacheDefinition(cd.getClassName());
                if (_cd != null)
                    cd = _cd;
            }
            try {
                Struct custom = toStruct(getAttr(eConnection, "custom"));
                // Workaround for old EHCache class defintions
                if (cd.getClassName() != null && cd.getClassName().endsWith(".EHCacheLite")) {
                    cd = new ClassDefinitionImpl("org.lucee.extension.cache.eh.EHCache");
                    if (!custom.containsKey("distributed"))
                        custom.setEL("distributed", "off");
                    if (!custom.containsKey("asynchronousReplicationIntervalMillis"))
                        custom.setEL("asynchronousReplicationIntervalMillis", "1000");
                    if (!custom.containsKey("maximumChunkSizeBytes"))
                        custom.setEL("maximumChunkSizeBytes", "5000000");
                } else // 
                if (cd.getClassName() != null && (cd.getClassName().endsWith(".extension.io.cache.eh.EHCache") || cd.getClassName().endsWith("lucee.runtime.cache.eh.EHCache")))
                    cd = new ClassDefinitionImpl("org.lucee.extension.cache.eh.EHCache");
                // else cacheClazz = cd.getClazz();
                cc = new CacheConnectionImpl(config, name, cd, custom, Caster.toBooleanValue(getAttr(eConnection, "read-only"), false), Caster.toBooleanValue(getAttr(eConnection, "storage"), false));
                if (!StringUtil.isEmpty(name)) {
                    caches.put(name.toLowerCase(), cc);
                } else
                    SystemOut.print(config.getErrWriter(), "missing cache name");
            } catch (ClassException ce) {
                log.error("Cache", ce);
            // SystemOut.print(config.getErrWriter(), ExceptionUtil.getStacktrace(ce, true));
            } catch (BundleException be) {
                log.error("Cache", be);
            // SystemOut.print(config.getErrWriter(), ExceptionUtil.getStacktrace(be, true));
            } catch (IOException e) {
                log.error("Cache", e);
            // SystemOut.print(config.getErrWriter(), ExceptionUtil.getStacktrace(e, true));
            }
        }
    // }
    // call static init once per driver
    {
        // group by classes
        final Map<ClassDefinition, List<CacheConnection>> _caches = new HashMap<ClassDefinition, List<CacheConnection>>();
        {
            Iterator<Entry<String, CacheConnection>> it = caches.entrySet().iterator();
            Entry<String, CacheConnection> entry;
            List<CacheConnection> list;
            while (it.hasNext()) {
                entry = it.next();
                cc = entry.getValue();
                // Jira 3196 ?!
                if (cc == null)
                    continue;
                list = _caches.get(cc.getClassDefinition());
                if (list == null) {
                    list = new ArrayList<CacheConnection>();
                    _caches.put(cc.getClassDefinition(), list);
                }
                list.add(cc);
            }
        }
        // call
        Iterator<Entry<ClassDefinition, List<CacheConnection>>> it = _caches.entrySet().iterator();
        Entry<ClassDefinition, List<CacheConnection>> entry;
        List<CacheConnection> list;
        ClassDefinition _cd;
        while (it.hasNext()) {
            entry = it.next();
            list = entry.getValue();
            _cd = entry.getKey();
            try {
                Method m = _cd.getClazz().getMethod("init", new Class[] { Config.class, String[].class, Struct[].class });
                if (Modifier.isStatic(m.getModifiers()))
                    m.invoke(null, new Object[] { config, _toCacheNames(list), _toArguments(list) });
                else
                    SystemOut.print(config.getErrWriter(), "method [init(Config,String[],Struct[]):void] for class [" + _cd.toString() + "] is not static");
            } catch (InvocationTargetException e) {
                log.error("Cache", e.getTargetException());
            } catch (RuntimeException e) {
                log.error("Cache", e);
            } catch (NoSuchMethodException e) {
                log.error("Cache", "missing method [public static init(Config,String[],Struct[]):void] for class [" + _cd.toString() + "] ");
            // SystemOut.print(config.getErrWriter(), "missing method [public static init(Config,String[],Struct[]):void] for class [" + _cd.toString() + "] ");
            } catch (Throwable e) {
                ExceptionUtil.rethrowIfNecessary(e);
                log.error("Cache", e);
            }
        }
    }
    // Copy Parent caches as readOnly
    if (hasCS) {
        Map<String, CacheConnection> ds = configServer.getCacheConnections();
        Iterator<Entry<String, CacheConnection>> it = ds.entrySet().iterator();
        Entry<String, CacheConnection> entry;
        while (it.hasNext()) {
            entry = it.next();
            cc = entry.getValue();
            if (!caches.containsKey(entry.getKey()))
                caches.put(entry.getKey(), new ServerCacheConnection(configServer, cc));
        }
    }
    config.setCaches(caches);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ServletConfig(javax.servlet.ServletConfig) ThreadLocalConfig(lucee.runtime.engine.ThreadLocalConfig) Element(org.w3c.dom.Element) ClassException(lucee.commons.lang.ClassException) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) Entry(java.util.Map.Entry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Method(java.lang.reflect.Method) lucee.aprint(lucee.aprint) InvocationTargetException(java.lang.reflect.InvocationTargetException) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) CacheConnectionImpl(lucee.runtime.cache.CacheConnectionImpl) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) ServerCacheConnection(lucee.runtime.cache.ServerCacheConnection) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ServerCacheConnection(lucee.runtime.cache.ServerCacheConnection) CacheConnection(lucee.runtime.cache.CacheConnection)

Example 15 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadORM.

private static void loadORM(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) {
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_ORM);
    Element orm = hasAccess ? getChildByName(doc.getDocumentElement(), "orm") : null;
    boolean hasCS = configServer != null;
    // engine
    ClassDefinition cdDefault = new ClassDefinitionImpl(DummyORMEngine.class);
    ClassDefinition cd = null;
    if (orm != null) {
        cd = getClassDefinition(orm, "engine-", config.getIdentification());
        if (cd == null || cd.isClassNameEqualTo(DummyORMEngine.class.getName()) || cd.isClassNameEqualTo("lucee.runtime.orm.hibernate.HibernateORMEngine"))
            cd = getClassDefinition(orm, "", config.getIdentification());
        if (cd != null && (cd.isClassNameEqualTo(DummyORMEngine.class.getName()) || cd.isClassNameEqualTo("lucee.runtime.orm.hibernate.HibernateORMEngine")))
            cd = null;
    }
    if (cd == null || !cd.hasClass()) {
        if (configServer != null)
            cd = configServer.getORMEngineClass();
        else
            cd = cdDefault;
    }
    // load class
    try {
        cd.getClazz();
    // TODO check interface as well
    } catch (Exception e) {
        log.error("ORM", e);
        cd = cdDefault;
    }
    config.setORMEngineClass(cd);
    // config
    if (orm == null)
        // this is just a dummy
        orm = doc.createElement("orm");
    ORMConfiguration def = hasCS ? configServer.getORMConfig() : null;
    ORMConfiguration ormConfig = ORMConfigurationImpl.load(config, null, orm, config.getRootDirectory(), def);
    config.setORMConfig(ormConfig);
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) DummyORMEngine(lucee.runtime.orm.DummyORMEngine) 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) ORMConfiguration(lucee.runtime.orm.ORMConfiguration)

Aggregations

ClassDefinitionImpl (lucee.transformer.library.ClassDefinitionImpl)33 ClassDefinition (lucee.runtime.db.ClassDefinition)26 Element (org.w3c.dom.Element)9 ApplicationException (lucee.runtime.exp.ApplicationException)8 PageException (lucee.runtime.exp.PageException)6 IOException (java.io.IOException)5 BundleException (org.osgi.framework.BundleException)5 MalformedURLException (java.net.MalformedURLException)4 lucee.aprint (lucee.aprint)4 ClassException (lucee.commons.lang.ClassException)4 SecurityException (lucee.runtime.exp.SecurityException)4 Struct (lucee.runtime.type.Struct)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 DumpWriterEntry (lucee.runtime.dump.DumpWriterEntry)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 GatewayEntry (lucee.runtime.gateway.GatewayEntry)3