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  /**
29   *  @deprecated since 2.0.8
30   */
31  public final class HtmlUtils {
32  
33    public static final String LAYOUT_ATTRIBUTE_PREFIX = "layout.";
34    /**
35     *  @deprecated since 2.0.8, use HtmlRendererUtils
36     */
37    public static final String CHAR_NON_BEAKING_SPACE = "\u00a0";
38  
39    private HtmlUtils() {
40    }
41  
42    public static String generateAttribute(final String name, final Object value) {
43      final String stringValue;
44      if (value == null) {
45        stringValue = null;
46      } else if (value instanceof String) {
47        stringValue = (String) value;
48      } else {
49        stringValue = value.toString();
50      }
51      return (stringValue != null && stringValue.length() > 0)
52          ? name + "=\"" + value + "\""
53          : "";
54    }
55  
56    public static String appendAttribute(final UIComponent component, final String name,
57        final String appendValue) {
58      final Object attribute = component.getAttributes().get(name);
59      return attribute != null
60          ? attribute.toString() + " " + appendValue : appendValue;
61    }
62  
63    /** @deprecated Since 2.0.8. Not allowed with CSP */
64    public static String generateOnchange(final UIInput component,
65        final FacesContext facesContext) {
66  
67      /*Validator[] validators = component.getValidators();
68      for (int i = 0; i < validators.length; i++) {
69        if (validators[i] instanceof LongRangeValidator) {
70          String functionCall = "validateLongRange('"
71              + component.getClientId(facesContext) + "')";
72          if (LOG.isDebugEnabled()) {
73            LOG.debug("validator functionCall: " + functionCall);
74          }
75          buffer.append(functionCall);
76        } else {
77          buffer.append("true");
78        }
79        if (i + 1 < validators.length) { // is not last
80          buffer.append(" && ");
81        }
82      } */
83  
84      final Object onchange = component.getAttributes().get(Attributes.ONCHANGE);
85      if (onchange != null) {
86        return onchange.toString();
87      }
88      return null;
89    }
90  
91  }