Source Code Cross Referenced for GETMAPValidator.java in  » GIS » GeoServer » org » vfny » geoserver » util » 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.util 
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:
006:        /*
007:         * Created on April 20, 2005
008:         *
009:         */
010:        package org.vfny.geoserver.util;
011:
012:        import org.apache.xerces.parsers.SAXParser;
013:        import org.vfny.geoserver.global.GeoserverDataDirectory;
014:        import org.xml.sax.InputSource;
015:        import org.xml.sax.SAXException;
016:        import org.xml.sax.SAXParseException;
017:        import org.xml.sax.helpers.DefaultHandler;
018:        import java.io.File;
019:        import java.io.InputStream;
020:        import java.io.InputStreamReader;
021:        import java.io.Reader;
022:        import java.util.ArrayList;
023:        import java.util.List;
024:        import javax.servlet.ServletContext;
025:
026:        public class GETMAPValidator {
027:            public GETMAPValidator() {
028:            }
029:
030:            /**
031:             *  validates against the "normal" location of the schema (ie. ".../capabilities/sld/StyleLayerDescriptor.xsd"
032:             *  uses the geoserver_home patch
033:             * @param xml
034:             * @param servContext servlet context
035:             * @return
036:             */
037:            public List validateGETMAP(InputStream xml,
038:                    ServletContext servContext) {
039:                // File schemaFile = new File( GeoserverDataDirectory.getGeoserverDataDirectory(servContext),"/data/capabilities/sld/StyledLayerDescriptor.xsd");
040:                File schemaFile = new File(GeoserverDataDirectory
041:                        .getGeoserverDataDirectory(),
042:                        "/data/capabilities/sld/GetMap.xsd");
043:
044:                try {
045:                    return validateGETMAP(xml, schemaFile.toURL().toString());
046:                } catch (Exception e) {
047:                    ArrayList al = new ArrayList();
048:                    al.add(new SAXException(e));
049:
050:                    return al;
051:                }
052:            }
053:
054:            public static String getErrorMessage(InputStream xml, List errors) {
055:                return getErrorMessage(new InputStreamReader(xml), errors);
056:            }
057:
058:            /**
059:             *  returns a better formated error message - suitable for framing.
060:             * There's a more complex version in StylesEditorAction.
061:             *
062:             * This will kick out a VERY LARGE errorMessage.
063:             *
064:             * @param xml
065:             * @param errors
066:             */
067:            public static String getErrorMessage(Reader xml, List errors) {
068:                return SLDValidator.getErrorMessage(xml, errors);
069:            }
070:
071:            public List validateGETMAP(InputStream xml, String SchemaUrl) {
072:                return validateGETMAP(new InputSource(xml), SchemaUrl);
073:            }
074:
075:            public List validateGETMAP(InputSource xml,
076:                    ServletContext servContext) {
077:                File schemaFile = new File(GeoserverDataDirectory
078:                        .getGeoserverDataDirectory(),
079:                        "/data/capabilities/sld/GetMap.xsd");
080:
081:                try {
082:                    return validateGETMAP(xml, schemaFile.toURL().toString());
083:                } catch (Exception e) {
084:                    ArrayList al = new ArrayList();
085:                    al.add(new SAXException(e));
086:
087:                    return al;
088:                }
089:            }
090:
091:            /**
092:             *  validate a GETMAP against the schema
093:             *
094:             * @param xml  input stream representing the GETMAP file
095:             * @param SchemaUrl location of the schemas. Normally use ".../capabilities/sld/StyleLayerDescriptor.xsd"
096:             * @return list of SAXExceptions (0 if the file's okay)
097:             */
098:            public List validateGETMAP(InputSource xml, String SchemaUrl) {
099:                SAXParser parser = new SAXParser();
100:
101:                try {
102:                    parser.setFeature("http://xml.org/sax/features/validation",
103:                            true);
104:                    parser.setFeature(
105:                            "http://apache.org/xml/features/validation/schema",
106:                            true);
107:                    parser
108:                            .setFeature(
109:                                    "http://apache.org/xml/features/validation/schema-full-checking",
110:                                    false);
111:
112:                    parser
113:                            .setProperty(
114:                                    "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
115:                                    SchemaUrl);
116:                    // parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation","http://www.opengis.net/sld "+SchemaUrl);
117:                    parser
118:                            .setProperty(
119:                                    "http://apache.org/xml/properties/schema/external-schemaLocation",
120:                                    "http://www.opengis.net/ows " + SchemaUrl);
121:
122:                    Validator handler = new Validator();
123:                    parser.setErrorHandler(handler);
124:                    parser.parse(xml);
125:
126:                    return handler.errors;
127:                } catch (java.io.IOException ioe) {
128:                    ArrayList al = new ArrayList();
129:                    al.add(new SAXParseException(ioe.getLocalizedMessage(),
130:                            null));
131:
132:                    return al;
133:                } catch (SAXException e) {
134:                    ArrayList al = new ArrayList();
135:                    al
136:                            .add(new SAXParseException(e.getLocalizedMessage(),
137:                                    null));
138:
139:                    return al;
140:                }
141:            }
142:
143:            // errors in the document will be put in "errors".
144:            // if errors.size() ==0  then there were no errors.
145:            private class Validator extends DefaultHandler {
146:                public ArrayList errors = new ArrayList();
147:
148:                public void error(SAXParseException exception)
149:                        throws SAXException {
150:                    if (!(exception.getMessage()
151:                            .startsWith("TargetNamespace.2: Expecting no namespace, but the schema document has a target name"))) {
152:                        errors.add(exception);
153:                    }
154:                }
155:
156:                public void fatalError(SAXParseException exception)
157:                        throws SAXException {
158:                    errors.add(exception);
159:                }
160:
161:                public void warning(SAXParseException exception)
162:                        throws SAXException {
163:                    //do nothing
164:                }
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.