1   /*
2    * BibSonomyExporter
3    * Copyright (C) 2007 Christian Schenk
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18   */
19  package org.christianschenk.bibsonomy.export.delicious;
20  
21  import java.util.Date;
22  import java.util.List;
23  
24  import org.bibsonomy.model.Bookmark;
25  import org.bibsonomy.model.Post;
26  import org.bibsonomy.model.Resource;
27  import org.christianschenk.bibsonomy.export.BibSonomyClient;
28  import org.christianschenk.bibsonomy.export.BibSonomyHelper;
29  
30  import del.icio.us.Delicious;
31  
32  /**
33   * Imports posts from BibSonomy to your del.icio.us account. 
34   * 
35   * @author Christian Schenk
36   */
37  public class DeliciousImporter {
38  
39  	private final String bibSonomyUsername;
40  	private final String bibSonomyApiKey;
41  	private final String deliciousUsername;
42  	private final String deliciousPassword;
43  
44  	public DeliciousImporter(final String bibSonomyUsername, final String bibSonomyApiKey, final String deliciousUsername, final String deliciousPassword) {
45  		this.bibSonomyUsername = bibSonomyUsername;
46  		this.bibSonomyApiKey = bibSonomyApiKey;
47  		this.deliciousUsername = deliciousUsername;
48  		this.deliciousPassword = deliciousPassword;
49  	}
50  
51  	public void doImport() {
52  		final List<Post<? extends Resource>> posts = new BibSonomyClient(this.bibSonomyUsername, this.bibSonomyApiKey).getAllBookmarksFromBibSonomy();
53  		final Delicious delicious = new Delicious(this.deliciousUsername, this.deliciousPassword);
54  		for (final Post<? extends Resource> post : posts) {
55  			final Bookmark bookmark = (Bookmark) post.getResource();
56  
57  			final String url = bookmark.getUrl();
58  			final String title = bookmark.getTitle();
59  			final String desc = post.getDescription();
60  			final String tags = BibSonomyHelper.getTags(post.getTags());
61  			final Date date = post.getDate();
62  			final boolean replace = true;
63  			final boolean shared = BibSonomyHelper.getShared(post.getGroups());
64  
65  			System.out.print("Posting: " + url);
66  			delicious.addPost(url, title, desc, tags, date, replace, shared);
67  			System.out.println(" done");
68  		}
69  	}
70  }