Source Code Cross Referenced for CharacterSubstitution.java in  » Web-Mail » Jwma » dtw » webmail » 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 Mail » Jwma » dtw.webmail.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /***
02:         * jwma Java WebMail
03:         * Copyright (c) 2000-2003 jwma team
04:         *
05:         * jwma is free software; you can distribute and use this source
06:         * under the terms of the BSD-style license received along with
07:         * the distribution.
08:         ***/package dtw.webmail.util;
09:
10:        import org.apache.oro.text.regex.*;
11:
12:        /**
13:         * Class that implements a Substitution, replacing special
14:         * HTML unsafe characters with their entity representations.
15:         *
16:         * @author Dieter Wimberger
17:         * @version 0.9.7 07/02/2003
18:         */
19:        public class CharacterSubstitution implements  Substitution {
20:
21:            /**
22:             * Appends the substitution to a buffer containing the original input
23:             * with substitutions applied for the pattern matches found so far.
24:             * For maximum flexibility, the original input as well as the
25:             * PatternMatcher and Pattern used to find the match are included as
26:             * arguments.  However, you will almost never find a need to use those
27:             * arguments when creating your own Substitution implementations.
28:             * <p>
29:             * For performance reasons, rather than provide a getSubstitution method
30:             * that returns a String used by Util.substitute, we have opted to pass
31:             * a StringBuffer argument from Util.substitute to which the Substitution
32:             * must append data.  The contract that an appendSubstitution
33:             * implementation must abide by is that the appendBuffer may only be
34:             * appended to.  appendSubstitution() may not alter the appendBuffer in
35:             * any way other than appending to it.
36:             * <p>
37:             * This method is invoked by Util.substitute every time it finds a match.
38:             * After finding a match, Util.substitute appends to the appendBuffer
39:             * all of the original input occuring between the end of the last match
40:             * and the beginning of the current match.  Then it invokes
41:             * appendSubstitution(), passing the appendBuffer, current match, and
42:             * other information as arguments.  The substitutionCount keeps track
43:             * of how many substitutions have been performed so far by an invocation
44:             * of Util.substitute.  Its value starts at 1 when the first substitution
45:             * is found and appendSubstitution is invoked for the first time.  It
46:             * will NEVER be zero or a negative value.
47:             * <p>
48:             * @param appendBuffer The buffer containing the new string resulting
49:             * from performing substitutions on the original input.
50:             * @param match The current match causing a substitution to be made.
51:             * @param substitutionCount  The number of substitutions that have been
52:             *  performed so far by Util.substitute.
53:             * @param originalInput The original input upon which the substitutions are
54:             * being performed.
55:             * @param matcher The PatternMatcher used to find the current match.
56:             * @param pattern The Pattern used to find the current match.
57:             */
58:            public void appendSubstitution(StringBuffer appendBuffer,
59:                    MatchResult match, int substitutionCount,
60:                    PatternMatcherInput originalInput, PatternMatcher matcher,
61:                    Pattern pattern) {
62:
63:                char c = match.toString().charAt(0);
64:                appendBuffer.append(char2Entity(c));
65:
66:            }//appendSubstitution
67:
68:            /**
69:             * Translates (a few) chars to their corresponding entity.
70:             */
71:            private String char2Entity(char c) {
72:                switch (c) {
73:                case AMPERSAND_CHAR:
74:                    return AMPERSAND_ENTITY;
75:                case GT_CHAR:
76:                    return GT_ENTITY;
77:                case LT_CHAR:
78:                    return LT_ENTITY;
79:                case QUOT_CHAR:
80:                    return QUOT_ENTITY;
81:                default:
82:                    return "" + c;
83:                }
84:
85:            }//char2Entity
86:
87:            private static final char AMPERSAND_CHAR = '&';
88:            private static final String AMPERSAND_ENTITY = "&amp;";
89:            private static final char GT_CHAR = '>';
90:            private static final String GT_ENTITY = "&gt;";
91:            private static final char LT_CHAR = '<';
92:            private static final String LT_ENTITY = "&lt;";
93:            private static final char QUOT_CHAR = '"';
94:            private static final String QUOT_ENTITY = "&quot;";
95:
96:        }//CharacterSubstitution
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.