From 52d91d99639086827c79e1cace51d1f4e7886dc6 Mon Sep 17 00:00:00 2001 From: markt Date: Sat, 24 Jul 2010 12:23:44 +0000 Subject: [PATCH] Extend checks to webapps Tab police for /test and /webapps git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@978861 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 3 + .../loader/TestWebappClassLoaderMemoryLeak.java | 4 +- .../apache/catalina/mbeans/TestRegistration.java | 8 +- .../test/interceptors/TestOrderInterceptor.java | 4 +- .../test/membership/TestMemberSerialization.java | 6 +- .../docs/appdev/sample/src/mypackage/Hello.java | 43 +++--- .../examples/WEB-INF/classes/CookieExample.java | 4 +- .../WEB-INF/classes/HelloWorldExample.java | 14 +- .../WEB-INF/classes/RequestHeaderExample.java | 4 +- .../WEB-INF/classes/RequestInfoExample.java | 27 ++-- .../WEB-INF/classes/RequestParamExample.java | 4 +- webapps/examples/WEB-INF/classes/cal/Entries.java | 99 ++++++------- .../examples/WEB-INF/classes/cal/JspCalendar.java | 84 +++++------ .../examples/WEB-INF/classes/cal/TableBean.java | 164 ++++++++++----------- .../WEB-INF/classes/checkbox/CheckTest.java | 4 +- .../WEB-INF/classes/dates/JspCalendar.java | 106 ++++++------- webapps/examples/WEB-INF/classes/error/Smart.java | 46 +++--- .../examples/WEB-INF/classes/examples/FooTag.java | 2 +- .../WEB-INF/classes/examples/ShowSource.java | 4 +- .../classes/jsp2/examples/el/Functions.java | 12 +- .../jsp2/examples/simpletag/EchoAttributesTag.java | 18 +-- .../jsp2/examples/simpletag/FindBookSimpleTag.java | 2 +- .../examples/simpletag/HelloWorldSimpleTag.java | 2 +- .../jsp2/examples/simpletag/RepeatSimpleTag.java | 4 +- .../jsp2/examples/simpletag/TileSimpleTag.java | 6 +- .../WEB-INF/classes/listeners/ContextListener.java | 29 ++-- .../WEB-INF/classes/listeners/SessionListener.java | 130 ++++++++-------- webapps/examples/WEB-INF/classes/servletToJsp.java | 17 ++- 28 files changed, 413 insertions(+), 437 deletions(-) diff --git a/build.xml b/build.xml index c50268b03..fb8909de8 100644 --- a/build.xml +++ b/build.xml @@ -421,6 +421,9 @@ + + + diff --git a/test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java b/test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java index 526e22d32..f232591b8 100644 --- a/test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java +++ b/test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java @@ -56,9 +56,9 @@ public class TestWebappClassLoaderMemoryLeak extends TomcatBaseTest { // If the thread still exists, we have a thread/memory leak try { - Thread.sleep(10); + Thread.sleep(10); } catch(InterruptedException ie) { - // ignore + // ignore } Thread[] threads = getThreads(); for (Thread thread : threads) { diff --git a/test/org/apache/catalina/mbeans/TestRegistration.java b/test/org/apache/catalina/mbeans/TestRegistration.java index d137061e5..8f4ed612d 100644 --- a/test/org/apache/catalina/mbeans/TestRegistration.java +++ b/test/org/apache/catalina/mbeans/TestRegistration.java @@ -39,8 +39,8 @@ public class TestRegistration extends TomcatBaseTest { * registered. * @author Marc Guillemot */ - public void testMBeanDeregistration() throws Exception { - final MBeanServer mbeanServer = Registry.getRegistry(null, null).getMBeanServer(); + public void testMBeanDeregistration() throws Exception { + final MBeanServer mbeanServer = Registry.getRegistry(null, null).getMBeanServer(); Set onames = mbeanServer.queryNames(new ObjectName("Catalina:*"), null); assertEquals("Remaining: " + onames, 0, onames.size()); @@ -88,6 +88,6 @@ public class TestRegistration extends TomcatBaseTest { assertEquals("Remaining: " + onames, 0, onames.size()); onames = mbeanServer.queryNames(new ObjectName("Tomcat:*"), null); assertEquals("Remaining: " + onames, 0, onames.size()); - } - + } + } diff --git a/test/org/apache/catalina/tribes/test/interceptors/TestOrderInterceptor.java b/test/org/apache/catalina/tribes/test/interceptors/TestOrderInterceptor.java index b62e6983b..2d502a32c 100644 --- a/test/org/apache/catalina/tribes/test/interceptors/TestOrderInterceptor.java +++ b/test/org/apache/catalina/tribes/test/interceptors/TestOrderInterceptor.java @@ -119,8 +119,8 @@ public class TestOrderInterceptor extends TestCase { threads[i].join(); } if (!exceptionQueue.isEmpty()) { - fail("Exception while sending in threads: " - + exceptionQueue.remove().toString()); + fail("Exception while sending in threads: " + + exceptionQueue.remove().toString()); } Thread.sleep(5000); for ( int i=0; i"); - writer.println(""); - writer.println("Sample Application Servlet Page"); - writer.println(""); - writer.println(""); + writer.println(""); + writer.println(""); + writer.println("Sample Application Servlet Page"); + writer.println(""); + writer.println(""); - writer.println(""); - writer.println(""); - writer.println(""); - writer.println(""); - writer.println(""); - writer.println("
"); - writer.println(""); - writer.println(""); - writer.println("

Sample Application Servlet

"); - writer.println("This is the output of a servlet that is part of"); - writer.println("the Hello, World application."); - writer.println("
"); + writer.println(""); + writer.println(""); + writer.println(""); + writer.println(""); + writer.println(""); + writer.println("
"); + writer.println(""); + writer.println(""); + writer.println("

Sample Application Servlet

"); + writer.println("This is the output of a servlet that is part of"); + writer.println("the Hello, World application."); + writer.println("
"); - writer.println(""); - writer.println(""); + writer.println(""); + writer.println(""); } diff --git a/webapps/examples/WEB-INF/classes/CookieExample.java b/webapps/examples/WEB-INF/classes/CookieExample.java index e99e9a9b4..3c1c58ae3 100644 --- a/webapps/examples/WEB-INF/classes/CookieExample.java +++ b/webapps/examples/WEB-INF/classes/CookieExample.java @@ -54,12 +54,12 @@ public class CookieExample extends HttpServlet { out.println(""); out.println(""); - // relative links + // relative links // XXX // making these absolute till we work out the // addition of a PathInfo issue - + out.println(""); out.println("\"view"); diff --git a/webapps/examples/WEB-INF/classes/HelloWorldExample.java b/webapps/examples/WEB-INF/classes/HelloWorldExample.java index be8cb065d..cc2c6b67b 100644 --- a/webapps/examples/WEB-INF/classes/HelloWorldExample.java +++ b/webapps/examples/WEB-INF/classes/HelloWorldExample.java @@ -46,22 +46,22 @@ public class HelloWorldExample extends HttpServlet { out.println(""); out.println(""); - String title = rb.getString("helloworld.title"); + String title = rb.getString("helloworld.title"); - out.println("" + title + ""); + out.println("" + title + ""); out.println(""); out.println(""); - // note that all links are created to be relative. this - // ensures that we can move the web application that this - // servlet belongs to to a different place in the url - // tree and not have any harmful side effects. + // note that all links are created to be relative. this + // ensures that we can move the web application that this + // servlet belongs to to a different place in the url + // tree and not have any harmful side effects. // XXX // making these absolute till we work out the // addition of a PathInfo issue - out.println(""); + out.println(""); out.println("\"view"); out.println(""); diff --git a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java index 3d0be7c68..1dd7bacfb 100644 --- a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java +++ b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java @@ -54,12 +54,12 @@ public class RequestHeaderExample extends HttpServlet { out.println(""); out.println(""); - // all links relative + // all links relative // XXX // making these absolute till we work out the // addition of a PathInfo issue - + out.println(""); out.println("\"view"); diff --git a/webapps/examples/WEB-INF/classes/RequestInfoExample.java b/webapps/examples/WEB-INF/classes/RequestInfoExample.java index 256a5ed69..d9ad44a86 100644 --- a/webapps/examples/WEB-INF/classes/RequestInfoExample.java +++ b/webapps/examples/WEB-INF/classes/RequestInfoExample.java @@ -55,12 +55,12 @@ public class RequestInfoExample extends HttpServlet { out.println(""); // img stuff not req'd for source code html showing - // all links relative! + // all links relative! // XXX // making these absolute till we work out the // addition of a PathInfo issue - + out.println(""); out.println("\"view"); @@ -88,21 +88,20 @@ public class RequestInfoExample extends HttpServlet { out.println(""); out.println(RB.getString("requestinfo.label.remoteaddr")); - String cipherSuite= - (String)request.getAttribute("javax.servlet.request.cipher_suite"); + String cipherSuite= + (String)request.getAttribute("javax.servlet.request.cipher_suite"); out.println(""); out.println(request.getRemoteAddr()); out.println(""); - - if(cipherSuite!=null){ - out.println(""); - out.println("SSLCipherSuite:"); - out.println(""); - out.println(""); - out.println(request.getAttribute("javax.servlet.request.cipher_suite")); - out.println(""); - } - + + if(cipherSuite!=null){ + out.println(""); + out.println("SSLCipherSuite:"); + out.println(""); + out.println(""); + out.println(request.getAttribute("javax.servlet.request.cipher_suite")); + out.println(""); + } } @Override diff --git a/webapps/examples/WEB-INF/classes/RequestParamExample.java b/webapps/examples/WEB-INF/classes/RequestParamExample.java index 984de8e0e..9a7ab4220 100644 --- a/webapps/examples/WEB-INF/classes/RequestParamExample.java +++ b/webapps/examples/WEB-INF/classes/RequestParamExample.java @@ -56,12 +56,12 @@ public class RequestParamExample extends HttpServlet { // img stuff not req'd for source code html showing - // all links relative + // all links relative // XXX // making these absolute till we work out the // addition of a PathInfo issue - + out.println(""); out.println("\"view"); diff --git a/webapps/examples/WEB-INF/classes/cal/Entries.java b/webapps/examples/WEB-INF/classes/cal/Entries.java index 9b5d587d5..03afc7e40 100644 --- a/webapps/examples/WEB-INF/classes/cal/Entries.java +++ b/webapps/examples/WEB-INF/classes/cal/Entries.java @@ -1,19 +1,19 @@ /* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You 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. -*/ + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 cal; import java.util.Hashtable; @@ -21,52 +21,39 @@ import javax.servlet.http.*; public class Entries { - private Hashtable entries; - private static final String[] time = {"8am", "9am", "10am", "11am", "12pm", - "1pm", "2pm", "3pm", "4pm", "5pm", "6pm", - "7pm", "8pm" }; - public static final int rows = 12; + private Hashtable entries; + private static final String[] time = { "8am", "9am", "10am", "11am", + "12pm", "1pm", "2pm", "3pm", "4pm", "5pm", "6pm", "7pm", "8pm" }; + public static final int rows = 12; - public Entries () { - entries = new Hashtable (rows); - for (int i=0; i < rows; i++) { - entries.put (time[i], new Entry(time[i])); - } - } + public Entries() { + entries = new Hashtable(rows); + for (int i = 0; i < rows; i++) { + entries.put(time[i], new Entry(time[i])); + } + } - public int getRows () { - return rows; - } + public int getRows() { + return rows; + } - public Entry getEntry (int index) { - return this.entries.get(time[index]); - } + public Entry getEntry(int index) { + return this.entries.get(time[index]); + } - public int getIndex (String tm) { - for (int i=0; i= 0) { - String descr = request.getParameter ("description"); - entries.get(time[index]).setDescription (descr); + public void processRequest(HttpServletRequest request, String tm) { + int index = getIndex(tm); + if (index >= 0) { + String descr = request.getParameter("description"); + entries.get(time[index]).setDescription(descr); + } } - } } - - - - - - - - - - - - - diff --git a/webapps/examples/WEB-INF/classes/cal/JspCalendar.java b/webapps/examples/WEB-INF/classes/cal/JspCalendar.java index a15242cba..34d1c5b80 100644 --- a/webapps/examples/WEB-INF/classes/cal/JspCalendar.java +++ b/webapps/examples/WEB-INF/classes/cal/JspCalendar.java @@ -23,127 +23,127 @@ public class JspCalendar { Calendar calendar = null; public JspCalendar() { - calendar = Calendar.getInstance(); - Date trialTime = new Date(); - calendar.setTime(trialTime); + calendar = Calendar.getInstance(); + Date trialTime = new Date(); + calendar.setTime(trialTime); } public int getYear() { - return calendar.get(Calendar.YEAR); + return calendar.get(Calendar.YEAR); } public String getMonth() { - int m = getMonthInt(); - String[] months = new String [] { "January", "February", "March", - "April", "May", "June", - "July", "August", "September", - "October", "November", "December" }; - if (m > 12) - return "Unknown to Man"; - - return months[m - 1]; + int m = getMonthInt(); + String[] months = new String [] { "January", "February", "March", + "April", "May", "June", + "July", "August", "September", + "October", "November", "December" }; + if (m > 12) + return "Unknown to Man"; + + return months[m - 1]; } public String getDay() { - int x = getDayOfWeek(); - String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday"}; + int x = getDayOfWeek(); + String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday"}; - if (x > 7) - return "Unknown to Man"; + if (x > 7) + return "Unknown to Man"; - return days[x - 1]; + return days[x - 1]; } public int getMonthInt() { - return 1 + calendar.get(Calendar.MONTH); + return 1 + calendar.get(Calendar.MONTH); } public String getDate() { - return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear(); + return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear(); } public String getCurrentDate() { Date dt = new Date (); - calendar.setTime (dt); - return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear(); + calendar.setTime (dt); + return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear(); } public String getNextDate() { calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1); - return getDate (); + return getDate (); } public String getPrevDate() { calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1); - return getDate (); + return getDate (); } public String getTime() { - return getHour() + ":" + getMinute() + ":" + getSecond(); + return getHour() + ":" + getMinute() + ":" + getSecond(); } public int getDayOfMonth() { - return calendar.get(Calendar.DAY_OF_MONTH); + return calendar.get(Calendar.DAY_OF_MONTH); } public int getDayOfYear() { - return calendar.get(Calendar.DAY_OF_YEAR); + return calendar.get(Calendar.DAY_OF_YEAR); } public int getWeekOfYear() { - return calendar.get(Calendar.WEEK_OF_YEAR); + return calendar.get(Calendar.WEEK_OF_YEAR); } public int getWeekOfMonth() { - return calendar.get(Calendar.WEEK_OF_MONTH); + return calendar.get(Calendar.WEEK_OF_MONTH); } public int getDayOfWeek() { - return calendar.get(Calendar.DAY_OF_WEEK); + return calendar.get(Calendar.DAY_OF_WEEK); } public int getHour() { - return calendar.get(Calendar.HOUR_OF_DAY); + return calendar.get(Calendar.HOUR_OF_DAY); } public int getMinute() { - return calendar.get(Calendar.MINUTE); + return calendar.get(Calendar.MINUTE); } public int getSecond() { - return calendar.get(Calendar.SECOND); + return calendar.get(Calendar.SECOND); } public int getEra() { - return calendar.get(Calendar.ERA); + return calendar.get(Calendar.ERA); } public String getUSTimeZone() { - String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific", - "Mountain", "Central", "Eastern"}; - - return zones[10 + getZoneOffset()]; + String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific", + "Mountain", "Central", "Eastern"}; + + return zones[10 + getZoneOffset()]; } public int getZoneOffset() { - return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000); + return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000); } public int getDSTOffset() { - return calendar.get(Calendar.DST_OFFSET)/(60*60*1000); + return calendar.get(Calendar.DST_OFFSET)/(60*60*1000); } public int getAMPM() { - return calendar.get(Calendar.AM_PM); + return calendar.get(Calendar.AM_PM); } } diff --git a/webapps/examples/WEB-INF/classes/cal/TableBean.java b/webapps/examples/WEB-INF/classes/cal/TableBean.java index cddd92e11..d158a669b 100644 --- a/webapps/examples/WEB-INF/classes/cal/TableBean.java +++ b/webapps/examples/WEB-INF/classes/cal/TableBean.java @@ -1,19 +1,19 @@ /* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You 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. -*/ + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 cal; import javax.servlet.http.*; @@ -21,80 +21,80 @@ import java.util.Hashtable; public class TableBean { - Hashtable table; - JspCalendar JspCal; - Entries entries; - String date; - String name = null; - String email = null; - boolean processError = false; - - public TableBean () { - this.table = new Hashtable (10); - this.JspCal = new JspCalendar (); - this.date = JspCal.getCurrentDate (); - } - - public void setName (String nm) { - this.name = nm; - } - - public String getName () { - return this.name; - } - - public void setEmail (String mail) { - this.email = mail; - } - - public String getEmail () { - return this.email; - } - - public String getDate () { - return this.date; - } - - public Entries getEntries () { - return this.entries; - } - - public void processRequest (HttpServletRequest request) { - - // Get the name and e-mail. - this.processError = false; - if (name == null || name.equals("")) setName(request.getParameter ("name")); - if (email == null || email.equals("")) setEmail(request.getParameter ("email")); - if (name == null || email == null || - name.equals("") || email.equals("")) { - this.processError = true; - return; + Hashtable table; + JspCalendar JspCal; + Entries entries; + String date; + String name = null; + String email = null; + boolean processError = false; + + public TableBean() { + this.table = new Hashtable(10); + this.JspCal = new JspCalendar(); + this.date = JspCal.getCurrentDate(); } - // Get the date. - String dateR = request.getParameter ("date"); - if (dateR == null) date = JspCal.getCurrentDate (); - else if (dateR.equalsIgnoreCase("next")) date = JspCal.getNextDate (); - else if (dateR.equalsIgnoreCase("prev")) date = JspCal.getPrevDate (); - - entries = table.get (date); - if (entries == null) { - entries = new Entries (); - table.put (date, entries); + public void setName(String nm) { + this.name = nm; } - // If time is provided add the event. - String time = request.getParameter("time"); - if (time != null) entries.processRequest (request, time); - } - - public boolean getProcessError () { - return this.processError; - } -} + public String getName() { + return this.name; + } + public void setEmail(String mail) { + this.email = mail; + } + public String getEmail() { + return this.email; + } + public String getDate() { + return this.date; + } + public Entries getEntries() { + return this.entries; + } + public void processRequest(HttpServletRequest request) { + + // Get the name and e-mail. + this.processError = false; + if (name == null || name.equals("")) + setName(request.getParameter("name")); + if (email == null || email.equals("")) + setEmail(request.getParameter("email")); + if (name == null || email == null || name.equals("") + || email.equals("")) { + this.processError = true; + return; + } + + // Get the date. + String dateR = request.getParameter("date"); + if (dateR == null) + date = JspCal.getCurrentDate(); + else if (dateR.equalsIgnoreCase("next")) + date = JspCal.getNextDate(); + else if (dateR.equalsIgnoreCase("prev")) + date = JspCal.getPrevDate(); + + entries = table.get(date); + if (entries == null) { + entries = new Entries(); + table.put(date, entries); + } + + // If time is provided add the event. + String time = request.getParameter("time"); + if (time != null) + entries.processRequest(request, time); + } + public boolean getProcessError() { + return this.processError; + } +} diff --git a/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java b/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java index 73070214e..e38269c95 100644 --- a/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java +++ b/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java @@ -22,10 +22,10 @@ public class CheckTest { String b[] = new String[] { "1", "2", "3", "4" }; public String[] getFruit() { - return b; + return b; } public void setFruit(String [] b) { - this.b = b; + this.b = b; } } diff --git a/webapps/examples/WEB-INF/classes/dates/JspCalendar.java b/webapps/examples/WEB-INF/classes/dates/JspCalendar.java index 82fadd451..0008ca13f 100644 --- a/webapps/examples/WEB-INF/classes/dates/JspCalendar.java +++ b/webapps/examples/WEB-INF/classes/dates/JspCalendar.java @@ -22,131 +22,131 @@ public class JspCalendar { Calendar calendar = null; public JspCalendar() { - calendar = Calendar.getInstance(); - Date trialTime = new Date(); - calendar.setTime(trialTime); + calendar = Calendar.getInstance(); + Date trialTime = new Date(); + calendar.setTime(trialTime); } public int getYear() { - return calendar.get(Calendar.YEAR); + return calendar.get(Calendar.YEAR); } public String getMonth() { - int m = getMonthInt(); - String[] months = new String [] { "January", "February", "March", - "April", "May", "June", - "July", "August", "September", - "October", "November", "December" }; - if (m > 12) - return "Unknown to Man"; - - return months[m - 1]; + int m = getMonthInt(); + String[] months = new String [] { "January", "February", "March", + "April", "May", "June", + "July", "August", "September", + "October", "November", "December" }; + if (m > 12) + return "Unknown to Man"; + + return months[m - 1]; } public String getDay() { - int x = getDayOfWeek(); - String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday"}; + int x = getDayOfWeek(); + String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday"}; - if (x > 7) - return "Unknown to Man"; + if (x > 7) + return "Unknown to Man"; - return days[x - 1]; + return days[x - 1]; } public int getMonthInt() { - return 1 + calendar.get(Calendar.MONTH); + return 1 + calendar.get(Calendar.MONTH); } public String getDate() { - return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear(); + return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear(); } public String getTime() { - return getHour() + ":" + getMinute() + ":" + getSecond(); + return getHour() + ":" + getMinute() + ":" + getSecond(); } public int getDayOfMonth() { - return calendar.get(Calendar.DAY_OF_MONTH); + return calendar.get(Calendar.DAY_OF_MONTH); } public int getDayOfYear() { - return calendar.get(Calendar.DAY_OF_YEAR); + return calendar.get(Calendar.DAY_OF_YEAR); } public int getWeekOfYear() { - return calendar.get(Calendar.WEEK_OF_YEAR); + return calendar.get(Calendar.WEEK_OF_YEAR); } public int getWeekOfMonth() { - return calendar.get(Calendar.WEEK_OF_MONTH); + return calendar.get(Calendar.WEEK_OF_MONTH); } public int getDayOfWeek() { - return calendar.get(Calendar.DAY_OF_WEEK); + return calendar.get(Calendar.DAY_OF_WEEK); } public int getHour() { - return calendar.get(Calendar.HOUR_OF_DAY); + return calendar.get(Calendar.HOUR_OF_DAY); } public int getMinute() { - return calendar.get(Calendar.MINUTE); + return calendar.get(Calendar.MINUTE); } public int getSecond() { - return calendar.get(Calendar.SECOND); + return calendar.get(Calendar.SECOND); } public static void main(String args[]) { - JspCalendar db = new JspCalendar(); - p("date: " + db.getDayOfMonth()); - p("year: " + db.getYear()); - p("month: " + db.getMonth()); - p("time: " + db.getTime()); - p("date: " + db.getDate()); - p("Day: " + db.getDay()); - p("DayOfYear: " + db.getDayOfYear()); - p("WeekOfYear: " + db.getWeekOfYear()); - p("era: " + db.getEra()); - p("ampm: " + db.getAMPM()); - p("DST: " + db.getDSTOffset()); - p("ZONE Offset: " + db.getZoneOffset()); - p("TIMEZONE: " + db.getUSTimeZone()); + JspCalendar db = new JspCalendar(); + p("date: " + db.getDayOfMonth()); + p("year: " + db.getYear()); + p("month: " + db.getMonth()); + p("time: " + db.getTime()); + p("date: " + db.getDate()); + p("Day: " + db.getDay()); + p("DayOfYear: " + db.getDayOfYear()); + p("WeekOfYear: " + db.getWeekOfYear()); + p("era: " + db.getEra()); + p("ampm: " + db.getAMPM()); + p("DST: " + db.getDSTOffset()); + p("ZONE Offset: " + db.getZoneOffset()); + p("TIMEZONE: " + db.getUSTimeZone()); } private static void p(String x) { - System.out.println(x); + System.out.println(x); } public int getEra() { - return calendar.get(Calendar.ERA); + return calendar.get(Calendar.ERA); } public String getUSTimeZone() { - String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific", - "Mountain", "Central", "Eastern"}; - - return zones[10 + getZoneOffset()]; + String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific", + "Mountain", "Central", "Eastern"}; + + return zones[10 + getZoneOffset()]; } public int getZoneOffset() { - return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000); + return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000); } public int getDSTOffset() { - return calendar.get(Calendar.DST_OFFSET)/(60*60*1000); + return calendar.get(Calendar.DST_OFFSET)/(60*60*1000); } public int getAMPM() { - return calendar.get(Calendar.AM_PM); + return calendar.get(Calendar.AM_PM); } } diff --git a/webapps/examples/WEB-INF/classes/error/Smart.java b/webapps/examples/WEB-INF/classes/error/Smart.java index 94beb3958..82c22f6f5 100644 --- a/webapps/examples/WEB-INF/classes/error/Smart.java +++ b/webapps/examples/WEB-INF/classes/error/Smart.java @@ -1,32 +1,30 @@ /* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You 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. -*/ - - + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 error; public class Smart { - String name = "JSP"; + String name = "JSP"; - public String getName () { - return name; - } + public String getName() { + return name; + } - public void setName (String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } } diff --git a/webapps/examples/WEB-INF/classes/examples/FooTag.java b/webapps/examples/WEB-INF/classes/examples/FooTag.java index fba2bc661..6f716578a 100644 --- a/webapps/examples/WEB-INF/classes/examples/FooTag.java +++ b/webapps/examples/WEB-INF/classes/examples/FooTag.java @@ -57,7 +57,7 @@ public class FooTag extends ExampleTagBase { @Override public int doStartTag() throws JspException { i = 0; - return EVAL_BODY_BUFFERED; + return EVAL_BODY_BUFFERED; } @Override diff --git a/webapps/examples/WEB-INF/classes/examples/ShowSource.java b/webapps/examples/WEB-INF/classes/examples/ShowSource.java index dda3aa02b..1c74c5775 100644 --- a/webapps/examples/WEB-INF/classes/examples/ShowSource.java +++ b/webapps/examples/WEB-INF/classes/examples/ShowSource.java @@ -38,10 +38,10 @@ public class ShowSource extends TagSupport { @Override public int doEndTag() throws JspException { - if ((jspFile.indexOf( ".." ) >= 0) || + if ((jspFile.indexOf( ".." ) >= 0) || (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/WEB-INF/") != 0) || (jspFile.toUpperCase(Locale.ENGLISH).indexOf("/META-INF/") != 0)) - throw new JspTagException("Invalid JSP file " + jspFile); + throw new JspTagException("Invalid JSP file " + jspFile); InputStream in = pageContext.getServletContext().getResourceAsStream(jspFile); diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java b/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java index f3b665fca..e8ccb8271 100644 --- a/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java @@ -30,13 +30,13 @@ public class Functions { public static int numVowels( String text ) { String vowels = "aeiouAEIOU"; - int result = 0; + int result = 0; for( int i = 0; i < text.length(); i++ ) { - if( vowels.indexOf( text.charAt( i ) ) != -1 ) { - result++; - } - } - return result; + if( vowels.indexOf( text.charAt( i ) ) != -1 ) { + result++; + } + } + return result; } public static String caps( String text ) { diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java index 97d9e0e17..9a9e9d10f 100644 --- a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java @@ -37,19 +37,19 @@ public class EchoAttributesTag @Override public void doTag() throws JspException, IOException { - JspWriter out = getJspContext().getOut(); - for( int i = 0; i < keys.size(); i++ ) { - String key = keys.get( i ); - Object value = values.get( i ); - out.println( "
  • " + key + " = " + value + "
  • " ); + JspWriter out = getJspContext().getOut(); + for( int i = 0; i < keys.size(); i++ ) { + String key = keys.get( i ); + Object value = values.get( i ); + out.println( "
  • " + key + " = " + value + "
  • " ); } } public void setDynamicAttribute( String uri, String localName, - Object value ) - throws JspException + Object value ) + throws JspException { - keys.add( localName ); - values.add( value ); + keys.add( localName ); + values.add( value ); } } diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java index 9cccdac29..c607f1cff 100644 --- a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java @@ -40,6 +40,6 @@ public class FindBookSimpleTag extends SimpleTagSupport { } public void setVar( String var ) { - this.var = var; + this.var = var; } } diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java index 38a6cd321..b63ef613d 100644 --- a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java @@ -28,6 +28,6 @@ import java.io.IOException; public class HelloWorldSimpleTag extends SimpleTagSupport { @Override public void doTag() throws JspException, IOException { - getJspContext().getOut().write( "Hello, world!" ); + getJspContext().getOut().write( "Hello, world!" ); } } diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java index 5d4c5b1c3..38633d9d7 100644 --- a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java @@ -33,11 +33,11 @@ public class RepeatSimpleTag extends SimpleTagSupport { public void doTag() throws JspException, IOException { for (int i=0; i
    " + this.label + + getJspContext().getOut().write( + "
    " + this.label + "
    " ); } diff --git a/webapps/examples/WEB-INF/classes/listeners/ContextListener.java b/webapps/examples/WEB-INF/classes/listeners/ContextListener.java index 370628279..8152b5f15 100644 --- a/webapps/examples/WEB-INF/classes/listeners/ContextListener.java +++ b/webapps/examples/WEB-INF/classes/listeners/ContextListener.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package listeners; @@ -58,8 +57,8 @@ public final class ContextListener */ public void attributeAdded(ServletContextAttributeEvent event) { - log("attributeAdded('" + event.getName() + "', '" + - event.getValue() + "')"); + log("attributeAdded('" + event.getName() + "', '" + + event.getValue() + "')"); } @@ -71,8 +70,8 @@ public final class ContextListener */ public void attributeRemoved(ServletContextAttributeEvent event) { - log("attributeRemoved('" + event.getName() + "', '" + - event.getValue() + "')"); + log("attributeRemoved('" + event.getName() + "', '" + + event.getValue() + "')"); } @@ -84,8 +83,8 @@ public final class ContextListener */ public void attributeReplaced(ServletContextAttributeEvent event) { - log("attributeReplaced('" + event.getName() + "', '" + - event.getValue() + "')"); + log("attributeReplaced('" + event.getName() + "', '" + + event.getValue() + "')"); } @@ -97,8 +96,8 @@ public final class ContextListener */ public void contextDestroyed(ServletContextEvent event) { - log("contextDestroyed()"); - this.context = null; + log("contextDestroyed()"); + this.context = null; } @@ -110,8 +109,8 @@ public final class ContextListener */ public void contextInitialized(ServletContextEvent event) { - this.context = event.getServletContext(); - log("contextInitialized()"); + this.context = event.getServletContext(); + log("contextInitialized()"); } @@ -126,10 +125,10 @@ public final class ContextListener */ private void log(String message) { - if (context != null) - context.log("ContextListener: " + message); - else - System.out.println("ContextListener: " + message); + if (context != null) + context.log("ContextListener: " + message); + else + System.out.println("ContextListener: " + message); } diff --git a/webapps/examples/WEB-INF/classes/listeners/SessionListener.java b/webapps/examples/WEB-INF/classes/listeners/SessionListener.java index 82e003c17..084b08f3f 100644 --- a/webapps/examples/WEB-INF/classes/listeners/SessionListener.java +++ b/webapps/examples/WEB-INF/classes/listeners/SessionListener.java @@ -1,23 +1,21 @@ /* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You 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. -*/ - + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 listeners; - import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @@ -26,137 +24,131 @@ import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; - /** * Example listener for context-related application events, which were - * introduced in the 2.3 version of the Servlet API. This listener - * merely documents the occurrence of such events in the application log - * associated with our servlet context. - * + * introduced in the 2.3 version of the Servlet API. This listener merely + * documents the occurrence of such events in the application log associated + * with our servlet context. + * * @author Craig R. McClanahan * @version $Id$ */ -public final class SessionListener - implements ServletContextListener, - HttpSessionAttributeListener, HttpSessionListener { - +public final class SessionListener implements ServletContextListener, + HttpSessionAttributeListener, HttpSessionListener { // ----------------------------------------------------- Instance Variables - /** * The servlet context with which we are associated. */ private ServletContext context = null; - // --------------------------------------------------------- Public Methods - /** * Record the fact that a servlet context attribute was added. - * - * @param event The session attribute event + * + * @param event + * The session attribute event */ public void attributeAdded(HttpSessionBindingEvent event) { - log("attributeAdded('" + event.getSession().getId() + "', '" + - event.getName() + "', '" + event.getValue() + "')"); + log("attributeAdded('" + event.getSession().getId() + "', '" + + event.getName() + "', '" + event.getValue() + "')"); } - /** * Record the fact that a servlet context attribute was removed. - * - * @param event The session attribute event + * + * @param event + * The session attribute event */ public void attributeRemoved(HttpSessionBindingEvent event) { - log("attributeRemoved('" + event.getSession().getId() + "', '" + - event.getName() + "', '" + event.getValue() + "')"); + log("attributeRemoved('" + event.getSession().getId() + "', '" + + event.getName() + "', '" + event.getValue() + "')"); } - /** * Record the fact that a servlet context attribute was replaced. - * - * @param event The session attribute event + * + * @param event + * The session attribute event */ public void attributeReplaced(HttpSessionBindingEvent event) { - log("attributeReplaced('" + event.getSession().getId() + "', '" + - event.getName() + "', '" + event.getValue() + "')"); + log("attributeReplaced('" + event.getSession().getId() + "', '" + + event.getName() + "', '" + event.getValue() + "')"); } - /** * Record the fact that this web application has been destroyed. - * - * @param event The servlet context event + * + * @param event + * The servlet context event */ public void contextDestroyed(ServletContextEvent event) { - log("contextDestroyed()"); - this.context = null; + log("contextDestroyed()"); + this.context = null; } - /** * Record the fact that this web application has been initialized. - * - * @param event The servlet context event + * + * @param event + * The servlet context event */ public void contextInitialized(ServletContextEvent event) { - this.context = event.getServletContext(); - log("contextInitialized()"); + this.context = event.getServletContext(); + log("contextInitialized()"); } - /** * Record the fact that a session has been created. - * - * @param event The session event + * + * @param event + * The session event */ public void sessionCreated(HttpSessionEvent event) { - log("sessionCreated('" + event.getSession().getId() + "')"); + log("sessionCreated('" + event.getSession().getId() + "')"); } - /** * Record the fact that a session has been destroyed. - * - * @param event The session event + * + * @param event + * The session event */ public void sessionDestroyed(HttpSessionEvent event) { - log("sessionDestroyed('" + event.getSession().getId() + "')"); + log("sessionDestroyed('" + event.getSession().getId() + "')"); } - // -------------------------------------------------------- Private Methods - /** * Log a message to the servlet context application log. - * - * @param message Message to be logged + * + * @param message + * Message to be logged */ private void log(String message) { - if (context != null) - context.log("SessionListener: " + message); - else - System.out.println("SessionListener: " + message); + if (context != null) + context.log("SessionListener: " + message); + else + System.out.println("SessionListener: " + message); } diff --git a/webapps/examples/WEB-INF/classes/servletToJsp.java b/webapps/examples/WEB-INF/classes/servletToJsp.java index ffc2737fa..0bc8739ab 100644 --- a/webapps/examples/WEB-INF/classes/servletToJsp.java +++ b/webapps/examples/WEB-INF/classes/servletToJsp.java @@ -22,14 +22,15 @@ public class servletToJsp extends HttpServlet { @Override public void doGet (HttpServletRequest request, - HttpServletResponse response) { + HttpServletResponse response) { - try { - // Set the attribute and Forward to hello.jsp - request.setAttribute ("servletName", "servletToJsp"); - getServletConfig().getServletContext().getRequestDispatcher("/jsp/jsptoserv/hello.jsp").forward(request, response); - } catch (Exception ex) { - ex.printStackTrace (); - } + try { + // Set the attribute and Forward to hello.jsp + request.setAttribute ("servletName", "servletToJsp"); + getServletConfig().getServletContext().getRequestDispatcher( + "/jsp/jsptoserv/hello.jsp").forward(request, response); + } catch (Exception ex) { + ex.printStackTrace (); + } } } -- 2.11.0