Source Code Cross Referenced for WfsXmlWriter.java in  » GIS » GeoServer » org » geoserver » wfs » response » 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 » GIS » GeoServer » org.geoserver.wfs.response 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002:         * This code is licensed under the GPL 2.0 license, availible at the root
003:         * application directory.
004:         */
005:        package org.geoserver.wfs.response;
006:
007:        import org.geoserver.ows.util.ResponseUtils;
008:        import org.geoserver.ows.xml.v1_0.OWS;
009:        import org.geoserver.wfs.WFS;
010:        import org.geotools.filter.v1_0.OGC;
011:        import org.geotools.gml2.bindings.GML;
012:        import org.geotools.xs.bindings.XS;
013:        import org.xml.sax.helpers.NamespaceSupport;
014:        import java.io.BufferedWriter;
015:        import java.io.IOException;
016:        import java.io.OutputStream;
017:        import java.io.OutputStreamWriter;
018:        import java.util.Enumeration;
019:        import java.util.HashMap;
020:        import java.util.Iterator;
021:        import java.util.Map;
022:        import java.util.Map.Entry;
023:
024:        /**
025:         * Utility class for writing out wfs xml documents.
026:         * <p>
027:         * Usage:
028:         * <pre>
029:         *         WFS wfs = ...;
030:         *  OutputStream output = ...;
031:         *
032:         *         WfsXmlWriter writer = new WfsXmlWriter.WFS1_0( wfs, output );
033:         *
034:         *  //declare application schema namespaces
035:         *  writer.getNamespaceSupport().declareNamespace( "cdf", "http://cite.opengeospatial.org/cite" );
036:         *
037:         *  //write the document
038:         *  writer.openTag( "wfs", "GetCapabilities" );
039:         *  ...
040:         *  //write the response
041:         *  writer.closeTag( "wfs", "GetCapabilities" );
042:         *  ....
043:         *
044:         *  //close the writer
045:         *  writer.close();
046:         * </pre>
047:         * </p>
048:         * @author Justin Deoliveira, The Open Planning Project
049:         *
050:         */
051:        public abstract class WfsXmlWriter {
052:            /**
053:             * wfs configuration
054:             */
055:            WFS wfs;
056:
057:            /**
058:             * The output stream
059:             */
060:            OutputStream output;
061:
062:            /**
063:             * The character encoding.
064:             */
065:            String charSetEncoding;
066:
067:            /**
068:             * Declared namespaces
069:             */
070:            NamespaceSupport namespaceSupport;
071:
072:            /**
073:             * HashMap schemaLocations
074:             */
075:            HashMap schemaLocations;
076:
077:            /**
078:             * The wfs version
079:             */
080:            String version;
081:
082:            /**
083:             * writer
084:             */
085:            BufferedWriter writer;
086:
087:            public WfsXmlWriter(WFS wfs, OutputStream output) {
088:                this .wfs = wfs;
089:                this .output = output;
090:
091:                //default to wfs configured charset
092:                charSetEncoding = wfs.getCharSet().name();
093:
094:                //schema locations
095:                schemaLocations = new HashMap();
096:
097:                //declare the namespaces ( wfs is default )
098:                namespaceSupport = new NamespaceSupport();
099:                namespaceSupport.declarePrefix("xs", XS.NAMESPACE);
100:                namespaceSupport.declarePrefix("ogc", OGC.NAMESPACE);
101:                namespaceSupport.declarePrefix("gml", GML.NAMESPACE);
102:
103:                namespaceSupport.declarePrefix("wfs",
104:                        org.geoserver.wfs.xml.v1_0_0.WFS.NAMESPACE);
105:                namespaceSupport.declarePrefix("",
106:                        org.geoserver.wfs.xml.v1_0_0.WFS.NAMESPACE);
107:            }
108:
109:            public void setCharSetEncoding(String charSetEncoding) {
110:                this .charSetEncoding = charSetEncoding;
111:            }
112:
113:            public NamespaceSupport getNamespaceSupport() {
114:                return namespaceSupport;
115:            }
116:
117:            private void init() throws IOException {
118:                //namespace declarations
119:                for (Enumeration e = namespaceSupport.getDeclaredPrefixes(); e
120:                        .hasMoreElements();) {
121:                    String pre = (String) e.nextElement();
122:                    String uri = namespaceSupport.getURI(pre);
123:
124:                    if ("".equals(pre)) {
125:                        attribute("xmlns" + pre, uri);
126:                    } else {
127:                        attribute("xmlns:" + pre, uri);
128:                    }
129:                }
130:
131:                //schema locations
132:                if (!schemaLocations.isEmpty()) {
133:                    StringBuffer buffer = new StringBuffer();
134:
135:                    for (Iterator e = schemaLocations.entrySet().iterator(); e
136:                            .hasNext();) {
137:                        Map.Entry entry = (Entry) e.next();
138:                        String uri = (String) entry.getKey();
139:                        String location = (String) entry.getValue();
140:
141:                        buffer.append(uri + " " + location);
142:
143:                        if (e.hasNext()) {
144:                            buffer.append(" ");
145:                        }
146:                    }
147:
148:                    attribute("xs:schemaLocation", buffer.toString());
149:                }
150:            }
151:
152:            private void attribute(String name, String value)
153:                    throws IOException {
154:                writer.write(" " + name + "=\"" + value + "\"");
155:            }
156:
157:            public void openTag(String prefix, String name) throws IOException {
158:                openTag(prefix, name, null);
159:            }
160:
161:            public void openTag(String prefix, String name, String[] attributes)
162:                    throws IOException {
163:                boolean root = writer == null;
164:
165:                if (root) {
166:                    writer = new BufferedWriter(new OutputStreamWriter(output));
167:
168:                    //write the processing instruction
169:                    writer.write("<?xml version=\"1.0\" encoding=\""
170:                            + charSetEncoding + "\"?>");
171:                }
172:
173:                //write the element
174:                if (prefix != null) {
175:                    writer.write("<" + prefix + ":" + name);
176:                } else {
177:                    writer.write("<" + name);
178:                }
179:
180:                if (root) {
181:                    init();
182:                }
183:
184:                if (attributes != null) {
185:                    for (int i = 0; i < attributes.length; i += 2) {
186:                        attribute(attributes[i], attributes[i + 1]);
187:                    }
188:                }
189:
190:                writer.write(">");
191:            }
192:
193:            public void text(String text) throws IOException {
194:                writer.write(text);
195:            }
196:
197:            public void closeTag(String prefix, String name) throws IOException {
198:                //write the element
199:                if (prefix != null) {
200:                    writer.write("</" + prefix + ":" + name + ">");
201:                } else {
202:                    writer.write("</" + name + ">");
203:                }
204:            }
205:
206:            public void close() throws IOException {
207:                //close the writer
208:                writer.flush();
209:                writer.close();
210:
211:                writer = null;
212:            }
213:
214:            public static class WFS1_0 extends WfsXmlWriter {
215:                public WFS1_0(WFS wfs, OutputStream output) {
216:                    super (wfs, output);
217:
218:                    //set the schema location
219:                    schemaLocations.put(
220:                            org.geoserver.wfs.xml.v1_0_0.WFS.NAMESPACE,
221:                            ResponseUtils.appendPath(wfs.getSchemaBaseURL(),
222:                                    "wfs/1.0.0/WFS-transaction.xsd"));
223:
224:                    version = "1.0.0";
225:                }
226:            }
227:
228:            public static class WFS1_1 extends WfsXmlWriter {
229:                public WFS1_1(WFS wfs, OutputStream output) {
230:                    super (wfs, output);
231:
232:                    //add the ows namespace
233:                    namespaceSupport.declarePrefix("ows", OWS.NAMESPACE);
234:
235:                    //set the schema location
236:                    schemaLocations.put(
237:                            org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE,
238:                            ResponseUtils.appendPath(wfs.getSchemaBaseURL(),
239:                                    "wfs/1.1.0/wfs.xsd"));
240:
241:                    version = "1.1.0";
242:                }
243:            }
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.