Skip to content

Commit b690134

Browse files
committed
replaced getContextPath with ContextPath.getPath
1 parent 073d547 commit b690134

File tree

15 files changed

+65
-454
lines changed

15 files changed

+65
-454
lines changed

api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.jena.shared.Lock;
2828

2929
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
30+
import edu.cornell.mannlib.vitro.webapp.config.ContextPath;
3031
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
3132
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
3233
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
@@ -45,7 +46,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse res)
4546
super.doGet(req, res);
4647

4748
//get URL without hostname or servlet context
48-
String url = req.getRequestURI().substring(req.getContextPath().length());
49+
String url = req.getRequestURI().substring(ContextPath.getPath(req).length());
4950

5051
String redirectURL = checkForRedirect ( url, req.getHeader("accept") );
5152

@@ -218,11 +219,11 @@ private void doRedirect(HttpServletRequest req, HttpServletResponse res,
218219
String hn = req.getHeader("Host");
219220
if (req.isSecure()) {
220221
res.setHeader("Location", res.encodeURL("https://" + hn
221-
+ req.getContextPath() + redirectURL));
222+
+ ContextPath.getPath(req) + redirectURL));
222223
log.info("doRedirect by using HTTPS");
223224
} else {
224225
res.setHeader("Location", res.encodeURL("http://" + hn
225-
+ req.getContextPath() + redirectURL));
226+
+ ContextPath.getPath(req) + redirectURL));
226227
log.info("doRedirect by using HTTP");
227228
}
228229
res.setStatus(res.SC_SEE_OTHER);

