001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.configuration2.web;
019
020import java.applet.Applet;
021import java.util.Arrays;
022import java.util.Iterator;
023
024/**
025 * A configuration wrapper to read applet parameters. This configuration is
026 * read only, adding or removing a property will throw an
027 * UnsupportedOperationException.
028 *
029 * @since 1.1
030 */
031public class AppletConfiguration extends BaseWebConfiguration
032{
033    /** Stores the wrapped applet.*/
034    protected Applet applet;
035
036    /**
037     * Create an AppletConfiguration using the initialization parameters of
038     * the specified Applet.
039     *
040     * @param applet the applet
041     */
042    public AppletConfiguration(final Applet applet)
043    {
044        this.applet = applet;
045    }
046
047    @Override
048    protected Object getPropertyInternal(final String key)
049    {
050        return handleDelimiters(applet.getParameter(key));
051    }
052
053    @Override
054    protected Iterator<String> getKeysInternal()
055    {
056        final String[][] paramsInfo = applet.getParameterInfo();
057        final String[] keys = new String[paramsInfo != null ? paramsInfo.length : 0];
058        for (int i = 0; i < keys.length; i++)
059        {
060            keys[i] = paramsInfo[i][0];
061        }
062
063        return Arrays.asList(keys).iterator();
064    }
065}