Source Code Cross Referenced for Writer.java in  » J2EE » enhydra-IDE-plugin » org » enhydra » kelp » common » 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 » J2EE » enhydra IDE plugin » org.enhydra.kelp.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         * Paul Mahar
021:         *
022:         */
023:
024:        package org.enhydra.kelp.common;
025:
026:        // Kelp imports
027:        import org.enhydra.kelp.common.event.WriteEvent;
028:        import org.enhydra.kelp.common.event.WriteListener;
029:
030:        // Standard imports
031:        import java.io.StringWriter;
032:        import java.util.ArrayList;
033:        import java.util.Arrays;
034:
035:        /**
036:         * Class declaration
037:         *
038:         */
039:        public class Writer extends StringWriter {
040:            private WriteListener[] writeListeners = new WriteListener[0];
041:            private boolean buffered = false;
042:            private StringBuffer lineBuffer = new StringBuffer();
043:
044:            /**
045:             * Constructor declaration
046:             *
047:             */
048:            public Writer() {
049:            }
050:
051:            public void setLineBuffered(boolean b) {
052:                buffered = b;
053:            }
054:
055:            public boolean isLineBuffered() {
056:                return buffered;
057:            }
058:
059:            /**
060:             * Method declaration
061:             *
062:             *
063:             * @param c
064:             */
065:            public synchronized void write(int c) {
066:                char[] ca = new char[1];
067:
068:                ca[0] = (char) c;
069:                String cs = new String(ca);
070:
071:                write(cs);
072:            }
073:
074:            /**
075:             * Method declaration
076:             *
077:             *
078:             * @param str
079:             */
080:            public synchronized void write(String str) {
081:
082:                // if (isLineBuffered()) {
083:                // if (str != null && str.trim().length() > 0) {
084:                // write(str, 0, str.length());
085:                // }
086:                // } else {
087:                write(str, 0, str.length());
088:
089:                // }
090:            }
091:
092:            /**
093:             * Method declaration
094:             *
095:             *
096:             * @param str
097:             */
098:            public synchronized void writeln(String str) {
099:                write(str + '\n');
100:            }
101:
102:            /**
103:             * Method declaration
104:             *
105:             *
106:             * @param str
107:             * @param off
108:             * @param len
109:             */
110:            public synchronized void write(String str, int off, int len) {
111:                String out = str.substring(off, (off + len));
112:                boolean writeLine = false;
113:
114:                if (isLineBuffered()) {
115:                    if (out.length() > 1) {
116:                        char end1 = out.charAt(out.length() - 2);
117:                        char end2 = out.charAt(out.length() - 1);
118:
119:                        if ((int) end1 == 13 && (int) end2 == 10) {
120:                            if (out.length() < 3) {
121:                                out = new String();
122:                            } else {
123:                                out = out.substring(0, out.length() - 3);
124:                            }
125:                            writeLine = true;
126:                        }
127:                        if ((out.length() > 0)
128:                                && (out.charAt(out.length() - 1) == '\n')) {
129:                            writeLine = true;
130:                        }
131:                    }
132:                    if (writeLine) {
133:                        notifyWriteListeners(lineBuffer.toString() + out);
134:                        lineBuffer = new StringBuffer();
135:                    } else {
136:                        lineBuffer.append(out);
137:                    }
138:                } else {
139:                    notifyWriteListeners(out);
140:                }
141:            }
142:
143:            // event methods
144:
145:            /**
146:             * Method declaration
147:             *
148:             *
149:             * @param l
150:             */
151:            public synchronized void addWriteListener(WriteListener l) {
152:                ArrayList list = null;
153:                list = new ArrayList(Arrays.asList(writeListeners));
154:                if (!list.contains(l)) {
155:                    list.add(l);
156:                }
157:                list.trimToSize();
158:                writeListeners = new WriteListener[list.size()];
159:                writeListeners = (WriteListener[]) list.toArray(writeListeners);
160:                list.clear();
161:            }
162:
163:            /**
164:             * Method declaration
165:             *
166:             *
167:             * @param l
168:             */
169:            public synchronized void removeWriteListener(WriteListener l) {
170:                ArrayList list = null;
171:                list = new ArrayList(Arrays.asList(writeListeners));
172:                if (list.contains(l)) {
173:                    list.remove(l);
174:                }
175:                list.trimToSize();
176:                writeListeners = new WriteListener[list.size()];
177:                writeListeners = (WriteListener[]) list.toArray(writeListeners);
178:                list.clear();
179:            }
180:
181:            public synchronized WriteListener[] getWriteListeners() {
182:                return writeListeners;
183:            }
184:
185:            /**
186:             * Method declaration
187:             *
188:             *
189:             * @param s
190:             */
191:            private synchronized void notifyWriteListeners(String s) {
192:                WriteEvent event = new WriteEvent(this , WriteEvent.OUTPUT, s);
193:
194:                for (int i = 0; i < writeListeners.length; i++) {
195:                    writeListeners[i].onWrite(event);
196:                }
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.