api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/accounts/user/UserAccountsUserController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
1515
import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage;
1616
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
17+
import edu.cornell.mannlib.vitro.webapp.config.ContextPath;
1718
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
1819
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
1920
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator.LoginNotPermitted;
@@ -151,14 +152,15 @@ private ResponseValues showLoginRedirection(VitroRequest vreq,
151152
* Bridge the gap.
152153
*/
153154
private String stripContextPath(VitroRequest vreq, String uri) {
154-
if ((uri == null) || uri.isEmpty() || uri.equals(vreq.getContextPath())) {
155+
String contextPath = ContextPath.getPath(vreq);
156+
if ((uri == null) || uri.isEmpty() || uri.equals(contextPath)) {
155157
return "/";
156158
}
157159
if (uri.contains("://")) {
158160
return uri;
159161
}
160-
if (uri.startsWith(vreq.getContextPath() + '/')) {
161-
return uri.substring(vreq.getContextPath().length());
162+
if (uri.startsWith(contextPath + '/')) {
163+
return uri.substring(contextPath.length());
162164
}
163165
return uri;
164166
}

api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest;
2727
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
2828
import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage;
29+
import edu.cornell.mannlib.vitro.webapp.config.ContextPath;
2930
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
3031
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
3132
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper.TemplateProcessingException;
@@ -485,7 +486,7 @@ private String normalizeServletName(String name) {
485486
}
486487

487488
protected MainMenu getDisplayModelMenu(VitroRequest vreq){
488-
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
489+
String url = vreq.getRequestURI().substring(ContextPath.getPath(vreq).length());
489490
return vreq.getWebappDaoFactory().getMenuDao().getMainMenu(url);
490491
}
491492

api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualRequestAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.apache.commons.logging.LogFactory;
1717

1818
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
19+
import edu.cornell.mannlib.vitro.webapp.config.ContextPath;
1920
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
2021
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
2122

@@ -42,8 +43,7 @@ public IndividualRequestAnalyzer(VitroRequest vreq,
4243
this.vreq = vreq;
4344

4445
// get URL without hostname or servlet context
45-
this.url = vreq.getRequestURI().substring(
46-
vreq.getContextPath().length());
46+
this.url = vreq.getRequestURI().substring(ContextPath.getPath(vreq).length());
4747

4848
this.analysisContext = analysisContext;
4949
}

api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/StartupStatusDisplayFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.lang3.StringUtils;
2323

2424
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
25+
import edu.cornell.mannlib.vitro.webapp.config.ContextPath;
2526
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
2627
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
2728
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
@@ -107,7 +108,7 @@ private void displayStartupStatus(ServletRequest req, ServletResponse resp)
107108
}
108109

109110
private String getContextPath() {
110-
String cp = ctx.getContextPath();
111+
String cp = ContextPath.getPath(ctx);
111112
if ((cp == null) || cp.isEmpty()) {
112113
return "The application";
113114
} else {

api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
import java.util.ArrayList;
66
import java.util.Iterator;
77
import java.util.List;
8-
import java.util.regex.Pattern;
98

109
import javax.servlet.ServletContext;
1110
import javax.servlet.http.HttpServletRequest;
1211
import javax.servlet.http.HttpServletResponse;
1312
import javax.servlet.http.HttpServletResponseWrapper;
1413

15-
import org.apache.commons.logging.Log;
16-
import org.apache.commons.logging.LogFactory;
17-
1814
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
1915
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
2016
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
2117
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
2218
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
19+
import org.apache.commons.logging.Log;
20+
import org.apache.commons.logging.LogFactory;
2321

2422
public class URLRewritingHttpServletResponse extends HttpServletResponseWrapper/*implements HttpServletResponse */{
2523

@@ -28,15 +26,12 @@ public class URLRewritingHttpServletResponse extends HttpServletResponseWrapper/
2826
private HttpServletResponse _response;
2927
private ServletContext _context;
3028
private WebappDaoFactory wadf;
31-
private int contextPathDepth;
32-
private Pattern slashPattern = Pattern.compile("/");
3329

3430
public URLRewritingHttpServletResponse(HttpServletResponse response, HttpServletRequest request, ServletContext context) {
3531
super(response);
3632
this._response = response;
3733
this._context = context;
38-
this.wadf = ModelAccess.on(context).getWebappDaoFactory();
39-
this.contextPathDepth = slashPattern.split(request.getContextPath()).length-1;
34+
this.wadf = ModelAccess.getInstance().getWebappDaoFactory();
4035
}
4136

4237
/** for testing. */
@@ -69,7 +64,6 @@ public String encodeURL(String inUrl) {
6964
if( log.isDebugEnabled() ){
7065
log.debug("START");
7166
log.debug("charEncoding: " + this.getCharacterEncoding() );
72-
log.debug("contextPathDepth," + contextPathDepth);
7367
log.debug("nsMap," + nsMap);
7468
log.debug("wadf.getDefaultNamespace(), " + wadf.getDefaultNamespace());
7569
log.debug("externallyLinkedNamespaces " + externallyLinkedNamespaces);
@@ -80,7 +74,6 @@ public String encodeURL(String inUrl) {
8074
inUrl,
8175
this.getCharacterEncoding(),
8276
/*wadf.getPortalDao().isSinglePortal()*/ true,
83-
contextPathDepth,
8477
nsMap,
8578
wadf.getDefaultNamespace(),
8679
externallyLinkedNamespaces
@@ -100,7 +93,6 @@ protected String encodeForVitro(
10093
String inUrl,
10194
String characterEncoding,
10295
Boolean isSInglePortal,
103-
int contextPathDepth,
10496
NamespaceMapper nsMap,
10597
String defaultNamespace,
10698
List<String> externalNamespaces) {

api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private String getCancelUrl(HttpServletRequest request) {
209209
* What's the password recovery URL for this servlet?
210210
*/
211211
private String getForgotPasswordUrl(HttpServletRequest request) {
212-
String contextPath = request.getContextPath();
212+
String contextPath = ContextPath.getPath(request);
213213
return contextPath + "/forgotPassword";
214214
}
215215

api/src/main/java/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.linkeddatafragments.servlet;
22

33
import com.fasterxml.jackson.databind.JsonNode;
4+
import edu.cornell.mannlib.vitro.webapp.config.ContextPath;
45
import org.apache.jena.riot.Lang;
56
import org.linkeddatafragments.config.ConfigReader;
67
import org.linkeddatafragments.datasource.DataSourceFactory;
@@ -128,7 +129,7 @@ public void destroy()
128129
* @throws IOException
129130
*/
130131
private IDataSource getDataSource(HttpServletRequest request) throws DataSourceNotFoundException {
131-
String contextPath = request.getContextPath();
132+
String contextPath = ContextPath.getPath(request);
132133
String requestURI = request.getRequestURI();
133134

134135
String path = contextPath == null

api/src/main/java/org/vivoweb/linkeddatafragments/servlet/VitroLinkedDataFragmentServlet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
4242
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
43+
import edu.cornell.mannlib.vitro.webapp.config.ContextPath;
4344
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
4445
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
4546
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
@@ -103,7 +104,7 @@ public void init(ServletConfig servletConfig) throws ServletException {
103104
MIMEParse.register(Lang.NTRIPLES.getHeaderString());
104105
MIMEParse.register(Lang.RDFXML.getHeaderString());
105106

106-
HtmlTriplePatternFragmentWriterImpl.setContextPath(servletConfig.getServletContext().getContextPath());
107+
HtmlTriplePatternFragmentWriterImpl.setContextPath(ContextPath.getPath(ctx));
107108
} catch (Exception e) {
108109
throw new ServletException(e);
109110
}
@@ -133,7 +134,7 @@ private boolean configurationPresent() {
133134
}
134135

135136
private IDataSource getDataSource(HttpServletRequest request) throws DataSourceNotFoundException {
136-
String contextPath = request.getContextPath();
137+
String contextPath = ContextPath.getPath(request);
137138
String requestURI = request.getRequestURI();
138139

139140
String path = contextPath == null

0 commit comments

Comments
 (0)