Source Code Cross Referenced for CharSepLE.java in  » Report » datavision-1.1.0 » jimm » datavision » layout » 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 » Report » datavision 1.1.0 » jimm.datavision.layout 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision.layout;
002:
003:        import jimm.datavision.*;
004:        import jimm.datavision.field.*;
005:        import java.io.*;
006:
007:        /**
008:         * <code>CharSepLE</code> is a layout engine that outputs text data files.
009:         * Output is one line per row of data. Column data is separated by a
010:         * user-specified character.
011:         *
012:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
013:         */
014:        public class CharSepLE extends SortedLayoutEngine {
015:
016:            protected char sepChar;
017:            protected boolean first;
018:
019:            /**
020:             * Constructor.
021:             *
022:             * @param out the output writer
023:             * @param sepChar the character used to separate column data
024:             */
025:            public CharSepLE(PrintWriter out, char sepChar) {
026:                super (out);
027:                this .sepChar = sepChar;
028:            }
029:
030:            /**
031:             * This override handles output of a section.
032:             *
033:             * @param sect section
034:             */
035:            protected void doOutputSection(Section sect) {
036:                first = true;
037:                super .doOutputSection(sect);
038:                out.println();
039:            }
040:
041:            /**
042:             * This override handles output of a field.
043:             *
044:             * @param field a field
045:             */
046:            protected void doOutputField(Field field) {
047:                String fieldAsString = field.toString();
048:                if (fieldAsString == null)
049:                    fieldAsString = "";
050:
051:                if (first)
052:                    first = false;
053:                else
054:                    out.print(sepChar);
055:
056:                // Make fieldAsString safe for comma- or tab-separated data
057:                out.print(asSafeSepString(fieldAsString));
058:            }
059:
060:            protected void doOutputImage(ImageField image) {
061:                doOutputField(image);
062:            }
063:
064:            /**
065:             * Ignores line output.
066:             *
067:             * @param line a line
068:             */
069:            protected void doOutputLine(Line line) {
070:            }
071:
072:            /**
073:             * Return a string that's safe to use in a comma-delimited data file.
074:             * Returns a new string with all double quotes replaced by two double
075:             * quotes. If there are any double quotes, commas, or newlines in the
076:             * string, the returned string will be surrounded by double quotes.
077:             *
078:             * @param str a string to be used in a comma-delimited data file
079:             * @return a new string that's safe for use in a comma-delimited data file
080:             */
081:            protected String asSafeSepString(String str) {
082:                if (str == null)
083:                    return "";
084:
085:                StringBuffer buf = new StringBuffer();
086:                boolean needsToBeQuoted = false;
087:                int len = str.length();
088:                for (int i = 0; i < len; ++i) {
089:                    char c = str.charAt(i);
090:                    switch (c) {
091:                    case '"':
092:                        buf.append("\"\"");
093:                        needsToBeQuoted = true;
094:                        break;
095:                    case '\n':
096:                    case '\r':
097:                        buf.append(c);
098:                        needsToBeQuoted = true;
099:                        break;
100:                    default:
101:                        buf.append(c);
102:                        if (c == sepChar)
103:                            needsToBeQuoted = true;
104:                        break;
105:                    }
106:                }
107:
108:                if (needsToBeQuoted) {
109:                    buf.insert(0, '"');
110:                    buf.append('"');
111:                }
112:                return buf.toString();
113:            }
114:
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.