Search in sources :

Example 86 with ArrayImpl

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

the class Map method invoke.

private static Query invoke(PageContext pc, Query qry, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures, Query rtn) throws PageException {
    Key[] colNames = qry.getColumnNames();
    if (rtn == null) {
        rtn = new QueryImpl(colNames, 0, qry.getName());
    } else {
        // check if we have the necessary columns
        for (Key colName : colNames) {
            if (rtn.getColumn(colName, null) == null) {
                rtn.addColumn(colName, new ArrayImpl());
            }
        }
    }
    final int pid = pc.getId();
    ForEachQueryIterator it = new ForEachQueryIterator(qry, pid);
    int rowNbr;
    Object row, res;
    boolean async = es != null;
    while (it.hasNext()) {
        row = it.next();
        rowNbr = qry.getCurrentrow(pid);
        res = _inv(pc, udf, new Object[] { row, rowNbr, qry }, rowNbr, es, futures);
        if (!async) {
            addRow(Caster.toStruct(res), rtn);
        }
    }
    return rtn;
}
Also used : ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) QueryImpl(lucee.runtime.type.QueryImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) Key(lucee.runtime.type.Collection.Key) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Example 87 with ArrayImpl

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

the class ORMExecuteQuery method _call.

private static Object _call(PageContext pc, String hql, Object params, boolean unique, Struct queryOptions) throws PageException {
    ORMSession session = ORMUtil.getSession(pc);
    String dsn = null;
    if (queryOptions != null)
        dsn = Caster.toString(queryOptions.get(KeyConstants._datasource, null), null);
    if (StringUtil.isEmpty(dsn, true))
        dsn = ORMUtil.getDefaultDataSource(pc).getName();
    if (params == null)
        return toCFML(session.executeQuery(pc, dsn, hql, new ArrayImpl(), unique, queryOptions));
    else if (Decision.isStruct(params))
        return toCFML(session.executeQuery(pc, dsn, hql, Caster.toStruct(params), unique, queryOptions));
    else if (Decision.isArray(params))
        return toCFML(session.executeQuery(pc, dsn, hql, Caster.toArray(params), unique, queryOptions));
    else if (Decision.isCastableToStruct(params))
        return toCFML(session.executeQuery(pc, dsn, hql, Caster.toStruct(params), unique, queryOptions));
    else if (Decision.isCastableToArray(params))
        return toCFML(session.executeQuery(pc, dsn, hql, Caster.toArray(params), unique, queryOptions));
    else
        throw new FunctionException(pc, "ORMExecuteQuery", 2, "params", "cannot convert the params to a array or a struct");
}
Also used : ORMSession(lucee.runtime.orm.ORMSession) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 88 with ArrayImpl

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

the class HTTPClient method call.

@Override
public Object call(PageContext pc, Key methodName, Object[] arguments) throws PageException {
    checkFunctionExistence(pc, methodName, false);
    if (arguments.length == 0)
        return _callWithNamedValues(pc, methodName, new StructImpl());
    Struct m = checkFunctionExistence(pc, methodName, true);
    Array args = Caster.toArray(m.get(KeyConstants._arguments, null), null);
    if (args == null)
        args = new ArrayImpl();
    Struct sct = new StructImpl(), el;
    String name;
    for (int i = 0; i < arguments.length; i++) {
        if (args.size() > i) {
            el = Caster.toStruct(args.get(i + 1, null), null);
            if (el != null) {
                name = Caster.toString(el.get(KeyConstants._name, null), null);
                if (!StringUtil.isEmpty(name)) {
                    sct.set(name, arguments[i]);
                    continue;
                }
            }
        }
        sct.set("arg" + (i + 1), arguments[i]);
    }
    return _callWithNamedValues(pc, methodName, sct);
}
Also used : Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct)

Example 89 with ArrayImpl

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

the class MultiPartResponseUtils method getParts.

public static Array getParts(byte[] barr, String contentTypeHeader) throws IOException, PageException {
    String boundary = extractBoundary(contentTypeHeader, "");
    ByteArrayInputStream bis = new ByteArrayInputStream(barr);
    MultipartStream stream;
    Array result = new ArrayImpl();
    // 
    stream = new MultipartStream(bis, getBytes(boundary, "UTF-8"));
    boolean hasNextPart = stream.skipPreamble();
    while (hasNextPart) {
        result.append(getPartData(stream));
        hasNextPart = stream.readBoundary();
    }
    return result;
}
Also used : Array(lucee.runtime.type.Array) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayImpl(lucee.runtime.type.ArrayImpl) MultipartStream(org.apache.commons.fileupload.MultipartStream)

Example 90 with ArrayImpl

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

the class MailClient method getContent.

/**
 * write content data to query
 * @param qry
 * @param content
 * @param row
 * @throws MessagingException
 * @throws IOException
 */
private void getContent(Query query, Message message, int row) throws MessagingException, IOException {
    StringBuffer body = new StringBuffer();
    Struct cids = new StructImpl();
    query.setAtEL(CIDS, row, cids);
    if (message.isMimeType("text/plain")) {
        String content = getConent(message);
        query.setAtEL(TEXT_BODY, row, content);
        body.append(content);
    } else if (message.isMimeType("text/html")) {
        String content = getConent(message);
        query.setAtEL(HTML_BODY, row, content);
        body.append(content);
    } else {
        Object content = message.getContent();
        if (content instanceof MimeMultipart) {
            Array attachments = new ArrayImpl();
            Array attachmentFiles = new ArrayImpl();
            getMultiPart(query, row, attachments, attachmentFiles, cids, (MimeMultipart) content, body);
            if (attachments.size() > 0) {
                try {
                    query.setAtEL(ATTACHMENTS, row, ListUtil.arrayToList(attachments, "\t"));
                } catch (PageException pageexception) {
                }
            }
            if (attachmentFiles.size() > 0) {
                try {
                    query.setAtEL(ATTACHMENT_FILES, row, ListUtil.arrayToList(attachmentFiles, "\t"));
                } catch (PageException pageexception1) {
                }
            }
        }
    }
    query.setAtEL(BODY, row, body.toString());
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException) StructImpl(lucee.runtime.type.StructImpl) MimeMultipart(javax.mail.internet.MimeMultipart) ArrayImpl(lucee.runtime.type.ArrayImpl) Struct(lucee.runtime.type.Struct)

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