Author: markt
Date: Sun Oct 30 09:52:51 2005
New Revision: 329593
URL: http://svn.apache.org/viewcvs?rev=329593&view=rev
Log:
Fix bug 22802 - implement mappedfile. Port of:
- Kin-man's mappedfile implementation from TC5
- Jan's patch to use String rather than char[]
Added:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/TextOptimizer.java
(with props)
Modified:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Generator.java
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspReader.java
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Node.java
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Parser.java
Modified:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
URL:
http://svn.apache.org/viewcvs/tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Compiler.java?rev=329593&r1=329592&r2=329593&view=diff
==============================================================================
---
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
(original)
+++
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
Sun Oct 30 09:52:51 2005
@@ -196,6 +196,9 @@
// Determine which custom tag needs to declare which scripting vars
ScriptingVariabler.set(pageNodes);
+ // Optimization: concatenate contiguous template texts.
+ TextOptimizer.concatenate(this, pageNodes);
+
// generate servlet .java file
Generator.generate(writer, this, pageNodes);
writer.close();
Modified:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Generator.java
URL:
http://svn.apache.org/viewcvs/tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Generator.java?rev=329593&r1=329592&r2=329593&view=diff
==============================================================================
---
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Generator.java
(original)
+++
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Generator.java
Sun Oct 30 09:52:51 2005
@@ -597,7 +597,7 @@
public void visit(Node.Scriptlet n) throws JasperException {
n.setBeginJavaLine(out.getJavaLine());
- out.printMultiLn(new String(n.getText()));
+ out.printMultiLn(n.getText());
out.println();
n.setEndJavaLine(out.getJavaLine());
}
@@ -1225,8 +1225,7 @@
public void visit(Node.TemplateText n) throws JasperException {
- char[] chars = n.getText();
- int size = chars.length;
+ String text = n.getText();
n.setBeginJavaLine(out.getJavaLine());
@@ -1234,8 +1233,8 @@
StringBuffer sb = new StringBuffer("out.write(\"");
int initLength = sb.length();
int count = CHUNKSIZE;
- for (int i = 0 ; i < size ; i++) {
- char ch = chars[i];
+ for (int i = 0 ; i < text.length() ; i++) {
+ char ch = text.charAt(i);
--count;
switch(ch) {
case '"':
Modified:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
URL:
http://svn.apache.org/viewcvs/tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java?rev=329593&r1=329592&r2=329593&view=diff
==============================================================================
---
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
(original)
+++
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
Sun Oct 30 09:52:51 2005
@@ -231,9 +231,7 @@
if ((current instanceof Node.JspText) || !isAllSpace) {
Mark start = new Mark(path, locator.getLineNumber(),
locator.getColumnNumber());
- char[] bufCopy = new char[len];
- System.arraycopy(buf, offset, bufCopy, 0, len);
- new Node.TemplateText(bufCopy, start, current);
+ new Node.TemplateText(new String(buf, offset, len), start,
current);
}
}
@@ -268,9 +266,7 @@
if (!inDTD) {
Mark start = new Mark(path, locator.getLineNumber(),
locator.getColumnNumber());
- char[] bufCopy = new char[len];
- System.arraycopy(buf, offset, bufCopy, 0, len);
- new Node.Comment(bufCopy, start, current);
+ new Node.TemplateText(new String(buf, offset, len), start,
current);
}
}
Modified:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspReader.java
URL:
http://svn.apache.org/viewcvs/tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspReader.java?rev=329593&r1=329592&r2=329593&view=diff
==============================================================================
---
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspReader.java
(original)
+++
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/JspReader.java
Sun Oct 30 09:52:51 2005
@@ -197,7 +197,7 @@
* Gets Content until the next potential JSP element. Because all elements
* begin with a '<' we can just move until we see the next one.
*/
- char[] nextContent() {
+ String nextContent() {
int cur_cursor = current.cursor;
int len = current.stream.length;
char ch;
@@ -221,13 +221,11 @@
}
len = current.cursor - cur_cursor;
- char[] content = new char[len];
- System.arraycopy(current.stream, cur_cursor, content, 0, len);
- return content;
+ return new String (current.stream, cur_cursor, len);
}
- char[] getText(Mark start, Mark stop) throws JasperException {
+ String getText(Mark start, Mark stop) throws JasperException {
Mark oldstart = mark();
reset(start);
CharArrayWriter caw = new CharArrayWriter();
@@ -235,7 +233,7 @@
caw.write(nextChar());
caw.close();
reset(oldstart);
- return caw.toCharArray();
+ return caw.toString();
}
public int peekChar() {
Modified:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Node.java
URL:
http://svn.apache.org/viewcvs/tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Node.java?rev=329593&r1=329592&r2=329593&view=diff
==============================================================================
---
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Node.java
(original)
+++
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Node.java
Sun Oct 30 09:52:51 2005
@@ -33,7 +33,7 @@
protected Attributes attrs;
protected Nodes body;
- protected char[] text;
+ protected String text;
protected Mark startMark;
protected int beginJavaLine;
protected int endJavaLine;
@@ -67,7 +67,7 @@
* @param start The location of the jsp page
* @param parent The enclosing node
*/
- public Node(char[] text, Mark start, Node parent) {
+ public Node(String text, Mark start, Node parent) {
this.text = text;
this.startMark = start;
addToParent(parent);
@@ -93,7 +93,7 @@
this.body = body;
}
- public char[] getText() {
+ public String getText() {
return text;
}
@@ -295,7 +295,7 @@
*/
public static class Comment extends Node {
- public Comment(char[] text, Mark start, Node parent) {
+ public Comment(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -309,7 +309,7 @@
*/
public static abstract class ScriptingElement extends Node {
- public ScriptingElement(char[] text, Mark start, Node parent) {
+ public ScriptingElement(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -324,16 +324,14 @@
* TemplateText nodes in its body. This method handles either case.
* @return The text string
*/
- public char[] getText() {
- char[] ret = text;
+ public String getText() {
+ String ret = text;
if ((ret == null) && (body != null)) {
- CharArrayWriter chars = new CharArrayWriter();
- int size = body.size();
- for (int i=0; i<size; i++) {
- chars.write(body.getNode(i).getText(), 0,
- body.getNode(i).getText().length);
+ StringBuffer buf = new StringBuffer();
+ for (int i=0; i<body.size(); i++) {
+ buf.append(body.getNode(i).getText());
}
- ret = chars.toCharArray();
+ ret = buf.toString();
}
return ret;
}
@@ -344,7 +342,7 @@
*/
public static class Declaration extends ScriptingElement {
- public Declaration(char[] text, Mark start, Node parent) {
+ public Declaration(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -363,7 +361,7 @@
*/
public static class Expression extends ScriptingElement {
- public Expression(char[] text, Mark start, Node parent) {
+ public Expression(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -381,7 +379,7 @@
*/
public static class Scriptlet extends ScriptingElement {
- public Scriptlet(char[] text, Mark start, Node parent) {
+ public Scriptlet(String text, Mark start, Node parent) {
super(text, start, parent);
}
@@ -892,13 +890,32 @@
*/
public static class TemplateText extends Node {
- public TemplateText(char[] text, Mark start, Node parent) {
+ public TemplateText(String text, Mark start, Node parent) {
super(text, start, parent);
}
public void accept(Visitor v) throws JasperException {
v.visit(this);
}
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ /**
+ * Returns true if this template text contains whitespace only.
+ */
+ public boolean isAllSpace() {
+ boolean isAllSpace = true;
+ for (int i=0; i<text.length(); i++) {
+ if (!Character.isWhitespace(text.charAt(i))) {
+ isAllSpace = false;
+ break;
+ }
+ }
+ return isAllSpace;
+ }
+
}
/*********************************************************************
Modified:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java
URL:
http://svn.apache.org/viewcvs/tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java?rev=329593&r1=329592&r2=329593&view=diff
==============================================================================
---
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java
(original)
+++
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/PageDataImpl.java
Sun Oct 30 09:52:51 2005
@@ -333,7 +333,7 @@
/*
* Appends the given tag, including its text body, to the XML view.
*/
- private void appendTag(String tag, Attributes attrs, char[] text)
+ private void appendTag(String tag, Attributes attrs, String text)
throws JasperException {
buf.append("<").append(tag);
buf.append("\n");
@@ -400,7 +400,7 @@
buf.append("/>\n");
}
- private void appendText(char[] text, boolean createJspTextElement) {
+ private void appendText(String text, boolean createJspTextElement) {
if (createJspTextElement) {
buf.append(JSP_TEXT_TAG_START);
appendCDATA(text);
@@ -414,7 +414,7 @@
* Appends the given text as a CDATA section to the XML view, unless
* the text has already been marked as CDATA.
*/
- private void appendCDATA(char[] text) {
+ private void appendCDATA(String text) {
buf.append(CDATA_START_SECTION);
buf.append(escapeCDATA(text));
buf.append(CDATA_END_SECTION);
@@ -424,13 +424,14 @@
* Escapes any occurrences of "]]>" (by replacing them with "]]>")
* within the given text, so it can be included in a CDATA section.
*/
- private char[] escapeCDATA(char[] text) {
- CharArrayWriter result = new CharArrayWriter(text.length);
- for (int i=0; i<text.length; i++) {
- if (((i+2) < text.length)
- && (text[i] == ']')
- && (text[i+1] == ']')
- && (text[i+2] == '>')) {
+ private String escapeCDATA(String text) {
+ int len = text.length();
+ CharArrayWriter result = new CharArrayWriter(len);
+ for (int i=0; i<len; i++) {
+ if (((i+2) < len)
+ && (text.charAt(i) == ']')
+ && (text.charAt(i+1) == ']')
+ && (text.charAt(i+2) == '>')) {
// match found
result.write(']');
result.write(']');
@@ -440,10 +441,10 @@
result.write(';');
i += 2;
} else {
- result.write(text[i]);
+ result.write(text.charAt(i));
}
}
- return result.toCharArray();
+ return result.toString();
}
/*
Modified:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Parser.java
URL:
http://svn.apache.org/viewcvs/tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Parser.java?rev=329593&r1=329592&r2=329593&view=diff
==============================================================================
---
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Parser.java
(original)
+++
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/Parser.java
Sun Oct 30 09:52:51 2005
@@ -190,19 +190,21 @@
* | '\>'
* | Char
*/
- private String parseQuoted(char[] tx) {
+ private String parseQuoted(String tx) {
StringBuffer buf = new StringBuffer();
- int size = tx.length;
+ int size = tx.length();
int i = 0;
while (i < size) {
- char ch = tx[i];
+ char ch =tx.charAt(i);
if (ch == '&') {
- if (i+5 < size && tx[i+1] == 'a' && tx[i+2] == 'p' &&
- tx[i+3] == 'o' && tx[i+4] == 's' && tx[i+5] == ';') {
+ if (i+5 < size && tx.charAt(i+1) == 'a'
+ && tx.charAt(i+2) == 'p' && tx.charAt(i+3) == 'o'
+ && tx.charAt(i+4) == 's' && tx.charAt(i+5) == ';') {
buf.append('\'');
i += 6;
- } else if (i+5 < size && tx[i+1] == 'q' && tx[i+2] == 'u' &&
- tx[i+3] == 'o' && tx[i+4] == 't' && tx[i+5] == ';') {
+ } else if (i+5 < size && tx.charAt(i+1) == 'q'
+ && tx.charAt(i+2) == 'u' && tx.charAt(i+3) == 'o'
+ && tx.charAt(i+4) == 't' && tx.charAt(i+5) == ';') {
buf.append('"');
i += 6;
} else {
@@ -210,7 +212,7 @@
++i;
}
} else if (ch == '\\' && i+1 < size) {
- ch = tx[i+1];
+ ch = tx.charAt(i+1);
if (ch == '\\' || ch == '\"' || ch == '\'' || ch == '>') {
buf.append(ch);
i += 2;
@@ -226,13 +228,14 @@
return buf.toString();
}
- private char[] parseScriptText(char[] tx) {
+ private String parseScriptText(String tx) {
CharArrayWriter cw = new CharArrayWriter();
- int size = tx.length;
+ int size = tx.length();
int i = 0;
while (i < size) {
- char ch = tx[i];
- if (i+2 < size && ch == '%' && tx[i+1] == '\\' && tx[i+2] == '>') {
+ char ch = tx.charAt(i);
+ if (i+2 < size && ch == '%' && tx.charAt(i+1) == '\\'
+ && tx.charAt(i+2) == '>') {
cw.write('%');
cw.write('>');
i += 3;
@@ -242,7 +245,7 @@
}
}
cw.close();
- return cw.toCharArray();
+ return cw.toString();
}
/*
@@ -721,12 +724,8 @@
// Quoting in template text is handled here.
// JSP2.6 "A literal <% is quoted by <\%"
if (reader.matches("<\\%")) {
- char[] content = reader.nextContent();
- char[] text = new char[content.length + 2];
- text[0] = '<';
- text[1] = '%';
- System.arraycopy(content, 0, text, 2, content.length);
- new Node.TemplateText(text, start, parent);
+ String content = reader.nextContent();
+ new Node.TemplateText("<%" + content, start, parent);
} else {
new Node.TemplateText(reader.nextContent(), start, parent);
}
Added:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/TextOptimizer.java
URL:
http://svn.apache.org/viewcvs/tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/TextOptimizer.java?rev=329593&view=auto
==============================================================================
---
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/TextOptimizer.java
(added)
+++
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/TextOptimizer.java
Sun Oct 30 09:52:51 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jasper.compiler;
+
+import org.apache.jasper.JasperException;
+
+/**
+ */
+public class TextOptimizer {
+
+ /**
+ * A visitor to concatenate contiguous template texts.
+ */
+ static class TextCatVisitor extends Node.Visitor {
+
+ private int textNodeCount = 0;
+ private Node.TemplateText firstTextNode = null;
+ private StringBuffer textBuffer;
+ private final String emptyText = new String("");
+
+ public TextCatVisitor(Compiler compiler) {
+ }
+
+ public void doVisit(Node n) throws JasperException {
+ collectText();
+ }
+
+ /*
+ * The following directives are ignored in text concatenation
+ */
+
+ public void visit(Node.PageDirective n) throws JasperException {
+ }
+
+ public void visit(Node.TaglibDirective n) throws JasperException {
+ }
+
+ /*
+ * Don't concatenate text across body boundaries
+ */
+ public void visitBody(Node n) throws JasperException {
+ super.visitBody(n);
+ collectText();
+ }
+
+ public void visit(Node.TemplateText n) throws JasperException {
+
+ if (textNodeCount++ == 0) {
+ firstTextNode = n;
+ textBuffer = new StringBuffer(n.getText());
+ } else {
+ // Append text to text buffer
+ textBuffer.append(n.getText());
+ n.setText(emptyText);
+ }
+ }
+
+ /**
+ * This method breaks concatenation mode. As a side effect it copies
+ * the concatenated string to the first text node
+ */
+ private void collectText() {
+
+ if (textNodeCount > 1) {
+ // Copy the text in buffer into the first template text node.
+ firstTextNode.setText(textBuffer.toString());
+ }
+ textNodeCount = 0;
+ }
+
+ }
+
+ public static void concatenate(Compiler compiler, Node.Nodes page)
+ throws JasperException {
+
+ TextCatVisitor v = new TextCatVisitor(compiler);
+ page.visit(v);
+
+ // Cleanup, in case the page ends with a template text
+ v.collectText();
+ }
+}
\ No newline at end of file
Propchange:
tomcat/jasper/branches/tc4.1.x/jasper2/src/share/org/apache/jasper/compiler/TextOptimizer.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]