Search in sources :

Example 1 with UDF

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

the class ComponentController method _invoke.

public static Object _invoke(String name, Object[] args) throws PageException {
    Key key = Caster.toKey(name);
    Component c = component.get();
    PageContext p = pagecontext.get();
    MessageContext mc = messageContext.get();
    if (c == null)
        throw new ApplicationException("missing component");
    if (p == null)
        throw new ApplicationException("missing pagecontext");
    UDF udf = Caster.toFunction(c.get(p, key, null), null);
    FunctionArgument[] fa = null;
    if (udf != null)
        fa = udf.getFunctionArguments();
    for (int i = 0; i < args.length; i++) {
        if (fa != null && i < fa.length && fa[i].getType() == CFTypes.TYPE_UNKNOW) {
            args[i] = AxisCaster.toLuceeType(p, fa[i].getTypeAsString(), args[i]);
        } else
            args[i] = AxisCaster.toLuceeType(p, args[i]);
    }
    // return type
    String rtnType = udf != null ? udf.getReturnTypeAsString() : "any";
    Object rtn = c.call(p, key, args);
    // cast return value to Axis type
    try {
        RPCServer server = RPCServer.getInstance(p.getId(), p, p.getServletContext());
        TypeMapping tm = mc != null ? mc.getTypeMapping() : TypeMappingUtil.getServerTypeMapping(server.getEngine().getTypeMappingRegistry());
        rtn = Caster.castTo(p, rtnType, rtn, false);
        Class<?> clazz = Caster.cfTypeToClass(rtnType);
        return AxisCaster.toAxisType(tm, rtn, clazz.getComponentType() != null ? clazz : null);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    }
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) UDF(lucee.runtime.type.UDF) TypeMapping(javax.xml.rpc.encoding.TypeMapping) PageContext(lucee.runtime.PageContext) MessageContext(org.apache.axis.MessageContext) Component(lucee.runtime.Component) FunctionArgument(lucee.runtime.type.FunctionArgument) Key(lucee.runtime.type.Collection.Key)

Example 2 with UDF

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

the class SMTPClient method send.

public void send(PageContext pc, long sendTime) throws MailException {
    if (plainText == null && htmlText == null)
        throw new MailException("you must define plaintext or htmltext");
    Server[] servers = ((PageContextImpl) pc).getMailServers();
    ConfigWeb config = pc.getConfig();
    if (ArrayUtil.isEmpty(servers) && ArrayUtil.isEmpty(host))
        throw new MailException("no SMTP Server defined");
    if (spool == SPOOL_YES || (spool == SPOOL_UNDEFINED && config.isMailSpoolEnable())) {
        MailSpoolerTask mst = new MailSpoolerTask(this, servers, sendTime);
        if (listener instanceof Component)
            mst.setListener(new ComponentSpoolerTaskListener(SystemUtil.getCurrentContext(), mst, (Component) listener));
        else if (listener instanceof UDF)
            mst.setListener(new UDFSpoolerTaskListener(SystemUtil.getCurrentContext(), mst, (UDF) listener));
        config.getSpoolerEngine().add(mst);
    } else
        _send(config, servers);
}
Also used : Server(lucee.runtime.net.mail.Server) UDFSpoolerTaskListener(lucee.runtime.spooler.UDFSpoolerTaskListener) UDF(lucee.runtime.type.UDF) MailException(lucee.runtime.net.mail.MailException) PageContextImpl(lucee.runtime.PageContextImpl) MailSpoolerTask(lucee.runtime.spooler.mail.MailSpoolerTask) Component(lucee.runtime.Component) ConfigWeb(lucee.runtime.config.ConfigWeb) ComponentSpoolerTaskListener(lucee.runtime.spooler.ComponentSpoolerTaskListener)

Example 3 with UDF

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

the class ScriptConverter method _serializeComponent.

/**
 * serialize a Component
 * @param c Component to serialize
 * @param sb
 * @param done
 * @throws ConverterException
 */
