コード例 #1
0
  private boolean handleDropTransfer(String dropStr, final int dropRow) throws IOException {
    if (dropStr.startsWith("file:")) {
      // This appears to be a dragged file link and not a reference
      // format. Check if we can map this to a set of files:
      if (handleDraggedFilenames(dropStr, dropRow)) {
        return true;
        // If not, handle it in the normal way...
      }
    } else if (dropStr.startsWith("http:")) {
      // This is the way URL links are received on OS X and KDE (Gnome?):
      URL url = new URL(dropStr);
      // JOptionPane.showMessageDialog(null, "Making URL:
      // "+url.toString());
      return handleDropTransfer(url);
    }
    File tmpfile = java.io.File.createTempFile("jabrefimport", "");
    tmpfile.deleteOnExit();
    try (FileWriter fw = new FileWriter(tmpfile)) {
      fw.write(dropStr);
    }

    // System.out.println("importing from " + tmpfile.getAbsolutePath());

    ImportMenuItem importer = new ImportMenuItem(frame, false);
    importer.automatedImport(new String[] {tmpfile.getAbsolutePath()});

    return true;
  }
コード例 #2
0
  /**
   * Take a set of filenames. Those with names indicating bib files are opened as such if possible.
   * All other files we will attempt to import into the current database.
   *
   * @param fileNames The names of the files to open.
   * @param dropRow success status for the operation
   */
  private void loadOrImportFiles(String[] fileNames, int dropRow) {

    OpenDatabaseAction openAction = new OpenDatabaseAction(frame, false);
    List<String> notBibFiles = new ArrayList<>();
    List<String> bibFiles = new ArrayList<>();
    for (String fileName : fileNames) {
      // Find the file's extension, if any:
      String extension = "";
      ExternalFileType fileType = null;
      int index = fileName.lastIndexOf('.');
      if ((index >= 0) && (index < fileName.length())) {
        extension = fileName.substring(index + 1).toLowerCase();
      }
      if ("bib".equals(extension)) {
        // we assume that it is a BibTeX file.
        // When a user wants to import something with file extension "bib", but which is not a
        // BibTeX file, he should use "file -> import"
        bibFiles.add(fileName);
        continue;
      }

      fileType = Globals.prefs.getExternalFileTypeByExt(extension);
      /*
       * This is a linkable file. If the user dropped it on an entry, we
       * should offer options for autolinking to this files:
       *
       * TODO we should offer an option to highlight the row the user is on too.
       */
      if ((fileType != null) && (dropRow >= 0)) {

        /*
         * TODO: need to signal if this is a local or autodownloaded
         * file
         */
        boolean local = true;

        /*
         * TODO: make this an instance variable?
         */
        DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
        dfh.handleDroppedfile(fileName, fileType, local, entryTable, dropRow);

        continue;
      }
      notBibFiles.add(fileName);
    }

    openAction.openFilesAsStringList(bibFiles, true);

    if (!notBibFiles.isEmpty()) {
      String[] toImport = new String[notBibFiles.size()];
      notBibFiles.toArray(toImport);

      // Import into new if entryTable==null, otherwise into current
      // database:
      ImportMenuItem importer = new ImportMenuItem(frame, entryTable == null);
      importer.automatedImport(toImport);
    }
  }
コード例 #3
0
  private boolean handleDropTransfer(URL dropLink) throws IOException {
    File tmpfile = java.io.File.createTempFile("jabrefimport", "");
    tmpfile.deleteOnExit();

    // System.out.println("Import url: " + dropLink.toString());
    // System.out.println("Temp file: "+tmpfile.getAbsolutePath());

    MonitoredURLDownload.buildMonitoredDownload(entryTable, dropLink).downloadToFile(tmpfile);

    // Import into new if entryTable==null, otherwise into current database:
    ImportMenuItem importer = new ImportMenuItem(frame, entryTable == null);
    importer.automatedImport(new String[] {tmpfile.getAbsolutePath()});

    return true;
  }