Source Code Cross Referenced for HTMLTableFeatureInfoResponse.java in  » GIS » GeoServer » org » vfny » geoserver » wms » responses » featureInfo » 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.featureInfo 
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.featureInfo;
006:
007:        import java.io.IOException;
008:        import java.io.OutputStream;
009:        import java.io.OutputStreamWriter;
010:        import java.nio.charset.Charset;
011:        import java.util.Collections;
012:        import java.util.HashMap;
013:        import java.util.Iterator;
014:
015:        import org.geoserver.template.FeatureWrapper;
016:        import org.geoserver.template.GeoServerTemplateLoader;
017:        import org.geotools.feature.FeatureCollection;
018:        import org.geotools.feature.FeatureType;
019:
020:        import freemarker.template.Configuration;
021:        import freemarker.template.Template;
022:        import freemarker.template.TemplateException;
023:
024:        /**
025:         * Produces a FeatureInfo response in HTML.  Relies on {@link AbstractFeatureInfoResponse} and
026:         * the feature delegate to do most of the work, just implements an HTML based
027:         * writeTo method.
028:         *
029:         * <p>
030:         * In the future James suggested that we allow some sort of template system, so
031:         * that one can control the formatting of the html output, since now we just
032:         * hard code some minimal header stuff. See
033:         * http://jira.codehaus.org/browse/GEOS-196
034:         * </p>
035:         *
036:         * @author James Macgill, PSU
037:         * @author Andrea Aime, TOPP
038:         * @version $Id: HTMLTableFeatureInfoResponse.java 7589 2007-10-11 08:02:59Z aaime $
039:         */
040:        public class HTMLTableFeatureInfoResponse extends
041:                AbstractFeatureInfoResponse {
042:            private static Configuration templateConfig;
043:
044:            static {
045:                // initialize the template engine, this is static to maintain a cache
046:                // over instantiations of kml writer
047:                templateConfig = new Configuration();
048:                templateConfig.setObjectWrapper(new FeatureWrapper());
049:            }
050:
051:            GeoServerTemplateLoader templateLoader;
052:
053:            /**
054:             *
055:             */
056:            public HTMLTableFeatureInfoResponse() {
057:                format = "text/html";
058:                supportedFormats = Collections.singletonList(format);
059:            }
060:
061:            /**
062:             * Returns any extra headers that this service might want to set in the HTTP response object.
063:             * @see org.vfny.geoserver.Response#getResponseHeaders()
064:             */
065:            public HashMap getResponseHeaders() {
066:                return new HashMap();
067:            }
068:
069:            /**
070:             * Writes the image to the client.
071:             *
072:             * @param out The output stream to write to.
073:             *
074:             * @throws org.vfny.geoserver.ServiceException For problems with geoserver
075:             * @throws java.io.IOException For problems writing the output.
076:             */
077:            public void writeTo(OutputStream out)
078:                    throws org.vfny.geoserver.ServiceException,
079:                    java.io.IOException {
080:                // setup the writer
081:                Charset charSet = getRequest().getGeoServer().getCharSet();
082:                OutputStreamWriter osw = new OutputStreamWriter(out, charSet);
083:
084:                // if there is only one feature type loaded, we allow for header/footer customization,
085:                // otherwise we stick with the generic ones
086:                FeatureType templateFeatureType = null;
087:                if (results.size() == 1) {
088:                    templateFeatureType = ((FeatureCollection) results.get(0))
089:                            .getSchema();
090:                }
091:                Template header = getTemplate(templateFeatureType,
092:                        "header.ftl", charSet);
093:                Template footer = getTemplate(templateFeatureType,
094:                        "footer.ftl", charSet);
095:
096:                try {
097:                    header.process(null, osw);
098:
099:                    for (Iterator it = results.iterator(); it.hasNext();) {
100:                        FeatureCollection fc = (FeatureCollection) it.next();
101:                        if (fc.size() > 0) {
102:                            FeatureType ft = fc.getSchema();
103:                            Template content = getTemplate(ft, "content.ftl",
104:                                    charSet);
105:                            content.process(fc, osw);
106:                        }
107:                    }
108:
109:                    footer.process(null, osw);
110:                } catch (TemplateException e) {
111:                    String msg = "Error occured processing template.";
112:                    throw (IOException) new IOException(msg).initCause(e);
113:                }
114:                osw.flush();
115:            }
116:
117:            public String getContentDisposition() {
118:                return null;
119:            }
120:
121:            Template getTemplate(FeatureType featureType,
122:                    String templateFileName, Charset charset)
123:                    throws IOException {
124:                // setup template subsystem
125:                if (templateLoader == null) {
126:                    templateLoader = new GeoServerTemplateLoader(getClass());
127:                }
128:                templateLoader.setFeatureType(featureType);
129:
130:                synchronized (templateConfig) {
131:                    templateConfig.setTemplateLoader(templateLoader);
132:                    Template t = templateConfig.getTemplate(templateFileName);
133:                    t.setEncoding(charset.name());
134:                    return t;
135:                }
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.