Package org.thymeleaf.exceptions

Examples of org.thymeleaf.exceptions.TemplateProcessingException


       
        Object leftValue = expression.getLeft().execute(configuration, processingContext, expContext);
        Object rightValue = expression.getRight().execute(configuration, processingContext, expContext);

        if (leftValue == null || rightValue == null) {
            throw new TemplateProcessingException(
                    "Cannot execute LESS THAN comparison: operands are \"" + LiteralValue.unwrap(leftValue) + "\" and \"" + LiteralValue.unwrap(rightValue) + "\"");
        }

        leftValue = LiteralValue.unwrap(leftValue);
        rightValue = LiteralValue.unwrap(rightValue);

        Boolean result = null;

        final BigDecimal leftNumberValue = EvaluationUtil.evaluateAsNumber(leftValue);
        final BigDecimal rightNumberValue = EvaluationUtil.evaluateAsNumber(rightValue);
       
        if (leftNumberValue != null && rightNumberValue != null) {
            result = Boolean.valueOf(leftNumberValue.compareTo(rightNumberValue) == -1);
        } else {
            if (leftValue != null && rightValue != null &&
                    leftValue.getClass().equals(rightValue.getClass()) &&
                    Comparable.class.isAssignableFrom(leftValue.getClass())) {
                result = Boolean.valueOf(((Comparable<Object>)leftValue).compareTo(rightValue) < 0);
            } else {
                throw new TemplateProcessingException(
                        "Cannot execute LESS THAN from Expression \"" +
                        expression.getStringRepresentation() + "\". Left is \"" +
                        leftValue + "\", right is \"" + rightValue + "\"");
            }
        }
View Full Code Here


        final IStandardExpression templateNameExpression = fragmentSelection.getTemplateName();
        final String templateName;
        if (templateNameExpression != null) {
            final Object templateNameObject = templateNameExpression.execute(configuration, processingContext);
            if (templateNameObject == null) {
                throw new TemplateProcessingException(
                        "Evaluation of template name from spec \"" + standardFragmentSpec + "\" " +
                                "returned null.");
            }
            final String evaluatedTemplateName = templateNameObject.toString();
            if (TEMPLATE_NAME_CURRENT_TEMPLATE.equals(evaluatedTemplateName)) {
                // Template name is "this" and therefore we are including a fragment from the same template.
                templateName = null;
            } else {
                templateName = templateNameObject.toString();
            }
        } else {
            // If template name expression is null, we will execute the fragment on the "current" template
            templateName = null;
        }


        // Resolve fragment parameters, if specified (null if not)
        final Map<String,Object> fragmentParameters =
                resolveFragmentParameters(configuration,processingContext,fragmentSelection.getParameters());

        if (fragmentSelection.hasFragmentSelector()) {

            final Object fragmentSelectorObject =
                    fragmentSelection.getFragmentSelector().execute(configuration, processingContext);
            if (fragmentSelectorObject == null) {
                throw new TemplateProcessingException(
                        "Evaluation of fragment selector from spec \"" + standardFragmentSpec + "\" " +
                        "returned null.");
            }

            String fragmentSelector = fragmentSelectorObject.toString();
View Full Code Here

        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) {
            throw new TemplateProcessingException("Thymeleaf context returned a null ServletContext");
        }
       
        return servletContext.getResourceAsStream(resourceName);
       
    }
View Full Code Here

        }
        try {
            return URLEncoder.encode(queryParam, "UTF-8");
        } catch (final UnsupportedEncodingException e) {
            // This should never happen as 'UTF-8' will always exist.
            throw new TemplateProcessingException("Exception while processing URL encoding", e);
        }
    }
View Full Code Here

                final byte[] charAsBytes;
                try {
                    charAsBytes = new String(new char[] {c}).getBytes("UTF-8");
                } catch (final UnsupportedEncodingException e) {
                    // This should never happen as 'UTF-8' will always exist.
                    throw new TemplateProcessingException("Exception while processing URL encoding", e);
                }
                for (final byte b : charAsBytes) {
                    strBuilder.append('%');
                    final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
                    final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
View Full Code Here

            if (leftExpr == null || !((Boolean)leftAllowedMethod.invoke(null,leftExpr)).booleanValue()) {
                return null;
            }
        } catch (final IllegalAccessException e) {
            // Should never happen, would be a programming error
            throw new TemplateProcessingException("Error invoking operand validation in binary operation", e);
        } catch (final InvocationTargetException e) {
            // Should never happen, would be a programming error
            throw new TemplateProcessingException("Error invoking operand validation in binary operation", e);
        }

        final Expression rightExpr = ExpressionParsingUtil.parseAndCompose(state, rightStr);
        try {
            if (rightExpr == null || !((Boolean)rightAllowedMethod.invoke(null,rightExpr)).booleanValue()) {
                return null;
            }
        } catch (final IllegalAccessException e) {
            // Should never happen, would be a programming error
            throw new TemplateProcessingException("Error invoking operand validation in binary operation", e);
        } catch (final InvocationTargetException e) {
            // Should never happen, would be a programming error
            throw new TemplateProcessingException("Error invoking operand validation in binary operation", e);
        }

        try {

            final BinaryOperationExpression operationExpression =
                operationClass.getDeclaredConstructor(IStandardExpression.class, IStandardExpression.class).
                            newInstance(leftExpr, rightExpr);
            state.setNode(nodeIndex, operationExpression);
           
        } catch (final TemplateProcessingException e) {
            throw e;
        } catch (final Exception e) {
            throw new TemplateProcessingException(
                    "Error during creation of Binary Operation expression for operator: \"" + operator + "\"", e);
        }

        return state;
       
