示例#1
0
  /** 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);
  }
示例#2
0
 private String getViewPage(Class<?> clazz, String pageName, String defaultValue) {
   while (clazz != Object.class) {
     String name = clazz.getName().replace('.', '/').replace('$', '/') + "/" + pageName;
     if (clazz.getClassLoader().getResource(name) != null) return '/' + name;
     clazz = clazz.getSuperclass();
   }
   return defaultValue;
 }
示例#3
0
  /**
   * 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;
  }