public void init()

in src/java/org/apache/turbine/services/urlmapper/TurbineURLMapperService.java [258:314]


    public void init() throws InitializationException
    {
        Configuration cfg = getConfiguration();

        String configFile = cfg.getString(CONFIGURATION_FILE_KEY, DEFAULT_CONFIGURATION_FILE);

        // context resource path has to begin with slash, cft.
        // context.getResource
        if (!configFile.startsWith("/"))
        {
            configFile = "/" + configFile;
        }

        ServletService servletService = (ServletService) TurbineServices.getInstance().getService(ServletService.SERVICE_NAME);

        try (InputStream reader = servletService.getResourceAsStream(configFile))
        {
            if (configFile.endsWith(".xml"))
            {
                JAXBContext jaxb = JAXBContext.newInstance(URLMappingContainer.class);
                Unmarshaller unmarshaller = jaxb.createUnmarshaller();
                container = (URLMappingContainer) unmarshaller.unmarshal(reader);
            } else if (configFile.endsWith(".yml"))
            {
                // org.apache.commons.configuration2.YAMLConfiguration does only expose property like configuration values,
                // which is not what we need here -> java object deserialization.
                ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
                container = mapper.readValue(reader, URLMappingContainer.class);
            } else if (configFile.endsWith(".json"))
            {
                ObjectMapper mapper = JsonMapper.builder().build();
                container = mapper.readValue(reader, URLMappingContainer.class);
            }
        }
        catch (IOException | JAXBException e)
        {
            throw new InitializationException("Could not load configuration file " + configFile, e);
        }

        // Get groupNamesMap for every Pattern and store it in the entry
        for (URLMapEntry urlMap : container.getMapEntries())
        {
            int position = 1;
            Map<String, Integer> groupNamesMap = new HashMap<>();
            Matcher matcher = NAMED_GROUPS_PATTERN.matcher(urlMap.getUrlPattern().pattern());

            while (matcher.find())
            {
                groupNamesMap.put(matcher.group(1), Integer.valueOf(position++));
            }
            urlMap.setGroupNamesMap(groupNamesMap);
        }

        log.info("Loaded {} url-mappings from {}", Integer.valueOf(container.getMapEntries().size()), configFile);

        setInit(true);
    }