Source Code Cross Referenced for ServletContextWriter.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » struts 1.3.8 » org.apache.struts.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ServletContextWriter.java 471754 2006-11-06 14:55:09Z husted $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts.util;
022:
023:        import javax.servlet.ServletContext;
024:
025:        import java.io.PrintWriter;
026:        import java.io.StringWriter;
027:
028:        /**
029:         * A PrintWriter implementation that uses the logging facilities of a
030:         * <code>javax.servlet.ServletContext</code> to output its results.  Output
031:         * will be buffered until a newline character is output, <code>flush()</code>
032:         * is called, or until one of the <code>println()</code> methods is called.
033:         * Along the way, carriage return characters are skipped.
034:         *
035:         * @version $Rev: 471754 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
036:         *          $
037:         */
038:        public class ServletContextWriter extends PrintWriter {
039:            // ------------------------------------------------------------- Properties
040:
041:            /**
042:             * The buffer into which we accumulate lines to be logged.
043:             */
044:            protected StringBuffer buffer = new StringBuffer();
045:
046:            /**
047:             * The servlet context with which we are associated.
048:             */
049:            protected ServletContext context = null;
050:
051:            /**
052:             * The error state for this stream.
053:             */
054:            protected boolean error = false;
055:
056:            // ----------------------------------------------------------- Constructors
057:
058:            /**
059:             * Construct a ServletContextWriter associated with the specified
060:             * ServletContext instance.
061:             *
062:             * @param context The associated servlet context
063:             */
064:            public ServletContextWriter(ServletContext context) {
065:                super (new StringWriter());
066:                this .context = context;
067:            }
068:
069:            // --------------------------------------------------------- Public Methods
070:
071:            /**
072:             * Flush the stream and check for its error state.  <strong>IMPLEMENTATION
073:             * NOTE</strong> - our associated servlet context gives no indication of
074:             * problems with logging, so the only way this method will return
075:             * <code>true</code> is if <code>setError()</code> is called.
076:             */
077:            public boolean checkError() {
078:                flush();
079:
080:                return (error);
081:            }
082:
083:            /**
084:             * Close the stream.
085:             */
086:            public void close() {
087:                flush();
088:            }
089:
090:            /**
091:             * Flush the stream.
092:             */
093:            public void flush() {
094:                if (buffer.length() > 0) {
095:                    context.log(buffer.toString());
096:                    buffer.setLength(0);
097:                }
098:            }
099:
100:            /**
101:             * Print a boolean value.
102:             *
103:             * @param b The value to be printed
104:             */
105:            public void print(boolean b) {
106:                write(String.valueOf(b));
107:            }
108:
109:            /**
110:             * Print a character value.
111:             *
112:             * @param c The value to be printed
113:             */
114:            public void print(char c) {
115:                write(c);
116:            }
117:
118:            /**
119:             * Print a character array.
120:             *
121:             * @param c The character array to be printed
122:             */
123:            public void print(char[] c) {
124:                for (int i = 0; i < c.length; i++) {
125:                    write(c[i]);
126:                }
127:            }
128:
129:            /**
130:             * Print a double value.
131:             *
132:             * @param d The value to be printed
133:             */
134:            public void print(double d) {
135:                write(String.valueOf(d));
136:            }
137:
138:            /**
139:             * Print a float value.
140:             *
141:             * @param f The value to be printed
142:             */
143:            public void print(float f) {
144:                write(String.valueOf(f));
145:            }
146:
147:            /**
148:             * Print an integer value.
149:             *
150:             * @param i The value to be printed
151:             */
152:            public void print(int i) {
153:                write(String.valueOf(i));
154:            }
155:
156:            /**
157:             * Print a long value.
158:             *
159:             * @param l The value to be printed
160:             */
161:            public void print(long l) {
162:                write(String.valueOf(l));
163:            }
164:
165:            /**
166:             * Print an object.
167:             *
168:             * @param o The value to be printed
169:             */
170:            public void print(Object o) {
171:                write(o.toString());
172:            }
173:
174:            /**
175:             * Print a String value.
176:             *
177:             * @param s The value to be printed
178:             */
179:            public void print(String s) {
180:                int len = s.length();
181:
182:                for (int i = 0; i < len; i++) {
183:                    write(s.charAt(i));
184:                }
185:            }
186:
187:            /**
188:             * Terminate the current line and flush the buffer.
189:             */
190:            public void println() {
191:                flush();
192:            }
193:
194:            /**
195:             * Print a boolean value and terminate the line.
196:             *
197:             * @param b The value to be printed
198:             */
199:            public void println(boolean b) {
200:                println(String.valueOf(b));
201:            }
202:
203:            /**
204:             * Print a character value and terminate the line.
205:             *
206:             * @param c The value to be printed
207:             */
208:            public void println(char c) {
209:                write(c);
210:                println();
211:            }
212:
213:            /**
214:             * Print a character array and terminate the line.
215:             *
216:             * @param c The character array to be printed
217:             */
218:            public void println(char[] c) {
219:                for (int i = 0; i < c.length; i++) {
220:                    print(c[i]);
221:                }
222:
223:                println();
224:            }
225:
226:            /**
227:             * Print a double value and terminate the line.
228:             *
229:             * @param d The value to be printed
230:             */
231:            public void println(double d) {
232:                println(String.valueOf(d));
233:            }
234:
235:            /**
236:             * Print a float value and terminate the line.
237:             *
238:             * @param f The value to be printed
239:             */
240:            public void println(float f) {
241:                println(String.valueOf(f));
242:            }
243:
244:            /**
245:             * Print an integer value and terminate the line.
246:             *
247:             * @param i The value to be printed
248:             */
249:            public void println(int i) {
250:                println(String.valueOf(i));
251:            }
252:
253:            /**
254:             * Print a long value and terminate the line.
255:             *
256:             * @param l The value to be printed
257:             */
258:            public void println(long l) {
259:                println(String.valueOf(l));
260:            }
261:
262:            /**
263:             * Print an object and terminate the line.
264:             *
265:             * @param o The value to be printed
266:             */
267:            public void println(Object o) {
268:                println(o.toString());
269:            }
270:
271:            /**
272:             * Print a String value and terminate the line.
273:             *
274:             * @param s The value to be printed
275:             */
276:            public void println(String s) {
277:                int len = s.length();
278:
279:                for (int i = 0; i < len; i++) {
280:                    print(s.charAt(i));
281:                }
282:
283:                println();
284:            }
285:
286:            /**
287:             * Set the error state for this stream.
288:             */
289:            public void setError() {
290:                this .error = true;
291:            }
292:
293:            /**
294:             * Write a single character to this stream.
295:             *
296:             * @param c The character to be written
297:             */
298:            public void write(char c) {
299:                if (c == '\n') {
300:                    flush();
301:                } else if (c != '\r') {
302:                    buffer.append(c);
303:                }
304:            }
305:
306:            /**
307:             * Write a single character to this stream.
308:             *
309:             * @param c The character to be written
310:             */
311:            public void write(int c) {
312:                write((char) c);
313:            }
314:
315:            /**
316:             * Write an array of charaters to this stream.
317:             *
318:             * @param buf The character array to be written
319:             */
320:            public void write(char[] buf) {
321:                for (int i = 0; i < buf.length; i++) {
322:                    write(buf[i]);
323:                }
324:            }
325:
326:            /**
327:             * Write the specified subset of an array of characters to this stream.
328:             *
329:             * @param buf The character array from which to write
330:             * @param off The zero-relative starting offset to write
331:             * @param len The number of characters to write
332:             */
333:            public void write(char[] buf, int off, int len) {
334:                for (int i = off; i < len; i++) {
335:                    write(buf[i]);
336:                }
337:            }
338:
339:            /**
340:             * Write a String to this stream.
341:             *
342:             * @param s The string to be written
343:             */
344:            public void write(String s) {
345:                int len = s.length();
346:
347:                for (int i = 0; i < len; i++) {
348:                    write(s.charAt(i));
349:                }
350:            }
351:
352:            /**
353:             * Write the specified portion of a String to this stream.
354:             *
355:             * @param s   The String from which to write
356:             * @param off The zero-relative starting offset to write
357:             * @param len The number of characters to write
358:             */
359:            public void write(String s, int off, int len) {
360:                for (int i = off; i < len; i++) {
361:                    write(s.charAt(i));
362:                }
363:            }
364:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.