Search in sources :

Example 1 with MicroformatParser

use of org.structr.web.common.microformat.MicroformatParser in project structr by structr.

the class ParseFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) {
    if (sources != null && sources.length == 2) {
        try {
            final String source = sources[0].toString();
            final String selector = sources[1].toString();
            final List<Map<String, Object>> objects = new MicroformatParser().parse(source, selector);
            final List<GraphObjectMap> elements = new LinkedList<>();
            for (final Map<String, Object> map : objects) {
                final GraphObjectMap obj = new GraphObjectMap();
                elements.add(obj);
                recursivelyConvertMapToGraphObjectMap(obj, map, 0);
            }
            return elements;
        } catch (Throwable t) {
            logException(caller, t, sources);
        }
        return "";
    } else {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
    }
    return usage(ctx.isJavaScriptContext());
}
Also used : GraphObjectMap(org.structr.core.GraphObjectMap) Map(java.util.Map) GraphObjectMap(org.structr.core.GraphObjectMap) MicroformatParser(org.structr.web.common.microformat.MicroformatParser) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 GraphObjectMap (org.structr.core.GraphObjectMap)1 MicroformatParser (org.structr.web.common.microformat.MicroformatParser)1