Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for buffer deletions

  • Loading branch information...
commit 7e8206e611ea941ddebb67994127b7ef64de80fa 1 parent e50fec8
@jroper jroper authored
View
4 src/java/com/opensymphony/module/sitemesh/DefaultSitemeshBuffer.java
@@ -42,7 +42,7 @@ public void writeTo(Writer writer, int start, int length) throws IOException {
// Write the buffer up to the fragment
writer.write(buffer, pos, fragment.getPosition() - pos);
// Write the fragment
- fragment.getBuffer().writeTo(writer, fragment.getStart(), fragment.getLength());
+ fragment.writeTo(writer);
// increment pos
pos = fragment.getPosition();
}
@@ -66,7 +66,7 @@ public int getTotalLength(int start, int length) {
if (fragment.getPosition() > start + length) {
break;
}
- total += fragment.getBuffer().getTotalLength(fragment.getStart(), fragment.getLength());
+ total += fragment.getTotalLength();
}
return total;
}
View
45 src/java/com/opensymphony/module/sitemesh/SitemeshBufferFragment.java
@@ -1,5 +1,10 @@
package com.opensymphony.module.sitemesh;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collections;
+import java.util.List;
+
/**
* A fragment of a sitemesh buffer
*/
@@ -8,16 +13,52 @@
private final int position;
private final int start;
private final int length;
+ private final List<SitemeshBufferFragmentDeletion> deletions;
public SitemeshBufferFragment(SitemeshBuffer buffer, int start, int length, int position) {
+ this(buffer, start, length, position, Collections.<SitemeshBufferFragmentDeletion>emptyList());
+ }
+
+ public SitemeshBufferFragment(SitemeshBuffer buffer, int start, int length, int position, List<SitemeshBufferFragmentDeletion> deletions) {
this.buffer = buffer;
this.start = start;
this.length = length;
this.position = position;
+ this.deletions = deletions;
+ }
+
+ public void writeTo(Writer writer) throws IOException
+ {
+ int pos = start;
+ for (SitemeshBufferFragmentDeletion deletion : deletions) {
+ if (deletion.getStart() > pos) {
+ buffer.writeTo(writer, pos, deletion.getStart() - pos);
+ }
+ pos = deletion.getStart() + deletion.getLength();
+ }
+ int remain = start + length - pos;
+ if (remain > 0)
+ {
+ buffer.writeTo(writer, pos, remain);
+ }
}
- public SitemeshBuffer getBuffer() {
- return buffer;
+ public int getTotalLength()
+ {
+ int total = 0;
+ int pos = start;
+ for (SitemeshBufferFragmentDeletion deletion : deletions) {
+ if (deletion.getStart() > pos) {
+ total += buffer.getTotalLength(pos, deletion.getStart() - pos);
+ }
+ pos = deletion.getStart() + deletion.getLength();
+ }
+ int remain = start + length - pos;
+ if (remain > 0)
+ {
+ total += remain;
+ }
+ return total;
}
public int getStart() {
View
26 src/java/com/opensymphony/module/sitemesh/SitemeshBufferFragmentDeletion.java
@@ -0,0 +1,26 @@
+package com.opensymphony.module.sitemesh;
+
+/**
+ *
+ */
+public class SitemeshBufferFragmentDeletion
+{
+ private final int start;
+ private final int length;
+
+ public SitemeshBufferFragmentDeletion(int start, int length)
+ {
+ this.start = start;
+ this.length = length;
+ }
+
+ public int getStart()
+ {
+ return start;
+ }
+
+ public int getLength()
+ {
+ return length;
+ }
+}
View
2  src/test/com/opensymphony/module/sitemesh/chaining/ChainingBufferTest.java
@@ -33,8 +33,6 @@ public void testAfter() throws Exception
assertEquals("a", getContent(buffer, 3, 1));
}
- public void
-
private String getContent(SitemeshBuffer buffer) throws Exception
{
CharArrayWriter writer = new CharArrayWriter();
Please sign in to comment.
Something went wrong with that request. Please try again.