1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.lar;
16  
17  /**
18   * <a href="PortletDataHandlerChoice.java.html"><b><i>View Source</i></b></a>
19   *
20   * @author Raymond Augé
21   */
22  public class PortletDataHandlerChoice extends PortletDataHandlerControl {
23  
24      public PortletDataHandlerChoice(String namespace, String controlName) {
25          this(namespace, controlName, 0, _DEFAULT_CHOICES);
26      }
27  
28      public PortletDataHandlerChoice(
29          String namespace, String controlName, int defaultChoice) {
30          this(namespace, controlName, defaultChoice, _DEFAULT_CHOICES);
31      }
32  
33      public PortletDataHandlerChoice(
34          String namespace, String controlName, int defaultChoice,
35          String[] choices) {
36  
37          super(namespace, controlName);
38  
39          _choices = choices;
40          _defaultChoice = defaultChoice;
41      }
42  
43      public String[] getChoices() {
44          if ((_choices == null) || (_choices.length < 1)) {
45              return _DEFAULT_CHOICES;
46          }
47          else {
48              return _choices;
49          }
50      }
51  
52      public String getDefaultChoice() {
53          return getChoices()[getDefaultChoiceIndex()];
54      }
55  
56      public int getDefaultChoiceIndex() {
57          if ((_defaultChoice < 0) || (_defaultChoice >= _choices.length)) {
58              return 0;
59          }
60          else {
61              return _defaultChoice;
62          }
63      }
64  
65      private static final String[] _DEFAULT_CHOICES = new String[] {
66          "false", "true"
67      };
68  
69      private String[] _choices;
70      private int _defaultChoice;
71  
72  }