View Javadoc

1   /*
2    * $Id: ContentStorageAccessorHandler.java,v 1.8 2010/03/19 14:53:48 oeuillot Exp $
3    */
4   package org.rcfaces.core.internal.contentStorage;
5   
6   import javax.faces.context.FacesContext;
7   
8   import org.rcfaces.core.internal.RcfacesContext;
9   import org.rcfaces.core.internal.contentAccessor.ContentAccessorsRegistryImpl;
10  import org.rcfaces.core.internal.contentAccessor.IContentAccessor;
11  import org.rcfaces.core.internal.contentAccessor.IContentAccessorHandler;
12  import org.rcfaces.core.internal.contentAccessor.IContentPath;
13  import org.rcfaces.core.internal.contentAccessor.IGeneratedResourceInformation;
14  import org.rcfaces.core.internal.contentAccessor.IGenerationResourceInformation;
15  import org.rcfaces.core.model.IContentModel;
16  import org.rcfaces.core.model.IFiltredModel;
17  import org.rcfaces.core.provider.AbstractProvider;
18  
19  /**
20   * 
21   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
22   * @version $Revision: 1.8 $ $Date: 2010/03/19 14:53:48 $
23   */
24  public class ContentStorageAccessorHandler extends AbstractProvider implements
25          IContentAccessorHandler {
26      private static final String REVISION = "$Revision: 1.8 $";
27  
28      public void startup(FacesContext facesContext) {
29          super.startup(facesContext);
30  
31          RcfacesContext rcfacesContext = RcfacesContext
32                  .getInstance(facesContext);
33  
34          ((ContentAccessorsRegistryImpl) rcfacesContext
35                  .getContentAccessorRegistry()).declareContentAccessorHandler(
36                  null, this);
37      }
38  
39      public String getId() {
40          return "ContentStorageAccessorHandler";
41      }
42  
43      public IContentAccessor handleContent(FacesContext facesContext,
44              IContentAccessor contentAccessor,
45              IGeneratedResourceInformation[] generatedInformationRef,
46              IGenerationResourceInformation generationInformation) {
47  
48          if (contentAccessor.getPathType() != IContentPath.UNDEFINED_PATH_TYPE) {
49              return null;
50          }
51  
52          Object ref = contentAccessor.getContentRef();
53          if (ref == null || (ref instanceof String)) {
54              return null;
55          }
56  
57          RcfacesContext rcfacesContext = RcfacesContext
58                  .getInstance(facesContext);
59  
60          if (ref instanceof IContentModel) {
61              IContentModel contentModel = (IContentModel) ref;
62              IGeneratedResourceInformation generatedInformation = generatedInformationRef[0];
63  
64              if (contentModel instanceof IFiltredModel) {
65                  ((IFiltredModel) contentModel).setFilter(generationInformation
66                          .getFilterProperties());
67  
68                  if (contentAccessor != null) {
69                      generatedInformation.setFiltredModel(true);
70                  }
71              }
72  
73              return rcfacesContext.getContentStorageEngine()
74                      .registerContentModel(facesContext, contentModel,
75                              generatedInformationRef[0], generationInformation);
76          }
77  
78          return rcfacesContext.getContentStorageEngine().registerRaw(
79                  facesContext, ref, generatedInformationRef[0]);
80      }
81  
82  }