Advertisement
Guest User

WebConfiguration.java

a guest
Jan 6th, 2016
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 56.23 KB | None | 0 0
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * The contents of this file are subject to the terms of either the GNU
  7. * General Public License Version 2 only ("GPL") or the Common Development
  8. * and Distribution License("CDDL") (collectively, the "License"). You
  9. * may not use this file except in compliance with the License. You can
  10. * obtain a copy of the License at
  11. * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  12. * or packager/legal/LICENSE.txt. See the License for the specific
  13. * language governing permissions and limitations under the License.
  14. *
  15. * When distributing the software, include this License Header Notice in each
  16. * file and include the License file at packager/legal/LICENSE.txt.
  17. *
  18. * GPL Classpath Exception:
  19. * Oracle designates this particular file as subject to the "Classpath"
  20. * exception as provided by Oracle in the GPL Version 2 section of the License
  21. * file that accompanied this code.
  22. *
  23. * Modifications:
  24. * If applicable, add the following below the License Header, with the fields
  25. * enclosed by brackets [] replaced by your own identifying information:
  26. * "Portions Copyright [year] [name of copyright owner]"
  27. *
  28. * Contributor(s):
  29. * If you wish your version of this file to be governed by only the CDDL or
  30. * only the GPL Version 2, indicate your decision by adding "[Contributor]
  31. * elects to include this software in this distribution under the [CDDL or GPL
  32. * Version 2] license." If you don't indicate a single choice of license, a
  33. * recipient has the option to distribute your version of this file under
  34. * either the CDDL, the GPL Version 2 or to extend the choice of license to
  35. * its licensees as provided above. However, if you add GPL Version 2 code
  36. * and therefore, elected the GPL Version 2 license, then the option applies
  37. * only if the new code is made subject to such option by the copyright
  38. * holder.
  39. */
  40.  
  41. package com.sun.faces.config;
  42.  
  43. import com.sun.faces.application.ApplicationAssociate;
  44. import com.sun.faces.application.view.FaceletViewHandlingStrategy;
  45. import com.sun.faces.facelets.util.Classpath;
  46. import com.sun.faces.lifecycle.HttpMethodRestrictionsPhaseListener;
  47. import java.util.ArrayList;
  48. import java.util.Arrays;
  49. import java.util.EnumMap;
  50. import java.util.Enumeration;
  51. import java.util.HashSet;
  52. import java.util.Map;
  53. import java.util.Set;
  54. import java.util.logging.Level;
  55. import java.util.logging.Logger;
  56. import java.util.regex.Pattern;
  57.  
  58. //import javax.enterprise.inject.spi.BeanManager;
  59. import javax.faces.application.ResourceHandler;
  60. import javax.faces.application.ViewHandler;
  61. import javax.faces.application.StateManager;
  62. import javax.faces.context.ExternalContext;
  63. import javax.faces.context.FacesContext;
  64. import javax.naming.Context;
  65. import javax.naming.InitialContext;
  66. import javax.naming.NamingException;
  67. import javax.servlet.ServletContext;
  68.  
  69. import com.sun.faces.util.FacesLogger;
  70. import com.sun.faces.util.Util;
  71. import java.io.IOException;
  72. import java.net.URL;
  73. import java.util.Collections;
  74.  
  75. import java.util.HashMap;
  76. import java.util.Iterator;
  77. import java.util.List;
  78. import java.util.concurrent.ConcurrentHashMap;
  79. import javax.faces.FactoryFinder;
  80. import javax.faces.application.ProjectStage;
  81. import javax.faces.component.UIInput;
  82. import javax.faces.convert.Converter;
  83. import javax.faces.event.PhaseListener;
  84. import javax.faces.lifecycle.ClientWindow;
  85. import javax.faces.lifecycle.Lifecycle;
  86. import javax.faces.lifecycle.LifecycleFactory;
  87. import javax.faces.validator.BeanValidator;
  88. import javax.faces.view.facelets.ResourceResolver;
  89. import javax.faces.webapp.FacesServlet;
  90.  
  91.  
  92. /** Class Documentation */
  93. public class WebConfiguration {
  94.  
  95.  
  96. // Log instance for this class
  97. private static final Logger LOGGER = FacesLogger.CONFIG.getLogger();
  98.  
  99. // A Simple regular expression of allowable boolean values
  100. private static final Pattern ALLOWABLE_BOOLEANS =
  101. Pattern.compile("true|false", Pattern.CASE_INSENSITIVE);
  102.  
  103. // Key under which we store our WebConfiguration instance.
  104. private static final String WEB_CONFIG_KEY =
  105. "com.sun.faces.config.WebConfiguration";
  106.  
  107. public static final String META_INF_CONTRACTS_DIR = "META-INF" +
  108. WebContextInitParameter.WebAppContractsDirectory.getDefaultValue();
  109.  
  110. private static final int META_INF_CONTRACTS_DIR_LEN = META_INF_CONTRACTS_DIR.length();
  111.  
  112. private static final String RESOURCE_CONTRACT_SUFFIX = "/" + ResourceHandler.RESOURCE_CONTRACT_XML;
  113.  
  114. // Logging level. Defaults to FINE
  115. private Level loggingLevel = Level.FINE;
  116.  
  117. private Map<BooleanWebContextInitParameter, Boolean> booleanContextParameters =
  118. new EnumMap<BooleanWebContextInitParameter, Boolean>(BooleanWebContextInitParameter.class);
  119.  
  120. private Map<WebContextInitParameter, String> contextParameters =
  121. new EnumMap<WebContextInitParameter, String>(WebContextInitParameter.class);
  122.  
  123. private Map<WebContextInitParameter, Map<String, String>> facesConfigParameters =
  124. new EnumMap<WebContextInitParameter, Map<String, String>>(WebContextInitParameter.class);
  125.  
  126. private Map<WebEnvironmentEntry, String> envEntries =
  127. new EnumMap<WebEnvironmentEntry, String>(WebEnvironmentEntry.class);
  128.  
  129. private Map<WebContextInitParameter, String []> cachedListParams;
  130.  
  131. private Set<String> setParams = new HashSet<String>();
  132.  
  133. private ServletContext servletContext;
  134.  
  135. private ArrayList<DeferredLoggingAction> deferredLoggingActions;
  136.  
  137. private FaceletsConfiguration faceletsConfig;
  138.  
  139. private boolean hasFlows;
  140.  
  141.  
  142. // ------------------------------------------------------------ Constructors
  143.  
  144.  
  145. private WebConfiguration(ServletContext servletContext) {
  146.  
  147. this.servletContext = servletContext;
  148.  
  149. String contextName = getServletContextName();
  150.  
  151. initSetList(servletContext);
  152. processBooleanParameters(servletContext, contextName);
  153. processInitParameters(servletContext, contextName);
  154. if (canProcessJndiEntries()) {
  155. processJndiEntries(contextName);
  156. }
  157.  
  158. // build the cache of list type params
  159. cachedListParams = new HashMap<WebContextInitParameter, String []>(3);
  160. getOptionValue(WebContextInitParameter.ResourceExcludes, " ");
  161. getOptionValue(WebContextInitParameter.DefaultSuffix, " ");
  162. getOptionValue(WebContextInitParameter.FaceletsViewMappings, ";");
  163. getOptionValue(WebContextInitParameter.FaceletsSuffix, " ");
  164. }
  165.  
  166.  
  167.  
  168. // ---------------------------------------------------------- Public Methods
  169.  
  170.  
  171. /**
  172. * Return the WebConfiguration instance for this application passing
  173. * the result of FacesContext.getCurrentInstance().getExternalContext()
  174. * to {@link #getInstance(javax.faces.context.ExternalContext)}.
  175. * @return the WebConfiguration for this application or <code>null</code>
  176. * if no FacesContext is available.
  177. */
  178. public static WebConfiguration getInstance() {
  179.  
  180. FacesContext facesContext = FacesContext.getCurrentInstance();
  181. return getInstance(facesContext.getExternalContext());
  182.  
  183. }
  184.  
  185.  
  186. /**
  187. * Return the WebConfiguration instance for this application.
  188. * @param extContext the ExternalContext for this request
  189. * @return the WebConfiguration for this application
  190. */
  191. public static WebConfiguration getInstance(ExternalContext extContext) {
  192.  
  193. WebConfiguration config = (WebConfiguration) extContext.getApplicationMap()
  194. .get(WEB_CONFIG_KEY);
  195. if (config == null) {
  196. return getInstance((ServletContext) extContext.getContext());
  197. } else {
  198. return config;
  199. }
  200.  
  201. }
  202.  
  203.  
  204. /**
  205. * Return the WebConfiguration instance for this application.
  206. * @param servletContext the ServletContext
  207. * @return the WebConfiguration for this application or <code>null</code>
  208. * if no WebConfiguration could be located
  209. */
  210. public static WebConfiguration getInstance(ServletContext servletContext) {
  211.  
  212. WebConfiguration webConfig = (WebConfiguration)
  213. servletContext.getAttribute(WEB_CONFIG_KEY);
  214.  
  215. if (webConfig == null) {
  216. webConfig = new WebConfiguration(servletContext);
  217. servletContext.setAttribute(WEB_CONFIG_KEY, webConfig);
  218. }
  219. return webConfig;
  220.  
  221. }
  222.  
  223. public static WebConfiguration getInstanceWithoutCreating(ServletContext servletContext) {
  224. WebConfiguration webConfig = (WebConfiguration)
  225. servletContext.getAttribute(WEB_CONFIG_KEY);
  226.  
  227. return webConfig;
  228. }
  229.  
  230.  
  231. /**
  232. * @return The <code>ServletContext</code> originally used to construct
  233. * this WebConfiguration instance
  234. */
  235. public ServletContext getServletContext() {
  236.  
  237. return servletContext;
  238.  
  239. }
  240.  
  241. public boolean isHasFlows() {
  242. return hasFlows;
  243. }
  244.  
  245. public void setHasFlows(boolean hasFlows) {
  246. this.hasFlows = hasFlows;
  247. }
  248.  
  249. /**
  250. * Obtain the value of the specified boolean parameter
  251. * @param param the parameter of interest
  252. * @return the value of the specified boolean parameter
  253. */
  254. public boolean isOptionEnabled(BooleanWebContextInitParameter param) {
  255.  
  256. if (booleanContextParameters.get(param) != null) {
  257. return booleanContextParameters.get(param);
  258. } else {
  259. return param.getDefaultValue();
  260. }
  261.  
  262. }
  263.  
  264.  
  265. /**
  266. * Obtain the value of the specified parameter
  267. * @param param the parameter of interest
  268. * @return the value of the specified parameter
  269. */
  270. public String getOptionValue(WebContextInitParameter param) {
  271. String result = contextParameters.get(param);
  272.  
  273. if (null == result) {
  274. WebContextInitParameter alternate = param.getAlternate();
  275. if (null != alternate) {
  276. result = contextParameters.get(alternate);
  277. }
  278. }
  279.  
  280. return result;
  281.  
  282. }
  283.  
  284. public void setOptionValue(WebContextInitParameter param, String value) {
  285. contextParameters.put(param, value);
  286. }
  287.  
  288. public void setOptionEnabled(BooleanWebContextInitParameter param, boolean value) {
  289. booleanContextParameters.put(param, value);
  290. }
  291.  
  292. public FaceletsConfiguration getFaceletsConfiguration() {
  293.  
  294. if (null == faceletsConfig) {
  295. faceletsConfig = new FaceletsConfiguration(this);
  296. }
  297. return faceletsConfig;
  298.  
  299. }
  300.  
  301. public Map<String, String> getFacesConfigOptionValue(WebContextInitParameter param, boolean create) {
  302. Map<String, String> result = null;
  303.  
  304. assert(null != facesConfigParameters);
  305.  
  306. result = facesConfigParameters.get(param);
  307. if (null == result) {
  308. if (create) {
  309. result = new ConcurrentHashMap<String, String>(3);
  310. facesConfigParameters.put(param, result);
  311. } else {
  312. result = Collections.emptyMap();
  313. }
  314. }
  315.  
  316. return result;
  317.  
  318. }
  319.  
  320. public Map<String, String> getFacesConfigOptionValue(WebContextInitParameter param) {
  321. return getFacesConfigOptionValue(param, false);
  322. }
  323.  
  324.  
  325. public String[] getOptionValue(WebContextInitParameter param, String sep) {
  326. String [] result;
  327.  
  328. assert(null != cachedListParams);
  329. if (null == (result = cachedListParams.get(param))) {
  330. String value = getOptionValue(param);
  331. if (null == value) {
  332. result = new String[0];
  333. } else {
  334. Map<String, Object> appMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
  335. result = Util.split(appMap, value, sep);
  336. }
  337. cachedListParams.put(param, result);
  338. }
  339.  
  340. return result;
  341. }
  342.  
  343.  
  344. /**
  345. * Obtain the value of the specified env-entry
  346. * @param entry the env-entry of interest
  347. * @return the value of the specified env-entry
  348. */
  349. public String getEnvironmentEntry(WebEnvironmentEntry entry) {
  350.  
  351. return envEntries.get(entry);
  352.  
  353. }
  354.  
  355.  
  356. /**
  357. * @param param the init parameter of interest
  358. * @return <code>true</code> if the parameter was explicitly set,
  359. * otherwise, <code>false</code>
  360. */
  361. public boolean isSet(WebContextInitParameter param) {
  362.  
  363. return isSet(param.getQualifiedName());
  364.  
  365. }
  366.  
  367.  
  368. /**
  369. * @param param the init parameter of interest
  370. * @return <code>true</code> if the parameter was explicitly set,
  371. * otherwise, <code>false</code>
  372. */
  373. public boolean isSet(BooleanWebContextInitParameter param) {
  374.  
  375. return isSet(param.getQualifiedName());
  376.  
  377. }
  378.  
  379.  
  380. /**
  381. * @return the name of this application
  382. */
  383. public String getServletContextName() {
  384.  
  385. if (servletContext.getMajorVersion() == 2
  386. && servletContext.getMinorVersion() <= 4) {
  387. return servletContext.getServletContextName();
  388. } else {
  389. return servletContext.getContextPath();
  390. }
  391.  
  392. }
  393.  
  394.  
  395. public void overrideContextInitParameter(BooleanWebContextInitParameter param, boolean value) {
  396.  
  397. if (param == null) {
  398. return;
  399. }
  400. boolean oldVal = booleanContextParameters.put(param, value);
  401. if (LOGGER.isLoggable(Level.FINE) && oldVal != value) {
  402. LOGGER.log(Level.FINE,
  403. "Overriding init parameter {0}. Changing from {1} to {2}.",
  404. new Object[] { param.getQualifiedName(), oldVal, value});
  405. }
  406.  
  407. }
  408.  
  409.  
  410. public void overrideContextInitParameter(WebContextInitParameter param, String value) {
  411.  
  412. if (param == null || value == null || value.length() == 0) {
  413. return;
  414. }
  415. value = value.trim();
  416. String oldVal = contextParameters.put(param, value);
  417. cachedListParams.remove(param);
  418. if (oldVal != null && LOGGER.isLoggable(Level.FINE) && !(oldVal.equals(value))) {
  419. LOGGER.log(Level.FINE,
  420. "Overriding init parameter {0}. Changing from {1} to {2}.",
  421. new Object[]{param.getQualifiedName(),
  422. oldVal,
  423. value});
  424. }
  425. }
  426.  
  427. public void doPostBringupActions() {
  428.  
  429. if (deferredLoggingActions != null) {
  430. for (DeferredLoggingAction loggingAction : deferredLoggingActions) {
  431. loggingAction.log();
  432. }
  433. }
  434.  
  435. // add the HttpMethodRestrictionPhaseListener if the parameter is enabled.
  436. boolean enabled = this.isOptionEnabled(BooleanWebContextInitParameter.EnableHttpMethodRestrictionPhaseListener);
  437. if (enabled) {
  438. LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
  439. Iterator<String> ids = factory.getLifecycleIds();
  440. PhaseListener listener = null;
  441. Lifecycle cur;
  442.  
  443. while (ids.hasNext()) {
  444. cur = factory.getLifecycle(ids.next());
  445. boolean foundExistingListenerInstance = false;
  446. for (PhaseListener curListener : cur.getPhaseListeners()) {
  447. if (curListener instanceof HttpMethodRestrictionsPhaseListener) {
  448. foundExistingListenerInstance = true;
  449. break;
  450. }
  451. }
  452. if (!foundExistingListenerInstance) {
  453. if (null == listener) {
  454. listener = new HttpMethodRestrictionsPhaseListener();
  455. }
  456. cur.addPhaseListener(listener);
  457. }
  458. }
  459. }
  460.  
  461. discoverResourceLibraryContracts();
  462.  
  463. }
  464.  
  465. private void discoverResourceLibraryContracts() {
  466. FacesContext context = FacesContext.getCurrentInstance();
  467. ExternalContext extContex = context.getExternalContext();
  468. Set<String> foundContracts = new HashSet<String>();
  469. Set<String> candidates;
  470.  
  471. // Scan for "contractMappings" in the web app root
  472. String contractsDirName = getOptionValue(WebContextInitParameter.WebAppContractsDirectory);
  473. assert(null != contractsDirName);
  474. candidates = extContex.getResourcePaths(contractsDirName);
  475. if (null != candidates) {
  476. int contractsDirNameLen = contractsDirName.length();
  477. int end;
  478. for (String cur : candidates) {
  479. end = cur.length();
  480. if (cur.endsWith("/")) {
  481. end--;
  482. }
  483. foundContracts.add(cur.substring(contractsDirNameLen + 1, end));
  484. }
  485. }
  486.  
  487. // Scan for "META-INF" contractMappings in the classpath
  488. try {
  489. URL[] candidateURLs = Classpath.search(Util.getCurrentLoader(this),
  490. META_INF_CONTRACTS_DIR,
  491. RESOURCE_CONTRACT_SUFFIX,
  492. Classpath.SearchAdvice.AllMatches);
  493. for (URL curURL : candidateURLs) {
  494. String cur = curURL.toExternalForm();
  495.  
  496. int i = cur.indexOf(META_INF_CONTRACTS_DIR) + META_INF_CONTRACTS_DIR_LEN + 1;
  497. int j = cur.indexOf(RESOURCE_CONTRACT_SUFFIX);
  498. if (i < j) {
  499. foundContracts.add(cur.substring(i,j));
  500. }
  501.  
  502. }
  503. } catch (IOException ioe) {
  504. if (LOGGER.isLoggable(Level.FINEST)) {
  505. LOGGER.log(Level.FINEST, "Unable to scan " + META_INF_CONTRACTS_DIR, ioe);
  506. }
  507. }
  508.  
  509.  
  510. if (foundContracts.isEmpty()) {
  511. return;
  512. }
  513.  
  514. Map<String, List<String>> contractMappings = new HashMap<String, List<String>>();
  515.  
  516. ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
  517. Map<String, List<String>> contractsFromConfig = associate.getResourceLibraryContracts();
  518. List<String> contractsToExpose;
  519.  
  520. if (null != contractsFromConfig && !contractsFromConfig.isEmpty()) {
  521. List<String> contractsFromMapping;
  522. for (Map.Entry<String, List<String>> cur : contractsFromConfig.entrySet()) {
  523. // Verify that the contractsToExpose in this mapping actually exist
  524. // in the application. If not, log a message.
  525. contractsFromMapping = cur.getValue();
  526. if (null == contractsFromMapping || contractsFromMapping.isEmpty()) {
  527. if (LOGGER.isLoggable(Level.CONFIG)) {
  528. LOGGER.log(Level.CONFIG, "resource library contract mapping for pattern {0} has no contracts.", cur.getKey());
  529. }
  530. } else {
  531. contractsToExpose = new ArrayList<String>();
  532. for (String curContractFromMapping : contractsFromMapping) {
  533. if (foundContracts.contains(curContractFromMapping)) {
  534. contractsToExpose.add(curContractFromMapping);
  535. } else {
  536. if (LOGGER.isLoggable(Level.CONFIG)) {
  537. LOGGER.log(Level.CONFIG, "resource library contract mapping for pattern {0} exposes contract {1}, but that contract is not available to the application.",
  538. new String [] { cur.getKey(), curContractFromMapping });
  539. }
  540. }
  541. }
  542. if (!contractsToExpose.isEmpty()) {
  543. contractMappings.put(cur.getKey(), contractsToExpose);
  544. }
  545. }
  546. }
  547. } else {
  548. contractsToExpose = new ArrayList<String>();
  549. contractsToExpose.addAll(foundContracts);
  550. contractMappings.put("*", contractsToExpose);
  551. }
  552. extContex.getApplicationMap().put(FaceletViewHandlingStrategy.RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE_KEY,
  553. contractMappings);
  554.  
  555. }
  556.  
  557. /**
  558. * To inlcude the facelets suffix into the supported suffixes.
  559. *
  560. * @return merged suffixes including both default suffixes and the facelet suffixes.
  561. */
  562. public String[] getConfiguredExtensions() {
  563. String[] defaultSuffix = getOptionValue(WebContextInitParameter.DefaultSuffix, " ");
  564. String[] faceletsSuffix = getOptionValue(WebContextInitParameter.FaceletsSuffix, " ");
  565.  
  566. List<String> mergedList = new ArrayList<String>(Arrays.asList(defaultSuffix));
  567. mergedList.addAll(Arrays.asList(faceletsSuffix));
  568.  
  569. return mergedList.toArray(new String[0]);
  570. }
  571.  
  572.  
  573. // ------------------------------------------------- Package Private Methods
  574.  
  575.  
  576. static void clear(ServletContext servletContext) {
  577.  
  578. servletContext.removeAttribute(WEB_CONFIG_KEY);
  579.  
  580. }
  581.  
  582.  
  583. // --------------------------------------------------------- Private Methods
  584.  
  585.  
  586. /**
  587. * <p>Is the configured value valid against the default boolean pattern.</p>
  588. * @param param the boolean parameter
  589. * @param value the configured value
  590. * @return <code>true</code> if the value is valid,
  591. * otherwise <code>false</code>
  592. */
  593. private boolean isValueValid(BooleanWebContextInitParameter param,
  594. String value) {
  595.  
  596. if (!ALLOWABLE_BOOLEANS.matcher(value).matches()) {
  597. if (LOGGER.isLoggable(Level.WARNING)) {
  598. LOGGER.log(Level.WARNING,
  599. "jsf.config.webconfig.boolconfig.invalidvalue",
  600. new Object[]{
  601. value,
  602. param.getQualifiedName(),
  603. "true|false",
  604. "true|false",
  605. param.getDefaultValue()
  606. });
  607. }
  608. return false;
  609. }
  610.  
  611. return true;
  612.  
  613. }
  614.  
  615.  
  616. /**
  617. * <p>Process all boolean context initialization parameters.</p>
  618. * @param servletContext the ServletContext of interest
  619. * @param contextName the context name
  620. */
  621. private void processBooleanParameters(ServletContext servletContext,
  622. String contextName) {
  623.  
  624. // process boolean contxt parameters
  625. for (BooleanWebContextInitParameter param : BooleanWebContextInitParameter
  626. .values()) {
  627. String strValue =
  628. servletContext.getInitParameter(param.getQualifiedName());
  629. boolean value;
  630.  
  631. if (strValue != null && strValue.length() > 0 && param.isDeprecated()) {
  632. BooleanWebContextInitParameter alternate = param.getAlternate();
  633. if (LOGGER.isLoggable(Level.WARNING)) {
  634. if (alternate != null) {
  635. queueLoggingAction(new DeferredBooleanParameterLoggingAction(
  636. param,
  637. Level.WARNING,
  638. "jsf.config.webconfig.param.deprecated",
  639. new Object[]{
  640. contextName,
  641. param.getQualifiedName(),
  642. alternate.getQualifiedName()}));
  643.  
  644. } else {
  645. queueLoggingAction(new DeferredBooleanParameterLoggingAction(
  646. param,
  647. Level.WARNING,
  648. "jsf.config.webconfig.param.deprecated.no_replacement",
  649. new Object[]{
  650. contextName,
  651. param.getQualifiedName()}));
  652.  
  653. }
  654. }
  655.  
  656. if (alternate != null) {
  657. if (isValueValid(param, strValue)) {
  658. value = Boolean.valueOf(strValue);
  659. } else {
  660. value = param.getDefaultValue();
  661. }
  662.  
  663. if (LOGGER.isLoggable(Level.INFO) && alternate != null) {
  664. queueLoggingAction(new DeferredBooleanParameterLoggingAction(
  665. param,
  666. Level.INFO,
  667. ((value)
  668. ? "jsf.config.webconfig.configinfo.reset.enabled"
  669. : "jsf.config.webconfig.configinfo.reset.disabled"),
  670. new Object[]{
  671. contextName,
  672. alternate.getQualifiedName()}));
  673. }
  674.  
  675. booleanContextParameters.put(alternate, value);
  676. }
  677. continue;
  678. }
  679.  
  680. if (!param.isDeprecated()) {
  681. if (strValue == null) {
  682. value = param.getDefaultValue();
  683. } else {
  684. if (isValueValid(param, strValue)) {
  685. value = Boolean.valueOf(strValue);
  686. } else {
  687. value = param.getDefaultValue();
  688. }
  689. }
  690.  
  691. // first param processed should be
  692. // com.sun.faces.displayConfiguration
  693. if (BooleanWebContextInitParameter.DisplayConfiguration.equals(param) && value) {
  694. loggingLevel = Level.INFO;
  695. }
  696.  
  697. if (LOGGER.isLoggable(loggingLevel)) {
  698. LOGGER.log(loggingLevel,
  699. ((value)
  700. ? "jsf.config.webconfig.boolconfiginfo.enabled"
  701. : "jsf.config.webconfig.boolconfiginfo.disabled"),
  702. new Object[]{contextName,
  703. param.getQualifiedName()});
  704. }
  705.  
  706. booleanContextParameters.put(param, value);
  707. }
  708.  
  709. }
  710.  
  711. }
  712.  
  713.  
  714. /**
  715. * Adds all com.sun.faces init parameter names to a list. This allows
  716. * callers to determine if a parameter was explicitly set.
  717. * @param servletContext the ServletContext of interest
  718. */
  719. private void initSetList(ServletContext servletContext) {
  720.  
  721. for (Enumeration e = servletContext.getInitParameterNames();
  722. e.hasMoreElements(); ) {
  723. String name = e.nextElement().toString();
  724. if (name.startsWith("com.sun.faces") ||
  725. name.startsWith("javax.faces")) {
  726. setParams.add(name);
  727. }
  728. }
  729.  
  730. }
  731.  
  732.  
  733. /**
  734. * @param name the param name
  735. * @return <code>true</code> if the name was explicitly specified
  736. */
  737. private boolean isSet(String name) {
  738.  
  739. return setParams.contains(name);
  740.  
  741. }
  742.  
  743.  
  744. /**
  745. * <p>Process all non-boolean context initialization parameters.</p>
  746. * @param servletContext the ServletContext of interest
  747. * @param contextName the context name
  748. */
  749. private void processInitParameters(ServletContext servletContext,
  750. String contextName) {
  751.  
  752. for (WebContextInitParameter param : WebContextInitParameter.values()) {
  753. String value =
  754. servletContext.getInitParameter(param.getQualifiedName());
  755.  
  756. if (value != null && value.length() > 0 && param.isDeprecated()) {
  757. WebContextInitParameter alternate = param.getAlternate();
  758. DeprecationLoggingStrategy strategy = param.getDeprecationLoggingStrategy();
  759. if (strategy == null || strategy.shouldBeLogged(this)) {
  760. if (LOGGER.isLoggable(Level.WARNING)) {
  761. if (alternate != null) {
  762. queueLoggingAction(new DeferredParameterLoggingAction(param, Level.WARNING,
  763. "jsf.config.webconfig.param.deprecated",
  764. new Object[]{
  765. contextName,
  766. param.getQualifiedName(),
  767. alternate.getQualifiedName()}));
  768.  
  769. } else {
  770. queueLoggingAction(new DeferredParameterLoggingAction(
  771. param,
  772. Level.WARNING,
  773. "jsf.config.webconfig.param.deprecated.no_replacement",
  774. new Object[]{
  775. contextName,
  776. param.getQualifiedName()}));
  777. }
  778. }
  779. }
  780.  
  781. if (alternate != null) {
  782. queueLoggingAction(
  783. new DeferredParameterLoggingAction(param,
  784. Level.INFO,
  785. "jsf.config.webconfig.configinfo.reset",
  786. new Object[]{
  787. contextName,
  788. alternate.getQualifiedName(),
  789. value}));
  790.  
  791. contextParameters.put(alternate, value);
  792. }
  793. continue;
  794. }
  795.  
  796. if ((value == null || value.length() == 0) && !param.isDeprecated()) {
  797. value = param.getDefaultValue();
  798. }
  799. if (value == null || value.length() == 0) {
  800. continue;
  801. }
  802.  
  803. if (value.length() > 0) {
  804. if (LOGGER.isLoggable(loggingLevel)) {
  805. LOGGER.log(loggingLevel,
  806. "jsf.config.webconfig.configinfo",
  807. new Object[]{contextName,
  808. param.getQualifiedName(),
  809. value});
  810.  
  811. }
  812. contextParameters.put(param, value);
  813. } else {
  814. if (LOGGER.isLoggable(loggingLevel)) {
  815. LOGGER.log(loggingLevel,
  816. "jsf.config.webconfig.option.notconfigured",
  817. new Object[]{contextName,
  818. param.getQualifiedName()});
  819. }
  820. }
  821.  
  822. }
  823.  
  824. }
  825.  
  826.  
  827. /**
  828. * <p>Process all JNDI entries.</p>
  829. * @param contextName the context name
  830. */
  831. private void processJndiEntries(String contextName) {
  832.  
  833. /* Incompatibility with GAE
  834.  
  835. Context initialContext = null;
  836. try {
  837. initialContext = new InitialContext();
  838. } catch (NoClassDefFoundError nde) {
  839. // on google app engine InitialContext is forbidden to use and GAE throws NoClassDefFoundError
  840. if (LOGGER.isLoggable(Level.FINE)) {
  841. LOGGER.log(Level.FINE, nde.toString(), nde);
  842. }
  843. } catch (NamingException ne) {
  844. if (LOGGER.isLoggable(Level.WARNING)) {
  845. LOGGER.log(Level.WARNING, ne.toString(), ne);
  846. }
  847. }
  848.  
  849. if (initialContext != null) {
  850. // process environment entries
  851. for (WebEnvironmentEntry entry : WebEnvironmentEntry.values()) {
  852. String entryName = entry.getQualifiedName();
  853. String value = null;
  854.  
  855. try {
  856. value = (String) initialContext.lookup(entryName);
  857. } catch (NamingException root) {
  858. if (LOGGER.isLoggable(Level.FINE)) {
  859. LOGGER.fine(root.toString());
  860. }
  861. }
  862.  
  863. if (value != null) {
  864. if (LOGGER.isLoggable(Level.INFO)) {
  865. if (LOGGER
  866. .isLoggable(loggingLevel)) {
  867. LOGGER.log(loggingLevel,
  868. "jsf.config.webconfig.enventryinfo",
  869. new Object[]{contextName,
  870. entryName,
  871. value});
  872. }
  873. }
  874. envEntries.put(entry, value);
  875. }
  876. }
  877. BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance());
  878. if (null != beanManager) {
  879. Util.setCDIAvailable(servletContext, beanManager);
  880. }
  881. }*/
  882.  
  883. }
  884.  
  885.  
  886. public boolean canProcessJndiEntries() {
  887.  
  888. /* Incompatibility with GAE
  889.  
  890. try {
  891. Util.getCurrentLoader(this).loadClass("javax.naming.InitialContext");
  892. } catch (Exception e) {
  893. if (LOGGER.isLoggable(Level.FINE)) {
  894. LOGGER.fine(
  895. "javax.naming is unavailable. JNDI entries related to Mojarra configuration will not be processed.");
  896. }
  897. return false;
  898. }
  899. return true;*/
  900.  
  901. if (LOGGER.isLoggable(Level.FINE)) {
  902. LOGGER.fine(
  903. "javax.naming is unavailable. JNDI entries related to Mojarra configuration will not be processed.");
  904. }
  905. return false;
  906.  
  907. }
  908.  
  909.  
  910. private void queueLoggingAction(DeferredLoggingAction loggingAction) {
  911.  
  912. if (deferredLoggingActions == null) {
  913. deferredLoggingActions = new ArrayList<DeferredLoggingAction>();
  914. }
  915. deferredLoggingActions.add(loggingAction);
  916.  
  917. }
  918.  
  919.  
  920. // ------------------------------------------------------------------- Enums
  921.  
  922.  
  923. /**
  924. * <p>An <code>enum</code> of all non-boolean context initalization parameters
  925. * recognized by the implementation.</p>
  926. */
  927. public enum WebContextInitParameter {
  928.  
  929.  
  930. // implementation note:
  931. // if a parameter is to be deprecated,
  932. // then the <name>Deprecated enum element
  933. // *must* appear after the one that is taking
  934. // its place. The reporting logic depends on this
  935.  
  936. ManagedBeanFactoryDecorator(
  937. "com.sun.faces.managedBeanFactoryDecoratorClass",
  938. ""
  939. ),
  940. StateSavingMethod(
  941. StateManager.STATE_SAVING_METHOD_PARAM_NAME,
  942. "server"
  943. ),
  944. FaceletsSuffix(
  945. ViewHandler.FACELETS_SUFFIX_PARAM_NAME,
  946. ViewHandler.DEFAULT_FACELETS_SUFFIX
  947. ),
  948. DefaultSuffix(
  949. ViewHandler.DEFAULT_SUFFIX_PARAM_NAME,
  950. ViewHandler.DEFAULT_SUFFIX
  951. ),
  952. JavaxFacesConfigFiles(
  953. FacesServlet.CONFIG_FILES_ATTR,
  954. ""
  955. ),
  956. JavaxFacesProjectStage(
  957. ProjectStage.PROJECT_STAGE_PARAM_NAME,
  958. "Production"
  959. ),
  960. AlternateLifecycleId(
  961. FacesServlet.LIFECYCLE_ID_ATTR,
  962. ""
  963. ),
  964. ResourceExcludes(
  965. ResourceHandler.RESOURCE_EXCLUDES_PARAM_NAME,
  966. ResourceHandler.RESOURCE_EXCLUDES_DEFAULT_VALUE + " .groovy"
  967. ),
  968. NumberOfViews(
  969. "com.sun.faces.numberOfViewsInSession",
  970. "15"
  971. ),
  972. NumberOfViewsDeprecated(
  973. "com.sun.faces.NUMBER_OF_VIEWS_IN_SESSION",
  974. "15",
  975. true,
  976. NumberOfViews
  977. ),
  978. NumberOfLogicalViews(
  979. "com.sun.faces.numberOfLogicalViews",
  980. "15"
  981. ),
  982. NumberOfLogicalViewsDeprecated(
  983. "com.sun.faces.NUMBER_OF_VIEWS_IN_LOGICAL_VIEW_IN_SESSION",
  984. "15",
  985. true,
  986. NumberOfLogicalViews
  987. ),
  988. NumberOfConcurrentFlashUsers(
  989. "com.sun.faces.numberOfConcerrentFlashUsers",
  990. "5000"
  991. ),
  992. NumberOfFlashesBetweenFlashReapings(
  993. "com.sun.faces.numberOfFlashesBetweenFlashReapings",
  994. "5000"
  995. ),
  996. InjectionProviderClass(
  997. "com.sun.faces.injectionProvider",
  998. ""
  999. ),
  1000. SerializationProviderClass(
  1001. "com.sun.faces.serializationProvider",
  1002. ""
  1003. ),
  1004. ResponseBufferSize(
  1005. "com.sun.faces.responseBufferSize",
  1006. "1024"
  1007. ),
  1008. FaceletsBufferSize(
  1009. ViewHandler.FACELETS_BUFFER_SIZE_PARAM_NAME,
  1010. "1024"
  1011. ),
  1012. FaceletsBufferSizeDeprecated(
  1013. "facelets.BUFFER_SIZE",
  1014. "1024",
  1015. true,
  1016. FaceletsBufferSize,
  1017. new FaceletsConfigParamLoggingStrategy()
  1018. ),
  1019. ClientStateWriteBufferSize(
  1020. "com.sun.faces.clientStateWriteBufferSize",
  1021. "8192"
  1022. ),
  1023. ResourceBufferSize(
  1024. "com.sun.faces.resourceBufferSize",
  1025. "2048"
  1026. ),
  1027. ExpressionFactory(
  1028. "com.sun.faces.expressionFactory",
  1029. "com.sun.el.ExpressionFactoryImpl"
  1030. ),
  1031. ClientStateTimeout(
  1032. "com.sun.faces.clientStateTimeout",
  1033. ""
  1034. ),
  1035. DefaultResourceMaxAge(
  1036. "com.sun.faces.defaultResourceMaxAge",
  1037. "604800000" // 7 days
  1038. ),
  1039. ResourceUpdateCheckPeriod(
  1040. "com.sun.faces.resourceUpdateCheckPeriod",
  1041. "5" // in minutes
  1042. ),
  1043. CompressableMimeTypes(
  1044. "com.sun.faces.compressableMimeTypes",
  1045. ""
  1046. ),
  1047. DisableUnicodeEscaping(
  1048. "com.sun.faces.disableUnicodeEscaping",
  1049. "auto"
  1050. ),
  1051. FaceletsDefaultRefreshPeriod(
  1052. ViewHandler.FACELETS_REFRESH_PERIOD_PARAM_NAME,
  1053. "2"
  1054. ),
  1055. FaceletsDefaultRefreshPeriodDeprecated(
  1056. "facelets.REFRESH_PERIOD",
  1057. "2",
  1058. true,
  1059. FaceletsDefaultRefreshPeriod,
  1060. new FaceletsConfigParamLoggingStrategy()
  1061. ),
  1062. FaceletsResourceResolver(
  1063. ResourceResolver.FACELETS_RESOURCE_RESOLVER_PARAM_NAME,
  1064. ""
  1065. ),
  1066. FaceletsResourceResolverDeprecated(
  1067. "facelets.RESOURCE_RESOLVER",
  1068. "",
  1069. true,
  1070. FaceletsResourceResolver,
  1071. new FaceletsConfigParamLoggingStrategy()
  1072. ),
  1073. FaceletsViewMappings(
  1074. ViewHandler.FACELETS_VIEW_MAPPINGS_PARAM_NAME,
  1075. ""
  1076. ),
  1077. FaceletsViewMappingsDeprecated(
  1078. "facelets.VIEW_MAPPINGS",
  1079. "",
  1080. true,
  1081. FaceletsViewMappings,
  1082. new FaceletsConfigParamLoggingStrategy()
  1083. ),
  1084. FaceletsLibraries(
  1085. ViewHandler.FACELETS_LIBRARIES_PARAM_NAME,
  1086. ""
  1087. ),
  1088. FaceletsLibrariesDeprecated(
  1089. "facelets.LIBRARIES",
  1090. "",
  1091. true,
  1092. FaceletsLibraries,
  1093. new FaceletsConfigParamLoggingStrategy()
  1094. ),
  1095. FaceletsDecorators(
  1096. ViewHandler.FACELETS_DECORATORS_PARAM_NAME,
  1097. ""
  1098. ),
  1099. FaceletsDecoratorsDeprecated(
  1100. "facelets.DECORATORS",
  1101. "",
  1102. true,
  1103. FaceletsDecorators,
  1104. new FaceletsConfigParamLoggingStrategy()
  1105. ),
  1106. DuplicateJARPattern(
  1107. "com.sun.faces.duplicateJARPattern",
  1108. ""
  1109. ),
  1110. ValidateEmptyFields(
  1111. UIInput.VALIDATE_EMPTY_FIELDS_PARAM_NAME,
  1112. "auto"
  1113. ),
  1114. FullStateSavingViewIds(
  1115. StateManager.FULL_STATE_SAVING_VIEW_IDS_PARAM_NAME,
  1116. ""
  1117. ),
  1118. AnnotationScanPackages(
  1119. "com.sun.faces.annotationScanPackages",
  1120. ""
  1121. ),
  1122. FaceletCache(
  1123. "com.sun.faces.faceletCache",
  1124. ""
  1125. ),
  1126. FaceletsProcessingFileExtensionProcessAs(
  1127. "",
  1128. ""
  1129. ),
  1130. ClientWindowMode(
  1131. ClientWindow.CLIENT_WINDOW_MODE_PARAM_NAME,
  1132. "none"
  1133. ),
  1134. WebAppResourcesDirectory(
  1135. ResourceHandler.WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME,
  1136. "/resources"
  1137. ),
  1138. WebAppContractsDirectory(
  1139. ResourceHandler.WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME,
  1140. "/contracts"
  1141. );
  1142.  
  1143.  
  1144.  
  1145. private String defaultValue;
  1146. private String qualifiedName;
  1147. private WebContextInitParameter alternate;
  1148. private boolean deprecated;
  1149. private DeprecationLoggingStrategy loggingStrategy;
  1150.  
  1151.  
  1152. // ---------------------------------------------------------- Public Methods
  1153.  
  1154.  
  1155. public String getDefaultValue() {
  1156.  
  1157. return defaultValue;
  1158.  
  1159. }
  1160.  
  1161.  
  1162. public String getQualifiedName() {
  1163.  
  1164. return qualifiedName;
  1165.  
  1166. }
  1167.  
  1168.  
  1169. DeprecationLoggingStrategy getDeprecationLoggingStrategy() {
  1170.  
  1171. return loggingStrategy;
  1172.  
  1173. }
  1174.  
  1175.  
  1176. // ------------------------------------------------- Package Private Methods
  1177.  
  1178.  
  1179. WebContextInitParameter(String qualifiedName,
  1180. String defaultValue) {
  1181.  
  1182. this(qualifiedName, defaultValue, false, null);
  1183.  
  1184. }
  1185.  
  1186.  
  1187. WebContextInitParameter(String qualifiedName,
  1188. String defaultValue,
  1189. boolean deprecated,
  1190. WebContextInitParameter alternate) {
  1191.  
  1192. this.qualifiedName = qualifiedName;
  1193. this.defaultValue = defaultValue;
  1194. this.deprecated = deprecated;
  1195. this.alternate = alternate;
  1196.  
  1197. }
  1198.  
  1199.  
  1200. WebContextInitParameter(String qualifiedName,
  1201. String defaultValue,
  1202. boolean deprecated,
  1203. WebContextInitParameter alternate,
  1204. DeprecationLoggingStrategy loggingStrategy) {
  1205.  
  1206. this(qualifiedName, defaultValue, deprecated, alternate);
  1207. this.loggingStrategy = loggingStrategy;
  1208.  
  1209. }
  1210.  
  1211.  
  1212. // --------------------------------------------------------- Private Methods
  1213.  
  1214.  
  1215. private WebContextInitParameter getAlternate() {
  1216.  
  1217. return alternate;
  1218.  
  1219. }
  1220.  
  1221.  
  1222. private boolean isDeprecated() {
  1223.  
  1224. return deprecated;
  1225.  
  1226. }
  1227.  
  1228. }
  1229.  
  1230. /**
  1231. * <p>An <code>enum</code> of all boolean context initalization parameters
  1232. * recognized by the implementation.</p>
  1233. */
  1234. public enum BooleanWebContextInitParameter {
  1235.  
  1236.  
  1237. // implementation note:
  1238. // if a parameter is to be deprecated,
  1239. // then the <name>Deprecated enum element
  1240. // *must* appear after the one that is taking
  1241. // its place. The reporting logic depends on this
  1242.  
  1243. DisplayConfiguration(
  1244. "com.sun.faces.displayConfiguration",
  1245. false
  1246. ),
  1247. ValidateFacesConfigFiles(
  1248. "com.sun.faces.validateXml",
  1249. false
  1250. ),
  1251. VerifyFacesConfigObjects(
  1252. "com.sun.faces.verifyObjects",
  1253. false
  1254. ),
  1255. ForceLoadFacesConfigFiles(
  1256. "com.sun.faces.forceLoadConfiguration",
  1257. false
  1258. ),
  1259. DisableArtifactVersioning(
  1260. "com.sun.faces.disableVersionTracking",
  1261. false,
  1262. true,
  1263. null
  1264. ),
  1265. DisableClientStateEncryption(
  1266. "com.sun.faces.disableClientStateEncryption",
  1267. false
  1268. ),
  1269. EnableClientStateDebugging(
  1270. "com.sun.faces.enableClientStateDebugging",
  1271. false
  1272. ),
  1273. EnableHtmlTagLibraryValidator(
  1274. "com.sun.faces.enableHtmlTagLibValidator",
  1275. false
  1276. ),
  1277. EnableCoreTagLibraryValidator(
  1278. "com.sun.faces.enableCoreTagLibValidator",
  1279. false
  1280. ),
  1281. PreferXHTMLContentType(
  1282. "com.sun.faces.preferXHTML",
  1283. false
  1284. ),
  1285. PreferXHTMLContextTypeDeprecated(
  1286. "com.sun.faces.PreferXHTML",
  1287. false,
  1288. true,
  1289. PreferXHTMLContentType
  1290. ),
  1291. CompressViewState(
  1292. "com.sun.faces.compressViewState",
  1293. true
  1294. ),
  1295. CompressViewStateDeprecated(
  1296. "com.sun.faces.COMPRESS_STATE",
  1297. true,
  1298. true,
  1299. CompressViewState
  1300. ),
  1301. CompressJavaScript(
  1302. "com.sun.faces.compressJavaScript",
  1303. true
  1304. ),
  1305. ExternalizeJavaScriptDeprecated(
  1306. "com.sun.faces.externalizeJavaScript",
  1307. true,
  1308. true,
  1309. null
  1310. ),
  1311. SendPoweredByHeader(
  1312. "com.sun.faces.sendPoweredByHeader",
  1313. false
  1314. ),
  1315. EnableJSStyleHiding(
  1316. "com.sun.faces.enableJSStyleHiding",
  1317. false
  1318. ),
  1319. EnableScriptInAttributeValue(
  1320. "com.sun.faces.enableScriptsInAttributeValues",
  1321. true
  1322. ),
  1323. WriteStateAtFormEnd(
  1324. "com.sun.faces.writeStateAtFormEnd",
  1325. true
  1326. ),
  1327. EnableLazyBeanValidation(
  1328. "com.sun.faces.enableLazyBeanValidation",
  1329. true
  1330. ),
  1331. EnableLoadBundle11Compatibility(
  1332. "com.sun.faces.enabledLoadBundle11Compatibility",
  1333. false
  1334. ),
  1335. EnableRestoreView11Compatibility(
  1336. "com.sun.faces.enableRestoreView11Compatibility",
  1337. false
  1338. ),
  1339. SerializeServerState(
  1340. StateManager.SERIALIZE_SERVER_STATE_PARAM_NAME,
  1341. false
  1342. ),
  1343. SerializeServerStateDeprecated(
  1344. "com.sun.faces.serializeServerState",
  1345. false,
  1346. true,
  1347. SerializeServerState
  1348. ),
  1349. EnableViewStateIdRendering(
  1350. "com.sun.faces.enableViewStateIdRendering",
  1351. true
  1352. ),
  1353. RegisterConverterPropertyEditors(
  1354. "com.sun.faces.registerConverterPropertyEditors",
  1355. false
  1356. ),
  1357. EnableGroovyScripting(
  1358. "com.sun.faces.enableGroovyScripting",
  1359. false
  1360. ),
  1361. DisableFaceletJSFViewHandler(
  1362. ViewHandler.DISABLE_FACELET_JSF_VIEWHANDLER_PARAM_NAME,
  1363. false
  1364. ),
  1365. DisableDefaultBeanValidator(
  1366. BeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME,
  1367. false),
  1368. DateTimeConverterUsesSystemTimezone(
  1369. Converter.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME,
  1370. false
  1371. ),
  1372. EnableHttpMethodRestrictionPhaseListener(
  1373. "com.sun.faces.ENABLE_HTTP_METHOD_RESTRICTION_PHASE_LISTENER",
  1374. false
  1375. ),
  1376. FaceletsSkipComments(
  1377. ViewHandler.FACELETS_SKIP_COMMENTS_PARAM_NAME,
  1378. false
  1379. ),
  1380. FaceletsSkipCommentsDeprecated(
  1381. "facelets.SKIP_COMMENTS",
  1382. false,
  1383. true,
  1384. FaceletsSkipComments,
  1385. new FaceletsConfigParamLoggingStrategy()
  1386. ),
  1387. PartialStateSaving(
  1388. StateManager.PARTIAL_STATE_SAVING_PARAM_NAME,
  1389. true
  1390. ),
  1391. GenerateUniqueServerStateIds(
  1392. "com.sun.faces.generateUniqueServerStateIds",
  1393. true
  1394. ),
  1395. AutoCompleteOffOnViewState(
  1396. "com.sun.faces.autoCompleteOffOnViewState",
  1397. true
  1398. ),
  1399. EnableThreading(
  1400. "com.sun.faces.enableThreading",
  1401. false
  1402. ),
  1403. AllowTextChildren(
  1404. "com.sun.faces.allowTextChildren",
  1405. false
  1406. ),
  1407. CacheResourceModificationTimestamp(
  1408. "com.sun.faces.cacheResourceModificationTimestamp",
  1409. false
  1410. ),
  1411. EnableAgressiveSessionDirtying(
  1412. "com.sun.faces.enableAgressiveSessionDirtying",
  1413. false
  1414. ),
  1415. EnableDistributable(
  1416. "com.sun.faces.enableDistributable",
  1417. false
  1418. ),
  1419. EnableFaceletsResourceResolverResolveCompositeComponents(
  1420. "com.sun.faces.enableFaceletsResourceResolverCompositeComponents",
  1421. false
  1422. ),
  1423. EnableMissingResourceLibraryDetection(
  1424. "com.sun.faces.enableMissingResourceLibraryDetection",
  1425. false
  1426. ),
  1427. DisableIdUniquenessCheck(
  1428. "com.sun.faces.disableIdUniquenessCheck",
  1429. false),
  1430. EnableTransitionTimeNoOpFlash(
  1431. "com.sun.faces.enableTransitionTimeNoOpFlash",
  1432. false),
  1433. NamespaceParameters(
  1434. "com.sun.faces.namespaceParameters",
  1435. false),
  1436. ForceAlwaysWriteFlashCookie(
  1437. "com.sun.faces.forceAlwaysWriteFlashCookie",
  1438. false);
  1439.  
  1440. private BooleanWebContextInitParameter alternate;
  1441.  
  1442. private String qualifiedName;
  1443. private boolean defaultValue;
  1444. private boolean deprecated;
  1445. private DeprecationLoggingStrategy loggingStrategy;
  1446.  
  1447.  
  1448. // ---------------------------------------------------------- Public Methods
  1449.  
  1450.  
  1451. public boolean getDefaultValue() {
  1452.  
  1453. return defaultValue;
  1454.  
  1455. }
  1456.  
  1457.  
  1458. public String getQualifiedName() {
  1459.  
  1460. return qualifiedName;
  1461.  
  1462. }
  1463.  
  1464.  
  1465. DeprecationLoggingStrategy getDeprecationLoggingStrategy() {
  1466.  
  1467. return loggingStrategy;
  1468.  
  1469. }
  1470.  
  1471.  
  1472. // ------------------------------------------------- Package Private Methods
  1473.  
  1474.  
  1475. BooleanWebContextInitParameter(String qualifiedName,
  1476. boolean defaultValue) {
  1477.  
  1478. this(qualifiedName, defaultValue, false, null);
  1479.  
  1480. }
  1481.  
  1482.  
  1483. BooleanWebContextInitParameter(String qualifiedName,
  1484. boolean defaultValue,
  1485. boolean deprecated,
  1486. BooleanWebContextInitParameter alternate) {
  1487.  
  1488. this.qualifiedName = qualifiedName;
  1489. this.defaultValue = defaultValue;
  1490. this.deprecated = deprecated;
  1491. this.alternate = alternate;
  1492.  
  1493. }
  1494.  
  1495.  
  1496. BooleanWebContextInitParameter(String qualifiedName,
  1497. boolean defaultValue,
  1498. boolean deprecated,
  1499. BooleanWebContextInitParameter alternate,
  1500. DeprecationLoggingStrategy loggingStrategy) {
  1501.  
  1502. this(qualifiedName, defaultValue, deprecated, alternate);
  1503. this.loggingStrategy = loggingStrategy;
  1504.  
  1505. }
  1506.  
  1507.  
  1508. // --------------------------------------------------------- Private Methods
  1509.  
  1510.  
  1511. private BooleanWebContextInitParameter getAlternate() {
  1512.  
  1513. return alternate;
  1514.  
  1515. }
  1516.  
  1517.  
  1518. private boolean isDeprecated() {
  1519.  
  1520. return deprecated;
  1521.  
  1522. }
  1523.  
  1524. }
  1525.  
  1526. /**
  1527. * <p>An <code>enum</code> of all environment entries (specified in the
  1528. * web.xml) recognized by the implemenetation.</p>
  1529. */
  1530. public enum WebEnvironmentEntry {
  1531.  
  1532.  
  1533. ProjectStage(javax.faces.application.ProjectStage.PROJECT_STAGE_JNDI_NAME);
  1534.  
  1535. private static final String JNDI_PREFIX = "java:comp/env/";
  1536. private String qualifiedName;
  1537.  
  1538.  
  1539. // ---------------------------------------------------------- Public Methods
  1540.  
  1541.  
  1542. public String getQualifiedName() {
  1543.  
  1544. return qualifiedName;
  1545.  
  1546. }
  1547.  
  1548.  
  1549. // ------------------------------------------------- Package Private Methods
  1550.  
  1551.  
  1552. WebEnvironmentEntry(String qualifiedName) {
  1553.  
  1554. if (qualifiedName.startsWith(JNDI_PREFIX)) {
  1555. this.qualifiedName = qualifiedName;
  1556. } else {
  1557. this.qualifiedName = JNDI_PREFIX + qualifiedName;
  1558. }
  1559.  
  1560. }
  1561.  
  1562. }
  1563.  
  1564. /**
  1565. * <p>An <code>enum</code> of all possible values for the <code>disableUnicodeEscaping</code>
  1566. * configuration parameter.</p>
  1567. */
  1568. public enum DisableUnicodeEscaping {
  1569. True("true"),
  1570. False("false"),
  1571. Auto("auto");
  1572.  
  1573. private final String value;
  1574.  
  1575. DisableUnicodeEscaping(String value) {
  1576. this.value = value;
  1577. }
  1578.  
  1579. public static DisableUnicodeEscaping getByValue(String value)
  1580. {
  1581. for (DisableUnicodeEscaping disableUnicodeEscaping : DisableUnicodeEscaping.values()) {
  1582. if (disableUnicodeEscaping.value.equals(value)) {
  1583. return disableUnicodeEscaping;
  1584. }
  1585. }
  1586.  
  1587. return null;
  1588. }
  1589. }
  1590.  
  1591.  
  1592. // ----------------------------------------------------------- Inner Classes
  1593.  
  1594.  
  1595. private interface DeprecationLoggingStrategy {
  1596.  
  1597. boolean shouldBeLogged(WebConfiguration configuration);
  1598.  
  1599. }
  1600.  
  1601.  
  1602. private static class FaceletsConfigParamLoggingStrategy implements DeprecationLoggingStrategy {
  1603.  
  1604. public boolean shouldBeLogged(WebConfiguration configuration) {
  1605. return !configuration.isOptionEnabled(BooleanWebContextInitParameter.DisableFaceletJSFViewHandler);
  1606. }
  1607.  
  1608. } // END FaceletsConfigParamLoggingStrategy
  1609.  
  1610.  
  1611. private interface DeferredLoggingAction {
  1612.  
  1613. void log();
  1614.  
  1615. } // END DeferredLogginAction
  1616.  
  1617.  
  1618. private class DeferredParameterLoggingAction implements DeferredLoggingAction {
  1619.  
  1620. private WebContextInitParameter parameter;
  1621. private Level loggingLevel;
  1622. private String logKey;
  1623. private Object[] params;
  1624.  
  1625.  
  1626. DeferredParameterLoggingAction(WebContextInitParameter parameter,
  1627. Level loggingLevel,
  1628. String logKey,
  1629. Object[] params) {
  1630.  
  1631. this.parameter = parameter;
  1632. this.loggingLevel = loggingLevel;
  1633. this.logKey = logKey;
  1634. this.params = params;
  1635.  
  1636. }
  1637.  
  1638. public void log() {
  1639.  
  1640. if (WebConfiguration.LOGGER.isLoggable(loggingLevel)) {
  1641. DeprecationLoggingStrategy strategy = parameter.getDeprecationLoggingStrategy();
  1642. if (strategy != null && strategy.shouldBeLogged(WebConfiguration.this)) {
  1643. WebConfiguration.LOGGER.log(loggingLevel, logKey, params);
  1644. }
  1645. }
  1646.  
  1647. }
  1648.  
  1649. } // END DeferredParameterLogginAction
  1650.  
  1651.  
  1652. private class DeferredBooleanParameterLoggingAction implements DeferredLoggingAction {
  1653.  
  1654. private BooleanWebContextInitParameter parameter;
  1655. private Level loggingLevel;
  1656. private String logKey;
  1657. private Object[] params;
  1658.  
  1659. DeferredBooleanParameterLoggingAction(BooleanWebContextInitParameter parameter,
  1660. Level loggingLevel,
  1661. String logKey,
  1662. Object[] params) {
  1663. this.parameter = parameter;
  1664. this.loggingLevel = loggingLevel;
  1665. this.logKey = logKey;
  1666. this.params = params;
  1667. }
  1668.  
  1669. public void log() {
  1670.  
  1671. if (WebConfiguration.LOGGER.isLoggable(loggingLevel)) {
  1672. DeprecationLoggingStrategy strategy = parameter.getDeprecationLoggingStrategy();
  1673. if (strategy != null && strategy.shouldBeLogged(WebConfiguration.this)) {
  1674. WebConfiguration.LOGGER.log(loggingLevel, logKey, params);
  1675. }
  1676. }
  1677.  
  1678. }
  1679.  
  1680. } // END DeferredBooleanParameterLoggingAction
  1681.  
  1682. } // END WebConfiguration
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement