Search in sources :

Example 61 with StructImpl

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

the class JSONConverter method _serializeUDF.

private void _serializeUDF(PageContext pc, Set test, UDF udf, StringBuilder sb, boolean serializeQueryByColumns, Set<Object> done) throws ConverterException {
    Struct sct = new StructImpl();
    try {
        // Meta
        Struct meta = udf.getMetaData(pc);
        sct.setEL("Metadata", meta);
        // Parameters
        sct.setEL("MethodAttributes", meta.get("PARAMETERS"));
    } catch (PageException e) {
        throw toConverterException(e);
    }
    sct.setEL("Access", ComponentUtil.toStringAccess(udf.getAccess(), "public"));
    sct.setEL("Output", Caster.toBoolean(udf.getOutput()));
    sct.setEL("ReturnType", udf.getReturnTypeAsString());
    try {
        sct.setEL("PagePath", udf.getSource());
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    _serializeStruct(pc, test, sct, sb, serializeQueryByColumns, true, done);
// TODO key SuperScope and next?
}
Also used : PageException(lucee.runtime.exp.PageException) StructImpl(lucee.runtime.type.StructImpl) Struct(lucee.runtime.type.Struct)

Example 62 with StructImpl

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

the class WDDXConverter method _deserializeStruct.

/**
 * Desirialize a Struct Object
 *
 * @param elStruct
 *            Struct Object as XML Element
 * @return Struct Object
 * @throws ConverterException
 */
private Object _deserializeStruct(Element elStruct) throws ConverterException {
    String type = elStruct.getAttribute("type");
    Struct struct = new StructImpl();
    NodeList list = elStruct.getChildNodes();
    int len = list.getLength();
    for (int i = 0; i < len; i++) {
        // print.ln(i);
        Node node = list.item(i);
        if (node instanceof Element) {
            Element var = (Element) node;
            Element value = getChildElement((Element) node);
            if (value != null) {
                struct.setEL(var.getAttribute("name"), _deserialize(value));
            }
        }
    }
    /**
     * java objects are serialized as empty struct with a type that denotes the class, so
     * if it's not a known struct-type it is not a struct
     */
    if (struct.isEmpty() && !StringUtil.isEmpty(type) && !KNOWN_STRUCT_TYPES.contains(type))
        return "";
    return struct;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Struct(lucee.runtime.type.Struct)

Example 63 with StructImpl

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

the class CFMLEngineImpl method cli.

@Override
public void cli(Map<String, String> config, ServletConfig servletConfig) throws IOException, JspException, ServletException {
    ServletContext servletContext = servletConfig.getServletContext();
    HTTPServletImpl servlet = new HTTPServletImpl(servletConfig, servletContext, servletConfig.getServletName());
    // webroot
    String strWebroot = config.get("webroot");
    if (StringUtil.isEmpty(strWebroot, true))
        throw new IOException("missing webroot configuration");
    Resource root = ResourcesImpl.getFileResourceProvider().getResource(strWebroot);
    root.mkdirs();
    // serverName
    String serverName = config.get("server-name");
    if (StringUtil.isEmpty(serverName, true))
        serverName = "localhost";
    // uri
    String strUri = config.get("uri");
    if (StringUtil.isEmpty(strUri, true))
        throw new IOException("missing uri configuration");
    URI uri;
    try {
        uri = lucee.commons.net.HTTPUtil.toURI(strUri);
    } catch (URISyntaxException e) {
        throw Caster.toPageException(e);
    }
    // cookie
    Cookie[] cookies;
    String strCookie = config.get("cookie");
    if (StringUtil.isEmpty(strCookie, true))
        cookies = new Cookie[0];
    else {
        Map<String, String> mapCookies = HTTPUtil.parseParameterList(strCookie, false, null);
        int index = 0;
        cookies = new Cookie[mapCookies.size()];
        Entry<String, String> entry;
        Iterator<Entry<String, String>> it = mapCookies.entrySet().iterator();
        Cookie c;
        while (it.hasNext()) {
            entry = it.next();
            c = ReqRspUtil.toCookie(entry.getKey(), entry.getValue(), null);
            if (c != null)
                cookies[index++] = c;
            else
                throw new IOException("cookie name [" + entry.getKey() + "] is invalid");
        }
    }
    // header
    Pair[] headers = new Pair[0];
    // parameters
    Pair[] parameters = new Pair[0];
    // attributes
    StructImpl attributes = new StructImpl();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    HttpServletRequestDummy req = new HttpServletRequestDummy(root, serverName, uri.getPath(), uri.getQuery(), cookies, headers, parameters, attributes, null, null);
    req.setProtocol("CLI/1.0");
    HttpServletResponse rsp = new HttpServletResponseDummy(os);
    serviceCFML(servlet, req, rsp);
    String res = os.toString(ReqRspUtil.getCharacterEncoding(null, rsp).name());
    System.out.println(res);
}
Also used : Cookie(javax.servlet.http.Cookie) Resource(lucee.commons.io.res.Resource) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(java.net.URI) ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) HttpServletRequestDummy(lucee.runtime.net.http.HttpServletRequestDummy) ServletContext(javax.servlet.ServletContext) HttpServletResponseDummy(lucee.runtime.net.http.HttpServletResponseDummy) HTTPServletImpl(lucee.cli.servlet.HTTPServletImpl) Pair(lucee.commons.lang.Pair)

Example 64 with StructImpl

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

the class CatchBlockImpl method duplicate.

@Override
public Collection duplicate(boolean deepCopy) {
    Struct sct = new StructImpl();
    StructUtil.copy(this, sct, true);
    return sct;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) Struct(lucee.runtime.type.Struct)

Example 65 with StructImpl

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

the class PageExceptionImpl method addContext.

@Override
public void addContext(PageSource ps, int line, int column, StackTraceElement element) {
    if (line == -187) {
        sources.add(ps);
        return;
    }
    Struct struct = new StructImpl();
    // print.out(pr.getDisplayPath());
    try {
        String[] content = ps.getSource();
        struct.set(KeyConstants._template, ps.getDisplayPath());
        struct.set(KeyConstants._line, new Double(line));
        struct.set(KeyConstants._id, "??");
        struct.set(KeyConstants._Raw_Trace, (element != null) ? element.toString() : "");
        struct.set(KeyConstants._Type, "cfml");
        struct.set(KeyConstants._column, new Double(column));
        if (content != null) {
            struct.set(KeyConstants._codePrintHTML, getCodePrint(content, line, true));
            struct.set(KeyConstants._codePrintPlain, getCodePrint(content, line, false));
        }
        tagContext.append(struct);
    } catch (Exception e) {
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Struct(lucee.runtime.type.Struct)

Aggregations

StructImpl (lucee.runtime.type.StructImpl)251 Struct (lucee.runtime.type.Struct)216 PageException (lucee.runtime.exp.PageException)40 Entry (java.util.Map.Entry)34 Key (lucee.runtime.type.Collection.Key)28 Array (lucee.runtime.type.Array)25 ArrayImpl (lucee.runtime.type.ArrayImpl)24 ApplicationException (lucee.runtime.exp.ApplicationException)21 IOException (java.io.IOException)19 Map (java.util.Map)19 Resource (lucee.commons.io.res.Resource)18 Iterator (java.util.Iterator)17 PageContextImpl (lucee.runtime.PageContextImpl)14 QueryImpl (lucee.runtime.type.QueryImpl)13 Collection (lucee.runtime.type.Collection)11 Query (lucee.runtime.type.Query)11 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)11 HashMap (java.util.HashMap)9 PageSource (lucee.runtime.PageSource)8 Element (org.w3c.dom.Element)8