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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.arsdigita.rssfeed;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.persistence.DataObject;
@ -28,15 +28,15 @@ import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.DataCollection;
/**
* Domain object for an RSS channel.
*
* @author Simon Buckle (sbuckle@arsdigita.com)
*/
public class Feed extends ACSObject {
public static final String BASE_DATA_OBJECT_TYPE
= "com.arsdigita.rssfeed.Feed";
= "com.arsdigita.rssfeed.Feed";
// Attributes
public static final String TITLE = "title";
@ -63,6 +63,7 @@ public class Feed extends ACSObject {
/**
* Constructor
*
* @param obj
*/
public Feed(DataObject obj) {
@ -71,6 +72,7 @@ public class Feed extends ACSObject {
/**
* Constructor
*
* @param oid
*/
public Feed(OID oid)
@ -84,6 +86,7 @@ public class Feed extends ACSObject {
* @param title
* @param desc
* @param provider
*
* @return
*/
public static Feed create(String url,
@ -103,7 +106,9 @@ public class Feed extends ACSObject {
/**
*
* @param id
*
* @return
*
* @throws DataObjectNotFoundException
*/
public static Feed retrieve(BigDecimal id)
@ -123,15 +128,16 @@ public class Feed extends ACSObject {
throw new DataObjectNotFoundException("cannot find feed " + id);
}
/**
*
* @param url
*
* @return
*
* @throws DataObjectNotFoundException
*/
public static Feed retrieve(String url)
throws DataObjectNotFoundException {
throws DataObjectNotFoundException {
Session session = SessionManager.getSession();
DataCollection feed = session.retrieve(BASE_DATA_OBJECT_TYPE);
@ -176,7 +182,7 @@ public class Feed extends ACSObject {
}
public String getTitle() {
return (String)get(TITLE);
return (String) get(TITLE);
}
/*
@ -187,7 +193,7 @@ public class Feed extends ACSObject {
}
public String getURL() {
return (String)get(URL);
return (String) get(URL);
}
/*
@ -198,7 +204,7 @@ public class Feed extends ACSObject {
}
public String getDescription() {
return (String)get(DESCRIPTION);
return (String) get(DESCRIPTION);
}
public void setProvider(boolean provider) {
@ -206,6 +212,7 @@ public class Feed extends ACSObject {
}
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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.arsdigita.rssfeed;
import com.arsdigita.domain.DataObjectNotFoundException;
@ -28,12 +27,13 @@ import com.arsdigita.rssfeed.portlet.WorkspaceDirectoryPortlet;
import com.arsdigita.web.Application;
import com.arsdigita.web.ApplicationType;
import com.arsdigita.web.URL;
import com.arsdigita.web.Web;
import org.apache.log4j.Logger;
/**
* Executes nonrecurring at install time and loads (installs and initializes)
* the ccm-rssfeed package persistently into database.
* Executes nonrecurring at install time and loads (installs and initializes) the ccm-rssfeed
* package persistently into database.
*
* @author Justin Ross <jross@redhat.com>
* @author Peter Boy <pboy@barkhof.uni-bremen.de>
@ -52,6 +52,7 @@ public class Loader extends PackageLoader {
public void run(final ScriptContext ctx) {
new KernelExcursion() {
@Override
public void excurse() {
setEffectiveParty(Kernel.getSystemParty());
@ -64,31 +65,29 @@ public class Loader extends PackageLoader {
// RSS currently depends on an existing category domain in terms
// an a domain mapping to this applicaion.
/*
String catKey = RSSFeed.getConfig().getCategoryKey();
s_log.info("Setting RSS Category Key to " + catKey + ".");
if (!CategoryPurpose.purposeExists(catKey)) {
(new CategoryPurpose(catKey, "RSS Feed")).save();
}
String catKey = RSSFeed.getConfig().getCategoryKey();
s_log.info("Setting RSS Category Key to " + catKey + ".");
if (!CategoryPurpose.purposeExists(catKey)) {
(new CategoryPurpose(catKey, "RSS Feed")).save();
}
*/
// load application type for admin application into database
// (i.e. create application type)
setupChannelControlCenter();
// Load local feeds into database
// setupLocalFeeds(); // currently not working, incompatible with
// changes in handling webapp's web context
setupLocalFeeds(); // currently not working, incompatible with
// changes in handling webapp's web context
// load portlet type into database
loadWorkspaceDirectoryPortlet();
}
}.run();
}
/**
* Creates the application type for the admin application as an
* (new style) legacy-free applicaiton and an instance of the admin
* application.
* Creates the application type for the admin application as an (new style) legacy-free
* applicaiton and an instance of the admin application.
*/
public void setupChannelControlCenter() {
@ -100,8 +99,8 @@ public class Loader extends PackageLoader {
* hyphen and converted to lower case.
* "RSSFeed" will become "rssfeed". */
ApplicationType type = new ApplicationType(
"RSS Feed",
RSSFeed.BASE_DATA_OBJECT_TYPE );
"RSS Feed",
RSSFeed.BASE_DATA_OBJECT_TYPE);
type.setSingleton(true);
type.setDescription("Provides RSS feed service");
@ -109,10 +108,10 @@ public class Loader extends PackageLoader {
"/channels/")) {
// create an (singelton) application instance
Application app = Application
.createApplication(type,
"channels",
"RSS Service",
null);
.createApplication(type,
"channels",
"RSS Service",
null);
app.setDescription("RSS feed channels");
app.save();
}
@ -123,22 +122,26 @@ public class Loader extends PackageLoader {
*/
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 {
Feed feed = Feed.retrieve(external.getURL());
// Feed feed = Feed.retrieve(external.getURL());
Feed feed = Feed.retrieve(externalURL);
} catch (DataObjectNotFoundException ex) {
Feed feed = Feed.create(external.getURL(),
Feed feed = Feed.create(externalURL,
"External feeds",
"External rss content feeds",
true);
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 {
Feed feed = Feed.retrieve(index.getURL());
//Feed feed = Feed.retrieve(index.getURL());
Feed feed = Feed.retrieve(indexURL);
} catch (DataObjectNotFoundException ex) {
Feed feed = Feed.create(index.getURL(),
Feed feed = Feed.create(indexURL,
"Local content feeds",
"Local CMS content feeds",
true);
@ -146,11 +149,11 @@ public class Loader extends PackageLoader {
}
}
private void loadWorkspaceDirectoryPortlet() {
PortletType type = PortletType.createPortletType("Workspace Directory",
PortletType.WIDE_PROFILE,
WorkspaceDirectoryPortlet.BASE_DATA_OBJECT_TYPE);
type.setDescription("Displays a list of workspaces");
}
private void loadWorkspaceDirectoryPortlet() {
PortletType type = PortletType.createPortletType("Workspace Directory",
PortletType.WIDE_PROFILE,
WorkspaceDirectoryPortlet.BASE_DATA_OBJECT_TYPE);
type.setDescription("Displays a list of workspaces");
}
}

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.arsdigita.rssfeed;
import javax.servlet.http.HttpServletRequest;
@ -51,12 +50,11 @@ import org.jdom.output.XMLOutputter;
import org.jdom.ProcessingInstruction;
import com.arsdigita.kernel.User;
/**
* Methods for generating RSS Channels & Items.
*
* This class has been extended to also generate the LAWs syndication standard
* extensions to RSS 1.0. The implementation is very basic.
* This class has been extended to also generate the LAWs syndication standard extensions to RSS
* 1.0. The implementation is very basic.
*
* @author Scott Seago (sseago@redhat.com)
* @author Daniel Berrange (berrange@redhat.com)
@ -66,8 +64,8 @@ import com.arsdigita.kernel.User;
*/
public class RSSService {
private static org.apache.log4j.Logger s_log =
org.apache.log4j.Logger.getLogger(RSSService.class);
private static org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
RSSService.class);
private static final RSSFeedConfig s_config = RSSFeedConfig.getConfig();
@ -79,10 +77,10 @@ public class RSSService {
* Generates an RSS channel for a specified category and and all of its Articles.
*/
public static void generateChannel(
BigDecimal categoryId,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
BigDecimal categoryId,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
Category cat = new Category(categoryId);
boolean useLAWs = "laws-1.0".equals(request.getParameter("extension"));
@ -93,32 +91,27 @@ public class RSSService {
}
// The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements.
Namespace rdfNS =
Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rdfNS = Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
// The following namespaces are declared for the possible
// use of the LAWS extension
Namespace dcNS =
Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/");
Namespace dcNS = Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/");
Namespace egmsNS = null;
if (useESD) {
egmsNS =
Namespace.getNamespace(
"esd",
"http://www.esd.org.uk/standards/esd/3.0/esd.rdfs");
egmsNS = Namespace.getNamespace(
"esd",
"http://www.esd.org.uk/standards/esd/3.0/esd.rdfs");
} else {
egmsNS =
Namespace.getNamespace(
"egms",
"http://www.esd.org.uk/standards/egms/3.0/egms.rdfs");
egmsNS = Namespace.getNamespace(
"egms",
"http://www.esd.org.uk/standards/egms/3.0/egms.rdfs");
}
Namespace lgclNS =
Namespace.getNamespace(
"lgcl",
"http://www.esd.org.uk/standards/lgcl/1.03/lgcl.rdfs");
Namespace lgclNS = Namespace.getNamespace(
"lgcl",
"http://www.esd.org.uk/standards/lgcl/1.03/lgcl.rdfs");
// rdf is the root element
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
@ -132,9 +125,9 @@ public class RSSService {
// Channel info
Element channel = new Element("channel", rssNS);
channel.setAttribute(
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS);
@ -148,7 +141,8 @@ public class RSSService {
}
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);
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
// (below rdf)
SortedSet items = new TreeSet();
CategorizedCollection objects =
cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE);
CategorizedCollection objects = cat.getObjects(ContentItem.BASE_DATA_OBJECT_TYPE);
while (objects.next()) {
ContentItem item = (ContentItem) objects.getACSObject();
@ -203,7 +196,8 @@ public class RSSService {
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");
@ -228,7 +222,7 @@ public class RSSService {
if (description != null) {
Element descEl = new Element("description", rssNS);
descEl.setText(
com.arsdigita.util.StringUtils.truncateString(
com.arsdigita.util.StringUtils.truncateString(
description,
100,
true)
@ -262,8 +256,7 @@ public class RSSService {
dcDateEl.setText(dcDateString);
itemEl.addContent(dcDateEl);
Element subjectCategoryEl =
new Element("subjectCategory", egmsNS);
Element subjectCategoryEl = new Element("subjectCategory", egmsNS);
itemEl.addContent(subjectCategoryEl);
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
// LGCL categories for this item:
Domain lgclDomain = Domain.retrieve("LGCL");
DomainCollection terms = lgclDomain.getTerms();
terms.addEqualsFilter("model.childObjects.id", item.getID());
if (terms != null) {
DomainCollectionIterator it =
new DomainCollectionIterator(terms);
DomainCollectionIterator it = new DomainCollectionIterator(terms);
while (it.hasNext()) {
@ -309,8 +300,10 @@ public class RSSService {
// Write XML to the output stream
Document doc = new Document();
if (getConfig().getPIxslt()!= null) {
doc.addContent(new ProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"" + getConfig().getPIxslt() + "\""));
if (getConfig().getPIxslt() != null) {
doc.addContent(new ProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\""
+ getConfig().getPIxslt()
+ "\""));
}
doc.setRootElement(rdf);
@ -323,6 +316,7 @@ public class RSSService {
}
private static class NewestFirstItem implements Comparable {
private ContentItem m_item;
private BigDecimal m_liveID;
@ -342,8 +336,7 @@ public class RSSService {
public int compareTo(Object o) {
if ((o instanceof NewestFirstItem)) {
return
- 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID()));
return - 1 * (m_liveID.compareTo(((NewestFirstItem) o).getLiveID()));
} else {
throw new ClassCastException("Must compare to NewestFirstItem");
}
@ -356,23 +349,22 @@ public class RSSService {
return false;
}
}
}
/**
* Generates an RSS channel for a specified category purpose
*/
public static void generateChannelList(
Category root,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
public static void generateChannelList(Category root,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements.
Namespace rdfNS =
Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rdfNS = Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
// rdf is the root element
@ -382,9 +374,9 @@ public class RSSService {
// Channel info
Element channel = new Element("channel", rssNS);
channel.setAttribute(
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS);
@ -462,17 +454,14 @@ public class RSSService {
/**
* Generates an RSS channel for a specified category and and all of its Articles.
*/
public static void generateFeedList(
boolean acsj,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
public static void generateFeedList(boolean acsj,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
// The two namespaces used for basic rdf. rssNS is the default namespace
// for all elements.
Namespace rdfNS =
Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rdfNS = Namespace.getNamespace(
"rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
Namespace rssNS = Namespace.getNamespace("http://purl.org/rss/1.0/");
// rdf is the root element
@ -482,9 +471,9 @@ public class RSSService {
// Channel info
Element channel = new Element("channel", rssNS);
channel.setAttribute(
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
"about",
URL.here(request, "/rss/").getURL(),
rdfNS);
rdf.addContent(channel);
Element channelTitle = new Element("title", rssNS);
@ -563,7 +552,7 @@ public class RSSService {
upperCamel += word.toUpperCase();
} else {
upperCamel += word.substring(0, 1).toUpperCase()
+ word.substring(1, word.length());
+ word.substring(1, word.length());
}
}
@ -571,4 +560,5 @@ public class RSSService {
return upperCamel;
}
}