2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    *  * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * $Id: SelectManyMenuBuilder.java 464373 2006-10-16 04:21:54Z rahul $
20   */
21  package org.apache.shale.clay.parser.builder;
22  
23  import java.util.ArrayList;
24  import java.util.Iterator;
25  
26  import org.apache.shale.clay.config.beans.ComponentBean;
27  import org.apache.shale.clay.config.beans.ElementBean;
28  import org.apache.shale.clay.parser.Node;
29  
30  /***
31   * <p>
32   * This {@link Builder} creates a {@link org.apache.shale.clay.config.beans.ElementBean}
33   * mapped to a html select {@link org.apache.shale.clay.parser.Node} by the
34   * {@link org.apache.shale.clay.parser.builder.chain.SelectBuilderRule}. The JSF component
35   * type for a multi-select is <code>javax.faces.HtmlSelectManyMenu</code>
36   * <p>
37   */
38  public class SelectManyMenuBuilder extends Builder {
39  
40      /***
41       * <p>
42       * Returns the JSF component type of
43       * <code>javax.faces.HtmlSelectManyMenu</code> that will populate the
44       * target {@link org.apache.shale.clay.config.beans.ElementBean}.
45       * </p>
46       *
47       * @param node markup node
48       * @return component type
49       */
50      protected String getComponentType(Node node) {
51          return "javax.faces.HtmlSelectManyMenu";
52      }
53  
54      /***
55       * <p>
56       * Returns the <code>jsfid</code> for the target
57       * {@link org.apache.shale.clay.config.beans.ElementBean}.
58       * </p>
59       *
60       * @param node current markup node
61       * @return target jsfid
62       */
63      protected String getJsfid(Node node) {
64          return "selectManyMenu";
65      }
66  
67      /***
68       * <p>
69       * Returns <code>true</code> indicating that the multi-select component
70       * can have children.
71       * </p>
72       *
73       * @return always returns <code>true</code>
74       */
75      public boolean isChildrenAllowed() {
76          return true;
77      }
78  
79      /***
80       * <p>Remove any child nodes that are not "option" nodes.</p>
81       *
82       * @param node current markup node
83       * @param target bean that will be build from the node
84       * @param root the parent of the target
85       */
86      protected void encodeBegin(Node node, ElementBean target, ComponentBean root) {
87  
88          //remove any children that are not option nodes
89          ArrayList delList = new ArrayList();
90          Iterator ci = node.getChildren().iterator();
91          while (ci.hasNext()) {
92             Node child = (Node) ci.next();
93             if (child.getName() == null || !child.getName().equalsIgnoreCase("option")) {
94                delList.add(child);
95             }
96          }
97          for (int i = 0; i < delList.size(); i++) {
98             node.getChildren().remove(delList.get(i));
99          }
100         delList.clear();
101 
102         super.encodeBegin(node, target, root);
103     }
104 
105 }