Package org.thymeleaf

Examples of org.thymeleaf.Arguments


        if (processingContext instanceof Arguments) {
            // Try to initialize the context variables by asking the SpEL expression
            // evaluator object (which might be a subclass of the standard one) to create
            // this variable map.
           
            final Arguments arguments = (Arguments) processingContext;
            final IStandardVariableExpressionEvaluator expressionEvaluator =
                    StandardExpressions.getVariableExpressionEvaluator(arguments.getConfiguration());

            contextVariables =
                    SpringVersionSpecificUtils.computeExpressionObjectsFromExpressionEvaluator(arguments, expressionEvaluator);

        }
View Full Code Here


                       
            /*
             *  If there are local variables at the node, add them to the ones at the
             *  Arguments object.
             */
            Arguments executionArguments =
                    (this.nodeLocalVariables != null && this.nodeLocalVariables.size() > 0?
                            arguments.addLocalVariables(this.nodeLocalVariables) : arguments);
           
            /*
             * If the Arguments object has local variables, synchronize the node-local
             * variables map.
             */
            if (executionArguments.hasLocalVariables()) {
                unsafeSetNodeLocalVariables(executionArguments.getLocalVariables());
            }
           
            /*
             * Perform the actual processing
             */
            if (!isDetached() && this.processors != null && this.processors.size() > 0) {
               
                final IdentityCounter<ProcessorAndContext> alreadyExecuted =
                        new IdentityCounter<ProcessorAndContext>(this.processors.size());
                Arguments processingArguments = executionArguments;

                while (!isDetached() && processingArguments != null) {
                   
                    // This way of executing processors allows processors to perform updates
                    // that might change which processors should be applied (for example, by
View Full Code Here

            for (final ProcessorAndContext processor : node.processors) {
               
                if (!alreadyExecuted.isAlreadyCounted(processor)) {
                   
                    Arguments executionArguments = arguments;

                    // Obtain a "hash snapshot" of the node local variables map before
                    // the processor is executed
                    final int nodeLocalVariablesHashBefore =
                            (node.nodeLocalVariables == null? -1 : node.nodeLocalVariables.contentsHash());
                   
                    // Execute processor
                    final ProcessorResult processorResult =
                            processor.getProcessor().process(executionArguments, processor.getContext(), node);

                    // Obtain a "hash snapshot" of the node local variables map after
                    // the processor has been executed
                    final int nodeLocalVariablesHashAfter =
                            (node.nodeLocalVariables == null? -1 : node.nodeLocalVariables.contentsHash());

                    // Check whether the processor just modified the node variables map. This
                    // is done BEFORE processorResult.computeNewArguments(...) so that variables
                    // set from the ProcessorResult have higher priority (i.e. can override) variables
                    // set directly into the nodeLocalVariables map.
                    if (nodeLocalVariablesHashBefore != nodeLocalVariablesHashAfter) {
                        executionArguments = executionArguments.addLocalVariables(node.nodeLocalVariables);
                    }
                   
                    // The execution arguments need to be updated as instructed by the processor
                    // (for example, for adding local variables)
                    executionArguments = processorResult.computeNewArguments(executionArguments);

                    // Using only the Arguments object for keeping track of whether the text/comment nodes had to be
                    // computed or not is not a good option because such information dissapears if the node
                    // setting these flags dissapears afterwards (because of a "remove", for instance).
                    if (processorResult.isProcessTextNodesSet()) {
                        node.setProcessTextNodes(processorResult.getProcessTextNodes());
                    }
                    if (processorResult.isProcessCommentNodesSet()) {
                        node.setProcessCommentNodes(processorResult.getProcessCommentNodes());
                    }

                    // If we have added local variables, we should update the node's map for these variables in
                    // order to keep them synchronized
                    if ((processorResult.hasLocalVariables() || processorResult.isSelectionTargetSet()) && executionArguments.hasLocalVariables()) {
                        node.unsafeSetNodeLocalVariables(executionArguments.getLocalVariables());
                    }
                   
                    // Make sure this specific processor instance is not executed again
                    alreadyExecuted.count(processor);
                   
View Full Code Here

       
        final Document document = new Document(templateName);
        document.addChild(node);
       
       
        final Arguments arguments =
                new Arguments(new TemplateEngine(),
                        templateProcessingParameters, templateResolution,
                        templateRepository, document);

        return getOutputFor(arguments, node, templateWriter);
           
View Full Code Here

            variables.put(SELECTION_VARIABLE_NAME, evaluationRoot);
        }

        if (processingContext instanceof Arguments) {
           
            final Arguments arguments = (Arguments) processingContext;

            final Messages messages = new Messages(arguments);
            variables.put(MESSAGES_EVALUATION_VARIABLE_NAME, messages);

            final Ids ids = new Ids(arguments);
            variables.put(IDS_EVALUATION_VARIABLE_NAME, ids);

            final Conversions conversions = new Conversions(arguments.getConfiguration(), arguments);
            variables.put(CONVERSIONS_EVALUATION_VARIABLE_NAME, conversions);

        }
       
        return variables;
View Full Code Here

        if (assignations == null) {
            throw new TemplateProcessingException(
                    "Could not parse value as attribute assignations: \"" + attributeValue + "\"");
        }

        Arguments assignationExecutionArguments = arguments;

        final Map<String,Object> newLocalVariables = new HashMap<String,Object>(assignations.size() + 1, 1.0f);
        for (final Assignation assignation : assignations) {
           
            final IStandardExpression leftExpr = assignation.getLeft();
            final Object leftValue = leftExpr.execute(configuration, assignationExecutionArguments);

            final IStandardExpression rightExpr = assignation.getRight();
            final Object rightValue = rightExpr.execute(configuration, assignationExecutionArguments);

            final String newVariableName = (leftValue == null? null : leftValue.toString());
            if (StringUtils.isEmptyOrWhitespace(newVariableName)) {
                throw new TemplateProcessingException(
                        "Variable name expression evaluated as null or empty: \"" + leftExpr + "\"");
            }

            // Creating a new Arguments object allows the reuse of variables in, for example, th:with expressions.
            assignationExecutionArguments =
                    assignationExecutionArguments.addLocalVariables(Collections.singletonMap(newVariableName, rightValue));

            newLocalVariables.put(newVariableName, rightValue);
           
        }
       
View Full Code Here

                    "can only be evaluated in a template-processing environment (as a part of an in-template expression) " +
                    "where evaluation context is an " + Arguments.class.getClass() + " instance instead of an instance of " +
                    processingContext.getClass().getName());
        }
       
        final Arguments arguments = (Arguments) processingContext;

        final IStandardExpression baseExpression = expression.getBase();
        Object messageKey = baseExpression.execute(configuration, arguments, expContext);
        messageKey = LiteralValue.unwrap(messageKey);
        if (messageKey != null && !(messageKey instanceof String)) {
View Full Code Here

    Configuration configuration = arguments.getConfiguration();
    final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(configuration);

    final Map<String, Object> newLocalVariables = new HashMap<String, Object>(1, 1.0f);

    Arguments withExecutionArguments = arguments;

    for (Attribute attribute : attributeMap.values()) {
      if (dialectPrefix.equals(Attribute.getPrefixFromAttributeName(attribute.getNormalizedName()))) {
        final String newVariableName = Attribute.getUnprefixedAttributeName(attribute.getOriginalName());
        final IStandardExpression expression = expressionParser.parseExpression(arguments.getConfiguration(),
            withExecutionArguments, attribute.getValue());
        final Object newVariableValue = expression.execute(configuration, withExecutionArguments);
        withExecutionArguments = withExecutionArguments.addLocalVariables(Collections.singletonMap(newVariableName,
            newVariableValue));
        newLocalVariables.put(newVariableName, newVariableValue);
        element.removeAttribute(attribute.getNormalizedName());
      }
    }
View Full Code Here

TOP

Related Classes of org.thymeleaf.Arguments

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.