Fixed loader problem in ccm-rssfeed
git-svn-id: https://svn.libreccm.org/ccm/trunk@2788 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
a33cb45780
commit
4532447619
|
|
@ -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,15 +28,15 @@ 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 {
|
||||||
|
|
||||||
public static final String BASE_DATA_OBJECT_TYPE
|
public static final String BASE_DATA_OBJECT_TYPE
|
||||||
= "com.arsdigita.rssfeed.Feed";
|
= "com.arsdigita.rssfeed.Feed";
|
||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
public static final String TITLE = "title";
|
public static final String TITLE = "title";
|
||||||
|
|
@ -53,7 +53,7 @@ public class Feed extends ACSObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
public Feed(BigDecimal id)
|
public Feed(BigDecimal id)
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -79,12 +81,13 @@ public class Feed extends ACSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param url
|
* @param url
|
||||||
* @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,
|
||||||
String title,
|
String title,
|
||||||
|
|
@ -101,10 +104,12 @@ 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)
|
||||||
throws DataObjectNotFoundException {
|
throws DataObjectNotFoundException {
|
||||||
|
|
@ -123,15 +128,16 @@ 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)
|
||||||
throws DataObjectNotFoundException {
|
throws DataObjectNotFoundException {
|
||||||
|
|
||||||
Session session = SessionManager.getSession();
|
Session session = SessionManager.getSession();
|
||||||
DataCollection feed = session.retrieve(BASE_DATA_OBJECT_TYPE);
|
DataCollection feed = session.retrieve(BASE_DATA_OBJECT_TYPE);
|
||||||
|
|
@ -148,9 +154,9 @@ public class Feed extends ACSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static FeedCollection retrieveAll() {
|
public static FeedCollection retrieveAll() {
|
||||||
Session session = SessionManager.getSession();
|
Session session = SessionManager.getSession();
|
||||||
|
|
@ -176,7 +182,7 @@ public class Feed extends ACSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return (String)get(TITLE);
|
return (String) get(TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -187,7 +193,7 @@ public class Feed extends ACSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getURL() {
|
public String getURL() {
|
||||||
return (String)get(URL);
|
return (String) get(URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -198,7 +204,7 @@ public class Feed extends ACSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return (String)get(DESCRIPTION);
|
return (String) get(DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProvider(boolean provider) {
|
public void setProvider(boolean provider) {
|
||||||
|
|
@ -206,6 +212,7 @@ public class Feed extends ACSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProvider() {
|
public boolean isProvider() {
|
||||||
return ((Boolean)get(IS_PROVIDER)).booleanValue();
|
return ((Boolean) get(IS_PROVIDER)).booleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
|
|
@ -64,31 +65,29 @@ public class Loader extends PackageLoader {
|
||||||
// RSS currently depends on an existing category domain in terms
|
// RSS currently depends on an existing category domain in terms
|
||||||
// an a domain mapping to this applicaion.
|
// an a domain mapping to this applicaion.
|
||||||
/*
|
/*
|
||||||
String catKey = RSSFeed.getConfig().getCategoryKey();
|
String catKey = RSSFeed.getConfig().getCategoryKey();
|
||||||
s_log.info("Setting RSS Category Key to " + catKey + ".");
|
s_log.info("Setting RSS Category Key to " + catKey + ".");
|
||||||
if (!CategoryPurpose.purposeExists(catKey)) {
|
if (!CategoryPurpose.purposeExists(catKey)) {
|
||||||
(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() {
|
||||||
|
|
||||||
|
|
@ -99,46 +98,50 @@ public class Loader extends PackageLoader {
|
||||||
* replacing blanks between words and illegal characters with an
|
* replacing blanks between words and illegal characters with an
|
||||||
* hyphen and converted to lower case.
|
* hyphen and converted to lower case.
|
||||||
* "RSSFeed" will become "rssfeed". */
|
* "RSSFeed" will become "rssfeed". */
|
||||||
ApplicationType type = new ApplicationType(
|
ApplicationType type = new ApplicationType(
|
||||||
"RSS Feed",
|
"RSS Feed",
|
||||||
RSSFeed.BASE_DATA_OBJECT_TYPE );
|
RSSFeed.BASE_DATA_OBJECT_TYPE);
|
||||||
type.setSingleton(true);
|
type.setSingleton(true);
|
||||||
type.setDescription("Provides RSS feed service");
|
type.setDescription("Provides RSS feed service");
|
||||||
|
|
||||||
if (!Application.isInstalled(RSSFeed.BASE_DATA_OBJECT_TYPE,
|
if (!Application.isInstalled(RSSFeed.BASE_DATA_OBJECT_TYPE,
|
||||||
"/channels/")) {
|
"/channels/")) {
|
||||||
// create an (singelton) application instance
|
// create an (singelton) application instance
|
||||||
Application app = Application
|
Application app = Application
|
||||||
.createApplication(type,
|
.createApplication(type,
|
||||||
"channels",
|
"channels",
|
||||||
"RSS Service",
|
"RSS Service",
|
||||||
null);
|
null);
|
||||||
app.setDescription("RSS feed channels");
|
app.setDescription("RSS feed channels");
|
||||||
app.save();
|
app.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
|
|
@ -146,11 +149,11 @@ public class Loader extends PackageLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadWorkspaceDirectoryPortlet() {
|
private void loadWorkspaceDirectoryPortlet() {
|
||||||
PortletType type = PortletType.createPortletType("Workspace Directory",
|
PortletType type = PortletType.createPortletType("Workspace Directory",
|
||||||
PortletType.WIDE_PROFILE,
|
PortletType.WIDE_PROFILE,
|
||||||
WorkspaceDirectoryPortlet.BASE_DATA_OBJECT_TYPE);
|
WorkspaceDirectoryPortlet.BASE_DATA_OBJECT_TYPE);
|
||||||
type.setDescription("Displays a list of workspaces");
|
type.setDescription("Displays a list of workspaces");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -65,65 +63,60 @@ import com.arsdigita.kernel.User;
|
||||||
* @version $Revision: #17 $, $Date: 2004/03/29 $
|
* @version $Revision: #17 $, $Date: 2004/03/29 $
|
||||||
*/
|
*/
|
||||||
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();
|
||||||
|
|
||||||
public static RSSFeedConfig getConfig() {
|
public static RSSFeedConfig getConfig() {
|
||||||
return s_config;
|
return s_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 generateChannel(
|
public static void generateChannel(
|
||||||
BigDecimal categoryId,
|
BigDecimal categoryId,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response)
|
HttpServletResponse response)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Category cat = new Category(categoryId);
|
Category cat = new Category(categoryId);
|
||||||
|
|
||||||
boolean useLAWs = "laws-1.0".equals(request.getParameter("extension"));
|
boolean useLAWs = "laws-1.0".equals(request.getParameter("extension"));
|
||||||
|
|
||||||
boolean useESD = "laws-esd".equals(request.getParameter("extension"));
|
boolean useESD = "laws-esd".equals(request.getParameter("extension"));
|
||||||
if (useESD) {
|
if (useESD) {
|
||||||
useLAWs = true;
|
useLAWs = true;
|
||||||
}
|
}
|
||||||
// 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");
|
|
||||||
|
|
||||||
// rdf is the root element
|
// rdf is the root element
|
||||||
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
|
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
|
||||||
rdf.addNamespaceDeclaration(rssNS);
|
rdf.addNamespaceDeclaration(rssNS);
|
||||||
|
|
||||||
if (useLAWs) {
|
if (useLAWs) {
|
||||||
rdf.addNamespaceDeclaration(dcNS);
|
rdf.addNamespaceDeclaration(dcNS);
|
||||||
rdf.addNamespaceDeclaration(egmsNS);
|
rdf.addNamespaceDeclaration(egmsNS);
|
||||||
|
|
@ -132,50 +125,50 @@ public class RSSService {
|
||||||
// Channel info
|
// Channel info
|
||||||
Element channel = new Element("channel", rssNS);
|
Element channel = new Element("channel", rssNS);
|
||||||
channel.setAttribute(
|
channel.setAttribute(
|
||||||
"about",
|
"about",
|
||||||
URL.here(request, "/rss/").getURL(),
|
URL.here(request, "/rss/").getURL(),
|
||||||
rdfNS);
|
rdfNS);
|
||||||
rdf.addContent(channel);
|
rdf.addContent(channel);
|
||||||
|
|
||||||
Element channelTitle = new Element("title", rssNS);
|
Element channelTitle = new Element("title", rssNS);
|
||||||
channelTitle.setText(cat.getName());
|
channelTitle.setText(cat.getName());
|
||||||
channel.addContent(channelTitle);
|
channel.addContent(channelTitle);
|
||||||
|
|
||||||
if (useLAWs) {
|
if (useLAWs) {
|
||||||
Element channelDCTitle = new Element("title", dcNS);
|
Element channelDCTitle = new Element("title", dcNS);
|
||||||
channelDCTitle.setText(cat.getName());
|
channelDCTitle.setText(cat.getName());
|
||||||
channel.addContent(channelDCTitle);
|
channel.addContent(channelDCTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
channelDescription.setText(cat.getDescription());
|
channelDescription.setText(cat.getDescription());
|
||||||
channel.addContent(channelDescription);
|
channel.addContent(channelDescription);
|
||||||
|
|
||||||
Element channelItems = new Element("items", rssNS);
|
Element channelItems = new Element("items", rssNS);
|
||||||
channel.addContent(channelItems);
|
channel.addContent(channelItems);
|
||||||
|
|
||||||
Element itemsSeq = new Element("Seq", rdfNS);
|
Element itemsSeq = new Element("Seq", rdfNS);
|
||||||
channelItems.addContent(itemsSeq);
|
channelItems.addContent(itemsSeq);
|
||||||
|
|
||||||
// Get and store a list of items. Items urls are added to the list in
|
// Get and store a list of items. Items urls are added to the list in
|
||||||
// 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();
|
||||||
|
|
||||||
s_log.debug("item: " + item.getDisplayName());
|
s_log.debug("item: " + item.getDisplayName());
|
||||||
if (ContentItem.LIVE.equals(item.getVersion())) {
|
if (ContentItem.LIVE.equals(item.getVersion())) {
|
||||||
items.add(new NewestFirstItem(item));
|
items.add(new NewestFirstItem(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator iter = items.iterator();
|
Iterator iter = items.iterator();
|
||||||
int max = 10;
|
int max = 10;
|
||||||
int current = 0;
|
int current = 0;
|
||||||
|
|
@ -186,7 +179,7 @@ public class RSSService {
|
||||||
}
|
}
|
||||||
NewestFirstItem itemWrapper = (NewestFirstItem) iter.next();
|
NewestFirstItem itemWrapper = (NewestFirstItem) iter.next();
|
||||||
ContentItem item = itemWrapper.getContentItem();
|
ContentItem item = itemWrapper.getContentItem();
|
||||||
|
|
||||||
String title;
|
String title;
|
||||||
String description = "";
|
String description = "";
|
||||||
try {
|
try {
|
||||||
|
|
@ -202,46 +195,47 @@ public class RSSService {
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
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");
|
||||||
|
|
||||||
// Add the element to the channel list
|
// Add the element to the channel list
|
||||||
Element seqEl = new Element("li", rdfNS);
|
Element seqEl = new Element("li", rdfNS);
|
||||||
seqEl.setAttribute("resource", itemURL, rdfNS);
|
seqEl.setAttribute("resource", itemURL, rdfNS);
|
||||||
itemsSeq.addContent(seqEl);
|
itemsSeq.addContent(seqEl);
|
||||||
|
|
||||||
// Add the element to the top level
|
// Add the element to the top level
|
||||||
Element itemEl = new Element("item", rssNS);
|
Element itemEl = new Element("item", rssNS);
|
||||||
itemEl.setAttribute("about", itemURL, rdfNS);
|
itemEl.setAttribute("about", itemURL, rdfNS);
|
||||||
rdf.addContent(itemEl);
|
rdf.addContent(itemEl);
|
||||||
|
|
||||||
Element titleEl = new Element("title", rssNS);
|
Element titleEl = new Element("title", rssNS);
|
||||||
titleEl.setText(title);
|
titleEl.setText(title);
|
||||||
itemEl.addContent(titleEl);
|
itemEl.addContent(titleEl);
|
||||||
|
|
||||||
Element linkEl = new Element("link", rssNS);
|
Element linkEl = new Element("link", rssNS);
|
||||||
linkEl.setText(itemURL);
|
linkEl.setText(itemURL);
|
||||||
itemEl.addContent(linkEl);
|
itemEl.addContent(linkEl);
|
||||||
|
|
||||||
if (description != null) {
|
if (description != null) {
|
||||||
Element descEl = new Element("description", rssNS);
|
Element descEl = new Element("description", rssNS);
|
||||||
descEl.setText(
|
descEl.setText(
|
||||||
com.arsdigita.util.StringUtils.truncateString(
|
com.arsdigita.util.StringUtils.truncateString(
|
||||||
description,
|
description,
|
||||||
100,
|
100,
|
||||||
true)
|
true)
|
||||||
+ "...");
|
+ "...");
|
||||||
itemEl.addContent(descEl);
|
itemEl.addContent(descEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useLAWs) {
|
if (useLAWs) {
|
||||||
|
|
||||||
Element dcTitleEl = new Element("title", dcNS);
|
Element dcTitleEl = new Element("title", dcNS);
|
||||||
dcTitleEl.setText(title);
|
dcTitleEl.setText(title);
|
||||||
itemEl.addContent(dcTitleEl);
|
itemEl.addContent(dcTitleEl);
|
||||||
|
|
||||||
User creatorUser = item.getCreationUser();
|
User creatorUser = item.getCreationUser();
|
||||||
String creator = "Not specified";
|
String creator = "Not specified";
|
||||||
if (creatorUser != null) {
|
if (creatorUser != null) {
|
||||||
|
|
@ -250,105 +244,104 @@ public class RSSService {
|
||||||
Element dcCreatorEl = new Element("creator", dcNS);
|
Element dcCreatorEl = new Element("creator", dcNS);
|
||||||
dcCreatorEl.setText(creator);
|
dcCreatorEl.setText(creator);
|
||||||
itemEl.addContent(dcCreatorEl);
|
itemEl.addContent(dcCreatorEl);
|
||||||
|
|
||||||
Date dcDate = item.getCreationDate();
|
Date dcDate = item.getCreationDate();
|
||||||
String dcDateString = "Not specified";
|
String dcDateString = "Not specified";
|
||||||
if (dcDate != null) {
|
if (dcDate != null) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
dcDateString = sdf.format(dcDate);
|
dcDateString = sdf.format(dcDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
Element dcDateEl = new Element("date", dcNS);
|
Element dcDateEl = new Element("date", dcNS);
|
||||||
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);
|
||||||
subjectCategoryEl.addContent(subjectBagEl);
|
subjectCategoryEl.addContent(subjectBagEl);
|
||||||
|
|
||||||
Element liEl;
|
Element liEl;
|
||||||
Element categoryEl;
|
Element categoryEl;
|
||||||
Element rdfValueEl;
|
Element rdfValueEl;
|
||||||
|
|
||||||
// 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()) {
|
||||||
|
|
||||||
Term term = (Term) it.next();
|
Term term = (Term) it.next();
|
||||||
String name = term.getName();
|
String name = term.getName();
|
||||||
String urlName = toUpperCamel(name);
|
String urlName = toUpperCamel(name);
|
||||||
|
|
||||||
liEl = new Element("li", rdfNS);
|
liEl = new Element("li", rdfNS);
|
||||||
subjectBagEl.addContent(liEl);
|
subjectBagEl.addContent(liEl);
|
||||||
|
|
||||||
categoryEl = new Element(urlName, lgclNS);
|
categoryEl = new Element(urlName, lgclNS);
|
||||||
liEl.addContent(categoryEl);
|
liEl.addContent(categoryEl);
|
||||||
|
|
||||||
rdfValueEl = new Element("value", rdfNS);
|
rdfValueEl = new Element("value", rdfNS);
|
||||||
rdfValueEl.setText(name);
|
rdfValueEl.setText(name);
|
||||||
categoryEl.addContent(rdfValueEl);
|
categoryEl.addContent(rdfValueEl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write XML to the output stream
|
// Write XML to the output stream
|
||||||
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);
|
||||||
|
|
||||||
response.setContentType("text/xml; charset=UTF-8");
|
response.setContentType("text/xml; charset=UTF-8");
|
||||||
|
|
||||||
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
|
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
|
||||||
xmlOutput.setNewlines(true);
|
xmlOutput.setNewlines(true);
|
||||||
xmlOutput.setIndent(true);
|
xmlOutput.setIndent(true);
|
||||||
xmlOutput.output(doc, response.getWriter());
|
xmlOutput.output(doc, response.getWriter());
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
public NewestFirstItem(ContentItem item) {
|
public NewestFirstItem(ContentItem item) {
|
||||||
m_item = item;
|
m_item = item;
|
||||||
|
|
||||||
m_liveID = item.getID();
|
m_liveID = item.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentItem getContentItem() {
|
public ContentItem getContentItem() {
|
||||||
return m_item;
|
return m_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getLiveID() {
|
public BigDecimal getLiveID() {
|
||||||
return m_liveID;
|
return m_liveID;
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if ((o instanceof NewestFirstItem)) {
|
if ((o instanceof NewestFirstItem)) {
|
||||||
return m_item.equals(((NewestFirstItem) o).getContentItem());
|
return m_item.equals(((NewestFirstItem) o).getContentItem());
|
||||||
|
|
@ -356,55 +349,54 @@ 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/");
|
||||||
|
|
||||||
// rdf is the root element
|
// rdf is the root element
|
||||||
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
|
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
|
||||||
rdf.addNamespaceDeclaration(rssNS);
|
rdf.addNamespaceDeclaration(rssNS);
|
||||||
|
|
||||||
// Channel info
|
// Channel info
|
||||||
Element channel = new Element("channel", rssNS);
|
Element channel = new Element("channel", rssNS);
|
||||||
channel.setAttribute(
|
channel.setAttribute(
|
||||||
"about",
|
"about",
|
||||||
URL.here(request, "/rss/").getURL(),
|
URL.here(request, "/rss/").getURL(),
|
||||||
rdfNS);
|
rdfNS);
|
||||||
rdf.addContent(channel);
|
rdf.addContent(channel);
|
||||||
|
|
||||||
Element channelTitle = new Element("title", rssNS);
|
Element channelTitle = new Element("title", rssNS);
|
||||||
channelTitle.setText("Channel Index");
|
channelTitle.setText("Channel Index");
|
||||||
channel.addContent(channelTitle);
|
channel.addContent(channelTitle);
|
||||||
|
|
||||||
Element channelLink = new Element("link", rssNS);
|
Element channelLink = new Element("link", rssNS);
|
||||||
channelLink.setText(URL.here(request, "/rss/").getURL());
|
channelLink.setText(URL.here(request, "/rss/").getURL());
|
||||||
channel.addContent(channelLink);
|
channel.addContent(channelLink);
|
||||||
|
|
||||||
Element channelDescription = new Element("description", rssNS);
|
Element channelDescription = new Element("description", rssNS);
|
||||||
channelDescription.setText("The list of content feeds");
|
channelDescription.setText("The list of content feeds");
|
||||||
channel.addContent(channelDescription);
|
channel.addContent(channelDescription);
|
||||||
|
|
||||||
Element channelItems = new Element("items", rssNS);
|
Element channelItems = new Element("items", rssNS);
|
||||||
channel.addContent(channelItems);
|
channel.addContent(channelItems);
|
||||||
|
|
||||||
Element itemsSeq = new Element("Seq", rdfNS);
|
Element itemsSeq = new Element("Seq", rdfNS);
|
||||||
channelItems.addContent(itemsSeq);
|
channelItems.addContent(itemsSeq);
|
||||||
|
|
||||||
Map cats = CategorizationTree.getSubtreePath(root);
|
Map cats = CategorizationTree.getSubtreePath(root);
|
||||||
s_log.debug("Get categories");
|
s_log.debug("Get categories");
|
||||||
Iterator i = cats.keySet().iterator();
|
Iterator i = cats.keySet().iterator();
|
||||||
|
|
@ -412,34 +404,34 @@ public class RSSService {
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
String path = (String) i.next();
|
String path = (String) i.next();
|
||||||
Category cat = (Category) cats.get(path);
|
Category cat = (Category) cats.get(path);
|
||||||
|
|
||||||
if (cat.getID().equals(root.getID())) {
|
if (cat.getID().equals(root.getID())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_log.debug("GOt sub cat " + path + " id " + cat.getID());
|
s_log.debug("GOt sub cat " + path + " id " + cat.getID());
|
||||||
ParameterMap params = new ParameterMap();
|
ParameterMap params = new ParameterMap();
|
||||||
params.setParameter("id", cat.getID());
|
params.setParameter("id", cat.getID());
|
||||||
URL url = URL.here(request, "/rss/channel.rss", params);
|
URL url = URL.here(request, "/rss/channel.rss", params);
|
||||||
|
|
||||||
// Add the element to the channel list
|
// Add the element to the channel list
|
||||||
Element seqEl = new Element("li", rdfNS);
|
Element seqEl = new Element("li", rdfNS);
|
||||||
seqEl.setAttribute("resource", url.getURL(), rdfNS);
|
seqEl.setAttribute("resource", url.getURL(), rdfNS);
|
||||||
itemsSeq.addContent(seqEl);
|
itemsSeq.addContent(seqEl);
|
||||||
|
|
||||||
// Add the element to the top level
|
// Add the element to the top level
|
||||||
Element itemEl = new Element("item", rssNS);
|
Element itemEl = new Element("item", rssNS);
|
||||||
itemEl.setAttribute("about", url.getURL(), rdfNS);
|
itemEl.setAttribute("about", url.getURL(), rdfNS);
|
||||||
rdf.addContent(itemEl);
|
rdf.addContent(itemEl);
|
||||||
|
|
||||||
Element titleEl = new Element("title", rssNS);
|
Element titleEl = new Element("title", rssNS);
|
||||||
titleEl.setText(path);
|
titleEl.setText(path);
|
||||||
itemEl.addContent(titleEl);
|
itemEl.addContent(titleEl);
|
||||||
|
|
||||||
Element linkEl = new Element("link", rssNS);
|
Element linkEl = new Element("link", rssNS);
|
||||||
linkEl.setText(url.getURL());
|
linkEl.setText(url.getURL());
|
||||||
itemEl.addContent(linkEl);
|
itemEl.addContent(linkEl);
|
||||||
|
|
||||||
if (cat.getDescription() != null) {
|
if (cat.getDescription() != null) {
|
||||||
Element descEl = new Element("description", rssNS);
|
Element descEl = new Element("description", rssNS);
|
||||||
descEl.setText(cat.getDescription());
|
descEl.setText(cat.getDescription());
|
||||||
|
|
@ -447,128 +439,126 @@ public class RSSService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s_log.debug("All done");
|
s_log.debug("All done");
|
||||||
|
|
||||||
// Write XML to the output stream
|
// Write XML to the output stream
|
||||||
Document doc = new Document(rdf);
|
Document doc = new Document(rdf);
|
||||||
|
|
||||||
response.setContentType("text/xml; charset=UTF-8");
|
response.setContentType("text/xml; charset=UTF-8");
|
||||||
|
|
||||||
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
|
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
|
||||||
xmlOutput.setNewlines(true);
|
xmlOutput.setNewlines(true);
|
||||||
xmlOutput.setIndent(true);
|
xmlOutput.setIndent(true);
|
||||||
xmlOutput.output(doc, response.getWriter());
|
xmlOutput.output(doc, response.getWriter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) throws Exception {
|
||||||
HttpServletResponse response)
|
|
||||||
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/");
|
||||||
|
|
||||||
// rdf is the root element
|
// rdf is the root element
|
||||||
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
|
Element rdf = new Element("RDF", "rdf", rdfNS.getURI());
|
||||||
rdf.addNamespaceDeclaration(rssNS);
|
rdf.addNamespaceDeclaration(rssNS);
|
||||||
|
|
||||||
// Channel info
|
// Channel info
|
||||||
Element channel = new Element("channel", rssNS);
|
Element channel = new Element("channel", rssNS);
|
||||||
channel.setAttribute(
|
channel.setAttribute(
|
||||||
"about",
|
"about",
|
||||||
URL.here(request, "/rss/").getURL(),
|
URL.here(request, "/rss/").getURL(),
|
||||||
rdfNS);
|
rdfNS);
|
||||||
rdf.addContent(channel);
|
rdf.addContent(channel);
|
||||||
|
|
||||||
Element channelTitle = new Element("title", rssNS);
|
Element channelTitle = new Element("title", rssNS);
|
||||||
channelTitle.setText("Channel Index");
|
channelTitle.setText("Channel Index");
|
||||||
channel.addContent(channelTitle);
|
channel.addContent(channelTitle);
|
||||||
|
|
||||||
Element channelLink = new Element("link", rssNS);
|
Element channelLink = new Element("link", rssNS);
|
||||||
channelLink.setText(URL.here(request, "/rss/").getURL());
|
channelLink.setText(URL.here(request, "/rss/").getURL());
|
||||||
channel.addContent(channelLink);
|
channel.addContent(channelLink);
|
||||||
|
|
||||||
Element channelDescription = new Element("description", rssNS);
|
Element channelDescription = new Element("description", rssNS);
|
||||||
channelDescription.setText("The list of server feeds");
|
channelDescription.setText("The list of server feeds");
|
||||||
channel.addContent(channelDescription);
|
channel.addContent(channelDescription);
|
||||||
|
|
||||||
Element channelItems = new Element("items", rssNS);
|
Element channelItems = new Element("items", rssNS);
|
||||||
channel.addContent(channelItems);
|
channel.addContent(channelItems);
|
||||||
|
|
||||||
Element itemsSeq = new Element("Seq", rdfNS);
|
Element itemsSeq = new Element("Seq", rdfNS);
|
||||||
channelItems.addContent(itemsSeq);
|
channelItems.addContent(itemsSeq);
|
||||||
|
|
||||||
FeedCollection feeds = Feed.retrieveAll();
|
FeedCollection feeds = Feed.retrieveAll();
|
||||||
feeds.filterACSJFeeds(acsj);
|
feeds.filterACSJFeeds(acsj);
|
||||||
|
|
||||||
while (feeds.next()) {
|
while (feeds.next()) {
|
||||||
Feed feed = feeds.getFeed();
|
Feed feed = feeds.getFeed();
|
||||||
|
|
||||||
// Add the element to the channel list
|
// Add the element to the channel list
|
||||||
Element seqEl = new Element("li", rdfNS);
|
Element seqEl = new Element("li", rdfNS);
|
||||||
seqEl.setAttribute("resource", feed.getURL(), rdfNS);
|
seqEl.setAttribute("resource", feed.getURL(), rdfNS);
|
||||||
itemsSeq.addContent(seqEl);
|
itemsSeq.addContent(seqEl);
|
||||||
|
|
||||||
// Add the element to the top level
|
// Add the element to the top level
|
||||||
Element itemEl = new Element("item", rssNS);
|
Element itemEl = new Element("item", rssNS);
|
||||||
itemEl.setAttribute("about", feed.getURL(), rdfNS);
|
itemEl.setAttribute("about", feed.getURL(), rdfNS);
|
||||||
rdf.addContent(itemEl);
|
rdf.addContent(itemEl);
|
||||||
|
|
||||||
Element titleEl = new Element("title", rssNS);
|
Element titleEl = new Element("title", rssNS);
|
||||||
titleEl.setText(feed.getTitle());
|
titleEl.setText(feed.getTitle());
|
||||||
itemEl.addContent(titleEl);
|
itemEl.addContent(titleEl);
|
||||||
|
|
||||||
Element linkEl = new Element("link", rssNS);
|
Element linkEl = new Element("link", rssNS);
|
||||||
linkEl.setText(feed.getURL());
|
linkEl.setText(feed.getURL());
|
||||||
itemEl.addContent(linkEl);
|
itemEl.addContent(linkEl);
|
||||||
|
|
||||||
String desc = feed.getDescription();
|
String desc = feed.getDescription();
|
||||||
if (desc != null) {
|
if (desc != null) {
|
||||||
Element descEl = new Element("description", rssNS);
|
Element descEl = new Element("description", rssNS);
|
||||||
descEl.setText(desc);
|
descEl.setText(desc);
|
||||||
itemEl.addContent(descEl);
|
itemEl.addContent(descEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write XML to the output stream
|
// Write XML to the output stream
|
||||||
Document doc = new Document(rdf);
|
Document doc = new Document(rdf);
|
||||||
|
|
||||||
response.setContentType("text/xml; charset=UTF-8");
|
response.setContentType("text/xml; charset=UTF-8");
|
||||||
|
|
||||||
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
|
XMLOutputter xmlOutput = new XMLOutputter("UTF-8");
|
||||||
xmlOutput.setNewlines(true);
|
xmlOutput.setNewlines(true);
|
||||||
xmlOutput.setIndent(true);
|
xmlOutput.setIndent(true);
|
||||||
xmlOutput.output(doc, response.getWriter());
|
xmlOutput.output(doc, response.getWriter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toUpperCamel(String termName) {
|
public static String toUpperCamel(String termName) {
|
||||||
|
|
||||||
String upperCamel = "";
|
String upperCamel = "";
|
||||||
|
|
||||||
if (termName != null) {
|
if (termName != null) {
|
||||||
|
|
||||||
StringTokenizer tokens = new StringTokenizer(termName);
|
StringTokenizer tokens = new StringTokenizer(termName);
|
||||||
while (tokens.hasMoreTokens()) {
|
while (tokens.hasMoreTokens()) {
|
||||||
|
|
||||||
String word = tokens.nextToken();
|
String word = tokens.nextToken();
|
||||||
if (word.length() <= 1) {
|
if (word.length() <= 1) {
|
||||||
upperCamel += word.toUpperCase();
|
upperCamel += word.toUpperCase();
|
||||||
} else {
|
} else {
|
||||||
upperCamel += word.substring(0, 1).toUpperCase()
|
upperCamel += word.substring(0, 1).toUpperCase()
|
||||||
+ word.substring(1, word.length());
|
+ word.substring(1, word.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return upperCamel;
|
return upperCamel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue