Search in sources :

Example 21 with ExpressionException

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

the class UDFSetterProperty method call.

@Override
public Object call(PageContext pageContext, Object[] args, boolean doIncludePath) throws PageException {
    if (args.length < 1)
        throw new ExpressionException("The parameter " + prop.getName() + " to function " + getFunctionName() + " is required but was not passed in.");
    validate(validate, validateParams, args[0]);
    component.getComponentScope().set(propName, cast(pageContext, this.arguments[0], args[0], 1));
    // make sure it is reconized that set is called by hibernate
    // if(component.isPersistent())ORMUtil.getSession(pageContext);
    ApplicationContext appContext = pageContext.getApplicationContext();
    if (appContext.isORMEnabled() && component.isPersistent())
        ORMUtil.getSession(pageContext);
    return component;
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 22 with ExpressionException

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

the class XMLConfigAdmin method _updateComponentMapping.

private void _updateComponentMapping(String virtual, String physical, String archive, String primary, short inspect) throws ExpressionException {
    primary = primary.equalsIgnoreCase("archive") ? "archive" : "physical";
    if (physical == null)
        physical = "";
    else
        physical = physical.trim();
    if (archive == null)
        archive = "";
    else
        archive = archive.trim();
    boolean isArchive = primary.equalsIgnoreCase("archive");
    if (isArchive && archive.length() == 0) {
        throw new ExpressionException("archive must have a value when primary has value archive");
    }
    if (!isArchive && physical.length() == 0) {
        throw new ExpressionException("physical must have a value when primary has value physical");
    }
    Element mappings = _getRootElement("component");
    Element[] children = XMLConfigWebFactory.getChildren(mappings, "mapping");
    Element el;
    /* ignore when exists
        for(int i=0;i<children.length;i++) {
      		el=children[i];
      	    if(el.getAttribute("physical").equals(physical) &&
      	    		el.getAttribute("archive").equals(archive) &&
      	    		el.getAttribute("primary").equals(primary) &&
      	    		el.getAttribute("trusted").equals(Caster.toString(trusted))){
      	    	return;
  			}
      	}*/
    // Update
    String v;
    for (int i = 0; i < children.length; i++) {
        el = children[i];
        // if there is no virtual defintion (old records), we use the position
        v = createVirtual(el);
        if (v.equals(virtual)) {
            // set to make sure it exists for the future
            el.setAttribute("virtual", v);
            el.setAttribute("physical", physical);
            el.setAttribute("archive", archive);
            el.setAttribute("primary", primary.equalsIgnoreCase("archive") ? "archive" : "physical");
            el.setAttribute("inspect-template", ConfigWebUtil.inspectTemplate(inspect, ""));
            el.removeAttribute("trusted");
            return;
        }
    }
    // Insert
    el = doc.createElement("mapping");
    mappings.appendChild(el);
    if (physical.length() > 0)
        el.setAttribute("physical", physical);
    if (archive.length() > 0)
        el.setAttribute("archive", archive);
    el.setAttribute("primary", primary.equalsIgnoreCase("archive") ? "archive" : "physical");
    el.setAttribute("inspect-template", ConfigWebUtil.inspectTemplate(inspect, ""));
    el.setAttribute("virtual", virtual);
}
Also used : Element(org.w3c.dom.Element) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 23 with ExpressionException

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

the class XMLConfigAdmin method removeJDBCDriver.

public void removeJDBCDriver(String className) throws ExpressionException, SecurityException {
    checkWriteAccess();
    // check parameters
    if (StringUtil.isEmpty(className))
        throw new ExpressionException("class name for jdbc driver cannot be empty");
    Element parent = _getRootElement("jdbc");
    Element[] children = XMLConfigWebFactory.getChildren(parent, "driver");
    for (int i = 0; i < children.length; i++) {
        String n = children[i].getAttribute("class");
        if (n != null && n.equalsIgnoreCase(className)) {
            parent.removeChild(children[i]);
        }
    }
}
Also used : Element(org.w3c.dom.Element) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 24 with ExpressionException

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

the class XMLConfigAdmin method updateCPPCFX.

public void updateCPPCFX(String name, String procedure, String strServerLibrary, boolean keepAlive) throws PageException {
    checkWriteAccess();
    boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_CFX_SETTING);
    if (!hasAccess)
        throw new SecurityException("no access to change cfx settings");
    // name
    if (StringUtil.isEmpty(name))
        throw new ExpressionException("name cannot be a empty value");
    // serverLibrary
    if (StringUtil.isEmpty(strServerLibrary))
        throw new ExpressionException("serverLibrary cannot be a empty value");
    Resource serverLibrary = ResourceUtil.toResourceExisting(config, strServerLibrary);
    // procedure
    if (StringUtil.isEmpty(procedure))
        throw new ExpressionException("procedure cannot be a empty value");
    renameOldstyleCFX();
    Element tags = _getRootElement("ext-tags");
    // Update
    Element[] children = XMLConfigWebFactory.getChildren(tags, "ext-tag");
    for (int i = 0; i < children.length; i++) {
        String n = children[i].getAttribute("name");
        if (n != null && n.equalsIgnoreCase(name)) {
            Element el = children[i];
            if (!"cpp".equalsIgnoreCase(el.getAttribute("type")))
                throw new ExpressionException("there is already a java cfx tag with this name");
            el.setAttribute("server-library", serverLibrary.getAbsolutePath());
            el.setAttribute("procedure", procedure);
            el.setAttribute("keep-alive", Caster.toString(keepAlive));
            el.setAttribute("type", "cpp");
            return;
        }
    }
    // Insert
    Element el = doc.createElement("ext-tag");
    tags.appendChild(el);
    el.setAttribute("server-library", serverLibrary.getAbsolutePath());
    el.setAttribute("procedure", procedure);
    el.setAttribute("keep-alive", Caster.toString(keepAlive));
    el.setAttribute("name", name);
    el.setAttribute("type", "cpp");
}
Also used : Element(org.w3c.dom.Element) Resource(lucee.commons.io.res.Resource) SecurityException(lucee.runtime.exp.SecurityException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 25 with ExpressionException

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

the class XMLConfigAdmin method removeDataSource.

/**
 * remove a DataSource Connection
 * @param name
 * @throws ExpressionException
 * @throws SecurityException
 */
public void removeDataSource(String name) throws ExpressionException, SecurityException {
    checkWriteAccess();
    // check parameters
    if (name == null || name.length() == 0)
        throw new ExpressionException("name for Datasource Connection can be a empty value");
    Element datasources = _getRootElement("data-sources");
    Element[] children = XMLConfigWebFactory.getChildren(datasources, "data-source");
    for (int i = 0; i < children.length; i++) {
        String n = children[i].getAttribute("name");
        if (n != null && n.equalsIgnoreCase(name)) {
            datasources.removeChild(children[i]);
        }
    }
}
Also used : Element(org.w3c.dom.Element) 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