Ejemplo n.º 1
0
  /**
   * doImport called when "eventSubmit_doBatch_Import" is in the request parameters to run an
   * import.
   */
  public void doBatch_Import(RunData data, Context context) {
    SessionState state =
        ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    Hashtable fTable = new Hashtable();

    if (!securityService.isSuperUser()) {
      addAlert(state, rb.getString("archive.batch.auth"));
      return;
    }

    // String fileName = data.getParameters().getString("import-file");
    FileItem fi = data.getParameters().getFileItem("importFile");
    if (fi == null) {
      addAlert(state, rb.getString("archive.batch.missingname"));
    } else {
      // get content
      String content = fi.getString();

      String[] lines = content.split("\n");
      for (int i = 0; i < lines.length; i++) {
        String lineContent = (String) lines[i];
        String[] lineContents = lineContent.split("\t");
        if (lineContents.length == 2) {
          fTable.put(lineContents[0], lineContents[1]);
        } else {
          addAlert(state, rb.getString("archive.batch.wrongformat"));
        }
      }
    }

    if (!fTable.isEmpty()) {
      Enumeration importFileName = fTable.keys();
      int count = 1;
      while (importFileName.hasMoreElements()) {
        String path = StringUtils.trimToNull((String) importFileName.nextElement());
        String siteCreatorName = StringUtils.trimToNull((String) fTable.get(path));
        if (path != null && siteCreatorName != null) {
          String nSiteId = idManager.createUuid();

          try {
            Object[] params = new Object[] {count, path, nSiteId, siteCreatorName};
            addAlert(state, rb.getFormattedMessage("archive.import1", params));
            addAlert(state, archiveService.merge(path, nSiteId, siteCreatorName));

          } catch (Exception ignore) {
          }
        }

        count++;
      }
    }
  }
Ejemplo n.º 2
0
 private String getNextUuid() {
   return idManager.createUuid();
 }