Source Code Cross Referenced for TextFeatureInfoResponse.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.OutputStream;
008:        import java.io.OutputStreamWriter;
009:        import java.io.PrintWriter;
010:        import java.nio.charset.Charset;
011:        import java.util.Collections;
012:        import java.util.HashMap;
013:        import java.util.logging.Level;
014:
015:        import org.geotools.feature.AttributeType;
016:        import org.geotools.feature.Feature;
017:        import org.geotools.feature.FeatureCollection;
018:        import org.geotools.feature.FeatureIterator;
019:        import org.geotools.feature.FeatureType;
020:
021:        import com.vividsolutions.jts.geom.Geometry;
022:
023:        /**
024:         * Generates a FeatureInfoResponse of type text. This simply reports the
025:         * attributes of the feature requested as a text string. This class just
026:         * performs the writeTo, the GetFeatureInfoDelegate and abstract feature info
027:         * class handle the rest.
028:         *
029:         * @author James Macgill, PSU
030:         * @version $Id: TextFeatureInfoResponse.java,v 1.3 2004/07/19 22:31:40 jmacgill
031:         *          Exp $
032:         */
033:        public class TextFeatureInfoResponse extends
034:                AbstractFeatureInfoResponse {
035:            /**
036:             *
037:             */
038:            public TextFeatureInfoResponse() {
039:                format = "text/plain";
040:                supportedFormats = Collections.singletonList("text/plain");
041:            }
042:
043:            /**
044:             * Returns any extra headers that this service might want to set in the HTTP
045:             * response object.
046:             *
047:             * @see org.vfny.geoserver.Response#getResponseHeaders()
048:             */
049:            public HashMap getResponseHeaders() {
050:                return new HashMap();
051:            }
052:
053:            /**
054:             * Writes the feature information to the client in text/plain format.
055:             *
056:             * @param out
057:             *            The output stream to write to.
058:             *
059:             * @throws org.vfny.geoserver.ServiceException
060:             *             DOCUMENT ME!
061:             * @throws java.io.IOException
062:             *             DOCUMENT ME!
063:             */
064:            public void writeTo(OutputStream out)
065:                    throws org.vfny.geoserver.ServiceException,
066:                    java.io.IOException {
067:                Charset charSet = getRequest().getGeoServer().getCharSet();
068:                OutputStreamWriter osw = new OutputStreamWriter(out, charSet);
069:
070:                // getRequest().getGeoServer().getCharSet());
071:                PrintWriter writer = new PrintWriter(osw);
072:
073:                // DJB: this is to limit the number of features read - as per the spec
074:                // 7.3.3.7 FEATURE_COUNT
075:                int featuresPrinted = 0; // how many features we've actually printed
076:                // so far!
077:
078:                int maxfeatures = getRequest().getFeatureCount(); // will default to 1
079:                // if not specified
080:                // in the request
081:
082:                FeatureIterator reader = null;
083:
084:                try {
085:                    final int size = results.size();
086:                    FeatureCollection fr;
087:                    Feature f;
088:
089:                    FeatureType schema;
090:                    AttributeType[] types;
091:
092:                    for (int i = 0; i < size; i++) // for each layer queried
093:                    {
094:                        fr = (FeatureCollection) results.get(i);
095:                        reader = fr.features();
096:
097:                        if (reader.hasNext() && (featuresPrinted < maxfeatures)) // if this layer has a hit and we're going to print it
098:                        {
099:                            writer.println("Results for FeatureType '"
100:                                    + fr.getFeatureType().getTypeName() + "':");
101:                        }
102:
103:                        while (reader.hasNext()) {
104:                            f = reader.next();
105:                            schema = f.getFeatureType();
106:                            types = schema.getAttributeTypes();
107:
108:                            if (featuresPrinted < maxfeatures) {
109:                                writer
110:                                        .println("--------------------------------------------");
111:
112:                                for (int j = 0; j < types.length; j++) // for each
113:                                // column in the
114:                                // featuretype
115:                                {
116:                                    if (Geometry.class
117:                                            .isAssignableFrom(types[j]
118:                                                    .getType())) {
119:                                        // writer.println(types[j].getName() + " =
120:                                        // [GEOMETRY]");
121:
122:                                        // DJB: changed this to print out WKT - its very
123:                                        // nice for users
124:                                        // Geometry g = (Geometry)
125:                                        // f.getAttribute(types[j].getName());
126:                                        // writer.println(types[j].getName() + " =
127:                                        // [GEOMETRY] = "+g.toText() );
128:
129:                                        // DJB: decided that all the geometry info was
130:                                        // too much - they should use GML version if
131:                                        // they want those details
132:                                        Geometry g = (Geometry) f
133:                                                .getAttribute(types[j]
134:                                                        .getName());
135:                                        writer.println(types[j].getName()
136:                                                + " = [GEOMETRY ("
137:                                                + g.getGeometryType()
138:                                                + ") with " + g.getNumPoints()
139:                                                + " points]");
140:                                    } else {
141:                                        writer.println(types[j].getName()
142:                                                + " = "
143:                                                + f.getAttribute(types[j]
144:                                                        .getName()));
145:                                    }
146:                                }
147:
148:                                writer
149:                                        .println("--------------------------------------------");
150:                                featuresPrinted++;
151:                            }
152:                        }
153:                    }
154:                } catch (Exception ife) {
155:                    LOGGER.log(Level.WARNING,
156:                            "Error generating getFeaturInfo, HTML format", ife);
157:                    writer.println("Unable to generate information " + ife);
158:                } finally {
159:                    if (reader != null) {
160:                        reader.close();
161:                    }
162:                }
163:
164:                if (featuresPrinted == 0) {
165:                    writer.println("no features were found");
166:                }
167:
168:                writer.flush();
169:            }
170:
171:            public String getContentDisposition() {
172:                // TODO Auto-generated method stub
173:                return null;
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.