Source Code Cross Referenced for XMLConfigReader.java in  » GIS » GeoServer » org » vfny » geoserver » global » xml » 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.global.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
0002:         * This code is licensed under the GPL 2.0 license, availible at the root
0003:         * application directory.
0004:         */
0005:        package org.vfny.geoserver.global.xml;
0006:
0007:        import java.io.File;
0008:        import java.io.FileFilter;
0009:        import java.io.FileInputStream;
0010:        import java.io.FileNotFoundException;
0011:        import java.io.IOException;
0012:        import java.io.Reader;
0013:        import java.io.StringWriter;
0014:        import java.io.UnsupportedEncodingException;
0015:        import java.net.MalformedURLException;
0016:        import java.net.URL;
0017:        import java.net.URLDecoder;
0018:        import java.nio.charset.Charset;
0019:        import java.util.ArrayList;
0020:        import java.util.Collections;
0021:        import java.util.HashMap;
0022:        import java.util.Iterator;
0023:        import java.util.LinkedList;
0024:        import java.util.List;
0025:        import java.util.Map;
0026:        import java.util.Vector;
0027:        import java.util.logging.Level;
0028:        import java.util.logging.Logger;
0029:
0030:        import javax.servlet.ServletContext;
0031:
0032:        import org.apache.xml.serialize.LineSeparator;
0033:        import org.apache.xml.serialize.OutputFormat;
0034:        import org.apache.xml.serialize.XMLSerializer;
0035:        import org.geoserver.ows.util.XmlCharsetDetector;
0036:        import org.geoserver.ows.xml.v1_0.UpdateSequenceTypeBinding;
0037:        import org.geoserver.util.ReaderUtils;
0038:        import org.geotools.coverage.grid.GeneralGridRange;
0039:        import org.geotools.coverage.grid.GridGeometry2D;
0040:        import org.geotools.filter.FilterDOMParser;
0041:        import org.geotools.geometry.GeneralDirectPosition;
0042:        import org.geotools.geometry.GeneralEnvelope;
0043:        import org.geotools.referencing.CRS;
0044:        import org.geotools.referencing.operation.DefaultMathTransformFactory;
0045:        import org.geotools.referencing.operation.matrix.GeneralMatrix;
0046:        import org.geotools.util.NameFactory;
0047:        import org.geotools.util.NumberRange;
0048:        import org.opengis.coverage.grid.GridGeometry;
0049:        import org.opengis.filter.Filter;
0050:        import org.opengis.geometry.MismatchedDimensionException;
0051:        import org.opengis.referencing.FactoryException;
0052:        import org.opengis.referencing.NoSuchAuthorityCodeException;
0053:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
0054:        import org.opengis.referencing.operation.MathTransform;
0055:        import org.opengis.referencing.operation.MathTransformFactory;
0056:        import org.opengis.referencing.operation.Matrix;
0057:        import org.opengis.referencing.operation.TransformException;
0058:        import org.opengis.util.InternationalString;
0059:        import org.vfny.geoserver.global.ConfigurationException;
0060:        import org.vfny.geoserver.global.CoverageDimension;
0061:        import org.vfny.geoserver.global.FeatureTypeInfo;
0062:        import org.vfny.geoserver.global.GeoserverDataDirectory;
0063:        import org.vfny.geoserver.global.MetaDataLink;
0064:        import org.vfny.geoserver.global.dto.AttributeTypeInfoDTO;
0065:        import org.vfny.geoserver.global.dto.ContactDTO;
0066:        import org.vfny.geoserver.global.dto.CoverageInfoDTO;
0067:        import org.vfny.geoserver.global.dto.CoverageStoreInfoDTO;
0068:        import org.vfny.geoserver.global.dto.DataDTO;
0069:        import org.vfny.geoserver.global.dto.DataStoreInfoDTO;
0070:        import org.vfny.geoserver.global.dto.FeatureTypeInfoDTO;
0071:        import org.vfny.geoserver.global.dto.GeoServerDTO;
0072:        import org.vfny.geoserver.global.dto.LegendURLDTO;
0073:        import org.vfny.geoserver.global.dto.NameSpaceInfoDTO;
0074:        import org.vfny.geoserver.global.dto.ServiceDTO;
0075:        import org.vfny.geoserver.global.dto.StyleDTO;
0076:        import org.vfny.geoserver.global.dto.WCSDTO;
0077:        import org.vfny.geoserver.global.dto.WFSDTO;
0078:        import org.vfny.geoserver.global.dto.WMSDTO;
0079:        import org.vfny.geoserver.util.CoverageStoreUtils;
0080:        import org.w3c.dom.Element;
0081:        import org.w3c.dom.Node;
0082:        import org.w3c.dom.NodeList;
0083:
0084:        import com.vividsolutions.jts.geom.Coordinate;
0085:        import com.vividsolutions.jts.geom.Envelope;
0086:
0087:        /**
0088:         * XMLConfigReader purpose.
0089:         * 
0090:         * <p>
0091:         * Description of XMLConfigReader Static class to load a configuration
0092:         * org.vfny.geoserver.global.dto
0093:         * </p>
0094:         * 
0095:         * <p>
0096:         * Example Use:
0097:         * 
0098:         * <pre><code>
0099:         * ModelConfig m = XMLConfigReader.load(new File(&quot;/conf/&quot;));
0100:         * </code></pre>
0101:         * 
0102:         * </p>
0103:         * 
0104:         * @author dzwiers, Refractions Research, Inc.
0105:         * @version $Id: XMLConfigReader.java 8443 2008-02-25 13:18:59Z groldan $
0106:         */
0107:        public class XMLConfigReader {
0108:            /** Used internally to create log information to detect errors. */
0109:            private static final Logger LOGGER = org.geotools.util.logging.Logging
0110:                    .getLogger("org.vfny.geoserver.global");
0111:
0112:            /** The root directory from which the configuration is loaded. */
0113:            private File root;
0114:
0115:            /** Is set to true after the model is loaded into memory. */
0116:            private boolean initialized = false;
0117:
0118:            private WMSDTO wms;
0119:
0120:            private WFSDTO wfs;
0121:
0122:            private WCSDTO wcs;
0123:
0124:            private GeoServerDTO geoServer;
0125:
0126:            private DataDTO data;
0127:
0128:            /** the servlet context * */
0129:            ServletContext context;
0130:
0131:            /**
0132:             * XMLConfigReader constructor.
0133:             * 
0134:             * <p>
0135:             * Should never be called.
0136:             * </p>
0137:             */
0138:            protected XMLConfigReader(ServletContext context) {
0139:                this .context = context;
0140:                wms = new WMSDTO();
0141:                wfs = new WFSDTO();
0142:                wcs = new WCSDTO();
0143:                geoServer = new GeoServerDTO();
0144:                data = new DataDTO();
0145:                root = new File(".");
0146:            }
0147:
0148:            /**
0149:             * <p>
0150:             * This method loads the config files from the specified directory into a
0151:             * ModelConfig. If the path is incorrect, or the directory is formed
0152:             * correctly, a ConfigException will be thrown and/or null returned. <br>
0153:             * <br>
0154:             * The config directory is as follows:<br>
0155:             * 
0156:             * <ul>
0157:             * <li> ./WEB-INF/catalog.xml </li>
0158:             * <li> ./WEB-INF/services.xml </li>
0159:             * <li> ./data/featuretypes/ /info.xml </li>
0160:             * <li> ./data/featuretypes/ /schema.xml </li>
0161:             * </ul>
0162:             * </p>
0163:             * 
0164:             * @param root
0165:             *            A directory which contains the config files.
0166:             * 
0167:             * @throws ConfigurationException
0168:             *             When an error occurs.
0169:             */
0170:            public XMLConfigReader(File root, ServletContext context)
0171:                    throws ConfigurationException {
0172:                this .root = root;
0173:                this .context = context;
0174:                wms = new WMSDTO();
0175:                wfs = new WFSDTO();
0176:                wcs = new WCSDTO();
0177:                geoServer = new GeoServerDTO();
0178:                data = new DataDTO();
0179:                load();
0180:                initialized = true;
0181:            }
0182:
0183:            public boolean isInitialized() {
0184:                return initialized;
0185:            }
0186:
0187:            /**
0188:             * load purpose.
0189:             * 
0190:             * <p>
0191:             * Main load routine, sets up file handles for various other portions of the
0192:             * load procedure.
0193:             * </p>
0194:             * 
0195:             * @throws ConfigurationException
0196:             */
0197:            protected void load() throws ConfigurationException {
0198:                try {
0199:                    root = ReaderUtils.checkFile(root, true);
0200:                } catch (FileNotFoundException e) {
0201:                    throw new ConfigurationException("Can't access "
0202:                            + root.getAbsolutePath(), e);
0203:                }
0204:
0205:                // try and see if this is a data dir of some kind, then load the services
0206:                File servicesFile = GeoserverDataDirectory
0207:                        .findConfigFile("services.xml");
0208:                File catalogFile = GeoserverDataDirectory
0209:                        .findConfigFile("catalog.xml");
0210:                if (servicesFile == null)
0211:                    throw new ConfigurationException(
0212:                            "Invalid data dir, it does not contain a valid services.xml");
0213:                if (catalogFile == null)
0214:                    throw new ConfigurationException(
0215:                            "Invalid data dir, it does not contain a valid catalog.xml");
0216:                loadServices(servicesFile);
0217:
0218:                // find or create the minimal subdirs in a data directory, then load the catalog
0219:                File featureTypeDir = GeoserverDataDirectory
0220:                        .findCreateConfigDir("featureTypes");
0221:                File styleDir = GeoserverDataDirectory
0222:                        .findCreateConfigDir("styles");
0223:                File coverageDir = GeoserverDataDirectory
0224:                        .findCreateConfigDir("coverages");
0225:                loadCatalog(catalogFile, featureTypeDir, styleDir, coverageDir);
0226:            }
0227:
0228:            /**
0229:             * loadServices purpose.
0230:             * 
0231:             * <p>
0232:             * loads services.xml into memory with the assistance of other class
0233:             * methods.
0234:             * </p>
0235:             * 
0236:             * @param configFile
0237:             *            services.xml
0238:             * 
0239:             * @throws ConfigurationException
0240:             *             When an error occurs.
0241:             */
0242:            protected void loadServices(File configFile)
0243:                    throws ConfigurationException {
0244:                if (LOGGER.isLoggable(Level.FINE)) {
0245:                    LOGGER.config(new StringBuffer(
0246:                            "Loading configuration file: ").append(configFile)
0247:                            .toString());
0248:                }
0249:
0250:                Element configElem = null;
0251:
0252:                try {
0253:                    Reader reader = XmlCharsetDetector
0254:                            .getCharsetAwareReader(new FileInputStream(
0255:                                    configFile));
0256:                    configElem = ReaderUtils.parse(reader);
0257:                    reader.close();
0258:                } catch (FileNotFoundException e) {
0259:                    throw new ConfigurationException(configFile
0260:                            + " was not found", e);
0261:                } catch (Exception e) {
0262:                    throw new ConfigurationException(configFile
0263:                            + " contents do not seem to be valid", e);
0264:                }
0265:
0266:                if (LOGGER.isLoggable(Level.FINE)) {
0267:                    LOGGER.fine("parsing configuration documents");
0268:                }
0269:
0270:                Element elem = (Element) configElem.getElementsByTagName(
0271:                        "global").item(0);
0272:                loadGlobal(elem);
0273:
0274:                NodeList configuredServices = configElem
0275:                        .getElementsByTagName("service");
0276:                boolean foundWCS = false; // record if we have found them or not
0277:
0278:                int nServices = configuredServices.getLength();
0279:
0280:                for (int i = 0; i < nServices; i++) {
0281:                    elem = (Element) configuredServices.item(i);
0282:
0283:                    String serviceType = elem.getAttribute("type");
0284:
0285:                    if ("WCS".equalsIgnoreCase(serviceType)) {
0286:                        foundWCS = true;
0287:                        loadWCS(elem);
0288:                    } else if ("WFS".equalsIgnoreCase(serviceType)) {
0289:                        loadWFS(elem);
0290:                    } else if ("WMS".equalsIgnoreCase(serviceType)) {
0291:                        loadWMS(elem);
0292:                    } else {
0293:                        LOGGER.warning("Ignoring unknown service type: "
0294:                                + serviceType);
0295:                    }
0296:                }
0297:
0298:                if (!foundWCS) {
0299:                    wcs = defaultWcsDto();
0300:                }
0301:            }
0302:
0303:            /**
0304:             * This is a very poor, but effective tempory method of setting a default
0305:             * service value for WCS, until we get a new config system.
0306:             * 
0307:             * @return
0308:             */
0309:            private WCSDTO defaultWcsDto() {
0310:                WCSDTO dto = new WCSDTO();
0311:                ServiceDTO service = new ServiceDTO();
0312:                service.setName("My GeoServer WCS");
0313:                service.setTitle("My GeoServer WCS");
0314:                service.setEnabled(true);
0315:
0316:                List keyWords = new ArrayList();
0317:                keyWords.add("WCS");
0318:                keyWords.add("WMS");
0319:                keyWords.add("GEOSERVER");
0320:                service.setKeywords(keyWords);
0321:
0322:                MetaDataLink mdl = new MetaDataLink();
0323:                mdl.setAbout("http://geoserver.org");
0324:                mdl.setType("undef");
0325:                mdl.setMetadataType("other");
0326:                mdl.setContent("NONE");
0327:                service.setMetadataLink(mdl);
0328:                service.setFees("NONE");
0329:                service.setAccessConstraints("NONE");
0330:                service
0331:                        .setMaintainer("http://jira.codehaus.org/secure/BrowseProject.jspa?id=10311");
0332:
0333:                try {
0334:                    service.setOnlineResource(new URL("http://geoserver.org"));
0335:                } catch (MalformedURLException e) {
0336:                    e.printStackTrace();
0337:                }
0338:
0339:                dto.setService(service);
0340:
0341:                return dto;
0342:            }
0343:
0344:            /**
0345:             * loadCatalog purpose.
0346:             * 
0347:             * <p>
0348:             * loads catalog.xml into memory with the assistance of other class methods.
0349:             * </p>
0350:             * 
0351:             * @param catalogFile
0352:             *            catalog.xml
0353:             * @param featureTypeDir
0354:             *            the directory containing the info.xml files for the
0355:             *            featuretypes.
0356:             * 
0357:             * @throws ConfigurationException
0358:             *             When an error occurs.
0359:             */
0360:            protected void loadCatalog(File catalogFile, File featureTypeDir,
0361:                    File styleDir, File coverageDir)
0362:                    throws ConfigurationException {
0363:                Element catalogElem = null;
0364:
0365:                try {
0366:                    if (LOGGER.isLoggable(Level.FINE)) {
0367:                        LOGGER.config(new StringBuffer(
0368:                                "Loading configuration file: ").append(
0369:                                catalogFile).toString());
0370:                    }
0371:
0372:                    Reader fr = XmlCharsetDetector
0373:                            .getCharsetAwareReader(new FileInputStream(
0374:                                    catalogFile));
0375:                    catalogElem = ReaderUtils.parse(fr);
0376:                    fr.close();
0377:                } catch (FileNotFoundException e) {
0378:                    throw new ConfigurationException(catalogFile
0379:                            + " was not found", e);
0380:                } catch (Exception e) {
0381:                    throw new ConfigurationException(catalogFile
0382:                            + " contents to not seem to be valid", e);
0383:                }
0384:
0385:                try {
0386:                    data.setNameSpaces(loadNameSpaces(ReaderUtils
0387:                            .getChildElement(catalogElem, "namespaces", true)));
0388:                    setDefaultNS();
0389:
0390:                    try { // try <formats> to be backwards compatible to 1.4
0391:
0392:                        Element formatElement = ReaderUtils.getChildElement(
0393:                                catalogElem, "formats", true);
0394:                        data.setFormats(loadFormats(formatElement));
0395:                    } catch (Exception e) {
0396:                        // gobble
0397:                        LOGGER
0398:                                .warning("Your catalog.xml file is not up to date and is probably from an older "
0399:                                        + "version of GeoServer. This problem is now being fixed automatically.");
0400:                    }
0401:
0402:                    data.setDataStores(loadDataStores(ReaderUtils
0403:                            .getChildElement(catalogElem, "datastores", true)));
0404:
0405:                    data.setStyles(loadStyles(ReaderUtils.getChildElement(
0406:                            catalogElem, "styles", false), styleDir));
0407:                    // must be last
0408:                    data.setFeaturesTypes(loadFeatureTypes(featureTypeDir));
0409:                    data.setCoverages(loadCoverages(coverageDir));
0410:                } catch (Exception e) {
0411:                    throw new ConfigurationException(e);
0412:                }
0413:            }
0414:
0415:            /**
0416:             * setDefaultNS purpose.
0417:             * 
0418:             * <p>
0419:             * Finds and sets the default namespace. The namespaces in catalog must
0420:             * already be loaded.
0421:             * </p>
0422:             */
0423:            protected void setDefaultNS() {
0424:                Iterator i = data.getNameSpaces().values().iterator();
0425:
0426:                while (i.hasNext()) {
0427:                    NameSpaceInfoDTO ns = (NameSpaceInfoDTO) i.next();
0428:
0429:                    if (ns.isDefault()) {
0430:                        data.setDefaultNameSpacePrefix(ns.getPrefix());
0431:
0432:                        if (LOGGER.isLoggable(Level.FINER)) {
0433:                            LOGGER.finer(new StringBuffer(
0434:                                    "set default namespace pre to ").append(
0435:                                    ns.getPrefix()).toString());
0436:                        }
0437:
0438:                        return;
0439:                    }
0440:                }
0441:            }
0442:
0443:            /**
0444:             * getLoggingLevel purpose.
0445:             * 
0446:             * <p>
0447:             * Parses the LoggingLevel from a DOM tree and converts the level into a
0448:             * Level Object.
0449:             * </p>
0450:             * 
0451:             * @param globalConfigElem
0452:             * 
0453:             * @return The logging Level
0454:             * 
0455:             * @throws ConfigurationException
0456:             *             When an error occurs.
0457:             */
0458:            protected Level getLoggingLevel(Element globalConfigElem)
0459:                    throws ConfigurationException {
0460:                Level level = Logger.getLogger("org.vfny.geoserver").getLevel();
0461:                Element levelElem = ReaderUtils.getChildElement(
0462:                        globalConfigElem, "loggingLevel");
0463:
0464:                if (levelElem != null) {
0465:                    String levelName = levelElem.getFirstChild().getNodeValue();
0466:
0467:                    try {
0468:                        level = Level.parse(levelName);
0469:                    } catch (IllegalArgumentException ex) {
0470:                        if (LOGGER.isLoggable(Level.WARNING)) {
0471:                            LOGGER.warning(new StringBuffer(
0472:                                    "illegal loggingLevel name: ").append(
0473:                                    levelName).toString());
0474:                        }
0475:                    }
0476:                } else {
0477:                    if (LOGGER.isLoggable(Level.FINE)) {
0478:                        LOGGER
0479:                                .config("No loggingLevel found, using default logging.properties setting");
0480:                    }
0481:                }
0482:
0483:                return level;
0484:            }
0485:
0486:            /**
0487:             * loadGlobal purpose.
0488:             * 
0489:             * <p>
0490:             * Converts a DOM tree into a GlobalData configuration.
0491:             * </p>
0492:             * 
0493:             * @param globalElem
0494:             *            A DOM tree representing a complete global configuration.
0495:             * 
0496:             * @throws ConfigurationException
0497:             *             When an error occurs.
0498:             */
0499:            protected void loadGlobal(Element globalElem)
0500:                    throws ConfigurationException {
0501:                try {
0502:                    geoServer = new GeoServerDTO();
0503:
0504:                    if (LOGGER.isLoggable(Level.FINER)) {
0505:                        LOGGER.finer("parsing global configuration parameters");
0506:                    }
0507:
0508:                    String log4jConfigFile = ReaderUtils.getChildText(
0509:                            globalElem, "log4jConfigFile", false);
0510:                    geoServer.setLog4jConfigFile(log4jConfigFile);
0511:
0512:                    boolean suppressStdOutLogging = false;
0513:                    Element elem = null;
0514:                    elem = ReaderUtils.getChildElement(globalElem,
0515:                            "suppressStdOutLogging", false);
0516:
0517:                    if (elem != null) {
0518:                        suppressStdOutLogging = ReaderUtils
0519:                                .getBooleanAttribute(elem, "value", false,
0520:                                        false);
0521:                    }
0522:
0523:                    String logLocation = ReaderUtils.getChildText(globalElem,
0524:                            "logLocation");
0525:
0526:                    if ((logLocation != null) && "".equals(logLocation.trim())) {
0527:                        logLocation = null;
0528:                    }
0529:
0530:                    geoServer.setSuppressStdOutLogging(suppressStdOutLogging);
0531:                    geoServer.setLogLocation(logLocation);
0532:
0533:                    if (LOGGER.isLoggable(Level.FINE)) {
0534:                        LOGGER.fine(new StringBuffer("logging config is ")
0535:                                .append(log4jConfigFile).toString());
0536:                    }
0537:
0538:                    if (logLocation != null) {
0539:                        if (LOGGER.isLoggable(Level.FINE)) {
0540:                            LOGGER.fine(new StringBuffer("logging to ").append(
0541:                                    logLocation).toString());
0542:                        }
0543:                    }
0544:
0545:                    double jaiMemoryCapacity = 0;
0546:                    elem = ReaderUtils.getChildElement(globalElem,
0547:                            "JaiMemoryCapacity", false);
0548:
0549:                    if (elem != null) {
0550:                        jaiMemoryCapacity = ReaderUtils.getDoubleAttribute(
0551:                                elem, "value", false);
0552:                    }
0553:
0554:                    double jaiMemoryThreshold = 0.0;
0555:                    elem = ReaderUtils.getChildElement(globalElem,
0556:                            "JaiMemoryThreshold", false);
0557:
0558:                    if (elem != null) {
0559:                        jaiMemoryThreshold = ReaderUtils.getDoubleAttribute(
0560:                                elem, "value", false);
0561:                    }
0562:
0563:                    int jaiTileThreads = 7;
0564:                    elem = ReaderUtils.getChildElement(globalElem,
0565:                            "JaiTileThreads", false);
0566:
0567:                    if (elem != null) {
0568:                        jaiTileThreads = ReaderUtils.getIntAttribute(elem,
0569:                                "value", false, 7);
0570:                    }
0571:
0572:                    int jaiTilePriority = 5;
0573:                    elem = ReaderUtils.getChildElement(globalElem,
0574:                            "JaiTilePriority", false);
0575:
0576:                    if (elem != null) {
0577:                        jaiTilePriority = ReaderUtils.getIntAttribute(elem,
0578:                                "value", false, 5);
0579:                    }
0580:
0581:                    Boolean jaiRecycling = Boolean.FALSE;
0582:                    elem = ReaderUtils.getChildElement(globalElem,
0583:                            "JaiRecycling", false);
0584:
0585:                    if (elem != null) {
0586:                        jaiRecycling = Boolean.valueOf(ReaderUtils
0587:                                .getBooleanAttribute(elem, "value", false,
0588:                                        false));
0589:                    }
0590:
0591:                    Boolean imageIOCache = Boolean.FALSE;
0592:                    elem = ReaderUtils.getChildElement(globalElem,
0593:                            "ImageIOCache", false);
0594:
0595:                    if (elem != null) {
0596:                        imageIOCache = Boolean.valueOf(ReaderUtils
0597:                                .getBooleanAttribute(elem, "value", false,
0598:                                        false));
0599:                    }
0600:
0601:                    Boolean jaiJPEGNative = Boolean.TRUE;
0602:                    elem = ReaderUtils.getChildElement(globalElem,
0603:                            "JaiJPEGNative", false);
0604:
0605:                    if (elem != null) {
0606:                        jaiJPEGNative = Boolean.valueOf(ReaderUtils
0607:                                .getBooleanAttribute(elem, "value", false,
0608:                                        false));
0609:                    }
0610:
0611:                    Boolean jaiPNGNative = Boolean.TRUE;
0612:                    elem = ReaderUtils.getChildElement(globalElem,
0613:                            "JaiPNGNative", false);
0614:
0615:                    if (elem != null) {
0616:                        jaiPNGNative = Boolean.valueOf(ReaderUtils
0617:                                .getBooleanAttribute(elem, "value", false,
0618:                                        false));
0619:                    }
0620:
0621:                    geoServer.setJaiMemoryCapacity(jaiMemoryCapacity);
0622:                    geoServer.setJaiMemoryThreshold(jaiMemoryThreshold);
0623:                    geoServer.setJaiTileThreads(jaiTileThreads);
0624:                    geoServer.setJaiTilePriority(jaiTilePriority);
0625:                    geoServer.setJaiRecycling(jaiRecycling);
0626:                    geoServer.setImageIOCache(imageIOCache);
0627:                    geoServer.setJaiJPEGNative(jaiJPEGNative);
0628:                    geoServer.setJaiPNGNative(jaiPNGNative);
0629:
0630:                    elem = ReaderUtils.getChildElement(globalElem,
0631:                            "ContactInformation");
0632:                    geoServer.setContact(loadContact(elem));
0633:
0634:                    elem = ReaderUtils.getChildElement(globalElem, "verbose",
0635:                            false);
0636:
0637:                    if (elem != null) {
0638:                        geoServer.setVerbose(ReaderUtils.getBooleanAttribute(
0639:                                elem, "value", false, true));
0640:                    }
0641:
0642:                    elem = ReaderUtils.getChildElement(globalElem,
0643:                            "maxFeatures");
0644:
0645:                    if (elem != null) {
0646:                        // if the element is pressent, it's "value" attribute is
0647:                        // mandatory
0648:                        geoServer.setMaxFeatures(ReaderUtils
0649:                                .getIntAttribute(elem, "value", true, geoServer
0650:                                        .getMaxFeatures()));
0651:                    }
0652:
0653:                    if (LOGGER.isLoggable(Level.FINE)) {
0654:                        LOGGER.fine(new StringBuffer("maxFeatures is ").append(
0655:                                geoServer.getMaxFeatures()).toString());
0656:                    }
0657:
0658:                    elem = ReaderUtils.getChildElement(globalElem,
0659:                            "numDecimals");
0660:
0661:                    if (elem != null) {
0662:                        geoServer.setNumDecimals(ReaderUtils
0663:                                .getIntAttribute(elem, "value", true, geoServer
0664:                                        .getNumDecimals()));
0665:                    }
0666:
0667:                    if (LOGGER.isLoggable(Level.FINE)) {
0668:                        LOGGER.fine(new StringBuffer(
0669:                                "numDecimals returning is ").append(
0670:                                geoServer.getNumDecimals()).toString());
0671:                    }
0672:
0673:                    elem = ReaderUtils.getChildElement(globalElem, "charSet");
0674:
0675:                    if (elem != null) {
0676:                        String chSet = ReaderUtils.getAttribute(elem, "value",
0677:                                true);
0678:
0679:                        try {
0680:                            Charset cs = Charset.forName(chSet);
0681:                            geoServer.setCharSet(cs);
0682:
0683:                            if (LOGGER.isLoggable(Level.FINER)) {
0684:                                LOGGER.finer(new StringBuffer("charSet: ")
0685:                                        .append(cs.name()).toString());
0686:                            }
0687:                        } catch (Exception ex) {
0688:                            if (LOGGER.isLoggable(Level.INFO)) {
0689:                                LOGGER.info(ex.getMessage());
0690:                            }
0691:                        }
0692:                    }
0693:
0694:                    if (LOGGER.isLoggable(Level.FINE)) {
0695:                        LOGGER.fine(new StringBuffer("charSet is ").append(
0696:                                geoServer.getCharSet()).toString());
0697:                    }
0698:
0699:                    // Schema base doesn't work - this root thing is wrong. So for 1.2.0
0700:                    // I'm
0701:                    // just going to leave it out. The GeoServer.getSchemaBaseUrl is
0702:                    // never
0703:                    // called, Request.getSchemaBaseUrl is used, and it always returns
0704:                    // the
0705:                    // relative local one. This field was a hack anyways, so I don't
0706:                    // think
0707:                    // anyone is going to miss it much - though I could be proved wrong.
0708:                    // ch
0709:                    String schemaBaseUrl = ReaderUtils.getChildText(globalElem,
0710:                            "SchemaBaseUrl");
0711:
0712:                    if (schemaBaseUrl != null) {
0713:                        geoServer.setSchemaBaseUrl(schemaBaseUrl);
0714:                    } else {
0715:                        // This is wrong - need some key to tell the method to return
0716:                        // based
0717:                        // on the url passed in.
0718:                        geoServer.setSchemaBaseUrl(root.toString()
0719:                                + "/data/capabilities/");
0720:                    }
0721:
0722:                    String proxyBaseUrl = ReaderUtils.getChildText(globalElem,
0723:                            "ProxyBaseUrl");
0724:
0725:                    if (proxyBaseUrl != null) {
0726:                        geoServer.setProxyBaseUrl(proxyBaseUrl);
0727:                    } else {
0728:                        geoServer.setSchemaBaseUrl(null);
0729:                    }
0730:
0731:                    String adminUserName = ReaderUtils.getChildText(globalElem,
0732:                            "adminUserName");
0733:
0734:                    if (adminUserName != null) {
0735:                        geoServer.setAdminUserName(adminUserName);
0736:                    }
0737:
0738:                    String adminPassword = ReaderUtils.getChildText(globalElem,
0739:                            "adminPassword");
0740:
0741:                    if (adminPassword != null) {
0742:                        geoServer.setAdminPassword(adminPassword);
0743:                    }
0744:
0745:                    elem = ReaderUtils.getChildElement(globalElem,
0746:                            "verboseExceptions", false);
0747:
0748:                    if (elem != null) {
0749:                        geoServer
0750:                                .setVerboseExceptions(ReaderUtils
0751:                                        .getBooleanAttribute(elem, "value",
0752:                                                false, true));
0753:                    }
0754:
0755:                    String tileCache = ReaderUtils.getChildText(globalElem,
0756:                            "tileCache", false);
0757:
0758:                    if (tileCache != null) {
0759:                        geoServer.setTileCache(tileCache);
0760:                    } else {
0761:                        geoServer.setTileCache(null);
0762:                    }
0763:
0764:                    String gsUpdateSequence = ReaderUtils.getChildText(
0765:                            globalElem, "updateSequence");
0766:                    if (gsUpdateSequence == null) {
0767:                        geoServer.setUpdateSequence(0);
0768:                    } else {
0769:                        try {
0770:                            geoServer.setUpdateSequence(Integer
0771:                                    .parseInt(gsUpdateSequence));
0772:                        } catch (NumberFormatException nfe) {
0773:                            LOGGER.warning("Couldn't parse update sequence "
0774:                                    + gsUpdateSequence
0775:                                    + ".  Setting UpdateSequence to zero.");
0776:                            geoServer.setUpdateSequence(0);
0777:                        }
0778:                    }
0779:
0780:                } catch (Exception e) {
0781:                    throw new ConfigurationException(e);
0782:                }
0783:            }
0784:
0785:            /**
0786:             * loadContact purpose.
0787:             * 
0788:             * <p>
0789:             * Converts a DOM tree into a ContactConfig
0790:             * </p>
0791:             * 
0792:             * @param contactInfoElement
0793:             *            a DOM tree to convert into a ContactConfig.
0794:             * 
0795:             * @return The resulting ContactConfig object from the DOM tree.
0796:             * 
0797:             * @throws ConfigurationException
0798:             *             When an error occurs.
0799:             */
0800:            protected ContactDTO loadContact(Element contactInfoElement)
0801:                    throws ConfigurationException {
0802:                ContactDTO c = new ContactDTO();
0803:
0804:                if (contactInfoElement == null) {
0805:                    return c;
0806:                }
0807:
0808:                Element elem;
0809:                NodeList nodeList;
0810:                elem = ReaderUtils.getChildElement(contactInfoElement,
0811:                        "ContactPersonPrimary");
0812:
0813:                if (elem != null) {
0814:                    c.setContactPerson(ReaderUtils.getChildText(elem,
0815:                            "ContactPerson"));
0816:                    c.setContactOrganization(ReaderUtils.getChildText(elem,
0817:                            "ContactOrganization"));
0818:                }
0819:
0820:                c.setContactPosition(ReaderUtils.getChildText(
0821:                        contactInfoElement, "ContactPosition"));
0822:                elem = ReaderUtils.getChildElement(contactInfoElement,
0823:                        "ContactAddress");
0824:
0825:                if (elem != null) {
0826:                    c.setAddressType(ReaderUtils.getChildText(elem,
0827:                            "AddressType"));
0828:                    c.setAddress(ReaderUtils.getChildText(elem, "Address"));
0829:                    c.setAddressCity(ReaderUtils.getChildText(elem, "City"));
0830:                    c.setAddressState(ReaderUtils.getChildText(elem,
0831:                            "StateOrProvince"));
0832:                    c.setAddressPostalCode(ReaderUtils.getChildText(elem,
0833:                            "PostCode"));
0834:                    c.setAddressCountry(ReaderUtils.getChildText(elem,
0835:                            "Country"));
0836:                }
0837:
0838:                c.setContactVoice(ReaderUtils.getChildText(contactInfoElement,
0839:                        "ContactVoiceTelephone"));
0840:                c.setContactFacsimile(ReaderUtils.getChildText(
0841:                        contactInfoElement, "ContactFacsimileTelephone"));
0842:                c.setContactEmail(ReaderUtils.getChildText(contactInfoElement,
0843:                        "ContactElectronicMailAddress"));
0844:                c.setOnlineResource(ReaderUtils.getChildText(
0845:                        contactInfoElement, "ContactOnlineResource"));
0846:
0847:                return c;
0848:            }
0849:
0850:            /**
0851:             * loadWCS purpose.
0852:             * 
0853:             * <p>
0854:             * Converts a DOM tree into a WCS object.
0855:             * </p>
0856:             * 
0857:             * @param wfsElement
0858:             *            a DOM tree to convert into a WCS object.
0859:             * 
0860:             * @throws ConfigurationException
0861:             *             When an error occurs.
0862:             * 
0863:             * @see GlobalData#getBaseUrl()
0864:             */
0865:            protected void loadWCS(Element wcsElement)
0866:                    throws ConfigurationException {
0867:                wcs = new WCSDTO();
0868:                wcs.setService(loadService(wcsElement));
0869:            }
0870:
0871:            /**
0872:             * loadWFS purpose.
0873:             * 
0874:             * <p>
0875:             * Converts a DOM tree into a WFS object.
0876:             * </p>
0877:             * 
0878:             * @param wfsElement
0879:             *            a DOM tree to convert into a WFS object.
0880:             * 
0881:             * @throws ConfigurationException
0882:             *             When an error occurs.
0883:             * 
0884:             * @see GlobalData#getBaseUrl()
0885:             */
0886:            protected void loadWFS(Element wfsElement)
0887:                    throws ConfigurationException {
0888:                wfs = new WFSDTO();
0889:
0890:                try {
0891:                    wfs.setFeatureBounding(ReaderUtils.getBooleanAttribute(
0892:                            ReaderUtils.getChildElement(wfsElement,
0893:                                    "featureBounding"), "value", false, false));
0894:
0895:                    Element elem = ReaderUtils.getChildElement(wfsElement,
0896:                            "srsXmlStyle", false);
0897:
0898:                    if (LOGGER.isLoggable(Level.FINE)) {
0899:                        LOGGER.fine(new StringBuffer("reading srsXmlStyle: ")
0900:                                .append(elem).toString());
0901:                    }
0902:
0903:                    if (elem != null) {
0904:                        wfs.setSrsXmlStyle(ReaderUtils.getBooleanAttribute(
0905:                                elem, "value", false, true));
0906:
0907:                        if (LOGGER.isLoggable(Level.FINE)) {
0908:                            LOGGER
0909:                                    .fine(new StringBuffer(
0910:                                            "set srsXmlStyle to ")
0911:                                            .append(
0912:                                                    ReaderUtils
0913:                                                            .getBooleanAttribute(
0914:                                                                    elem,
0915:                                                                    "value",
0916:                                                                    false, true))
0917:                                            .toString());
0918:                        }
0919:                    }
0920:
0921:                    String serviceLevelValue = ReaderUtils.getChildText(
0922:                            wfsElement, "serviceLevel");
0923:                    int serviceLevel = WFSDTO.COMPLETE;
0924:
0925:                    if ((serviceLevelValue != null)
0926:                            && !serviceLevelValue.equals("")) {
0927:                        if (LOGGER.isLoggable(Level.FINER)) {
0928:                            LOGGER.finer(new StringBuffer(
0929:                                    "reading serviceLevel: ").append(
0930:                                    serviceLevelValue).toString());
0931:                        }
0932:
0933:                        if (serviceLevelValue.equalsIgnoreCase("basic")) {
0934:                            serviceLevel = WFSDTO.BASIC;
0935:                        } else if (serviceLevelValue
0936:                                .equalsIgnoreCase("complete")) {
0937:                            serviceLevel = WFSDTO.COMPLETE;
0938:                        } else if (serviceLevelValue
0939:                                .equalsIgnoreCase("transactional")) {
0940:                            serviceLevel = WFSDTO.TRANSACTIONAL;
0941:                        } else {
0942:                            try {
0943:                                serviceLevel = Integer
0944:                                        .parseInt(serviceLevelValue);
0945:                            } catch (NumberFormatException nfe) {
0946:                                String mesg = "Could not parse serviceLevel.  It "
0947:                                        + "should be one of Basic, Complete, or Transactional"
0948:                                        + " or else an integer value";
0949:                                throw new ConfigurationException(mesg, nfe);
0950:                            }
0951:                        }
0952:                    } else { // TODO: this should probably parse the strings as well,
0953:                        serviceLevel = ReaderUtils.getIntAttribute(ReaderUtils
0954:                                .getChildElement(wfsElement, "serviceLevel"),
0955:                                "value", false, WFSDTO.COMPLETE);
0956:                    }
0957:
0958:                    if (LOGGER.isLoggable(Level.FINER)) {
0959:                        LOGGER.finer(new StringBuffer(
0960:                                "setting service level to ").append(
0961:                                serviceLevel).toString());
0962:                    }
0963:
0964:                    wfs.setServiceLevel(serviceLevel);
0965:
0966:                    // get the conformance hacks attribute
0967:                    // it might not be there, in which case we just use the default
0968:                    // value
0969:                    // (see WFSDTO.java)
0970:                    Element e = ReaderUtils.getChildElement(wfsElement,
0971:                            "citeConformanceHacks");
0972:
0973:                    if (e != null) {
0974:                        String text = ReaderUtils.getChildText(wfsElement,
0975:                                "citeConformanceHacks");
0976:                        boolean citeConformanceHacks = Boolean.valueOf(text)
0977:                                .booleanValue(); // just
0978:                        // get
0979:                        // the
0980:                        // value
0981:                        // and
0982:                        // parse
0983:                        // it
0984:                        wfs.setCiteConformanceHacks(citeConformanceHacks);
0985:
0986:                        if (LOGGER.isLoggable(Level.FINER)) {
0987:                            LOGGER.finer(new StringBuffer(
0988:                                    "setting citeConformanceHacks to ").append(
0989:                                    citeConformanceHacks).toString());
0990:                        }
0991:                    }
0992:                } catch (Exception e) {
0993:                    throw new ConfigurationException(e);
0994:                }
0995:
0996:                ServiceDTO s = loadService(wfsElement);
0997:                wfs.setService(s);
0998:            }
0999:
1000:            /**
1001:             * loadWMS purpose.
1002:             * 
1003:             * <p>
1004:             * Converts a DOM tree into a WMS object.
1005:             * </p>
1006:             * 
1007:             * @param wmsElement
1008:             *            a DOM tree to convert into a WMS object.
1009:             * 
1010:             * @throws ConfigurationException
1011:             *             When an error occurs.
1012:             * 
1013:             * @see GlobalData#getBaseUrl()
1014:             */
1015:            protected void loadWMS(Element wmsElement)
1016:                    throws ConfigurationException {
1017:                wms = new WMSDTO();
1018:                wms.setService(loadService(wmsElement));
1019:
1020:                wms.setSvgRenderer(ReaderUtils.getChildText(wmsElement,
1021:                        "svgRenderer"));
1022:                wms.setSvgAntiAlias(!"false".equals(ReaderUtils.getChildText(
1023:                        wmsElement, "svgAntiAlias")));
1024:
1025:                try {
1026:                    wms.setAllowInterpolation(ReaderUtils.getChildText(
1027:                            wmsElement, "allowInterpolation", true));
1028:                } catch (Exception e) {
1029:                    wms.setAllowInterpolation("Nearest");
1030:                }
1031:
1032:                loadBaseMapLayers(wmsElement);
1033:            }
1034:
1035:            private void loadBaseMapLayers(Element wmsElement) {
1036:                HashMap layerMap = new HashMap();
1037:                HashMap styleMap = new HashMap();
1038:                HashMap envelopeMap = new HashMap();
1039:
1040:                Element groupBase = ReaderUtils.getChildElement(wmsElement,
1041:                        "BaseMapGroups");
1042:
1043:                if (groupBase == null) {
1044:                    LOGGER.config("No baseMap groups defined yet");
1045:
1046:                    return;
1047:                }
1048:
1049:                Element[] groups = ReaderUtils.getChildElements(groupBase,
1050:                        "BaseMapGroup");
1051:
1052:                for (int i = 0; i < groups.length; i++) {
1053:                    Element group = groups[i];
1054:
1055:                    try {
1056:                        String title = ReaderUtils.getAttribute(group,
1057:                                "baseMapTitle", true);
1058:                        String layers = ReaderUtils.getChildText(group,
1059:                                "baseMapLayers");
1060:                        String styles = ReaderUtils.getChildText(group,
1061:                                "baseMapStyles");
1062:
1063:                        Element envelope = ReaderUtils.getChildElement(group,
1064:                                "baseMapEnvelope");
1065:                        String srsName = ReaderUtils.getAttribute(envelope,
1066:                                "srsName", true);
1067:                        layerMap.put(title, layers);
1068:                        styleMap.put(title, styles);
1069:                        envelopeMap.put(title, loadEnvelope(envelope, CRS
1070:                                .decode(srsName)));
1071:                    } catch (Exception ex) {
1072:                        ex.printStackTrace();
1073:                    }
1074:                }
1075:
1076:                wms.setBaseMapLayers(layerMap);
1077:                wms.setBaseMapStyles(styleMap);
1078:                wms.setBaseMapEnvelopes(envelopeMap);
1079:            }
1080:
1081:            /**
1082:             * loadService purpose.
1083:             * 
1084:             * <p>
1085:             * Converts a DOM tree into a ServiceDTO object.
1086:             * </p>
1087:             * 
1088:             * @param serviceRoot
1089:             *            a DOM tree to convert into a ServiceDTO object.
1090:             * 
1091:             * @return A complete ServiceDTO object loaded from the DOM tree provided.
1092:             * 
1093:             * @throws ConfigurationException
1094:             *             When an error occurs.
1095:             */
1096:            protected ServiceDTO loadService(Element serviceRoot)
1097:                    throws ConfigurationException {
1098:                ServiceDTO s = new ServiceDTO();
1099:
1100:                try {
1101:                    String name = ReaderUtils.getChildText(serviceRoot, "name",
1102:                            true);
1103:                    s.setName(name);
1104:                    s.setTitle(ReaderUtils.getChildText(serviceRoot, "title",
1105:                            false));
1106:                    s.setAbstract(ReaderUtils.getChildText(serviceRoot,
1107:                            "abstract"));
1108:                    s.setKeywords(ReaderUtils.getKeyWords(ReaderUtils
1109:                            .getChildElement(serviceRoot, "keywords")));
1110:                    s.setMetadataLink(getMetaDataLink(ReaderUtils
1111:                            .getChildElement(serviceRoot, "metadataLink")));
1112:                    s.setFees(ReaderUtils.getChildText(serviceRoot, "fees"));
1113:                    s.setAccessConstraints(ReaderUtils.getChildText(
1114:                            serviceRoot, "accessConstraints"));
1115:                    s.setMaintainer(ReaderUtils.getChildText(serviceRoot,
1116:                            "maintainer"));
1117:                    s.setEnabled(ReaderUtils.getBooleanAttribute(serviceRoot,
1118:                            "enabled", false, true));
1119:                    s.setStrategy(ReaderUtils.getChildText(serviceRoot,
1120:                            "serviceStrategy"));
1121:                    s.setPartialBufferSize(ReaderUtils.getIntAttribute(
1122:                            serviceRoot, "partialBufferSize", false, 0));
1123:
1124:                    String url = ReaderUtils.getChildText(serviceRoot,
1125:                            "onlineResource", true);
1126:
1127:                    try {
1128:                        s.setOnlineResource(new URL(url));
1129:                    } catch (MalformedURLException e) {
1130:                        LOGGER
1131:                                .severe("Invalid online resource URL for service "
1132:                                        + name
1133:                                        + ": "
1134:                                        + url
1135:                                        + ". Defaulting to geoserver home.");
1136:                        s
1137:                                .setOnlineResource(new URL(
1138:                                        "http://www.geoserver.org"));
1139:                    }
1140:                } catch (Exception e) {
1141:                    throw new ConfigurationException(e);
1142:                }
1143:
1144:                return s;
1145:            }
1146:
1147:            /**
1148:             * loadNameSpaces purpose.
1149:             * 
1150:             * <p>
1151:             * Converts a DOM tree into a Map of NameSpaces.
1152:             * </p>
1153:             * 
1154:             * @param nsRoot
1155:             *            a DOM tree to convert into a Map of NameSpaces.
1156:             * 
1157:             * @return A complete Map of NameSpaces loaded from the DOM tree provided.
1158:             * 
1159:             * @throws ConfigurationException
1160:             *             When an error occurs.
1161:             */
1162:            protected Map loadNameSpaces(Element nsRoot)
1163:                    throws ConfigurationException {
1164:                NodeList nsList = nsRoot.getElementsByTagName("namespace");
1165:                Element elem;
1166:                int nsCount = nsList.getLength();
1167:                Map nameSpaces = new HashMap(nsCount);
1168:
1169:                try {
1170:                    for (int i = 0; i < nsCount; i++) {
1171:                        elem = (Element) nsList.item(i);
1172:
1173:                        NameSpaceInfoDTO ns = new NameSpaceInfoDTO();
1174:                        ns.setUri(ReaderUtils.getAttribute(elem, "uri", true));
1175:                        ns.setPrefix(ReaderUtils.getAttribute(elem, "prefix",
1176:                                true));
1177:                        ns.setDefault(ReaderUtils.getBooleanAttribute(elem,
1178:                                "default", false, false)
1179:                                || (nsCount == 1));
1180:
1181:                        if (LOGGER.isLoggable(Level.FINE)) {
1182:                            LOGGER.config(new StringBuffer("added namespace ")
1183:                                    .append(ns).toString());
1184:                        }
1185:
1186:                        nameSpaces.put(ns.getPrefix(), ns);
1187:                    }
1188:                } catch (Exception e) {
1189:                    throw new ConfigurationException(e);
1190:                }
1191:
1192:                return nameSpaces;
1193:            }
1194:
1195:            /**
1196:             * loadStyles purpose.
1197:             * 
1198:             * <p>
1199:             * Converts a DOM tree into a Map of Styles.
1200:             * </p>
1201:             * 
1202:             * @param stylesElem
1203:             *            a DOM tree to convert into a Map of Styles.
1204:             * @param baseDir
1205:             *            DOCUMENT ME!
1206:             * 
1207:             * @return A complete Map of Styles loaded from the DOM tree provided.
1208:             * 
1209:             * @throws ConfigurationException
1210:             *             When an error occurs.
1211:             */
1212:            protected Map loadStyles(Element stylesElem, File baseDir)
1213:                    throws ConfigurationException {
1214:                Map styles = new HashMap();
1215:
1216:                NodeList stylesList = null;
1217:
1218:                if (stylesElem != null) {
1219:                    stylesList = stylesElem.getElementsByTagName("style");
1220:                }
1221:
1222:                if ((stylesList == null) || (stylesList.getLength() == 0)) {
1223:                    // no styles where defined, just add a default one
1224:                    StyleDTO s = new StyleDTO();
1225:                    s.setId("normal");
1226:                    s.setFilename(new File(baseDir, "normal.sld"));
1227:                    s.setDefault(true);
1228:                    styles.put("normal", s);
1229:                }
1230:
1231:                int styleCount = stylesList.getLength();
1232:                Element styleElem;
1233:
1234:                for (int i = 0; i < styleCount; i++) {
1235:                    try {
1236:                        styleElem = (Element) stylesList.item(i);
1237:
1238:                        StyleDTO s = new StyleDTO();
1239:                        s
1240:                                .setId(ReaderUtils.getAttribute(styleElem,
1241:                                        "id", true));
1242:                        s.setFilename(new File(baseDir, ReaderUtils
1243:                                .getAttribute(styleElem, "filename", true)));
1244:                        s.setDefault(ReaderUtils.getBooleanAttribute(styleElem,
1245:                                "default", false, false));
1246:                        styles.put(s.getId(), s);
1247:
1248:                        if (LOGGER.isLoggable(Level.FINE)) {
1249:                            LOGGER.config(new StringBuffer("Loaded style ")
1250:                                    .append(s.getId()).toString());
1251:                        }
1252:                    } catch (Exception e) {
1253:                        LOGGER.log(Level.WARNING,
1254:                                "Ignored misconfigured style", e);
1255:                    }
1256:                }
1257:
1258:                return styles;
1259:            }
1260:
1261:            /**
1262:             * loadFormats purpose.
1263:             * 
1264:             * <p>
1265:             * Converts a DOM tree into a Map of Formats.
1266:             * </p>
1267:             * 
1268:             * @param fmRoot
1269:             *            a DOM tree to convert into a Map of Formats.
1270:             * 
1271:             * @return A complete Map of Formats loaded from the DOM tree provided.
1272:             * 
1273:             * @throws ConfigurationException
1274:             *             When an error occurs.
1275:             */
1276:            protected Map loadFormats(Element fmRoot)
1277:                    throws ConfigurationException {
1278:                Map formats = new HashMap();
1279:
1280:                if (fmRoot == null) { // if there are no formats (they are using
1281:                    // v.1.4)
1282:
1283:                    return formats; // just return the empty list
1284:                }
1285:
1286:                NodeList fmElements = fmRoot.getElementsByTagName("format");
1287:                int fmCnt = fmElements.getLength();
1288:                CoverageStoreInfoDTO fmConfig;
1289:                Element fmElem;
1290:
1291:                for (int i = 0; i < fmCnt; i++) {
1292:                    fmElem = (Element) fmElements.item(i);
1293:
1294:                    try {
1295:                        fmConfig = loadFormat(fmElem);
1296:
1297:                        if (formats.containsKey(fmConfig.getId())) {
1298:                            LOGGER.warning("Ignored duplicated format "
1299:                                    + data.getNameSpaces().get(
1300:                                            fmConfig.getNameSpaceId()));
1301:                        } else {
1302:                            formats.put(fmConfig.getId(), fmConfig);
1303:                        }
1304:                    } catch (ConfigurationException e) {
1305:                        LOGGER.log(Level.WARNING,
1306:                                "Ignored a misconfigured coverage.", e);
1307:                    }
1308:                }
1309:
1310:                return formats;
1311:            }
1312:
1313:            /**
1314:             * loadFormat purpose.
1315:             * 
1316:             * <p>
1317:             * Converts a DOM tree into a CoverageStoreInfo object.
1318:             * </p>
1319:             * 
1320:             * @param fmElem
1321:             *            a DOM tree to convert into a CoverageStoreInfo object.
1322:             * 
1323:             * @return A complete CoverageStoreInfo object loaded from the DOM tree
1324:             *         provided.
1325:             * 
1326:             * @throws ConfigurationException
1327:             *             When an error occurs.
1328:             */
1329:            protected CoverageStoreInfoDTO loadFormat(Element fmElem)
1330:                    throws ConfigurationException {
1331:                CoverageStoreInfoDTO fm = new CoverageStoreInfoDTO();
1332:
1333:                if (LOGGER.isLoggable(Level.FINER)) {
1334:                    LOGGER.finer("creating a new FormatDTO configuration");
1335:                }
1336:
1337:                try {
1338:                    fm.setId(ReaderUtils.getAttribute(fmElem, "id", true));
1339:
1340:                    String namespacePrefix = ReaderUtils.getAttribute(fmElem,
1341:                            "namespace", true);
1342:
1343:                    if (data.getNameSpaces().containsKey(namespacePrefix)) {
1344:                        fm.setNameSpaceId(namespacePrefix);
1345:                    } else {
1346:                        LOGGER.warning("Could not find namespace "
1347:                                + namespacePrefix + " defaulting to "
1348:                                + data.getDefaultNameSpacePrefix());
1349:                        fm.setNameSpaceId(data.getDefaultNameSpacePrefix());
1350:                    }
1351:
1352:                    fm.setType(ReaderUtils.getChildText(fmElem, "type", true));
1353:                    fm.setUrl(ReaderUtils.getChildText(fmElem, "url", false));
1354:                    fm.setEnabled(ReaderUtils.getBooleanAttribute(fmElem,
1355:                            "enabled", false, true));
1356:                    fm.setTitle(ReaderUtils
1357:                            .getChildText(fmElem, "title", false));
1358:                    fm.setAbstract(ReaderUtils.getChildText(fmElem,
1359:                            "description", false));
1360:
1361:                    if (LOGGER.isLoggable(Level.FINER)) {
1362:                        LOGGER.finer(new StringBuffer(
1363:                                "loading parameters for FormatDTO ").append(
1364:                                fm.getId()).toString());
1365:                    }
1366:                } catch (Exception e) {
1367:                    throw new ConfigurationException(e);
1368:                }
1369:
1370:                return fm;
1371:            }
1372:
1373:            /**
1374:             * loadDataStores purpose.
1375:             * 
1376:             * <p>
1377:             * Converts a DOM tree into a Map of DataStores.
1378:             * </p>
1379:             * 
1380:             * @param dsRoot
1381:             *            a DOM tree to convert into a Map of DataStores.
1382:             * 
1383:             * @return A complete Map of DataStores loaded from the DOM tree provided.
1384:             * 
1385:             * @throws ConfigurationException
1386:             *             When an error occurs.
1387:             */
1388:            protected Map loadDataStores(Element dsRoot)
1389:                    throws ConfigurationException {
1390:                Map dataStores = new HashMap();
1391:
1392:                NodeList dsElements = dsRoot.getElementsByTagName("datastore");
1393:                int dsCnt = dsElements.getLength();
1394:                DataStoreInfoDTO dsConfig = null;
1395:                Element dsElem;
1396:
1397:                for (int i = 0; i < dsCnt; i++) {
1398:                    dsElem = (Element) dsElements.item(i);
1399:
1400:                    try {
1401:                        dsConfig = loadDataStore(dsElem);
1402:
1403:                        if (dataStores.containsKey(dsConfig.getId())) {
1404:                            LOGGER
1405:                                    .warning("Ignored duplicated datastore with id "
1406:                                            + dsConfig.getId());
1407:                        } else {
1408:                            dataStores.put(dsConfig.getId(), dsConfig);
1409:                        }
1410:                    } catch (ConfigurationException e) {
1411:                        LOGGER.log(Level.WARNING,
1412:                                "Ignored a misconfigured datastore.", e);
1413:                    }
1414:                }
1415:
1416:                return dataStores;
1417:            }
1418:
1419:            /**
1420:             * loadDataStore purpose.
1421:             * 
1422:             * <p>
1423:             * Converts a DOM tree into a DataStoreInfo object.
1424:             * </p>
1425:             * 
1426:             * @param dsElem
1427:             *            a DOM tree to convert into a DataStoreInfo object.
1428:             * 
1429:             * @return A complete DataStoreInfo object loaded from the DOM tree
1430:             *         provided.
1431:             * 
1432:             * @throws ConfigurationException
1433:             *             When an error occurs.
1434:             */
1435:            protected DataStoreInfoDTO loadDataStore(Element dsElem)
1436:                    throws ConfigurationException {
1437:                DataStoreInfoDTO ds = new DataStoreInfoDTO();
1438:
1439:                try {
1440:                    if (LOGGER.isLoggable(Level.FINER)) {
1441:                        LOGGER
1442:                                .finer("creating a new DataStoreDTO configuration");
1443:                    }
1444:
1445:                    ds.setId(ReaderUtils.getAttribute(dsElem, "id", true));
1446:
1447:                    String namespacePrefix = ReaderUtils.getAttribute(dsElem,
1448:                            "namespace", true);
1449:
1450:                    if (data.getNameSpaces().containsKey(namespacePrefix)) {
1451:                        ds.setNameSpaceId(namespacePrefix);
1452:                    } else {
1453:                        LOGGER.warning("Could not find namespace "
1454:                                + namespacePrefix + " defaulting to "
1455:                                + data.getDefaultNameSpacePrefix());
1456:                        ds.setNameSpaceId(data.getDefaultNameSpacePrefix());
1457:                    }
1458:
1459:                    ds.setEnabled(ReaderUtils.getBooleanAttribute(dsElem,
1460:                            "enabled", false, true));
1461:                    ds.setTitle(ReaderUtils
1462:                            .getChildText(dsElem, "title", false));
1463:                    ds.setAbstract(ReaderUtils.getChildText(dsElem,
1464:                            "description", false));
1465:
1466:                    if (LOGGER.isLoggable(Level.FINER)) {
1467:                        LOGGER
1468:                                .finer(new StringBuffer(
1469:                                        "loading connection parameters for DataStoreDTO ")
1470:                                        .append(ds.getNameSpaceId()).toString());
1471:                    }
1472:
1473:                    ds
1474:                            .setConnectionParams(loadConnectionParams(ReaderUtils
1475:                                    .getChildElement(dsElem,
1476:                                            "connectionParams", true)));
1477:                } catch (Exception e) {
1478:                    throw new ConfigurationException(e);
1479:                }
1480:
1481:                if (LOGGER.isLoggable(Level.FINE)) {
1482:                    LOGGER.config(new StringBuffer("Loaded datastore ").append(
1483:                            ds.getId()).toString());
1484:                }
1485:
1486:                return ds;
1487:            }
1488:
1489:            /**
1490:             * loadConnectionParams purpose.
1491:             * 
1492:             * <p>
1493:             * Converts a DOM tree into a Map of Strings which represent connection
1494:             * parameters.
1495:             * </p>
1496:             * 
1497:             * @param connElem
1498:             *            a DOM tree to convert into a Map of Strings which represent
1499:             *            connection parameters.
1500:             * 
1501:             * @return A complete Map of Strings which represent connection parameters
1502:             *         loaded from the DOM tree provided.
1503:             * 
1504:             * @throws ConfigurationException
1505:             *             When an error occurs.
1506:             */
1507:            protected Map loadConnectionParams(Element connElem)
1508:                    throws ConfigurationException {
1509:                Map connectionParams = new HashMap();
1510:
1511:                if (connElem == null) {
1512:                    return connectionParams;
1513:                }
1514:
1515:                NodeList paramElems = connElem
1516:                        .getElementsByTagName("parameter");
1517:                int pCount = paramElems.getLength();
1518:                Element param;
1519:                String paramKey;
1520:                String paramValue;
1521:
1522:                try {
1523:                    for (int i = 0; i < pCount; i++) {
1524:                        param = (Element) paramElems.item(i);
1525:                        paramKey = ReaderUtils
1526:                                .getAttribute(param, "name", true);
1527:                        paramValue = ReaderUtils.getAttribute(param, "value",
1528:                                false);
1529:                        if ("shapefile url".equals(paramKey))
1530:                            paramKey = "url";
1531:                        connectionParams.put(paramKey, paramValue);
1532:
1533:                        if (LOGGER.isLoggable(Level.FINER)) {
1534:                            LOGGER.finer(new StringBuffer("added parameter ")
1535:                                    .append(paramKey).append(": '").append(
1536:                                            paramValue.replaceAll("'", "\""))
1537:                                    .append("'").toString());
1538:                        }
1539:                    }
1540:                } catch (Exception e) {
1541:                    throw new ConfigurationException(e);
1542:                }
1543:
1544:                return connectionParams;
1545:            }
1546:
1547:            /**
1548:             * Load map of FeatureTypeDTO instances from a directory.
1549:             * 
1550:             * <p>
1551:             * Expected directory structure:
1552:             * </p>
1553:             * 
1554:             * <ul>
1555:             * <li> rootDir </li>
1556:             * <li> rootDir/featureType1/info.xml - required </li>
1557:             * <li> rootDir/featureType1/schema.xml - optional </li>
1558:             * <li> rootDir/featureType2/info.xml - required </li>
1559:             * <li> rootDir/featureType2/schema.xml - optional </li>
1560:             * </ul>
1561:             * 
1562:             * <p>
1563:             * If a schema.xml file is not used, the information may be generated from a
1564:             * FeatureType using DataTransferObjectFactory.
1565:             * </p>
1566:             * 
1567:             * @param featureTypeRoot
1568:             *            Root FeatureType directory
1569:             * 
1570:             * @return Map of FeatureTypeInfoDTO by <code>dataStoreId:typeName</code>
1571:             * 
1572:             * @throws ConfigurationException
1573:             *             When an error occurs.
1574:             * @throws IllegalArgumentException
1575:             *             DOCUMENT ME!
1576:             */
1577:            protected Map loadFeatureTypes(File featureTypeRoot)
1578:                    throws ConfigurationException {
1579:                if (LOGGER.isLoggable(Level.FINEST)) {
1580:                    LOGGER.finest(new StringBuffer("examining: ").append(
1581:                            featureTypeRoot.getAbsolutePath()).toString());
1582:                    LOGGER.finest(new StringBuffer("is dir: ").append(
1583:                            featureTypeRoot.isDirectory()).toString());
1584:                }
1585:
1586:                if (featureTypeRoot == null) { // no coverages have been specified by the
1587:                    // user (that is ok)
1588:                    return Collections.EMPTY_MAP;
1589:                }
1590:
1591:                if (!featureTypeRoot.isDirectory()) {
1592:                    throw new IllegalArgumentException(
1593:                            "featureTypeRoot must be a directoy");
1594:                }
1595:
1596:                File[] directories = featureTypeRoot
1597:                        .listFiles(new FileFilter() {
1598:                            public boolean accept(File pathname) {
1599:                                return pathname.isDirectory();
1600:                            }
1601:                        });
1602:
1603:                Map map = new HashMap();
1604:
1605:                for (int i = 0, n = directories.length; i < n; i++) {
1606:                    File info = new File(directories[i], "info.xml");
1607:
1608:                    if (info.exists() && info.isFile()) {
1609:                        if (LOGGER.isLoggable(Level.FINER)) {
1610:                            LOGGER.finer(new StringBuffer("Info dir:").append(
1611:                                    info).toString());
1612:                        }
1613:                        try { // Decode the URL of the FT. This is to catch colons
1614:                            // used in filenames
1615:
1616:                            FeatureTypeInfoDTO dto = loadFeature(info);
1617:                            String ftName = null;
1618:
1619:                            ftName = URLDecoder.decode(dto.getKey(), "UTF-8");
1620:
1621:                            if (LOGGER.isLoggable(Level.FINE)) {
1622:                                LOGGER.config("Decoding file name: " + ftName);
1623:                            }
1624:
1625:                            map.put(ftName, dto);
1626:                        } catch (UnsupportedEncodingException e) {
1627:                            // throw new ConfigurationException(e);
1628:                            LOGGER
1629:                                    .severe("unable to load featuretype from file "
1630:                                            + info
1631:                                            + ".  Skipping that featuretype.  Error was: "
1632:                                            + e);
1633:                            continue;
1634:                        } catch (ConfigurationException ce) {
1635:                            LOGGER
1636:                                    .severe("unable to load featuretype from file "
1637:                                            + info
1638:                                            + ".  Skipping that featuretype.  Error was: "
1639:                                            + ce);
1640:                            continue;
1641:                        }
1642:                    }
1643:                }
1644:
1645:                return map;
1646:            }
1647:
1648:            /**
1649:             * Load FeatureTypeInfoDTO from a directory.
1650:             * 
1651:             * <p>
1652:             * Expected directory structure:
1653:             * </p>
1654:             * 
1655:             * <ul>
1656:             * <li> info.xml - required </li>
1657:             * <li> schema.xml - optional </li>
1658:             * </ul>
1659:             * 
1660:             * <p>
1661:             * If a schema.xml file is not used, the information may be generated from a
1662:             * FeatureType using DataTransferObjectFactory.
1663:             * </p>
1664:             * 
1665:             * @param infoFile
1666:             *            a File to convert into a FeatureTypeInfo object. (info.xml)
1667:             * 
1668:             * @return A complete FeatureTypeInfo object loaded from the File handle
1669:             *         provided.
1670:             * 
1671:             * @throws ConfigurationException
1672:             *             When an error occurs.
1673:             * @throws IllegalArgumentException
1674:             *             DOCUMENT ME!
1675:             * 
1676:             * @see loadFeaturePt2(Element)
1677:             */
1678:            protected FeatureTypeInfoDTO loadFeature(File infoFile)
1679:                    throws ConfigurationException {
1680:                if (!infoFile.exists()) {
1681:                    throw new IllegalArgumentException("Info File not found:"
1682:                            + infoFile);
1683:                }
1684:
1685:                if (!infoFile.isFile()) {
1686:                    throw new IllegalArgumentException(
1687:                            "Info file is the wrong type:" + infoFile);
1688:                }
1689:
1690:                if (!isInfoFile(infoFile)) {
1691:                    throw new IllegalArgumentException("Info File not valid:"
1692:                            + infoFile);
1693:                }
1694:
1695:                Element featureElem = null;
1696:
1697:                try {
1698:                    if (LOGGER.isLoggable(Level.FINE)) {
1699:                        LOGGER.config(new StringBuffer(
1700:                                "Loading configuration file: ")
1701:                                .append(infoFile).toString());
1702:                    }
1703:
1704:                    Reader reader = XmlCharsetDetector
1705:                            .getCharsetAwareReader(new FileInputStream(infoFile));
1706:                    featureElem = ReaderUtils.parse(reader);
1707:                    reader.close();
1708:                } catch (FileNotFoundException fileNotFound) {
1709:                    throw new ConfigurationException(
1710:                            "Could not read info file:" + infoFile,
1711:                            fileNotFound);
1712:                } catch (Exception erk) {
1713:                    throw new ConfigurationException(
1714:                            "Could not parse info file:" + infoFile, erk);
1715:                }
1716:
1717:                FeatureTypeInfoDTO dto = loadFeaturePt2(featureElem);
1718:
1719:                File parentDir = infoFile.getParentFile();
1720:                dto.setDirName(parentDir.getName());
1721:
1722:                List attributeList;
1723:
1724:                File schemaFile = new File(parentDir, "schema.xml");
1725:
1726:                if (schemaFile.exists() && schemaFile.isFile()) {
1727:                    // attempt to load optional schema information
1728:                    //
1729:                    if (LOGGER.isLoggable(Level.FINEST)) {
1730:                        LOGGER.finest(new StringBuffer("process schema file ")
1731:                                .append(infoFile).toString());
1732:                    }
1733:
1734:                    try {
1735:                        loadSchema(schemaFile, dto);
1736:                    } catch (Exception badDog) {
1737:                        badDog.printStackTrace();
1738:                        attributeList = Collections.EMPTY_LIST;
1739:                    }
1740:                } else {
1741:                    dto.setSchemaAttributes(Collections.EMPTY_LIST);
1742:                }
1743:
1744:                if (LOGGER.isLoggable(Level.FINE)) {
1745:                    LOGGER.config(new StringBuffer("added featureType ")
1746:                            .append(dto.getName()).toString());
1747:                }
1748:
1749:                return dto;
1750:            }
1751:
1752:            /**
1753:             * loadFeaturePt2 purpose.
1754:             * 
1755:             * <p>
1756:             * Converts a DOM tree into a FeatureTypeInfo object.
1757:             * </p>
1758:             * 
1759:             * @param fTypeRoot
1760:             *            a DOM tree to convert into a FeatureTypeInfo object.
1761:             * 
1762:             * @return A complete FeatureTypeInfo object loaded from the DOM tree
1763:             *         provided.
1764:             * 
1765:             * @throws ConfigurationException
1766:             *             When an error occurs.
1767:             */
1768:            protected FeatureTypeInfoDTO loadFeaturePt2(Element fTypeRoot)
1769:                    throws ConfigurationException {
1770:                FeatureTypeInfoDTO ft = new FeatureTypeInfoDTO();
1771:
1772:                try {
1773:                    ft.setName(ReaderUtils
1774:                            .getChildText(fTypeRoot, "name", true));
1775:                    ft.setAlias(ReaderUtils.getChildText(fTypeRoot, "alias",
1776:                            false));
1777:                    ft.setTitle(ReaderUtils.getChildText(fTypeRoot, "title",
1778:                            true));
1779:                    ft.setAbstract(ReaderUtils.getChildText(fTypeRoot,
1780:                            "abstract"));
1781:                    ft.setWmsPath(ReaderUtils.getChildText(fTypeRoot, "wmspath" /*
1782:                     * ,
1783:                     * true
1784:                     */));
1785:
1786:                    String keywords = ReaderUtils.getChildText(fTypeRoot,
1787:                            "keywords");
1788:
1789:                    if (keywords != null) {
1790:                        List l = new LinkedList();
1791:                        String[] ss = keywords.split(",");
1792:
1793:                        for (int i = 0; i < ss.length; i++)
1794:                            l.add(ss[i].trim());
1795:
1796:                        ft.setKeywords(l);
1797:                    }
1798:
1799:                    Element urls = ReaderUtils.getChildElement(fTypeRoot,
1800:                            "metadataLinks");
1801:
1802:                    if (urls != null) {
1803:                        Element[] childs = ReaderUtils.getChildElements(urls,
1804:                                "metadataLink");
1805:                        List l = new LinkedList();
1806:
1807:                        for (int i = 0; i < childs.length; i++) {
1808:                            l.add(getMetaDataLink(childs[i]));
1809:                        }
1810:
1811:                        ft.setMetadataLinks(l);
1812:                    }
1813:
1814:                    ft.setDataStoreId(ReaderUtils.getAttribute(fTypeRoot,
1815:                            "datastore", true));
1816:                    ft.setSRS(Integer.parseInt(ReaderUtils.getChildText(
1817:                            fTypeRoot, "SRS", true)));
1818:                    try {
1819:                        String srsHandling = ReaderUtils.getChildText(
1820:                                fTypeRoot, "SRSHandling", false);
1821:                        ft.setSRSHandling(srsHandling != null ? Integer
1822:                                .parseInt(srsHandling) : FeatureTypeInfo.FORCE);
1823:                    } catch (Exception e) {
1824:                        ft.setSRSHandling(FeatureTypeInfo.FORCE);
1825:                    }
1826:
1827:                    Element tmp = ReaderUtils.getChildElement(fTypeRoot,
1828:                            "styles");
1829:
1830:                    if (tmp != null) {
1831:                        ft.setDefaultStyle(ReaderUtils.getAttribute(tmp,
1832:                                "default", false));
1833:
1834:                        final NodeList childrens = tmp.getChildNodes();
1835:                        final int numChildNodes = childrens.getLength();
1836:                        Node child;
1837:
1838:                        for (int n = 0; n < numChildNodes; n++) {
1839:                            child = childrens.item(n);
1840:
1841:                            if (child.getNodeType() == Node.ELEMENT_NODE) {
1842:                                if (child.getNodeName().equals("style")) {
1843:                                    ft.addStyle(ReaderUtils
1844:                                            .getElementText((Element) child));
1845:                                }
1846:                            }
1847:                        }
1848:                    }
1849:
1850:                    Element cacheInfo = ReaderUtils.getChildElement(fTypeRoot,
1851:                            "cacheinfo");
1852:
1853:                    if (cacheInfo != null) {
1854:                        ft.setCacheMaxAge(ReaderUtils.getAttribute(cacheInfo,
1855:                                "maxage", false)); // not
1856:                        // mandatory
1857:                        ft.setCachingEnabled((new Boolean(ReaderUtils
1858:                                .getAttribute(cacheInfo, "enabled", true)))
1859:                                .booleanValue());
1860:                    }
1861:
1862:                    // Modif C. Kolbowicz - 06/10/2004
1863:                    Element legendURL = ReaderUtils.getChildElement(fTypeRoot,
1864:                            "LegendURL");
1865:
1866:                    if (legendURL != null) {
1867:                        LegendURLDTO legend = new LegendURLDTO();
1868:                        legend.setWidth(Integer.parseInt(ReaderUtils
1869:                                .getAttribute(legendURL, "width", true)));
1870:                        legend.setHeight(Integer.parseInt(ReaderUtils
1871:                                .getAttribute(legendURL, "height", true)));
1872:                        legend.setFormat(ReaderUtils.getChildText(legendURL,
1873:                                "Format", true));
1874:                        legend.setOnlineResource(ReaderUtils.getAttribute(
1875:                                ReaderUtils.getChildElement(legendURL,
1876:                                        "OnlineResource", true), "xlink:href",
1877:                                true));
1878:                        ft.setLegendURL(legend);
1879:                    }
1880:
1881:                    Envelope latLonBBox = loadBBox(ReaderUtils.getChildElement(
1882:                            fTypeRoot, "latLonBoundingBox"));
1883:                    // -- Modif C. Kolbowicz - 06/10/2004
1884:                    ft.setLatLongBBox(latLonBBox);
1885:
1886:                    Envelope nativeBBox = loadBBox(ReaderUtils.getChildElement(
1887:                            fTypeRoot, "nativeBBox"));
1888:                    ft.setNativeBBox(nativeBBox);
1889:
1890:                    Element numDecimalsElem = ReaderUtils.getChildElement(
1891:                            fTypeRoot, "numDecimals", false);
1892:
1893:                    if (numDecimalsElem != null) {
1894:                        ft.setNumDecimals(ReaderUtils.getIntAttribute(
1895:                                numDecimalsElem, "value", false, 8));
1896:                    }
1897:
1898:                    ft.setDefinitionQuery(loadDefinitionQuery(fTypeRoot));
1899:
1900:                    final String maxFeaturesText = ReaderUtils.getChildText(
1901:                            fTypeRoot, "maxFeatures", false);
1902:                    try {
1903:                        ft.setMaxFeatures(Integer.parseInt(maxFeaturesText));
1904:                    } catch (Exception e) {
1905:                        // this may fail for a number of reasons, attribute not there, or not a number
1906:                        ft.setMaxFeatures(0);
1907:                    }
1908:
1909:                } catch (Exception e) {
1910:                    throw new ConfigurationException(e);
1911:                }
1912:
1913:                return ft;
1914:            }
1915:
1916:            /**
1917:             * This method loads all the coverages present under the geoserver data
1918:             * directory in a Map by using their respective DTOs.
1919:             * 
1920:             * @see XMLConfigReader#loadCoverage(File)
1921:             * @param coverageRoot
1922:             * @return
1923:             * @throws ConfigurationException
1924:             */
1925:            protected Map loadCoverages(File coverageRoot)
1926:                    throws ConfigurationException {
1927:                if (LOGGER.isLoggable(Level.FINEST) && (coverageRoot != null)) {
1928:                    LOGGER.finest(new StringBuffer("examining: ").append(
1929:                            coverageRoot.getAbsolutePath()).toString());
1930:                    LOGGER.finest(new StringBuffer("is dir: ").append(
1931:                            coverageRoot.isDirectory()).toString());
1932:                }
1933:
1934:                if (coverageRoot == null) { // no coverages have been specified by the
1935:                    // user (that is ok)
1936:
1937:                    return Collections.EMPTY_MAP;
1938:                }
1939:
1940:                if (!coverageRoot.isDirectory()) {
1941:                    throw new IllegalArgumentException(
1942:                            "coverageRoot must be a directoy");
1943:                }
1944:
1945:                File[] directories = coverageRoot.listFiles(new FileFilter() {
1946:                    public boolean accept(File pathname) {
1947:                        return pathname.isDirectory();
1948:                    }
1949:                });
1950:
1951:                Map map = new HashMap();
1952:                File info;
1953:                CoverageInfoDTO dto;
1954:                final int numDirectories = directories.length;
1955:
1956:                for (int i = 0, n = numDirectories; i < n; i++) {
1957:                    info = new File(directories[i], "info.xml");
1958:
1959:                    if (info.exists() && info.isFile()) {
1960:                        if (LOGGER.isLoggable(Level.FINER)) {
1961:                            LOGGER.finer(new StringBuffer("Info dir:").append(
1962:                                    info).toString());
1963:                        }
1964:
1965:                        try {
1966:                            dto = loadCoverage(info);
1967:                            map.put(dto.getKey(), dto);
1968:                        } catch (ConfigurationException e) {
1969:                            LOGGER.log(Level.WARNING,
1970:                                    "Skipped misconfigured coverage "
1971:                                            + info.getPath(), e);
1972:                        }
1973:                    }
1974:                }
1975:
1976:                return map;
1977:            }
1978:
1979:            /**
1980:             * This method loads the coverage information DTO from an info.xml file on
1981:             * the disk.
1982:             * 
1983:             * @param infoFile
1984:             * @return
1985:             * @throws ConfigurationException
1986:             */
1987:            protected CoverageInfoDTO loadCoverage(File infoFile)
1988:                    throws ConfigurationException {
1989:                if (!infoFile.exists()) {
1990:                    throw new IllegalArgumentException("Info File not found:"
1991:                            + infoFile);
1992:                }
1993:
1994:                if (!infoFile.isFile()) {
1995:                    throw new IllegalArgumentException(
1996:                            "Info file is the wrong type:" + infoFile);
1997:                }
1998:
1999:                if (!isInfoFile(infoFile)) {
2000:                    throw new IllegalArgumentException("Info File not valid:"
2001:                            + infoFile);
2002:                }
2003:
2004:                Element coverageElem = null;
2005:
2006:                try {
2007:                    Reader reader = XmlCharsetDetector
2008:                            .getCharsetAwareReader(new FileInputStream(infoFile));
2009:                    coverageElem = ReaderUtils.parse(reader);
2010:                    reader.close();
2011:                } catch (FileNotFoundException fileNotFound) {
2012:                    throw new ConfigurationException(
2013:                            "Could not read info file:" + infoFile,
2014:                            fileNotFound);
2015:                } catch (Exception erk) {
2016:                    throw new ConfigurationException(
2017:                            "Could not parse info file:" + infoFile, erk);
2018:                }
2019:
2020:                // loding the DTO.
2021:                CoverageInfoDTO dto = loadCoverageDTOFromXML(coverageElem);
2022:
2023:                File parentDir = infoFile.getParentFile();
2024:                dto.setDirName(parentDir.getName());
2025:
2026:                if (LOGGER.isLoggable(Level.FINER)) {
2027:                    LOGGER.finer(new StringBuffer("added coverageType ")
2028:                            .append(dto.getName()).toString());
2029:                }
2030:
2031:                return dto;
2032:            }
2033:
2034:            /**
2035:             * Creation of a DTo cfron an info.xml file for a coverage.
2036:             * 
2037:             * @param coverageRoot
2038:             * @return
2039:             * @throws ConfigurationException
2040:             */
2041:            protected CoverageInfoDTO loadCoverageDTOFromXML(
2042:                    Element coverageRoot) throws ConfigurationException {
2043:                final CoverageInfoDTO cv = new CoverageInfoDTO();
2044:
2045:                try {
2046:                    int length = 0;
2047:                    List l = null;
2048:                    int i = 0;
2049:                    String[] ss = null;
2050:                    // /////////////////////////////////////////////////////////////////////
2051:                    //
2052:                    // COVERAGEINFO DTO INITIALIZATION
2053:                    //
2054:                    // /////////////////////////////////////////////////////////////////////
2055:                    cv.setFormatId(ReaderUtils.getAttribute(coverageRoot,
2056:                            "format", true));
2057:                    cv.setName(ReaderUtils.getChildText(coverageRoot, "name",
2058:                            true));
2059:                    cv.setWmsPath(ReaderUtils.getChildText(coverageRoot,
2060:                            "wmspath" /*
2061:                             * ,
2062:                             * true
2063:                             */));
2064:                    cv.setLabel(ReaderUtils.getChildText(coverageRoot, "label",
2065:                            true));
2066:                    cv.setDescription(ReaderUtils.getChildText(coverageRoot,
2067:                            "description"));
2068:
2069:                    // /////////////////////////////////////////////////////////////////////
2070:                    //
2071:                    // METADATA AND KEYORDS
2072:                    //
2073:                    // /////////////////////////////////////////////////////////////////////
2074:                    final String keywords = ReaderUtils.getChildText(
2075:                            coverageRoot, "keywords");
2076:
2077:                    if (keywords != null) {
2078:                        l = new ArrayList(10);
2079:                        ss = keywords.split(",");
2080:                        length = ss.length;
2081:
2082:                        for (i = 0; i < length; i++)
2083:                            l.add(ss[i].trim());
2084:
2085:                        cv.setKeywords(l);
2086:                    }
2087:
2088:                    cv.setMetadataLink(loadMetaDataLink(ReaderUtils
2089:                            .getChildElement(coverageRoot, "metadataLink")));
2090:
2091:                    // /////////////////////////////////////////////////////////////////////
2092:                    //
2093:                    // DEAFULT STYLE
2094:                    //
2095:                    // /////////////////////////////////////////////////////////////////////
2096:                    final Element tmp = ReaderUtils.getChildElement(
2097:                            coverageRoot, "styles");
2098:
2099:                    if (tmp != null) {
2100:                        cv.setDefaultStyle(ReaderUtils.getAttribute(tmp,
2101:                                "default", false));
2102:
2103:                        final NodeList childrens = tmp.getChildNodes();
2104:                        final int numChildNodes = childrens.getLength();
2105:                        Node child;
2106:
2107:                        for (int n = 0; n < numChildNodes; n++) {
2108:                            child = childrens.item(n);
2109:
2110:                            if (child.getNodeType() == Node.ELEMENT_NODE) {
2111:                                if (child.getNodeName().equals("style")) {
2112:                                    cv.addStyle(ReaderUtils
2113:                                            .getElementText((Element) child));
2114:                                }
2115:                            }
2116:                        }
2117:                    }
2118:
2119:                    // /////////////////////////////////////////////////////////////////////
2120:                    //
2121:                    // CRS
2122:                    //
2123:                    // /////////////////////////////////////////////////////////////////////
2124:                    final Element envelope = ReaderUtils.getChildElement(
2125:                            coverageRoot, "envelope");
2126:                    cv.setSrsName(ReaderUtils.getAttribute(envelope, "srsName",
2127:                            true));
2128:
2129:                    final CoordinateReferenceSystem crs;
2130:
2131:                    try {
2132:                        crs = CRS.parseWKT(ReaderUtils.getAttribute(envelope,
2133:                                "crs", false).replaceAll("'", "\""));
2134:                    } catch (FactoryException e) {
2135:                        throw new ConfigurationException(e);
2136:                    } catch (ConfigurationException e) {
2137:                        throw new ConfigurationException(e);
2138:                    }
2139:
2140:                    cv.setCrs(crs);
2141:                    cv.setSrsWKT(crs.toWKT());
2142:
2143:                    // /////////////////////////////////////////////////////////////////////
2144:                    //
2145:                    // ENVELOPE
2146:                    //
2147:                    // /////////////////////////////////////////////////////////////////////
2148:                    GeneralEnvelope gcEnvelope = loadEnvelope(envelope, crs);
2149:                    cv.setEnvelope(gcEnvelope);
2150:
2151:                    try {
2152:                        cv.setLonLatWGS84Envelope(CoverageStoreUtils
2153:                                .getWGS84LonLatEnvelope(gcEnvelope));
2154:                    } catch (MismatchedDimensionException e) {
2155:                        throw new ConfigurationException(e);
2156:                    } catch (IndexOutOfBoundsException e) {
2157:                        throw new ConfigurationException(e);
2158:                    } catch (NoSuchAuthorityCodeException e) {
2159:                        throw new ConfigurationException(e);
2160:                    } catch (FactoryException e) {
2161:                        throw new ConfigurationException(e);
2162:                    } catch (TransformException e) {
2163:                        throw new ConfigurationException(e);
2164:                    }
2165:
2166:                    // /////////////////////////////////////////////////////////////////////
2167:                    //
2168:                    // GRID GEOMETRY
2169:                    //
2170:                    // /////////////////////////////////////////////////////////////////////
2171:                    final Element grid = ReaderUtils.getChildElement(
2172:                            coverageRoot, "grid");
2173:                    cv.setGrid(loadGrid(grid, gcEnvelope, crs));
2174:
2175:                    // /////////////////////////////////////////////////////////////////////
2176:                    //
2177:                    // SAMPLE DIMENSIONS
2178:                    //
2179:                    // /////////////////////////////////////////////////////////////////////
2180:                    cv.setDimensionNames(loadDimensionNames(grid));
2181:
2182:                    final NodeList dims = coverageRoot
2183:                            .getElementsByTagName("CoverageDimension");
2184:                    cv.setDimensions(loadDimensions(dims));
2185:
2186:                    // /////////////////////////////////////////////////////////////////////
2187:                    //
2188:                    // SUPPORTED/REQUEST CRS
2189:                    //
2190:                    // /////////////////////////////////////////////////////////////////////
2191:                    final Element supportedCRSs = ReaderUtils.getChildElement(
2192:                            coverageRoot, "supportedCRSs");
2193:                    final String requestCRSs = ReaderUtils.getChildText(
2194:                            supportedCRSs, "requestCRSs");
2195:
2196:                    if (requestCRSs != null) {
2197:                        l = new LinkedList();
2198:                        ss = requestCRSs.split(",");
2199:
2200:                        length = ss.length;
2201:
2202:                        for (i = 0; i < length; i++)
2203:                            l.add(ss[i].trim());
2204:
2205:                        cv.setRequestCRSs(l);
2206:                    }
2207:
2208:                    final String responseCRSs = ReaderUtils.getChildText(
2209:                            supportedCRSs, "responseCRSs");
2210:
2211:                    if (responseCRSs != null) {
2212:                        l = new LinkedList();
2213:                        ss = responseCRSs.split(",");
2214:                        length = ss.length;
2215:
2216:                        for (i = 0; i < length; i++)
2217:                            l.add(ss[i].trim());
2218:
2219:                        cv.setResponseCRSs(l);
2220:                    }
2221:
2222:                    // /////////////////////////////////////////////////////////////////////
2223:                    //
2224:                    // SUPPORTED FORMATS
2225:                    //
2226:                    // /////////////////////////////////////////////////////////////////////
2227:                    final Element supportedFormats = ReaderUtils
2228:                            .getChildElement(coverageRoot, "supportedFormats");
2229:                    cv.setNativeFormat(ReaderUtils.getAttribute(
2230:                            supportedFormats, "nativeFormat", true));
2231:
2232:                    final String formats = ReaderUtils.getChildText(
2233:                            supportedFormats, "formats");
2234:
2235:                    if (formats != null) {
2236:                        l = new LinkedList();
2237:                        ss = formats.split(",");
2238:                        length = ss.length;
2239:
2240:                        for (i = 0; i < length; i++)
2241:                            l.add(ss[i].trim());
2242:
2243:                        cv.setSupportedFormats(l);
2244:                    }
2245:
2246:                    // /////////////////////////////////////////////////////////////////////
2247:                    //
2248:                    // SUPPORTED INTERPOLATIONS
2249:                    //
2250:                    // /////////////////////////////////////////////////////////////////////
2251:                    final Element supportedInterpolations = ReaderUtils
2252:                            .getChildElement(coverageRoot,
2253:                                    "supportedInterpolations");
2254:                    cv.setDefaultInterpolationMethod(ReaderUtils.getAttribute(
2255:                            supportedInterpolations, "default", true));
2256:
2257:                    final String interpolations = ReaderUtils.getChildText(
2258:                            supportedInterpolations, "interpolationMethods");
2259:
2260:                    if (interpolations != null) {
2261:                        l = new LinkedList();
2262:                        ss = interpolations.split(",");
2263:                        length = ss.length;
2264:
2265:                        for (i = 0; i < length; i++)
2266:                            l.add(ss[i].trim());
2267:
2268:                        cv.setInterpolationMethods(l);
2269:                    }
2270:
2271:                    // /////////////////////////////////////////////////////////////////////
2272:                    //
2273:                    // READ PARAMETERS
2274:                    //
2275:                    // /////////////////////////////////////////////////////////////////////
2276:                    cv
2277:                            .setParameters(loadConnectionParams(ReaderUtils
2278:                                    .getChildElement(coverageRoot,
2279:                                            "parameters", false)));
2280:                } catch (Exception e) {
2281:                    throw new ConfigurationException(e);
2282:                }
2283:
2284:                return cv;
2285:            }
2286:
2287:            /**
2288:             * Loading the envelope for this coverage from the info.xml file.
2289:             * 
2290:             * @todo Remve usage of JTS and use GeneralEnvelope instead.
2291:             * @param envelopeElem
2292:             * @return
2293:             * @throws ConfigurationException
2294:             */
2295:            protected GeneralEnvelope loadEnvelope(Element envelopeElem,
2296:                    CoordinateReferenceSystem crs)
2297:                    throws ConfigurationException {
2298:                if (envelopeElem == null) {
2299:                    return new GeneralEnvelope(crs);
2300:                }
2301:
2302:                final NodeList positions = envelopeElem
2303:                        .getElementsByTagName("pos");
2304:                final int numCoordinates = positions.getLength();
2305:                final Coordinate[] coords = new Coordinate[numCoordinates];
2306:                String values;
2307:                double[] dd;
2308:
2309:                for (int i = 0; i < numCoordinates; i++) {
2310:                    values = ReaderUtils.getElementText((Element) positions
2311:                            .item(i));
2312:
2313:                    if (values != null) {
2314:                        String[] ss = values.split(" ");
2315:                        final int length = ss.length;
2316:                        dd = new double[length];
2317:
2318:                        for (int j = 0; j < length; j++)
2319:                            dd[j] = Double.parseDouble(ss[j].trim());
2320:
2321:                        coords[i] = new Coordinate(dd[0], dd[1]);
2322:                    }
2323:                }
2324:
2325:                GeneralEnvelope envelope = new GeneralEnvelope(new double[] {
2326:                        coords[0].x, coords[0].y }, new double[] { coords[1].x,
2327:                        coords[1].y });
2328:                envelope.setCoordinateReferenceSystem(crs);
2329:
2330:                return envelope;
2331:            }
2332:
2333:            /**
2334:             * This method is in charge for loading the grid geometry for this
2335:             * coverage's info.xml file.
2336:             * 
2337:             * @param gridElem
2338:             * @param envelope
2339:             * @param crs
2340:             * @return
2341:             * @throws ConfigurationException
2342:             */
2343:            protected GridGeometry loadGrid(Element gridElem,
2344:                    GeneralEnvelope envelope, CoordinateReferenceSystem crs)
2345:                    throws ConfigurationException, FactoryException {
2346:                final GeneralEnvelope gcEnvelope = new GeneralEnvelope(
2347:                        new GeneralDirectPosition(envelope.getLowerCorner()
2348:                                .getOrdinate(0), envelope.getLowerCorner()
2349:                                .getOrdinate(1)), new GeneralDirectPosition(
2350:                                envelope.getUpperCorner().getOrdinate(0),
2351:                                envelope.getUpperCorner().getOrdinate(1)));
2352:
2353:                gcEnvelope.setCoordinateReferenceSystem(crs);
2354:
2355:                if (gridElem == null) {
2356:                    // new grid range
2357:                    GeneralGridRange newGridrange = new GeneralGridRange(
2358:                            new int[] { 0, 0 }, new int[] { 1, 1 });
2359:                    GridGeometry2D newGridGeometry = new GridGeometry2D(
2360:                            newGridrange, gcEnvelope);
2361:
2362:                    return newGridGeometry;
2363:                }
2364:
2365:                NodeList low = gridElem.getElementsByTagName("low");
2366:                NodeList high = gridElem.getElementsByTagName("high");
2367:                int[] lowers = null;
2368:                int[] upers = null;
2369:
2370:                for (int i = 0; i < low.getLength(); i++) {
2371:                    String values = ReaderUtils.getElementText((Element) low
2372:                            .item(i));
2373:
2374:                    if (values != null) {
2375:                        String[] ss = values.split(" ");
2376:                        lowers = new int[ss.length];
2377:
2378:                        for (int j = 0; j < ss.length; j++)
2379:                            lowers[j] = Integer.parseInt(ss[j].trim());
2380:                    }
2381:                }
2382:
2383:                for (int i = 0; i < high.getLength(); i++) {
2384:                    String values = ReaderUtils.getElementText((Element) high
2385:                            .item(i));
2386:
2387:                    if (values != null) {
2388:                        String[] ss = values.split(" ");
2389:                        upers = new int[ss.length];
2390:
2391:                        for (int j = 0; j < ss.length; j++)
2392:                            upers[j] = Integer.parseInt(ss[j].trim());
2393:                    }
2394:                }
2395:
2396:                // new grid range
2397:                GeneralGridRange newGridrange = new GeneralGridRange(lowers,
2398:                        upers);
2399:
2400:                Element geoTransform = ReaderUtils.getChildElement(gridElem,
2401:                        "geoTransform");
2402:                if (geoTransform != null) {
2403:                    double[] flatMatrix = new double[3 * 3];
2404:
2405:                    Element scaleX = ReaderUtils.getChildElement(geoTransform,
2406:                            "scaleX");
2407:                    Element scaleY = ReaderUtils.getChildElement(geoTransform,
2408:                            "scaleY");
2409:                    Element shearX = ReaderUtils.getChildElement(geoTransform,
2410:                            "shearX");
2411:                    Element shearY = ReaderUtils.getChildElement(geoTransform,
2412:                            "shearY");
2413:                    Element translateX = ReaderUtils.getChildElement(
2414:                            geoTransform, "translateX");
2415:                    Element translateY = ReaderUtils.getChildElement(
2416:                            geoTransform, "translateY");
2417:
2418:                    if (scaleX != null) {
2419:                        flatMatrix[0] = Double.parseDouble(ReaderUtils
2420:                                .getElementText(scaleX));
2421:                    }
2422:                    if (shearX != null) {
2423:                        flatMatrix[1] = Double.parseDouble(ReaderUtils
2424:                                .getElementText(shearX));
2425:                    }
2426:                    if (translateX != null) {
2427:                        flatMatrix[2] = Double.parseDouble(ReaderUtils
2428:                                .getElementText(translateX));
2429:                    }
2430:
2431:                    if (shearY != null) {
2432:                        flatMatrix[3] = Double.parseDouble(ReaderUtils
2433:                                .getElementText(shearY));
2434:                    }
2435:                    if (scaleY != null) {
2436:                        flatMatrix[4] = Double.parseDouble(ReaderUtils
2437:                                .getElementText(scaleY));
2438:                    }
2439:                    if (translateY != null) {
2440:                        flatMatrix[5] = Double.parseDouble(ReaderUtils
2441:                                .getElementText(translateY));
2442:                    }
2443:
2444:                    flatMatrix[8] = 1.0;
2445:
2446:                    /**
2447:                     *  scaleX		shearX		translateX
2448:                     *  shearY		scaleY		translateY
2449:                     *  0.0		0.		1.0
2450:                     */
2451:                    Matrix matrix = new GeneralMatrix(3, 3, flatMatrix);
2452:                    final MathTransformFactory factory = new DefaultMathTransformFactory();
2453:                    MathTransform gridToCRS = factory
2454:                            .createAffineTransform(matrix);
2455:
2456:                    return new GridGeometry2D(newGridrange, gridToCRS,
2457:                            gcEnvelope.getCoordinateReferenceSystem());
2458:                } else {
2459:                    return new GridGeometry2D(newGridrange, gcEnvelope);
2460:                }
2461:
2462:            }
2463:
2464:            /**
2465:             * 
2466:             * @param gridElem
2467:             * @return
2468:             * @throws ConfigurationException
2469:             */
2470:            protected InternationalString[] loadDimensionNames(Element gridElem)
2471:                    throws ConfigurationException {
2472:                if (gridElem == null) {
2473:                    return null;
2474:                }
2475:
2476:                NodeList axisNames = gridElem.getElementsByTagName("axisName");
2477:                InternationalString[] dimNames = new InternationalString[axisNames
2478:                        .getLength()];
2479:
2480:                for (int i = 0; i < axisNames.getLength(); i++) {
2481:                    String values = ReaderUtils
2482:                            .getElementText((Element) axisNames.item(i));
2483:
2484:                    if (values != null) {
2485:                        dimNames[i] = NameFactory.create(values)
2486:                                .toInternationalString();
2487:                    }
2488:                }
2489:
2490:                return dimNames;
2491:            }
2492:
2493:            protected CoverageDimension[] loadDimensions(NodeList dimElems)
2494:                    throws ConfigurationException {
2495:                CoverageDimension[] dimensions = null;
2496:
2497:                if ((dimElems != null) && (dimElems.getLength() > 0)) {
2498:                    dimensions = new CoverageDimension[dimElems.getLength()];
2499:
2500:                    for (int dim = 0; dim < dimElems.getLength(); dim++) {
2501:                        dimensions[dim] = new CoverageDimension();
2502:                        dimensions[dim].setName(ReaderUtils
2503:                                .getElementText((Element) ((Element) dimElems
2504:                                        .item(dim))
2505:                                        .getElementsByTagName("name").item(0)));
2506:                        dimensions[dim].setDescription(ReaderUtils
2507:                                .getElementText((Element) ((Element) dimElems
2508:                                        .item(dim)).getElementsByTagName(
2509:                                        "description").item(0)));
2510:
2511:                        NodeList interval = ((Element) dimElems.item(dim))
2512:                                .getElementsByTagName("interval");
2513:                        double min = Double.parseDouble(ReaderUtils
2514:                                .getElementText((Element) ((Element) interval
2515:                                        .item(0)).getElementsByTagName("min")
2516:                                        .item(0)));
2517:                        double max = Double.parseDouble(ReaderUtils
2518:                                .getElementText((Element) ((Element) interval
2519:                                        .item(0)).getElementsByTagName("max")
2520:                                        .item(0)));
2521:                        dimensions[dim].setRange(new NumberRange(min, max));
2522:
2523:                        NodeList nullValues = ((Element) dimElems.item(dim))
2524:                                .getElementsByTagName("nullValues");
2525:
2526:                        if ((nullValues != null)
2527:                                && (nullValues.getLength() > 0)) {
2528:                            NodeList values = ((Element) nullValues.item(0))
2529:                                    .getElementsByTagName("value");
2530:
2531:                            if (values != null) {
2532:                                Vector nulls = new Vector();
2533:
2534:                                for (int nl = 0; nl < values.getLength(); nl++) {
2535:                                    nulls.add(new Double(ReaderUtils
2536:                                            .getElementText((Element) values
2537:                                                    .item(nl))));
2538:                                }
2539:
2540:                                dimensions[dim].setNullValues((Double[]) nulls
2541:                                        .toArray(new Double[nulls.size()]));
2542:                            }
2543:                        }
2544:                    }
2545:                }
2546:
2547:                return dimensions;
2548:            }
2549:
2550:            protected MetaDataLink loadMetaDataLink(Element metalinkRoot) {
2551:                MetaDataLink ml = new MetaDataLink();
2552:
2553:                try {
2554:                    ml.setAbout(ReaderUtils.getAttribute(metalinkRoot, "about",
2555:                            false));
2556:                    ml.setType(ReaderUtils.getAttribute(metalinkRoot, "type",
2557:                            false));
2558:                    ml.setMetadataType(ReaderUtils.getAttribute(metalinkRoot,
2559:                            "metadataType", false));
2560:                    ml.setContent(ReaderUtils.getElementText(metalinkRoot));
2561:                } catch (Exception e) {
2562:                    ml = null;
2563:                }
2564:
2565:                return ml;
2566:            }
2567:
2568:            /**
2569:             * getKeyWords purpose.
2570:             * 
2571:             * <p>
2572:             * Converts a DOM tree into a List of Strings representing keywords.
2573:             * </p>
2574:             * 
2575:             * @param keywordsElem
2576:             *            a DOM tree to convert into a List of Strings representing
2577:             *            keywords.
2578:             * 
2579:             * @return A complete List of Strings representing keywords loaded from the
2580:             *         DOM tree provided.
2581:             */
2582:            protected List getKeyWords(Element keywordsElem) {
2583:                NodeList klist = keywordsElem.getElementsByTagName("keyword");
2584:                int kCount = klist.getLength();
2585:                List keywords = new LinkedList();
2586:                String kword;
2587:                Element kelem;
2588:
2589:                for (int i = 0; i < kCount; i++) {
2590:                    kelem = (Element) klist.item(i);
2591:                    kword = ReaderUtils.getElementText(kelem);
2592:
2593:                    if (kword != null) {
2594:                        keywords.add(kword);
2595:                    }
2596:                }
2597:
2598:                return keywords;
2599:            }
2600:
2601:            /**
2602:             * loadLatLongBBox purpose.
2603:             * 
2604:             * <p>
2605:             * Converts a DOM tree into a Envelope object.
2606:             * </p>
2607:             * 
2608:             * @param bboxElem
2609:             *            a DOM tree to convert into a Envelope object.
2610:             * 
2611:             * @return A complete Envelope object loaded from the DOM tree provided.
2612:             * 
2613:             * @throws ConfigurationException
2614:             *             When an error occurs.
2615:             */
2616:            protected Envelope loadBBox(Element bboxElem)
2617:                    throws ConfigurationException {
2618:                if (bboxElem == null) {
2619:                    return new Envelope();
2620:                }
2621:
2622:                try {
2623:                    boolean dynamic = ReaderUtils.getBooleanAttribute(bboxElem,
2624:                            "dynamic", false, true);
2625:
2626:                    if (!dynamic) {
2627:                        double minx = ReaderUtils.getDoubleAttribute(bboxElem,
2628:                                "minx", true);
2629:                        double miny = ReaderUtils.getDoubleAttribute(bboxElem,
2630:                                "miny", true);
2631:                        double maxx = ReaderUtils.getDoubleAttribute(bboxElem,
2632:                                "maxx", true);
2633:                        double maxy = ReaderUtils.getDoubleAttribute(bboxElem,
2634:                                "maxy", true);
2635:
2636:                        return new Envelope(minx, maxx, miny, maxy);
2637:                    }
2638:                } catch (Exception e) {
2639:                    throw new ConfigurationException(e);
2640:                }
2641:
2642:                return new Envelope();
2643:            }
2644:
2645:            /**
2646:             * loadDefinitionQuery purpose.
2647:             * 
2648:             * <p>
2649:             * Converts a DOM tree into a Filter object.
2650:             * </p>
2651:             * 
2652:             * @param typeRoot
2653:             *            a DOM tree to convert into a Filter object.
2654:             * 
2655:             * @return A complete Filter object loaded from the DOM tree provided.
2656:             * 
2657:             * @throws ConfigurationException
2658:             *             When an error occurs.
2659:             */
2660:            protected Filter loadDefinitionQuery(Element typeRoot)
2661:                    throws ConfigurationException {
2662:                try {
2663:                    Element defQNode = ReaderUtils.getChildElement(typeRoot,
2664:                            "definitionQuery", false);
2665:                    Filter filter = null;
2666:
2667:                    if (defQNode != null) {
2668:                        LOGGER
2669:                                .finer("definitionQuery element found, looking for Filter");
2670:
2671:                        Element filterNode = ReaderUtils.getChildElement(
2672:                                defQNode, "Filter", false);
2673:
2674:                        if ((filterNode != null)
2675:                                && ((filterNode = ReaderUtils
2676:                                        .getFirstChildElement(filterNode)) != null)) {
2677:                            filter = FilterDOMParser.parseFilter(filterNode);
2678:
2679:                            return filter;
2680:                        }
2681:
2682:                        LOGGER.finer("No Filter definition query found");
2683:                    }
2684:
2685:                    return filter;
2686:                } catch (Exception e) {
2687:                    throw new ConfigurationException(e);
2688:                }
2689:            }
2690:
2691:            /**
2692:             * isInfoFile purpose.
2693:             * 
2694:             * <p>
2695:             * Used to perform safety checks on info.xml file handles.
2696:             * </p>
2697:             * 
2698:             * @param testFile
2699:             *            The file to test.
2700:             * 
2701:             * @return true if the file is an info.xml file.
2702:             */
2703:            protected static boolean isInfoFile(File testFile) {
2704:                String testName = testFile.getAbsolutePath();
2705:
2706:                int start = testName.length() - "info.xml".length();
2707:                int end = testName.length();
2708:
2709:                return testName.substring(start, end).equals("info.xml");
2710:            }
2711:
2712:            /**
2713:             * Process schema File for a list of AttributeTypeInfoDTO.
2714:             * 
2715:             * <p>
2716:             * The provided FeatureTypeInfoDTO will be updated with the schemaBase.
2717:             * </p>
2718:             * 
2719:             * @param schemaFile
2720:             *            File containing schema definition
2721:             * @param dto
2722:             *            Schema DOM element
2723:             * 
2724:             * @throws ConfigurationException
2725:             */
2726:            protected void loadSchema(File schemaFile, FeatureTypeInfoDTO dto)
2727:                    throws ConfigurationException {
2728:                try {
2729:                    schemaFile = ReaderUtils.checkFile(schemaFile, false);
2730:                } catch (FileNotFoundException e) {
2731:                    throw new ConfigurationException("Can't access "
2732:                            + schemaFile.getAbsolutePath(), e);
2733:                }
2734:
2735:                Element elem = null;
2736:                dto.setSchemaFile(schemaFile);
2737:
2738:                if ((schemaFile == null)
2739:                        || (!schemaFile.exists() || !schemaFile.canRead())) {
2740:                    System.err.println("File does not exist for schema for "
2741:                            + dto.getName());
2742:
2743:                    return;
2744:                }
2745:
2746:                try {
2747:                    if (LOGGER.isLoggable(Level.FINE)) {
2748:                        LOGGER.config(new StringBuffer(
2749:                                "Loading configuration file: ").append(
2750:                                schemaFile).toString());
2751:                    }
2752:
2753:                    Reader reader = XmlCharsetDetector
2754:                            .getCharsetAwareReader(new FileInputStream(
2755:                                    schemaFile));
2756:                    elem = ReaderUtils.parse(reader);
2757:                    reader.close();
2758:                } catch (FileNotFoundException e) {
2759:                    if (LOGGER.isLoggable(Level.FINEST)) {
2760:                        LOGGER.log(Level.FINEST, e.getMessage(), e);
2761:                    }
2762:
2763:                    throw new ConfigurationException(
2764:                            "Could not open schema file:" + schemaFile, e);
2765:                } catch (Exception erk) {
2766:                    throw new ConfigurationException(
2767:                            "Could not parse schema file:" + schemaFile, erk);
2768:                }
2769:
2770:                try {
2771:                    processSchema(elem, dto);
2772:                } catch (ConfigurationException e) {
2773:                    throw new ConfigurationException("Error occured in "
2774:                            + schemaFile + "\n" + e.getMessage(), e);
2775:                }
2776:            }
2777:
2778:            /**
2779:             * Process schema DOM for a list of AttributeTypeInfoDTO.
2780:             * 
2781:             * <p>
2782:             * The provided FeatureTypeInfoDTO will be updated with the schemaBase.
2783:             * </p>
2784:             * 
2785:             * @param elem
2786:             *            Schema DOM element
2787:             * @param featureTypeInfoDTO
2788:             * 
2789:             * @throws ConfigurationException
2790:             */
2791:            public static void processSchema(Element elem,
2792:                    FeatureTypeInfoDTO featureTypeInfoDTO)
2793:                    throws ConfigurationException {
2794:                ArrayList list = new ArrayList();
2795:
2796:                try {
2797:                    featureTypeInfoDTO.setSchemaName(ReaderUtils.getAttribute(
2798:                            elem, "name", true));
2799:
2800:                    elem = ReaderUtils.getChildElement(elem,
2801:                            "xs:complexContent");
2802:                    elem = ReaderUtils.getChildElement(elem, "xs:extension");
2803:
2804:                    NameSpaceTranslator gml = NameSpaceTranslatorFactory
2805:                            .getInstance().getNameSpaceTranslator("gml");
2806:                    NameSpaceElement nse = gml.getElement(ReaderUtils
2807:                            .getAttribute(elem, "base", true));
2808:                    featureTypeInfoDTO.setSchemaBase(nse
2809:                            .getQualifiedTypeDefName());
2810:                    elem = ReaderUtils.getChildElement(elem, "xs:sequence");
2811:
2812:                    NodeList nl = elem.getElementsByTagName("xs:element");
2813:
2814:                    for (int i = 0; i < nl.getLength(); i++) {
2815:                        // one element now
2816:                        elem = (Element) nl.item(i);
2817:
2818:                        AttributeTypeInfoDTO ati = new AttributeTypeInfoDTO();
2819:                        String name = ReaderUtils.getAttribute(elem, "name",
2820:                                false);
2821:                        String ref = ReaderUtils.getAttribute(elem, "ref",
2822:                                false);
2823:                        String type = ReaderUtils.getAttribute(elem, "type",
2824:                                false);
2825:
2826:                        NameSpaceTranslator nst1 = NameSpaceTranslatorFactory
2827:                                .getInstance().getNameSpaceTranslator("xs");
2828:                        NameSpaceTranslator nst2 = NameSpaceTranslatorFactory
2829:                                .getInstance().getNameSpaceTranslator("gml");
2830:
2831:                        if ((ref != null) && (ref != "")) {
2832:                            ati.setComplex(false);
2833:                            nse = nst1.getElement(ref);
2834:
2835:                            if (nse == null) {
2836:                                nse = nst2.getElement(ref);
2837:                            }
2838:
2839:                            String tmp = nse.getTypeRefName();
2840:
2841:                            // tmp = Character.toLowerCase(tmp.charAt(0)) +
2842:                            // tmp.substring(1);
2843:                            ati.setType(tmp);
2844:                            ati.setName(tmp);
2845:                        } else {
2846:                            ati.setName(name);
2847:
2848:                            if ((type != null) && (type != "")) {
2849:                                nse = nst1.getElement(type);
2850:
2851:                                if (nse == null) {
2852:                                    nse = nst2.getElement(type);
2853:                                }
2854:
2855:                                String tmp = nse.getTypeRefName();
2856:
2857:                                ati.setType(tmp);
2858:                                ati.setComplex(false);
2859:                            } else {
2860:                                Element tmp = ReaderUtils
2861:                                        .getFirstChildElement(elem);
2862:                                OutputFormat format = new OutputFormat(tmp
2863:                                        .getOwnerDocument());
2864:                                format.setLineSeparator(LineSeparator.Windows);
2865:                                format.setIndenting(true);
2866:                                format.setLineWidth(0);
2867:                                format.setPreserveSpace(true);
2868:
2869:                                StringWriter sw = new StringWriter();
2870:                                XMLSerializer serializer = new XMLSerializer(
2871:                                        sw, format);
2872:
2873:                                try {
2874:                                    serializer.asDOMSerializer();
2875:                                    serializer.serialize(tmp);
2876:                                } catch (IOException e) {
2877:                                    throw new ConfigurationException(e);
2878:                                }
2879:
2880:                                ati.setType(elem.toString());
2881:                                ati.setComplex(true);
2882:                            }
2883:                        }
2884:
2885:                        ati.setNillable(ReaderUtils.getBooleanAttribute(elem,
2886:                                "nillable", false, true));
2887:                        ati.setMaxOccurs(ReaderUtils.getIntAttribute(elem,
2888:                                "maxOccurs", false, 1));
2889:                        ati.setMinOccurs(ReaderUtils.getIntAttribute(elem,
2890:                                "minOccurs", false, 1));
2891:                        list.add(ati);
2892:                    }
2893:                } catch (Exception e) {
2894:                    throw new ConfigurationException(e);
2895:                }
2896:
2897:                featureTypeInfoDTO.setSchemaAttributes(list);
2898:            }
2899:
2900:            /**
2901:             * getData purpose.
2902:             * 
2903:             * <p>
2904:             * Description ...
2905:             * </p>
2906:             * 
2907:             * @return
2908:             */
2909:            public DataDTO getData() {
2910:                return data;
2911:            }
2912:
2913:            /**
2914:             * getGeoServer purpose.
2915:             * 
2916:             * <p>
2917:             * Description ...
2918:             * </p>
2919:             * 
2920:             * @return
2921:             */
2922:            public GeoServerDTO getGeoServer() {
2923:                return geoServer;
2924:            }
2925:
2926:            /**
2927:             * getWcs purpose.
2928:             * 
2929:             * <p>
2930:             * Description ...
2931:             * </p>
2932:             * 
2933:             * @return
2934:             */
2935:            public WCSDTO getWcs() {
2936:                return wcs;
2937:            }
2938:
2939:            /**
2940:             * getWfs purpose.
2941:             * 
2942:             * <p>
2943:             * Description ...
2944:             * </p>
2945:             * 
2946:             * @return
2947:             */
2948:            public WFSDTO getWfs() {
2949:                return wfs;
2950:            }
2951:
2952:            /**
2953:             * getWms purpose.
2954:             * 
2955:             * <p>
2956:             * Description ...
2957:             * </p>
2958:             * 
2959:             * @return
2960:             */
2961:            public WMSDTO getWms() {
2962:                return wms;
2963:            }
2964:
2965:            /**
2966:             * getMetaDataLink purpose.
2967:             * 
2968:             * <p>
2969:             * Used to help with XML manipulations. Returns a metedataLink Attribute
2970:             * </p>
2971:             * 
2972:             * @param metadataElem
2973:             *            The root element to look for children in.
2974:             * 
2975:             * @return The MetaDataLink that was found.
2976:             * @throws Exception
2977:             */
2978:            public static MetaDataLink getMetaDataLink(Element metadataElem)
2979:                    throws Exception {
2980:                MetaDataLink mdl = new MetaDataLink();
2981:                String tmp;
2982:
2983:                if (metadataElem != null) {
2984:                    tmp = ReaderUtils.getElementText(metadataElem, false);
2985:
2986:                    if ((tmp != null) && (tmp != "")) {
2987:                        mdl.setContent(tmp);
2988:                    }
2989:
2990:                    tmp = ReaderUtils
2991:                            .getAttribute(metadataElem, "about", false);
2992:
2993:                    if ((tmp != null) && (tmp != "")) {
2994:                        mdl.setAbout(tmp);
2995:                    }
2996:
2997:                    tmp = ReaderUtils.getAttribute(metadataElem, "type", false);
2998:
2999:                    if ((tmp != null) && (tmp != "")) {
3000:                        mdl.setType(tmp);
3001:                    }
3002:
3003:                    tmp = ReaderUtils.getAttribute(metadataElem,
3004:                            "metadataType", false);
3005:
3006:                    if ((tmp != null) && (tmp != "")) {
3007:                        mdl.setMetadataType(tmp);
3008:                    }
3009:                }
3010:
3011:                return mdl;
3012:            }
3013:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.