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.util;
20
21 /**
22 * Utilities for determining the current container and for the unified
23 * expression language.
24 *
25 */
26 public class ContainerUtils
27 {
28 /**
29 * Determines whether we're running in a Servlet 2.5/JSP 2.1 environment.
30 *
31 * @return <code>true</code> if we're running in a JSP 2.1 environment,
32 * <code>false</code> otherwise
33 */
34 public static boolean isJsp21()
35 {
36 try
37 {
38 // simply check if the class JspApplicationContext is available
39 Class.forName("javax.servlet.jsp.JspApplicationContext");
40 return true;
41 }
42 catch (ClassNotFoundException ex)
43 {
44 ; // expected exception in a JSP 2.0 (or less) environment
45 }
46
47 return false;
48 }
49
50 /**
51 * Return true if the specified string contains an EL expression.
52 *
53 * <p>
54 * <strong>NOTICE</strong> This method is just a copy of
55 * {@link UIComponentTag#isValueReference(String)}, but it's required
56 * because the class UIComponentTag depends on a JSP 2.1 container
57 * (for example, it indirectly implements the interface JspIdConsumer)
58 * and therefore internal classes shouldn't access this class. That's
59 * also the reason why this method is inside the class ContainerUtils,
60 * because it allows MyFaces to be independent of a JSP 2.1 container.
61 * </p>
62 */
63 public static boolean isValueReference(String value)
64 {
65 if (value == null) {
66 throw new NullPointerException("value");
67 }
68
69 int start = value.indexOf("#{");
70 if (start < 0) {
71 return false;
72 }
73
74 int end = value.lastIndexOf('}');
75 return (end >=0 && start < end);
76 }
77 }