You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/03/03 18:40:40 UTC
svn commit: r918597 - in /tomcat/tc6.0.x/trunk: ./ STATUS.txt
java/org/apache/jasper/JspC.java
java/org/apache/jasper/resources/LocalStrings.properties
webapps/docs/changelog.xml
Author: markt
Date: Wed Mar 3 17:40:39 2010
New Revision: 918597
URL: http://svn.apache.org/viewvc?rev=918597&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48371
Take account of comments when working out where to insert generated web.xml
Also
- Deprecate methods, removed in TC7
- Allow the encoding used for web.xml files to be configured, and allow the addWebXmlMappings option to be specified on the command line
Modified:
tomcat/tc6.0.x/trunk/ (props changed)
tomcat/tc6.0.x/trunk/STATUS.txt
tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java
tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties
tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc6.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 3 17:40:39 2010
@@ -1,2 +1,2 @@
/tomcat:883362
-/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,666232,673796,673820,677910,683969,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,713953,714002,718360,719119,719124,719602,719626,719628,720046,720069,721040,721286,721708,721886,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,746425,747834,747863,748344,750258,750291,750921,751286-751287,751289,751295,752323,753039,757335,757774,758249,758365,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,763193,763228,763262,763298,763302,763325,763599,763611,763654,763681,763706,764985,764997,765662,768335,769979,770716,77
0809,770876,772872,776921,776924,776935,776945,777464,777466,777576,777625,778379,778523-778524,781528,781779,782145,782791,783316,783696,783724,783756,783762,783766,783863,783934,784453,784602,784614,785381,785688,785768,785859,786468,786487,786490,786496,786667,787627,787770,787985,789389,790405,791041,791184,791194,791224,791243,791326,791328,791789,792740,793372,793757,793882,793981,794082,794673,794822,795043,795152,795210,795457,795466,797168,797425,797596,797607,802727,802940,804462,804544,804734,805153,809131,809603,810916,810977,812125,812137,812432,813001,813013,813866,814180,814708,814876,815972,816252,817442,817822,819339,819361,820110,820132,820874,820954,821397,828196,828201,828210,828225,828759,830378-830379,830999,831106,831774,831785,831828,831850,831860,832214,832218,833121,833545,834047,835036,835336,836405,881396,881412,883130,883134,883146,883165,883177,883362,883565,884341,885038,885231,885241,885260,885901,885991,886019,888072,889363,889606,889716,8901
39,890265,890349-890350,890417,891185-891187,891583,892198,892341,892415,892464,892555,892812,892814,892817,892843,892887,893321,893493,894580,894586,894805,894831,895013,895045,895057,895191,895392,895703,896370,896384,897380-897381,897776,898126,898256,898468,898527,898555,898558,898718,898836,898906,899284,899348,899420,899653,899769-899770,899783,899788,899792,899916,899918-899919,899935,899949,903916,905020,905151,905722,905728,905735,907311,907513,907538,907652,907819,907825,907864,908002,908721,908754,908759,909097,909206,909212,909525,909636,909875,909887,910266,910370,910442,910471,915226,915861,916141,916170
+/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,666232,673796,673820,677910,683969,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,713953,714002,718360,719119,719124,719602,719626,719628,720046,720069,721040,721286,721708,721886,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,746425,747834,747863,748344,750258,750291,750921,751286-751287,751289,751295,752323,753039,757335,757774,758249,758365,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,763193,763228,763262,763298,763302,763325,763599,763611,763654,763681,763706,764985,764997,765662,768335,769979,770716,77
0809,770876,772872,776921,776924,776935,776945,777464,777466,777576,777625,778379,778523-778524,781528,781779,782145,782791,783316,783696,783724,783756,783762,783766,783863,783934,784453,784602,784614,785381,785688,785768,785859,786468,786487,786490,786496,786667,787627,787770,787985,789389,790405,791041,791184,791194,791224,791243,791326,791328,791789,792740,793372,793757,793882,793981,794082,794673,794822,795043,795152,795210,795457,795466,797168,797425,797596,797607,802727,802940,804462,804544,804734,805153,809131,809603,810916,810977,812125,812137,812432,813001,813013,813866,814180,814708,814876,815972,816252,817442,817822,819339,819361,820110,820132,820874,820954,821397,828196,828201,828210,828225,828759,830378-830379,830999,831106,831774,831785,831828,831850,831860,832214,832218,833121,833545,834047,835036,835336,836405,881396,881412,883130,883134,883146,883165,883177,883362,883565,884341,885038,885231,885241,885260,885901,885991,886019,888072,889363,889606,889716,8901
39,890265,890349-890350,890417,891185-891187,891583,892198,892341,892415,892464,892555,892812,892814,892817,892843,892887,893321,893493,894580,894586,894805,894831,895013,895045,895057,895191,895392,895703,896370,896384,897380-897381,897776,898126,898256,898468,898527,898555,898558,898718,898836,898906,899284,899348,899420,899653,899769-899770,899783,899788,899792,899916,899918-899919,899935,899949,903916,905020,905151,905722,905728,905735,907311,907513,907538,907652,907819,907825,907864,908002,908721,908754,908759,909097,909206,909212,909525,909636,909869,909875,909887,910266,910370,910442,910471,915226,915737,915861,916097,916141,916157,916170
Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=918597&r1=918596&r2=918597&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Wed Mar 3 17:40:39 2010
@@ -88,17 +88,6 @@
+1: markt
-1:
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48371
- Take account of comments when working out where to insert generated
- web.xml (backport of r909869 by markt, 915737, 916097)
- Also
- - Deprecate methods, removed in TC7 (r916143)
- - Allow the encoding used for web.xml files to be configured,
- and allow the addWebXmlMappings option to be specified on the command line (r916157)
- http://people.apache.org/~kkolinko/patches/2010-02-25_tc6_bug48371.patch
- +1: kkolinko, markt,funkman
- -1:
-
* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48545
Truststores don't have to have passwords
Based on a patch by 'smmwpf54'
Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java?rev=918597&r1=918596&r2=918597&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java Wed Mar 3 17:40:39 2010
@@ -19,14 +19,16 @@
import java.io.BufferedReader;
import java.io.CharArrayWriter;
+import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.Reader;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
@@ -109,6 +111,8 @@
protected static final String SWITCH_FILE_WEBAPP = "-webapp";
protected static final String SWITCH_WEBAPP_INC = "-webinc";
protected static final String SWITCH_WEBAPP_XML = "-webxml";
+ protected static final String SWITCH_WEBAPP_XML_ENCODING = "-webxmlencoding";
+ protected static final String SWITCH_ADD_WEBAPP_XML_MAPPINGS = "-addwebxmlmappings";
protected static final String SWITCH_MAPPED = "-mapped";
protected static final String SWITCH_XPOWERED_BY = "-xpoweredBy";
protected static final String SWITCH_TRIM_SPACES = "-trimSpaces";
@@ -195,6 +199,7 @@
// Generation of web.xml fragments
protected String webxmlFile;
protected int webxmlLevel;
+ protected String webxmlEncoding;
protected boolean addWebXmlMappings = false;
protected Writer mapout;
@@ -295,6 +300,10 @@
if (webxmlFile != null) {
webxmlLevel = ALL_WEBXML;
}
+ } else if (tok.equals(SWITCH_WEBAPP_XML_ENCODING)) {
+ setWebXmlEncoding(nextArg());
+ } else if (tok.equals(SWITCH_ADD_WEBAPP_XML_MAPPINGS)) {
+ setAddWebXmlMappings(true);
} else if (tok.equals(SWITCH_MAPPED)) {
mappedFile = true;
} else if (tok.equals(SWITCH_XPOWERED_BY)) {
@@ -434,6 +443,10 @@
errorOnUseBeanInvalidClassAttribute = b;
}
+ /**
+ * @deprecated Removed in Tomcat 7
+ */
+ @Deprecated
public int getTagPoolSize() {
return Constants.MAX_POOL_SIZE;
}
@@ -445,8 +458,12 @@
return mappedFile;
}
- // Off-line compiler, no need for security manager
+ /**
+ * @deprecated Removed in Tomcat 7
+ */
+ @Deprecated
public Object getProtectionDomain() {
+ // Off-line compiler, no need for security manager
return null;
}
@@ -594,11 +611,19 @@
return scratchDir;
}
+ /**
+ * @deprecated Removed in Tomcat 7
+ */
+ @Deprecated
public Class getJspCompilerPlugin() {
// we don't compile, so this is meanlingless
return null;
}
+ /**
+ * @deprecated Removed in Tomcat 7
+ */
+ @Deprecated
public String getJspCompilerPath() {
// we don't compile, so this is meanlingless
return null;
@@ -864,6 +889,20 @@
}
/**
+ * Sets the encoding to be used to read and write web.xml files.
+ *
+ * <p>
+ * If not specified, defaults to the platform default encoding.
+ * </p>
+ *
+ * @param encoding
+ * Encoding, e.g. "UTF-8".
+ */
+ public void setWebXmlEncoding(String encoding) {
+ webxmlEncoding = encoding;
+ }
+
+ /**
* Sets the option to merge generated web.xml fragment into the
* WEB-INF/web.xml file of the web application that we were processing.
*
@@ -964,72 +1003,67 @@
String insertEndMarker =
Localizer.getMessage("jspc.webinc.insertEnd");
- BufferedReader reader = new BufferedReader(new FileReader(webXml));
- BufferedReader fragmentReader =
- new BufferedReader(new FileReader(webxmlFile));
- PrintWriter writer = new PrintWriter(new FileWriter(webXml2));
+ BufferedReader reader = new BufferedReader(openWebxmlReader(webXml));
+ BufferedReader fragmentReader = new BufferedReader(
+ openWebxmlReader(new File(webxmlFile)));
+ PrintWriter writer = new PrintWriter(openWebxmlWriter(webXml2));
// Insert the <servlet> and <servlet-mapping> declarations
- int pos = -1;
- String line = null;
- while (true) {
- line = reader.readLine();
- if (line == null) {
- break;
- }
- // Skip anything previously generated by JSPC
- if (line.indexOf(insertStartMarker) >= 0) {
- while (true) {
- line = reader.readLine();
- if (line == null) {
- return;
+ boolean inserted = false;
+ int current = reader.read();
+ while (current > -1) {
+ if (current == '<') {
+ String element = getElement(reader);
+ boolean found = false;
+ if (!inserted) {
+ for (String before : insertBefore) {
+ if (element.equals(before)) {
+ found = true;
+ break;
+ }
}
- if (line.indexOf(insertEndMarker) >= 0) {
- line = reader.readLine();
- line = reader.readLine();
+ }
+ if (found) {
+ // Insert generated content here
+ writer.println(insertStartMarker);
+ while (true) {
+ String line = fragmentReader.readLine();
if (line == null) {
- return;
+ writer.println();
+ break;
}
- break;
+ writer.println(line);
}
+ writer.println(insertEndMarker);
+ writer.println();
+ writer.write(element);
+ inserted = true;
+ } else if (element.equals(insertStartMarker)) {
+ // Skip the previous auto-generated content
+ while (true) {
+ current = reader.read();
+ if (current < 0) {
+ throw new EOFException();
+ }
+ if (current == '<') {
+ element = getElement(reader);
+ if (element.equals(insertEndMarker)) {
+ break;
+ }
+ }
+ }
+ current = reader.read();
+ while (current == '\n' || current == '\r') {
+ current = reader.read();
+ }
+ continue;
+ } else {
+ writer.write(element);
}
- }
- for (int i = 0; i < insertBefore.length; i++) {
- pos = line.indexOf(insertBefore[i]);
- if (pos >= 0)
- break;
- }
- if (pos >= 0) {
- writer.print(line.substring(0, pos));
- break;
} else {
- writer.println(line);
- }
- }
-
- writer.println(insertStartMarker);
- while (true) {
- String line2 = fragmentReader.readLine();
- if (line2 == null) {
- writer.println();
- break;
- }
- writer.println(line2);
- }
- writer.println(insertEndMarker);
- writer.println();
-
- for (int i = 0; i < pos; i++) {
- writer.print(" ");
- }
- writer.println(line.substring(pos));
-
- while (true) {
- line = reader.readLine();
- if (line == null) {
- break;
+ writer.write(current);
}
- writer.println(line);
+ current = reader.read();
}
writer.close();
@@ -1056,6 +1090,43 @@
}
+
+ /*
+ * Assumes valid xml
+ */
+ private String getElement(Reader reader) throws IOException {
+ StringBuilder result = new StringBuilder();
+ result.append('<');
+
+ boolean done = false;
+
+ while (!done) {
+ int current = reader.read();
+ while (current != '>') {
+ if (current < 0) {
+ throw new EOFException();
+ }
+ result.append((char) current);
+ current = reader.read();
+ }
+ result.append((char) current);
+
+ int len = result.length();
+ if (len > 4 && result.substring(0, 4).equals("<!--")) {
+ // This is a comment - make sure we are at the end
+ if (len >= 7 && result.substring(len - 3, len).equals("-->")) {
+ done = true;
+ }
+ } else {
+ done = true;
+ }
+ }
+
+
+ return result.toString();
+ }
+
+
protected void processFile(String file)
throws JasperException
{
@@ -1309,8 +1380,7 @@
protected void initWebXml() {
try {
if (webxmlLevel >= INC_WEBXML) {
- File fmapings = new File(webxmlFile);
- mapout = new FileWriter(fmapings);
+ mapout = openWebxmlWriter(new File(webxmlFile));
servletout = new CharArrayWriter();
mappingout = new CharArrayWriter();
} else {
@@ -1522,4 +1592,26 @@
return FileUtils.newFileUtils().resolveFile(getProject().getBaseDir(), s);
}
}
+
+ private Reader openWebxmlReader(File file) throws IOException {
+ FileInputStream fis = new FileInputStream(file);
+ try {
+ return webxmlEncoding != null ? new InputStreamReader(fis,
+ webxmlEncoding) : new InputStreamReader(fis);
+ } catch (IOException ex) {
+ fis.close();
+ throw ex;
+ }
+ }
+
+ private Writer openWebxmlWriter(File file) throws IOException {
+ FileOutputStream fos = new FileOutputStream(file);
+ try {
+ return webxmlEncoding != null ? new OutputStreamWriter(fos,
+ webxmlEncoding) : new OutputStreamWriter(fos);
+ } catch (IOException ex) {
+ fos.close();
+ throw ex;
+ }
+ }
}
Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties?rev=918597&r1=918596&r2=918597&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties Wed Mar 3 17:40:39 2010
@@ -251,6 +251,10 @@
\ -compile Compiles generated servlets\n\
\ -webinc <file> Creates a partial servlet mappings in the file\n\
\ -webxml <file> Creates a complete web.xml in the file\n\
+\ -webxmlencoding <enc> Set the encoding charset used to read and write the web.xml\n\
+\ file (default is platform default encoding)\n\
+\ -addwebxmlmappings Merge generated web.xml fragment into the web.xml file of the\n\
+\ web-app, whose JSP pages we are processing\n\
\ -ieplugin <clsid> Java Plugin classid for Internet Explorer\n\
\ -classpath <path> Overrides java.class.path system property\n\
\ -xpoweredBy Add X-Powered-By response header\n\
Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=918597&r1=918596&r2=918597&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Wed Mar 3 17:40:39 2010
@@ -50,6 +50,13 @@
<subsection name="Jasper">
<changelog>
<fix>
+ <bug>48371</bug>: Ensure generated servlet mappings are inserted at the
+ correct location when using JspC and allow the option that controls this
+ to be configured on the command line. Also allow the encoding of web.xml
+ to be configured when using JspC and deprecate some unused JspC methods.
+ (markt/kkolinko)
+ </fix>
+ <fix>
<bug>48498</bug>: Avoid ArrayIndexOutOfBoundsException triggered by a
Java 6/7 XML parser bug. (markt/kkolinko)
</fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org