public Template getTemplate(AbstractTheme theme, String template) throws TemplateDoesNotExistException { logger.debug("[Finding] " + template + " for " + theme.getName()); try { return _getTemplate(theme, template); } catch (TemplateDoesNotExistException e) { /* If it goes wrong, try the default theme */ return _getTemplate(SeventyEight.getInstance().getDefaultTheme(), template); } }
private void executeThing(Request request, Response response, Item item, String urlName) throws ActionHandlerException { logger.debug("EXECUTE: " + item + ", " + urlName); /* First try to find a view, if not a POST */ try { logger.debug("Item: " + item + " -> " + urlName); executeMethod(item, request, response, urlName); return; } catch (Exception e) { e.printStackTrace(); logger.debug(item + " does not not have " + urlName + ", " + e.getMessage()); } logger.debug("TRYING VIEW FILE"); if (!request.isRequestPost()) { try { request .getContext() .put( "content", SeventyEight.getInstance() .getTemplateManager() .getRenderer(request) .renderObject(item, urlName + ".vm")); response .getWriter() .print( SeventyEight.getInstance() .getTemplateManager() .getRenderer(request) .render(request.getTemplate())); return; } catch (Exception e) { logger.debug("Unable to view " + urlName + " for " + item + ": " + e.getMessage()); throw new ActionHandlerException(e); } } }
public String render(String template) throws TemplateDoesNotExistException { /* Resolve template */ Template t = null; try { t = getTemplate(theme, template); } catch (TemplateDoesNotExistException e) { /* If it goes wrong, try the default theme */ t = getTemplate(SeventyEight.getInstance().getDefaultTheme(), template); } catch (Exception e) { logger.error(e); } return render(t); }
public String render(Template template) { StringWriter writer = new StringWriter(); logger.debug("[Rendering] " + template.getName()); context.put("core", SeventyEight.getInstance()); context.put("theme", theme); // context.put( "url" ); /* I18N */ context.put("locale", locale); template.merge(context, writer); return writer.toString(); }