private void _serializeComponent(Component c, StringBuilder sb, Set<Object> done) throws ConverterException {
    ComponentSpecificAccess cw = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, c);
    sb.append(goIn());
    try {
        sb.append("evaluateComponent(").append(QUOTE_CHR).append(c.getAbsName()).append(QUOTE_CHR).append(',').append(QUOTE_CHR).append(ComponentUtil.md5(c)).append(QUOTE_CHR).append(",{");
    } catch (Exception e) {
        throw toConverterException(e);
    }
    boolean doIt = false;
    Object member;
    {
        Iterator<Entry<Key, Object>> it = cw.entryIterator();
        deep++;
        Entry<Key, Object> e;
        while (it.hasNext()) {
            e = it.next();
            member = e.getValue();
            if (member instanceof UDF)
                continue;
            if (doIt)
                sb.append(',');
            doIt = true;
            sb.append(QUOTE_CHR);
            sb.append(escape(e.getKey().getString()));
            sb.append(QUOTE_CHR);
            sb.append(':');
            _serialize(member, sb, done);
        }
        sb.append("}");
        deep--;
    }
    {
        boolean isPeristent = c.isPersistent();
        ComponentScope scope = c.getComponentScope();
        Iterator<Entry<Key, Object>> it = scope.entryIterator();
        sb.append(",{");
        deep++;
        doIt = false;
        Property p;
        Boolean remotingFetch;
        Struct props = ignoreRemotingFetch ? null : ComponentUtil.getPropertiesAsStruct(c, false);
        Entry<Key, Object> e;
        Key k;
        while (it.hasNext()) {
            e = it.next();
            k = e.getKey();
            // String key=Caster.toString(it.next(),"");
            if (KeyConstants._THIS.equalsIgnoreCase(k))
                continue;
            if (!ignoreRemotingFetch) {
                p = (Property) props.get(k, null);
                if (p != null) {
                    remotingFetch = Caster.toBoolean(p.getDynamicAttributes().get(REMOTING_FETCH, null), null);
                    if (remotingFetch == null) {
                        if (isPeristent && ORMUtil.isRelated(p))
                            continue;
                    } else if (!remotingFetch.booleanValue())
                        continue;
                }
            }
            member = e.getValue();
            if (member instanceof UDF)
                continue;
            if (doIt)
                sb.append(',');
            doIt = true;
            sb.append(QUOTE_CHR);
            sb.append(escape(k.getString()));
            sb.append(QUOTE_CHR);
            sb.append(':');
            _serialize(member, sb, done);
        }
        sb.append("}");
        deep--;
    }
    sb.append(")");
// sb.append("");
// throw new ConverterException("can't serialize a component "+component.getDisplayName());
}
Also used : Entry(java.util.Map.Entry) ComponentScope(lucee.runtime.ComponentScope) UDF(lucee.runtime.type.UDF) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Property(lucee.runtime.component.Property) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) Key(lucee.runtime.type.Collection.Key) Struct(lucee.runtime.type.Struct)

Example 4 with UDF

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

the class WDDXConverter method _serializeComponent.

/**
 * serialize a Component
 *
 * @param component
 *            Component to serialize
 * @param done
 * @return serialized component
 * @throws ConverterException
 */
