Fixed loader problem in ccm-rssfeed

git-svn-id: https://svn.libreccm.org/ccm/trunk@2788 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2014-08-05 13:10:47 +00:00
parent a33cb45780
commit 4532447619
3 changed files with 225 additions and 225 deletions

View File

@ -15,9 +15,9 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.rssfeed; package com.arsdigita.rssfeed;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.kernel.ACSObject; import com.arsdigita.kernel.ACSObject;
import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.DataObject;
@ -28,9 +28,9 @@ import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.Session; import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
/** /**
* Domain object for an RSS channel. * Domain object for an RSS channel.
*
* @author Simon Buckle (sbuckle@arsdigita.com) * @author Simon Buckle (sbuckle@arsdigita.com)
*/ */
public class Feed extends ACSObject { public class Feed extends ACSObject {
@ -63,6 +63,7 @@ public class Feed extends ACSObject {
/** /**
* Constructor * Constructor
*
* @param obj * @param obj
*/ */
public Feed(DataObject obj) { public Feed(DataObject obj) {
@ -71,6 +72,7 @@ public class Feed extends ACSObject {
/** /**
* Constructor * Constructor
*
* @param oid * @param oid
*/ */
public Feed(OID oid) public Feed(OID oid)
@ -84,6 +86,7 @@ public class Feed extends ACSObject {
* @param title * @param title
* @param desc * @param desc
* @param provider * @param provider
*
* @return * @return
*/ */
public static Feed create(String url, public static Feed create(String url,
@ -103,7 +106,9 @@ public class Feed extends ACSObject {
/** /**
* *
* @param id * @param id
*
* @return * @return
*
* @throws DataObjectNotFoundException * @throws DataObjectNotFoundException
*/ */
public static Feed retrieve(BigDecimal id) public static Feed retrieve(BigDecimal id)
@ -123,11 +128,12 @@ public class Feed extends ACSObject {
throw new DataObjectNotFoundException("cannot find feed " + id); throw new DataObjectNotFoundException("cannot find feed " + id);
} }
/** /**
* *
* @param url * @param url
*
* @return * @return
*
* @throws DataObjectNotFoundException * @throws DataObjectNotFoundException
*/ */
public static Feed retrieve(String url) public static Feed retrieve(String url)
@ -208,4 +214,5 @@ public class Feed extends ACSObject {
public boolean isProvider() { public boolean isProvider() {
return ((Boolean) get(IS_PROVIDER)).booleanValue(); return ((Boolean) get(IS_PROVIDER)).booleanValue();
} }
} }

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.rssfeed; package com.arsdigita.rssfeed;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
@ -28,12 +27,13 @@ import com.arsdigita.rssfeed.portlet.WorkspaceDirectoryPortlet;
import com.arsdigita.web.Application; import com.arsdigita.web.Application;
import com.arsdigita.web.ApplicationType; import com.arsdigita.web.ApplicationType;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
import com.arsdigita.web.Web;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* Executes nonrecurring at install time and loads (installs and initializes) * Executes nonrecurring at install time and loads (installs and initializes) the ccm-rssfeed
* the ccm-rssfeed package persistently into database. * package persistently into database.
* *
* @author Justin Ross <jross@redhat.com> * @author Justin Ross <jross@redhat.com>
* @author Peter Boy <pboy@barkhof.uni-bremen.de> * @author Peter Boy <pboy@barkhof.uni-bremen.de>
@ -52,6 +52,7 @@ public class Loader extends PackageLoader {
public void run(final ScriptContext ctx) { public void run(final ScriptContext ctx) {
new KernelExcursion() { new KernelExcursion() {
@Override @Override
public void excurse() { public void excurse() {
setEffectiveParty(Kernel.getSystemParty()); setEffectiveParty(Kernel.getSystemParty());
@ -70,25 +71,23 @@ public class Loader extends PackageLoader {
(new CategoryPurpose(catKey, "RSS Feed")).save(); (new CategoryPurpose(catKey, "RSS Feed")).save();
} }
*/ */
// load application type for admin application into database // load application type for admin application into database
// (i.e. create application type) // (i.e. create application type)
setupChannelControlCenter(); setupChannelControlCenter();
// Load local feeds into database // Load local feeds into database
// setupLocalFeeds(); // currently not working, incompatible with setupLocalFeeds(); // currently not working, incompatible with
// changes in handling webapp's web context // changes in handling webapp's web context
// load portlet type into database // load portlet type into database
loadWorkspaceDirectoryPortlet(); loadWorkspaceDirectoryPortlet();
} }
}.run(); }.run();
} }
/** /**
* Creates the application type for the admin application as an * Creates the application type for the admin application as an (new style) legacy-free
* (new style) legacy-free applicaiton and an instance of the admin * applicaiton and an instance of the admin application.
* application.
*/ */
public void setupChannelControlCenter() { public void setupChannelControlCenter() {
@ -123,22 +122,26 @@ public class Loader extends PackageLoader {
*/ */
public void setupLocalFeeds() { public void setupLocalFeeds() {
URL external = URL.there("/channels/rss/external.rss", null); //URL external = URL.there("/channels/rss/external.rss", null);
String externalURL = "/channels/rss/external.rss";
try { try {
Feed feed = Feed.retrieve(external.getURL()); // Feed feed = Feed.retrieve(external.getURL());
Feed feed = Feed.retrieve(externalURL);
} catch (DataObjectNotFoundException ex) { } catch (DataObjectNotFoundException ex) {
Feed feed = Feed.create(external.getURL(), Feed feed = Feed.create(externalURL,
"External feeds", "External feeds",
"External rss content feeds", "External rss content feeds",
true); true);
feed.save(); feed.save();
} }
URL index = URL.there("/channels/rss/index.rss", null); //URL index = URL.there("/channels/rss/index.rss", null);
String indexURL = "/channels/rss/index.rss";
try { try {
Feed feed = Feed.retrieve(index.getURL()); //Feed feed = Feed.retrieve(index.getURL());
Feed feed = Feed.retrieve(indexURL);
} catch (DataObjectNotFoundException ex) { } catch (DataObjectNotFoundException ex) {
Feed feed = Feed.create(index.getURL(), Feed feed = Feed.create(indexURL,
"Local content feeds", "Local content feeds",
"Local CMS content feeds", "Local CMS content feeds",
true); true);

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.rssfeed; package com.arsdigita.rssfeed;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -51,12 +50,11 @@ import org.jdom.output.XMLOutputter;
import org.jdom.ProcessingInstruction; import org.jdom.ProcessingInstruction;
import com.arsdigita.kernel.User; import com.arsdigita.kernel.User;
/** /**
* Methods for generating RSS Channels & Items. * Methods for generating RSS Channels & Items.
* *
* This class has been extended to also generate the LAWs syndication standard * This class has been extended to also generate the LAWs syndication standard extensions to RSS
* extensions to RSS 1.0. The implementation is very basic. * 1.0. The implementation is very basic.
* *
* @author Scott Seago (sseago@redhat.com) * @author Scott Seago (sseago@redhat.com)
* @author Daniel Berrange (berrange@redhat.com) * @author Daniel Berrange (berrange@redhat.com)
@ -66,8 +64,8 @@ import com.arsdigita.kernel.User;
*/ */
public class RSSService { public class RSSService {
private static org.apache.log4j.Logger s_log = private static org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
org.apache.log4j.Logger.getLogger(RSSService.class); RSSService.class);
private static final RSSFeedConfig s_config = RSSFeedConfig.getConfig(); private static final RSSFeedConfig s_config = RSSFeedConfig.getConfig();
@ -93,30 +91,25 @@ public class RSSService {
} }
// The two namespaces used for basic rdf. rssNS is the default namespace // The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements. // for all elements.
Namespace rdfNS = Namespace rdfNS = Namespace.getNamespace(
Namespace.getNamespace(
"rdf", "rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
// The following namespaces are declared for the possible // The following namespaces are declared for the possible
// use of the LAWS extension // use of the LAWS extension
Namespace dcNS = Namespace dcNS = Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/");
Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/");
Namespace egmsNS = null; Namespace egmsNS = null;
if (useESD) { if (useESD) {
egmsNS = egmsNS = Namespace.getNamespace(
Namespace.getNamespace(
"esd", "esd",
"http://www.esd.org.uk/standards/esd/3.0/esd.rdfs"); "http://www.esd.org.uk/standards/esd/3.0/esd.rdfs");
} else { } else {
egmsNS = egmsNS = Namespace.getNamespace(
Namespace.getNamespace(
"egms", "egms",
"http://www.esd.org.uk/standards/egms/3.0/egms.rdfs"); "http://www.esd.org.uk/standards/egms/3.0/egms.rdfs");
} }
Namespace lgclNS = Namespace lgclNS = Namespace.getNamespace(
Namespace.getNamespace(
"lgcl", "lgcl",
"http://www.esd.org.uk/standards/lgcl/1.03/lgcl.rdfs"); "http://www.esd.org.uk/standards/lgcl/1.03/lgcl.rdfs");
@ -148,7 +141,8 @@ public class RSSService {
} }
Element channelLink = new Element("link", rssNS); Element channelLink = new Element("link", rssNS);
channelLink.setText((URL.there(request,null).getServerURI()).concat(URLService.locate(cat.getOID()))); channelLink.setText((URL.there(request, null).getServerURI()).concat(URLService.locate(cat
.getOID())));
channel.addContent(channelLink); channel.addContent(channelLink);
Element channelDescription = new Element("description", rssNS); Element channelDescription = new Element("description", rssNS);
@ -165,8 +159,7 @@ public class RSSService {
// the channel info, and a complete entry is added at the top level // the channel info, and a complete entry is added at the top level
// (below rdf) // (below rdf)
SortedSet items = new TreeSet(); SortedSet items = new TreeSet();
CategorizedCollection objects = CategorizedCollection objects = cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE);
cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE);
while (objects.next()) { while (objects.next()) {
ContentItem item = (ContentItem) objects.getACSObject(); ContentItem item = (ContentItem) objects.getACSObject();
@ -203,7 +196,8 @@ public class RSSService {
title = item.getDisplayName(); title = item.getDisplayName();
} }
String itemURL = (URL.there(request,null).getServerURI()).concat(URLService.locate(item.getOID())); String itemURL = (URL.there(request, null).getServerURI()).concat(URLService.locate(item
.getOID()));
s_log.debug("item is live"); s_log.debug("item is live");
@ -262,8 +256,7 @@ public class RSSService {
dcDateEl.setText(dcDateString); dcDateEl.setText(dcDateString);
itemEl.addContent(dcDateEl); itemEl.addContent(dcDateEl);
Element subjectCategoryEl = Element subjectCategoryEl = new Element("subjectCategory", egmsNS);
new Element("subjectCategory", egmsNS);
itemEl.addContent(subjectCategoryEl); itemEl.addContent(subjectCategoryEl);
Element subjectBagEl = new Element("Bag", rdfNS); Element subjectBagEl = new Element("Bag", rdfNS);
@ -275,15 +268,13 @@ public class RSSService {
// OK now we are going to see if we can find any // OK now we are going to see if we can find any
// LGCL categories for this item: // LGCL categories for this item:
Domain lgclDomain = Domain.retrieve("LGCL"); Domain lgclDomain = Domain.retrieve("LGCL");
DomainCollection terms = lgclDomain.getTerms(); DomainCollection terms = lgclDomain.getTerms();
terms.addEqualsFilter("model.childObjects.id", item.getID()); terms.addEqualsFilter("model.childObjects.id", item.getID());
if (terms != null) { if (terms != null) {
DomainCollectionIterator it = DomainCollectionIterator it = new DomainCollectionIterator(terms);
new DomainCollectionIterator(terms);
while (it.hasNext()) { while (it.hasNext()) {
@ -310,7 +301,9 @@ public class RSSService {
Document doc = new Document(); Document doc = new Document();
if (getConfig().getPIxslt() != null) { if (getConfig().getPIxslt() != null) {
doc.addContent(new ProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"" + getConfig().getPIxslt() + "\"")); doc.addContent(new ProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\""
+ getConfig().getPIxslt()
+ "\""));
} }
doc.setRootElement(rdf); doc.setRootElement(rdf);
@ -323,6 +316,7 @@ public class RSSService {
} }
private static class NewestFirstItem implements Comparable { private static class NewestFirstItem implements Comparable {
private ContentItem m_item; private ContentItem m_item;
private BigDecimal m_liveID; private BigDecimal m_liveID;
@ -342,8 +336,7 @@ public class RSSService {
public int compareTo(Object o) { public int compareTo(Object o) {
if ((o instanceof NewestFirstItem)) { if ((o instanceof NewestFirstItem)) {
return return - 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID()));
- 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID()));
} else { } else {
throw new ClassCastException("Must compare to NewestFirstItem"); throw new ClassCastException("Must compare to NewestFirstItem");
} }
@ -356,21 +349,20 @@ public class RSSService {
return false; return false;
} }
} }
} }
/** /**
* Generates an RSS channel for a specified category purpose * Generates an RSS channel for a specified category purpose
*/ */
public static void generateChannelList( public static void generateChannelList(Category root,
Category root,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) HttpServletResponse response)
throws Exception { throws Exception {
// The two namespaces used for basic rdf. rssNS is the default namespace // The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements. // for all elements.
Namespace rdfNS = Namespace rdfNS = Namespace.getNamespace(
Namespace.getNamespace(
"rdf", "rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
@ -462,15 +454,12 @@ public class RSSService {
/** /**
* Generates an RSS channel for a specified category and and all of its Articles. * Generates an RSS channel for a specified category and and all of its Articles.
*/ */
public static void generateFeedList( public static void generateFeedList(boolean acsj,
boolean acsj,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) HttpServletResponse response) throws Exception {
throws Exception {
// The two namespaces used for basic rdf. rssNS is the default namespace // The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements. // for all elements.
Namespace rdfNS = Namespace rdfNS = Namespace.getNamespace(
Namespace.getNamespace(
"rdf", "rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/"); Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
@ -571,4 +560,5 @@ public class RSSService {
return upperCamel; return upperCamel;
} }
} }