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");
}
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);
}
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);
}
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);
}
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;
}
Aggregations