Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/atlassian/sitemesh2 into …
Browse files Browse the repository at this point in the history
…atlassian

Conflicts:
	src/java/com/opensymphony/sitemesh/webapp/decorator/BaseWebAppDecorator.java
  • Loading branch information
Joe Walnes committed Aug 14, 2011
2 parents e6f60f0 + 70d8499 commit cf2be90
Show file tree
Hide file tree
Showing 77 changed files with 1,844 additions and 674 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -1,2 +1,8 @@
build
target
out
*.iml
*.ipr
*.iws
.idea
dist
7 changes: 7 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,10 @@
--------------------------
-- Changes in 2.5 --
--------------------------
* Single buffer parsing
* Buffer chaining
* PartialPageParser that only parses the <head> section of bodies

--------------------------
-- Changes in 2.4.2 --
--------------------------
Expand Down
2 changes: 1 addition & 1 deletion build.properties
Expand Up @@ -18,4 +18,4 @@ compile.nowarn = off

Name = OpenSymphony SiteMesh
name = sitemesh
version = 2.4.2
version = 2.5-atlassian-5
8 changes: 8 additions & 0 deletions build.xml
Expand Up @@ -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">
Expand Down
23 changes: 23 additions & 0 deletions pom.xml
@@ -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>
137 changes: 137 additions & 0 deletions src/java/com/opensymphony/module/sitemesh/DefaultSitemeshBuffer.java
@@ -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);
}
}
}
8 changes: 0 additions & 8 deletions src/java/com/opensymphony/module/sitemesh/Page.java
Expand Up @@ -67,14 +67,6 @@ public interface Page {
*/
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>.
*
Expand Down
18 changes: 10 additions & 8 deletions src/java/com/opensymphony/module/sitemesh/PageParser.java
Expand Up @@ -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;
}
58 changes: 58 additions & 0 deletions src/java/com/opensymphony/module/sitemesh/SitemeshBuffer.java
@@ -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();
}

0 comments on commit cf2be90

Please sign in to comment.