Source Code Cross Referenced for XStream11XmlFriendlyReplacer.java in  » XML » xstream-1.3 » com » thoughtworks » xstream » io » xml » 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 » XML » xstream 1.3 » com.thoughtworks.xstream.io.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2006 Joe Walnes.
003:         * Copyright (C) 2006, 2007 XStream Committers.
004:         * All rights reserved.
005:         *
006:         * The software in this package is published under the terms of the BSD
007:         * style license a copy of which has been included with this distribution in
008:         * the LICENSE.txt file.
009:         * 
010:         * Created on 22. April 2006 by Mauro Talevi
011:         */
012:        package com.thoughtworks.xstream.io.xml;
013:
014:        /**
015:         * Allows replacement of Strings in xml-friendly drivers to provide compatibility with XStream 1.1 format
016:         *  
017:         * @author Mauro Talevi
018:         * @since 1.2
019:         */
020:        public class XStream11XmlFriendlyReplacer extends XmlFriendlyReplacer {
021:
022:            private char dollarReplacementInClass = '-';
023:            private String dollarReplacementInField = "_DOLLAR_";
024:            private String underscoreReplacementInField = "__";
025:            private String noPackagePrefix = "default";
026:
027:            /**
028:             * Default constructor. 
029:             */
030:            public XStream11XmlFriendlyReplacer() {
031:            }
032:
033:            /**
034:             * Noop implementation that does not unescape name.  Used for XStream 1.1 compatibility.
035:             * @param name the name of attribute or node
036:             * @return The String with unescaped name
037:             */
038:            public String unescapeName(String name) {
039:                return name;
040:            }
041:
042:            protected String escapeClassName(String className) {
043:                // the $ used in inner class names is illegal as an xml element getNodeName
044:                className = className.replace('$', dollarReplacementInClass);
045:
046:                // special case for classes named $Blah with no package; <-Blah> is illegal XML
047:                if (className.charAt(0) == dollarReplacementInClass) {
048:                    className = noPackagePrefix + className;
049:                }
050:
051:                return className;
052:            }
053:
054:            protected String escapeFieldName(String fieldName) {
055:                StringBuffer result = new StringBuffer();
056:                int length = fieldName.length();
057:                for (int i = 0; i < length; i++) {
058:                    char c = fieldName.charAt(i);
059:                    if (c == '$') {
060:                        result.append(dollarReplacementInField);
061:                    } else if (c == '_') {
062:                        result.append(underscoreReplacementInField);
063:                    } else {
064:                        result.append(c);
065:                    }
066:                }
067:                return result.toString();
068:            }
069:
070:            protected String unescapeClassName(String className) {
071:                // special case for classes named $Blah with no package; <-Blah> is illegal XML
072:                if (className.startsWith(noPackagePrefix
073:                        + dollarReplacementInClass)) {
074:                    className = className.substring(noPackagePrefix.length());
075:                }
076:
077:                // the $ used in inner class names is illegal as an xml element getNodeName
078:                className = className.replace(dollarReplacementInClass, '$');
079:
080:                return className;
081:            }
082:
083:            protected String unescapeFieldName(String xmlName) {
084:                StringBuffer result = new StringBuffer();
085:                int length = xmlName.length();
086:                for (int i = 0; i < length; i++) {
087:                    char c = xmlName.charAt(i);
088:                    if (stringFoundAt(xmlName, i, underscoreReplacementInField)) {
089:                        i += underscoreReplacementInField.length() - 1;
090:                        result.append('_');
091:                    } else if (stringFoundAt(xmlName, i,
092:                            dollarReplacementInField)) {
093:                        i += dollarReplacementInField.length() - 1;
094:                        result.append('$');
095:                    } else {
096:                        result.append(c);
097:                    }
098:                }
099:                return result.toString();
100:            }
101:
102:            private boolean stringFoundAt(String name, int i, String replacement) {
103:                if (name.length() >= i + replacement.length()
104:                        && name.substring(i, i + replacement.length()).equals(
105:                                replacement)) {
106:                    return true;
107:                }
108:                return false;
109:            }
110:
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.