@Override
  public void write(OutputStream outputStream) throws IOException {
    if (isMultipart()) {
      for (FormData data : getEntries()) {
        // Write the boundary line
        outputStream.write(("--" + getMultipartBoundary()).getBytes());
        HeaderUtils.writeCRLF(outputStream);

        // Write the optional content type header line
        if (MediaType.TEXT_PLAIN.equals(data.getMediaType())) {
          // Write the content disposition header line
          String line = "Content-Disposition: form-data; name=\"" + data.getName() + "\"";
          outputStream.write(line.getBytes());
          HeaderUtils.writeCRLF(outputStream);
        } else {
          // Write the content disposition header line
          String line =
              "Content-Disposition: form-data; name=\""
                  + data.getName()
                  + "\"; filename=\""
                  + data.getFilename()
                  + "\"";
          outputStream.write(line.getBytes());
          HeaderUtils.writeCRLF(outputStream);

          // Write the content type header line
          line = "Content-Type: " + ContentType.writeHeader(data.getValueRepresentation());
          outputStream.write(line.getBytes());
          HeaderUtils.writeCRLF(outputStream);
        }

        // Write the data content
        HeaderUtils.writeCRLF(outputStream);
        data.getValueRepresentation().write(outputStream);
        HeaderUtils.writeCRLF(outputStream);
      }

      // Write the final boundary line
      outputStream.write(("--" + getMultipartBoundary() + "--").getBytes());
      HeaderUtils.writeCRLF(outputStream);
    } else {
      Representation formRep =
          new StringRepresentation(
              getQueryString(), MediaType.APPLICATION_WWW_FORM, null, CharacterSet.UTF_8);
      formRep.write(outputStream);
    }
  }
  private ParsedFormData isValid(FormData formData) {
    ParsedFormData result;
    result = new ParsedFormData(ParsedFormData.Status.ERROR);

    if (!isValidName(formData.getName())
        || !isValidPckg(formData.getPckg())
        || !isValidDescription(formData.getDescription())) {
      return result;
    }

    Project project = new Project();
    project.setName(formData.getName());
    project.setDescription(formData.getDescription());
    project.setPckg(formData.getPckg());
    result.setProject(project);

    VCSConfiguration vcsConfig;
    try {
      vcsConfig = getVCSConfig(formData);
    } catch (IllegalArgumentException ex) {
      return result;
    }
    result.setVcsConfiguration(vcsConfig);

    CIConfiguration ciConfig;
    try {
      ciConfig = getCIConfig(formData);
    } catch (IllegalArgumentException ex) {
      return result;
    }
    result.setCiConfiguration(ciConfig);

    JiraConfiguration jiraConfig;
    try {
      jiraConfig = getJiraConfig(formData);
    } catch (IllegalArgumentException ex) {
      return result;
    }
    result.setJiraConfiguration(jiraConfig);

    if (isValidGroupName(formData.getJiraGroupName()) != null) {
      return result;
    }
    result.setJiraGroupName(formData.getJiraGroupName());

    if (!isValidJiraPermissionScheme(jiraConfig, formData.getJiraPermissionScheme())) {
      return result;
    }
    result.setJiraPermissionScheme(formData.getJiraPermissionScheme());

    if (isValidJIRAProjectKey(formData.getJiraConfigName(), formData.getJiraProjectKey()) != null) {
      return result;
    }
    result.setJiraProjectKey(formData.getJiraProjectKey());

    if (formData.getUsers().isEmpty()) {
      return result;
    }
    result.setJiraUsers(formData.getUsers());

    CatalogEntry scaffold;
    try {
      scaffold = getScaffold(formData);
    } catch (IllegalArgumentException ex) {
      return result;
    }
    result.setScaffold(scaffold);

    if (isRequiredContextFilledIn(scaffold, formData)) {
      result.setContext(formData.getContextParameters());
      result.setStatus(ParsedFormData.Status.OK);
    }

    return result;
  }