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  package org.apache.myfaces.trinidad.util;
20  
21  /**
22   * Utilities for the unified expression language.
23   * Keeps Trinidad independent of a JSP 2.1 container,
24   * for example if Facelets are used.
25   */
26  public final class ContainerUtils
27  {
28  
29    private ContainerUtils()
30    {
31      //no-op
32    }
33  
34    /**
35     * Return true if the specified string contains an EL expression.
36     * 
37     * <p>
38     * <strong>NOTICE</strong> This method is just a copy of
39     * {@link UIComponentTag#isValueReference(String)}, but it's required
40     * because the class UIComponentTag depends on a JSP 2.1 container 
41     * (for example, it indirectly implements the interface JspIdConsumer)
42     * and therefore internal classes shouldn't access this class. That's
43     * also the reason why this method is inside the class ContainerUtils,
44     * because it allows MyFaces to be independent of a JSP 2.1 container.
45     * </p>
46     */
47    public static boolean isValueReference(String value) 
48    {
49      if (value == null)
50      {
51  
52        throw new NullPointerException("value");
53  
54      }
55  
56      int start = value.indexOf("#{");
57  
58  
59      if (start < 0)
60      {
61        return false;
62  
63      }
64  
65      int end = value.lastIndexOf('}');
66  
67      return (end >=0 && start < end);
68    }
69  }