org.appng.core.templating

## Interface ThymeleafReplaceInterceptor

- All Known Implementing Classes:
    ThymeleafReplaceInterceptorBase

      public interface ThymeleafReplaceInterceptor

  This interface has to be implemented by interceptors to intercept the call of the replace tag to determine if this call has to be replaced by another fragment. The interceptor can also add additional context variables. An interceptor also has to be available as bean in the spring context. Therefore the @`Component` annotation might be useful.
  Example:

       @Component
       public class CustomInterceptor extends ThymeleafReplaceInterceptorBase {

              public boolean intercept(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
                              String attributeValue, IElementTagStructureHandler structureHandler,
                              ThymeleafStandardReplaceTagProcessorCaller tagProcessor) {

                      if (attributeValue.contains("::datacell")) {
                              // we want to replace each call of datacell with our own fragment
                              attributeValue = attributeValue.replace("::datacell", "customtemplate.html::datacell_custom");
                              // proceed processing with our customized attribute value
                              tagProcessor.callStandardDoProcess(context, tag, attributeName, attributeValue, structureHandler);
                              // tell the replace tag processor that this intereptor already triggered the
                              // processing
                              return true;
                      }
                      // tell the replace tag processor that this interceptor did not intercept
                      return false;
              }

              // add all needed template file names for this interceptor
              public Collection getAdditionalTemplateResourceNames() {
                      Set resources = Sets.newHashSet();
                      resources.add("personregister.html");
                      return resources;
              }

       }

  Author:
    Claus Stümke

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `Collection<String>` | `getAdditionalTemplateResourceNames()` With this method the interceptor can define additional template files which should be added to the template engine that custom fragments are available during processing
    `default int` | `getPriority()` In case that an application has different interceptors intercepting on the same replace call, the first interceptor will win.
    `boolean` | `intercept(org.thymeleaf.context.ITemplateContext context, org.thymeleaf.model.IProcessableElementTag tag, org.thymeleaf.engine.AttributeName attributeName, String attributeValue, org.thymeleaf.processor.element.IElementTagStructureHandler structureHandler, ThymeleafStandardReplaceTagProcessorCaller tagProcessor)` This method is called from the `ReplaceTagProcessor` before executing the ordinary replace logic as implemented by the `StandardReplaceTagProcessor`.

- - ### Method Detail

    - #### intercept

          boolean intercept(org.thymeleaf.context.ITemplateContext context,
                            org.thymeleaf.model.IProcessableElementTag tag,
                            org.thymeleaf.engine.AttributeName attributeName,
                            String attributeValue,
                            org.thymeleaf.processor.element.IElementTagStructureHandler structureHandler,
                            ThymeleafStandardReplaceTagProcessorCaller tagProcessor)

      This method is called from the `ReplaceTagProcessor` before executing the ordinary replace logic as implemented by the `StandardReplaceTagProcessor`. With this method the interceptor can decide to overwrite the attribute value of the replace tag to call another target fragment instead. Probably the interceptor also has to add additional variables to the context if the other target fragment has parameters which does not exist in the given context If the interceptor wants to intercept, it has to modify the attributeValue and call the doProcess method of the given tagProcessor. It has to return true to indicate that processing was done within this interception to avoid another processing by the `ReplaceTagProcessor`
      Parameters:
        `context` -
        `tag` -
        `attributeName` -
        `attributeValue` -
        `structureHandler` -
        `tagProcessor` -
      Returns:

    - #### getAdditionalTemplateResourceNames

          Collection<String> getAdditionalTemplateResourceNames()

      With this method the interceptor can define additional template files which should be added to the template engine that custom fragments are available during processing
      Returns:

    - #### getPriority

          default int getPriority()

      In case that an application has different interceptors intercepting on the same replace call, the first interceptor will win. The order of interceptors can be affected by setting a high priority to interceptors which shall be processed first
      Returns:

Copyright © 2011–2023 aiticon GmbH. All rights reserved.