Search in sources :

Example 1 with JSONElement

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

the class IndexGenerator method generateIndexFiles.

private void generateIndexFiles() {
    OrchidRootInternalIndex internalIndex = context.getInternalIndex();
    Map<String, OrchidInternalIndex> mappedIndex = internalIndex.getAllIndexedPages();
    OrchidIndex indices = new OrchidInternalIndex("indices");
    // Render an page for each generator's individual index
    mappedIndex.keySet().forEach(key -> {
        OrchidResource resource = new JsonResource(new JSONElement(mappedIndex.get(key).toJSON()), new OrchidReference(context, "meta/" + key + ".index.json"));
        OrchidPage page = new OrchidPage(resource);
        page.renderRaw();
        indices.addToIndex(indices.getOwnKey() + "/" + page.getReference().getPath(), page);
    });
    // Render full composite index page
    OrchidResource compositeIndexResource = new JsonResource(new JSONElement(internalIndex.toJSON()), new OrchidReference(context, "meta/index.json"));
    OrchidPage compositeIndexPage = new OrchidPage(compositeIndexResource);
    compositeIndexPage.renderRaw();
    indices.addToIndex(indices.getOwnKey() + "/" + compositeIndexPage.getReference().getPath(), compositeIndexPage);
    // Render an index of all indices, so individual index pages can be found
    OrchidResource indicesIndexResource = new JsonResource(new JSONElement(indices.toJSON()), new OrchidReference(context, "meta/indices.json"));
    OrchidPage indicesPage = new OrchidPage(indicesIndexResource);
    indicesPage.renderRaw();
}
Also used : OrchidRootInternalIndex(com.eden.orchid.impl.indexing.OrchidRootInternalIndex) OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) OrchidReference(com.eden.orchid.api.theme.pages.OrchidReference) OrchidInternalIndex(com.eden.orchid.impl.indexing.OrchidInternalIndex) JSONElement(com.eden.common.json.JSONElement) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) JsonResource(com.eden.orchid.api.resources.resource.JsonResource) OrchidIndex(com.eden.orchid.api.indexing.OrchidIndex)

Example 2 with JSONElement

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

the class DisabledGeneratorsOption method parseOption.

@Override
public JSONElement parseOption(String[] options) {
    String[] classNames;
    if (options[1].contains(File.pathSeparator)) {
        classNames = options[1].split(File.pathSeparator);
    } else {
        classNames = new String[] { options[1] };
    }
    JSONArray classNamesArray = new JSONArray();
    for (String className : classNames) {
        classNamesArray.put(className);
    }
    if (classNamesArray.length() > 0) {
        return new JSONElement(classNamesArray);
    } else {
        return null;
    }
}
Also used : JSONElement(com.eden.common.json.JSONElement) JSONArray(org.json.JSONArray)

Example 3 with JSONElement

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

the class ThemeOption method parseOption.

@Override
public JSONElement parseOption(String[] options) {
    try {
        Class<? extends Theme> themeClass = (Class<? extends Theme>) Class.forName(options[1]);
        Theme theme = Orchid.getInstance().getInjector().getInstance(themeClass);
        if (theme != null) {
            Orchid.getInstance().getContext().setTheme(theme);
            return new JSONElement(options[1]);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    Clog.e("The Theme class #{$1} could not be found. Please make sure it has been registered properly.", new Object[] { options[1] });
    return new JSONElement(options[1]);
}
Also used : JSONElement(com.eden.common.json.JSONElement) Theme(com.eden.orchid.api.theme.Theme)

Example 4 with JSONElement

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

the class QueryFilter method apply.

public Object apply(Object value, Object... params) {
    if (params != null && params[0] != null) {
        String pointer = params[0].toString();
        if (value instanceof Map) {
            JSONObject mapObject = new JSONObject((Map<String, ?>) value);
            JSONElement el = new JSONElement(mapObject);
            el = el.query(pointer);
            if (el != null) {
                if (el.getElement() instanceof JSONObject) {
                    return ((JSONObject) el.getElement()).toMap();
                } else if (el.getElement() instanceof JSONArray) {
                    return ((JSONArray) el.getElement()).toList();
                }
            }
        } else if (value instanceof Collection) {
            JSONArray collectionObject = new JSONArray(value);
            JSONElement el = new JSONElement(collectionObject).query(pointer);
            if (el != null) {
                if (el.getElement() instanceof JSONObject) {
                    return ((JSONObject) el.getElement()).toMap();
                } else if (el.getElement() instanceof JSONArray) {
                    return ((JSONArray) el.getElement()).toList();
                }
            }
        }
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) JSONElement(com.eden.common.json.JSONElement) JSONArray(org.json.JSONArray) Collection(java.util.Collection) Map(java.util.Map)

Example 5 with JSONElement

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

the class OrchidGenerators method buildExternalIndex.

private void buildExternalIndex() {
    this.externalIndex = new OrchidRootExternalIndex();
    JSONElement externalIndexReferences = context.query("options.data.externalIndex");
    if (OrchidUtils.elementIsArray(externalIndexReferences)) {
        JSONArray externalIndex = (JSONArray) externalIndexReferences.getElement();
        for (int i = 0; i < externalIndex.length(); i++) {
            JSONObject indexJson = this.orchidResources.loadAdditionalFile(externalIndex.getString(i));
            if (indexJson != null) {
                OrchidIndex index = OrchidIndex.fromJSON(context, indexJson);
                this.externalIndex.addChildIndex(index);
            }
        }
    }
}
Also used : OrchidRootExternalIndex(com.eden.orchid.impl.indexing.OrchidRootExternalIndex) JSONElement(com.eden.common.json.JSONElement) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) OrchidIndex(com.eden.orchid.api.indexing.OrchidIndex)

Aggregations

JSONElement (com.eden.common.json.JSONElement)15 JSONObject (org.json.JSONObject)11 JSONArray (org.json.JSONArray)7 OrchidIndex (com.eden.orchid.api.indexing.OrchidIndex)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 OrchidContext (com.eden.orchid.api.OrchidContext)2 File (java.io.File)2 List (java.util.List)2 Clog (com.caseyjbrooks.clog.Clog)1 EdenUtils (com.eden.common.util.EdenUtils)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 AssetManager (com.eden.orchid.api.theme.assets.AssetManager)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