Search in sources :

Example 16 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class ArrayMid method call.

public static Array call(PageContext pc, Array arr, double start, double count) throws ExpressionException {
    int s = (int) start;
    int c = (int) count;
    if (s < 1)
        throw new FunctionException(pc, "ArrayMid", 2, "start", "Parameter which is now [" + s + "] must be a positive integer");
    if (c == -1)
        c = arr.size();
    else if (c < -1)
        throw new FunctionException(pc, "ArrayMid", 3, "count", "Parameter which is now [" + c + "] must be a non-negative integer or -1 (for string length)");
    c += s - 1;
    if (s > arr.size())
        return new ArrayImpl();
    ArrayImpl rtn = new ArrayImpl();
    int len = arr.size();
    Object value;
    for (int i = s; i <= c && i <= len; i++) {
        value = arr.get(i, null);
        rtn.appendEL(value);
    }
    return rtn;
}
Also used : ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 17 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class CacheGetAllIds method call.

public static Array call(PageContext pc, String filter, String cacheName) throws PageException {
    try {
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        List<String> keys = isFilter(filter) ? cache.keys(new WildCardFilter(filter, true)) : cache.keys();
        Iterator<String> it = keys.iterator();
        Array arr = new ArrayImpl();
        while (it.hasNext()) {
            arr.append(it.next());
        }
        return arr;
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Cache(lucee.commons.io.cache.Cache)

Example 18 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class ComponentImpl method metaUDFs.

private static void metaUDFs(PageContext pc, ComponentImpl comp, Struct sct, int access) throws PageException {
    // UDFs
    /*ArrayImpl arr1=new ArrayImpl();
		{
			Page page = comp._getPageSource().loadPage(pc, false);
			// Page page = ((PageSourceImpl)comp._getPageSource()).getPage();
			if(page!=null && page.udfs!=null) {
				for(int i=0;i<page.udfs.length;i++){
					if(page.udfs[i].getAccess()>access) continue;
					print.e(">>"+((UDFPropertiesBase)page.udfs[i]).getFunctionName());
					arr1.append(ComponentUtil.getMetaData(pc,(UDFPropertiesBase) page.udfs[i]));
				}
			}
    	}*/
    ArrayImpl arr = new ArrayImpl();
    if (comp.absFin != null) {
        // we not to add abstract separately because they are not real Methods, more a rule
        if (comp.absFin.hasAbstractUDFs())
            getUDFs(pc, comp.absFin.getAbstractUDFs().values().iterator(), comp, access, arr);
    }
    if (comp._udfs != null)
        getUDFs(pc, comp._udfs.values().iterator(), comp, access, arr);
    // property functions
    Iterator<Entry<Key, UDF>> it = comp._udfs.entrySet().iterator();
    Entry<Key, UDF> entry;
    UDF udf;
    while (it.hasNext()) {
        entry = it.next();
        udf = entry.getValue();
        if (udf.getAccess() > access || !(udf instanceof UDFGSProperty))
            continue;
        if (comp.base != null) {
            if (udf == comp.base.getMember(access, entry.getKey(), true, true))
                continue;
        }
        arr.append(udf.getMetaData(pc));
    }
    if (arr.size() != 0) {
        Collections.sort(arr, new ComparatorImpl());
        sct.set(KeyConstants._functions, arr);
    }
}
Also used : UDF(lucee.runtime.type.UDF) ArrayImpl(lucee.runtime.type.ArrayImpl) UDFGSProperty(lucee.runtime.type.UDFGSProperty) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Example 19 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class InterfaceImpl method _getMetaData.

private static Struct _getMetaData(PageContext pc, InterfaceImpl icfc, boolean ignoreCache) throws PageException {
    Page page = MetadataUtil.getPageWhenMetaDataStillValid(pc, icfc, ignoreCache);
    if (page != null && page.metaData != null && page.metaData.get() != null)
        return page.metaData.get();
    long creationTime = System.currentTimeMillis();
    Struct sct = new StructImpl();
    ArrayImpl arr = new ArrayImpl();
    {
        Iterator<UDF> it = icfc.udfs.values().iterator();
        while (it.hasNext()) {
            arr.append(it.next().getMetaData(pc));
        }
    }
    if (icfc.meta != null) {
        Iterator it = icfc.meta.entrySet().iterator();
        Map.Entry entry;
        while (it.hasNext()) {
            entry = (Entry) it.next();
            sct.setEL(KeyImpl.toKey(entry.getKey()), entry.getValue());
        }
    }
    if (!StringUtil.isEmpty(icfc.hint, true))
        sct.set(KeyConstants._hint, icfc.hint);
    if (!StringUtil.isEmpty(icfc.dspName, true))
        sct.set(KeyConstants._displayname, icfc.dspName);
    // init(pc,icfc);
    if (!ArrayUtil.isEmpty(icfc.extend)) {
        Set<String> _set = lucee.runtime.type.util.ListUtil.listToSet(icfc.strExtend, ',', true);
        Struct ex = new StructImpl();
        sct.set(KeyConstants._extends, ex);
        Iterator<InterfaceImpl> it = icfc.extend.iterator();
        InterfaceImpl inter;
        while (it.hasNext()) {
            inter = it.next();
            if (!_set.contains(inter.getCallPath()))
                continue;
            ex.setEL(KeyImpl.init(inter.getCallPath()), _getMetaData(pc, inter, true));
        }
    }
    if (arr.size() != 0)
        sct.set(KeyConstants._functions, arr);
    PageSource ps = icfc.pageSource;
    sct.set(KeyConstants._name, ps.getComponentName());
    sct.set(KeyConstants._fullname, ps.getComponentName());
    sct.set(KeyConstants._path, ps.getDisplayPath());
    sct.set(KeyConstants._type, "interface");
    page.metaData = new MetaDataSoftReference<Struct>(sct, creationTime);
    return sct;
}
Also used : Entry(java.util.Map.Entry) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct) StructImpl(lucee.runtime.type.StructImpl) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class DebugEntryTemplatePartComparator method getDebuggingData.

@Override
public Struct getDebuggingData(PageContext pc, boolean addAddionalInfo) throws DatabaseException {
    Struct debugging = new StructImpl();
    // datasources
    debugging.setEL(KeyConstants._datasources, ((ConfigImpl) pc.getConfig()).getDatasourceConnectionPool().meta());
    // queries
    List<QueryEntry> queries = getQueries();
    Struct qryExe = new StructImpl();
    ListIterator<QueryEntry> qryIt = queries.listIterator();
    Collection.Key[] cols = new Collection.Key[] { KeyConstants._name, KeyConstants._time, KeyConstants._sql, KeyConstants._src, KeyConstants._count, KeyConstants._datasource, KeyConstants._usage, CACHE_TYPE };
    String[] types = new String[] { "VARCHAR", "DOUBLE", "VARCHAR", "VARCHAR", "DOUBLE", "VARCHAR", "ANY", "VARCHAR" };
    Query qryQueries = null;
    try {
        qryQueries = new QueryImpl(cols, types, queries.size(), "query");
    } catch (DatabaseException e) {
        qryQueries = new QueryImpl(cols, queries.size(), "query");
    }
    int row = 0;
    try {
        QueryEntry qe;
        while (qryIt.hasNext()) {
            row++;
            qe = qryIt.next();
            qryQueries.setAt(KeyConstants._name, row, qe.getName() == null ? "" : qe.getName());
            qryQueries.setAt(KeyConstants._time, row, Long.valueOf(qe.getExecutionTime()));
            qryQueries.setAt(KeyConstants._sql, row, qe.getSQL().toString());
            qryQueries.setAt(KeyConstants._src, row, qe.getSrc());
            qryQueries.setAt(KeyConstants._count, row, Integer.valueOf(qe.getRecordcount()));
            qryQueries.setAt(KeyConstants._datasource, row, qe.getDatasource());
            qryQueries.setAt(CACHE_TYPE, row, qe.getCacheType());
            Struct usage = getUsage(qe);
            if (usage != null)
                qryQueries.setAt(KeyConstants._usage, row, usage);
            Object o = qryExe.get(KeyImpl.init(qe.getSrc()), null);
            if (o == null)
                qryExe.setEL(KeyImpl.init(qe.getSrc()), Long.valueOf(qe.getExecutionTime()));
            else
                qryExe.setEL(KeyImpl.init(qe.getSrc()), Long.valueOf(((Long) o).longValue() + qe.getExecutionTime()));
        }
    } catch (PageException dbe) {
    }
    // Pages
    // src,load,app,query,total
    row = 0;
    ArrayList<DebugEntryTemplate> arrPages = toArray();
    int len = arrPages.size();
    Query qryPage = new QueryImpl(new Collection.Key[] { KeyConstants._id, KeyConstants._count, KeyConstants._min, KeyConstants._max, KeyConstants._avg, KeyConstants._app, KeyConstants._load, KeyConstants._query, KeyConstants._total, KeyConstants._src }, len, "query");
    try {
        DebugEntryTemplate de;
        // PageSource ps;
        for (int i = 0; i < len; i++) {
            row++;
            de = arrPages.get(i);
            // ps = de.getPageSource();
            qryPage.setAt(KeyConstants._id, row, de.getId());
            qryPage.setAt(KeyConstants._count, row, _toString(de.getCount()));
            qryPage.setAt(KeyConstants._min, row, _toString(de.getMin()));
            qryPage.setAt(KeyConstants._max, row, _toString(de.getMax()));
            qryPage.setAt(KeyConstants._avg, row, _toString(de.getExeTime() / de.getCount()));
            qryPage.setAt(KeyConstants._app, row, _toString(de.getExeTime() - de.getQueryTime()));
            qryPage.setAt(KeyConstants._load, row, _toString(de.getFileLoadTime()));
            qryPage.setAt(KeyConstants._query, row, _toString(de.getQueryTime()));
            qryPage.setAt(KeyConstants._total, row, _toString(de.getFileLoadTime() + de.getExeTime()));
            qryPage.setAt(KeyConstants._src, row, de.getSrc());
        }
    } catch (PageException dbe) {
    }
    // Pages Parts
    List<DebugEntryTemplatePart> filteredPartEntries = null;
    boolean hasParts = partEntries != null && !partEntries.isEmpty() && !arrPages.isEmpty();
    int qrySize = 0;
    if (hasParts) {
        String slowestTemplate = arrPages.get(0).getPath();
        filteredPartEntries = new ArrayList();
        java.util.Collection<DebugEntryTemplatePartImpl> col = partEntries.values();
        for (DebugEntryTemplatePart detp : col) {
            if (detp.getPath().equals(slowestTemplate))
                filteredPartEntries.add(detp);
        }
        qrySize = Math.min(filteredPartEntries.size(), MAX_PARTS);
    }
    Query qryPart = new QueryImpl(new Collection.Key[] { KeyConstants._id, KeyConstants._count, KeyConstants._min, KeyConstants._max, KeyConstants._avg, KeyConstants._total, KeyConstants._path, KeyConstants._start, KeyConstants._end, KeyConstants._startLine, KeyConstants._endLine, KeyConstants._snippet }, qrySize, "query");
    if (hasParts) {
        row = 0;
        Collections.sort(filteredPartEntries, DEBUG_ENTRY_TEMPLATE_PART_COMPARATOR);
        DebugEntryTemplatePart[] parts = new DebugEntryTemplatePart[qrySize];
        if (filteredPartEntries.size() > MAX_PARTS)
            parts = filteredPartEntries.subList(0, MAX_PARTS).toArray(parts);
        else
            parts = filteredPartEntries.toArray(parts);
        try {
            DebugEntryTemplatePart de;
            // PageSource ps;
            for (int i = 0; i < parts.length; i++) {
                row++;
                de = parts[i];
                qryPart.setAt(KeyConstants._id, row, de.getId());
                qryPart.setAt(KeyConstants._count, row, _toString(de.getCount()));
                qryPart.setAt(KeyConstants._min, row, _toString(de.getMin()));
                qryPart.setAt(KeyConstants._max, row, _toString(de.getMax()));
                qryPart.setAt(KeyConstants._avg, row, _toString(de.getExeTime() / de.getCount()));
                qryPart.setAt(KeyConstants._start, row, _toString(de.getStartPosition()));
                qryPart.setAt(KeyConstants._end, row, _toString(de.getEndPosition()));
                qryPart.setAt(KeyConstants._total, row, _toString(de.getExeTime()));
                qryPart.setAt(KeyConstants._path, row, de.getPath());
                if (de instanceof DebugEntryTemplatePartImpl) {
                    qryPart.setAt(KeyConstants._startLine, row, _toString(((DebugEntryTemplatePartImpl) de).getStartLine()));
                    qryPart.setAt(KeyConstants._endLine, row, _toString(((DebugEntryTemplatePartImpl) de).getEndLine()));
                    qryPart.setAt(KeyConstants._snippet, row, ((DebugEntryTemplatePartImpl) de).getSnippet());
                }
            }
        } catch (PageException dbe) {
        }
    }
    // exceptions
    len = exceptions == null ? 0 : exceptions.size();
    Array arrExceptions = new ArrayImpl();
    if (len > 0) {
        Iterator<CatchBlock> it = exceptions.iterator();
        row = 0;
        while (it.hasNext()) {
            arrExceptions.appendEL(it.next());
        }
    }
    // output log
    // Query qryOutputLog=getOutputText();
    // timers
    len = timers == null ? 0 : timers.size();
    Query qryTimers = new QueryImpl(new Collection.Key[] { KeyConstants._label, KeyConstants._time, KeyConstants._template }, len, "timers");
    if (len > 0) {
        try {
            Iterator<DebugTimerImpl> it = timers.iterator();
            DebugTimer timer;
            row = 0;
            while (it.hasNext()) {
                timer = it.next();
                row++;
                qryTimers.setAt(KeyConstants._label, row, timer.getLabel());
                qryTimers.setAt(KeyConstants._template, row, timer.getTemplate());
                qryTimers.setAt(KeyConstants._time, row, Caster.toDouble(timer.getTime()));
            }
        } catch (PageException dbe) {
        }
    }
    // dumps
    len = dumps == null ? 0 : dumps.size();
    if (!((ConfigImpl) pc.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DUMP))
        len = 0;
    Query qryDumps = new QueryImpl(new Collection.Key[] { KeyConstants._output, KeyConstants._template, KeyConstants._line }, len, "dumps");
    if (len > 0) {
        try {
            Iterator<DebugDump> it = dumps.iterator();
            DebugDump dd;
            row = 0;
            while (it.hasNext()) {
                dd = it.next();
                row++;
                qryDumps.setAt(KeyConstants._output, row, dd.getOutput());
                if (!StringUtil.isEmpty(dd.getTemplate()))
                    qryDumps.setAt(KeyConstants._template, row, dd.getTemplate());
                if (dd.getLine() > 0)
                    qryDumps.setAt(KeyConstants._line, row, new Double(dd.getLine()));
            }
        } catch (PageException dbe) {
        }
    }
    // traces
    len = traces == null ? 0 : traces.size();
    if (!((ConfigImpl) pc.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_TRACING))
        len = 0;
    Query qryTraces = new QueryImpl(new Collection.Key[] { KeyConstants._type, KeyConstants._category, KeyConstants._text, KeyConstants._template, KeyConstants._line, KeyConstants._action, KeyConstants._varname, KeyConstants._varvalue, KeyConstants._time }, len, "traces");
    if (len > 0) {
        try {
            Iterator<DebugTraceImpl> it = traces.iterator();
            DebugTraceImpl trace;
            row = 0;
            while (it.hasNext()) {
                trace = it.next();
                row++;
                qryTraces.setAt(KeyConstants._type, row, DebugTraceImpl.toType(trace.getType(), "INFO"));
                if (!StringUtil.isEmpty(trace.getCategory()))
                    qryTraces.setAt(KeyConstants._category, row, trace.getCategory());
                if (!StringUtil.isEmpty(trace.getText()))
                    qryTraces.setAt(KeyConstants._text, row, trace.getText());
                if (!StringUtil.isEmpty(trace.getTemplate()))
                    qryTraces.setAt(KeyConstants._template, row, trace.getTemplate());
                if (trace.getLine() > 0)
                    qryTraces.setAt(KeyConstants._line, row, new Double(trace.getLine()));
                if (!StringUtil.isEmpty(trace.getAction()))
                    qryTraces.setAt(KeyConstants._action, row, trace.getAction());
                if (!StringUtil.isEmpty(trace.getVarName()))
                    qryTraces.setAt(KeyImpl.init("varname"), row, trace.getVarName());
                if (!StringUtil.isEmpty(trace.getVarValue()))
                    qryTraces.setAt(KeyImpl.init("varvalue"), row, trace.getVarValue());
                qryTraces.setAt(KeyConstants._time, row, new Double(trace.getTime()));
            }
        } catch (PageException dbe) {
        }
    }
    // scope access
    len = implicitAccesses == null ? 0 : implicitAccesses.size();
    Query qryImplicitAccesseses = new QueryImpl(new Collection.Key[] { KeyConstants._template, KeyConstants._line, KeyConstants._scope, KeyConstants._count, KeyConstants._name }, len, "implicitAccess");
    if (len > 0) {
        try {
            Iterator<ImplicitAccessImpl> it = implicitAccesses.values().iterator();
            ImplicitAccessImpl das;
            row = 0;
            while (it.hasNext()) {
                das = it.next();
                row++;
                qryImplicitAccesseses.setAt(KeyConstants._template, row, das.getTemplate());
                qryImplicitAccesseses.setAt(KeyConstants._line, row, new Double(das.getLine()));
                qryImplicitAccesseses.setAt(KeyConstants._scope, row, das.getScope());
                qryImplicitAccesseses.setAt(KeyConstants._count, row, new Double(das.getCount()));
                qryImplicitAccesseses.setAt(KeyConstants._name, row, das.getName());
            }
        } catch (PageException dbe) {
        }
    }
    Query history = new QueryImpl(new Collection.Key[] {}, 0, "history");
    try {
        history.addColumn(KeyConstants._id, historyId);
        history.addColumn(KeyConstants._level, historyLevel);
    } catch (PageException e) {
    }
    if (addAddionalInfo) {
        debugging.setEL(KeyConstants._cgi, pc.cgiScope());
        debugging.setEL(KeyImpl.init("starttime"), new DateTimeImpl(starttime, false));
        debugging.setEL(KeyConstants._id, pc.getId());
    }
    debugging.setEL(KeyConstants._pages, qryPage);
    debugging.setEL(PAGE_PARTS, qryPart);
    debugging.setEL(KeyConstants._queries, qryQueries);
    debugging.setEL(KeyConstants._timers, qryTimers);
    debugging.setEL(KeyConstants._traces, qryTraces);
    debugging.setEL("dumps", qryDumps);
    debugging.setEL(IMPLICIT_ACCESS, qryImplicitAccesseses);
    // debugging.setEL(OUTPUT_LOG,qryOutputLog);
    debugging.setEL(KeyConstants._history, history);
    debugging.setEL(KeyConstants._exceptions, arrExceptions);
    return debugging;
}
Also used : Query(lucee.runtime.type.Query) ArrayImpl(lucee.runtime.type.ArrayImpl) ArrayList(java.util.ArrayList) Struct(lucee.runtime.type.Struct) QueryImpl(lucee.runtime.type.QueryImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) PageException(lucee.runtime.exp.PageException) Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) CatchBlock(lucee.runtime.exp.CatchBlock) Collection(lucee.runtime.type.Collection) DatabaseException(lucee.runtime.exp.DatabaseException) ConfigImpl(lucee.runtime.config.ConfigImpl) Key(lucee.runtime.type.Collection.Key)

Aggregations

ArrayImpl (lucee.runtime.type.ArrayImpl)100 Array (lucee.runtime.type.Array)79 Struct (lucee.runtime.type.Struct)33 StructImpl (lucee.runtime.type.StructImpl)24 PageException (lucee.runtime.exp.PageException)14 Entry (java.util.Map.Entry)13 Key (lucee.runtime.type.Collection.Key)12 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 ArrayList (java.util.ArrayList)6 ListIterator (java.util.ListIterator)6 FunctionException (lucee.runtime.exp.FunctionException)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 ApplicationException (lucee.runtime.exp.ApplicationException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Query (lucee.runtime.type.Query)5 QueryImpl (lucee.runtime.type.QueryImpl)5 ListAsArray (lucee.runtime.type.wrap.ListAsArray)5 NodeList (org.w3c.dom.NodeList)5