Author: jaz
Date: Tue Feb 13 18:55:48 2007 New Revision: 507365 URL: http://svn.apache.org/viewvc?view=rev&rev=507365 Log: first pass of RSS feeds for blogs (see ecommerce) Added: ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java (with props) Modified: ofbiz/trunk/applications/content/servicedef/services.xml Modified: ofbiz/trunk/applications/content/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/servicedef/services.xml?view=diff&rev=507365&r1=507364&r2=507365 ============================================================================== --- ofbiz/trunk/applications/content/servicedef/services.xml (original) +++ ofbiz/trunk/applications/content/servicedef/services.xml Tue Feb 13 18:55:48 2007 @@ -1488,6 +1488,7 @@ <attribute name="locale" type="java.util.Locale" mode="IN" optional="true"/> <attribute name="outByteWrapper" type="org.ofbiz.entity.util.ByteWrapper" mode="OUT" optional="false"/> </service> + <!-- blog services --> <service name="persistBlogAll" engine="java" location="org.ofbiz.content.blog.BlogServices" invoke="persistBlogAll" auth="true" transaction-timeout="72000"> @@ -1508,4 +1509,12 @@ <attribute mode="IN" name="userLogin" optional="false" type="GenericValue"/> <attribute mode="OUT" name="blogList" optional="true" type="List"/> </service> + <service name="generateBlogRssFeed" engine="java" auth="false" + location="org.ofbiz.content.blog.BlogRssServices" invoke="generateBlogRssFeed"> + <description>Blog RSS Feed</description> + <implements service="rssFeedInterface"/> + <attribute name="caContentId" type="String" mode="IN" optional="false"/> + <attribute name="ownerContentId" type="String" mode="IN" optional="false"/> + </service> + </services> Added: ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java?view=auto&rev=507365 ============================================================================== --- ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java (added) +++ ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java Tue Feb 13 18:55:48 2007 @@ -0,0 +1,139 @@ +/* + 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 org.ofbiz.content.blog; + +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.ServiceUtil; +import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.condition.EntityExpr; +import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.condition.EntityConditionList; +import org.ofbiz.content.content.ContentWorker; +import com.sun.syndication.feed.synd.*; + +import java.util.*; +import java.sql.Timestamp; +import java.io.IOException; + +import javolution.util.FastList; + +/** + * BlogRssServices + */ +public class BlogRssServices { + + public static final String module = BlogRssServices.class.getName(); + public static final String mimeTypeId = "text/html"; + public static final String mapKey = "SUMMARY"; + + public static Map generateBlogRssFeed(DispatchContext dctx, Map context) { + GenericValue userLogin = (GenericValue) context.get("userLogin"); + String caContentId = (String) context.get("caContentId"); + String entryLink = (String) context.get("entryLink"); + String feedType = (String) context.get("feedType"); + Locale locale = (Locale) context.get("locale"); + + // create the main link + String mainLink = (String) context.get("mainLink"); + mainLink = mainLink + "?caContentId=" + caContentId + "&ownerContentId=" + caContentId; + + GenericDelegator delegator = dctx.getDelegator(); + + // get the main blog content + GenericValue content = null; + try { + content = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", caContentId)); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + + if (content == null) { + return ServiceUtil.returnError("Not able to generate RSS feed for content: " + caContentId); + } + + // create the feed + SyndFeed feed = new SyndFeedImpl(); + feed.setFeedType(feedType); + feed.setLink(mainLink); + + feed.setTitle(content.getString("contentName")); + feed.setDescription(content.getString("description")); + feed.setEntries(generateEntryList(delegator, caContentId, entryLink, locale, userLogin)); + + Map resp = ServiceUtil.returnSuccess(); + resp.put("wireFeed", feed.createWireFeed()); + return resp; + } + + public static List generateEntryList(GenericDelegator delegator, String contentId, String entryLink, Locale locale, GenericValue userLogin) { + Timestamp fromDate = UtilDateTime.nowTimestamp(); + + List entries = FastList.newInstance(); + List exprs = FastList.newInstance(); + exprs.add(new EntityExpr("contentIdStart", EntityOperator.EQUALS, contentId)); + exprs.add(new EntityExpr("caContentAssocTypeId", EntityOperator.EQUALS, "PUBLISH_LINK")); + exprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, "BLOG_PUBLISHED")); + + List contentRecs = null; + try { + contentRecs = delegator.findByCondition("ContentAssocViewTo", new EntityConditionList(exprs, EntityOperator.AND), null, UtilMisc.toList("-caFromDate")); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + + if (contentRecs != null) { + Iterator i = contentRecs.iterator(); + while (i.hasNext()) { + GenericValue v = (GenericValue) i.next(); + String sub = null; + try { + sub = ContentWorker.renderSubContentAsTextCache(delegator, v.getString("contentId"), mapKey, null, new HashMap(), locale, mimeTypeId, userLogin, fromDate); + } catch (GeneralException e) { + Debug.logError(e, module); + } catch (IOException e) { + Debug.logError(e, module); + } + if (sub != null) { + String thisLink = entryLink + "?articleContentId=" + v.getString("contentId") + "&ownerContentId=" + contentId; + SyndContent desc = new SyndContentImpl(); + desc.setType("text/plain"); + desc.setValue(sub); + + SyndEntry entry = new SyndEntryImpl(); + entry.setTitle(v.getString("contentName")); + entry.setPublishedDate(v.getTimestamp("createdDate")); + entry.setDescription(desc); + entry.setLink(thisLink); + // TODO: set author(s) + + entries.add(entry); + } + } + } + + return entries; + } +} \ No newline at end of file Propchange: ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/trunk/applications/content/src/org/ofbiz/content/blog/BlogRssServices.java ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |