Package org.thymeleaf.context

Examples of org.thymeleaf.context.IContext


    private IContext toIContext(final Map<String, Object> context) {

        final VariablesMap<String, Object> variables = new VariablesMap<>(context);

        return new IContext() {
            @Override
            public VariablesMap<String, Object> getVariables() {
                return variables;
            }
View Full Code Here


        try {
           
            Validate.notNull(templateName, "Template name cannot be null");
            Validate.notNull(processingContext, "Processing context cannot be null");
           
            final IContext context = processingContext.getContext();
           
            final long startNanos = System.nanoTime();

            if (logger.isDebugEnabled()) {
                logger.debug("[THYMELEAF][{}] STARTING PROCESS OF TEMPLATE \"{}\" WITH LOCALE {}", new Object[] {TemplateEngine.threadIndex(), templateName, context.getLocale()});
            }
           
            // Add context execution info
            context.addContextExecutionInfo(templateName);
           
            final TemplateProcessingParameters templateProcessingParameters =
                new TemplateProcessingParameters(this.configuration, templateName, processingContext);
           
            process(templateProcessingParameters, fragmentSpec, writer);
           
            final long endNanos = System.nanoTime();
           
            if (logger.isDebugEnabled()) {
                logger.debug("[THYMELEAF][{}] FINISHED PROCESS AND OUTPUT OF TEMPLATE \"{}\" WITH LOCALE {}", new Object[] {TemplateEngine.threadIndex(), templateName, context.getLocale()});
            }
           
            if (timerLogger.isDebugEnabled()) {
                final BigDecimal elapsed = BigDecimal.valueOf(endNanos - startNanos);
                final BigDecimal elapsedMs = elapsed.divide(BigDecimal.valueOf(NANOS_IN_SECOND), RoundingMode.HALF_UP);
                timerLogger.debug(
                        "[THYMELEAF][{}][{}][{}][{}][{}] TEMPLATE \"{}\" WITH LOCALE {} PROCESSED IN {} nanoseconds (approx. {}ms)",
                        new Object[] {TemplateEngine.threadIndex(),
                                templateName, context.getLocale(), elapsed, elapsedMs,
                                templateName, context.getLocale(), elapsed, elapsedMs});
            }
           
        } catch (final TemplateOutputException e) {
           
            logger.error("[THYMELEAF][{}] Exception processing template \"{}\": {}", new Object[] {TemplateEngine.threadIndex(), templateName, e.getMessage()});
View Full Code Here

     */
    public static Map<String,Object> computeEvaluationObjects(
            final IProcessingContext processingContext) {


        final IContext context = processingContext.getContext();

        final Map<String,Object> variables = new HashMap<String, Object>(30);

        variables.putAll(computeBaseObjectsByLocale(context.getLocale()));

        variables.put(CONTEXT_VARIABLE_NAME, context);
        variables.put(LOCALE_EVALUATION_VARIABLE_NAME, context.getLocale());

        if (context instanceof IWebContext) {
            final IWebContext webContext = (IWebContext) context;
            // This gives access to the HttpServletRequest and HttpSession objects, if they exist
            variables.put(
View Full Code Here

    public InputStream getResourceAsStream(final TemplateProcessingParameters templateProcessingParameters, final String resourceName) {
       
        Validate.notNull(templateProcessingParameters, "Template Processing Parameters cannot be null");
        Validate.notNull(resourceName, "Resource name cannot be null");
       
        final IContext context = templateProcessingParameters.getContext();
        if (!(context instanceof IWebContext)) {
            throw new TemplateProcessingException(
                    "Resource resolution by ServletContext with " +
                    this.getClass().getName() + " can only be performed " +
                    "when context implements " + IWebContext.class.getName() +
                    " [current context: " + context.getClass().getName() + "]");
        }
       
        final ServletContext servletContext =
            ((IWebContext)context).getServletContext();
        if (servletContext == null) {
View Full Code Here

    public InputStream getResourceAsStream(final TemplateProcessingParameters templateProcessingParameters, final String resourceName) {

        Validate.notNull(templateProcessingParameters, "Template Processing Parameters cannot be null");
        Validate.notNull(resourceName, "Resource name cannot be null");

        final IContext context = templateProcessingParameters.getContext();
        if (!(context instanceof IWebContext)) {
            throw new TemplateProcessingException(
                    "Resource resolution by ServletContext with " +
                            this.getClass().getName() + " can only be performed " +
                            "when context implements " + IWebContext.class.getName() +
                            " [current context: " + context.getClass().getName() + "]");
        }

        try {
            String repoPath;
            if(resourceName.startsWith(WEB_INF_CLASSES)){
View Full Code Here

TOP

Related Classes of org.thymeleaf.context.IContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.