1
2
3
4 package org.rcfaces.core.internal.contentAccessor;
5
6 import javax.faces.context.FacesContext;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.rcfaces.core.internal.RcfacesContext;
11
12
13
14
15
16
17 public class ContentAccessorEngine {
18 private static final String REVISION = "$Revision: 1.10 $";
19
20 private static final Log LOG = LogFactory
21 .getLog(ContentAccessorEngine.class);
22
23 public static IContentAccessor resolveURL(FacesContext facesContext,
24 final IContentAccessor contentAccessor,
25 final IGeneratedResourceInformation generatedInformation,
26 final IGenerationResourceInformation generationInformation) {
27
28 RcfacesContext rcfacesContext = RcfacesContext
29 .getInstance(facesContext);
30
31 IContentAccessorRegistry registry = rcfacesContext
32 .getContentAccessorRegistry();
33
34 IContentAccessorHandler handlers[] = registry
35 .listContentAccessorHandlers(contentAccessor.getContentFamily());
36
37 if (LOG.isDebugEnabled()) {
38 LOG.debug("Try to resolve URL '" + contentAccessor + "'");
39 }
40
41 IContentAccessor returnContentAccessor = contentAccessor;
42
43 IGeneratedResourceInformation contentInformationRef[] = new IGeneratedResourceInformation[] { generatedInformation };
44 for (int i = 0; i < handlers.length; i++) {
45 IContentAccessorHandler handler = handlers[i];
46
47 IContentAccessor newContentAccessor = handler.handleContent(
48 facesContext, returnContentAccessor, contentInformationRef,
49 generationInformation);
50
51 if (LOG.isDebugEnabled()) {
52 LOG.debug("ContentAccessorHandler(" + handler.getId()
53 + ") returns " + newContentAccessor);
54 }
55
56 if (newContentAccessor != null) {
57 returnContentAccessor = newContentAccessor;
58 break;
59 }
60 }
61
62 Object result = returnContentAccessor.getContentRef();
63 if (result == null
64 || result
65 .equals(ContentAccessorFactory.UNSUPPORTED_CONTENT_ACCESSOR)) {
66 return null;
67 }
68
69 IContentVersionHandler contentVersionHandler = returnContentAccessor
70 .getContentVersionHandler();
71 if (contentVersionHandler != null) {
72 IContentAccessor versionedContentAccessor = contentVersionHandler
73 .getVersionedContentAccessor(rcfacesContext, facesContext,
74 returnContentAccessor, contentInformationRef);
75
76 if (LOG.isDebugEnabled()) {
77 LOG.debug("contentVersionHandler("
78 + contentVersionHandler.getId() + ") returns "
79 + versionedContentAccessor);
80 }
81
82 if (versionedContentAccessor != null) {
83 returnContentAccessor = versionedContentAccessor;
84 }
85 }
86
87 IContentProxyHandler contentProxyHandler = returnContentAccessor
88 .getContentProxyHandler();
89 if (contentProxyHandler != null) {
90 IContentAccessor proxyedContentAccessor = contentProxyHandler
91 .getProxyedContentAccessor(rcfacesContext, facesContext,
92 returnContentAccessor, contentInformationRef);
93
94 if (LOG.isDebugEnabled()) {
95 LOG.debug("contentProxyHandler(" + contentProxyHandler.getId()
96 + ") returns " + proxyedContentAccessor);
97 }
98
99 if (proxyedContentAccessor != null) {
100 returnContentAccessor = proxyedContentAccessor;
101 }
102 }
103
104 if (LOG.isDebugEnabled()) {
105 LOG.debug("ResolveURL '" + contentAccessor + "' returns '"
106 + returnContentAccessor + "'");
107 }
108 return returnContentAccessor;
109 }
110 }