Search in sources :

Example 6 with OrchidResource

use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.

the class AdminController method renderList.

@Get(path = "/lists/:name")
public OrchidResponse renderList(OrchidRequest request, String name) {
    Clog.v("calling /admin/lists/:name");
    OrchidResource resource = resources.getResourceEntry("templates/server/admin/lists/" + name + ".twig");
    if (resource != null) {
        JSONObject data = new JSONObject();
        data.put("httpServerPort", server.get().getHttpServerPort());
        data.put("websocketPort", server.get().getWebsocketPort());
        data.put(name, getList(name));
        return new OrchidResponse(context.getTheme().compile(resource.getReference().getExtension(), resource.getContent(), data));
    }
    return new OrchidResponse("List not found");
}
Also used : JSONObject(org.json.JSONObject) OrchidResponse(com.eden.orchid.server.api.OrchidResponse) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) Get(com.eden.orchid.server.api.methods.Get)

Example 7 with OrchidResource

use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.

the class AdminController method doNothing.

@Get(path = "/")
public OrchidResponse doNothing(OrchidRequest request) {
    Clog.v("calling /admin");
    OrchidResource resource = resources.getResourceEntry("templates/server/admin/admin.twig");
    String content = "";
    if (resource != null) {
        JSONObject data = new JSONObject();
        data.put("httpServerPort", server.get().getHttpServerPort());
        data.put("websocketPort", server.get().getWebsocketPort());
        content = context.getTheme().compile(resource.getReference().getExtension(), resource.getContent(), data);
    }
    return new OrchidResponse(content);
}
Also used : JSONObject(org.json.JSONObject) OrchidResponse(com.eden.orchid.server.api.OrchidResponse) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) Get(com.eden.orchid.server.api.methods.Get)

Example 8 with OrchidResource

use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.

the class IndexFileResponse method getResponse.

public NanoHTTPD.Response getResponse(File targetFile, String targetPath) {
    String content = "";
    if (targetFile.isDirectory()) {
        File[] files = targetFile.listFiles();
        if (files != null) {
            JSONArray jsonDirs = new JSONArray();
            JSONArray jsonFiles = new JSONArray();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd-hh:mm:ss z", Locale.getDefault());
            for (File file : files) {
                JSONObject newFile = new JSONObject();
                newFile.put("url", OrchidUtils.applyBaseUrl(context, StringUtils.strip(targetPath, "/") + "/" + file.getName()));
                newFile.put("name", file.getName());
                newFile.put("size", file.length());
                newFile.put("date", formatter.format(new Date(file.lastModified())));
                if (file.isDirectory()) {
                    newFile.put("icon", iconMap.get("folder"));
                    jsonDirs.put(newFile);
                } else {
                    newFile.put("icon", iconMap.containsKey(FilenameUtils.getExtension(file.getName())) ? iconMap.get(FilenameUtils.getExtension(file.getName())) : iconMap.get("file"));
                    jsonFiles.put(newFile);
                }
            }
            JSONObject page = new JSONObject();
            page.put("title", "List of files/dirs under " + targetPath);
            page.put("path", targetPath);
            page.put("dirs", jsonDirs);
            page.put("files", jsonFiles);
            JSONObject object = new JSONObject(context.getRoot().toMap());
            object.put("page", page);
            OrchidResource resource = resources.getResourceEntry("templates/server/directoryListing.twig");
            if (resource != null) {
                content = context.getTheme().compile(resource.getReference().getExtension(), resource.getContent(), object.toString(2));
            } else {
                content = object.toString(2);
            }
        }
    }
    Clog.i("Rendering Index: #{$1}", new Object[] { targetPath });
    return NanoHTTPD.newFixedLengthResponse(content);
}
Also used : JSONObject(org.json.JSONObject) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) JSONArray(org.json.JSONArray) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 9 with OrchidResource

use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.

the class NotFound404Response method getResponse.

public NanoHTTPD.Response getResponse(String targetPath) {
    JSONObject page = new JSONObject();
    page.put("title", "404 - " + targetPath);
    page.put("path", targetPath);
    JSONObject object = new JSONObject(context.getRoot().toMap());
    object.put("page", page);
    OrchidResource resource = resources.getResourceEntry("templates/server/404.twig");
    String content = "";
    if (resource != null) {
        content = context.getTheme().compile(resource.getReference().getExtension(), resource.getContent(), object.toString(2));
    }
    Clog.i("Rendering 404: #{$1}", new Object[] { targetPath });
    return NanoHTTPD.newFixedLengthResponse(content);
}
Also used : JSONObject(org.json.JSONObject) OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource)

Example 10 with OrchidResource

use of com.eden.orchid.api.resources.resource.OrchidResource in project Orchid by JavaEden.

the class PagesGenerator method startIndexing.

@Override
public List<? extends OrchidPage> startIndexing() {
    List<OrchidResource> resourcesList = resources.getLocalResourceEntries("pages", null, true);
    List<StaticPage> pages = new ArrayList<>();
    for (OrchidResource entry : resourcesList) {
        if (!EdenUtils.isEmpty(entry.queryEmbeddedData("title"))) {
            entry.getReference().setTitle(entry.queryEmbeddedData("title").toString());
        } else {
            entry.getReference().setTitle(entry.getReference().getFileName());
        }
        if (entry.queryEmbeddedData("root") != null) {
            if (Boolean.parseBoolean(entry.queryEmbeddedData("root").toString())) {
                entry.getReference().stripFromPath("pages");
            }
        }
        entry.getReference().setUsePrettyUrl(true);
        StaticPage page = new StaticPage(entry);
        pages.add(page);
    }
    return pages;
}
Also used : OrchidResource(com.eden.orchid.api.resources.resource.OrchidResource) ArrayList(java.util.ArrayList)

Aggregations

OrchidResource (com.eden.orchid.api.resources.resource.OrchidResource)14 ArrayList (java.util.ArrayList)6 JSONObject (org.json.JSONObject)6 StringResource (com.eden.orchid.api.resources.resource.StringResource)3 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)3 OrchidResponse (com.eden.orchid.server.api.OrchidResponse)2 Get (com.eden.orchid.server.api.methods.Get)2 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 JSONElement (com.eden.common.json.JSONElement)1 OrchidIndex (com.eden.orchid.api.indexing.OrchidIndex)1 FileResource (com.eden.orchid.api.resources.resource.FileResource)1 JarResource (com.eden.orchid.api.resources.resource.JarResource)1 JsonResource (com.eden.orchid.api.resources.resource.JsonResource)1 OrchidReference (com.eden.orchid.api.theme.pages.OrchidReference)1 OrchidInternalIndex (com.eden.orchid.impl.indexing.OrchidInternalIndex)1 OrchidRootInternalIndex (com.eden.orchid.impl.indexing.OrchidRootInternalIndex)1