Source Code Cross Referenced for SubstitutionWriter.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » utils » 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 » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2001 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.utils;
007:
008:        import java.io.IOException;
009:        import java.io.Writer;
010:
011:        /**
012:         * A filter presenting a <code>Writer</code> that performs
013:         * word substitution (search and replace) on the fly.
014:         *
015:         * 7/25/05 - UP-1180 - dmindler@rutgers.edu
016:         * Modified to make use of optimized SubstitutionIntegerFilter
017:         *
018:         * @author Peter Kharchenko  {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
019:         * @version $Revision: 36690 $
020:         */
021:        public class SubstitutionWriter extends Writer {
022:            SubstitutionIntegerFilter filter;
023:
024:            /**
025:             * Creates a new <code>SubstitutionWriter</code> instance.
026:             *
027:             * @param out a true <code>Writer</code> value where processed stream should be directed
028:             * @param target a <code>byte[]</code> value of a target to be replaced
029:             * @param substitute a <code>byte[]</code> value with which the target will be replaced
030:             * @param bufferSize a size of the buffer
031:             */
032:            public SubstitutionWriter(Writer out, char[] target,
033:                    char[] substitute, int bufferSize) {
034:                filter = new SubstitutionIntegerFilter(out, target, substitute,
035:                        bufferSize);
036:            }
037:
038:            /**
039:             * Creates a new <code>SubstitutionWriter</code> instance.
040:             *
041:             * @param out a true <code>Writer</code> value where processed stream should be directed
042:             * @param target a <code>byte[]</code> value of a target to be replaced
043:             * @param substitute a <code>byte[]</code> value with which the target will be replaced
044:             */
045:            public SubstitutionWriter(Writer out, char[] target,
046:                    char[] substitute) {
047:                filter = new SubstitutionIntegerFilter(out, target, substitute);
048:            }
049:
050:            public void write(int i) throws IOException {
051:                filter.write((char) i);
052:            }
053:
054:            public void flush() throws IOException {
055:                filter.flush();
056:            }
057:
058:            public void close() throws IOException {
059:                filter.close();
060:            }
061:
062:            public void write(char[] cbuf, int off, int len) throws IOException {
063:                // check boundaries
064:                if (off + len > cbuf.length)
065:                    throw new IOException("Invalid offsent or length specified");
066:
067:                for (int i = 0; i < len; i++) {
068:                    filter.write(cbuf[i]);
069:                }
070:            }
071:
072:            /**
073:             * A helper method to convert char array to int array.
074:             * I am sure there's a way to cast it correctly, but I don't want to take my chances :)
075:             * @param c a <code>char[]</code> value
076:             * @return an <code>int[]</code> value
077:             */
078:            private static int[] getIntArrayFromCharArray(char[] c) {
079:                int[] ic = new int[c.length];
080:                for (int i = 0; i < c.length; i++) {
081:                    ic[i] = (int) c[i];
082:                }
083:                return ic;
084:            }
085:
086:            /**
087:             * A test self-test method for the class.
088:             *
089:             */
090:            public static void main(String[] args) {
091:                // construct a string
092:                String inputString = "Marry had a little lamb, little lamb, little lamb.";
093:
094:                // set out the sink
095:                java.io.StringWriter sw = new java.io.StringWriter();
096:                SubstitutionWriter substw = new SubstitutionWriter(sw,
097:                        (new String("lamb")).toCharArray(),
098:                        (new String("rump")).toCharArray());
099:                try {
100:                    substw.write(inputString);
101:                    substw.flush();
102:                    String resultString = sw.toString();
103:                    if (resultString
104:                            .equals("Marry had a little rump, little rump, little rump.")) {
105:                        System.out.println("Test passed.");
106:                    } else {
107:                        System.out.println("Test failed!");
108:                    }
109:                } catch (Exception e) {
110:                    System.out.println("Test failed:");
111:                    e.printStackTrace();
112:                }
113:
114:            }
115:
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.