View Full Code Here

        final FragmentSignature fragmentSignature =
                FragmentSignatureUtils.internalParseFragmentSignature(input.trim());

        if (fragmentSignature == null) {
            throw new TemplateProcessingException("Could not parse as fragment signature: \"" + input + "\"");
        }

        if (configuration != null) {
            ExpressionCache.putFragmentSignatureIntoCache(configuration, input, fragmentSignature);
        }
View Full Code Here

        if (specifiedParameters == null || specifiedParameters.size() == 0) {

            if (fragmentSignature.hasParameters()) {
                // Fragment signature requires parameters, but we haven't specified them!
                throw new TemplateProcessingException(
                        "Cannot resolve fragment. Signature \"" + fragmentSignature.getStringRepresentation() "\" " +
                                "declares parameters, but fragment selection did not specify any parameters.");
            }

            return null;

        }

        final boolean parametersAreSynthetic =
                FragmentSelectionUtils.parameterNamesAreSynthetic(specifiedParameters.keySet());

        if (parametersAreSynthetic && !fragmentSignature.hasParameters()) {
            throw new TemplateProcessingException(
                    "Cannot resolve fragment. Signature \"" + fragmentSignature.getStringRepresentation() "\" " +
                            "declares no parameters, but fragment selection did specify parameters in a synthetic manner " +
                            "(without names), which is not correct due to the fact parameters cannot be assigned names " +
                            "unless signature specifies these names.");
        }

        if (parametersAreSynthetic) {
            // No need to match parameter names, just apply the ones from the signature

            final List<String> signatureParameterNames = fragmentSignature.getParameterNames();

            if (signatureParameterNames.size() != specifiedParameters.size()) {
                throw new TemplateProcessingException(
                        "Cannot resolve fragment. Signature \"" + fragmentSignature.getStringRepresentation() "\" " +
                                "declares " + signatureParameterNames.size() + " parameters, but fragment selection specifies " +
                                specifiedParameters.size() + " parameters. Fragment selection does not correctly match.");
            }

            final Map<String,Object> processedParameters = new HashMap<String, Object>(signatureParameterNames.size() + 1, 1.0f);
            int index = 0;
            for (final String parameterName : signatureParameterNames) {
                final String syntheticParameterName =
                        FragmentSelectionUtils.getSyntheticParameterNameForIndex(index++);
                final Object parameterValue = specifiedParameters.get(syntheticParameterName);
                processedParameters.put(parameterName, parameterValue);
            }

            return processedParameters;

        }

        if (!fragmentSignature.hasParameters()) {
            // Parameters in fragment selection are not synthetic, and fragment signature has no parameters,
            // so we just use the "specified parameters".
            return specifiedParameters;
        }

        // Parameters are not synthetic and signature does specify parameters, so their names should match (all
        // the parameters specified at the fragment signature should be specified at the fragment selection,
        // though fragment selection can specify more parameters, not present at the signature.

        final List<String> parameterNames = fragmentSignature.getParameterNames();
        for (final String parameterName : parameterNames) {
            if (!specifiedParameters.containsKey(parameterName)) {
                throw new TemplateProcessingException(
                        "Cannot resolve fragment. Signature \"" + fragmentSignature.getStringRepresentation() "\" " +
                                "declares parameter \"" + parameterName + "\", which is not specified at the fragment " +
                                "selection.");
            }
        }
View Full Code Here

            if (entry.getPublicID().matches(publicID) && entry.getSystemID().matches(systemID)) {
                return entry.createInputSource();
            }
        }
       
        throw new TemplateProcessingException(
                "Unsupported entity requested with PUBLICID \"" + publicID + "\" and " +
            "SYSTEMID \"" + systemID + "\". Make sure a corresponding " +
        IDocTypeResolutionEntry.class.getName() + " implementation is provided " +
        "by you dialect");
    }
View Full Code Here

        final FragmentSelection fragmentSelection =
                FragmentSelectionUtils.internalParseFragmentSelection(preprocessedInput.trim());

        if (fragmentSelection == null) {
            throw new TemplateProcessingException("Could not parse as fragment selection: \"" + input + "\"");
        }

        if (configuration != null) {
            ExpressionCache.putFragmentSelectionIntoCache(configuration, preprocessedInput, fragmentSelection);
        }
View Full Code Here

TOP

Related Classes of org.thymeleaf.exceptions.TemplateProcessingException

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.