Search in sources :

Example 91 with PageException

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

the class Log4jUtil method getLayout.

public static final Layout getLayout(ClassDefinition cd, Map<String, String> layoutArgs) {
    if (layoutArgs == null)
        layoutArgs = new HashMap<String, String>();
    // Layout
    Layout layout = null;
    if (cd != null && cd.hasClass()) {
        // Classic Layout
        if (ClassicLayout.class.getName().equalsIgnoreCase(cd.getClassName()))
            layout = new ClassicLayout();
        else // HTML Layout
        if (HTMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            HTMLLayout html = new HTMLLayout();
            layout = html;
            // Location Info
            Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
            if (locInfo != null)
                html.setLocationInfo(locInfo.booleanValue());
            else
                locInfo = Boolean.FALSE;
            layoutArgs.put("locationinfo", locInfo.toString());
            // Title
            String title = Caster.toString(layoutArgs.get("title"), "");
            if (!StringUtil.isEmpty(title, true))
                html.setTitle(title);
            layoutArgs.put("title", title);
        } else // XML Layout
        if (XMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            XMLLayout xml = new XMLLayout();
            layout = xml;
            // Location Info
            Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
            if (locInfo != null)
                xml.setLocationInfo(locInfo.booleanValue());
            else
                locInfo = Boolean.FALSE;
            layoutArgs.put("locationinfo", locInfo.toString());
            // Properties
            Boolean props = Caster.toBoolean(layoutArgs.get("properties"), null);
            if (props != null)
                xml.setProperties(props.booleanValue());
            else
                props = Boolean.FALSE;
            layoutArgs.put("properties", props.toString());
        } else // Pattern Layout
        if (PatternLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            PatternLayout patt = new PatternLayout();
            layout = patt;
            // pattern
            String pattern = Caster.toString(layoutArgs.get("pattern"), null);
            if (!StringUtil.isEmpty(pattern, true))
                patt.setConversionPattern(pattern);
            else {
                patt.setConversionPattern(DEFAULT_PATTERN);
                layoutArgs.put("pattern", DEFAULT_PATTERN);
            }
        } else // class defintion
        {
            Object obj = ClassUtil.loadInstance(cd.getClazz(null), null, null);
            if (obj instanceof Layout) {
                layout = (Layout) obj;
                Iterator<Entry<String, String>> it = layoutArgs.entrySet().iterator();
                Entry<String, String> e;
                while (it.hasNext()) {
                    e = it.next();
                    try {
                        Reflector.callSetter(obj, e.getKey(), e.getValue());
                    } catch (PageException e1) {
                        // TODO log
                        SystemOut.printDate(e1);
                    }
                }
            }
        }
    }
    if (layout != null)
        return layout;
    return new ClassicLayout();
}
Also used : PageException(lucee.runtime.exp.PageException) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) HTMLLayout(org.apache.log4j.HTMLLayout) ClassicLayout(lucee.commons.io.log.log4j.layout.ClassicLayout) XMLLayout(org.apache.log4j.xml.XMLLayout) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) HTMLLayout(org.apache.log4j.HTMLLayout) PatternLayout(org.apache.log4j.PatternLayout) ClassicLayout(lucee.commons.io.log.log4j.layout.ClassicLayout) Iterator(java.util.Iterator) XMLLayout(org.apache.log4j.xml.XMLLayout)

Example 92 with PageException

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

the class CFMLResourceProvider method callResourceArrayRTE.

