Package org.thymeleaf.exceptions

Examples of org.thymeleaf.exceptions.ConfigurationException


       
        /*
         * Check the application context has been set.
         */
        if (this.messageSource == null) {
            throw new ConfigurationException(
                    "Cannot initialize " + SpringMessageResolver.class.getSimpleName() +
                    ": MessageSource has not been set. Either define this object as " +
                    "a Spring bean (which will automatically set the MessageSource) or, " +
                    "if you instance it directly, set the MessageSource manually using its "+
                    "corresponding setter method.");
View Full Code Here


            if (dialect instanceof SpringStandardDialect) {
                initializeSpringSpecific();
                return;
            }
        }
        throw new ConfigurationException(
                "When using " + SpringTemplateEngine.class.getSimpleName() +
                ", at least one of the configured dialects must be or extend " +
                SpringStandardDialect.class.getName() + ".");
       
    }
View Full Code Here

     *
     * @param resourceResolver the new resource resolver
     */
    @Override
    public void setResourceResolver(final IResourceResolver resourceResolver) {
        throw new ConfigurationException(
                "Cannot set a resource resolver on " + this.getClass().getName() + ". If " +
                "you want to set your own resource resolver, use " + TemplateResolver.class.getName() +
                "instead");
    }
View Full Code Here

    final ITemplateModeHandler templateModeHandler = arguments.getConfiguration().getTemplateModeHandler(templateMode);
    final ITemplateWriter templateWriter = templateModeHandler.getTemplateWriter();

    if (templateWriter == null) {
      throw new ConfigurationException("No template writer defined for template mode \"" + templateMode + "\"");
    } else if (!AbstractGeneralTemplateWriter.class.isAssignableFrom(templateWriter.getClass())) {
      throw new ConfigurationException("The template writer defined for template mode \"" + templateMode
          + "\" is not an AbstractGeneralTemplateWriter");
    }

    StringWriter writer = new StringWriter();
    try {
View Full Code Here

    if (thymeleaf4Present) {
      applicationContext = getSpringApplicationContextForThymeleaf4(context);
    } else if (thymeleaf3Present) {
      applicationContext = getSpringApplicationContextForThymeleaf3(context);
    } else {
      throw new ConfigurationException("Neither Thymeleaf 3 SpringWebContext nor Thymeleaf 4 SpringWebContext is in "
          + "the application classpath.");
    }
    ConnectionRepository connectionRepository = applicationContext.getBean(ConnectionRepository.class);
    return connectionRepository;
  }
