use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class ModularListOptionExtractor method getDefaultValue.
@Override
public ModularList getDefaultValue(Field field) {
OrchidContext context = contextProvider.get();
ModularList modularList = (ModularList) context.resolve(field.getType());
modularList.initialize(context, new ArrayList<>());
return modularList;
}
use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class ModularListOptionExtractor method getOption.
@Override
public ModularList getOption(Field field, Object sourceObject, String key) {
OrchidContext context = contextProvider.get();
final String typeKey;
final String valueKey;
if (field.isAnnotationPresent(ImpliedKey.class)) {
ImpliedKey impliedKey = field.getAnnotation(ImpliedKey.class);
typeKey = impliedKey.typeKey();
valueKey = impliedKey.valueKey();
} else {
typeKey = null;
valueKey = null;
}
Iterable iterable = iterableConverter.convert(field.getType(), sourceObject, typeKey, valueKey).second;
List<Map<String, Object>> jsonArray = new ArrayList<>();
for (Object o : iterable) {
Map<String, Object> map = (Map<String, Object>) mapConverter.convert(field.getType(), o).second;
jsonArray.add(map);
}
if (jsonArray.size() > 0) {
ModularList modularList = (ModularList) contextProvider.get().resolve(field.getType());
modularList.initialize(context, jsonArray);
return modularList;
}
return null;
}
use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class Orchid method start.
public boolean start(List<Module> modules) {
OrchidContext context = null;
try {
String moduleLog = "\n--------------------";
for (Module module : modules) {
if (!module.getClass().getName().startsWith("com.eden.orchid.OrchidModule")) {
moduleLog += "\n * " + module.getClass().getName();
}
}
moduleLog += "\n";
Clog.tag("Using the following modules").log(moduleLog);
Injector injector = Guice.createInjector(modules);
String flagLog = "";
flagLog += "\n--------------------\n";
flagLog += OrchidFlags.getInstance().printFlags();
flagLog += "\n";
Clog.tag("Flag values").log(flagLog);
context = injector.getInstance(OrchidContext.class);
try {
OrchidSecurityManager manager = injector.getInstance(OrchidSecurityManager.class);
System.setSecurityManager(manager);
} catch (Exception e) {
}
Clog.i("Running Orchid version {}, site version {} in {} environment", context.getOrchidVersion(), context.getVersion(), context.getEnvironment());
context.start();
context.finish();
return true;
} catch (Exception e) {
Clog.e("Something went wrong running Orchid", e);
e.printStackTrace();
if (context != null) {
context.broadcast(Orchid.Lifecycle.Shutdown.fire(context, this));
}
return false;
}
}
use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class NonDynamicTabbedTagParser method render.
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws IOException {
OrchidContext orchidContext = contextProvider.get();
// create a new tag
TemplateTag freshTag = orchidContext.resolve(tagClass);
// evaluate its own params and populate the main Tag class with them
Map<String, Object> evaluatedParamExpressionMap = evaluateParams(paramExpressionMap, self, context);
Object pageVar = context.getVariable("page");
final OrchidPage actualPage;
if (pageVar instanceof OrchidPage) {
actualPage = (OrchidPage) pageVar;
} else {
actualPage = null;
}
freshTag.extractOptions(orchidContext, evaluatedParamExpressionMap);
// populate the content of each tab
for (Map.Entry<String, Expression<?>> tagBodyExpression : tagBodyExpressions.entrySet()) {
// get the tab body content
String key = tagBodyExpression.getKey();
String bodyContent = StringUtils.toString(tagBodyExpression.getValue().evaluate(self, context)).trim();
// Get a new Tab instance, evaluate that tab's options, and then populate the Tab instance with them
TemplateTag.Tab tab = freshTag.getNewTab(key, bodyContent);
Map<String, Object> tabParams = evaluateParams(tagBodyParams.get(key), self, context);
tab.extractOptions(orchidContext, tabParams);
// add the tab to the Tag
freshTag.setContent(key, tab);
}
freshTag.onRender(orchidContext, actualPage);
if (freshTag.rendersContent()) {
writer.append(freshTag.renderContent(orchidContext, actualPage));
}
}
use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class DynamicTabbedTagParser method render.
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws IOException {
OrchidContext orchidContext = contextProvider.get();
// create a new tag
TemplateTag freshTag = orchidContext.resolve(tagClass);
context.getScopeChain().pushScope(MapsKt.mapOf(new Pair<>("__parentTabbedTag", freshTag)));
// evaluate its own params and populate the main Tag class with them
Map<String, Object> evaluatedParamExpressionMap = evaluateParams(paramExpressionMap, self, context);
Object pageVar = context.getVariable("page");
final OrchidPage actualPage;
if (pageVar instanceof OrchidPage) {
actualPage = (OrchidPage) pageVar;
} else {
actualPage = null;
}
freshTag.extractOptions(orchidContext, evaluatedParamExpressionMap);
String bodyContent = StringUtils.toString(tagBodyExpression.evaluate(self, context)).trim();
TemplateTag.Tab tab = new TemplateTag.SimpleTab(null, null, bodyContent);
freshTag.onRender(orchidContext, actualPage);
if (freshTag.rendersContent()) {
writer.append(freshTag.renderContent(orchidContext, actualPage));
}
context.getScopeChain().popScope();
}
Aggregations