View Javadoc

1   package org.rcfaces.core.internal.contentAccessor;
2   
3   import javax.faces.context.FacesContext;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   import org.rcfaces.core.internal.tools.BindingTools;
8   import org.rcfaces.core.lang.IContentFamily;
9   
10  /**
11   * 
12   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
13   * @version $Revision: 1.9 $ $Date: 2010/03/19 14:53:48 $
14   */
15  public class BasicContentAccessor extends AbstractContentAccessor {
16      private static final String REVISION = "$Revision: 1.9 $";
17  
18      private static final Log LOG = LogFactory
19              .getLog(BasicContentAccessor.class);
20  
21      private final Object value;
22  
23      public BasicContentAccessor(FacesContext facesContext, String url,
24              int pathType, IContentFamily contentFamily) {
25          this(facesContext, url, pathType, contentFamily, null, null);
26      }
27  
28      public BasicContentAccessor(FacesContext facesContext, String url,
29              int pathType, IContentFamily contentFamily,
30              IContentVersionHandler contentVersionHandler,
31              IContentProxyHandler contentProxyHandler) {
32          super(contentFamily, contentVersionHandler, contentProxyHandler);
33  
34          this.value = url;
35          setPathType(pathType);
36      }
37  
38      public BasicContentAccessor(FacesContext facesContext, Object url,
39              IContentFamily contentFamily,
40              IContentVersionHandler contentVersionHandler,
41              IContentProxyHandler contentProxyHandler) {
42          super(contentFamily, contentVersionHandler, contentProxyHandler);
43  
44          this.value = convertURL(facesContext, url);
45      }
46  
47      public BasicContentAccessor(FacesContext facesContext, Object url,
48              IContentFamily contentFamily) {
49          this(facesContext, url, contentFamily, null, null);
50      }
51  
52      public BasicContentAccessor(FacesContext facesContext, Object url,
53              IContentAccessor root, int pathType) {
54          super(root);
55  
56          if (pathType == IContentPath.UNDEFINED_PATH_TYPE) {
57              this.value = convertURL(facesContext, url);
58  
59          } else {
60              this.value = url;
61              setPathType(pathType);
62          }
63      }
64  
65      public String getPath() {
66          return String.valueOf(getContentRef());
67      }
68  
69      public Object getContentRef() {
70          return value;
71      }
72  
73      protected Object convertURL(FacesContext facesContext, Object url) {
74          if (url == null) {
75              setPathType(IContentPath.UNDEFINED_PATH_TYPE);
76  
77              return null;
78          }
79  
80          url = BindingTools.resolveBinding(facesContext, url);
81  
82          if ((url instanceof String) == false) {
83              setPathType(IContentPath.UNDEFINED_PATH_TYPE);
84              return url;
85          }
86  
87          IContentPath cp = new BasicContentPath(getParentContentPath(),
88                  (String) url);
89  
90          setPathType(cp.getPathType());
91  
92          return cp.getPath();
93      }
94  
95      public String toString() {
96          return "[AbstractContentAccessor contentType=" + getContentFamily()
97                  + " pathType="
98                  + BasicContentPath.getPathTypeName(getPathType())
99                  + " versionHandler=" + getContentVersionHandler()
100                 + " content='" + value + "' root=" + getParentAccessor() + "]";
101     }
102 }