001/*
002 * Copyright 2023 Web-Legacy
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.apache.tiles.request.jakarta.servlet.extractor;
017
018import java.util.Enumeration;
019
020import org.apache.tiles.request.attribute.HasKeys;
021
022import jakarta.servlet.ServletContext;
023
024/**
025 * Extract initialization parameters from the servlet context.
026 *
027 * <p>Copied from Apache tiles-request-servlet 1.0.7 and adapted for
028 * Jakarta EE 9.</p>
029 */
030public class InitParameterExtractor implements HasKeys<String> {
031
032    /**
033     * The servlet context.
034     */
035    private ServletContext context;
036
037    /**
038     * Constructor.
039     *
040     * @param context The servlet context.
041     */
042    public InitParameterExtractor(ServletContext context) {
043        this.context = context;
044    }
045
046    /**
047     * The enumeration of the keys in the stored attributes.
048     *
049     * @return The keys.
050     */
051    @Override
052    public Enumeration<String> getKeys() {
053        return context.getInitParameterNames();
054    }
055
056    /**
057     * Returns the value of the attribute with the given key.
058     *
059     * @param key The key of the attribute.
060     *
061     * @return The value.
062     */
063    @Override
064    public String getValue(String key) {
065        return context.getInitParameter(key);
066    }
067}