示例#1
0
文件: User.java 项目: nahi/jenkins
  /** Accepts submission from the configuration page. */
  public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp)
      throws IOException, ServletException, FormException {
    checkPermission(Hudson.ADMINISTER);

    fullName = req.getParameter("fullName");
    description = req.getParameter("description");

    JSONObject json = req.getSubmittedForm();

    List<UserProperty> props = new ArrayList<UserProperty>();
    int i = 0;
    for (UserPropertyDescriptor d : UserProperty.all()) {
      UserProperty p = getProperty(d.clazz);

      JSONObject o = json.optJSONObject("userProperty" + (i++));
      if (o != null) {
        if (p != null) {
          p = p.reconfigure(req, o);
        } else {
          p = d.newInstance(req, o);
        }
        p.setUser(this);
      }

      if (p != null) props.add(p);
    }
    this.properties = props;

    save();

    rsp.sendRedirect(".");
  }
示例#2
0
文件: User.java 项目: nahi/jenkins
  /** Loads the other data from disk if it's available. */
  private synchronized void load() {
    properties.clear();

    XmlFile config = getConfigFile();
    try {
      if (config.exists()) config.unmarshal(this);
    } catch (IOException e) {
      LOGGER.log(Level.SEVERE, "Failed to load " + config, e);
    }

    // remove nulls that have failed to load
    for (Iterator<UserProperty> itr = properties.iterator(); itr.hasNext(); ) {
      if (itr.next() == null) itr.remove();
    }

    // allocate default instances if needed.
    // doing so after load makes sure that newly added user properties do get reflected
    for (UserPropertyDescriptor d : UserProperty.all()) {
      if (getProperty(d.clazz) == null) {
        UserProperty up = d.newInstance(this);
        if (up != null) properties.add(up);
      }
    }

    for (UserProperty p : properties) p.setUser(this);
  }