/** * 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(); }
/** * 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; }
/** * Computes the redirection target URL for the newly created {@link TopLevelItem}. */ protected String redirectAfterCreateItem(StaplerRequest req, TopLevelItem result) throws IOException { return req.getContextPath()+'/'+result.getUrl()+"configure"; }
public String getImageOf(String size) { return Stapler.getCurrentRequest().getContextPath()+ Jenkins.RESOURCE_PATH+"/images/"+size+'/'+image; }
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() {
/** * Returns the image that shows the current buildCommand status. */ public void doBuildStatus(StaplerRequest req, StaplerResponse rsp) throws IOException { rsp.sendRedirect2(req.getContextPath() + "/images/48x48/" + getBuildStatusUrl()); }
/** * 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"); } }
public void doBuildStatus( StaplerRequest req, StaplerResponse rsp ) throws IOException { rsp.sendRedirect2(req.getContextPath()+"/images/48x48/"+getBuildStatusUrl()); }
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>"; }
private void _errorWithMarkup(String message, String cssClass) throws IOException, ServletException { if(message==null) { ok(); } else { response.setContentType("text/html;charset=UTF-8"); // 1x16 spacer needed for IE since it doesn't support min-height response.getWriter().print("<div class="+ cssClass +"><img src='"+ request.getContextPath()+ Jenkins.RESOURCE_PATH+"/images/none.gif' height=16 width=1>"+ message+"</div>"); } }
/** * Depending on whether the user said "yes" or "no", send him to the right place. */ @RequirePOST public void doAct(StaplerRequest req, StaplerResponse rsp) throws IOException { if(req.hasParameter("no")) { disable(true); rsp.sendRedirect(req.getContextPath()+"/manage"); } else { rsp.sendRedirect(req.getContextPath()+"/newView"); } }
/** * Depending on whether the user said "yes" or "no", send him to the right place. */ @RequirePOST public void doAct(StaplerRequest req, StaplerResponse rsp) throws IOException { if(req.hasParameter("no")) { disable(true); rsp.sendRedirect(req.getContextPath()+"/manage"); } else { rsp.sendRedirect(req.getContextPath()+"/configureSecurity"); } } }
/** * Ignore the problem and go back to using Hudson. */ @RequirePOST public void doIgnore(StaplerRequest req, StaplerResponse rsp) throws IOException { ignore = true; Jenkins.getInstance().servletContext.setAttribute("app", Jenkins.getInstance()); rsp.sendRedirect2(req.getContextPath()+'/'); }
/** * URL binding to disable this monitor. */ @RequirePOST public void doDisable(StaplerRequest req, StaplerResponse rsp) throws IOException { disable(true); rsp.sendRedirect2(req.getContextPath()+"/manage"); }
@RequirePOST public void doAct(StaplerRequest req, StaplerResponse rsp) throws IOException { j.forceSetSlaveAgentPort(getExpectedPort()); rsp.sendRedirect2(req.getContextPath() + "/manage"); }
public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse response) throws IOException, JellyException { ContextMenu menu = new ContextMenu().from(this, request, response); for (MenuItem i : menu.items) { if (i.url.equals(request.getContextPath() + "/manage")) { // add "Manage Jenkins" subitems i.subMenu = new ContextMenu().from(this, request, response, "manage"); } } return menu; }
@RequirePOST public synchronized void doConfigure(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException { boolean result = configure(req, req.getSubmittedForm()); LOGGER.log(Level.FINE, "tools saved: "+result); FormApply.success(req.getContextPath() + "/manage").generateResponse(req, rsp, null); }
/** * Deletes this view. */ @RequirePOST public synchronized void doDoDelete(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { checkPermission(DELETE); owner.deleteView(this); rsp.sendRedirect2(req.getContextPath()+"/" + owner.getUrl()); }
@RequirePOST public synchronized void doConfigure(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { // for compatibility reasons, the actual value is stored in Jenkins BulkChange bc = new BulkChange(Jenkins.getInstance()); try{ boolean result = configure(req, req.getSubmittedForm()); LOGGER.log(Level.FINE, "security saved: "+result); Jenkins.getInstance().save(); FormApply.success(req.getContextPath()+"/manage").generateResponse(req, rsp, null); } finally { bc.commit(); } }