Permalink
Browse files

Converted HTMLPageParser to use a single buffer

  • Loading branch information...
1 parent 606b972 commit ae5c55cc64d7a93612ef81a9ea5ccefac9e17c3e @jroper jroper committed Jul 5, 2011
Showing with 1,086 additions and 879 deletions.
  1. +60 −18 src/java/com/opensymphony/module/sitemesh/DefaultSitemeshBuffer.java
  2. +205 −31 src/java/com/opensymphony/module/sitemesh/SitemeshBufferFragment.java
  3. +0 −26 src/java/com/opensymphony/module/sitemesh/SitemeshBufferFragmentDeletion.java
  4. +4 −5 src/java/com/opensymphony/module/sitemesh/SitemeshBufferWriter.java
  5. +4 −6 src/java/com/opensymphony/module/sitemesh/SitemeshWriter.java
  6. +0 −26 src/java/com/opensymphony/module/sitemesh/filter/BufferedContent.java
  7. +4 −3 src/java/com/opensymphony/module/sitemesh/filter/RoutablePrintWriter.java
  8. +3 −2 src/java/com/opensymphony/module/sitemesh/filter/SitemeshPrintWriter.java
  9. +9 −1 src/java/com/opensymphony/module/sitemesh/html/BasicRule.java
  10. +17 −13 src/java/com/opensymphony/module/sitemesh/html/BlockExtractingRule.java
  11. +20 −5 src/java/com/opensymphony/module/sitemesh/html/CustomTag.java
  12. +20 −40 src/java/com/opensymphony/module/sitemesh/html/HTMLProcessor.java
  13. +7 −4 src/java/com/opensymphony/module/sitemesh/html/HTMLProcessorContext.java
  14. +10 −5 src/java/com/opensymphony/module/sitemesh/html/State.java
  15. +0 −3 src/java/com/opensymphony/module/sitemesh/html/StateTransitionRule.java
  16. +12 −3 src/java/com/opensymphony/module/sitemesh/html/Tag.java
  17. +12 −4 src/java/com/opensymphony/module/sitemesh/html/Text.java
  18. +7 −4 src/java/com/opensymphony/module/sitemesh/html/rules/BodyTagRule.java
  19. +1 −1 src/java/com/opensymphony/module/sitemesh/html/rules/ContentBlockExtractingRule.java
  20. +1 −0 src/java/com/opensymphony/module/sitemesh/html/rules/FramesetRule.java
  21. +5 −3 src/java/com/opensymphony/module/sitemesh/html/rules/HeadExtractingRule.java
  22. +3 −0 src/java/com/opensymphony/module/sitemesh/html/rules/HtmlAttributesRule.java
  23. +1 −3 src/java/com/opensymphony/module/sitemesh/html/rules/MSOfficeDocumentPropertiesRule.java
  24. +0 −1 src/java/com/opensymphony/module/sitemesh/html/rules/MetaTagRule.java
  25. +1 −0 src/java/com/opensymphony/module/sitemesh/html/rules/ParameterExtractingRule.java
  26. +2 −1 src/java/com/opensymphony/module/sitemesh/html/rules/TagReplaceRule.java
  27. +1 −1 src/java/com/opensymphony/module/sitemesh/html/rules/TitleExtractingRule.java
  28. +14 −4 src/java/com/opensymphony/module/sitemesh/html/tokenizer/Parser.java
  29. +7 −1 src/java/com/opensymphony/module/sitemesh/html/tokenizer/TagTokenizer.java
  30. +48 −0 src/java/com/opensymphony/module/sitemesh/html/util/StringSitemeshBuffer.java
  31. +10 −5 src/java/com/opensymphony/module/sitemesh/multipass/DivExtractingPageParser.java
  32. +7 −32 src/java/com/opensymphony/module/sitemesh/multipass/MultipassReplacementPageParser.java
  33. +5 −0 src/java/com/opensymphony/module/sitemesh/parser/AbstractHTMLPage.java
  34. +30 −15 src/java/com/opensymphony/module/sitemesh/parser/AbstractPage.java
  35. +4 −12 src/java/com/opensymphony/module/sitemesh/parser/FastPage.java
  36. +2 −26 src/java/com/opensymphony/module/sitemesh/parser/FastPageParser.java
  37. +7 −31 src/java/com/opensymphony/module/sitemesh/parser/HTMLPageParser.java
  38. +381 −0 src/java/com/opensymphony/module/sitemesh/parser/PartialPageParser.java
  39. +18 −11 ...com/opensymphony/module/sitemesh/parser/{SuperFastHtmlPage.java → PartialPageParserHtmlPage.java}
  40. +29 −0 src/java/com/opensymphony/module/sitemesh/parser/PartialPageParserPage.java
  41. +0 −67 src/java/com/opensymphony/module/sitemesh/parser/SuperFastPage.java
  42. +3 −386 src/java/com/opensymphony/module/sitemesh/parser/SuperFastSimplePageParser.java
  43. +24 −12 src/java/com/opensymphony/module/sitemesh/parser/TokenizedHTMLPage.java
  44. +1 −1 src/parser-tests/parsers.properties
  45. +0 −3 src/parser-tests/test10.txt
  46. +43 −18 src/test/com/opensymphony/module/sitemesh/chaining/ChainingBufferTest.java
  47. +28 −35 src/test/com/opensymphony/module/sitemesh/html/HTMLProcessorTest.java
  48. +15 −10 src/test/com/opensymphony/module/sitemesh/html/rules/RegexReplacementTextFilterTest.java
  49. +1 −1 src/test/com/opensymphony/module/sitemesh/parser/ParserPerformanceComparison.java
