1 package ch
.cyberduck
.util
;
4 * ch.cyberduck.util.PreferencesDialog.java
11 * Copyright (c) 2003 David Kocher. All rights reserved.
12 * http://icu.unizh.ch/~dkocher/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * Bug fixes, suggestions and comments should be sent to:
25 * dkocher@cyberduck.ch
28 import javax
.swing
.Action
;
29 import javax
.swing
.JOptionPane
;
30 import java
.awt
.event
.ActionEvent
;
31 import java
.io
.BufferedReader
;
33 import java
.io
.FileReader
;
34 import java
.io
.IOException
;
37 import ch
.cyberduck
.connection
.Bookmark
;
40 * Import URLs from any text file
42 public class URLImporter
extends Thread
{
44 Action addBookmarkAction
;
46 public URLImporter(File path
, Action addBookmarkAction
) {
48 this.addBookmarkAction
= addBookmarkAction
;
53 BufferedReader br
= null;
58 br
= new BufferedReader(fr
= new FileReader(path
));
60 String line
= br
.readLine();
62 JOptionPane
.showMessageDialog(
64 "Found " + url_hits
+ " URLs from " + line_count
+ "\n" +
67 JOptionPane
.INFORMATION_MESSAGE
,
74 boolean moreURLs
= true;
78 int hit
= line
.indexOf("http://", index
);
80 hit
= line
.indexOf("ftp://", index
);
86 int end
= line
.indexOf(' ', hit
);
88 url
= new URL(line
.substring(hit
));
92 url
= new URL(line
.substring(hit
, end
));
95 Bookmark bookmark
= new Bookmark(url
);
96 addBookmarkAction
.actionPerformed(new ActionEvent(bookmark
, ActionEvent
.ACTION_PERFORMED
, "Import"));
97 // table.addEntry(bookmark);
99 } // end of while (moreurls)
101 } // end of while(!eof)
103 catch(IOException e
) {
104 JOptionPane
.showMessageDialog(null, "Failed to extract URLs from '" + path
.getName() + "':\n" + e
.getMessage(), "Import failed", JOptionPane
.ERROR_MESSAGE
);