public void load()

in ti/phase2/jars/core/src/java/org/apache/ti/pageflow/internal/DefaultURLTemplatesFactory.java [129:217]


    public void load(WebContext webContext, SourceResolver sourceResolver) {
        _urlTemplates = new URLTemplates();

        InputStream xmlInputStream = null;
        InputStream xsdInputStream = null;

        try {
            URL url = sourceResolver.resolve(_configFilePath, webContext);

            if (url != null) {
                xmlInputStream = url.openStream();

                /* load the XSD input stream */
                xsdInputStream = SCHEMA_RESOLVER.getInputStream();

                final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
                final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
                final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";

                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setValidating(true);
                dbf.setNamespaceAware(true);
                dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                dbf.setAttribute(JAXP_SCHEMA_SOURCE, xsdInputStream);

                DocumentBuilder db = dbf.newDocumentBuilder();

                /* add an ErrorHandler that just logs validation problems */
                db.setErrorHandler(new ErrorHandler() {
                        public void warning(SAXParseException exception) {
                            _log.info("Validation warning validating config file \"" + _configFilePath +
                                      "\" against XML Schema \"" + SCHEMA_RESOLVER.getResourcePath());
                        }

                        public void error(SAXParseException exception) {
                            _log.error("Validation errors occurred parsing the config file \"" + _configFilePath +
                                       "\".  Cause: " + exception, exception);
                        }

                        public void fatalError(SAXParseException exception) {
                            _log.error("Validation errors occurred parsing the config file \"" + _configFilePath +
                                       "\".  Cause: " + exception, exception);
                        }
                    });

                db.setEntityResolver(new EntityResolver() {
                        public InputSource resolveEntity(String publicId, String systemId) {
                            if (systemId.endsWith("/url-template-config.xsd")) {
                                InputStream inputStream = DefaultURLTemplatesFactory.class.getClassLoader().getResourceAsStream(CONFIG_SCHEMA);

                                return new InputSource(inputStream);
                            } else {
                                return null;
                            }
                        }
                    });

                Document document = db.parse(xmlInputStream);
                Element root = document.getDocumentElement();
                loadTemplates(root);
                loadTemplateRefGroups(root);
            } else {
                if (_log.isInfoEnabled()) {
                    _log.info("Running without URL template descriptor, " + _configFilePath);
                }
            }
        } catch (ParserConfigurationException pce) {
            _log.error("Problem loading URL template descriptor file " + _configFilePath, pce);
        } catch (SAXException se) {
            _log.error("Problem parsing URL template descriptor in " + _configFilePath, se);
        } catch (IOException ioe) {
            _log.error("Problem reading URL template descriptor file " + _configFilePath, ioe);
        } finally {
            // Close the streams
            try {
                if (xmlInputStream != null) {
                    xmlInputStream.close();
                }
            } catch (Exception ignore) {
            }

            try {
                if (xsdInputStream != null) {
                    xsdInputStream.close();
                }
            } catch (IOException ignore) {
            }
        }
    }