Commit ca86d0f9 authored by mkomar's avatar mkomar
Browse files

próba migracji do thymeleaf 3.0 #2

parent d472ab90
......@@ -224,12 +224,12 @@
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>1.4.0</version>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.github.mxab.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-data-attribute</artifactId>
<version>2.0</version>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
......@@ -619,11 +619,6 @@
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>uk.co.gcwilliams</groupId>
<artifactId>jodatime-thymeleaf-dialect</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
......
......@@ -172,10 +172,6 @@
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>uk.co.gcwilliams</groupId>
<artifactId>jodatime-thymeleaf-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
......
package pl.edu.icm.cocos.web.thymeleaf;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.thymeleaf.IEngineConfiguration;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.engine.AttributeName;
import org.thymeleaf.model.IModel;
import org.thymeleaf.model.IModelFactory;
import org.thymeleaf.model.ITemplateEvent;
import org.thymeleaf.processor.element.AbstractAttributeModelProcessor;
import org.thymeleaf.processor.element.IElementModelStructureHandler;
import org.thymeleaf.spring4.context.SpringContextUtils;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.util.FastStringWriter;
public class DecoratorModelProcessor extends AbstractAttributeModelProcessor {
protected DecoratorModelProcessor(TemplateMode templateMode, String dialectPrefix, String elementName, boolean prefixElementName, String attributeName,
boolean prefixAttributeName, int precedence, boolean removeAttribute) {
super(templateMode, dialectPrefix, elementName, prefixElementName, attributeName, prefixAttributeName, precedence, removeAttribute);
}
@Override
protected void doProcess(ITemplateContext context, IModel model, AttributeName attributeName, String attributeValue,
IElementModelStructureHandler structureHandler) {
final ApplicationContext appCtx = SpringContextUtils.getApplicationContext(context);
final Collection<ThymeleafOutputProcessor> processors = appCtx.getBeansOfType(ThymeleafOutputProcessor.class).values();
IModelFactory factory = context.getModelFactory();
final IEngineConfiguration configuration = context.getConfiguration();
for(int i=model.size()-1; i>=0 ;i--){
model.accept(new TemplateVisitor());
ITemplateEvent element = model.get(i);
// factory.createModel().a
element.toString();
// element.write(writer);
model.replace(i, element);
final Writer stringWriter = new FastStringWriter(200);
// configuration.getTemplateManager().process(model, context, stringWriter);
// element.;
}
// model.get(0).
// model.re
// model.
}
public final void process(ITemplateContext context, IModel model, Collection<ThymeleafOutputProcessor> proc) throws IOException {
List<ThymeleafOutputProcessor> processors = new ArrayList<>(proc);
StringReader reader = null;
for (Iterator<ThymeleafOutputProcessor> processorIt = processors.iterator(); processorIt.hasNext();) {
ThymeleafOutputProcessor processor = processorIt.next();
if (processorIt.hasNext()) {
StringWriter stringWriter = new StringWriter();
processor.process(reader, stringWriter);
reader = new StringReader(stringWriter.toString());
} else {
// processor.process(reader, writer);
}
}
}
}
package pl.edu.icm.cocos.web.thymeleaf;
import java.io.Writer;
import java.util.Collection;
import org.springframework.context.ApplicationContext;
import org.thymeleaf.IEngineConfiguration;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.model.IProcessableElementTag;
import org.thymeleaf.processor.element.AbstractElementTagProcessor;
import org.thymeleaf.processor.element.IElementTagStructureHandler;
import org.thymeleaf.spring4.context.SpringContextUtils;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.util.FastStringWriter;
public class DecoratorTagProcessor extends AbstractElementTagProcessor {
public DecoratorTagProcessor(TemplateMode templateMode, String dialectPrefix, String elementName, boolean prefixElementName, String attributeName,
boolean prefixAttributeName, int precedence) {
super(templateMode, dialectPrefix, elementName, prefixElementName, attributeName, prefixAttributeName, precedence);
}
// public final void process(final TemplateSpec templateSpec, final IContext context, final Writer writer) throws IOException {
// List<ThymeleafOutputProcessor> processors = new ArrayList<>(this.processors);
// // processors.add(0, (i, o) -> delegate.write(arguments, o, document));
// StringReader reader = null;
// for (Iterator<ThymeleafOutputProcessor> processorIt = processors.iterator(); processorIt.hasNext();) {
// ThymeleafOutputProcessor processor = processorIt.next();
// if (processorIt.hasNext()) {
// StringWriter stringWriter = new StringWriter();
// processor.process(reader, stringWriter);
// reader = new StringReader(stringWriter.toString());
// } else {
// processor.process(reader, writer);
// }
// }
// }
@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag, IElementTagStructureHandler structureHandler) {
final ApplicationContext appCtx = SpringContextUtils.getApplicationContext(context);
final Collection<ThymeleafOutputProcessor> processors = appCtx.getBeansOfType(ThymeleafOutputProcessor.class).values();
final IEngineConfiguration configuration = context.getConfiguration();
final Writer stringWriter = new FastStringWriter(200);
// configuration.getTemplateManager().process(, context, stringWriter);
structureHandler.replaceWith(stringWriter.toString(), false);
// tag.te
// configuration.getTemplateManager().p
}
}
package pl.edu.icm.cocos.web.thymeleaf;
import org.thymeleaf.model.AbstractModelVisitor;
import org.thymeleaf.model.ICDATASection;
import org.thymeleaf.model.ICloseElementTag;
import org.thymeleaf.model.IComment;
import org.thymeleaf.model.IDocType;
import org.thymeleaf.model.IOpenElementTag;
import org.thymeleaf.model.IProcessingInstruction;
import org.thymeleaf.model.IStandaloneElementTag;
import org.thymeleaf.model.ITemplateEnd;
import org.thymeleaf.model.ITemplateStart;
import org.thymeleaf.model.IText;
import org.thymeleaf.model.IXMLDeclaration;
public class TemplateVisitor extends AbstractModelVisitor {
@Override
public void visit(ITemplateStart templateStart) {
// TODO Auto-generated method stub
}
@Override
public void visit(ITemplateEnd templateEnd) {
// TODO Auto-generated method stub
}
@Override
public void visit(IXMLDeclaration xmlDeclaration) {
// TODO Auto-generated method stub
}
@Override
public void visit(IDocType docType) {
// TODO Auto-generated method stub
}
@Override
public void visit(ICDATASection cdataSection) {
// TODO Auto-generated method stub
}
@Override
public void visit(IComment comment) {
// TODO Auto-generated method stub
}
@Override
public void visit(IText text) {
// TODO Auto-generated method stub
}
@Override
public void visit(IStandaloneElementTag standaloneElementTag) {
// TODO Auto-generated method stub
}
@Override
public void visit(IOpenElementTag openElementTag) {
// TODO Auto-generated method stub
}
@Override
public void visit(ICloseElementTag closeElementTag) {
// TODO Auto-generated method stub
}
@Override
public void visit(IProcessingInstruction processingInstruction) {
// TODO Auto-generated method stub
}
}
package pl.edu.icm.cocos.web.thymeleaf;
import java.util.HashSet;
import java.util.Set;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.templatemode.TemplateMode;
public class ThymeleafTemplateDecoratorDialect extends AbstractProcessorDialect {
private static final String DIALECT_NAME = "decoratorDialect";
private static final String DIALECT_PREFIX = "decorator";
protected ThymeleafTemplateDecoratorDialect() {
super(DIALECT_NAME, DIALECT_PREFIX, Integer.MAX_VALUE);
}
@Override
public Set<IProcessor> getProcessors(String dialectPrefix) {
Set<IProcessor> processors = new HashSet<>();
// processors.add(new DecoratorTagProcessor(TemplateMode.HTML, DIALECT_PREFIX, "html", false, "compressMe", true, Integer.MAX_VALUE));
processors.add(new DecoratorModelProcessor(TemplateMode.HTML, DIALECT_PREFIX, "html", false, "compressMe", true, Integer.MAX_VALUE, true));
return processors;
}
}
package pl.edu.icm.cocos.web.thymeleaf;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.thymeleaf.TemplateSpec;
import org.thymeleaf.context.IContext;
import org.thymeleaf.engine.AbstractTemplateHandler;
import org.thymeleaf.model.ITemplateEnd;
import org.thymeleaf.model.IText;
public class ThymeleafTemplateHandler extends AbstractTemplateHandler {
private final List<ThymeleafOutputProcessor> processors;
public ThymeleafTemplateHandler() {
this.processors = null;
}
public ThymeleafTemplateHandler(List<ThymeleafOutputProcessor> processors) {
this.processors = processors;
}
@Override
public void handleText(IText text) {
super.handleText(text);
}
@Override
public void handleTemplateEnd(ITemplateEnd templateEnd) {
super.handleTemplateEnd(templateEnd);
}
public final void process(final TemplateSpec templateSpec, final IContext context, final Writer writer) throws IOException {
List<ThymeleafOutputProcessor> processors = new ArrayList<>(this.processors);
// processors.add(0, (i, o) -> delegate.write(arguments, o, document));
StringReader reader = null;
for (Iterator<ThymeleafOutputProcessor> processorIt = processors.iterator(); processorIt.hasNext();) {
ThymeleafOutputProcessor processor = processorIt.next();
if(processorIt.hasNext()){
StringWriter stringWriter = new StringWriter();
processor.process(reader, stringWriter);
reader = new StringReader(stringWriter.toString());
} else {
processor.process(reader, writer);
}
}
}
}
......@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout/main_layout.xhtml">
layout:decorate="~{main_layout.xhtml}">
<head>
<th:block th:unless="${properties['debug'] == 'true'}" >
......
<!DOCTYPE html >
<html decorator:compressMe xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title th:text="#{cocos.portal.mainPage.title}">TITLE</title>
......@@ -106,7 +106,6 @@
</head>
<body>
QQQQ
<div class="clearfix" id="cookiesWarning">
<!-- <a href="#" class="accept-warning " th:text="#{cocos.portal.cookiesWarning.close}">Close</a> -->
<p class="text-justify" th:text="#{cocos.portal.cookiesWarning}" />
......
<!DOCTYPE html >
<html decorator:compressMe xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout/main_content.xhtml">
<html decorator:compressMe xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/main_content.xhtml}">
<head>
<title th:text="#{cocos.portal.aboutProject.title}">About</title>
......
......@@ -20,15 +20,9 @@
</property>
<property name="additionalDialects">
<list>
<!-- <bean class="uk.co.gcwilliams.jodatime.thymeleaf.JodaTimeDialect" /> -->
<!-- <bean class="nz.net.ultraq.thymeleaf.LayoutDialect" /> -->
<bean class="nz.net.ultraq.thymeleaf.LayoutDialect" />
<bean class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect" />
<bean class="com.github.mxab.thymeleaf.extras.dataattribute.dialect.DataAttributeDialect" />
<bean class="pl.edu.icm.cocos.web.thymeleaf.ThymeleafTemplateDecoratorDialect">
<!-- <constructor-arg name="processors"> -->
<!-- <ref bean="compressorThymeleafOutputProcessor" /> -->
<!-- </constructor-arg> -->
</bean>
</list>
</property>
<property name="templateResolvers">
......@@ -37,24 +31,6 @@
<ref bean="templateResolver" />
</set>
</property>
<!-- <property name="defaultTemplateModeHandlers"> -->
<!-- <set> -->
<!-- <value>#{T(org.thymeleaf.templatemode.StandardTemplateModeHandlers).XML}</value> -->
<!-- <value>#{T(org.thymeleaf.templatemode.StandardTemplateModeHandlers).VALIDXML}</value> -->
<!-- <value>#{T(org.thymeleaf.templatemode.StandardTemplateModeHandlers).XHTML}</value> -->
<!-- <value>#{T(org.thymeleaf.templatemode.StandardTemplateModeHandlers).VALIDXHTML}</value> -->
<!-- <value>#{T(org.thymeleaf.templatemode.StandardTemplateModeHandlers).LEGACYHTML5}</value> -->
<!-- <bean class="org.thymeleaf.templatemode.TemplateModeHandler"> -->
<!-- <constructor-arg name="templateModeName" value="HTML5" /> -->
<!-- <constructor-arg name="templateParser"> -->
<!-- <bean class="org.thymeleaf.templateparser.markup.HTMLTemplateParser"> -->
<!-- <constructor-arg name="poolSize" value="8" /> -->
<!-- </bean> -->
<!-- </constructor-arg> -->
<!-- <constructor-arg name="templateWriter" ref="templateHandler" /> -->
<!-- </bean> -->
<!-- </set> -->
<!-- </property> -->
</bean>
<bean id="templateHandler" class="pl.edu.icm.cocos.web.thymeleaf.ThymeleafTemplateHandler">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment