001 package org.apache.myfaces.tobago.context; 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 org.apache.commons.collections.list.SetUniqueList; 021 import org.apache.commons.collections.set.ListOrderedSet; 022 import org.apache.myfaces.tobago.internal.component.AbstractUIPopup; 023 024 import javax.faces.context.FacesContext; 025 import java.util.ArrayList; 026 import java.util.HashMap; 027 import java.util.List; 028 import java.util.Map; 029 import java.util.Set; 030 031 032 public class TobagoFacesContext extends FacesContextWrapper { 033 034 private SetUniqueList scriptFiles; 035 036 private Set<String> scriptBlocks; 037 038 private Set<String> styleFiles; 039 040 private Set<String> styleBlocks; 041 042 private SetUniqueList onloadScripts; 043 044 private Set<String> onunloadScripts; 045 046 private Set<String> onexitScripts; 047 048 private Set<String> onsubmitScripts; 049 050 private Set<AbstractUIPopup> popups; 051 052 private String enctype; 053 054 private String ajaxComponentId; 055 056 private boolean ajax; 057 058 private Map<Object, Object> attributes; 059 060 public TobagoFacesContext(FacesContext context) { 061 super(context); 062 scriptFiles = SetUniqueList.decorate(new ArrayList()); 063 scriptBlocks = new ListOrderedSet(); 064 styleFiles = new ListOrderedSet(); 065 styleBlocks = new ListOrderedSet(); 066 onloadScripts = SetUniqueList.decorate(new ArrayList()); 067 onunloadScripts = new ListOrderedSet(); 068 onexitScripts = new ListOrderedSet(); 069 onsubmitScripts = new ListOrderedSet(); 070 popups = new ListOrderedSet(); 071 } 072 073 public final Map<Object, Object> getAttributes() { 074 if (attributes == null) { 075 attributes = new HashMap<Object, Object>(); 076 } 077 return attributes; 078 } 079 080 public boolean isAjax() { 081 return ajax; 082 } 083 084 public void setAjax(boolean ajax) { 085 this.ajax = ajax; 086 } 087 088 public String getAjaxComponentId() { 089 return ajaxComponentId; 090 } 091 092 public void setAjaxComponentId(String ajaxComponentId) { 093 this.ajaxComponentId = ajaxComponentId; 094 } 095 096 public String getEnctype() { 097 return enctype; 098 } 099 100 public void setEnctype(String enctype) { 101 this.enctype = enctype; 102 } 103 104 @SuppressWarnings("unchecked") 105 public List<String> getScriptFiles() { 106 return scriptFiles; 107 } 108 109 public Set<String> getScriptBlocks() { 110 return scriptBlocks; 111 } 112 113 public Set<String> getStyleFiles() { 114 return styleFiles; 115 } 116 117 public Set<String> getStyleBlocks() { 118 return styleBlocks; 119 } 120 121 public List<String> getOnloadScripts() { 122 return onloadScripts; 123 } 124 125 public Set<String> getOnunloadScripts() { 126 return onunloadScripts; 127 } 128 129 public Set<String> getOnexitScripts() { 130 return onexitScripts; 131 } 132 133 public Set<String> getOnsubmitScripts() { 134 return onsubmitScripts; 135 } 136 137 public Set<AbstractUIPopup> getPopups() { 138 return popups; 139 } 140 141 private void clearScriptsAndPopups() { 142 // clear script Set's 143 getOnloadScripts().clear(); 144 getOnunloadScripts().clear(); 145 getOnexitScripts().clear(); 146 getScriptBlocks().clear(); 147 getPopups().clear(); 148 } 149 150 @Override 151 public String toString() { 152 return getClass().getName() + " wrapped context=" + getContext(); 153 } 154 155 @Override 156 public void release() { 157 super.release(); 158 if (attributes != null) { 159 attributes.clear(); 160 } 161 clearScriptsAndPopups(); 162 } 163 }