예제 #1
0
  /**
   * Parses csv generated by {@link #toCsv()} to create
   *
   * @param csvParams String containing csv of params
   * @return ExportParams from the csv
   */
  public static ExportParams parseCsv(String csvParams) {
    String[] tokens = csvParams.split(";");
    ExportParams params = new ExportParams(ExportFormat.valueOf(tokens[0]));
    params.setExportTarget(ExportTarget.valueOf(tokens[1]));
    params.setExportStartTime(TimestampHelper.getTimestampFromUtcString(tokens[2]));
    params.setDeleteTransactionsAfterExport(Boolean.parseBoolean(tokens[3]));

    return params;
  }
예제 #2
0
 @Override
 public String toString() {
   return "Export all transactions created since "
       + TimestampHelper.getUtcStringFromTimestamp(mExportStartTime)
       + " UTC"
       + " as "
       + mExportFormat.name()
       + " to "
       + mExportTarget.name();
 }
예제 #3
0
  /**
   * Returns the export parameters formatted as CSV.
   *
   * <p>The CSV format is:
   * exportformat;exportTarget;shouldExportAllTransactions;shouldDeleteAllTransactions
   *
   * @return String containing CSV format of ExportParams
   */
  public String toCsv() {
    String separator = ";";

    return mExportFormat.name()
        + separator
        + mExportTarget.name()
        + separator
        + TimestampHelper.getUtcStringFromTimestamp(mExportStartTime)
        + separator
        + Boolean.toString(mDeleteTransactionsAfterExport);
  }
예제 #4
0
  public static void initAllExports(
      Map<String, ExportFormat> customFormats,
      LayoutFormatterPreferences layoutPreferences,
      SavePreferences savePreferences) {

    ExportFormats.EXPORT_FORMATS.clear();

    // Initialize Build-In Export Formats
    ExportFormats.putFormat(
        new ExportFormat(
            "HTML", "html", "html", null, ".html", layoutPreferences, savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            Localization.lang("Simple HTML"),
            "simplehtml",
            "simplehtml",
            null,
            ".html",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            "DocBook 4.4", "docbook", "docbook", null, ".xml", layoutPreferences, savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            "DIN 1505",
            "din1505",
            "din1505winword",
            "din1505",
            ".rtf",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            "BibO RDF", "bibordf", "bibordf", null, ".rdf", layoutPreferences, savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            Localization.lang("HTML table"),
            "tablerefs",
            "tablerefs",
            "tablerefs",
            ".html",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            Localization.lang("HTML list"),
            "listrefs",
            "listrefs",
            "listrefs",
            ".html",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            Localization.lang("HTML table (with Abstract & BibTeX)"),
            "tablerefsabsbib",
            "tablerefsabsbib",
            "tablerefsabsbib",
            ".html",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            "Harvard RTF",
            "harvard",
            "harvard",
            "harvard",
            ".rtf",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            "ISO 690 RTF",
            "iso690rtf",
            "iso690RTF",
            "iso690rtf",
            ".rtf",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            "ISO 690",
            "iso690txt",
            "iso690",
            "iso690txt",
            ".txt",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            "Endnote",
            "endnote",
            "EndNote",
            "endnote",
            ".txt",
            layoutPreferences,
            savePreferences));
    ExportFormats.putFormat(
        new ExportFormat(
            "OpenOffice/LibreOffice CSV",
            "oocsv",
            "openoffice-csv",
            "openoffice",
            ".csv",
            layoutPreferences,
            savePreferences));
    ExportFormat ef =
        new ExportFormat("RIS", "ris", "ris", "ris", ".ris", layoutPreferences, savePreferences);
    ef.setEncoding(StandardCharsets.UTF_8);
    ExportFormats.putFormat(ef);
    ExportFormats.putFormat(
        new ExportFormat(
            "MIS Quarterly", "misq", "misq", "misq", ".rtf", layoutPreferences, savePreferences));

    ExportFormats.putFormat(new BibTeXMLExportFormat());
    ExportFormats.putFormat(new OpenOfficeDocumentCreator());
    ExportFormats.putFormat(new OpenDocumentSpreadsheetCreator());
    ExportFormats.putFormat(new MSBibExportFormat());
    ExportFormats.putFormat(new ModsExportFormat());

    // Now add custom export formats
    for (IExportFormat format : customFormats.values()) {
      ExportFormats.putFormat(format);
    }
  }
  /**
   * Create a metadata folder according to MEF {@link Version} 2 specification. If current record is
   * based on an ISO profil, the stylesheet /convert/to19139.xsl is used to map to ISO. Both files
   * are included in MEF file. Export relevant information according to format parameter.
   *
   * @param context
   * @param uuid Metadata record to export
   * @param zipFs Zip file to add new record
   * @param skipUUID
   * @param stylePath
   * @param format
   * @throws Exception
   */
  private static void createMetadataFolder(
      ServiceContext context,
      String uuid,
      FileSystem zipFs,
      boolean skipUUID,
      Path stylePath,
      Format format,
      boolean resolveXlink,
      boolean removeXlinkAttribute)
      throws Exception {

    final Path metadataRootDir = zipFs.getPath(uuid);
    Files.createDirectories(metadataRootDir);

    Pair<Metadata, String> recordAndMetadataForExport =
        MEFLib.retrieveMetadata(context, uuid, resolveXlink, removeXlinkAttribute);
    Metadata record = recordAndMetadataForExport.one();
    String xmlDocumentAsString = recordAndMetadataForExport.two();

    String id = "" + record.getId();
    String isTemp = record.getDataInfo().getType().codeString;

    if (!"y".equals(isTemp) && !"n".equals(isTemp))
      throw new Exception("Cannot export sub template");

    Path pubDir = Lib.resource.getDir(context, "public", id);
    Path priDir = Lib.resource.getDir(context, "private", id);

    final Path metadataXmlDir = metadataRootDir.resolve(MD_DIR);
    Files.createDirectories(metadataXmlDir);

    Collection<ExportFormat> formats =
        context.getApplicationContext().getBeansOfType(ExportFormat.class).values();
    for (ExportFormat exportFormat : formats) {
      for (Pair<String, String> output : exportFormat.getFormats(context, record)) {
        Files.write(metadataXmlDir.resolve(output.one()), output.two().getBytes(CHARSET));
      }
    }

    // --- save native metadata
    Files.write(metadataXmlDir.resolve(FILE_METADATA), xmlDocumentAsString.getBytes(CHARSET));

    // --- save Feature Catalog
    String ftUUID = getFeatureCatalogID(context, record.getId());
    if (!ftUUID.equals("")) {
      Pair<Metadata, String> ftrecordAndMetadata =
          MEFLib.retrieveMetadata(context, ftUUID, resolveXlink, removeXlinkAttribute);
      Path featureMdDir = metadataRootDir.resolve(SCHEMA);
      Files.createDirectories(featureMdDir);
      Files.write(featureMdDir.resolve(FILE_METADATA), ftrecordAndMetadata.two().getBytes(CHARSET));
    }

    // --- save info file
    byte[] binData =
        MEFLib.buildInfoFile(context, record, format, pubDir, priDir, skipUUID)
            .getBytes(Constants.ENCODING);

    Files.write(metadataRootDir.resolve(FILE_INFO), binData);

    // --- save thumbnails and maps

    if (format == Format.PARTIAL || format == Format.FULL) {
      IO.copyDirectoryOrFile(pubDir, metadataRootDir, true);
    }

    if (format == Format.FULL) {
      try {
        Lib.resource.checkPrivilege(context, id, ReservedOperation.download);
        IO.copyDirectoryOrFile(priDir, metadataRootDir, true);
      } catch (Exception e) {
        // Current user could not download private data
      }
    }
  }
 @PostConstruct
 private void setup() {
   for (ExportFormat format : formats) {
     exporters.put(format.getExtension(), format);
   }
 }