001 package org.apache.myfaces.tobago.util; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 import javax.faces.application.Application; 021 022 public enum FacesVersion { 023 024 VERSION_11, 025 VERSION_12, 026 VERSION_20; 027 028 private static FacesVersion currentVersion; 029 030 static { 031 try { 032 Application.class.getMethod("getExpressionFactory"); 033 034 try { 035 Application.class.getMethod("getExceptionHandler"); 036 037 currentVersion = VERSION_20; 038 039 040 } catch (NoSuchMethodException e) { 041 currentVersion = VERSION_12; 042 } 043 044 } catch (NoSuchMethodException e) { 045 currentVersion = VERSION_11; 046 } 047 } 048 049 /** 050 * Does the JSF is version 1.2 or higher 051 * @return Supports 1.2 or higher 052 */ 053 public static boolean supports12() { 054 return currentVersion == VERSION_12 || currentVersion == VERSION_20; 055 } 056 057 /** 058 * Does the JSF is version 2.0 or higher 059 * @return Supports 2.0 or higher 060 */ 061 public static boolean supports20() { 062 return currentVersion == VERSION_20; 063 } 064 }