Search in sources :

Example 1 with OrchidExternalIndex

use of com.eden.orchid.impl.indexing.OrchidExternalIndex in project Orchid by JavaEden.

the class OrchidIndex method fromJSON.

public static OrchidIndex fromJSON(OrchidContext context, JSONObject source) {
    OrchidExternalIndex index = new OrchidExternalIndex(source.getString("ownKey"));
    if (source.has("ownPages")) {
        JSONArray ownPagesJson = source.getJSONArray("ownPages");
        List<OrchidPage> ownPages = new ArrayList<>();
        for (int i = 0; i < ownPagesJson.length(); i++) {
            OrchidPage externalPage = OrchidPage.fromJSON(context, ownPagesJson.getJSONObject(i));
            ownPages.add(externalPage);
        }
        index.ownPages = ownPages;
    }
    if (source.has("childrenPages")) {
        JSONObject childrenPagesJson = source.getJSONObject("childrenPages");
        Map<String, OrchidIndex> childrenPages = new HashMap<>();
        for (String key : childrenPagesJson.keySet()) {
            OrchidIndex childIndex = OrchidIndex.fromJSON(context, childrenPagesJson.getJSONObject(key));
            childrenPages.put(key, childIndex);
        }
        index.childrenPages = childrenPages;
    }
    return index;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) OrchidExternalIndex(com.eden.orchid.impl.indexing.OrchidExternalIndex)

Aggregations

OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)1 OrchidExternalIndex (com.eden.orchid.impl.indexing.OrchidExternalIndex)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1