Search in sources :

Example 31 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class XMLConfigAdmin method updateDataSource.

/**
 * update or insert new database connection
 * @param name
 * @param clazzName
 * @param dsn
 * @param username
 * @param password
 * @param host
 * @param database
 * @param port
 * @param connectionLimit
 * @param connectionTimeout
 * @param blob
 * @param clob
 * @param allow
 * @param storage
 * @param custom
 * @throws PageException
 */
public void updateDataSource(String name, String newName, ClassDefinition cd, String dsn, String username, String password, String host, String database, int port, int connectionLimit, int connectionTimeout, long metaCacheTimeout, boolean blob, boolean clob, int allow, boolean validate, boolean storage, String timezone, Struct custom, String dbdriver, ParamSyntax paramSyntax, boolean literalTimestampWithTSOffset, boolean alwaysSetTimeout) throws PageException {
    checkWriteAccess();
    SecurityManager sm = config.getSecurityManager();
    short access = sm.getAccess(SecurityManager.TYPE_DATASOURCE);
    boolean hasAccess = true;
    boolean hasInsertAccess = true;
    int maxLength = 0;
    if (access == SecurityManager.VALUE_YES)
        hasAccess = true;
    else if (access == SecurityManager.VALUE_NO)
        hasAccess = false;
    else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10) {
        int existingLength = getDatasourceLength(config);
        maxLength = access - SecurityManager.NUMBER_OFFSET;
        hasInsertAccess = maxLength > existingLength;
    // print.ln("maxLength:"+maxLength);
    // print.ln("existingLength:"+existingLength);
    }
    // boolean hasAccess=ConfigWebUtil.hasAccess(config,SecurityManager.TYPE_DATASOURCE);
    if (!hasAccess)
        throw new SecurityException("no access to update datsource connections");
    // check parameters
    if (name == null || name.length() == 0)
        throw new ExpressionException("name can't be a empty value");
    Element datasources = _getRootElement("data-sources");
    // Update
    Element[] children = XMLConfigWebFactory.getChildren(datasources, "data-source");
    for (int i = 0; i < children.length; i++) {
        String n = children[i].getAttribute("name");
        if (n.equalsIgnoreCase(name)) {
            Element el = children[i];
            if (password.equalsIgnoreCase("****************"))
                password = el.getAttribute("password");
            if (!StringUtil.isEmpty(newName) && !newName.equals(name))
                el.setAttribute("name", newName);
            setClass(el, null, "", cd);
            el.setAttribute("dsn", dsn);
            el.setAttribute("username", username);
            el.setAttribute("password", ConfigWebUtil.encrypt(password));
            el.setAttribute("host", host);
            if (!StringUtil.isEmpty(timezone))
                el.setAttribute("timezone", timezone);
            else if (el.hasAttribute("timezone"))
                el.removeAttribute("timezone");
            el.setAttribute("database", database);
            el.setAttribute("port", Caster.toString(port));
            el.setAttribute("connectionLimit", Caster.toString(connectionLimit));
            el.setAttribute("connectionTimeout", Caster.toString(connectionTimeout));
            el.setAttribute("metaCacheTimeout", Caster.toString(metaCacheTimeout));
            el.setAttribute("blob", Caster.toString(blob));
            el.setAttribute("clob", Caster.toString(clob));
            el.setAttribute("allow", Caster.toString(allow));
            el.setAttribute("validate", Caster.toString(validate));
            el.setAttribute("storage", Caster.toString(storage));
            el.setAttribute("custom", toStringURLStyle(custom));
            if (!StringUtil.isEmpty(dbdriver))
                el.setAttribute("dbdriver", Caster.toString(dbdriver));
            // Param Syntax
            el.setAttribute("param-delimiter", (paramSyntax.delimiter));
            el.setAttribute("param-leading-delimiter", (paramSyntax.leadingDelimiter));
            el.setAttribute("param-separator", (paramSyntax.separator));
            if (literalTimestampWithTSOffset)
                el.setAttribute("literal-timestamp-with-tsoffset", "true");
            else if (el.hasAttribute("literal-timestamp-with-tsoffset"))
                el.removeAttribute("literal-timestamp-with-tsoffset");
            if (alwaysSetTimeout)
                el.setAttribute("always-set-timeout", "true");
            else if (el.hasAttribute("always-set-timeout"))
                el.removeAttribute("always-set-timeout");
            return;
        }
    }
    if (!hasInsertAccess)
        throw new SecurityException("no access to add datasource connections, the maximum count of [" + maxLength + "] datasources is reached");
    // Insert
    Element el = doc.createElement("data-source");
    datasources.appendChild(el);
    if (!StringUtil.isEmpty(newName))
        el.setAttribute("name", newName);
    else
        el.setAttribute("name", name);
    setClass(el, null, "", cd);
    el.setAttribute("dsn", dsn);
    if (username.length() > 0)
        el.setAttribute("username", username);
    if (password.length() > 0)
        el.setAttribute("password", ConfigWebUtil.encrypt(password));
    el.setAttribute("host", host);
    if (!StringUtil.isEmpty(timezone))
        el.setAttribute("timezone", timezone);
    el.setAttribute("database", database);
    if (port > -1)
        el.setAttribute("port", Caster.toString(port));
    if (connectionLimit > -1)
        el.setAttribute("connectionLimit", Caster.toString(connectionLimit));
    if (connectionTimeout > -1)
        el.setAttribute("connectionTimeout", Caster.toString(connectionTimeout));
    if (metaCacheTimeout > -1)
        el.setAttribute("metaCacheTimeout", Caster.toString(metaCacheTimeout));
    el.setAttribute("blob", Caster.toString(blob));
    el.setAttribute("clob", Caster.toString(clob));
    el.setAttribute("validate", Caster.toString(validate));
    el.setAttribute("storage", Caster.toString(storage));
    if (allow > -1)
        el.setAttribute("allow", Caster.toString(allow));
    el.setAttribute("custom", toStringURLStyle(custom));
    if (!StringUtil.isEmpty(dbdriver))
        el.setAttribute("dbdriver", Caster.toString(dbdriver));
    // Param Syntax
    el.setAttribute("param-delimiter", (paramSyntax.delimiter));
    el.setAttribute("param-leading-delimiter", (paramSyntax.leadingDelimiter));
    el.setAttribute("param-separator", (paramSyntax.separator));
    if (literalTimestampWithTSOffset)
        el.setAttribute("literal-timestamp-with-tsoffset", "true");
    if (alwaysSetTimeout)
        el.setAttribute("always-set-timeout", "true");
}
Also used : SecurityManager(lucee.runtime.security.SecurityManager) Element(org.w3c.dom.Element) SecurityException(lucee.runtime.exp.SecurityException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 32 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class XMLConfigAdmin method updateRestMapping.

public void updateRestMapping(String virtual, String physical, boolean _default) throws ExpressionException, SecurityException {
    checkWriteAccess();
    // TODO ConfigWebUtil.hasAccess(config,SecurityManager.TYPE_REST);
    boolean hasAccess = true;
    virtual = virtual.trim();
    physical = physical.trim();
    if (!hasAccess)
        throw new SecurityException("no access to update REST mapping");
    // check virtual
    if (virtual == null || virtual.length() == 0)
        throw new ExpressionException("virtual path cannot be a empty value");
    virtual = virtual.replace('\\', '/');
    if (virtual.equals("/"))
        throw new ExpressionException("virtual path cannot be /");
    if (virtual.endsWith("/"))
        virtual = virtual.substring(0, virtual.length() - 1);
    if (virtual.charAt(0) != '/')
        virtual = "/" + virtual;
    if ((physical.length()) == 0)
        throw new ExpressionException("physical path cannot be a empty value");
    Element rest = _getRootElement("rest");
    Element[] children = XMLConfigWebFactory.getChildren(rest, "mapping");
    // remove existing default
    if (_default) {
        for (int i = 0; i < children.length; i++) {
            if (Caster.toBooleanValue(children[i].getAttribute("default"), false))
                children[i].setAttribute("default", "false");
        }
    }
    // Update
    String v;
    Element el = null;
    for (int i = 0; i < children.length; i++) {
        v = children[i].getAttribute("virtual");
        if (v != null && v.equals(virtual)) {
            el = children[i];
        }
    }
    // Insert
    if (el == null) {
        el = doc.createElement("mapping");
        rest.appendChild(el);
    }
    el.setAttribute("virtual", virtual);
    el.setAttribute("physical", physical);
    el.setAttribute("default", Caster.toString(_default));
}
Also used : Element(org.w3c.dom.Element) SecurityException(lucee.runtime.exp.SecurityException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 33 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class XMLConfigAdmin method removeRestMapping.

public void removeRestMapping(String virtual) throws ExpressionException, SecurityException {
    checkWriteAccess();
    // check parameters
    if (virtual == null || virtual.length() == 0)
        throw new ExpressionException("virtual path cannot be a empty value");
    virtual = virtual.replace('\\', '/');
    if (virtual.equals("/"))
        throw new ExpressionException("virtual path cannot be /");
    if (virtual.endsWith("/"))
        virtual = virtual.substring(0, virtual.length() - 1);
    if (virtual.charAt(0) != '/')
        virtual = "/" + virtual;
    Element mappings = _getRootElement("rest");
    Element[] children = XMLConfigWebFactory.getChildren(mappings, "mapping");
    for (int i = 0; i < children.length; i++) {
        String v = children[i].getAttribute("virtual");
        if (v != null) {
            if (!v.equals("/") && v.endsWith("/"))
                v = v.substring(0, v.length() - 1);
            if (v != null && v.equals(virtual)) {
                Element el = children[i];
                mappings.removeChild(el);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 34 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class XMLConfigAdmin method removeCacheConnection.

public void removeCacheConnection(String name) throws ExpressionException, SecurityException {
    checkWriteAccess();
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_CACHE);
    if (!hasAccess)
        throw new SecurityException("no access to remove cache connection");
    // check parameters
    if (StringUtil.isEmpty(name))
        throw new ExpressionException("name for Cache Connection can not be an empty value");
    Element parent = _getRootElement("cache");
    // remove default flag
    if (name.equalsIgnoreCase(parent.getAttribute("default-object")))
        parent.removeAttribute("default-object");
    if (name.equalsIgnoreCase(parent.getAttribute("default-template")))
        parent.removeAttribute("default-template");
    if (name.equalsIgnoreCase(parent.getAttribute("default-query")))
        parent.removeAttribute("default-query");
    if (name.equalsIgnoreCase(parent.getAttribute("default-resource")))
        parent.removeAttribute("default-resource");
    // remove element
    Element[] children = XMLConfigWebFactory.getChildren(parent, "connection");
    for (int i = 0; i < children.length; i++) {
        String n = children[i].getAttribute("name");
        if (n != null && n.equalsIgnoreCase(name)) {
            Map<String, CacheConnection> conns = config.getCacheConnections();
            CacheConnection cc = conns.get(n.toLowerCase());
            if (cc != null) {
                CacheUtil.releaseEL(cc);
            // CacheUtil.removeEL( config instanceof ConfigWeb ? (ConfigWeb) config : null, cc );
            }
            parent.removeChild(children[i]);
        }
    }
}
Also used : Element(org.w3c.dom.Element) SecurityException(lucee.runtime.exp.SecurityException) CacheConnection(lucee.runtime.cache.CacheConnection) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 35 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class ComponentImpl method callGetter.

private Object callGetter(PageContext pc, Collection.Key key) throws PageException {
    Key getterName = KeyImpl.getInstance("get" + key.getLowerString());
    Member member = getMember(pc, getterName, false, false);
    if (member instanceof UDFPlus) {
        UDFPlus udf = (UDFPlus) member;
        if (udf.getFunctionArguments().length == 0 && udf.getReturnType() != CFTypes.TYPE_VOID) {
            return _call(pc, getterName, udf, null, ArrayUtil.OBJECT_EMPTY);
        }
    }
    throw new ExpressionException("Component [" + getCallName() + "] has no accessible Member with name [" + key + "]");
}
Also used : UDFPlus(lucee.runtime.type.UDFPlus) Member(lucee.runtime.component.Member) DataMember(lucee.runtime.component.DataMember) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

ExpressionException (lucee.runtime.exp.ExpressionException)136 Element (org.w3c.dom.Element)24 Key (lucee.runtime.type.Collection.Key)15 SecurityException (lucee.runtime.exp.SecurityException)13 ArrayList (java.util.ArrayList)12 Struct (lucee.runtime.type.Struct)12 List (java.util.List)11 Collection (lucee.runtime.type.Collection)11 Entry (java.util.Map.Entry)10 Node (org.w3c.dom.Node)10 Resource (lucee.commons.io.res.Resource)9 Iterator (java.util.Iterator)8 PageException (lucee.runtime.exp.PageException)8 Map (java.util.Map)7 CasterException (lucee.runtime.exp.CasterException)7 NodeList (org.w3c.dom.NodeList)7 PageContextImpl (lucee.runtime.PageContextImpl)6 PageSource (lucee.runtime.PageSource)5 Casting (lucee.runtime.interpreter.ref.cast.Casting)5 ArrayImpl (lucee.runtime.type.ArrayImpl)5