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  
26  import javax.faces.context.FacesContext;
27  import javax.faces.context.FacesContextWrapper;
28  import java.util.ArrayList;
29  import java.util.List;
30  import java.util.Set;
31  
32  /**
33   * @deprecated since 2.0.0
34   */
35  @Deprecated
36  public class TobagoFacesContext extends FacesContextWrapper {
37  
38    private final FacesContext wrapped;
39  
40    private SetUniqueList scriptFiles;
41  
42    private Set<String> scriptBlocks;
43  
44    private Set<String> styleFiles;
45  
46    private Set<String> styleBlocks;
47  
48    private SetUniqueList onloadScripts;
49  
50    private Set<String> onunloadScripts;
51  
52    private Set<String> onexitScripts;
53  
54    private Set<String> onsubmitScripts;
55  
56    private Set<AbstractUIPopup> popups;
57  
58    private String enctype;
59  
60    private String ajaxComponentId;
61  
62    private boolean ajax;
63  
64    public TobagoFacesContext(final FacesContext wrapped) {
65      this.wrapped = wrapped;
66      scriptFiles = SetUniqueList.decorate(new ArrayList());
67      scriptBlocks = new ListOrderedSet();
68      styleFiles = new ListOrderedSet();
69      styleBlocks = new ListOrderedSet();
70      onloadScripts = SetUniqueList.decorate(new ArrayList());
71      onunloadScripts = new ListOrderedSet();
72      onexitScripts = new ListOrderedSet();
73      onsubmitScripts = new ListOrderedSet();
74      popups = new ListOrderedSet();
75    }
76  
77    public boolean isAjax() {
78      return ajax;
79    }
80  
81    public void setAjax(final boolean ajax) {
82      this.ajax = ajax;
83    }
84  
85    public String getAjaxComponentId() {
86      return ajaxComponentId;
87    }
88  
89    public void setAjaxComponentId(final String ajaxComponentId) {
90      this.ajaxComponentId = ajaxComponentId;
91    }
92  
93    public String getEnctype() {
94      return enctype;
95    }
96  
97    public void setEnctype(final String enctype) {
98      this.enctype = enctype;
99    }
100 
101   @SuppressWarnings("unchecked")
102   public List<String> getScriptFiles() {
103     return scriptFiles;
104   }
105 
106   public Set<String> getScriptBlocks() {
107     return scriptBlocks;
108   }
109 
110   public Set<String> getStyleFiles() {
111     return styleFiles;
112   }
113 
114   public Set<String> getStyleBlocks() {
115     return styleBlocks;
116   }
117 
118   public List<String> getOnloadScripts() {
119     return onloadScripts;
120   }
121 
122   public Set<String> getOnunloadScripts() {
123     return onunloadScripts;
124   }
125 
126   public Set<String> getOnexitScripts() {
127     return onexitScripts;
128   }
129 
130   public Set<String> getOnsubmitScripts() {
131     return onsubmitScripts;
132   }
133 
134   public Set<AbstractUIPopup> getPopups() {
135     return popups;
136   }
137 
138   private void clearScriptsAndPopups() {
139     // clear script Set's
140     getOnloadScripts().clear();
141     getOnunloadScripts().clear();
142     getOnexitScripts().clear();
143     getScriptBlocks().clear();
144     getPopups().clear();
145   }
146 
147   @Override
148   public String toString() {
149     return getClass().getName() + " wrapped context=" + getWrapped();
150   }
151 
152   @Override
153   public void release() {
154     super.release();
155     clearScriptsAndPopups();
156   }
157 
158   @Override
159   public FacesContext getWrapped() {
160     return wrapped;
161   }
162 }