*** empty log message ***
[cyberduck.git] / source / ch / cyberduck / Attic / util / URLImporter.java
blobdce614838e383f2cb58f59ebc8a828bcd3e97887
1 package ch.cyberduck.util;
3 /*
4 * ch.cyberduck.util.PreferencesDialog.java
5 * Cyberduck
7 * $Header$
8 * $Revision$
9 * $Date$
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;
32 import java.io.File;
33 import java.io.FileReader;
34 import java.io.IOException;
35 import java.net.URL;
37 import ch.cyberduck.connection.Bookmark;
39 /**
40 * Import URLs from any text file
42 public class URLImporter extends Thread {
43 File path;
44 Action addBookmarkAction;
46 public URLImporter(File path, Action addBookmarkAction) {
47 this.path = path;
48 this.addBookmarkAction = addBookmarkAction;
51 public void run() {
52 FileReader fr = null;
53 BufferedReader br = null;
54 boolean eof = false;
55 int url_hits = 0;
56 int line_count = 0;
57 try {
58 br = new BufferedReader(fr = new FileReader(path));
59 while (!eof) {
60 String line = br.readLine();
61 if (line == null) {
62 JOptionPane.showMessageDialog(
63 null,
64 "Found " + url_hits + " URLs from " + line_count + "\n" +
65 "parsed lines.",
66 "Import succeeded",
67 JOptionPane.INFORMATION_MESSAGE,
68 null
70 eof = true;
72 else {
73 line_count++;
74 boolean moreURLs = true;
75 URL url;
76 int index = 0;
77 while (moreURLs) {
78 int hit = line.indexOf("http://", index);
79 if (hit == -1) {
80 hit = line.indexOf("ftp://", index);
82 if(hit == -1)
83 moreURLs = false;
84 else {
85 url_hits++;
86 int end = line.indexOf(' ', hit);
87 if (end == - 1) {
88 url = new URL(line.substring(hit));
89 moreURLs = false;
91 else {
92 url = new URL(line.substring(hit, end));
93 index = 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)
102 } // end of try
103 catch(IOException e) {
104 JOptionPane.showMessageDialog(null, "Failed to extract URLs from '" + path.getName() + "':\n" + e.getMessage(), "Import failed", JOptionPane.ERROR_MESSAGE);