summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/contributions/blog-feed/src/main
diff options
context:
space:
mode:
authornash <nash@13f79535-47bb-0310-9956-ffa450edef68>2009-09-15 16:55:40 +0000
committernash <nash@13f79535-47bb-0310-9956-ffa450edef68>2009-09-15 16:55:40 +0000
commit5ed1f1297a26976e1b2e81fdcd34a62b21065766 (patch)
treecb6726b824f5238441be96d5772417e58032fb4b /sandbox/travelsample/contributions/blog-feed/src/main
parentc66f84baf8c62d073148a230e4da2c0e44cd7592 (diff)
Apply new naming convention to contributions/blog-feed and launchers/blog-feed
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@815393 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/travelsample/contributions/blog-feed/src/main')
-rw-r--r--sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/BlogPost.java68
-rw-r--r--sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/AtomBlogFeedImpl.java123
-rw-r--r--sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/BaseBlogFeedImpl.java89
-rw-r--r--sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/GenericBlogFeedImpl.java75
-rw-r--r--sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/RSSBlogFeedImpl.java94
-rw-r--r--sandbox/travelsample/contributions/blog-feed/src/main/resources/META-INF/sca-contribution.xml21
-rw-r--r--sandbox/travelsample/contributions/blog-feed/src/main/resources/blog-feed.composite59
7 files changed, 529 insertions, 0 deletions
diff --git a/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/BlogPost.java b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/BlogPost.java
new file mode 100644
index 0000000000..f93fe59b9d
--- /dev/null
+++ b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/BlogPost.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.tuscanyscatours.blog;
+
+import java.util.Date;
+
+/**
+ * Bean for blog posts.
+ */
+public class BlogPost {
+
+ private final String author;
+ private final String title;
+ private final String content;
+ private final Date updated;
+ private final String link;
+ private final String related;
+
+ public BlogPost(String author, String title, String content, Date updated, String link, String related) {
+ this.author = author;
+ this.title = title;
+ this.content = content;
+ this.updated = updated;
+ this.link = link;
+ this.related = related;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public Date getUpdated() {
+ return updated;
+ }
+
+ public String getLink() {
+ return link;
+ }
+
+ public String getRelated() {
+ return related;
+ }
+}
diff --git a/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/AtomBlogFeedImpl.java b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/AtomBlogFeedImpl.java
new file mode 100644
index 0000000000..edb8e17fc1
--- /dev/null
+++ b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/AtomBlogFeedImpl.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.tuscanyscatours.blog.feed.impl;
+
+import java.util.List;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.tuscany.sca.binding.atom.collection.NotFoundException;
+
+import com.tuscanyscatours.blog.BlogPost;
+
+/**
+ * An Atom feed that implements the org.apache.tuscany.sca.binding.atom.collection.Collection
+ * interface and uses the Atom APIs to construct the Atom feed.
+ */
+public class AtomBlogFeedImpl extends BaseBlogFeedImpl implements org.apache.tuscany.sca.binding.atom.collection.Collection {
+
+ /**
+ * Gets an Atom feed containing all the blog posts.
+ *
+ * @return An Atom feed containing all the blog posts.
+ */
+ public Feed getFeed() {
+ // Create SCA Tours blog Atom feed
+ final Factory factory = Abdera.getNewFactory();
+ final Feed feed = factory.newFeed();
+ feed.setTitle(FEED_TITLE);
+ feed.setSubtitle(FEED_DESCRIPTION);
+ feed.addAuthor(FEED_AUTHOR);
+
+ // Get all blog posts and convert to Atom entries
+ final List<BlogPost> blogEntries = getAllBlogPosts();
+ for (BlogPost blogEntry : blogEntries) {
+ final Entry entry = factory.newEntry();
+ entry.setId(nextBlogID());
+ entry.addAuthor(blogEntry.getAuthor());
+ entry.setTitle(blogEntry.getTitle());
+ entry.setContentAsHtml(blogEntry.getContent());
+ entry.setUpdated(blogEntry.getUpdated());
+ entry.addLink(blogEntry.getLink());
+ feed.addEntry(entry);
+ }
+
+ return feed;
+ }
+
+ /**
+ * Query the feed.
+ *
+ * @param query The query
+ * @return Always returns null as method not implemented
+ */
+ public Feed query(String query) {
+ // Not implemented
+ return null;
+ }
+
+ /**
+ * Posts a new entry to the blog.
+ *
+ * @param entry The new entry
+ * @return Always returns null as method not implemented
+ */
+ public Entry post(Entry entry) {
+ // Not implemented
+ return null;
+ }
+
+ /**
+ * Gets the specified entry from the blog.
+ *
+ * @param id ID of the entry to get
+ * @return Not used
+ * @throws NotFoundException Always thrown as method not implemented
+ */
+ public Entry get(String id) throws NotFoundException {
+ // Not implemented
+ throw new NotFoundException("You are not allowed to update entries");
+ }
+
+ /**
+ * Updates the specified entry on the blog.
+ *
+ * @param id ID of the entry to update
+ * @param entry The new entry
+ * @throws NotFoundException Always thrown as method not implemented
+ */
+ public void put(String id, Entry entry) throws NotFoundException {
+ // Not implemented
+ throw new NotFoundException("You are not allowed to update entries");
+ }
+
+ /**
+ * Deletes the specified entry from the blog.
+ *
+ * @param id ID of the entry to delete
+ * @throws NotFoundException Always thrown as method not implemented
+ */
+ public void delete(String id) throws NotFoundException {
+ // Not implemented
+ throw new NotFoundException("You are not allowed to delete entries");
+ }
+}
diff --git a/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/BaseBlogFeedImpl.java b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/BaseBlogFeedImpl.java
new file mode 100644
index 0000000000..1579480dc7
--- /dev/null
+++ b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/BaseBlogFeedImpl.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.tuscanyscatours.blog.feed.impl;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.tuscanyscatours.blog.BlogPost;
+
+/**
+ * Base class for all blog feeds that provides the common methods
+ * that are shared by all the blog feed implementations.
+ */
+public abstract class BaseBlogFeedImpl {
+
+ /**
+ * Title of the blog.feed.
+ */
+ protected static final String FEED_TITLE = "Tuscany SCA Tours Blog Feed";
+
+ /**
+ * Description of the blog feed.
+ */
+ protected static final String FEED_DESCRIPTION = "Feed contianing the latest blog posts from Tuscany SCA Tours";
+
+ /**
+ * Author of the blog feed.
+ */
+ protected static final String FEED_AUTHOR = "SCA Tours CEO";
+
+ /**
+ * Used to generate unique IDs for the blog entries.
+ */
+ protected static final AtomicInteger ID_GEN = new AtomicInteger();
+
+ /**
+ * Generates the next blog entry ID.
+ *
+ * @return Next blog entry ID
+ */
+ protected String nextBlogID() {
+ return Integer.toString(ID_GEN.incrementAndGet());
+ }
+
+ /**
+ * Retrieves a list of all blog posts.
+ *
+ * @return A list of all blog posts.
+ */
+ public List<BlogPost> getAllBlogPosts() {
+ // Note: To keep things simple, we will just hard code a sample post.
+ // A proper implementation would load all blog posts from some resource
+ // such as files or a database.
+ List<BlogPost> blogEntries = new ArrayList<BlogPost>();
+
+ // Create a sample entry
+ final BlogPost samplePost = new BlogPost(
+ FEED_AUTHOR,
+ "Apache Tuscany in Action book features SCA Tours",
+ "We are famous as SCA Tours has been featured in the Apache Tuscany in Action book published by Manning",
+ new Date(),
+ "http://www.manning.com/laws/",
+ null);
+
+ // Add sample post to the list of posts
+ blogEntries.add(samplePost);
+
+ return blogEntries;
+ }
+}
diff --git a/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/GenericBlogFeedImpl.java b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/GenericBlogFeedImpl.java
new file mode 100644
index 0000000000..816360d4fd
--- /dev/null
+++ b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/GenericBlogFeedImpl.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.tuscanyscatours.blog.feed.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.Item;
+
+import com.tuscanyscatours.blog.BlogPost;
+
+/**
+ * Implementation of the blog feed that uses the Tuscany Data API so
+ * that it is independent of any Feed APIs such as Atom and RSS.
+ */
+public class GenericBlogFeedImpl extends BaseBlogFeedImpl {
+
+ /**
+ * Implementation of the getAll() method from the Tuscany API
+ * that will return all of the blog posts as generic Tuscany
+ * feed items.
+ *
+ * @return All blog entries
+ */
+ public Entry<Object, Object>[] getAll() {
+ final List<BlogPost> posts = getAllBlogPosts();
+
+ final Entry<Object, Object>[] entries = new Entry[posts.size()];
+ int i = 0;
+ for (BlogPost post : posts) {
+ entries[i++] = convertBlogPostToFeedItem(post);
+ }
+
+ return entries;
+ }
+
+ /**
+ * Converts a blog post to a Tuscany API feed item.
+ *
+ * @param post The blog post to convert
+ * @return The blog post as a Tuscany API feed item
+ */
+ private Entry<Object, Object> convertBlogPostToFeedItem(BlogPost post) {
+ // Convert Blog entry into an Item
+ final Item item = new Item(
+ post.getTitle(),
+ post.getContent(),
+ post.getLink(),
+ post.getRelated(),
+ post.getUpdated());
+
+ // Add item to entry
+ final Entry<Object, Object> entry = new Entry<Object, Object>(
+ nextBlogID(), item);
+
+ return entry;
+ }
+}
diff --git a/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/RSSBlogFeedImpl.java b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/RSSBlogFeedImpl.java
new file mode 100644
index 0000000000..b4526af5d0
--- /dev/null
+++ b/sandbox/travelsample/contributions/blog-feed/src/main/java/com/tuscanyscatours/blog/feed/impl/RSSBlogFeedImpl.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.tuscanyscatours.blog.feed.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.binding.rss.collection.NotFoundException;
+
+import com.tuscanyscatours.blog.BlogPost;
+
+import com.sun.syndication.feed.synd.SyndContent;
+import com.sun.syndication.feed.synd.SyndContentImpl;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndEntryImpl;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
+
+/**
+ * An RSS feed that implements the org.apache.tuscany.sca.binding.rss.collection.Collection
+ * interface and uses the RSS APIs to construct the RSS feed.
+ */
+public class RSSBlogFeedImpl extends BaseBlogFeedImpl implements org.apache.tuscany.sca.binding.rss.collection.Collection {
+
+ /**
+ * Gets an RSS feed containing all the blog posts.
+ *
+ * @return An RSS feed containing all the blog posts.
+ */
+ public SyndFeed getFeed() {
+ // Create SCA Tours blog RSS feed
+ SyndFeed feed = new SyndFeedImpl();
+ feed.setTitle(FEED_TITLE);
+ feed.setDescription(FEED_DESCRIPTION);
+ feed.setAuthor(FEED_AUTHOR);
+
+ // Get all blog posts and convert to RSS entries
+ final List<BlogPost> blogEntries = getAllBlogPosts();
+ for (BlogPost blogEntry : blogEntries) {
+ SyndEntry entry = new SyndEntryImpl();
+ entry.setUri(nextBlogID());
+ entry.setAuthor(blogEntry.getAuthor());
+ entry.setTitle(blogEntry.getTitle());
+
+ SyndContent content = new SyndContentImpl();
+ content.setType("text");
+ content.setValue(blogEntry.getContent());
+
+ entry.setPublishedDate(blogEntry.getUpdated());
+ entry.setLink(blogEntry.getLink());
+
+ feed.getEntries().add(entry);
+ }
+
+ return feed;
+ }
+
+ /**
+ * Query the feed.
+ *
+ * @param query The query
+ * @return Always returns null as method not implemented
+ */
+ public SyndFeed query(String query) {
+ // Not implemented
+ return null;
+ }
+
+ public SyndEntry get(String id) throws NotFoundException {
+ // Not implemented
+ return null;
+ }
+
+ public List<SyndEntry> getAll() throws NotFoundException {
+ // Not implemented
+ return null;
+ }
+}
diff --git a/sandbox/travelsample/contributions/blog-feed/src/main/resources/META-INF/sca-contribution.xml b/sandbox/travelsample/contributions/blog-feed/src/main/resources/META-INF/sca-contribution.xml
new file mode 100644
index 0000000000..b4152d6e3f
--- /dev/null
+++ b/sandbox/travelsample/contributions/blog-feed/src/main/resources/META-INF/sca-contribution.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0">
+</contribution> \ No newline at end of file
diff --git a/sandbox/travelsample/contributions/blog-feed/src/main/resources/blog-feed.composite b/sandbox/travelsample/contributions/blog-feed/src/main/resources/blog-feed.composite
new file mode 100644
index 0000000000..1c9cd044b3
--- /dev/null
+++ b/sandbox/travelsample/contributions/blog-feed/src/main/resources/blog-feed.composite
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ targetNamespace="http://goodvaluetrips.com/"
+ name="blog-feed">
+
+
+ <!-- Example that shows using the Tuscany Data APIs to create a feed that -->
+ <!-- is independent of the Feed API -->
+ <service name="BlogAtom" promote="BlogFeed">
+ <tuscany:binding.atom uri="http://localhost:8090/BlogAtom"/>
+ </service>
+
+ <service name="BlogRSS" promote="BlogFeed">
+ <tuscany:binding.rss uri="http://localhost:8090/BlogRSS"/>
+ </service>
+
+ <component name="BlogFeed">
+ <implementation.java class="scatours.blog.feed.GenericBlogFeedImpl"/>
+ </component>
+
+ <!-- Example that shows using the Atom Collections API to create a feed that -->
+ <!-- uses the Atom APIs -->
+ <service name="BlogAtomAPIs" promote="BlogAtom">
+ <tuscany:binding.atom uri="http://localhost:8090/BlogAtomAPIs"/>
+ </service>
+
+ <component name="BlogAtom">
+ <implementation.java class="scatours.blog.feed.AtomBlogFeedImpl"/>
+ </component>
+
+ <!-- Example that shows using the RSS Collections API to create a feed that -->
+ <!-- uses the RSS APIs -->
+ <service name="BlogRSSAPIs" promote="BlogRSS">
+ <tuscany:binding.rss uri="http://localhost:8090/BlogRSSAPIs"/>
+ </service>
+
+ <component name="BlogRSS">
+ <implementation.java class="scatours.blog.feed.RSSBlogFeedImpl"/>
+ </component>
+</composite>