Source Code Cross Referenced for CatalogReader.java in  » GIS » GeoServer » org » geoserver » data » 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.geoserver.data 
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.geoserver.data;
006:
007:        import org.geoserver.util.ReaderUtils;
008:        import org.w3c.dom.Element;
009:        import org.w3c.dom.NodeList;
010:        import java.io.File;
011:        import java.io.FileReader;
012:        import java.io.IOException;
013:        import java.util.ArrayList;
014:        import java.util.HashMap;
015:        import java.util.List;
016:        import java.util.Map;
017:
018:        /**
019:         * Reads the GeoServer catalog.xml file.
020:         * <p>
021:         * Usage:
022:         *
023:         * <pre>
024:         *         <code>
025:         *                 File catalog = new File( ".../catalog.xml" );
026:         *                 CatalogReader reader = new CatalogReader();
027:         *                 reader.read( catalog );
028:         *                 List dataStores = reader.dataStores();
029:         *                 LIst nameSpaces = reader.nameSpaces();
030:         *         </code>
031:         * </pre>
032:         * </p>
033:         *
034:         * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
035:         *
036:         */
037:        public class CatalogReader {
038:            /**
039:             * Root catalog element.
040:             */
041:            Element catalog;
042:
043:            /**
044:             * Parses the catalog.xml file into a DOM.
045:             * <p>
046:             * This method *must* be called before any other methods.
047:             * </p>
048:             *
049:             * @param file The catalog.xml file.
050:             *
051:             * @throws IOException In event of a parser error.
052:             */
053:            public void read(File file) throws IOException {
054:                FileReader reader = new FileReader(file);
055:
056:                try {
057:                    catalog = ReaderUtils.parse(reader);
058:                } finally {
059:                    reader.close();
060:                }
061:            }
062:
063:            /**
064:             * Reads "datastore" elements from the catalog.xml file.
065:             * <p>
066:             *  For each datastore element read, a map of the connection parameters is
067:             *  created.
068:             *  </p>
069:             *
070:             * @return A list of Map objects containg the datastore connection parameters.
071:             *
072:             * @throws Exception If error processing "datastores" element.
073:             */
074:            public List /*<Map>*/dataStores() throws Exception {
075:                Element dataStoresElement = ReaderUtils.getChildElement(
076:                        catalog, "datastores", true);
077:
078:                NodeList dataStoreElements = dataStoresElement
079:                        .getElementsByTagName("datastore");
080:                ArrayList dataStores = new ArrayList();
081:
082:                for (int i = 0; i < dataStoreElements.getLength(); i++) {
083:                    Element dataStoreElement = (Element) dataStoreElements
084:                            .item(i);
085:
086:                    try {
087:                        Map params = dataStoreParams(dataStoreElement);
088:                        dataStores.add(params);
089:                    } catch (Exception e) {
090:                        //TODO: log this
091:                        continue;
092:                    }
093:                }
094:
095:                return dataStores;
096:            }
097:
098:            /**
099:             * Reads "namespace" elements from the catalog.xml file.
100:             * <p>
101:             *  For each namespace element read, an entry of <prefix,uri> is created
102:             *  in a map. The default uri is located under the empty string key.
103:             *  </p>
104:             *
105:             * @return A map containing <prefix,uri> tuples.
106:             *
107:             * @throws Exception If error processing "namespaces" element.
108:             */
109:            public Map namespaces() throws Exception {
110:                Element namespacesElement = ReaderUtils.getChildElement(
111:                        catalog, "namespaces", true);
112:
113:                NodeList namespaceElements = namespacesElement
114:                        .getElementsByTagName("namespace");
115:                Map namespaces = new HashMap();
116:
117:                for (int i = 0; i < namespaceElements.getLength(); i++) {
118:                    Element namespaceElement = (Element) namespaceElements
119:                            .item(i);
120:
121:                    try {
122:                        Map.Entry tuple = namespaceTuple(namespaceElement);
123:                        namespaces.put(tuple.getKey(), tuple.getValue());
124:
125:                        //check for default
126:                        if ("true".equals(namespaceElement
127:                                .getAttribute("default"))) {
128:                            namespaces.put("", tuple.getValue());
129:                        }
130:                    } catch (Exception e) {
131:                        //TODO: log this
132:                        continue;
133:                    }
134:                }
135:
136:                return namespaces;
137:            }
138:
139:            /**
140:             * Convenience method for reading connection parameters from a datastore
141:             * element.
142:             *
143:             * @param dataStoreElement The "datastore" element.
144:             *
145:             * @return The map of connection paramters.
146:             *
147:             * @throws Exception If problem parsing any parameters.
148:             */
149:            protected Map dataStoreParams(Element dataStoreElement)
150:                    throws Exception {
151:                Element paramsElement = ReaderUtils.getChildElement(
152:                        dataStoreElement, "connectionParameters", true);
153:                NodeList paramList = paramsElement
154:                        .getElementsByTagName("parameter");
155:
156:                Map params = new HashMap();
157:
158:                for (int i = 0; i < paramList.getLength(); i++) {
159:                    Element paramElement = (Element) paramList.item(i);
160:                    String key = ReaderUtils.getAttribute(paramElement, "name",
161:                            true);
162:                    String value = ReaderUtils.getAttribute(paramElement,
163:                            "value", true);
164:
165:                    params.put(key, value);
166:                }
167:
168:                return params;
169:            }
170:
171:            /**
172:             * Convenience method for reading namespace prefix and uri from a namespace
173:             * element.
174:             *
175:             * @param namespaceElement The "namespace" element.
176:             *
177:             * @return A <prefix,uri> tuple.
178:             *
179:             * @throws Exception If problem parsing any parameters.
180:             */
181:            protected Map.Entry namespaceTuple(Element namespaceElement)
182:                    throws Exception {
183:                final String pre = namespaceElement.getAttribute("prefix");
184:                final String uri = namespaceElement.getAttribute("uri");
185:
186:                return new Map.Entry() {
187:                    public Object getKey() {
188:                        return pre;
189:                    }
190:
191:                    public Object getValue() {
192:                        return uri;
193:                    }
194:
195:                    public Object setValue(Object value) {
196:                        throw new UnsupportedOperationException();
197:                    }
198:                };
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.