1
2
3
4 package org.rcfaces.core.internal.contentAccessor;
5
6 import javax.faces.FacesException;
7 import javax.faces.context.FacesContext;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12
13
14
15
16
17 public class BasicContentPath extends AbstractContentPath {
18 private static final Log LOG = LogFactory.getLog(BasicContentPath.class);
19
20 private String path;
21
22 public BasicContentPath(IContentPath parent, String path) {
23 super(parent);
24
25 resolvePath(null, path);
26 }
27
28 public String getPath() {
29 return path;
30 }
31
32 protected void resolvePath(FacesContext facesContext, String url) {
33 if (url == null || url.length() < 1) {
34 throw new FacesException("Invalid url '" + url + "'.");
35 }
36
37 int slash = url.indexOf('/');
38 if (url.length() > 1 && url.charAt(0) == '$') {
39 if (url.startsWith(IContentPath.CONTEXT_KEYWORD)
40 && (slash < 0 || slash == IContentPath.CONTEXT_KEYWORD
41 .length())) {
42 setPathType(IContentPath.CONTEXT_PATH_TYPE);
43
44 if (LOG.isDebugEnabled()) {
45 LOG.debug("Macro " + IContentPath.CONTEXT_KEYWORD
46 + " for url '" + url + "'.");
47 }
48
49 if (slash > 0) {
50 this.path = url.substring(slash + 1);
51 return;
52 }
53
54 this.path = "";
55 return;
56 }
57
58
59 if (LOG.isDebugEnabled()) {
60 LOG.debug("Invalid macro type for '" + url + "'.");
61 }
62
63 setPathType(IContentPath.UNDEFINED_PATH_TYPE);
64 this.path = "";
65 return;
66 }
67
68
69 if (slash == 0) {
70
71 if (facesContext == null) {
72 facesContext = FacesContext.getCurrentInstance();
73 }
74
75 String requestContextPath = facesContext.getExternalContext()
76 .getRequestContextPath();
77 if (requestContextPath.length() == 0
78 || url.startsWith(requestContextPath)) {
79 if (LOG.isDebugEnabled()) {
80 LOG.debug("Return context path type for '" + url + "'.");
81 }
82 setPathType(IContentPath.CONTEXT_PATH_TYPE);
83
84 this.path = url.substring(requestContextPath.length() + 1);
85 return;
86
87 }
88
89 if (LOG.isDebugEnabled()) {
90 LOG.debug("Return absolute path type for '" + url + "'.");
91 }
92 setPathType(IContentPath.ABSOLUTE_PATH_TYPE);
93
94 this.path = url;
95 return;
96 }
97
98 int colon = url.indexOf(':');
99 if (colon < 0) {
100
101 if (LOG.isDebugEnabled()) {
102 LOG.debug("Return relative path type for '" + url + "'.");
103 }
104
105 setPathType(IContentPath.RELATIVE_PATH_TYPE);
106 this.path = url;
107 return;
108 }
109 if (colon == 0) {
110
111 if (LOG.isDebugEnabled()) {
112 LOG.debug("Invalid path type for '" + url + "'.");
113 }
114 setPathType(IContentPath.UNDEFINED_PATH_TYPE);
115
116 this.path = url;
117 return;
118 }
119
120 int doubleColon = url.indexOf(IContentAccessor.FILTER_SEPARATOR, colon);
121 if (doubleColon > 0 && (slash < 0 || slash > doubleColon)
122 && (colon == doubleColon)) {
123
124
125
126
127 if (LOG.isDebugEnabled()) {
128 LOG.debug("Filter path type for '" + url + "'.");
129 }
130 setPathType(IContentPath.FILTER_PATH_TYPE);
131 this.path = url;
132 return;
133 }
134
135 if (colon > 0 && (slash < 0 || slash > colon)) {
136 if (LOG.isDebugEnabled()) {
137 LOG.debug("External path type for '" + url + "'.");
138 }
139 setPathType(IContentPath.EXTERNAL_PATH_TYPE);
140
141 this.path = url;
142 return;
143 }
144
145 if (LOG.isDebugEnabled()) {
146 LOG.debug("Relative path type (default) for '" + url + "'.");
147 }
148 setPathType(IContentPath.RELATIVE_PATH_TYPE);
149 this.path = url;
150 }
151 }