/** * For reusing code between text/html and text/plain, we run them both through the same code path * and use this request attribute to differentiate. */ private boolean isHtml() { StaplerRequest req = Stapler.getCurrentRequest(); return req!=null && req.getAttribute("html")!=null; }
/** * @param pre * If true, the message is put in a PRE tag. */ protected final void sendError(String message, StaplerRequest req, StaplerResponse rsp, boolean pre) throws ServletException, IOException { req.setAttribute("message",message); if(pre) req.setAttribute("pre",true); rsp.forward(this,"error",req); }
/** * 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; }
@DataBoundConstructor public BooleanParameterDefinition(String name, boolean defaultValue, String description) { super(name, description); this.defaultValue = defaultValue; }
public HttpResponse doToggleCollapse() throws ServletException, IOException { final StaplerRequest request = Stapler.getCurrentRequest(); final String paneId = request.getParameter("paneId"); PaneStatusProperties.forCurrentUser().toggleCollapsed(paneId); return HttpResponses.forwardToPreviousPage(); }
/** * 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; }
/** * Depending on whether the user said "dismiss" or "correct", send him to the right place. */ public void doAct(StaplerRequest req, StaplerResponse rsp) throws IOException { if(req.hasParameter("correct")) { rsp.sendRedirect(req.getContextPath()+"/pluginManager"); } }
/** * @since 1.402 */ public static String getCurrentDescriptorByNameUrl() { StaplerRequest req = Stapler.getCurrentRequest(); // this override allows RenderOnDemandClosure to preserve the proper value Object url = req.getAttribute("currentDescriptorByNameUrl"); if (url!=null) return url.toString(); Ancestor a = req.findAncestor(DescriptorByNameOwner.class); return a.getUrl(); }
@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 static boolean hasView(Object it, String path) throws IOException { if(it==null) return false; return Stapler.getCurrentRequest().getView(it,path)!=null; }
public static void restoreCurrentDescriptorByNameUrl(String old) { Stapler.getCurrentRequest().setAttribute("currentDescriptorByNameUrl", old); }
/** * @param permission * Permission needed to perform this validation, or null if no permission is necessary. */ protected FormFieldValidator(Permission permission) { this(Stapler.getCurrentRequest(),Stapler.getCurrentResponse(),permission); }
public WorkspaceFileMask(StaplerRequest request, StaplerResponse response, boolean errorIfNotExist) { // Require CONFIGURE permission on the job super(request, response, request.findAncestorObject(AbstractProject.class), Item.CONFIGURE); this.errorIfNotExist = errorIfNotExist; }
@DataBoundConstructor public WorkspaceSnapshotSCM(String jobName, String permalink) { this.jobName = jobName; this.permalink = permalink; }
public String getImageOf(String size) { return Stapler.getCurrentRequest().getContextPath()+ Jenkins.RESOURCE_PATH+"/images/"+size+'/'+image; }
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"; } } }
protected final void sendError(String message, StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException { req.setAttribute("message",message); rsp.forward(this,"error",req); }
@DataBoundConstructor public ServerTcpPort(int value, String type) { this.value = value; this.type = type; }
public String getImageOf(String size) { return Stapler.getCurrentRequest().getContextPath()+ Jenkins.RESOURCE_PATH+"/images/"+size+'/'+image; }