Resource[] callResourceArrayRTE(PageContext pc, Component component, String methodName, Object[] args) {
    pc = ThreadLocalPageContext.get(pc);
    try {
        Array arr = Caster.toArray(call(pc, getCFC(pc, component), methodName, args));
        Iterator<Object> it = arr.valueIterator();
        CFMLResource[] resources = new CFMLResource[arr.size()];
        int index = 0;
        while (it.hasNext()) {
            resources[index++] = new CFMLResource(this, Caster.toComponent(it.next()));
        }
        return resources;
    } catch (PageException pe) {
        throw new PageRuntimeException(pe);
    }
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 93 with PageException

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

the class DatasourceResource method listResources.

@Override
public Resource[] listResources() {
    if (!attr().isDirectory())
        return null;
    String path;
    if (parent == null)
        path = "/";
    else
        path = parent.concat(name).concat("/");
    Attr[] children = null;
    try {
        children = provider.getAttrs(data, path.hashCode(), path);
    } catch (PageException e) {
        throw new PageRuntimeException(e);
    }
    if (children == null)
        return new Resource[0];
    Resource[] attrs = new Resource[children.length];
    for (int i = 0; i < children.length; i++) {
        // TODO optimieren, alle attr mitgeben
        attrs[i] = new DatasourceResource(provider, data, path + children[i].getName());
    }
    return attrs;
}
Also used : PageException(lucee.runtime.exp.PageException) Resource(lucee.commons.io.res.Resource) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 94 with PageException

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

the class DatasourceResourceProvider method delete.

public void delete(ConnectionData data, int fullPathHash, String path, String name) throws IOException {
    Attr attr = getAttr(data, fullPathHash, path, name);
    if (attr == null)
        throw new IOException("can't delete resource " + path + name + ", resource does not exist");
    DatasourceConnection dc = null;
    try {
        dc = getDatasourceConnection(data);
        getCore(data).delete(dc, data.getPrefix(), attr);
    } catch (SQLException e) {
        throw new IOException(e.getMessage());
    } catch (PageException e) {
        throw new PageRuntimeException(e);
    } finally {
        removeFromCache(data, path, name);
        release(dc);
    // manager.releaseConnection(CONNECTION_ID,dc);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) DatasourceConnection(lucee.runtime.db.DatasourceConnection) SQLException(java.sql.SQLException) IOException(java.io.IOException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 95 with PageException

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

the class Admin method doStartTag.

@Override
public int doStartTag() throws PageException {
    config = (ConfigImpl) pageContext.getConfig();
    // Action
    Object objAction = attributes.get(KeyConstants._action);
    if (objAction == null)
        throw new ApplicationException("missing attrbute action for tag admin");
    action = StringUtil.toLowerCase(Caster.toString(objAction)).trim();
    // Generals
    if (action.equals("buildbundle")) {
        doBuildBundle();
        return SKIP_BODY;
    }
    if (action.equals("readbundle")) {
        doReadBundle();
        return SKIP_BODY;
    }
    if (action.equals("getlocales")) {
        doGetLocales();
        return SKIP_BODY;
    }
    if (action.equals("gettimezones")) {
        doGetTimeZones();
        return SKIP_BODY;
    }
    if (action.equals("printdebug")) {
        throw new DeprecatedException("action [printdebug] is no longer supported, use instead [getdebugdata]");
    }
    if (action.equals("getdebugdata")) {
        doGetDebugData();
        return SKIP_BODY;
    }
    if (action.equals("adddump")) {
        doAddDump();
        return SKIP_BODY;
    }
    if (action.equals("getloginsettings")) {
        doGetLoginSettings();
        return SKIP_BODY;
    }
    // Type
    type = toType(getString("type", "web"), true);
    // has Password
    if (action.equals("haspassword")) {
        boolean hasPassword = type == TYPE_WEB ? pageContext.getConfig().hasPassword() : pageContext.getConfig().hasServerPassword();
        pageContext.setVariable(getString("admin", action, "returnVariable", true), Caster.toBoolean(hasPassword));
        return SKIP_BODY;
    } else // update Password
    if (action.equals("updatepassword")) {
        try {
            ((ConfigWebImpl) pageContext.getConfig()).updatePassword(type != TYPE_WEB, getString("oldPassword", null), getString("admin", action, "newPassword", true));
        } catch (Exception e) {
            throw Caster.toPageException(e);
        }
        return SKIP_BODY;
    }
    try {
        _doStartTag();
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    return Tag.SKIP_BODY;
}
Also used : DeprecatedException(lucee.runtime.exp.DeprecatedException) ApplicationException(lucee.runtime.exp.ApplicationException) IOException(java.io.IOException) PageException(lucee.runtime.exp.PageException) SecurityException(lucee.runtime.exp.SecurityException) IOException(java.io.IOException) DeprecatedException(lucee.runtime.exp.DeprecatedException) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) SMTPException(lucee.runtime.net.mail.SMTPException) ApplicationException(lucee.runtime.exp.ApplicationException)

Aggregations

PageException (lucee.runtime.exp.PageException)200 ApplicationException (lucee.runtime.exp.ApplicationException)56 IOException (java.io.IOException)54 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)37 ExpressionException (lucee.runtime.exp.ExpressionException)32 Resource (lucee.commons.io.res.Resource)30 SecurityException (lucee.runtime.exp.SecurityException)26 BundleException (org.osgi.framework.BundleException)26 MalformedURLException (java.net.MalformedURLException)25 Array (lucee.runtime.type.Array)21 Key (lucee.runtime.type.Collection.Key)17 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)15 SAXException (org.xml.sax.SAXException)15 Entry (java.util.Map.Entry)14 ClassException (lucee.commons.lang.ClassException)14 DeprecatedException (lucee.runtime.exp.DeprecatedException)14 SMTPException (lucee.runtime.net.mail.SMTPException)13 ArrayImpl (lucee.runtime.type.ArrayImpl)13 Query (lucee.runtime.type.Query)13