Permalink
Browse files

Merge branch 'master' of https://github.com/atlassian/sitemesh2 into …

…atlassian

Conflicts:
	src/java/com/opensymphony/sitemesh/webapp/decorator/BaseWebAppDecorator.java
  • Loading branch information...
2 parents e6f60f0 + 70d8499 commit cf2be9084ecce7550d959f83063ac736dfc3fb9d Joe Walnes committed Aug 14, 2011
Showing with 1,844 additions and 674 deletions.
  1. +6 −0 .gitignore
  2. +7 −0 CHANGES.txt
  3. +1 −1 build.properties
  4. +8 −0 build.xml
  5. +23 −0 pom.xml
  6. +137 −0 src/java/com/opensymphony/module/sitemesh/DefaultSitemeshBuffer.java
  7. +0 −8 src/java/com/opensymphony/module/sitemesh/Page.java
  8. +10 −8 src/java/com/opensymphony/module/sitemesh/PageParser.java
  9. +58 −0 src/java/com/opensymphony/module/sitemesh/SitemeshBuffer.java
  10. +265 −0 src/java/com/opensymphony/module/sitemesh/SitemeshBufferFragment.java
  11. +31 −0 src/java/com/opensymphony/module/sitemesh/SitemeshBufferWriter.java
  12. +26 −0 src/java/com/opensymphony/module/sitemesh/SitemeshWriter.java
  13. +9 −24 src/java/com/opensymphony/module/sitemesh/filter/Buffer.java
  14. +0 −24 src/java/com/opensymphony/module/sitemesh/filter/BufferedContent.java
  15. +2 −1 src/java/com/opensymphony/module/sitemesh/filter/PageResponseWrapper.java
  16. +26 −1 src/java/com/opensymphony/module/sitemesh/filter/RoutablePrintWriter.java
  17. +30 −0 src/java/com/opensymphony/module/sitemesh/filter/SitemeshPrintWriter.java
  18. +9 −1 src/java/com/opensymphony/module/sitemesh/html/BasicRule.java
  19. +18 −13 src/java/com/opensymphony/module/sitemesh/html/BlockExtractingRule.java
  20. +20 −5 src/java/com/opensymphony/module/sitemesh/html/CustomTag.java
  21. +20 −40 src/java/com/opensymphony/module/sitemesh/html/HTMLProcessor.java
  22. +7 −4 src/java/com/opensymphony/module/sitemesh/html/HTMLProcessorContext.java
  23. +10 −5 src/java/com/opensymphony/module/sitemesh/html/State.java
  24. +0 −3 src/java/com/opensymphony/module/sitemesh/html/StateTransitionRule.java
  25. +12 −3 src/java/com/opensymphony/module/sitemesh/html/Tag.java
  26. +12 −4 src/java/com/opensymphony/module/sitemesh/html/Text.java
  27. +7 −4 src/java/com/opensymphony/module/sitemesh/html/rules/BodyTagRule.java
  28. +1 −1 src/java/com/opensymphony/module/sitemesh/html/rules/ContentBlockExtractingRule.java
  29. +1 −0 src/java/com/opensymphony/module/sitemesh/html/rules/FramesetRule.java
  30. +5 −3 src/java/com/opensymphony/module/sitemesh/html/rules/HeadExtractingRule.java
  31. +3 −0 src/java/com/opensymphony/module/sitemesh/html/rules/HtmlAttributesRule.java
  32. +1 −3 src/java/com/opensymphony/module/sitemesh/html/rules/MSOfficeDocumentPropertiesRule.java
  33. +0 −1 src/java/com/opensymphony/module/sitemesh/html/rules/MetaTagRule.java
  34. +1 −0 src/java/com/opensymphony/module/sitemesh/html/rules/ParameterExtractingRule.java
  35. +2 −1 src/java/com/opensymphony/module/sitemesh/html/rules/TagReplaceRule.java
  36. +1 −1 src/java/com/opensymphony/module/sitemesh/html/rules/TitleExtractingRule.java
  37. +14 −4 src/java/com/opensymphony/module/sitemesh/html/tokenizer/Parser.java
  38. +7 −1 src/java/com/opensymphony/module/sitemesh/html/tokenizer/TagTokenizer.java
  39. +48 −0 src/java/com/opensymphony/module/sitemesh/html/util/StringSitemeshBuffer.java
  40. +10 −5 src/java/com/opensymphony/module/sitemesh/multipass/DivExtractingPageParser.java
  41. +12 −15 src/java/com/opensymphony/module/sitemesh/multipass/MultipassReplacementPageParser.java
  42. +13 −1 src/java/com/opensymphony/module/sitemesh/parser/AbstractHTMLPage.java
  43. +11 −23 src/java/com/opensymphony/module/sitemesh/parser/AbstractPage.java
  44. +4 −6 src/java/com/opensymphony/module/sitemesh/parser/FastPage.java
  45. +8 −16 src/java/com/opensymphony/module/sitemesh/parser/FastPageParser.java
  46. +12 −16 src/java/com/opensymphony/module/sitemesh/parser/HTMLPageParser.java
  47. +385 −0 src/java/com/opensymphony/module/sitemesh/parser/PartialPageParser.java
  48. +92 −0 src/java/com/opensymphony/module/sitemesh/parser/PartialPageParserHtmlPage.java
  49. +29 −0 src/java/com/opensymphony/module/sitemesh/parser/PartialPageParserPage.java
  50. +0 −39 src/java/com/opensymphony/module/sitemesh/parser/SuperFastHtmlPage.java
  51. +0 −56 src/java/com/opensymphony/module/sitemesh/parser/SuperFastPage.java
  52. +3 −202 src/java/com/opensymphony/module/sitemesh/parser/SuperFastSimplePageParser.java
  53. +26 −14 src/java/com/opensymphony/module/sitemesh/parser/TokenizedHTMLPage.java
  54. +8 −5 src/java/com/opensymphony/module/sitemesh/taglib/page/ApplyDecoratorTag.java
  55. +0 −6 src/java/com/opensymphony/sitemesh/Content.java
  56. +2 −2 src/java/com/opensymphony/sitemesh/ContentProcessor.java
  57. +3 −7 src/java/com/opensymphony/sitemesh/compatability/Content2HTMLPage.java
  58. +0 −4 src/java/com/opensymphony/sitemesh/compatability/HTMLPage2Content.java
  59. +3 −7 src/java/com/opensymphony/sitemesh/compatability/PageParser2ContentProcessor.java
  60. +2 −2 src/java/com/opensymphony/sitemesh/webapp/ContentBufferingResponse.java
  61. +0 −2 src/java/com/opensymphony/sitemesh/webapp/decorator/NoDecorator.java
  62. +5 −3 src/parser-tests/parsers.properties
  63. +1 −0 src/parser-tests/superfast/test01.txt
  64. +2 −0 src/parser-tests/superfast/test02.txt
  65. +3 −0 src/parser-tests/superfast/test03.txt
  66. +2 −0 src/parser-tests/superfast/test04.txt
  67. +3 −2 src/parser-tests/superfast/test05.txt
  68. +26 −0 src/parser-tests/superfast/test06.txt
  69. +35 −0 src/parser-tests/superfast/test07.txt
  70. +0 −3 src/parser-tests/test10.txt
  71. +24 −0 src/parser-tests/test45.txt
  72. +109 −0 src/test/com/opensymphony/module/sitemesh/chaining/ChainingBufferTest.java
  73. +29 −35 src/test/com/opensymphony/module/sitemesh/html/HTMLProcessorTest.java
  74. +15 −10 src/test/com/opensymphony/module/sitemesh/html/rules/RegexReplacementTextFilterTest.java
  75. +2 −1 src/test/com/opensymphony/module/sitemesh/multipass/DivExtractingPageParserTest.java
  76. +17 −2 src/test/com/opensymphony/module/sitemesh/parser/HTMLPageParserTest.java
  77. +110 −26 src/test/com/opensymphony/module/sitemesh/parser/ParserPerformanceComparison.java
