private InputStream getHelpStream(Class c, String suffix) { Locale locale = Stapler.getCurrentRequest().getLocale(); String base = c.getName().replace('.', '/').replace('$', '/') + "/help" + suffix; ClassLoader cl = c.getClassLoader(); if (cl == null) return null; InputStream in; in = cl.getResourceAsStream( base + '_' + locale.getLanguage() + '_' + locale.getCountry() + '_' + locale.getVariant() + ".html"); if (in != null) return in; in = cl.getResourceAsStream( base + '_' + locale.getLanguage() + '_' + locale.getCountry() + ".html"); if (in != null) return in; in = cl.getResourceAsStream(base + '_' + locale.getLanguage() + ".html"); if (in != null) return in; // default return cl.getResourceAsStream(base + ".html"); }
/** Serves <tt>help.html</tt> from the resource of {@link #clazz}. */ public void doHelp(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { String path = req.getRestOfPath(); if (path.contains("..")) throw new ServletException("Illegal path: " + path); path = path.replace('/', '-'); for (Class c = clazz; c != null; c = c.getSuperclass()) { RequestDispatcher rd = Stapler.getCurrentRequest().getView(c, "help" + path); if (rd != null) { // Jelly-generated help page rd.forward(req, rsp); return; } InputStream in = getHelpStream(c, path); if (in != null) { // TODO: generalize macro expansion and perhaps even support JEXL rsp.setContentType("text/html;charset=UTF-8"); String literal = IOUtils.toString(in, "UTF-8"); rsp.getWriter() .println( Util.replaceMacro( literal, Collections.singletonMap("rootURL", req.getContextPath()))); in.close(); return; } } rsp.sendError(SC_NOT_FOUND); }
/** * Method for checking whether current build is sub job(MatrixRun) of Matrix build. * * @return boolean */ public boolean isMatrixRun() { StaplerRequest request = Stapler.getCurrentRequest(); if (request != null) { build = request.findAncestorObject(AbstractBuild.class); if (build != null && build instanceof MatrixRun) { return true; } } return false; }
/** * Method will return current project. * * @return currentProject. */ public AbstractProject getProject() { if (build != null) { return build.getProject(); } AbstractProject currentProject = null; StaplerRequest request = Stapler.getCurrentRequest(); if (request != null) { currentProject = request.findAncestorObject(AbstractProject.class); } if (currentProject == null) { throw new NullPointerException("Current Project is null"); } return currentProject; }
/** * Returns the path to the help screen HTML for the given field. * * <p>The help files are assumed to be at "help/FIELDNAME.html" with possible locale variations. */ public String getHelpFile(final String fieldName) { for (Class c = clazz; c != null; c = c.getSuperclass()) { String page = "/descriptor/" + getId() + "/help"; String suffix; if (fieldName == null) { suffix = ""; } else { page += '/' + fieldName; suffix = '-' + fieldName; } try { if (Stapler.getCurrentRequest().getView(c, "help" + suffix) != null) return page; } catch (IOException e) { throw new Error(e); } InputStream in = getHelpStream(c, suffix); IOUtils.closeQuietly(in); if (in != null) return page; } return null; }
/** * Helper method for {@link #parse(StaplerRequest, Annotation, Class, String)} to convert to the * right type from String. */ protected final Object convert(Class targetType, String value) { Converter converter = Stapler.lookupConverter(targetType); if (converter == null) throw new IllegalArgumentException("Unable to convert to " + targetType); return converter.convert(targetType, value); }
/** Gets the current {@link WebApp} that the calling thread is associated with. */ public static WebApp getCurrent() { return Stapler.getCurrent().getWebApp(); }
public final String issueCrumb() { return issueCrumb(Stapler.getCurrentRequest()); }
private String getCurrentDescriptorByNameUrl() { StaplerRequest req = Stapler.getCurrentRequest(); Ancestor a = req.findAncestor(DescriptorByNameOwner.class); return a.getUrl(); }