public String getHelpPage() { // yes, I know this is a hack. ComputerSet object = Stapler.getCurrentRequest().findAncestorObject(ComputerSet.class); if (object != null) { // we're on a node configuration page, show show that help page return "/help/system-config/nodeEnvironmentVariables.html"; } else { // show the help for the global config page return "/help/system-config/globalEnvironmentVariables.html"; } } }
public MenuItem withUrl(String url) { try { this.url = new URI(Stapler.getCurrentRequest().getRequestURI()).resolve(new URI(url)).toString(); } catch (URISyntaxException x) { throw new IllegalArgumentException("Bad URI from " + Stapler.getCurrentRequest().getRequestURI() + " vs. " + url, x); } return this; }
/** * Sets the URL by passing in a URL relative to the context path of Jenkins */ public MenuItem withContextRelativeUrl(String url) { if (!url.startsWith("/")) url = '/'+url; this.url = Stapler.getCurrentRequest().getContextPath()+url; return this; }
public static Locale getCurrentLocale() { Locale locale=null; StaplerRequest req = Stapler.getCurrentRequest(); if(req!=null) locale = req.getLocale(); if(locale==null) locale = Locale.getDefault(); return locale; }
/** * Sets the icon from core's stock icon * * @param icon * String like "gear.png" that resolves to 24x24 stock icon in the core */ public MenuItem withStockIcon(String icon) { this.icon = Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH + "/images/24x24/"+icon; return this; }
public static String getViewResource(Object it, String path) { Class clazz = it.getClass(); if(it instanceof Class) clazz = (Class)it; if(it instanceof Descriptor) clazz = ((Descriptor)it).clazz; StringBuilder buf = new StringBuilder(Stapler.getCurrentRequest().getContextPath()); buf.append(Jenkins.VIEW_RESOURCE_PATH).append('/'); buf.append(clazz.getName().replace('.','/').replace('$','/')); buf.append('/').append(path); return buf.toString(); }
@Override public boolean isInstantiable() { // doesn't make sense to add a ProxyView to the global views return !(Stapler.getCurrentRequest().findAncestorObject(ViewGroup.class) instanceof Jenkins); }
public String renderHtml() { StaplerRequest req = Stapler.getCurrentRequest(); if (req == null) { // being called from some other context return message; } // 1x16 spacer needed for IE since it doesn't support min-height return "<div class="+ kind.name().toLowerCase(Locale.ENGLISH) +"><img src='"+ req.getContextPath()+ Jenkins.RESOURCE_PATH+"/images/none.gif' height=16 width=1>"+ message+"</div>"; } @Override public String toString() {
/** * If we know the user's screen resolution, return it. Otherwise null. * @since 1.213 */ public static Area getScreenResolution() { Cookie res = Functions.getCookie(Stapler.getCurrentRequest(),"screenResolution"); if(res!=null) return Area.parse(res.getValue()); return null; }
/** * Validates the captcha. */ protected final boolean validateCaptcha(String text) { if (captchaSupport != null) { String id = Stapler.getCurrentRequest().getSession().getId(); return captchaSupport.validateCaptcha(id, text); } // If no Captcha Support then bogus validation always returns true return true; }
/** * Finds the inner-most {@link SearchableModelObject} in scope. */ public static String getSearchURL() { List list = Stapler.getCurrentRequest().getAncestors(); for( int i=list.size()-1; i>=0; i-- ) { Ancestor anc = (Ancestor) list.get(i); if(anc.getObject() instanceof SearchableModelObject) return anc.getUrl()+"/search/"; } return null; }
/** * Get a crumb value based on user specific information in the current request. * Intended for use only by the remote API. */ @Exported public String getCrumb() { return getCrumb(Stapler.getCurrentRequest()); }
public static String setCurrentDescriptorByNameUrl(String value) { String o = getCurrentDescriptorByNameUrl(); Stapler.getCurrentRequest().setAttribute("currentDescriptorByNameUrl", value); return o; }
public String renderHtml() { StaplerRequest req = Stapler.getCurrentRequest(); if (req == null) { // being called from some other context return message; } // 1x16 spacer needed for IE since it doesn't support min-height return "<div class=" + getKind().name().toLowerCase(Locale.ENGLISH) + "><img src='" + req.getContextPath() + Jenkins.RESOURCE_PATH + "/images/none.gif' height=16 width=1>" + message + "</div>"; }
public Object getTarget() { try { checkPermission(READ); } catch (AccessDeniedException e) { if (!isSubjectToMandatoryReadPermissionCheck(Stapler.getCurrentRequest().getRestOfPath())) { return this; } throw e; } return this; }
public HttpResponse doTest() { String referer = Stapler.getCurrentRequest().getReferer(); Jenkins j = Jenkins.getInstance(); // May need to send an absolute URL, since handling of HttpRedirect with a relative URL does not currently honor X-Forwarded-Proto/Port at all. String redirect = j.getRootUrl() + "administrativeMonitor/" + id + "/testForReverseProxySetup/" + (referer != null ? Util.rawEncode(referer) : "NO-REFERER") + "/"; LOGGER.log(Level.FINE, "coming from {0} and redirecting to {1}", new Object[] {referer, redirect}); return new HttpRedirect(redirect); }
/** * Creates a new instance of a {@link Describable} * from the structured form submission data posted * by a radio button group. */ public T newInstanceFromRadioList(JSONObject config) throws FormException { if(config.isNullObject()) return null; // none was selected int idx = config.getInt("value"); return get(idx).newInstance(Stapler.getCurrentRequest(),config); }
private static void checkPermissionForValidate() { AccessControlled subject = Stapler.getCurrentRequest().findAncestorObject(AbstractProject.class); if (subject == null) Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); else subject.checkPermission(Item.CONFIGURE); }
public HttpResponse doToggleCollapse() throws ServletException, IOException { final StaplerRequest request = Stapler.getCurrentRequest(); final String paneId = request.getParameter("paneId"); PaneStatusProperties.forCurrentUser().toggleCollapsed(paneId); return HttpResponses.forwardToPreviousPage(); }
/** * Possible {@link ViewJobFilter} types that can be used with this view. */ public List<Descriptor<ViewJobFilter>> getJobFiltersDescriptors() { StaplerRequest request = Stapler.getCurrentRequest(); if (request != null) { View view = request.findAncestorObject(clazz); return view == null ? DescriptorVisibilityFilter.applyType(clazz, ViewJobFilter.all()) : DescriptorVisibilityFilter.apply(view, ViewJobFilter.all()); } return ViewJobFilter.all(); }