View
@@ -1,2 +1,8 @@
build
+target
+out
+*.iml
+*.ipr
+*.iws
+.idea
dist
View
@@ -1,4 +1,11 @@
--------------------------
+-- Changes in 2.5 --
+--------------------------
+ * Single buffer parsing
+ * Buffer chaining
+ * PartialPageParser that only parses the <head> section of bodies
+
+--------------------------
-- Changes in 2.4.2 --
--------------------------
Minor update to allow SiteMesh to initialize correctly when deployed on Google AppEngine.
View
@@ -18,4 +18,4 @@ compile.nowarn = off
Name = OpenSymphony SiteMesh
name = sitemesh
-version = 2.4.2
+version = 2.5-atlassian-5
View
@@ -123,6 +123,14 @@
</jar>
</target>
+ <target name="sources" depends="compile">
+ <mkdir dir="dist"/>
+ <jar jarfile="dist/${name}-${version}-sources.jar">
+ <fileset dir="src/java"/>
+ <fileset dir="build/java"/>
+ </jar>
+ </target>
+
<target name="blank" depends="jar" description="Builds simple web-app to get started with SiteMesh">
<mkdir dir="dist"/>
<war warfile="dist/${name}-blank.war" webxml="src/etc/blank/WEB-INF/web.xml">
View
@@ -0,0 +1,23 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <!--
+ ant clean test
+ ant clean jar sources
+ mvn deploy:deploy-file -Dfile=./dist/sitemesh-2.5-atlassian-5.jar -DpomFile=./pom.xml -Durl=https://maven.atlassian.com/public -DrepositoryId=atlassian-public
+ mvn deploy:deploy-file -Dfile=./dist/sitemesh-2.5-atlassian-5-sources.jar -DpomFile=./pom.xml -Dclassifier=sources -Durl=https://maven.atlassian.com/public -DrepositoryId=atlassian-public
+ -->
+
+ <groupId>opensymphony</groupId>
+ <artifactId>sitemesh</artifactId>
+ <version>2.5-atlassian-5</version>
+
+ <packaging>jar</packaging>
+ <name>SiteMesh</name>
+ <description>Atlassian's fork of SiteMesh</description>
+ <url>https://github.com/atlassian/sitemesh2</url>
+
+
+</project>
@@ -0,0 +1,137 @@
+package com.opensymphony.module.sitemesh;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.*;
+
+/**
+ * The default implementation of sitemesh buffer
+ */
+public class DefaultSitemeshBuffer implements SitemeshBuffer {
+
+ private final char[] buffer;
+ private final int length;
+ private final TreeMap<Integer, SitemeshBufferFragment> bufferFragments;
+
+ public DefaultSitemeshBuffer(char[] buffer) {
+ this(buffer, buffer.length);
+ }
+
+ public DefaultSitemeshBuffer(char[] buffer, int length) {
+ this(buffer, length, new TreeMap<Integer, SitemeshBufferFragment>());
+ }
+
+ public DefaultSitemeshBuffer(char[] buffer, int length, TreeMap<Integer, SitemeshBufferFragment> bufferFragments) {
+ this.buffer = buffer;
+ this.length = length;
+ this.bufferFragments = bufferFragments;
+ }
+
+ public void writeTo(Writer writer, int start, int length) throws IOException {
+ int pos = start;
+ for (Map.Entry<Integer, SitemeshBufferFragment> entry : bufferFragments.entrySet()) {
+ int fragmentPosition = entry.getKey();
+ if (fragmentPosition < pos) {
+ continue;
+ }
+ if (fragmentPosition > start + length) {
+ break;
+ }
+ // Write the buffer up to the fragment
+ writer.write(buffer, pos, fragmentPosition - pos);
+ // Write the fragment
+ entry.getValue().writeTo(writer);
+ // increment pos
+ pos = fragmentPosition;
+ }
+ // Write out the remaining buffer
+ if (pos < start + length) {
+ writer.write(buffer, pos, (start + length) - pos);
+ }
+ }
+
+ public int getTotalLength() {
+ return getTotalLength(0, length);
+ }
+
+ public int getTotalLength(int start, int length) {
+ int total = length;
+
+ for (Map.Entry<Integer, SitemeshBufferFragment> entry : bufferFragments.entrySet()) {
+ int fragmentPosition = entry.getKey();
+ if (fragmentPosition < start) {
+ continue;
+ }
+ if (fragmentPosition > start + length) {
+ break;
+ }
+ total += entry.getValue().getTotalLength();
+ }
+ return total;
+ }
+
+ public int getBufferLength() {
+ return length;
+ }
+
+ public char[] getCharArray() {
+ return buffer;
+ }
+
+ public boolean hasFragments() {
+ return !bufferFragments.isEmpty();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static Builder builder(SitemeshBuffer sitemeshBuffer) {
+ if (sitemeshBuffer instanceof DefaultSitemeshBuffer) {
+ return new Builder((DefaultSitemeshBuffer) sitemeshBuffer);
+ } else {
+ return new Builder(sitemeshBuffer);
+ }
+ }
+
+ public static class Builder {
+ private char[] buffer;
+ private int length;
+ private final TreeMap<Integer, SitemeshBufferFragment> fragments;
+
+ private Builder() {
+ this.fragments = new TreeMap<Integer, SitemeshBufferFragment>();
+ }
+
+ private Builder(DefaultSitemeshBuffer buffer) {
+ this.buffer = buffer.buffer;
+ this.length = buffer.length;
+ this.fragments = new TreeMap<Integer, SitemeshBufferFragment>(buffer.bufferFragments);
+ }
+
+ private Builder(SitemeshBuffer buffer) {
+ this.buffer = buffer.getCharArray();
+ this.length = buffer.getBufferLength();
+ this.fragments = new TreeMap<Integer, SitemeshBufferFragment>();
+ }
+
+ public Builder setBuffer(char[] buffer) {
+ this.buffer = buffer;
+ return this;
+ }
+
+ public Builder setLength(int length) {
+ this.length = length;
+ return this;
+ }
+
+ public Builder insert(int position, SitemeshBufferFragment fragment) {
+ this.fragments.put(position, fragment);
+ return this;
+ }
+
+ public SitemeshBuffer build() {
+ return new DefaultSitemeshBuffer(buffer, length, fragments);
+ }
+ }
+}
@@ -68,14 +68,6 @@
String getTitle();
/**
- * Length of the <code>Page</code>, in the format before
- * it was parsed.
- *
- * @return Length of page data (in number of bytes).
- */
- int getContentLength();
-
- /**
* Get a property embedded into the <code>Page</code> as a <code>String</code>.
*
* @param name Name of property
@@ -27,22 +27,24 @@
public interface PageParser {
/**
- * This builds a Page.
+ * Parse the given buffer into a page object. {@link DefaultSitemeshBuffer} is the appropriate implementation of
+ * this interface to pass in.
*
- * @param data The data for the page. Note, this array may be larger than the length of the content.
- * @param length The length of the page.
+ * @param buffer The buffer for the page.
* @return The parsed page
* @throws IOException if an error occurs
- * @since 2.5
*/
- Page parse(char[] data, int length) throws IOException;
+ Page parse(SitemeshBuffer buffer) throws IOException;
/**
- * This builds a Page.
+ * Parse the given buffer into a Page object.
*
- * @param data The data for the page.
+ * @param buffer The buffer for the page.
* @return The parsed page
* @throws IOException if an error occurs
+ * @deprecated Use {@link PageParser#parse(SitemeshBuffer)}, to allow performance improvement such as single buffer
+ * parsing and buffer chaining.
*/
- Page parse(char[] data) throws IOException;
+ @Deprecated
+ Page parse(char[] buffer) throws IOException;
}
@@ -0,0 +1,58 @@
+package com.opensymphony.module.sitemesh;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * A potentially chained sitemesh buffer
+ */
+public interface SitemeshBuffer {
+
+ /**
+ * Get the char array for this buffer. This array may be longer than the length of the content, you must use
+ * getBufferLength() in combination with this method.
+ *
+ * @return The char array for this buffer
+ */
+ char[] getCharArray();
+
+ /**
+ * Get the length of the buffered content.
+ *
+ * @return The length of the buffered content.
+ */
+ int getBufferLength();
+
+ /**
+ * Get the total length of the buffered content, including the length of any chained buffers.
+ *
+ * @return The total length.
+ */
+ int getTotalLength();
+
+ /**
+ * Get the total length of the buffered content, including chained buffers from start to length
+ *
+ * @param start Where to start counting the length from
+ * @param length Where to finish
+ * @return THe total length in the given range
+ */
+ int getTotalLength(int start, int length);
+
+ /**
+ * Write this buffer, and any chained sub buffers in the given range, out to the given writer
+ *
+ * @param start The position to start writing from
+ * @param length The length to write
+ * @param writer The writer to write to
+ * @throws IOException If an error occurred
+ */
+ void writeTo(Writer writer, int start, int length) throws IOException;
+
+ /**
+ * Whether the buffer has fragments or not
+ *
+ * @return True if it has fragments
+ */
+ boolean hasFragments();
+}
Oops, something went wrong.

0 comments on commit cf2be90

Please sign in to comment.