View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.renderkit;
21  
22  import org.apache.myfaces.tobago.component.Attributes;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.component.UIInput;
26  import javax.faces.context.FacesContext;
27  
28  public final class HtmlUtils {
29  
30    public static final String LAYOUT_ATTRIBUTE_PREFIX = "layout.";
31    public static final String CHAR_NON_BEAKING_SPACE = "\u00a0";
32  
33    private HtmlUtils() {
34    }
35  
36    public static String generateAttribute(String name, Object value) {
37      String stringValue;
38      if (value == null) {
39        stringValue = null;
40      } else if (value instanceof String) {
41        stringValue = (String) value;
42      } else {
43        stringValue = value.toString();
44      }
45      return (stringValue != null && stringValue.length() > 0)
46          ? name + "=\"" + value + "\""
47          : "";
48    }
49  
50    public static String appendAttribute(UIComponent component, String name,
51        String appendValue) {
52      Object attribute = component.getAttributes().get(name);
53      return attribute != null
54          ? attribute.toString() + " " + appendValue : appendValue;
55    }
56  
57    public static String generateOnchange(UIInput component,
58        FacesContext facesContext) {
59  
60      /*Validator[] validators = component.getValidators();
61      for (int i = 0; i < validators.length; i++) {
62        if (validators[i] instanceof LongRangeValidator) {
63          String functionCall = "validateLongRange('"
64              + component.getClientId(facesContext) + "')";
65          if (LOG.isDebugEnabled()) {
66            LOG.debug("validator functionCall: " + functionCall);
67          }
68          buffer.append(functionCall);
69        } else {
70          buffer.append("true");
71        }
72        if (i + 1 < validators.length) { // is not last
73          buffer.append(" && ");
74        }
75      } */
76  
77      Object onchange = component.getAttributes().get(Attributes.ONCHANGE);
78      if (onchange != null) {
79        return onchange.toString();
80      }
81      return null;
82    }
83  
84  }