This repository has been archived by the owner on Nov 10, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
holm
committed
Dec 17, 2010
0 parents
commit b69abf0
Showing
8 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"/> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> | ||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>delicious</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.maven.ide.eclipse.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.maven.ide.eclipse.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Fri Dec 17 21:01:38 CET 2010 | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#Fri Dec 17 21:01:08 CET 2010 | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
fullBuildGoals=process-test-resources | ||
resolveWorkspaceProjects=true | ||
resourceFilterGoals=process-resources resources\:testResources | ||
skipCompilerPlugin=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.podio</groupId> | ||
<artifactId>delicious</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>Delicious</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.podio</groupId> | ||
<artifactId>api</artifactId> | ||
<version>0.2.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.java.dev.rome</groupId> | ||
<artifactId>rome</artifactId> | ||
<version>1.0.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.java.dev.rome</groupId> | ||
<artifactId>rome-fetcher</artifactId> | ||
<version>1.0.0</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.podio.delicious; | ||
|
||
import java.util.List; | ||
|
||
public final class Bookmark { | ||
|
||
private final String id; | ||
|
||
private final String title; | ||
|
||
private final String link; | ||
|
||
private final List<String> tags; | ||
|
||
private final String notes; | ||
|
||
public Bookmark(String id, String title, String link, List<String> tags, | ||
String notes) { | ||
super(); | ||
this.id = id; | ||
this.title = title; | ||
this.link = link; | ||
this.tags = tags; | ||
this.notes = notes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Bookmark [id=" + id + ", title=" + title + ", link=" + link | ||
+ ", tags=" + tags + ", notes=" + notes + "]"; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public String getLink() { | ||
return link; | ||
} | ||
|
||
public List<String> getTags() { | ||
return tags; | ||
} | ||
|
||
public String getNotes() { | ||
return notes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.podio.delicious; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import com.podio.BaseAPI; | ||
import com.podio.item.FieldValuesUpdate; | ||
import com.podio.item.ItemAPI; | ||
import com.podio.item.ItemBadge; | ||
import com.podio.item.ItemCreate; | ||
import com.podio.oauth.OAuthClientCredentials; | ||
import com.podio.oauth.OAuthUsernameCredentials; | ||
import com.sun.syndication.feed.synd.SyndCategory; | ||
import com.sun.syndication.feed.synd.SyndEntry; | ||
import com.sun.syndication.feed.synd.SyndFeed; | ||
import com.sun.syndication.fetcher.FeedFetcher; | ||
import com.sun.syndication.fetcher.impl.FeedFetcherCache; | ||
import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache; | ||
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher; | ||
|
||
public class Reader { | ||
|
||
private static final int APP_ID = 13938; | ||
|
||
private static final int TITLE = 76687; | ||
private static final int URL = 76688; | ||
private static final int NOTES = 76689; | ||
|
||
private final String feed; | ||
|
||
private final String space; | ||
|
||
private BaseAPI podioAPI; | ||
|
||
public Reader(String configFile) throws IOException { | ||
Properties config = new Properties(); | ||
config.load(new FileInputStream(configFile)); | ||
|
||
this.podioAPI = new BaseAPI("api.nextpodio.dk", "upload.nextpodio.dk", | ||
443, true, false, new OAuthClientCredentials( | ||
config.getProperty("podio.client.mail"), | ||
config.getProperty("podio.client.secret")), | ||
new OAuthUsernameCredentials(config | ||
.getProperty("podio.user.mail"), config | ||
.getProperty("podio.user.password"))); | ||
|
||
this.feed = config.getProperty("delicious.feed"); | ||
this.space = config.getProperty("podio.space"); | ||
} | ||
|
||
public void run() throws Exception { | ||
List<Bookmark> bookmarks = loadBookmarks(); | ||
saveItems(bookmarks); | ||
} | ||
|
||
private SyndFeed getFeed() throws Exception { | ||
FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance(); | ||
FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache); | ||
return feedFetcher.retrieveFeed(new URL(feed)); | ||
} | ||
|
||
private List<Bookmark> loadBookmarks() throws Exception { | ||
SyndFeed syndFeed = getFeed(); | ||
|
||
List<Bookmark> bookmarks = new ArrayList<Bookmark>(); | ||
List<SyndEntry> entries = syndFeed.getEntries(); | ||
for (SyndEntry entry : entries) { | ||
List<String> tags = new ArrayList<String>(); | ||
List<SyndCategory> categories = entry.getCategories(); | ||
for (SyndCategory category : categories) { | ||
tags.add(category.getName()); | ||
} | ||
|
||
String id = entry.getUri().substring( | ||
entry.getUri().lastIndexOf('/') + 1, | ||
entry.getUri().lastIndexOf('#')); | ||
|
||
bookmarks.add(new Bookmark(id, entry.getTitle(), entry.getLink(), | ||
tags, entry.getDescription().getValue())); | ||
} | ||
|
||
return bookmarks; | ||
} | ||
|
||
private void saveItems(List<Bookmark> bookmarks) { | ||
ItemAPI itemAPI = new ItemAPI(podioAPI); | ||
|
||
for (Bookmark bookmark : bookmarks) { | ||
List<ItemBadge> items = itemAPI.getItemsByExternalId(APP_ID, | ||
bookmark.getId()).getItems(); | ||
if (items.size() == 0) { | ||
List<FieldValuesUpdate> fields = new ArrayList<FieldValuesUpdate>(); | ||
fields.add(new FieldValuesUpdate(TITLE, "value", bookmark | ||
.getTitle())); | ||
fields.add(new FieldValuesUpdate(URL, "value", bookmark | ||
.getLink())); | ||
fields.add(new FieldValuesUpdate(NOTES, "value", bookmark | ||
.getNotes())); | ||
|
||
itemAPI.addItem( | ||
APP_ID, | ||
new ItemCreate(bookmark.getId(), fields, Collections | ||
.<Integer> emptyList(), bookmark.getTags()), | ||
true); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
new Reader(args[0]).run(); | ||
} | ||
} |