View Full Code Here

    return connectionRepository;
  }

  private ApplicationContext getSpringApplicationContextForThymeleaf3(final IContext context) {
    if (!(context instanceof org.thymeleaf.spring3.context.SpringWebContext)) {
      throw new ConfigurationException(
          "Thymeleaf execution context is not a Spring web context (implementation of " +
              org.thymeleaf.spring3.context.SpringWebContext.class.getName() + ". Spring Social integration can only be used in " +
          "web environements with a Spring application context.");
    }
    final org.thymeleaf.spring3.context.SpringWebContext springContext = (org.thymeleaf.spring3.context.SpringWebContext) context;   
View Full Code Here

    return springContext.getApplicationContext();
  }

  private ApplicationContext getSpringApplicationContextForThymeleaf4(final IContext context) {
    if (!(context instanceof org.thymeleaf.spring4.context.SpringWebContext)) {
      throw new ConfigurationException(
          "Thymeleaf execution context is not a Spring web context (implementation of " +
          org.thymeleaf.spring4.context.SpringWebContext.class.getName() + ". Spring Social integration can only be used in " +
          "web environements with a Spring application context.");
    }
    final org.thymeleaf.spring4.context.SpringWebContext springContext = (org.thymeleaf.spring4.context.SpringWebContext) context;   
View Full Code Here

           
            /*
             * Checking dialects exist
             */
            if (this.dialectConfigurations == null) {
                throw new ConfigurationException("Cannot initialize: a dialect has not been set");
            }

           
            /*
             * Initialize dialect configurations
             */
            for (final DialectConfiguration dialectConfiguration : this.dialectConfigurations) {
                dialectConfiguration.initialize();
            }
           
           
            /*
             * Initialize "dialects by prefix" map and the "dialect set"
             */
            this.dialectsByPrefix = new LinkedHashMap<String, IDialect>(4,1.0f);
            for (final DialectConfiguration dialectConfiguration : this.dialectConfigurations) {
                this.dialectsByPrefix.put(dialectConfiguration.getPrefix(), dialectConfiguration.getDialect());
            }
            this.dialectsByPrefix = Collections.unmodifiableMap(this.dialectsByPrefix);
            this.dialectSet = Collections.unmodifiableSet(new LinkedHashSet<IDialect>(this.dialectsByPrefix.values()));
           
           
            /*
             * Merge dialects
             */
            final MergedDialectArtifacts mergedDialectArtifacts = mergeDialects(this.dialectConfigurations);
            this.mergedSpecificProcessorsByElementName =
                Collections.unmodifiableMap(mergedDialectArtifacts.getSpecificProcessorsByElementName());
            this.mergedSpecificProcessorsByAttributeName =
                Collections.unmodifiableMap(mergedDialectArtifacts.getSpecificProcessorsByAttributeName());
            this.mergedNonSpecificProcessorsByNodeClass =
                Collections.unmodifiableMap(mergedDialectArtifacts.getMergedNonSpecificProcessorsByNodeClass());
            this.mergedExecutionAttributes =
                Collections.unmodifiableMap(mergedDialectArtifacts.getExecutionAttributes());
            this.mergedDocTypeResolutionEntries =
                Collections.unmodifiableSet(mergedDialectArtifacts.getDocTypeResolutionEntries());
            this.mergedDocTypeTranslations =
                Collections.unmodifiableSet(mergedDialectArtifacts.getDocTypeTranslations());
           
           
            /*
             * Checking template resolvers
             */
            if (this.templateResolvers == null || this.templateResolvers.size() <= 0) {
                throw new ConfigurationException("Cannot initialize: no template resolvers have been set");
            }
            final List<ITemplateResolver> templateResolversList =
                new ArrayList<ITemplateResolver>(this.templateResolvers);
            for (final ITemplateResolver templateResolver : templateResolversList) {
                templateResolver.initialize();
            }
            Collections.sort(templateResolversList, TEMPLATE_RESOLVER_COMPARATOR);
            this.templateResolvers = new LinkedHashSet<ITemplateResolver>(templateResolversList);

           
            /*
             * Checking message resolvers
             */
            if (this.messageResolvers == null) {
                throw new ConfigurationException("Cannot initialize: message resolvers set is null");
            }
            if (this.messageResolvers.size() == 0) {
                // No message resolvers have been set, so default initialization will be performed
                if (this.defaultMessageResolvers == null || this.defaultMessageResolvers.size() == 0) {
                    throw new ConfigurationException(
                            "Cannot initialize: no message resolvers have been set and " +
                            "no default message resolvers have been set either.");
                }
                this.messageResolvers = this.defaultMessageResolvers;
            }
           
            for (final IMessageResolver messageResolver : this.messageResolvers) {
                messageResolver.initialize();
            }
           
            final List<IMessageResolver> messageResolversList =
                new ArrayList<IMessageResolver>(this.messageResolvers);
           
            Collections.sort(messageResolversList, MESSAGE_RESOLVER_COMPARATOR);

            this.messageResolvers = new LinkedHashSet<IMessageResolver>(messageResolversList);

           
            /*
             * Checking template mode handlers
             */
            if (this.templateModeHandlers == null) {
                throw new ConfigurationException("Cannot initialize: template mode handlers set is null");
            }
            if (this.templateModeHandlers.size() == 0) {
                // No message resolvers have been set, so default initialization will be performed
                if (this.defaultTemplateModeHandlers == null || this.defaultTemplateModeHandlers.size() == 0) {
                    throw new ConfigurationException(
                            "Cannot initialize: no template mode handlers have been set and " +
                            "no default template mode handlers have been set either.");
                }
                this.templateModeHandlers = this.defaultTemplateModeHandlers;
            }

            for (final ITemplateModeHandler handler : this.templateModeHandlers) {
                if (this.templateModeHandlersByName.containsKey(handler.getTemplateModeName())) {
                    throw new ConfigurationException(
                            "More than one handler configured for template mode \"" + handler.getTemplateModeName() + "\"");
                }
                if (handler.getTemplateParser() == null) {
                    throw new ConfigurationException(
                            "Null parser returned by handler for template mode \"" + handler.getTemplateModeName() + "\"");
                }
                this.templateModeHandlersByName.put(handler.getTemplateModeName(), handler);
            }
           
View Full Code Here

   
   
    private static MergedDialectArtifacts mergeDialects(final Set<DialectConfiguration> dialectConfigurations) {
       
        if (dialectConfigurations == null || dialectConfigurations.isEmpty()) {
            throw new ConfigurationException("No dialect has been specified");
        }
       
        final Map<String,Set<ProcessorAndContext>> specificProcessorsByElementName = new HashMap<String, Set<ProcessorAndContext>>(20);
        final Map<String,Set<ProcessorAndContext>> specificProcessorsByAttributeName = new HashMap<String, Set<ProcessorAndContext>>(20);
        final Map<Class<? extends Node>, Set<ProcessorAndContext>> nonSpecificProcessorsByNodeClass = new HashMap<Class<? extends Node>, Set<ProcessorAndContext>>(20);
        final Map<String,Object> executionAttributes = new HashMap<String, Object>(20);
        final Set<IDocTypeResolutionEntry> docTypeResolutionEntries = new HashSet<IDocTypeResolutionEntry>(20);
        final Set<IDocTypeTranslation> docTypeTranslations = new HashSet<IDocTypeTranslation>(20);

        if (dialectConfigurations.size() == 1) {
            // No conflicts possible!
           
            final DialectConfiguration dialectConfiguration = dialectConfigurations.iterator().next();
            final IDialect dialect = dialectConfiguration.getDialect();

            specificProcessorsByElementName.putAll(dialectConfiguration.unsafeGetSpecificProcessorsByElementName());
            specificProcessorsByAttributeName.putAll(dialectConfiguration.unsafeGetSpecificProcessorsByAttributeName());
            nonSpecificProcessorsByNodeClass.putAll(dialectConfiguration.unsafeGetNonSpecificProcessorsByNodeClass());

            executionAttributes.putAll(dialectConfiguration.getExecutionAttributes());
            docTypeResolutionEntries.addAll(dialect.getDocTypeResolutionEntries());
            docTypeTranslations.addAll(dialect.getDocTypeTranslations());
           
            return new MergedDialectArtifacts(
                    specificProcessorsByElementName, specificProcessorsByAttributeName, nonSpecificProcessorsByNodeClass,
                    executionAttributes, dialect.getDocTypeResolutionEntries(), dialect.getDocTypeTranslations());
           
        }
       
       
        /*
         * THERE ARE MORE THAN ONE DIALECT: MERGE THEM
         */
        final Set<Class<? extends IDialect>> mergedDialectClasses = new HashSet<Class<? extends IDialect>>(5,1.0f);
       
        for (final DialectConfiguration dialectConfiguration : dialectConfigurations) {

           
            final IDialect dialect = dialectConfiguration.getDialect();

            /*
             * Check the dialect is not being repeated
             */
            if (mergedDialectClasses.contains(dialect.getClass())) {
                throw new ConfigurationException(
                        "Dialect is declared twice: " + dialect.getClass().getName());
            }

           
           
            /*
             * Aggregate all the processors assigned to a specific element name
             */
            specificProcessorsByElementName.putAll(dialectConfiguration.unsafeGetSpecificProcessorsByElementName());
           

           
            /*
             * Aggregate all the processors assigned to a specific attribute name
             */
            specificProcessorsByAttributeName.putAll(dialectConfiguration.unsafeGetSpecificProcessorsByAttributeName());
           

           
            /*
             * Aggregate all the processors not assigned to a specific attribute or element name
             */
            nonSpecificProcessorsByNodeClass.putAll(dialectConfiguration.unsafeGetNonSpecificProcessorsByNodeClass());
           

            /*
             * Merge execution attributes
             */
            executionAttributes.putAll(dialectConfiguration.getExecutionAttributes());

           
            /*
             * Check that two dialects do not specify conflicting DOCTYPE resolution entries
             * for the same PUBLIC and SYSTEM IDs.
             */
           
            final Set<IDocTypeResolutionEntry> dialectDocTypeResolutionEntries =
                dialect.getDocTypeResolutionEntries();

            for (final IDocTypeResolutionEntry dialectDocTypeResolutionEntry : dialectDocTypeResolutionEntries) {
               
                boolean addDialectDocTypeResolutionEntry = true;
               
                final DocTypeIdentifier dialectDocTypeResolutionEntryPublicID = dialectDocTypeResolutionEntry.getPublicID();
                final DocTypeIdentifier dialectDocTypeResolutionEntrySystemID = dialectDocTypeResolutionEntry.getSystemID();

                for (final IDocTypeResolutionEntry docTypeResolutionEntry : docTypeResolutionEntries) {
                   
                    final DocTypeIdentifier docTypeResolutionEntryPublicID = docTypeResolutionEntry.getPublicID();
                    final DocTypeIdentifier docTypeResolutionEntrySystemID = docTypeResolutionEntry.getSystemID();
                   
                    final boolean publicIDMatches;
                    if (dialectDocTypeResolutionEntryPublicID == null) {
                        publicIDMatches = (docTypeResolutionEntryPublicID == null);
                    } else {
                        publicIDMatches = (docTypeResolutionEntryPublicID != null && docTypeResolutionEntryPublicID.equals(dialectDocTypeResolutionEntryPublicID));
                    }

                    final boolean systemIDMatches;
                    if (dialectDocTypeResolutionEntrySystemID == null) {
                        systemIDMatches = (docTypeResolutionEntrySystemID == null);
                    } else {
                        systemIDMatches = (docTypeResolutionEntrySystemID != null && docTypeResolutionEntrySystemID.equals(dialectDocTypeResolutionEntrySystemID));
                    }
                   
                    if (publicIDMatches && systemIDMatches) {
                        if (!dialectDocTypeResolutionEntry.equals(docTypeResolutionEntry)) {
                            throw new ConfigurationException(
                                    "Cannot initialize: two dialects provide different (non-equal) " +
                                    "DOCTYPE resolution entries for PUBLICID \"" + docTypeResolutionEntryPublicID +
                                    "\" and SYSTEMID \"" + docTypeResolutionEntrySystemID + "\"");
                        }
                        // No need to repeat an entry (even if it is a Set!)
                        addDialectDocTypeResolutionEntry = false;
                    }
                   
                }
               
                if (addDialectDocTypeResolutionEntry) {
                    docTypeResolutionEntries.add(dialectDocTypeResolutionEntry);
                }
               
            }

           
           
            /*
             * Check that two dialects do not specify conflicting DOCTYPE translations
             * for the same PUBLIC and SYSTEM IDs.
             */
           
            final Set<IDocTypeTranslation> dialectDocTypeTranslations = dialect.getDocTypeTranslations();

            for (final IDocTypeTranslation dialectDocTypeTranslation : dialectDocTypeTranslations) {
               
                boolean addDialectDocTypeTranslation = true;
               
                final DocTypeIdentifier dialectDocTypeTranslationSourcePublicID = dialectDocTypeTranslation.getSourcePublicID();
                final DocTypeIdentifier dialectDocTypeTranslationSourceSystemID = dialectDocTypeTranslation.getSourceSystemID();
                final DocTypeIdentifier dialectDocTypeTranslationTargetPublicID = dialectDocTypeTranslation.getTargetPublicID();
                final DocTypeIdentifier dialectDocTypeTranslationTargetSystemID = dialectDocTypeTranslation.getTargetSystemID();

                for (final IDocTypeTranslation docTypeTranslation : docTypeTranslations) {
                   
                    final DocTypeIdentifier docTypeTranslationSourcePublicID = docTypeTranslation.getSourcePublicID();
                    final DocTypeIdentifier docTypeTranslationSourceSystemID = docTypeTranslation.getSourceSystemID();
                    final DocTypeIdentifier docTypeTranslationTargetPublicID = docTypeTranslation.getTargetPublicID();
                    final DocTypeIdentifier docTypeTranslationTargetSystemID = docTypeTranslation.getTargetSystemID();
                   
                    boolean sourcePublicIDMatches = false;
                    boolean sourceSystemIDMatches = false;
                   
                    if (dialectDocTypeTranslationSourcePublicID == null) {
                        sourcePublicIDMatches = (docTypeTranslationSourcePublicID == null);
                    } else {
                        sourcePublicIDMatches = (docTypeTranslationSourcePublicID != null && docTypeTranslationSourcePublicID.equals(dialectDocTypeTranslationSourcePublicID));
                    }
                   
                    if (dialectDocTypeTranslationSourceSystemID == null) {
                        sourceSystemIDMatches = (docTypeTranslationSourceSystemID == null);
                    } else {
                        sourceSystemIDMatches = (docTypeTranslationSourceSystemID != null && docTypeTranslationSourceSystemID.equals(dialectDocTypeTranslationSourceSystemID));
                    }
                   
                    if (sourcePublicIDMatches && sourceSystemIDMatches) {

                        final boolean targetPublicIDMatches;
                        if (dialectDocTypeTranslationTargetPublicID == null) {
                            targetPublicIDMatches = (docTypeTranslationTargetPublicID == null);
                        } else {
                            targetPublicIDMatches = (docTypeTranslationTargetPublicID != null && docTypeTranslationTargetPublicID.equals(dialectDocTypeTranslationTargetPublicID));
                        }

                        final boolean targetSystemIDMatches;
                        if (dialectDocTypeTranslationTargetSystemID == null) {
                            targetSystemIDMatches = (docTypeTranslationTargetSystemID == null);
                        } else {
                            targetSystemIDMatches = (docTypeTranslationTargetSystemID != null && docTypeTranslationTargetSystemID.equals(dialectDocTypeTranslationTargetSystemID));
                        }
                       
                        if (!targetPublicIDMatches || !targetSystemIDMatches) {
                            throw new ConfigurationException(
                                    "Cannot initialize: two dialects provide different (non-equal) " +
                                    "DOCTYPE translations for PUBLICID \"" + docTypeTranslationSourcePublicID +
                                    "\" and SYSTEMID \"" + docTypeTranslationSourceSystemID + "\"");
                        }
                       
View Full Code Here

        final ITemplateModeHandler templateModeHandler =
                this.configuration.getTemplateModeHandler(templateMode);
        final ITemplateWriter templateWriter = templateModeHandler.getTemplateWriter();

        if (templateWriter == null) {
            throw new ConfigurationException(
                    "No template writer defined for template mode \"" + templateMode + "\"");
        }
       
        try {
            // It depends on the ITemplateWriter implementation to allow nulls or not.
View Full Code Here

TOP

Related Classes of org.thymeleaf.exceptions.ConfigurationException

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.