Source Code Cross Referenced for Transform.java in  » Net » mina-2.0.0-M1 » org » apache » mina » 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 » Net » mina 2.0.0 M1 » org.apache.mina.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.mina.util;
002:
003:        import java.io.IOException;
004:        import java.io.LineNumberReader;
005:        import java.io.PrintWriter;
006:        import java.io.StringReader;
007:        import java.io.StringWriter;
008:        import java.util.ArrayList;
009:
010:        /**
011:         * Utility class for working with xml data
012:         *
013:         * Implementation is heavily based on org.apache.log4j.helpers.Transform
014:         */
015:        public class Transform {
016:
017:            private static final String CDATA_START = "<![CDATA[";
018:            private static final String CDATA_END = "]]>";
019:            private static final String CDATA_PSEUDO_END = "]]&gt;";
020:            private static final String CDATA_EMBEDED_END = CDATA_END
021:                    + CDATA_PSEUDO_END + CDATA_START;
022:            private static final int CDATA_END_LEN = CDATA_END.length();
023:
024:            /**
025:             * This method takes a string which may contain HTML tags (ie,
026:             * &lt;b&gt;, &lt;table&gt;, etc) and replaces any
027:             * '<',  '>' , '&' or '"'
028:             * characters with respective predefined entity references.
029:             *
030:             * @param input The text to be converted.
031:             * @return The input string with the special characters replaced.
032:             * */
033:            static public String escapeTags(final String input) {
034:                // Check if the string is null, zero length or devoid of special characters
035:                // if so, return what was sent in.
036:
037:                if (input == null
038:                        || input.length() == 0
039:                        || (input.indexOf('"') == -1
040:                                && input.indexOf('&') == -1
041:                                && input.indexOf('<') == -1 && input
042:                                .indexOf('>') == -1)) {
043:                    return input;
044:                }
045:
046:                StringBuffer buf = new StringBuffer(input.length() + 6);
047:                char ch;
048:
049:                int len = input.length();
050:                for (int i = 0; i < len; i++) {
051:                    ch = input.charAt(i);
052:                    if (ch > '>') {
053:                        buf.append(ch);
054:                    } else if (ch == '<') {
055:                        buf.append("&lt;");
056:                    } else if (ch == '>') {
057:                        buf.append("&gt;");
058:                    } else if (ch == '&') {
059:                        buf.append("&amp;");
060:                    } else if (ch == '"') {
061:                        buf.append("&quot;");
062:                    } else {
063:                        buf.append(ch);
064:                    }
065:                }
066:                return buf.toString();
067:            }
068:
069:            /**
070:             * Ensures that embeded CDEnd strings (]]>) are handled properly
071:             * within message, NDC and throwable tag text.
072:             *
073:             * @param buf StringBuffer holding the XML data to this point.  The
074:             * initial CDStart (<![CDATA[) and final CDEnd (]]>) of the CDATA
075:             * section are the responsibility of the calling method.
076:             * @param str The String that is inserted into an existing CDATA Section within buf.
077:             * */
078:            static public void appendEscapingCDATA(final StringBuffer buf,
079:                    final String str) {
080:                if (str != null) {
081:                    int end = str.indexOf(CDATA_END);
082:                    if (end < 0) {
083:                        buf.append(str);
084:                    } else {
085:                        int start = 0;
086:                        while (end > -1) {
087:                            buf.append(str.substring(start, end));
088:                            buf.append(CDATA_EMBEDED_END);
089:                            start = end + CDATA_END_LEN;
090:                            if (start < str.length()) {
091:                                end = str.indexOf(CDATA_END, start);
092:                            } else {
093:                                return;
094:                            }
095:                        }
096:                        buf.append(str.substring(start));
097:                    }
098:                }
099:            }
100:
101:            /**
102:             * convert a Throwable into an array of Strings
103:             * @param throwable
104:             * @return string representation of the throwable
105:             */
106:            public static String[] getThrowableStrRep(Throwable throwable) {
107:                StringWriter sw = new StringWriter();
108:                PrintWriter pw = new PrintWriter(sw);
109:                throwable.printStackTrace(pw);
110:                pw.flush();
111:                LineNumberReader reader = new LineNumberReader(
112:                        new StringReader(sw.toString()));
113:                ArrayList<String> lines = new ArrayList<String>();
114:                try {
115:                    String line = reader.readLine();
116:                    while (line != null) {
117:                        lines.add(line);
118:                        line = reader.readLine();
119:                    }
120:                } catch (IOException ex) {
121:                    lines.add(ex.toString());
122:                }
123:                String[] rep = new String[lines.size()];
124:                lines.toArray(rep);
125:                return rep;
126:            }
127:
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.