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: OutputLinkBuilder.java 473459 2006-11-10 20:30:12Z gvanmatre $
20   */
21  package org.apache.shale.clay.parser.builder;
22  
23  import org.apache.shale.clay.config.beans.AttributeBean;
24  import org.apache.shale.clay.config.beans.ComponentBean;
25  import org.apache.shale.clay.config.beans.ElementBean;
26  import org.apache.shale.clay.config.beans.SymbolBean;
27  import org.apache.shale.clay.parser.Node;
28  
29  /***
30   * <p>
31   * This {@link Builder} will create a target
32   * {@link org.apache.shale.clay.config.beans.ElementBean} for a "&lt;a&gt;"
33   * {@link Node}. The mapping between the html and the builder is handled by the
34   * {@link AnchorBuilderRule}.
35   * </p>
36   */
37  public class OutputLinkBuilder extends Builder {
38  
39      /***
40       * <p>
41       * Returns a JSF component type of <code>javax.faces.HtmlOutputLink</code>.
42       * </p>
43       *
44       * @param node markup
45       * @return component type
46       */
47      protected String getComponentType(Node node) {
48          return "javax.faces.HtmlOutputLink";
49      }
50  
51      /***
52       * <p>
53       * Returns a <code>jsfid</code> that will populate the target
54       * {@link org.apache.shale.clay.config.beans.ElementBean}.
55       * </p>
56       *
57       * @param node markup
58       * @return jsfid
59       */
60      protected String getJsfid(Node node) {
61          return "outputLink";
62      }
63  
64      /***
65       * <p>
66       * Returns <code>true</code> meaning that the target JSF component can
67       * have children.
68       * </p>
69       *
70       * @return <code>true</code>
71       */
72      public boolean isChildrenAllowed() {
73          return true;
74      }
75  
76      /***
77       * <p>Calls super to populate the <code>target</code> config bean with the
78       * html <code>node</code>'s values.  The "href" attribute doesn't have a
79       * corresponding outputLink value so it will become a symbol.  If there
80       * is a "value" attribute, connect the component's "value" to the
81       * "@href" symbol.</p>
82       *
83       * @param node markup node
84       * @param target config bean
85       * @param root parent config bean
86       */
87      protected void encodeBegin(Node node, ElementBean target, ComponentBean root) {
88          super.encodeBegin(node, target, root);
89  
90          AttributeBean attr = target.getAttribute("value");
91          SymbolBean symbol = target.getSymbol("href");
92          if ((symbol != null && attr != null)
93              && (attr.getValue() == null || attr.getValue().length() == 0)) {
94              createAttribute(attr, "@href", target);
95          }
96      }
97  
98  }