use of org.kohsuke.stapler.Ancestor in project hudson-2.x by hudson.
the class Functions method decompose.
public static RunUrl decompose(StaplerRequest req) {
List<Ancestor> ancestors = req.getAncestors();
// find the first and last Run instances
Ancestor f = null, l = null;
for (Ancestor anc : ancestors) {
if (anc.getObject() instanceof Run) {
if (f == null)
f = anc;
l = anc;
}
}
// there was no Run object
if (l == null)
return null;
String head = f.getPrev().getUrl() + '/';
String base = l.getUrl();
String reqUri = req.getOriginalRequestURI();
// Find "rest" or URI by removing N path components.
// Not using reqUri.substring(f.getUrl().length()) to avoid mismatches due to
// url-encoding or extra slashes. Former may occur in Tomcat (despite the spec saying
// this string is not decoded, Tomcat apparently decodes this string. You see ' '
// instead of '%20', which is what the browser has sent), latter may occur in some
// proxy or URL-rewriting setups where extra slashes are inadvertently added.
String furl = f.getUrl();
int slashCount = 0;
// Count components in ancestor URL
for (int i = furl.indexOf('/'); i >= 0; i = furl.indexOf('/', i + 1)) slashCount++;
// Remove that many from request URL, ignoring extra slashes
String rest = reqUri.replaceFirst("(?:/+[^/]*){" + slashCount + "}", "");
return new RunUrl((Run) f.getObject(), head, base, rest);
}
use of org.kohsuke.stapler.Ancestor in project hudson-2.x by hudson.
the class TestResultProjectAction method doFlipTrend.
/**
* Changes the test result report display mode.
*/
public void doFlipTrend(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
boolean failureOnly = false;
// check the current preference value
Cookie[] cookies = req.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(FAILURE_ONLY_COOKIE))
failureOnly = Boolean.parseBoolean(cookie.getValue());
}
}
// flip!
failureOnly = !failureOnly;
// set the updated value
Cookie cookie = new Cookie(FAILURE_ONLY_COOKIE, String.valueOf(failureOnly));
List anc = req.getAncestors();
Ancestor a = (Ancestor) anc.get(anc.size() - 2);
// just for this project
cookie.setPath(a.getUrl());
// 1 year
cookie.setMaxAge(60 * 60 * 24 * 365);
rsp.addCookie(cookie);
// back to the project page
rsp.sendRedirect("..");
}
use of org.kohsuke.stapler.Ancestor in project hudson-2.x by hudson.
the class Search method makeSuggestIndex.
/**
* Creates merged search index for suggestion.
*/
private SearchIndex makeSuggestIndex(StaplerRequest req) {
SearchIndexBuilder builder = new SearchIndexBuilder();
for (Ancestor a : req.getAncestors()) {
if (a.getObject() instanceof SearchableModelObject) {
SearchableModelObject smo = (SearchableModelObject) a.getObject();
builder.add(smo.getSearchIndex());
}
}
return builder.make();
}
Aggregations