Search in sources :

Example 11 with JSONElement

use of com.eden.common.json.JSONElement in project Orchid by JavaEden.

the class OrchidUtils method findInMap.

private static String findInMap(String link, JSONObject mapObject, String displayName) {
    List urls = WalkMapFilter.walkObject(mapObject, "url");
    String template = "<a href=\"#{$1}\">#{$2}</a>";
    for (Object object : urls) {
        if (object instanceof Map) {
            Map map = (Map) object;
            if (map.containsKey("url")) {
                JSONElement element = new JSONElement(new JSONObject(map));
                if (OrchidUtils.elementIsString(element.query("data.info.qualifiedName")) && element.query("data.info.qualifiedName").toString().equals(link)) {
                    if (!EdenUtils.isEmpty(displayName)) {
                        return Clog.format(template, map.get("url"), displayName);
                    } else {
                        return Clog.format(template, map.get("url"), map.get("name"));
                    }
                } else if (map.containsKey("name") && map.get("name").toString().equals(link)) {
                    if (!EdenUtils.isEmpty(displayName)) {
                        return Clog.format(template, map.get("url"), displayName);
                    } else {
                        return Clog.format(template, map.get("url"), map.get("name"));
                    }
                }
            }
        }
    }
    return null;
}
Also used : JSONElement(com.eden.common.json.JSONElement) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) Map(java.util.Map)

Example 12 with JSONElement

use of com.eden.common.json.JSONElement in project Orchid by JavaEden.

the class PrioritizedSetFilter method getFilteredSet.

public Set<T> getFilteredSet() {
    if (fullFilteredSet != null) {
        return fullFilteredSet;
    }
    JSONElement element = context.query("options." + key);
    Stream<T> filter = originalSet.stream();
    if (OrchidUtils.elementIsObject(element)) {
        JSONObject filterQuery = (JSONObject) element.getElement();
        if (filterQuery.has(ALLOWED_KEY) && filterQuery.get(ALLOWED_KEY) instanceof JSONArray) {
            JSONArray allowedItems = filterQuery.getJSONArray(ALLOWED_KEY);
            if (allowedItems.length() > 0) {
                Clog.v("PrioritizedSetFilter '#{$1}' applying filters to whitelist items", new Object[] { key });
                filter = filter.filter(t -> {
                    boolean inAllowedItems = false;
                    for (int i = 0; i < allowedItems.length(); i++) {
                        inAllowedItems = t.getClass().getSimpleName().equals(allowedItems.getString(i));
                        inAllowedItems = inAllowedItems || (t.getClass().getName().equals(allowedItems.getString(i)));
                        if (inAllowedItems) {
                            break;
                        }
                    }
                    return inAllowedItems;
                });
            }
        }
        if (filterQuery.has(DISABLED_KEY) && filterQuery.get(DISABLED_KEY) instanceof JSONArray) {
            JSONArray disabledItems = filterQuery.getJSONArray(DISABLED_KEY);
            if (disabledItems.length() > 0) {
                Clog.v("PrioritizedSetFilter '#{$1}' applying filters to blacklist items", new Object[] { key });
                filter = filter.filter(t -> {
                    boolean inDisallowedItems = false;
                    for (int i = 0; i < disabledItems.length(); i++) {
                        inDisallowedItems = t.getClass().getSimpleName().equals(disabledItems.getString(i));
                        inDisallowedItems = inDisallowedItems || (t.getClass().getName().equals(disabledItems.getString(i)));
                        if (inDisallowedItems) {
                            break;
                        }
                    }
                    return !inDisallowedItems;
                });
            }
        }
    }
    Set<T> initialFilteredSet = filter.collect(Collectors.toSet());
    initialFilteredSet = (Set<T>) context.getFilterService().filter("filter:" + key, initialFilteredSet);
    fullFilteredSet = new ObservableTreeSet<>(initialFilteredSet);
    return fullFilteredSet;
}
Also used : EdenUtils(com.eden.common.util.EdenUtils) JSONObject(org.json.JSONObject) Stream(java.util.stream.Stream) Prioritized(com.eden.orchid.api.registration.Prioritized) Set(java.util.Set) Clog(com.caseyjbrooks.clog.Clog) JSONElement(com.eden.common.json.JSONElement) Collectors(java.util.stream.Collectors) OrchidContext(com.eden.orchid.api.OrchidContext) JSONArray(org.json.JSONArray) JSONElement(com.eden.common.json.JSONElement) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 13 with JSONElement

use of com.eden.common.json.JSONElement in project Orchid by JavaEden.

the class ClassDocParser method getDirectSubclasses.

public JSONArray getDirectSubclasses(ClassDoc classDoc) {
    Map<String, JSONObject> relatedClasses = new HashMap<>();
    JSONArray fields = new JSONArray();
    JSONArray element = OrchidUtils.queryIndex(context, "javadoc");
    for (int i = 0; i < element.length(); i++) {
        JSONObject object = element.getJSONObject(i);
        JSONElement objectElement = new JSONElement(object);
        if (objectElement.query("data.info") != null && objectElement.query("data.info.superclass") != null) {
            String objectQualifiedName = objectElement.query("data.info.qualifiedName").getElement().toString();
            String superclassQualifiedName = objectElement.query("data.info.superclass.qualifiedName").getElement().toString();
            if (superclassQualifiedName.equals(classDoc.qualifiedName()) && !relatedClasses.containsKey(objectQualifiedName)) {
                relatedClasses.put(objectQualifiedName, object);
                fields.put(object);
            }
        }
    }
    return fields;
}
Also used : JSONObject(org.json.JSONObject) JSONElement(com.eden.common.json.JSONElement) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray)

Aggregations

JSONElement (com.eden.common.json.JSONElement)13 JSONObject (org.json.JSONObject)10 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 OrchidIndex (com.eden.orchid.api.indexing.OrchidIndex)2 File (java.io.File)2 List (java.util.List)2 Clog (com.caseyjbrooks.clog.Clog)1 EdenUtils (com.eden.common.util.EdenUtils)1 OrchidContext (com.eden.orchid.api.OrchidContext)1 Prioritized (com.eden.orchid.api.registration.Prioritized)1 JsonResource (com.eden.orchid.api.resources.resource.JsonResource)1 OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)1 Theme (com.eden.orchid.api.theme.Theme)1 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)1 OrchidReference (com.eden.orchid.api.theme.pages.OrchidReference)1 OrchidInternalIndex (com.eden.orchid.impl.indexing.OrchidInternalIndex)1 OrchidRootExternalIndex (com.eden.orchid.impl.indexing.OrchidRootExternalIndex)1 OrchidRootInternalIndex (com.eden.orchid.impl.indexing.OrchidRootInternalIndex)1