Git Product home page Git Product logo

Comments (2)

duoduobingbing avatar duoduobingbing commented on June 11, 2024

Here's a working demo

Your error boils down to mixing APIs in an unsupported way.

If you have a look at the documentation for PostProcessors you will see that it states:

Pre-processors and post-processors are different to processors in that instead of executing on a single event or on an event model (a fragment of a template), they apply to the entire template execution process as an additional step in the engine’s processing chain. Therefore they follow an API completely different to that of processors, much more event-oriented, defined by the lower-level ITemplateHandler interface.

a) ITextProcessor cannot be used in conjunction with IPostProcessorDialect.

b) The method getHandlerClass() defines the implementation of your PostProcessor, so it fails in your case because of

return ITemplateHandler.class;

ITemplateHandler is an interface and does not have a constructor, thus the exception java.lang.NoSuchMethodException: org.thymeleaf.engine.ITemplateHandler.<init>()

How can it be fixed?

public class StripElementWhiteSpaceDialect implements IPostProcessorDialect {

    Set<IPostProcessor> processors = new HashSet<>();

    {
       processors.add(new PostProcessor(TemplateMode.HTML, StripElementWhiteSpaceHandler.class, Integer.MAX_VALUE));
    }

    @Override
    public int getDialectPostProcessorPrecedence() {
        return 0;
    }

    @Override
    public Set<IPostProcessor> getPostProcessors() {
        return processors;
    }

    @Override
    public String getName() {
        return "Minifier";
    }

    public static class StripElementWhiteSpaceHandler extends AbstractTemplateHandler {

       @Override
       public void handleText(IText textNode) {
          
           //update the text
           
           super.handleText(...);
       }

    }

}

from thymeleaf.

albilu avatar albilu commented on June 11, 2024

@duoduobingbing thanks for the demo. But actually textNode.getText() is not the final complete processed output but rather chuncks. So doesnt fit what i was looking for. Thanks very much anyway.

from thymeleaf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.