private String _serializeComponent(Component component, Set<Object> done) throws ConverterException {
    StringBuilder sb = new StringBuilder();
    Component ca;
    component = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, ca = component);
    boolean isPeristent = ca.isPersistent();
    deep++;
    Object member;
    Iterator<Key> it = component.keyIterator();
    Collection.Key key;
    while (it.hasNext()) {
        key = Caster.toKey(it.next(), null);
        member = component.get(key, null);
        if (member instanceof UDF)
            continue;
        sb.append(goIn() + "<var scope=\"this\" name=" + del + XMLUtil.escapeXMLString(key.toString()) + del + ">");
        sb.append(_serialize(member, done));
        sb.append(goIn() + "</var>");
    }
    Property p;
    Boolean remotingFetch;
    Struct props = ignoreRemotingFetch ? null : ComponentUtil.getPropertiesAsStruct(ca, false);
    ComponentScope scope = ca.getComponentScope();
    it = scope.keyIterator();
    while (it.hasNext()) {
        key = Caster.toKey(it.next(), null);
        if (!ignoreRemotingFetch) {
            p = (Property) props.get(key, null);
            if (p != null) {
                remotingFetch = Caster.toBoolean(p.getDynamicAttributes().get(REMOTING_FETCH, null), null);
                if (remotingFetch == null) {
                    if (isPeristent && ORMUtil.isRelated(p))
                        continue;
                } else if (!remotingFetch.booleanValue())
                    continue;
            }
        }
        member = scope.get(key, null);
        if (member instanceof UDF || key.equals(KeyConstants._this))
            continue;
        sb.append(goIn() + "<var scope=\"variables\" name=" + del + XMLUtil.escapeXMLString(key.toString()) + del + ">");
        sb.append(_serialize(member, done));
        sb.append(goIn() + "</var>");
    }
    deep--;
    try {
        // return goIn()+"<struct>"+sb+"</struct>";
        return goIn() + "<component md5=\"" + ComponentUtil.md5(component) + "\" name=\"" + XMLUtil.escapeXMLString(component.getAbsName()) + "\">" + sb + "</component>";
    } catch (Exception e) {
        throw toConverterException(e);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException) CoderException(lucee.runtime.coder.CoderException) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) ComponentScope(lucee.runtime.ComponentScope) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Collection(lucee.runtime.type.Collection) Component(lucee.runtime.Component) Property(lucee.runtime.component.Property) Key(lucee.runtime.type.Collection.Key)

Example 5 with UDF

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

the class ComponentImpl method thisScope.

