Source Code Cross Referenced for GMLUtils.java in  » GIS » GeoTools-2.4.1 » org » geotools » gml » producer » 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 » GeoTools 2.4.1 » org.geotools.gml.producer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, GeoTools Project Managment Committee (PMC)
005:         *    
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.gml.producer;
017:
018:        import java.util.logging.Logger;
019:
020:        import com.vividsolutions.jts.geom.Geometry;
021:        import com.vividsolutions.jts.geom.GeometryCollection;
022:        import com.vividsolutions.jts.geom.LineString;
023:        import com.vividsolutions.jts.geom.MultiLineString;
024:        import com.vividsolutions.jts.geom.MultiPoint;
025:        import com.vividsolutions.jts.geom.MultiPolygon;
026:        import com.vividsolutions.jts.geom.Point;
027:        import com.vividsolutions.jts.geom.Polygon;
028:
029:        //import org.geotools.feature.*;
030:
031:        /*
032:         * Utilities for gml and xml;
033:         * @author Chris Holmes, TOPP
034:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/gml/producer/GMLUtils.java $
035:         */
036:        final class GMLUtils {
037:            /** The logger for the filter module. */
038:            private static final Logger LOGGER = org.geotools.util.logging.Logging
039:                    .getLogger("org.geotools.gml.producer");
040:
041:            /** Internal representation of URL used to represent GML */
042:            public static final String GML_URL = "http://www.opengis.net/gml";
043:
044:            /** Internal representation of OGC SF Point */
045:            protected static final int POINT = 1;
046:
047:            /** Internal representation of OGC SF LineString */
048:            protected static final int LINESTRING = 2;
049:
050:            /** Internal representation of OGC SF Polygon */
051:            protected static final int POLYGON = 3;
052:
053:            /** Internal representation of OGC SF MultiPoint */
054:            protected static final int MULTIPOINT = 4;
055:
056:            /** Internal representation of OGC SF MultiLineString */
057:            protected static final int MULTILINESTRING = 5;
058:
059:            /** Internal representation of OGC SF MultiPolygon */
060:            protected static final int MULTIPOLYGON = 6;
061:
062:            /** Internal representation of OGC SF MultiGeometry */
063:            protected static final int MULTIGEOMETRY = 7;
064:
065:            /**
066:             * private constructor so default is not used.
067:             */
068:            private GMLUtils() {
069:            }
070:
071:            /**
072:             * Gets the String representation for the given Geometry
073:             *
074:             * @param geometry a Geometry
075:             *
076:             * @return String representation of geometry
077:             */
078:            public static String getGeometryName(Geometry geometry) {
079:                LOGGER.entering("GMLUtils", "getGeometryName", geometry);
080:
081:                Class geomClass = geometry.getClass();
082:                String returnValue = null;
083:
084:                if (geomClass.equals(Point.class)) {
085:                    returnValue = "Point";
086:                } else if (geomClass.equals(LineString.class)) {
087:                    returnValue = "LineString";
088:                } else if (geomClass.equals(Polygon.class)) {
089:                    returnValue = "Polygon";
090:                } else if (geomClass.equals(MultiPoint.class)) {
091:                    returnValue = "MultiPoint";
092:                } else if (geomClass.equals(MultiLineString.class)) {
093:                    returnValue = "MultiLineString";
094:                } else if (geomClass.equals(MultiPolygon.class)) {
095:                    returnValue = "MultiPolygon";
096:                } else if (geomClass.equals(GeometryCollection.class)) {
097:                    returnValue = "GeometryCollection";
098:                } else {
099:                    //HACK!!! throw exception
100:                    returnValue = null;
101:                }
102:
103:                LOGGER.exiting("GMLUtils", "getGeometryName", returnValue);
104:
105:                return returnValue;
106:            }
107:
108:            /**
109:             * Gets the internal representation for the given Geometry
110:             *
111:             * @param geometry a Geometry
112:             *
113:             * @return int representation of Geometry
114:             */
115:            public static int getGeometryType(Geometry geometry) {
116:                //LOGGER.entering("GMLUtils", "getGeometryType", geometry);
117:
118:                Class geomClass = geometry.getClass();
119:                int returnValue = -1;
120:
121:                if (geomClass.equals(Point.class)) {
122:                    //LOGGER.finest("found point");
123:                    returnValue = POINT;
124:                } else if (geomClass.equals(LineString.class)) {
125:                    //LOGGER.finest("found linestring");
126:                    returnValue = LINESTRING;
127:                } else if (geomClass.equals(Polygon.class)) {
128:                    //LOGGER.finest("found polygon");
129:                    returnValue = POLYGON;
130:                } else if (geomClass.equals(MultiPoint.class)) {
131:                    //LOGGER.finest("found multiPoint");
132:                    returnValue = MULTIPOINT;
133:                } else if (geomClass.equals(MultiLineString.class)) {
134:                    returnValue = MULTILINESTRING;
135:                } else if (geomClass.equals(MultiPolygon.class)) {
136:                    returnValue = MULTIPOLYGON;
137:                } else if (geomClass.equals(GeometryCollection.class)) {
138:                    returnValue = MULTIGEOMETRY;
139:                } else {
140:                    returnValue = -1;
141:
142:                    //HACK!!! throw exception.
143:                }
144:
145:                //LOGGER.exiting("GMLUtils", "getGeometryType", new Integer(returnValue));
146:
147:                return returnValue;
148:            }
149:
150:            public static String getMemberName(int geometryType) {
151:                //String member;
152:
153:                switch (geometryType) {
154:                case GMLUtils.MULTIPOINT:
155:                    return "pointMember";
156:
157:                case GMLUtils.MULTILINESTRING:
158:                    return "lineStringMember";
159:
160:                case GMLUtils.MULTIPOLYGON:
161:                    return "polygonMember";
162:
163:                default:
164:                    return "geometryMember";
165:                }
166:            }
167:
168:            /**
169:             * Parses the passed string, and encodes the special characters (used in
170:             * xml for special purposes) with the appropriate codes. e.g. right
171:             * bracket char is changed to '<'
172:             *
173:             * @param inData the string to encode.
174:             *
175:             * @return the encoded string. Returns null, if null is passed as argument
176:             *
177:             * @task TODO: Take output as a param, write directly to out, send the
178:             *       characters straight out, doing translation on the fly.
179:             */
180:            public static String encodeXML(String inData) {
181:                //LOGGER.entering("GMLUtils", "encodeXML", inData);
182:
183:                //return null, if null is passed as argument
184:                if (inData == null) {
185:                    return null;
186:                }
187:
188:                //if no special characters, just return
189:                //(for optimization. Though may be an overhead, but for most of the
190:                //strings, this will save time)
191:                if ((inData.indexOf('&') == -1) && (inData.indexOf('<') == -1)
192:                        && (inData.indexOf('>') == -1)
193:                        && (inData.indexOf('\'') == -1)
194:                        && (inData.indexOf('\"') == -1)) {
195:                    return inData;
196:                }
197:
198:                //get the length of input String
199:                int length = inData.length();
200:
201:                //create a StringBuffer of double the size (size is just for guidance
202:                //so as to reduce increase-capacity operations. The actual size of
203:                //the resulting string may be even greater than we specified, but is
204:                //extremely rare)
205:                StringBuffer buffer = new StringBuffer(2 * length);
206:
207:                char charToCompare;
208:
209:                //iterate over the input String
210:                for (int i = 0; i < length; i++) {
211:                    charToCompare = inData.charAt(i);
212:
213:                    //if the ith character is special character, replace by code
214:                    if (charToCompare == '&') {
215:                        buffer.append("&amp;");
216:                    } else if (charToCompare == '<') {
217:                        buffer.append("&lt;");
218:                    } else if (charToCompare == '>') {
219:                        buffer.append("&gt;");
220:                    } else if (charToCompare == '\"') {
221:                        buffer.append("&quot;");
222:                    } else if (charToCompare == '\'') {
223:                        buffer.append("&apos;");
224:                    } else {
225:                        buffer.append(charToCompare);
226:                    }
227:                }
228:
229:                //LOGGER.exiting("GMLUtils", "encodeXML", buffer.toString());
230:
231:                //return the encoded string
232:                return buffer.toString();
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.