Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPORTAL-2881 adding better error feedback to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
vrockai authored and nscavell committed Apr 8, 2013
1 parent 3b2f86e commit d0872d2
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.PortletRequestDispatcher;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;

/**
* @author <a href="mailto:vrockai@redhat.com">Viliam Rockai</a>
* @version $Revision$
*/
* @author <a href="mailto:vrockai@redhat.com">Viliam Rockai</a>
* @version $Revision$
*/
public class CommunityPortlet extends GenericPortlet {

private String DEFAULT_URL = "/#";
Expand All @@ -43,6 +45,7 @@ public class CommunityPortlet extends GenericPortlet {
private String URL_CONTENT_BLOG = "url.blog";
private String URL_CONTENT_TWITTER = "url.twitter";
private String PFX_BLOG_AUTHOR = "pfx.url.author";
private static final Logger log = LoggerFactory.getLogger(CommunityPortlet.class);

@Override
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
Expand All @@ -55,25 +58,30 @@ protected void doView(RenderRequest request, RenderResponse response) throws Por
String urlContentTwitter = portletPreferences.getValue(URL_CONTENT_TWITTER, DEFAULT_URL);
String pfxBlogAuthor = portletPreferences.getValue(PFX_BLOG_AUTHOR, "");

RomeRssControllerBean romeRssControllerBean = new RomeRssControllerBean();

URL gateInBlog = new URL(urlRssBlog);

RssReaderBean gateInBlogRssReader = new RssReaderBean();
gateInBlogRssReader.setFeedTitles(romeRssControllerBean.getFeedTitles(gateInBlog, 2));
gateInBlogRssReader.setAuthorUrlPrefix(pfxBlogAuthor);
gateInBlogRssReader.setContentSource(new URL(urlContentBlog));

URL gateInTwitter = new URL(urlRssTwitter);

RssReaderBean gateInTwitterRssReader = new RssReaderBean();
gateInTwitterRssReader.setFeedTitles(romeRssControllerBean.getFeedTitles(gateInTwitter, 2));
gateInTwitterRssReader.setContentSource(new URL(urlContentTwitter));
RssReaderBean gateInBlogRssReader = makeReaderBean(urlRssBlog, urlContentBlog, 2, pfxBlogAuthor);
RssReaderBean gateInTwitterRssReader = makeReaderBean(urlRssTwitter, urlContentTwitter, 2, null);

request.setAttribute("blogRSSBean", gateInBlogRssReader);
request.setAttribute("twitterRSSBean", gateInTwitterRssReader);

PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/jsp/community.jsp");
prd.include(request, response);
}

private RssReaderBean makeReaderBean(String urlRss, String urlContent, int head, String pfxBlogAuthor) {
RssReaderBean rssReaderBean = new RssReaderBean();

try {
URL rssSourceUrl = new URL(urlRss);
rssReaderBean.setFeedTitles(RomeRssControllerBean.getFeedTitles(rssSourceUrl, head));
rssReaderBean.setContentSource(new URL(urlContent));
rssReaderBean.setAuthorUrlPrefix(pfxBlogAuthor);
} catch (IOException e) {
rssReaderBean.setValid(false);
rssReaderBean.setSourceIO(urlRss);
log.error("Unable to open RSS feed url: " + e);
}

return rssReaderBean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,54 +37,50 @@
import org.gatein.common.logging.LoggerFactory;

/**
* @author <a href="mailto:vrockai@redhat.com">Viliam Rockai</a>
* @version $Revision$
*/
* @author <a href="mailto:vrockai@redhat.com">Viliam Rockai</a>
* @version $Revision$
*/
public class RomeRssControllerBean {

private static final Logger log = LoggerFactory.getLogger(RomeRssControllerBean.class);

public List<RssTitleBean> getFeedTitles(URL source, int headsize) {
public static List<RssTitleBean> getFeedTitles(URL source, int headsize) throws IOException {
List<RssTitleBean> rssTitleBeanList = new ArrayList<RssTitleBean>();
XmlReader reader = null;

try {
try {
reader = new XmlReader(source);
SyndFeed feed = new SyndFeedInput().build(reader);
reader = new XmlReader(source);
SyndFeed feed = new SyndFeedInput().build(reader);

for (Iterator i = feed.getEntries().iterator(); i.hasNext() && (headsize-- > 0);) {
SyndEntry entry = (SyndEntry) i.next();
for (Iterator i = feed.getEntries().iterator(); i.hasNext() && (headsize-- > 0);) {
SyndEntry entry = (SyndEntry) i.next();

RssTitleBean rssTitleBean = new RssTitleBean();
rssTitleBean.setTitle(entry.getTitle());
rssTitleBean.setLink(entry.getLink());
rssTitleBean.setPublishedDate(entry.getPublishedDate());
RssTitleBean rssTitleBean = new RssTitleBean();
rssTitleBean.setTitle(entry.getTitle());
rssTitleBean.setLink(entry.getLink());
rssTitleBean.setPublishedDate(entry.getPublishedDate());

List<RssAuthorBean> rssAuthors = new ArrayList<RssAuthorBean>();
List<RssAuthorBean> rssAuthors = new ArrayList<RssAuthorBean>();

for (SyndPerson author : (List<SyndPerson>) entry.getAuthors()) {
RssAuthorBean rssAuthorBean = new RssAuthorBean();
rssAuthorBean.setName(author.getName());
rssAuthorBean.setUri(author.getUri());
for (SyndPerson author : (List<SyndPerson>) entry.getAuthors()) {
RssAuthorBean rssAuthorBean = new RssAuthorBean();
rssAuthorBean.setName(author.getName());
rssAuthorBean.setUri(author.getUri());

rssAuthors.add(rssAuthorBean);
}
rssAuthors.add(rssAuthorBean);
}

rssTitleBean.setAuthors(rssAuthors);
rssTitleBean.setAuthors(rssAuthors);

rssTitleBeanList.add(rssTitleBean);
}
} catch (FeedException e) {
log.error("RSS Feed related exception: " + e);
rssTitleBeanList.add(rssTitleBean);
}
} catch (FeedException e) {
log.error("RSS Feed related exception: " + e);

} finally {
if (reader != null) {
reader.close();
}
} finally {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
log.error("Unable to open RSS feed url: " + e);
}

return rssTitleBeanList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ public class RssReaderBean {
private String authorUrlPrefix = "";
private List<RssTitleBean> feedTitles = new ArrayList<RssTitleBean>();

private boolean valid = true;
private String sourceIO = "";

public boolean isValid() {
return valid;
}

public void setValid(boolean isValid) {
this.valid = isValid;
}

public String getSourceIO() {
return sourceIO;
}

public void setSourceIO(String sourceIO) {
this.sourceIO = sourceIO;
}

public String getAuthorUrlPrefix() {
return authorUrlPrefix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ conversation.blog.label=Blog Entries
conversation.blog.link=All blog posts \u00bb
conversation.twitter.label=Latest Tweet
conversation.twitter.link=All tweets \u00bb
conversation.io.error=Unable to read properly from the specified source:

documentation.label=Documentation
documentation.content=The information you need about the latest stable and development releases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@
list-style: none;
}

.gtnResponsiveCommunityPortlet #tweets-content-mobile p {
.gtnResponsiveCommunityPortlet #tweets-content-mobile a {
display: block;
font-size: 0.875em;
margin-top: .75em;
margin-bottom: 0;
}

Expand Down Expand Up @@ -233,6 +235,18 @@
text-indent: -99999px;
}

.gtnResponsiveCommunityPortlet .errorPane {
margin: .25em 1.25em 1.25em 1.25em;
color: #e33;
}

.gtnResponsiveCommunityPortlet #tweets-content-mobile .errorPane a,
.gtnResponsiveCommunityPortlet .errorPane > a,
.gtnResponsiveCommunityPortlet .errorPane > p {
font-size: 1em;
margin: 0;
}

@media only screen and (min-width: 30em) {
.gtnResponsiveCommunityPortlet #documentation i {
background: url("../images/welcome-book.png") no-repeat scroll left top transparent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,35 @@
<i class="icon-blog icon-gray"></i>${resourceBundle.getString("conversation.blog.label")}
</a>
<div class="accordion-body collapse in" id="blog-content-mobile">
<ul>
<c:forEach var="blogArticle" items="${blogRSSBean.feedTitles}">
<h6>
<a href="${blogArticle.link}">${blogArticle.title}</a>
</h6>
<div class="info">
<span>
<c:forEach var="author" items="${blogArticle.authors}">
<a href="${blogRSSBean.authorUrlPrefix}${author.uri}">${author.name}</a>
</c:forEach>
</span>
<c:choose>
<c:when test="${blogRSSBean.valid}">
<ul>
<c:forEach var="blogArticle" items="${blogRSSBean.feedTitles}">
<h6>
<a href="${blogArticle.link}">${blogArticle.title}</a>
</h6>
<div class="info">
<span>
<c:forEach var="author" items="${blogArticle.authors}">
<a href="${blogRSSBean.authorUrlPrefix}${author.uri}">${author.name}</a>
</c:forEach>
</span>

<span>
<fmt:formatDate value="${blogArticle.publishedDate}" pattern="dd MMM" />
</span>
<span>
<fmt:formatDate value="${blogArticle.publishedDate}" pattern="dd MMM" />
</span>
</div>
</c:forEach>
</ul>
<a href="${blogRSSBean.contentSource}">${resourceBundle.getString("conversation.blog.link")}</a>
</c:when>
<c:otherwise>
<div class="errorPane">
<p>${resourceBundle.getString("conversation.io.error")}</p>
<a href="${blogRSSBean.sourceIO}">${blogRSSBean.sourceIO}</a>
</div>
</c:forEach>
</ul>
<a href="${blogRSSBean.contentSource}">${resourceBundle.getString("conversation.blog.link")}</a>
</c:otherwise>
</c:choose>
</div>
</div>

Expand All @@ -60,21 +70,29 @@
<i class="icon-twitter icon-gray"></i>${resourceBundle.getString("conversation.twitter.label")}
</a>
<div class="accordion-body collapse" id="tweets-content-mobile">
<ul>
<c:forEach var="twitterTweet" items="${twitterRSSBean.feedTitles}">
<li>
<p>
<a href="${twitterTweet.link}">${twitterTweet.title}</a>
</p>
<div class="info">
<span>
<fmt:formatDate value="${twitterTweet.publishedDate}" pattern="dd MMM" />
</span>
</div>
</li>
</c:forEach>
</ul>
<a href="${twitterRSSBean.contentSource}">${resourceBundle.getString("conversation.twitter.link")}</a>
<c:choose>
<c:when test="${twitterRSSBean.valid}">
<ul>
<c:forEach var="twitterTweet" items="${twitterRSSBean.feedTitles}">
<li>
<a href="${twitterTweet.link}">${twitterTweet.title}</a>
<div class="info">
<span>
<fmt:formatDate value="${twitterTweet.publishedDate}" pattern="dd MMM" />
</span>
</div>
</li>
</c:forEach>
</ul>
<a href="${twitterRSSBean.contentSource}">${resourceBundle.getString("conversation.twitter.link")}</a>
</c:when>
<c:otherwise>
<div class="errorPane">
<p>${resourceBundle.getString("conversation.io.error")}</p>
<a href="${twitterRSSBean.sourceIO}">${twitterRSSBean.sourceIO}</a>
</div>
</c:otherwise>
</c:choose>
</div>
</div>
</div>
Expand Down

0 comments on commit d0872d2

Please sign in to comment.