static DumpTable thisScope(ComponentImpl ci, PageContext pc, int maxlevel, DumpProperties dp, int access) {
    DumpTable table = new DumpTable("#ffffff", "#cccccc", "#000000");
    DumpTable[] accesses = new DumpTable[4];
    accesses[Component.ACCESS_REMOTE] = new DumpTable("#ccffcc", "#ffffff", "#000000");
    accesses[Component.ACCESS_REMOTE].setTitle("remote");
    accesses[Component.ACCESS_PUBLIC] = new DumpTable("#ffcc99", "#ffffcc", "#000000");
    accesses[Component.ACCESS_PUBLIC].setTitle("public");
    accesses[Component.ACCESS_PACKAGE] = new DumpTable("#ff9966", "#ffcc99", "#000000");
    accesses[Component.ACCESS_PACKAGE].setTitle("package");
    accesses[Component.ACCESS_PRIVATE] = new DumpTable("#ff6633", "#ff9966", "#000000");
    accesses[Component.ACCESS_PRIVATE].setTitle("private");
    maxlevel--;
    ComponentSpecificAccess cw = new ComponentSpecificAccess(Component.ACCESS_PRIVATE, ci);
    Collection.Key[] keys = cw.keys();
    List<DumpRow>[] drAccess = new List[4];
    for (int i = 0; i < drAccess.length; i++) // ACCESS_REMOTE=0, ACCESS_PUBLIC=1, ACCESS_PACKAGE=2, ACCESS_PRIVATE=3
    drAccess[i] = new ArrayList();
    Collection.Key key;
    for (int i = 0; i < keys.length; i++) {
        key = keys[i];
        List<DumpRow> box = drAccess[ci.getAccess(key)];
        Object o = cw.get(key, null);
        if (o == ci)
            o = "[this]";
        if (DumpUtil.keyValid(dp, maxlevel, key)) {
            String memberName = (o instanceof UDF) ? ((UDF) o).getFunctionName() : key.getString();
            box.add(new DumpRow(1, new SimpleDumpData(memberName), DumpUtil.toDumpData(o, pc, maxlevel, dp)));
        }
    }
    List<DumpRow> dumpRows;
    for (int i = 0; i < drAccess.length; i++) {
        dumpRows = drAccess[i];
        if (!dumpRows.isEmpty()) {
            Collections.sort(dumpRows, new Comparator<DumpRow>() {

                @Override
                public int compare(DumpRow o1, DumpRow o2) {
                    DumpData[] rowItems1 = o1.getItems();
                    DumpData[] rowItems2 = o2.getItems();
                    if (rowItems1.length >= 0 && rowItems2.length > 0 && rowItems1[0] instanceof SimpleDumpData && rowItems2[0] instanceof SimpleDumpData)
                        return String.CASE_INSENSITIVE_ORDER.compare(rowItems1[0].toString(), rowItems2[0].toString());
                    return 0;
                }
            });
            DumpTable dtAccess = accesses[i];
            dtAccess.setWidth("100%");
            for (DumpRow dr : dumpRows) dtAccess.appendRow(dr);
            table.appendRow(0, dtAccess);
        }
    }
    // properties
    if (ci.top.properties.persistent || ci.top.properties.accessors) {
        Property[] properties = ci.getProperties(false, true, false, false);
        DumpTable prop = new DumpTable("#99cc99", "#ccffcc", "#000000");
        prop.setTitle("Properties");
        prop.setWidth("100%");
        Property p;
        Object child;
        for (int i = 0; i < properties.length; i++) {
            p = properties[i];
            child = ci.scope.get(KeyImpl.init(p.getName()), null);
            DumpData dd;
            if (child instanceof Component) {
                DumpTable t = new DumpTable("component", "#99cc99", "#ffffff", "#000000");
                t.appendRow(1, new SimpleDumpData(((Component) child).getPageSource().getDialect() == CFMLEngine.DIALECT_CFML ? "Component" : "Class"), new SimpleDumpData(((Component) child).getCallName()));
                dd = t;
            } else {
                dd = DumpUtil.toDumpData(child, pc, maxlevel - 1, dp);
            }
            prop.appendRow(1, new SimpleDumpData(p.getName()), dd);
        }
        if (access >= ACCESS_PUBLIC && !prop.isEmpty()) {
            table.appendRow(0, prop);
        }
    }
    return table;
}
Also used : DumpRow(lucee.runtime.dump.DumpRow) ArrayList(java.util.ArrayList) DumpData(lucee.runtime.dump.DumpData) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) DumpTable(lucee.runtime.dump.DumpTable) UDF(lucee.runtime.type.UDF) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Collection(lucee.runtime.type.Collection) List(java.util.List) ArrayList(java.util.ArrayList) EvaluateComponent(lucee.runtime.functions.dynamicEvaluation.EvaluateComponent) UDFGSProperty(lucee.runtime.type.UDFGSProperty) Property(lucee.runtime.component.Property) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Aggregations

UDF (lucee.runtime.type.UDF)42 Key (lucee.runtime.type.Collection.Key)14 Struct (lucee.runtime.type.Struct)14 Component (lucee.runtime.Component)9 Entry (java.util.Map.Entry)7 PageException (lucee.runtime.exp.PageException)7 Member (lucee.runtime.component.Member)6 FunctionArgument (lucee.runtime.type.FunctionArgument)6 StructImpl (lucee.runtime.type.StructImpl)6 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)6 Iterator (java.util.Iterator)5 ComponentScope (lucee.runtime.ComponentScope)5 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)5 PageContextImpl (lucee.runtime.PageContextImpl)5 Property (lucee.runtime.component.Property)5 Array (lucee.runtime.type.Array)5 Collection (lucee.runtime.type.Collection)5 IOException (java.io.IOException)4 Map (java.util.Map)4 HashMap (java.util.HashMap)3