1 33 34 package com.icesoft.faces.webapp.parser; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 import javax.faces.FacesException; 40 import javax.faces.context.FacesContext; 41 import javax.servlet.jsp.PageContext ; 42 import java.util.List ; 43 44 import com.icesoft.faces.webapp.parser.ComponentRuleSet; 45 46 54 public class ImplementationUtil { 55 56 59 protected static Log log = LogFactory.getLog(ImplementationUtil.class); 60 61 62 65 private static boolean isRI = false; 66 private static boolean isMyFaces = false; 67 68 72 private static String RI_MARKER = 73 "com.sun.faces.application.ApplicationImpl"; 74 private static String MYFACES_MARKER = 75 "org.apache.myfaces.application.ApplicationImpl"; 76 77 83 private static String RI_COMPONENT_STACK_KEY = 84 "javax.faces.webapp.COMPONENT_TAG_STACK"; 85 86 private static String MYFACES_COMPONENT_STACK_KEY = 87 "javax.faces.webapp.UIComponentTag.COMPONENT_STACK"; 88 89 90 static { 91 try { 92 Class.forName(RI_MARKER); 93 isRI = true; 94 } catch (ClassNotFoundException e) { 95 } 96 97 try { 98 Class.forName(MYFACES_MARKER); 99 isMyFaces = true; 100 } catch (ClassNotFoundException e) { 101 } 102 103 if (log.isTraceEnabled()) { 104 log.trace("JSF-RI: " + isRI + " MyFaces: " + isMyFaces); 105 } 106 107 } 108 109 116 public static boolean isRI() { 117 return isRI; 118 } 119 120 126 public static boolean isMyFaces() { 127 return isMyFaces; 128 } 129 130 135 public static boolean isJSF12() { 136 return ComponentRuleSet.isJSF12(); 137 } 138 139 140 148 public static String getComponentStackKey() { 149 String key = null; 150 if (isRI) { 151 key = RI_COMPONENT_STACK_KEY; 152 } else if (isMyFaces) { 153 key = MYFACES_COMPONENT_STACK_KEY; 154 } 155 156 if (key != null) { 157 return key; 158 } 159 160 if (log.isFatalEnabled()) { 161 log.fatal( 162 "cannot detect JSF implementation so cannot determine component stack key"); 163 } 164 165 throw new UnknownJSFImplementationException( 166 "cannot determine component stack key"); 167 } 168 169 175 public static List getComponentStack(PageContext pageContext) { 176 List list = (List ) pageContext.getAttribute( 177 getComponentStackKey(), PageContext.REQUEST_SCOPE); 178 if (null == list) { 179 list = (List ) FacesContext.getCurrentInstance() 180 .getExternalContext().getRequestMap().get( 181 getComponentStackKey()); 182 } 183 return list; 184 185 } 186 } 187 188 class UnknownJSFImplementationException extends FacesException { 189 190 public UnknownJSFImplementationException() { 191 } 192 193 public UnknownJSFImplementationException(Throwable cause) { 194 super(cause); 195 } 196 197 public UnknownJSFImplementationException(String message) { 198 super(message); 199 } 200 201 public UnknownJSFImplementationException(String message, Throwable cause) { 202 super(message, cause); 203 } 204 205 } 206 | Popular Tags |