View Javadoc

1   /*
2    * $Id: ContentAccessorFactory.java,v 1.8 2010/03/19 14:53:48 oeuillot Exp $
3    */
4   package org.rcfaces.core.internal.contentAccessor;
5   
6   import java.util.Map;
7   
8   import javax.faces.context.FacesContext;
9   
10  import org.apache.commons.logging.Log;
11  import org.apache.commons.logging.LogFactory;
12  import org.rcfaces.core.component.familly.IContentAccessors;
13  import org.rcfaces.core.internal.Constants;
14  import org.rcfaces.core.internal.RcfacesContext;
15  import org.rcfaces.core.internal.component.IImageAccessors;
16  import org.rcfaces.core.lang.IContentFamily;
17  
18  /**
19   * 
20   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
21   * @version $Revision: 1.8 $ $Date: 2010/03/19 14:53:48 $
22   */
23  public class ContentAccessorFactory {
24      private static final String REVISION = "$Revision: 1.8 $";
25  
26      private static final Log LOG = LogFactory
27              .getLog(ContentAccessorFactory.class);
28  
29      public static final IContentAccessor UNSUPPORTED_CONTENT_ACCESSOR = new IContentAccessor() {
30          private static final String REVISION = "$Revision: 1.8 $";
31  
32          public Object getAttribute(String attributeName) {
33              return null;
34          }
35  
36          public Map getAttributes() {
37              return null;
38          }
39  
40          public Object getContentRef() {
41              return null;
42          }
43  
44          public IContentVersionHandler getContentVersionHandler() {
45              return null;
46          }
47  
48          public IContentProxyHandler getContentProxyHandler() {
49              return null;
50          }
51  
52          public void setContentProxyHandler(
53                  IContentProxyHandler contentProxyHandler) {
54          }
55  
56          public void setContentVersionHandler(
57                  IContentVersionHandler contentVersionHandler) {
58          }
59  
60          public int getPathType() {
61              return 0;
62          }
63  
64          public IContentAccessor getParentAccessor() {
65              return null;
66          }
67  
68          public IContentFamily getContentFamily() {
69              return null;
70          }
71  
72          public String resolveURL(FacesContext facesContext,
73                  IGeneratedResourceInformation contentInformation,
74                  IGenerationResourceInformation generationInformation) {
75              return null;
76          }
77  
78          public String resolveURL(FacesContext facesContext,
79                  IGeneratedResourceInformation contentInformation,
80                  IGenerationResourceInformation generationInformation,
81                  int pathTypeMask) {
82              return null;
83          }
84  
85          public void setPathType(int pathType) {
86          }
87  
88          public boolean equals(Object obj) {
89              return obj == this;
90          }
91  
92          public int hashCode() {
93              return 0;
94          }
95  
96          public String convertToPathType(FacesContext facesContext,
97                  int targetPathType) {
98              return null;
99          }
100 
101         public IContentPath getParentContentPath() {
102             return null;
103         }
104 
105         public String getPath() {
106             return null;
107         }
108 
109     };
110 
111     private static final IContentProxyHandler RESOURCE_CONTENT_PROXY_HANDLER = new AbstractContentProxyHandler() {
112         private static final String REVISION = "$Revision: 1.8 $";
113 
114         public String getId() {
115             return "ResourceProxyHandler(proxy)";
116         }
117 
118         public IContentAccessor getProxyedContentAccessor(
119                 RcfacesContext rcfacesContext, FacesContext facesContext,
120                 IContentAccessor contentAccessor,
121                 IGeneratedResourceInformation[] contentInformationRef) {
122 
123             if (Constants.RESOURCE_CONTENT_PROXY_SUPPORT == false) {
124                 return null;
125             }
126 
127             IContentProxyHandler contentProxyHandler = rcfacesContext
128                     .getDefaultContentProxyHandler();
129             if (contentProxyHandler == null) {
130                 return null;
131             }
132 
133             return contentProxyHandler.getProxyedContentAccessor(
134                     rcfacesContext, facesContext, contentAccessor,
135                     contentInformationRef);
136         }
137 
138     };
139 
140     private static final IContentVersionHandler RESOURCE_CONTENT_VERSION_HANDLER = new AbstractContentVersionHandler() {
141         private static final String REVISION = "$Revision: 1.8 $";
142 
143         public String getId() {
144             return "ResourceVersionHandler(proxy)";
145         }
146 
147         public IContentAccessor getVersionedContentAccessor(
148                 RcfacesContext rcfacesContext, FacesContext facesContext,
149                 IContentAccessor contentAccessor,
150                 IGeneratedResourceInformation[] contentInformation) {
151 
152             if (Constants.RESOURCE_CONTENT_VERSION_SUPPORT == false) {
153                 return null;
154             }
155 
156             IContentVersionHandler contentVersionHandler = rcfacesContext
157                     .getDefaultContentVersionHandler();
158             if (contentVersionHandler == null) {
159                 return null;
160             }
161 
162             return contentVersionHandler.getVersionedContentAccessor(
163                     rcfacesContext, facesContext, contentAccessor,
164                     contentInformation);
165         }
166 
167         public String getVersionTag(RcfacesContext rcfacesContext,
168                 FacesContext facesContext, String relativeUrl,
169                 IContentAccessor contentAccessor,
170                 IGeneratedResourceInformation contentInformation) {
171 
172             if (Constants.RESOURCE_CONTENT_VERSION_SUPPORT == false) {
173                 return null;
174             }
175 
176             IContentVersionHandler contentVersionHandler = rcfacesContext
177                     .getDefaultContentVersionHandler();
178             if (contentVersionHandler == null) {
179                 return null;
180             }
181 
182             return contentVersionHandler.getVersionTag(rcfacesContext,
183                     facesContext, relativeUrl, contentAccessor,
184                     contentInformation);
185         }
186 
187     };
188 
189     public static IContentAccessor createFromWebResource(
190             FacesContext facesContext, Object value, IContentFamily type) {
191 
192         IContentVersionHandler contentVersionHandler = RESOURCE_CONTENT_VERSION_HANDLER;
193         IContentProxyHandler contentProxyHandler = RESOURCE_CONTENT_PROXY_HANDLER;
194         if (IContentFamily.HELP.equals(type) || IContentFamily.JSP.equals(type)) {
195             contentVersionHandler = null;
196             contentProxyHandler = null;
197         }
198 
199         return new BasicContentAccessor(facesContext, value, type,
200                 contentVersionHandler, contentProxyHandler);
201     }
202 
203     public static IContentAccessor createFromWebResource(
204             FacesContext facesContext, Object value, IContentAccessor parent) {
205 
206         return new BasicContentAccessor(facesContext, value, parent,
207                 IContentPath.UNDEFINED_PATH_TYPE);
208     }
209 
210     public static IContentAccessors createSingleImageWebResource(
211             FacesContext facesContext, Object value, IContentFamily image) {
212         return new SimpleImageAccessor(facesContext, value, image,
213                 RESOURCE_CONTENT_VERSION_HANDLER,
214                 RESOURCE_CONTENT_PROXY_HANDLER);
215     }
216 
217     /**
218      * 
219      * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
220      * @version $Revision: 1.8 $ $Date: 2010/03/19 14:53:48 $
221      */
222     protected static class SimpleImageAccessor extends BasicContentAccessor
223             implements IImageAccessors {
224         private static final String REVISION = "$Revision: 1.8 $";
225 
226         public SimpleImageAccessor(FacesContext facesContext, Object url,
227                 IContentFamily contentType,
228                 IContentVersionHandler versionHandler,
229                 IContentProxyHandler contentProxyHandler) {
230             super(facesContext, url, contentType, versionHandler,
231                     contentProxyHandler);
232         }
233 
234         public IContentAccessor getImageAccessor() {
235             return this;
236         }
237     }
238 
239 }