コード例 #1
0
ファイル: Descriptor.java プロジェクト: srinivas-n4u/hudson
  /** 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
 /**
  * Creates a first admin user account.
  *
  * <p>This can be run by anyone, but only to create the very first user account.
  */
 public void doCreateFirstAccount(StaplerRequest req, StaplerResponse rsp)
     throws IOException, ServletException {
   if (hasSomeUser()) {
     rsp.sendError(SC_UNAUTHORIZED, "First user was already created");
     return;
   }
   User u = createAccount(req, rsp, "firstUser.jelly");
   if (u != null) {
     tryToMakeAdmin(u);
     loginAndTakeBack(req, rsp, u);
   }
 }