Source Code Cross Referenced for KMZMapProducer.java in  » GIS » GeoServer » org » vfny » geoserver » wms » responses » map » kml » 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.vfny.geoserver.wms.responses.map.kml 
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.vfny.geoserver.wms.responses.map.kml;
006:
007:        import java.io.IOException;
008:        import java.io.OutputStream;
009:        import java.util.logging.Logger;
010:        import java.util.zip.ZipEntry;
011:        import java.util.zip.ZipOutputStream;
012:
013:        import javax.xml.transform.TransformerException;
014:
015:        import org.geotools.map.MapLayer;
016:        import org.vfny.geoserver.ServiceException;
017:        import org.vfny.geoserver.global.WMS;
018:        import org.vfny.geoserver.wms.GetMapProducer;
019:        import org.vfny.geoserver.wms.WMSMapContext;
020:        import org.vfny.geoserver.wms.WmsException;
021:        import org.vfny.geoserver.wms.responses.AbstractGetMapProducer;
022:        import org.vfny.geoserver.wms.responses.map.png.PNGMapProducer;
023:
024:        /**
025:         * Handles a GetMap request that spects a map in KMZ format.
026:         * 
027:         * KMZ files are a zipped KML file. The KML file must have an emcompasing
028:         * <document> or <folder> element. So if you have many different placemarks or
029:         * ground overlays, they all need to be contained within one <document> element,
030:         * then zipped up and sent off with the extension "kmz".
031:         * 
032:         * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $
033:         * @author $Author: Simone Giannecchini (simboss1@gmail.com) $
034:         * @author $Author: Brent Owens
035:         * @author Justin Deoliveira
036:         * 
037:         */
038:        class KMZMapProducer extends AbstractGetMapProducer implements 
039:                GetMapProducer {
040:            /** standard logger */
041:            private static final Logger LOGGER = org.geotools.util.logging.Logging
042:                    .getLogger("org.vfny.geoserver.responses.wms.kmz");
043:
044:            /**
045:             * delegating producer for rendering.
046:             */
047:            PNGMapProducer mapProducer;
048:
049:            /**
050:             * transformer for creating kml
051:             */
052:            KMLTransformer transformer;
053:
054:            public KMZMapProducer(String mapFormat, String mime_type, WMS wms) {
055:                super (mapFormat, mime_type);
056:                mapProducer = new PNGMapProducer("image/png", "image/png", wms);
057:            }
058:
059:            public void abort() {
060:                LOGGER.fine("aborting KMZ map response");
061:                mapContext = null;
062:                mapProducer = null;
063:                transformer = null;
064:            }
065:
066:            public String getContentDisposition() {
067:                StringBuffer sb = new StringBuffer();
068:                for (int i = 0; i < mapContext.getLayerCount(); i++) {
069:                    MapLayer layer = mapContext.getLayer(i);
070:                    String title = layer.getFeatureSource().getSchema()
071:                            .getTypeName();
072:                    if (title != null && !title.equals("")) {
073:                        sb.append(title).append("_");
074:                    }
075:                }
076:                if (sb.length() > 0) {
077:                    sb.setLength(sb.length() - 1);
078:                    return "attachment; filename=" + sb.toString() + ".kml";
079:                }
080:                return "attachment; filename=geoserver.kml";
081:            }
082:
083:            public String getContentType() throws IllegalStateException {
084:                return KMZMapProducerFactory.MIME_TYPE;
085:            }
086:
087:            /**
088:             * Initializes the KML encoder. None of the map production is done here, it
089:             * is done in writeTo(). This way the output can be streamed directly to the
090:             * output response and not written to disk first, then loaded in and then
091:             * sent to the response.
092:             *
093:             * @param map
094:             *            WMSMapContext describing what layers, styles, area of interest
095:             *            etc are to be used when producing the map.
096:             *
097:             * @throws WmsException
098:             *             thrown if anything goes wrong during the production.
099:             */
100:            public void produceMap() throws WmsException {
101:                transformer = new KMLTransformer();
102:                transformer.setKmz(true);
103:
104:                // TODO: use GeoServer.isVerbose() to determine if we should indent?
105:                transformer.setIndentation(3);
106:            }
107:
108:            /**
109:             * Makes the map and sends it to the zipped output stream The produceMap()
110:             * method does not create the map in this case. We produce the map here so
111:             * we can stream directly to the response output stream, and not have to
112:             * write to disk, then send it to the stream.
113:             *
114:             * @Note: Do not close the output stream in this method, it gets closed
115:             *        later on.
116:             *
117:             * @param out
118:             *            OutputStream to stream the map to.
119:             *
120:             * @throws ServiceException
121:             * @throws IOException
122:             *
123:             */
124:            public void writeTo(OutputStream out) throws ServiceException,
125:                    IOException {
126:                // wrap the output stream in a zipped one
127:                ZipOutputStream zip = new ZipOutputStream(out);
128:
129:                // first create an entry for the kml
130:                ZipEntry entry = new ZipEntry("wms.kml");
131:                zip.putNextEntry(entry);
132:
133:                try {
134:                    transformer.transform(mapContext, zip);
135:                    zip.closeEntry();
136:                } catch (TransformerException e) {
137:                    throw (IOException) new IOException().initCause(e);
138:                }
139:
140:                // write the images
141:                for (int i = 0; i < mapContext.getLayerCount(); i++) {
142:                    MapLayer mapLayer = mapContext.getLayer(i);
143:
144:                    // create a context for this single layer
145:                    WMSMapContext mapContext = new WMSMapContext();
146:                    mapContext.addLayer(mapLayer);
147:                    mapContext.setRequest(this .mapContext.getRequest());
148:                    mapContext.setMapHeight(this .mapContext.getMapHeight());
149:                    mapContext.setMapWidth(this .mapContext.getMapWidth());
150:                    mapContext.setAreaOfInterest(this .mapContext
151:                            .getAreaOfInterest());
152:                    mapContext.setBgColor(this .mapContext.getBgColor());
153:                    mapContext.setBuffer(this .mapContext.getBuffer());
154:                    mapContext.setContactInformation(this .mapContext
155:                            .getContactInformation());
156:                    mapContext.setKeywords(this .mapContext.getKeywords());
157:                    mapContext.setAbstract(this .mapContext.getAbstract());
158:                    mapContext.setTransparent(true);
159:
160:                    // render the map
161:                    mapProducer.setMapContext(mapContext);
162:                    mapProducer.produceMap();
163:
164:                    // write it to the zip stream
165:                    entry = new ZipEntry("layer_" + i + ".png");
166:                    zip.putNextEntry(entry);
167:                    mapProducer.writeTo(zip);
168:                    zip.closeEntry();
169:                }
170:
171:                zip.finish();
172:                zip.flush();
173:            }
174:        }
w__w_w.___jav___a_2_s___.__c__o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.