Search in sources :

Example 1 with RegistryEntry

use of lucee.runtime.registry.RegistryEntry in project Lucee by lucee.

the class Registry method doGetAll.

/**
 * @throws PageException
 */
private void doGetAll() throws PageException {
    if (name == null)
        throw new ApplicationException("attribute name is required for tag registry, when action is [getAll]");
    try {
        RegistryEntry[] entries = RegistryQuery.getValues(branch, type);
        if (entries != null) {
            lucee.runtime.type.Query qry = new QueryImpl(new String[] { "entry", "type", "value" }, new String[] { "VARCHAR", "VARCHAR", "OTHER" }, entries.length, "query");
            for (int i = 0; i < entries.length; i++) {
                RegistryEntry e = entries[i];
                int row = i + 1;
                qry.setAt(KeyConstants._entry, row, e.getKey());
                qry.setAt(KeyConstants._type, row, RegistryEntry.toCFStringType(e.getType()));
                qry.setAt(KeyConstants._value, row, e.getValue());
            }
            // sort
            if (sort != null) {
                String[] arr = sort.toLowerCase().split(",");
                for (int i = arr.length - 1; i >= 0; i--) {
                    String[] col = arr[i].trim().split("\\s+");
                    if (col.length == 1)
                        qry.sort(KeyImpl.init(col[0].trim()));
                    else if (col.length == 2) {
                        String order = col[1].toLowerCase().trim();
                        if (order.equals("asc"))
                            qry.sort(KeyImpl.init(col[0]), lucee.runtime.type.Query.ORDER_ASC);
                        else if (order.equals("desc"))
                            qry.sort(KeyImpl.init(col[0]), lucee.runtime.type.Query.ORDER_DESC);
                        else
                            throw new ApplicationException("invalid order type [" + col[1] + "]");
                    }
                }
            }
            pageContext.setVariable(name, qry);
        }
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) ApplicationException(lucee.runtime.exp.ApplicationException) RegistryEntry(lucee.runtime.registry.RegistryEntry) SecurityException(lucee.runtime.exp.SecurityException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException)

Aggregations

ApplicationException (lucee.runtime.exp.ApplicationException)1 PageException (lucee.runtime.exp.PageException)1 SecurityException (lucee.runtime.exp.SecurityException)1 RegistryEntry (lucee.runtime.registry.RegistryEntry)1 QueryImpl (lucee.runtime.type.QueryImpl)1