in app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/WeblogPageRequest.java [80:268]
public WeblogPageRequest(HttpServletRequest request)
throws InvalidRequestException {
// let our parent take care of their business first
// parent determines weblog handle and locale if specified
super(request);
String servlet = request.getServletPath();
// we only want the path info left over from after our parents parsing
String pathInfo = this.getPathInfo();
// parse the request object and figure out what we've got
log.debug("parsing path " + pathInfo);
// was this request bound for the right servlet?
if (!isValidDestination(servlet)) {
throw new InvalidRequestException(
"invalid destination for request, "
+ request.getRequestURL());
}
/*
* parse path info
*
* we expect one of the following forms of url ...
*
* /entry/<anchor> - permalink /date/<YYYYMMDD> - date collection view
* /category/<category> - category collection view /tags/<tag>+<tag> -
* tags /page/<pagelink> - custom page
*
* path info may be null, which indicates the weblog homepage
*/
if (pathInfo != null && !pathInfo.isBlank()) {
// all views use 2 path elements
String[] pathElements = pathInfo.split("/", 2);
// the first part of the path always represents the context
this.context = pathElements[0];
// now check the rest of the path and extract other details
if (pathElements.length == 2) {
if ("entry".equals(this.context)) {
this.weblogAnchor = URLUtilities.decode(pathElements[1]);
// Other page
otherPageHit = true;
} else if ("date".equals(this.context)) {
if (this.isValidDateString(pathElements[1])) {
this.weblogDate = pathElements[1];
} else {
throw new InvalidRequestException("invalid date, "
+ request.getRequestURL());
}
// Other page
otherPageHit = true;
} else if ("category".equals(this.context)) {
this.weblogCategoryName = URLUtilities
.decode(pathElements[1]);
// Other page
otherPageHit = true;
} else if ("page".equals(this.context)) {
this.weblogPageName = pathElements[1];
String tagsString = request.getParameter("tags");
if (tagsString != null) {
this.tags = Utilities.splitStringAsTags(URLUtilities
.decode(tagsString));
}
// Other page, we do not want css etc stuff so filter out
if (!pathElements[1].contains(".")) {
otherPageHit = true;
}
} else if ("tags".equals(this.context)) {
String tagsString = pathElements[1].replace('+', ' ');
this.tags = Utilities.splitStringAsTags(URLUtilities
.decode(tagsString));
int maxSize = WebloggerConfig.getIntProperty(
"tags.queries.maxIntersectionSize", 3);
if (this.tags.size() > maxSize) {
throw new InvalidRequestException(
"max number of tags allowed is " + maxSize
+ ", " + request.getRequestURL());
}
// Other page
otherPageHit = true;
} else {
throw new InvalidRequestException("context " + this.context
+ "not supported, " + request.getRequestURL());
}
} else {
// empty data is only allowed for the tags section
if (!"tags".equals(this.context)) {
throw new InvalidRequestException("invalid index page, "
+ request.getRequestURL());
}
}
} else {
// default page
websitePageHit = true;
}
/*
* parse request parameters
*
* the only params we currently allow are: date - specifies a weblog
* date string cat - specifies a weblog category anchor - specifies a
* weblog entry (old way) entry - specifies a weblog entry
*
* we only allow request params if the path info is null or on user
* defined pages (for backwards compatability). this way we prevent
* mixing of path based and query param style urls.
*/
if (pathInfo == null || this.weblogPageName != null) {
// check for entry/anchor params which indicate permalink
if (request.getParameter("entry") != null) {
String anchor = request.getParameter("entry");
if (StringUtils.isNotEmpty(anchor)) {
this.weblogAnchor = anchor;
}
} else if (request.getParameter("anchor") != null) {
String anchor = request.getParameter("anchor");
if (StringUtils.isNotEmpty(anchor)) {
this.weblogAnchor = anchor;
}
}
// only check for other params if we didn't find an anchor above or
// tags
if (this.weblogAnchor == null && this.tags == null) {
if (request.getParameter("date") != null) {
String date = request.getParameter("date");
if (this.isValidDateString(date)) {
this.weblogDate = date;
} else {
throw new InvalidRequestException("invalid date, "
+ request.getRequestURL());
}
}
if (request.getParameter("cat") != null) {
this.weblogCategoryName = URLUtilities.decode(request
.getParameter("cat"));
}
}
}
// page request param is supported in all views
if (request.getParameter("page") != null) {
String pageInt = request.getParameter("page");
try {
this.pageNum = Integer.parseInt(pageInt);
} catch (NumberFormatException e) {
// ignored, bad input
}
}
// build customParams Map, we remove built-in params because we only
// want this map to represent params defined by the template author
customParams = new HashMap<>(request.getParameterMap());
customParams.remove("entry");
customParams.remove("anchor");
customParams.remove("date");
customParams.remove("cat");
customParams.remove("page");
customParams.remove("tags");
if (log.isDebugEnabled()) {
log.debug("context = " + this.context);
log.debug("weblogAnchor = " + this.weblogAnchor);
log.debug("weblogDate = " + this.weblogDate);
log.debug("weblogCategory = " + this.weblogCategoryName);
log.debug("tags = " + this.tags);
log.debug("weblogPage = " + this.weblogPageName);
log.debug("pageNum = " + this.pageNum);
}
}