| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.configuration.web.AppletConfiguration |
|
|
| 1 | /* |
|
| 2 | * Copyright 2004 The Apache Software Foundation. |
|
| 3 | * |
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
| 5 | * you may not use this file except in compliance with the License. |
|
| 6 | * You may obtain a copy of the License at |
|
| 7 | * |
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 9 | * |
|
| 10 | * Unless required by applicable law or agreed to in writing, software |
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 13 | * See the License for the specific language governing permissions and |
|
| 14 | * limitations under the License. |
|
| 15 | */ |
|
| 16 | ||
| 17 | package org.apache.commons.configuration.web; |
|
| 18 | ||
| 19 | import java.applet.Applet; |
|
| 20 | import java.util.Iterator; |
|
| 21 | import java.util.List; |
|
| 22 | ||
| 23 | import org.apache.commons.collections.iterators.ArrayIterator; |
|
| 24 | import org.apache.commons.configuration.AbstractConfiguration; |
|
| 25 | import org.apache.commons.configuration.PropertyConverter; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * A configuration wrapper to read applet parameters. This configuration is |
|
| 29 | * read only, adding or removing a property will throw an |
|
| 30 | * UnsupportedOperationException. |
|
| 31 | * |
|
| 32 | * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a> |
|
| 33 | * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $ |
|
| 34 | * @since 1.1 |
|
| 35 | */ |
|
| 36 | public class AppletConfiguration extends AbstractConfiguration |
|
| 37 | { |
|
| 38 | protected Applet applet; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Create an AppletConfiguration using the initialization parameters of |
|
| 42 | * the specified Applet. |
|
| 43 | * |
|
| 44 | * @param applet |
|
| 45 | 72 | */ |
| 46 | 72 | public AppletConfiguration(Applet applet) |
| 47 | 184 | { |
| 48 | 112 | this.applet = applet; |
| 49 | 112 | } |
| 50 | ||
| 51 | 45 | public Object getProperty(String key) |
| 52 | { |
|
| 53 | 98 | Object value = applet.getParameter(key); |
| 54 | 98 | List list = PropertyConverter.split((String) value, getDelimiter()); |
| 55 | ||
| 56 | 98 | return list.size() > 1 ? list : value; |
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * <p><strong>This operation is not supported and will throw an |
|
| 61 | * UnsupportedOperationException.</strong></p> |
|
| 62 | 9 | * |
| 63 | * @throws UnsupportedOperationException |
|
| 64 | */ |
|
| 65 | protected void addPropertyDirect(String key, Object obj) |
|
| 66 | { |
|
| 67 | 32 | throw new UnsupportedOperationException("Read only configuration"); |
| 68 | } |
|
| 69 | ||
| 70 | public boolean isEmpty() |
|
| 71 | { |
|
| 72 | 46 | return !getKeys().hasNext(); |
| 73 | } |
|
| 74 | ||
| 75 | public boolean containsKey(String key) |
|
| 76 | { |
|
| 77 | 28 | return getProperty(key) != null; |
| 78 | } |
|
| 79 | ||
| 80 | /** |
|
| 81 | * <p><strong>This operation is not supported and will throw an |
|
| 82 | * UnsupportedOperationException.</strong></p> |
|
| 83 | 9 | * |
| 84 | * @throws UnsupportedOperationException |
|
| 85 | */ |
|
| 86 | public void clearProperty(String key) |
|
| 87 | { |
|
| 88 | 50 | throw new UnsupportedOperationException("Read only configuration"); |
| 89 | 36 | } |
| 90 | 72 | |
| 91 | public Iterator getKeys() |
|
| 92 | 36 | { |
| 93 | 42 | String[][] paramsInfo = applet.getParameterInfo(); |
| 94 | 42 | String[] keys = new String[paramsInfo != null ? paramsInfo.length : 0]; |
| 95 | 162 | for (int i = 0; i < keys.length; i++) |
| 96 | { |
|
| 97 | 84 | keys[i] = paramsInfo[i][0]; |
| 98 | } |
|
| 99 | ||
| 100 | 42 | return new ArrayIterator(keys); |
| 101 | } |
|
| 102 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |