[seam-commits] Seam SVN: r8815 - in trunk/src: rss and 5 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Aug 26 10:40:17 EDT 2008


Author: nickarls
Date: 2008-08-26 10:40:17 -0400 (Tue, 26 Aug 2008)
New Revision: 8815

Added:
   trunk/src/rss/
   trunk/src/rss/build.xml
   trunk/src/rss/org/
   trunk/src/rss/org/jboss/
   trunk/src/rss/org/jboss/seam/
   trunk/src/rss/org/jboss/seam/rss/
   trunk/src/rss/org/jboss/seam/rss/ui/
   trunk/src/rss/org/jboss/seam/rss/ui/SyndicationComponent.java
   trunk/src/rss/org/jboss/seam/rss/ui/UIEntry.java
   trunk/src/rss/org/jboss/seam/rss/ui/UIFeed.java
   trunk/src/rss/seam.properties
Log:
preview for JSF rss-support

Added: trunk/src/rss/build.xml
===================================================================
--- trunk/src/rss/build.xml	                        (rev 0)
+++ trunk/src/rss/build.xml	2008-08-26 14:40:17 UTC (rev 8815)
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<project name="Concept" default="jar" basedir=".">
+
+	<fileset id="lib" dir="../../lib">
+		<include name="*.jar" />
+	</fileset>
+
+	<fileset id="yarfraw" dir="c:/java/lib/yarfraw-0.92-bin-all">
+		<include name="*.jar" />
+	</fileset>
+
+	<path id="build.classpath">
+		<fileset refid="lib" />
+		<fileset refid="yarfraw" />
+	</path>
+
+	<target name="compile">
+		<javac srcdir="." destdir="." classpathref="build.classpath" debug="on" source="1.5" />
+	</target>
+
+	<target name="jar" depends="compile">
+		<jar destfile="jboss-seam-rss.jar" basedir="." />
+	</target>
+</project>

Added: trunk/src/rss/org/jboss/seam/rss/ui/SyndicationComponent.java
===================================================================
--- trunk/src/rss/org/jboss/seam/rss/ui/SyndicationComponent.java	                        (rev 0)
+++ trunk/src/rss/org/jboss/seam/rss/ui/SyndicationComponent.java	2008-08-26 14:40:17 UTC (rev 8815)
@@ -0,0 +1,21 @@
+package org.jboss.seam.rss.ui;
+
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+public abstract class SyndicationComponent extends UIComponentBase
+{
+   protected static final String FEED_IMPL_KEY = "theFeed";
+   protected static final String ATOM_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+
+   protected Object valueOf(String name, Object defaultValue)
+   {
+      Object value = defaultValue;
+      if (getValueExpression(name) != null)
+      {
+         value = getValueExpression(name).getValue(FacesContext.getCurrentInstance().getELContext());
+      }
+      return value;
+   }
+   
+}

Added: trunk/src/rss/org/jboss/seam/rss/ui/UIEntry.java
===================================================================
--- trunk/src/rss/org/jboss/seam/rss/ui/UIEntry.java	                        (rev 0)
+++ trunk/src/rss/org/jboss/seam/rss/ui/UIEntry.java	2008-08-26 14:40:17 UTC (rev 8815)
@@ -0,0 +1,162 @@
+package org.jboss.seam.rss.ui;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.jboss.seam.contexts.Contexts;
+import javax.faces.context.FacesContext;
+
+import yarfraw.core.datamodel.ChannelFeed;
+import yarfraw.core.datamodel.Content;
+import yarfraw.core.datamodel.ItemEntry;
+import yarfraw.core.datamodel.Link;
+import yarfraw.core.datamodel.Person;
+import yarfraw.core.datamodel.Text;
+import yarfraw.core.datamodel.Text.TextType;
+
+/**
+ *atomEntry =
+   element atom:entry {
+      atomCommonAttributes,
+      (atomAuthor*
+       & atomCategory*
+       & atomContent?
+       & atomContributor*
+       & atomId
+       & atomLink*
+       & atomPublished?
+       & atomRights?
+       & atomSource?
+       & atomSummary?
+       & atomTitle
+       & atomUpdated
+       & extensionElement*)
+   }
+ */
+
+public class UIEntry extends SyndicationComponent
+{
+   private static final String COMPONENT_TYPE = "org.jboss.seam.rss.ui.UIEntry";
+
+   private String uid;
+   private String title;
+   private String link;
+   private String author;
+   private String summary;
+   private Date published;
+   private Date updated;
+
+   @Override
+   public String getFamily()
+   {
+      return COMPONENT_TYPE;
+   }
+
+
+   @SuppressWarnings("unchecked")
+   @Override
+   public void encodeBegin(FacesContext facesContext) throws IOException
+   {
+      ChannelFeed channelFeed = (ChannelFeed) Contexts.getEventContext().get(FEED_IMPL_KEY);
+
+      ItemEntry itemEntry = new ItemEntry();
+      itemEntry.setUid(getUid());
+      itemEntry.setTitle(getTitle());
+      itemEntry.addLink(getLink());
+      String author = getAuthor();
+      if (author != null) {
+         Person authorPerson = new Person();
+         authorPerson.setName(author);
+         itemEntry.addAuthorOrCreator(authorPerson);
+      }
+      itemEntry.setDescriptionOrSummary(getSummary());
+      itemEntry.setUpdatedDate(getUpdated(), new SimpleDateFormat(ATOM_DATE_FORMAT));
+      itemEntry.setPubDate(getPublished(), new SimpleDateFormat(ATOM_DATE_FORMAT));
+      
+      channelFeed.addItem(itemEntry);   
+   }
+
+   public String getTitle()
+   {
+      return (String) valueOf("title", title);
+   }
+
+
+   public void setTitle(String title)
+   {
+      this.title = title;
+   }
+
+
+   public String getLink()
+   {
+      return (String) valueOf("link", link);
+   }
+
+
+   public void setLink(String link)
+   {
+      this.link = link;
+   }
+
+
+   public String getAuthor()
+   {
+      return (String) valueOf("author", author);
+   }
+
+
+   public void setAuthor(String author)
+   {
+      this.author = author;
+   }
+
+
+   public String getSummary()
+   {
+      return (String) valueOf("summary", summary);
+   }
+
+
+   public void setSummary(String summary)
+   {
+      this.summary = summary;
+   }
+
+   public Date getPublished()
+   {
+      return (Date) valueOf("published", published);
+   }
+
+
+   public void setPublished(Date published)
+   {
+      this.published = published;
+   }
+
+
+   public Date getUpdated()
+   {
+      return (Date) valueOf("updated", updated);
+   }
+
+
+   public void setUpdated(Date updated)
+   {
+      this.updated = updated;
+   }
+
+
+   public String getUid()
+   {
+      return (String) valueOf("uid", uid);
+   }
+
+
+   public void setUid(String uid)
+   {
+      this.uid = uid;
+   }   
+
+}

Added: trunk/src/rss/org/jboss/seam/rss/ui/UIFeed.java
===================================================================
--- trunk/src/rss/org/jboss/seam/rss/ui/UIFeed.java	                        (rev 0)
+++ trunk/src/rss/org/jboss/seam/rss/ui/UIFeed.java	2008-08-26 14:40:17 UTC (rev 8815)
@@ -0,0 +1,218 @@
+package org.jboss.seam.rss.ui;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
+import javax.faces.context.FacesContext;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.document.DocumentData;
+import org.jboss.seam.document.DocumentStore;
+import org.jboss.seam.document.DocumentData.DocumentType;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.navigation.Pages;
+
+import yarfraw.core.datamodel.ChannelFeed;
+import yarfraw.core.datamodel.FeedFormat;
+import yarfraw.core.datamodel.Text;
+import yarfraw.core.datamodel.YarfrawException;
+import yarfraw.core.datamodel.Text.TextType;
+import yarfraw.io.FeedWriter;
+
+/*
+ * atomFeed =
+   element atom:feed {
+      atomCommonAttributes,
+      (atomAuthor*
+       & atomCategory*
+       & atomContributor*
+       & atomGenerator?
+       & atomIcon?
+       & atomId
+       & atomLink*
+       & atomLogo?
+       & atomRights?
+       & atomSubtitle?
+       & atomTitle
+       & atomUpdated
+       & extensionElement*),
+      atomEntry*
+   }
+ */
+
+public class UIFeed extends SyndicationComponent
+{
+   private static final String COMPONENT_TYPE = "org.jboss.seam.rss.ui.UIFeed";
+   private static final String EXTENSION = "xml";
+   private static final String MIMETYPE = "text/xml";
+   private static final FeedFormat DEFAULT_FEED_FORMAT = FeedFormat.ATOM10;
+
+   private boolean sendRedirect = true;
+
+   private FeedFormat feedFormat = DEFAULT_FEED_FORMAT;
+   private String uid;
+   private String title;
+   private String subtitle;
+   private Date updated;
+   private String link;
+
+
+   @SuppressWarnings("unchecked")
+   @Override
+   public void encodeBegin(FacesContext facesContext) throws IOException
+   {
+      ChannelFeed channelFeed = new ChannelFeed();
+      channelFeed.setUid(getUid());
+      channelFeed.setTitle(getTitle());
+      channelFeed.setDescriptionOrSubtitle(getSubtitle());
+      channelFeed.setPubDate(getUpdated(), new SimpleDateFormat(ATOM_DATE_FORMAT));
+      channelFeed.addLink(getLink());
+      Contexts.getEventContext().set(FEED_IMPL_KEY, channelFeed);
+   }
+
+   @Override
+   public void encodeEnd(FacesContext facesContext) throws IOException
+   {
+      ChannelFeed channelFeed = (ChannelFeed) Contexts.getEventContext().get(FEED_IMPL_KEY);
+      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+      try {
+         FeedWriter.writeChannel(DEFAULT_FEED_FORMAT, channelFeed, byteStream);
+      } catch (YarfrawException e) {
+         throw new IOException("Could not create feed", e);
+      }
+      byteStream.flush();
+      String x = byteStream.toString();
+      DocumentType documentType = new DocumentData.DocumentType(EXTENSION, MIMETYPE);
+
+      String viewId = Pages.getViewId(facesContext);
+      String baseName = baseNameForViewId(viewId);
+
+      DocumentData documentData = new DocumentData(baseName, documentType, byteStream.toByteArray());
+
+      if (sendRedirect)
+      {
+         DocumentStore store = DocumentStore.instance();
+         String id = store.newId();
+
+         String url = store.preferredUrlForContent(baseName, documentType.getExtension(), id);
+         url = Manager.instance().encodeConversationId(url, viewId);
+
+         store.saveData(id, documentData);
+
+         facesContext.getExternalContext().redirect(url);
+
+      }
+      else
+      {
+         UIComponent parent = getParent();
+
+         if (parent instanceof ValueHolder)
+         {
+            ValueHolder holder = (ValueHolder) parent;
+            holder.setValue(documentData);
+         }
+      }
+   }
+
+   public static String baseNameForViewId(String viewId)
+   {
+      int pos = viewId.lastIndexOf("/");
+      if (pos != -1)
+      {
+         viewId = viewId.substring(pos + 1);
+      }
+
+      pos = viewId.lastIndexOf(".");
+      if (pos != -1)
+      {
+         viewId = viewId.substring(0, pos);
+      }
+
+      return viewId;
+   }
+
+   public boolean isSendRedirect()
+   {
+      return sendRedirect;
+   }
+
+   public void setSendRedirect(boolean sendRedirect)
+   {
+      this.sendRedirect = sendRedirect;
+   }
+
+   @Override
+   public String getFamily()
+   {
+      return COMPONENT_TYPE;
+   }
+
+   public String getTitle()
+   {
+      return (String) valueOf("title", title);
+   }
+
+   public void setTitle(String title)
+   {
+      this.title = title;
+   }
+
+   public String getSubtitle()
+   {
+      return (String) valueOf("subtitle", subtitle);
+   }
+
+   public void setSubtitle(String subtitle)
+   {
+      this.subtitle = subtitle;
+   }
+
+   public Date getUpdated()
+   {
+      return (Date) valueOf("updated", updated);
+   }
+
+   public void setUpdated(Date updated)
+   {
+      this.updated = updated;
+   }
+
+   public String getLink()
+   {
+      return (String) valueOf("link", link);
+   }
+
+   public void setLink(String link)
+   {
+      this.link = link;
+   }
+
+   public String getFeedFormat()
+   {
+      return (String) valueOf("feedFormat", feedFormat);
+   }
+
+   public void setFeedFormat(FeedFormat feedFormat)
+   {
+      this.feedFormat = feedFormat;
+   }
+
+   public String getUid()
+   {
+      return (String) valueOf("uid", uid);
+   }
+
+   public void setUid(String uid)
+   {
+      this.uid = uid;
+   }
+
+
+}

Added: trunk/src/rss/seam.properties
===================================================================




More information about the seam-commits mailing list