@@ -2,9 +2,7 @@
import java.io.IOException;
import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
/**
* The default implementation of sitemesh buffer
@@ -13,38 +11,38 @@
private final char[] buffer;
private final int length;
- private final List<SitemeshBufferFragment> bufferFragments;
+ private final TreeMap<Integer, SitemeshBufferFragment> bufferFragments;
public DefaultSitemeshBuffer(char[] buffer) {
this(buffer, buffer.length);
}
public DefaultSitemeshBuffer(char[] buffer, int length) {
- this(buffer, length, Collections.<SitemeshBufferFragment>emptyList());
+ this(buffer, length, new TreeMap<Integer, SitemeshBufferFragment>());
}
- public DefaultSitemeshBuffer(char[] buffer, int length, List<SitemeshBufferFragment> bufferFragments) {
+ public DefaultSitemeshBuffer(char[] buffer, int length, TreeMap<Integer, SitemeshBufferFragment> bufferFragments) {
this.buffer = buffer;
this.length = length;
- this.bufferFragments = new ArrayList<SitemeshBufferFragment>(bufferFragments);
- Collections.sort(bufferFragments);
+ this.bufferFragments = bufferFragments;
}
public void writeTo(Writer writer, int start, int length) throws IOException {
int pos = start;
- for (SitemeshBufferFragment fragment : bufferFragments) {
- if (fragment.getPosition() < pos) {
+ for (Map.Entry<Integer, SitemeshBufferFragment> entry : bufferFragments.entrySet()) {
+ int fragmentPosition = entry.getKey();
+ if (fragmentPosition < pos) {
continue;
}
- if (fragment.getPosition() >= start + length) {
+ if (fragmentPosition > start + length) {
break;
}
// Write the buffer up to the fragment
- writer.write(buffer, pos, fragment.getPosition() - pos);
+ writer.write(buffer, pos, fragmentPosition - pos);
// Write the fragment
- fragment.writeTo(writer);
+ entry.getValue().writeTo(writer);
// increment pos
- pos = fragment.getPosition();
+ pos = fragmentPosition;
}
// Write out the remaining buffer
if (pos < start + length) {
@@ -59,14 +57,15 @@ public int getTotalLength() {
public int getTotalLength(int start, int length) {
int total = length;
- for (SitemeshBufferFragment fragment : bufferFragments) {
- if (fragment.getPosition() < start) {
+ for (Map.Entry<Integer, SitemeshBufferFragment> entry : bufferFragments.entrySet()) {
+ int fragmentPosition = entry.getKey();
+ if (fragmentPosition < start) {
continue;
}
- if (fragment.getPosition() > start + length) {
+ if (fragmentPosition > start + length) {
break;
}
- total += fragment.getTotalLength();
+ total += entry.getValue().getTotalLength();
}
return total;
}
@@ -82,4 +81,47 @@ public int getBufferLength() {
public boolean hasFragments() {
return !bufferFragments.isEmpty();
}
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static Builder builder(SitemeshBuffer sitemeshBuffer) {
+ return new Builder((DefaultSitemeshBuffer) 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);
+ }
+
+ 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);
+ }
+ }
}
Oops, something went wrong.

0 comments on commit ae5c55c

Please sign in to comment.