View Javadoc

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  
20  package org.apache.myfaces.tobago.context;
21  
22  import org.apache.commons.collections.list.SetUniqueList;
23  import org.apache.commons.collections.set.ListOrderedSet;
24  import org.apache.myfaces.tobago.internal.component.AbstractUIPopup;
25  import org.apache.myfaces.tobago.util.FacesVersion;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import javax.faces.context.FacesContext;
30  import java.util.ArrayList;
31  import java.util.List;
32  import java.util.Set;
33  
34  
35  public class TobagoFacesContext extends FacesContextWrapper {
36  
37    private static final Logger LOG = LoggerFactory.getLogger(TobagoFacesContext.class);
38  
39    private SetUniqueList scriptFiles;
40  
41    private Set<String> scriptBlocks;
42  
43    private Set<String> styleFiles;
44  
45    private Set<String> styleBlocks;
46  
47    private SetUniqueList onloadScripts;
48  
49    private Set<String> onunloadScripts;
50  
51    private Set<String> onexitScripts;
52  
53    private Set<String> onsubmitScripts;
54  
55    private Set<AbstractUIPopup> popups;
56  
57    private String enctype;
58  
59    private String ajaxComponentId;
60  
61    private boolean ajax;
62  
63  //  private Map<Object, Object> attributes;
64  
65    public TobagoFacesContext(FacesContext context) {
66      super(context);
67      scriptFiles = SetUniqueList.decorate(new ArrayList());
68      scriptBlocks = new ListOrderedSet();
69      styleFiles = new ListOrderedSet();
70      styleBlocks = new ListOrderedSet();
71      onloadScripts = SetUniqueList.decorate(new ArrayList());
72      onunloadScripts = new ListOrderedSet();
73      onexitScripts = new ListOrderedSet();
74      onsubmitScripts = new ListOrderedSet();
75      popups = new ListOrderedSet();
76    }
77  
78  /*  TBD: if we support JSF 1.2 whe have to do something here.*/
79    static {
80      if (!FacesVersion.supports20()) {
81        LOG.error("JSF 1.2 is currently not supported.");
82      }
83    }
84  
85  /* TBD: if we support JSF 1.2 whe have to do something here.
86    public final Map<Object, Object> getAttributes() {
87      if (attributes == null) {
88        attributes = new HashMap<Object, Object>();
89      }
90      return attributes;
91    }
92  */
93  
94    public boolean isAjax() {
95      return ajax;
96    }
97  
98    public void setAjax(boolean ajax) {
99      this.ajax = ajax;
100   }
101 
102   public String getAjaxComponentId() {
103     return ajaxComponentId;
104   }
105 
106   public void setAjaxComponentId(String ajaxComponentId) {
107     this.ajaxComponentId = ajaxComponentId;
108   }
109 
110   public String getEnctype() {
111     return enctype;
112   }
113 
114   public void setEnctype(String enctype) {
115     this.enctype = enctype;
116   }
117 
118   @SuppressWarnings("unchecked")
119   public List<String> getScriptFiles() {
120     return scriptFiles;
121   }
122 
123   public Set<String> getScriptBlocks() {
124     return scriptBlocks;
125   }
126 
127   public Set<String> getStyleFiles() {
128     return styleFiles;
129   }
130 
131   public Set<String> getStyleBlocks() {
132     return styleBlocks;
133   }
134 
135   public List<String> getOnloadScripts() {
136     return onloadScripts;
137   }
138 
139   public Set<String> getOnunloadScripts() {
140     return onunloadScripts;
141   }
142 
143   public Set<String> getOnexitScripts() {
144     return onexitScripts;
145   }
146 
147   public Set<String> getOnsubmitScripts() {
148     return onsubmitScripts;
149   }
150 
151   public Set<AbstractUIPopup> getPopups() {
152     return popups;
153   }
154 
155   private void clearScriptsAndPopups() {
156     // clear script Set's
157     getOnloadScripts().clear();
158     getOnunloadScripts().clear();
159     getOnexitScripts().clear();
160     getScriptBlocks().clear();
161     getPopups().clear();
162   }
163 
164   @Override
165   public String toString() {
166     return getClass().getName() + " wrapped context=" + getContext();
167   }
168 
169   @Override
170   public void release() {
171     super.release();
172 /*
173     if (attributes != null) {
174       attributes.clear();
175     }
176 */
177     clearScriptsAndPopups();
178   }
179 }