Source Code Cross Referenced for IndentingXMLStreamWriter.java in  » 6.0-JDK-Modules » jaxb-impl » com » sun » xml » txw2 » output » 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 » 6.0 JDK Modules » jaxb impl » com.sun.xml.txw2.output 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.xml.txw2.output;
002:
003:        import javax.xml.stream.XMLStreamException;
004:        import javax.xml.stream.XMLStreamWriter;
005:        import java.util.Stack;
006:
007:        /**
008:         * @author Kohsuke Kawaguchi
009:         */
010:        public class IndentingXMLStreamWriter extends DelegatingXMLStreamWriter {
011:            private final static Object SEEN_NOTHING = new Object();
012:            private final static Object SEEN_ELEMENT = new Object();
013:            private final static Object SEEN_DATA = new Object();
014:
015:            private Object state = SEEN_NOTHING;
016:            private Stack<Object> stateStack = new Stack<Object>();
017:
018:            private String indentStep = "  ";
019:            private int depth = 0;
020:
021:            public IndentingXMLStreamWriter(XMLStreamWriter writer) {
022:                super (writer);
023:            }
024:
025:            /**
026:             * Return the current indent step.
027:             *
028:             * <p>Return the current indent step: each start tag will be
029:             * indented by this number of spaces times the number of
030:             * ancestors that the element has.</p>
031:             *
032:             * @return The number of spaces in each indentation step,
033:             *         or 0 or less for no indentation.
034:             * @see #setIndentStep(int)
035:             *
036:             * @deprecated
037:             *      Only return the length of the indent string.
038:             */
039:            public int getIndentStep() {
040:                return indentStep.length();
041:            }
042:
043:            /**
044:             * Set the current indent step.
045:             *
046:             * @param indentStep The new indent step (0 or less for no
047:             *        indentation).
048:             * @see #getIndentStep()
049:             *
050:             * @deprecated
051:             *      Should use the version that takes string.
052:             */
053:            public void setIndentStep(int indentStep) {
054:                StringBuilder s = new StringBuilder();
055:                for (; indentStep > 0; indentStep--)
056:                    s.append(' ');
057:                setIndentStep(s.toString());
058:            }
059:
060:            public void setIndentStep(String s) {
061:                this .indentStep = s;
062:            }
063:
064:            private void onStartElement() throws XMLStreamException {
065:                stateStack.push(SEEN_ELEMENT);
066:                state = SEEN_NOTHING;
067:                if (depth > 0) {
068:                    super .writeCharacters("\n");
069:                }
070:                doIndent();
071:                depth++;
072:            }
073:
074:            private void onEndElement() throws XMLStreamException {
075:                depth--;
076:                if (state == SEEN_ELEMENT) {
077:                    super .writeCharacters("\n");
078:                    doIndent();
079:                }
080:                state = stateStack.pop();
081:            }
082:
083:            private void onEmptyElement() throws XMLStreamException {
084:                state = SEEN_ELEMENT;
085:                if (depth > 0) {
086:                    super .writeCharacters("\n");
087:                }
088:                doIndent();
089:            }
090:
091:            /**
092:             * Print indentation for the current level.
093:             *
094:             * @exception org.xml.sax.SAXException If there is an error
095:             *            writing the indentation characters, or if a filter
096:             *            further down the chain raises an exception.
097:             */
098:            private void doIndent() throws XMLStreamException {
099:                if (depth > 0) {
100:                    for (int i = 0; i < depth; i++)
101:                        super .writeCharacters(indentStep);
102:                }
103:            }
104:
105:            public void writeStartDocument() throws XMLStreamException {
106:                super .writeStartDocument();
107:                super .writeCharacters("\n");
108:            }
109:
110:            public void writeStartDocument(String version)
111:                    throws XMLStreamException {
112:                super .writeStartDocument(version);
113:                super .writeCharacters("\n");
114:            }
115:
116:            public void writeStartDocument(String encoding, String version)
117:                    throws XMLStreamException {
118:                super .writeStartDocument(encoding, version);
119:                super .writeCharacters("\n");
120:            }
121:
122:            public void writeStartElement(String localName)
123:                    throws XMLStreamException {
124:                onStartElement();
125:                super .writeStartElement(localName);
126:            }
127:
128:            public void writeStartElement(String namespaceURI, String localName)
129:                    throws XMLStreamException {
130:                onStartElement();
131:                super .writeStartElement(namespaceURI, localName);
132:            }
133:
134:            public void writeStartElement(String prefix, String localName,
135:                    String namespaceURI) throws XMLStreamException {
136:                onStartElement();
137:                super .writeStartElement(prefix, localName, namespaceURI);
138:            }
139:
140:            public void writeEmptyElement(String namespaceURI, String localName)
141:                    throws XMLStreamException {
142:                onEmptyElement();
143:                super .writeEmptyElement(namespaceURI, localName);
144:            }
145:
146:            public void writeEmptyElement(String prefix, String localName,
147:                    String namespaceURI) throws XMLStreamException {
148:                onEmptyElement();
149:                super .writeEmptyElement(prefix, localName, namespaceURI);
150:            }
151:
152:            public void writeEmptyElement(String localName)
153:                    throws XMLStreamException {
154:                onEmptyElement();
155:                super .writeEmptyElement(localName);
156:            }
157:
158:            public void writeEndElement() throws XMLStreamException {
159:                onEndElement();
160:                super .writeEndElement();
161:            }
162:
163:            public void writeCharacters(String text) throws XMLStreamException {
164:                state = SEEN_DATA;
165:                super .writeCharacters(text);
166:            }
167:
168:            public void writeCharacters(char[] text, int start, int len)
169:                    throws XMLStreamException {
170:                state = SEEN_DATA;
171:                super .writeCharacters(text, start, len);
172:            }
173:
174:            public void writeCData(String data) throws XMLStreamException {
175:                state = SEEN_DATA;
176:                super.writeCData(data);
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.