Skip to content

Commit 1680906

Browse files
committed
Upgrade to SiteMesh 2.7.0
Closes gh-1408
1 parent c632d75 commit 1680906

File tree

6 files changed

+16
-70
lines changed

6 files changed

+16
-70
lines changed

grace-web-gsp/src/main/groovy/org/grails/web/sitemesh/GSPSitemeshPage.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2025 the original author or authors.
2+
* Copyright 2004-2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222

23+
import com.opensymphony.module.sitemesh.DefaultSitemeshBuffer;
2324
import com.opensymphony.module.sitemesh.HTMLPage;
2425
import com.opensymphony.module.sitemesh.parser.AbstractHTMLPage;
2526
import com.opensymphony.sitemesh.Content;
@@ -58,6 +59,7 @@ public GSPSitemeshPage() {
5859
}
5960

6061
public GSPSitemeshPage(boolean renderingLayout) {
62+
super(new DefaultSitemeshBuffer(new char[0]));
6163
reset();
6264
this.renderingLayout = renderingLayout;
6365
}
@@ -148,10 +150,6 @@ public String getPage() {
148150
return null;
149151
}
150152

151-
public int originalLength() {
152-
return this.pageBuffer.size();
153-
}
154-
155153
public void writeOriginal(Writer writer) throws IOException {
156154
writePage(writer);
157155
}

grace-web-gsp/src/main/groovy/org/grails/web/sitemesh/GrailsContentBufferingResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2025 the original author or authors.
2+
* Copyright 2004-2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import jakarta.servlet.http.HttpServletResponse;
2121
import jakarta.servlet.http.HttpServletResponseWrapper;
2222

23+
import com.opensymphony.module.sitemesh.DefaultSitemeshBuffer;
2324
import com.opensymphony.module.sitemesh.PageParser;
2425
import com.opensymphony.module.sitemesh.PageParserSelector;
2526
import com.opensymphony.sitemesh.Content;
@@ -93,7 +94,7 @@ public Content getContent() throws IOException {
9394

9495
char[] data = this.pageResponseWrapper.getContents();
9596
if (data != null && this.webAppContext.getContentType() != null) {
96-
return this.contentProcessor.build(data, this.webAppContext);
97+
return this.contentProcessor.build(new DefaultSitemeshBuffer(data), this.webAppContext);
9798
}
9899

99100
return null;
Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2025 the original author or authors.
2+
* Copyright 2004-2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,68 +17,19 @@
1717

1818
import java.io.IOException;
1919

20-
import com.opensymphony.module.sitemesh.Page;
21-
import com.opensymphony.module.sitemesh.html.HTMLProcessor;
22-
import com.opensymphony.module.sitemesh.html.State;
23-
import com.opensymphony.module.sitemesh.html.StateTransitionRule;
24-
import com.opensymphony.module.sitemesh.html.rules.BodyTagRule;
25-
import com.opensymphony.module.sitemesh.html.rules.ContentBlockExtractingRule;
26-
import com.opensymphony.module.sitemesh.html.rules.FramesetRule;
27-
import com.opensymphony.module.sitemesh.html.rules.HeadExtractingRule;
28-
import com.opensymphony.module.sitemesh.html.rules.HtmlAttributesRule;
29-
import com.opensymphony.module.sitemesh.html.rules.MSOfficeDocumentPropertiesRule;
30-
import com.opensymphony.module.sitemesh.html.rules.MetaTagRule;
31-
import com.opensymphony.module.sitemesh.html.rules.PageBuilder;
32-
import com.opensymphony.module.sitemesh.html.rules.ParameterExtractingRule;
33-
import com.opensymphony.module.sitemesh.html.rules.TitleExtractingRule;
34-
import com.opensymphony.module.sitemesh.html.util.CharArray;
20+
import com.opensymphony.module.sitemesh.SitemeshBuffer;
3521
import com.opensymphony.module.sitemesh.parser.HTMLPageParser;
3622
import com.opensymphony.module.sitemesh.parser.TokenizedHTMLPage;
3723
import com.opensymphony.sitemesh.Content;
3824

3925
public class GrailsHTMLPageParser extends HTMLPageParser {
4026

41-
@Override
42-
public Page parse(char[] data) throws IOException {
43-
CharArray head = new CharArray(64);
44-
CharArray body = new CharArray(4096);
45-
TokenizedHTMLPage page = new TokenizedHTMLPage(data, body, head);
46-
HTMLProcessor processor = new HTMLProcessor(data, body);
47-
State html = processor.defaultState();
48-
49-
// Core rules for SiteMesh to be functional.
50-
html.addRule(new HeadExtractingRule(head)); // contents of <head>
51-
html.addRule(new BodyTagRule(page, body)); // contents of <body>
52-
html.addRule(new TitleExtractingRule(page)); // the <title>
53-
html.addRule(new FramesetRule(page)); // if the page is a frameset
54-
55-
// Additional rules - designed to be tweaked.
56-
addUserDefinedRules(html, page);
57-
58-
processor.process();
59-
return page;
60-
}
61-
6227
public Content parseContent(char[] data) throws IOException {
6328
return new TokenizedHTMLPage2Content((TokenizedHTMLPage) parse(data));
6429
}
6530

66-
@Override
67-
protected void addUserDefinedRules(State html, PageBuilder page) {
68-
// Ensure that while in <xml> tag, none of the other rules kick in.
69-
// For example <xml><book><title>hello</title></book></xml> should not change the affect the title of the page.
70-
State xml = new State();
71-
html.addRule(new StateTransitionRule("xml", xml));
72-
73-
// Useful properties
74-
html.addRule(new HtmlAttributesRule(page)); // attributes in <html> element
75-
html.addRule(new MetaTagRule(page)); // all <meta> tags
76-
html.addRule(new ParameterExtractingRule(page)); // <parameter> blocks
77-
html.addRule(new ContentBlockExtractingRule(page)); // <content> blocks
78-
79-
// Capture properties written to documents by MS Office (author, version, company, etc).
80-
// Note: These properties are from the xml state, not the html state.
81-
xml.addRule(new MSOfficeDocumentPropertiesRule(page));
31+
public Content parseContent(SitemeshBuffer buffer) throws IOException {
32+
return new TokenizedHTMLPage2Content((TokenizedHTMLPage) parse(buffer));
8233
}
8334

8435
}

grace-web-gsp/src/main/groovy/org/grails/web/sitemesh/GrailsViewBufferingResponse.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2025 the original author or authors.
2+
* Copyright 2014-2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import jakarta.servlet.http.HttpServletRequest;
2121
import jakarta.servlet.http.HttpServletResponse;
2222

23+
import com.opensymphony.module.sitemesh.SitemeshBuffer;
2324
import com.opensymphony.sitemesh.Content;
2425
import com.opensymphony.sitemesh.ContentProcessor;
2526
import com.opensymphony.sitemesh.SiteMeshContext;
@@ -42,8 +43,8 @@ private static class SimpleWebAppContext extends SiteMeshWebAppContext {
4243
private static class SimpleHtmlOnlyContentProcessor implements ContentProcessor {
4344

4445
@Override
45-
public Content build(final char[] data, SiteMeshContext context) throws IOException {
46-
return new GrailsHTMLPageParser().parseContent(data);
46+
public Content build(SitemeshBuffer buffer, SiteMeshContext context) throws IOException {
47+
return new GrailsHTMLPageParser().parseContent(buffer);
4748
}
4849

4950
@Override

grace-web-gsp/src/main/groovy/org/grails/web/sitemesh/TokenizedHTMLPage2Content.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2025 the original author or authors.
2+
* Copyright 2014-2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,11 +44,6 @@ public void writeBody(Writer out) throws IOException {
4444
this.page.writeBody(out);
4545
}
4646

47-
@Override
48-
public int originalLength() {
49-
return this.page.getContentLength();
50-
}
51-
5247
@Override
5348
public String getTitle() {
5449
return this.page.getTitle();

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ rxjava2 = "2.2.21"
6060
rxjava3 = "3.1.12"
6161
selenium = "4.31.0"
6262
selenium-htmlunit = "4.30.0"
63-
sitemesh = "2.6.2"
63+
sitemesh = "2.7.0"
6464
slf4j = "2.0.17"
6565
snakeyaml = "2.4"
6666
spock = "2.3-groovy-4.0"

0 commit comments

Comments
 (0)