Portlet LatestNews aus contrib WestSussex hinzugefügt. Muss noch weiter angepasst werden.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2070 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2013-02-13 18:07:02 +00:00
parent 74eaab17dc
commit 6ba1d1a8e4
18 changed files with 1068 additions and 0 deletions

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<ccm:application name="ccm-wsx-news-portlet"
prettyName="Personalised News Portlet"
version="1.0.1"
release="1"
webapp="ROOT"
xmlns:ccm="http://ccm.redhat.com/ccm-project">
<ccm:dependencies>
<ccm:requires name="ccm-cms-types-newsitem" version="6.1.0"/>
<!--
<ccm:requires name="ccm-ldn-portal" version="1.4.2"/>
<ccm:requires name="ccm-wsx-authentication" version="1.0.1"/>
-->
</ccm:dependencies>
<ccm:contacts>
<ccm:contact uri="http://wsgfl.westsussex.gov.uk" type="website"/>
<ccm:contact uri="mailto:chris.gilbert@westsussex.gov.uk" type="support"/>
</ccm:contacts>
<ccm:description>
Portlet either displays the latest news content, or the latest personalised items
</ccm:description>
</ccm:application>

View File

@ -0,0 +1,29 @@
//
// Copyright (C) 2003 Chris Gilbert All Rights Reserved.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2.1 of
// the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// model for a portlet that displays the latest news
model com.arsdigita.portlet;
import com.arsdigita.portal.Portlet;
object type NewsPortlet extends Portlet {
Integer[0..1] itemCount = portlet_news.item_count INTEGER;
reference key (portlet_news.portlet_id);
}

View File

@ -0,0 +1,2 @@
@ ddl/oracle-se/create.sql
@ ddl/oracle-se/deferred.sql

View File

@ -0,0 +1,4 @@
begin;
\i ddl/postgres/create.sql
\i ddl/postgres/deferred.sql
end;

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<config class="com.arsdigita.portlet.news.NewsPortletConfig"
storage="ccm-portlet-latestnews/newsportlet.properties"/>
</registry>

View File

@ -0,0 +1,24 @@
<load>
<requires>
<table name="inits"/>
<table name="acs_objects"/>
<initializer class="com.arsdigita.core.Initializer"/>
<table name="cms_items"/>
<initializer class="com.arsdigita.cms.Initializer"/>
<initializer class="com.arsdigita.portalworkspace.Initializer"/>
<!--
<initializer class="uk.gov.westsussex.authentication.Initializer"/>
-->
<initializer class="com.arsdigita.cms.contenttypes.NewsItemInitializer"/>
<initializer class="com.arsdigita.navigation.Initializer"/>
</requires>
<provides>
<table name="portlet_news"/>
<initializer class="com.arsdigita.portlet.news.Initializer"/>
</provides>
<scripts>
<schema directory="ccm-portlet-latestnews"/>
<data class="com.arsdigita.portlet.news.Loader"/>
</scripts>
</load>

View File

@ -0,0 +1,114 @@
/*
* Copyright (C) 2003 Chris Gilbert All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.portlet.news;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.db.DbHelper;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.kernel.ACSObjectInstantiator;
import com.arsdigita.kernel.ResourceType;
import com.arsdigita.kernel.ResourceTypeConfig;
import com.arsdigita.kernel.ui.ResourceConfigFormSection;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.pdl.ManifestSource;
import com.arsdigita.persistence.pdl.NameFilter;
import com.arsdigita.portal.PortletType;
import com.arsdigita.runtime.CompoundInitializer;
import com.arsdigita.runtime.DomainInitEvent;
import com.arsdigita.runtime.PDLInitializer;
import com.arsdigita.runtime.RuntimeConfig;
import com.arsdigita.portlet.news.ui.NewsPortletEditor;
import org.apache.log4j.Logger;
/**
* based on com.arsdigita.london.portal.installer.portlet
* @author Chris Gilbert (cgyg9330) &lt;chris.gilbert@westsussex.gov.uk&gt;
* @version $Id: Initializer.java,v 1.2 2005/03/07 13:48:49 cgyg9330 Exp $
*/
public class Initializer extends CompoundInitializer {
/** Private Logger instance for debugging purpose. */
private static final Logger s_log = Logger.getLogger(Initializer.class);
public Initializer() {
final String url = RuntimeConfig.getConfig().getJDBCURL();
final int database = DbHelper.getDatabaseFromURL(url);
add(
new PDLInitializer(
new ManifestSource(
"ccm-portlet-latestnews.pdl.mf",
new NameFilter(
DbHelper.getDatabaseSuffix(database),
"pdl"))));
}
/**
*
* @param e
*/
@Override
public void init(DomainInitEvent e) {
super.init(e);
/* Register portlet with the domain coupling machinery */
e.getFactory().registerInstantiator(
NewsPortlet.BASE_DATA_OBJECT_TYPE,
new ACSObjectInstantiator() {
@Override
public DomainObject doNewInstance(DataObject dataObject) {
return new NewsPortlet(dataObject);
}
});
/* */
new ResourceTypeConfig(NewsPortlet.BASE_DATA_OBJECT_TYPE) {
@Override
public ResourceConfigFormSection getCreateFormSection(
final ResourceType resType,
final RequestLocal parentAppRL) {
final ResourceConfigFormSection config = new
NewsPortletEditor(resType, parentAppRL);
return config;
}
@Override
public ResourceConfigFormSection getModifyFormSection(
final RequestLocal application) {
final NewsPortletEditor config = new
NewsPortletEditor(application);
return config;
}
};
/* Register internal default themes's stylesheet which concomitantly
* serves as a fallback if a custom theme is used without supporting
* this portlet. */
PortletType.registerXSLFile(
NewsPortlet.BASE_DATA_OBJECT_TYPE,
PortletType.INTERNAL_THEME_PORTLET_DIR + "news-portlet.xsl");
}
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (C) 2003 Chris Gilbert All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.portlet.news;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.kernel.KernelExcursion;
import com.arsdigita.loader.PackageLoader;
import com.arsdigita.portal.PortletType;
import com.arsdigita.runtime.ScriptContext;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringParameter;
import org.apache.log4j.Logger;
/**
*
* @author Chris Gilbert (cgyg9330) &lt;chris.gilbert@westsussex.gov.uk&gt;
* @version $Id: Loader.java, 2005/02/28 16:28:49 cgyg9330 $
*/
public class Loader extends PackageLoader {
private static final Logger s_log = Logger.getLogger(Loader.class);
private StringParameter typeName = new StringParameter
("uk.gov.westsussex.portlet.news.name",
Parameter.REQUIRED, "News");
public Loader() {
register(typeName);
}
public void run(final ScriptContext ctx) {
new KernelExcursion() {
public void excurse() {
setEffectiveParty(Kernel.getSystemParty());
PortletType type = PortletType
.createPortletType((String)get(typeName),
PortletType.WIDE_PROFILE,
NewsPortlet.BASE_DATA_OBJECT_TYPE);
type.setDescription("See your personalised news");
}
}.run();
}
}

View File

@ -0,0 +1,5 @@
uk.gov.westsussex.portlet.news.name.title=Portlet Type Name
uk.gov.westsussex.portlet.news.name.purpose=The name of the portlet type that appears in the drop down list of portlet types
uk.gov.westsussex.portlet.news.name.example=News
uk.gov.westsussex.portlet.news.name.format=[string]

View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2003 - 2004 Chris Gilbert All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.portlet.news;
/**
* Constants used by classes in the news portlet application.
*
* @author cgyg9330
*/
public interface NewsConstants {
public static final String ITEM_COUNT = "itemCount";
public static final String GENERAL_NEWS_CACHE_KEY = "generalNews";
//queries
public static final String RECENT_NEWS =
"uk.gov.westsussex.portal.portlet.RecentNews";
public static final String PERSONALISED_NEWS =
"uk.gov.westsussex.portal.portlet.PersonalisedNews";
public static final String LAST_UPDATE =
"uk.gov.westsussex.portal.portlet.LatestNewsDate";
// rendering
public static final String XML_NEWS_NS = "http://wsgfl.westsussex.gov.uk/portlet/news/1.0";
public static final String MAIN_PORTLET_ELEMENT = "portlet:news";
public static final String NEWS_ITEM_ELEMENT = "news-portlet:newsItem";
public static final String NEWS_ROOM_ATTRIBUTE = "newsroom-shortcut";
public static final String PERSONALISED_ATTRIBUTE = "personalised";
public static final String DATE_ATTRIBUTE = "date";
public static final String TITLE_ATTRIBUTE = "title";
public static final String LEAD_ATTRIBUTE = "lead";
public static final String URL_ATTRIBUTE = "url";
}

View File

@ -0,0 +1,126 @@
/*
* Copyright (C) 2003 Chris Gilbert All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.portlet.news;
import java.math.BigDecimal;
// import java.util.Date;
import com.arsdigita.portlet.news.ui.NewsPortletRenderer;
import com.arsdigita.bebop.portal.AbstractPortletRenderer;
// import com.arsdigita.cms.contenttypes.NewsItem;
// import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject;
// import com.arsdigita.persistence.SessionManager;
import com.arsdigita.portal.Portlet;
import org.apache.log4j.Logger;
/**
* List of news content types items, in descending order of date. The number
* of items retrieved is set by the administrator.
*
* @author Chris Gilbert (cgyg9330) &lt;chris.gilbert@westsussex.gov.uk&gt;
* @version $Id: NewsPortlet.java, 2007/08/08 09:28:26 cgyg9330 $
*/
public class NewsPortlet extends Portlet implements NewsConstants {
/** Private Logger instance for debugging purpose. */
private static final Logger s_log = Logger.getLogger(NewsPortlet.class);
/** PDL stuff */
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.portlet.NewsPortlet";
/**
* allows non personalised news page to be cached between updates
*/
private static BigDecimal s_latestNews = new BigDecimal(0);
private static long s_newsCount = 0;
private static final NewsPortletConfig s_config = NewsPortletConfig.getConfig();
static {
s_config.load();
}
public static NewsPortletConfig getConfig() {
return s_config;
}
public NewsPortlet(DataObject dataObject) {
super(dataObject);
}
@Override
protected String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE;
}
@Override
protected AbstractPortletRenderer doGetPortletRenderer() {
return new NewsPortletRenderer(this);
}
public int getItemCount() {
return ((Integer) get(ITEM_COUNT)).intValue();
}
public void setItemCount(int count) {
set(ITEM_COUNT, new Integer(count));
}
/**
*
* @return whether any homepage news items have been added or edited since last checked.
* If news has been updated, the stored value of the last update is changed. Note
* deleted news items do not cause true to be returned.
*
*/
/*
*
* starting to look doubtful whether this would actually save any time
*
* will recheck when more data on database
public boolean isNewNews() {
NewsItem latest = NewsItem.getMostRecentNewsItem();
if (!latest.getID().equals(s_latestNews)) {
s_latestNews = latest.getID();
return true;
}
DataCollection news = SessionManager.getSession().retrieve(NewsItem.BASE_DATA_OBJECT_TYPE);
news.addEqualsFilter(NewsItem.IS_HOMEPAGE, new Boolean(true));
long newsCount = news.size();
if (newsCount != s_newsCount) {
s_newsCount = newsCount;
return true;
}
return false;
}*/
}

View File

@ -0,0 +1,94 @@
/*
* Copyright (C) 2003 - 2004 Chris Gilbert All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.portlet.news;
import com.arsdigita.runtime.AbstractConfig;
// import com.arsdigita.util.parameter.IntegerParameter;
import com.arsdigita.util.parameter.Parameter;
// import com.arsdigita.util.parameter.StringArrayParameter;
// import com.arsdigita.util.parameter.URLParameter;
import com.arsdigita.util.parameter.StringParameter;
// import com.arsdigita.util.UncheckedWrapperException;
// import java.io.InputStream;
// import java.io.IOException;
// import java.net.URL;
// import java.net.MalformedURLException;
import org.apache.log4j.Logger;
/**
* Specification of datasources required by Atomwide application
*
* @author Chris Gilbert &lt;chris.gilbert@westsussex.gov.uk&gt;
* @version $Id: NewsPortletConfig.java,v 1.1 2005/03/07 13:48:49 cgyg9330 Exp $
*/
public class NewsPortletConfig extends AbstractConfig {
/** A logger instance to assist debugging. */
private static final Logger s_log = Logger.getLogger(NewsPortletConfig.class);
/** Singelton config object. */
private static NewsPortletConfig s_conf;
/**
* Gain a NewsPortletConfig object.
*
* Singelton pattern, don't instantiate a config object using the
* constructor directly!
* use RSSFeedConfig.getConfig(); instead
* @return
*/
public static synchronized NewsPortletConfig getConfig() {
if (s_conf == null) {
s_conf = new NewsPortletConfig();
s_conf.load();
}
return s_conf;
}
// ////////////////////////////////////////////////////////////////////////
// Set of configuration parameters
/** */
private final Parameter newsroomShortcut = new StringParameter
( "com.arsdigita.portlet.news.newsroom-shortcut",
Parameter.REQUIRED,
"/news");
/**
* Constructor initializes class.
*/
public NewsPortletConfig() {
register(newsroomShortcut);
loadInfo();
}
/**
* Getter newsroom shortcut parameter
*/
public final String getNewsroomShortcut() {
return (String)get(newsroomShortcut);
}
}

View File

@ -0,0 +1,4 @@
com.artsdigita.portlet.news.newsroom-shortcut.title=Newsroom Shortcut
com.artsdigita.portlet.news.newsroom-shortcut.purpose=used as a link at the bottom of the news portlet
com.artsdigita.portlet.news.newsroom-shortcut.example=/news
com.artsdigita.portlet.news.newsroom-shortcut.format=[string]

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2005 Chris Gilbert All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.portlet.news;
import com.arsdigita.domain.DomainCollection;
/**
* Service is used by news portlet to display potentially useful articles
* to the user.
*
* An implementation will require a mapping between content pages and some
* attributes of the user. In the atomwide authentication module, user profile
* values are modelled as terms in domains mapped to /content/ and so authors
* may specify which user groups their articles are to be promoted to
*
* @author chris.gilbert@westsussex.gov.uk
*/
public interface PersonalisedNewsTarget {
/**
*
* @return a domainCollection of com.arsdigita.cms.ContentPage objects
*/
public DomainCollection getMyNews();
}

View File

@ -0,0 +1,128 @@
/*
* Copyright (C) 2003 - 2004 Chris Gilbert All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.portlet.news.ui;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.IntegerValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.portal.PortletConfigFormSection;
import com.arsdigita.kernel.ResourceType;
import com.arsdigita.portal.Portlet;
import com.arsdigita.portlet.news.NewsPortlet;
import org.apache.log4j.Logger;
/**
*
*
* @author Chris Gilbert (cgyg9330) &lt;chris.gilbert@westsussex.gov.uk&gt;
* @version $Id: NewsPortletEditor.java 2005/03/07 13:48:49 cgyg9330 Exp $
*/
public class NewsPortletEditor extends PortletConfigFormSection {
private TextField m_itemCount;
private static final Logger s_log = Logger.getLogger(NewsPortletEditor.class);
/**
* Constructor
*
* @param resType
* @param parentAppRL
*/
public NewsPortletEditor(ResourceType resType, RequestLocal parentAppRL) {
super(resType, parentAppRL);
}
/**
* Constructor
*
* @param application
*/
public NewsPortletEditor(RequestLocal application) {
super(application);
}
/**
*
*/
@Override
protected void addWidgets() {
super.addWidgets();
m_itemCount =
new TextField(new StringParameter(NewsPortlet.ITEM_COUNT));
add(new Label("Number of items:", Label.BOLD), ColumnPanel.RIGHT);
m_itemCount.addValidationListener(new IntegerValidationListener());
add(m_itemCount);
}
/**
*
* @param state
* @param portlet
* @throws FormProcessException
*
* TODO: add validation or set up drop down list with contents of Static folder?
*/
@Override
protected void initWidgets(PageState state, Portlet portlet)
throws FormProcessException {
super.initWidgets(state, portlet);
if (portlet != null) {
NewsPortlet myportlet = (NewsPortlet) portlet;
m_itemCount.setValue(state, myportlet.getItemCount()+ "");
}
}
/**
*
* @param state
* @param portlet
* @throws FormProcessException
*/
@Override
protected void processWidgets(PageState state, Portlet portlet)
throws FormProcessException {
s_log.debug("START processWidgets");
super.processWidgets(state, portlet);
NewsPortlet myportlet = (NewsPortlet) portlet;
myportlet.setItemCount(new Integer(
(String) m_itemCount.getValue(state)).intValue());
s_log.debug("END processWidgets");
}
}

View File

@ -0,0 +1,252 @@
/*
* Copyright (C) 2003 - 2004 Chris Gilbert All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* 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.portlet.news.ui;
//import uk.gov.westsussex.authentication.ExternalUserFactory;
import com.arsdigita.portlet.news.NewsConstants;
import com.arsdigita.portlet.news.NewsPortlet;
import com.arsdigita.portlet.news.PersonalisedNewsTarget;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.portal.AbstractPortletRenderer;
import com.arsdigita.categorization.Category;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.domain.DomainCollection;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.kernel.User;
import com.arsdigita.kernel.permissions.PermissionService;
import com.arsdigita.kernel.permissions.PrivilegeDescriptor;
import com.arsdigita.navigation.Navigation;
// import com.arsdigita.portalworkspace.ui.PortalConstants;
import com.arsdigita.london.terms.Domain;
import com.arsdigita.london.terms.Term;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.portal.PortletType;
import com.arsdigita.xml.Element;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
/**
*
*
* @author Chris Gilbert (cgyg9330) &lt;chris.gilbert@westsussex.gov.uk&gt;
* @version $Id: NewsPortletRenderer.java 2005/03/07 13:48:49 cgyg9330 Exp $
*/
public class NewsPortletRenderer extends AbstractPortletRenderer
implements NewsConstants {
private static final Logger s_log =
Logger.getLogger(NewsPortletRenderer.class);
private NewsPortlet m_portlet;
/**
*
* @param portlet
*/
public NewsPortletRenderer(NewsPortlet portlet) {
m_portlet = portlet;
}
/* (non-Javadoc)
* @see
* com.arsdigita.bebop.portal.AbstractPortletRenderer#generateBodyXML(
* com.arsdigita.bebop.PageState,
* com.arsdigita.xml.Element)
*/
protected void generateBodyXML(PageState state, Element parent) {
s_log.debug("START - generateBodyXML");
Element newsPortlet = parent.newChildElement( MAIN_PORTLET_ELEMENT,
PortletType.PORTLET_XML_NS);
DateFormat formatter = new SimpleDateFormat("dd/MM/yy");
User thisUser = (User) Kernel.getContext().getParty();
if (null == thisUser) {
thisUser = Kernel.getPublicUser();
}
// Object customUser = ExternalUserFactory.getCustomUserObject(thisUser);
// if (customUser instanceof PersonalisedNewsTarget) {
// newsPortlet.addAttribute(PERSONALISED_ATTRIBUTE, "true");
// getPersonalisedNews(
// state,
// newsPortlet,
// (PersonalisedNewsTarget) customUser,
// formatter);
//
// } else {
newsPortlet.addAttribute(PERSONALISED_ATTRIBUTE, "false");
getGeneralNews(newsPortlet, formatter);
// }
newsPortlet.addAttribute(NEWS_ROOM_ATTRIBUTE,
NewsPortlet.getConfig().getNewsroomShortcut());
s_log.debug("FINISH - generateBodyXML");
}
/**
* @param newsPortlet
* @param profiledUser
*/
/* CURRENTLY NOT AVAILABLE
private void getPersonalisedNews( PageState state,
Element main,
PersonalisedNewsTarget profiledUser,
DateFormat formatter) {
s_log.debug("START - getPersonalisedNews");
DomainCollection myNews = profiledUser.getMyNews();
if (myNews == null) {
// method in personalised user class has been implemented to just return null
getGeneralNews(main, formatter);
return;
}
myNews.addOrder(ContentPage.LAUNCH_DATE + " desc");
PermissionService.filterObjects(
myNews,
PrivilegeDescriptor.get(SecurityManager.CMS_READ_ITEM),
Kernel.getContext().getParty().getOID());
myNews.setRange(
new Integer(1),
new Integer(m_portlet.getItemCount() + 1));
while (myNews.next()) {
ContentPage page = (ContentPage) myNews.getDomainObject();
Element item = main.newChildElement(NEWS_ITEM_ELEMENT, XML_NEWS_NS);
Date d = page.getLaunchDate();
String date = (d != null) ? formatter.format(d) : "";
item.addAttribute(DATE_ATTRIBUTE, date);
item.addAttribute(TITLE_ATTRIBUTE, page.getTitle());
item.addAttribute(LEAD_ATTRIBUTE, page.getSearchSummary());
item.addAttribute(
URL_ATTRIBUTE,
Navigation.redirectURL(page.getOID()));
}
s_log.debug("END - getPersonalisedNews");
}
*/
private void getGeneralNews(Element main, DateFormat formatter) {
s_log.debug("START - getGeneralNews");
// this is the default key - maybe should parametrise
Domain rss = Domain.retrieve("APLAWS-RSS");
DomainCollection rssRoots = rss.getRootTerms();
rssRoots.addEqualsFilter(Term.NAME, "News");
Term newsTerm = null;
while (rssRoots.next()) {
newsTerm = (Term) rssRoots.getDomainObject();
s_log.debug("found the news rss feed term");
Category cat = newsTerm.getModel();
DataCollection newsItems = SessionManager.getSession()
.retrieve(ContentPage.BASE_DATA_OBJECT_TYPE);
newsItems.addEqualsFilter("parent.categories.id",
cat.getID());
newsItems.addEqualsFilter(ContentItem.VERSION, ContentItem.LIVE);
newsItems.addOrder(ContentPage.LAUNCH_DATE + " desc");
// CategorizedCollection newsItems =
// cat.getObjects(ContentPage.BASE_DATA_OBJECT_TYPE);
s_log.debug("total items = " + newsItems.size());
newsItems.setRange(
new Integer(1),
new Integer(m_portlet.getItemCount() + 1));
ContentPage newsItem = null;
while (newsItems.next()) {
Element item =
main.newChildElement(NEWS_ITEM_ELEMENT, XML_NEWS_NS);
//newsItem = (ContentPage) newsItems.getDomainObject();
newsItem = (ContentPage)DomainObjectFactory
.newInstance(newsItems.getDataObject());
Date d = newsItem.getLaunchDate();
String date = (d != null) ? formatter.format(d) : "";
item.addAttribute(DATE_ATTRIBUTE, date);
item.addAttribute(TITLE_ATTRIBUTE, newsItem.getTitle());
item.addAttribute(LEAD_ATTRIBUTE, newsItem.getSearchSummary());
item.addAttribute(
URL_ATTRIBUTE,
Navigation.redirectURL(newsItem.getOID()));
}
}
s_log.debug("END - getGeneralNews");
}
/*
public Object getCacheKey() {
if (getProfiledUser() == null) {
return GENERAL_NEWS_CACHE_KEY;
} else {
return m_portlet.getID();
}
}
// is dirty if edited, as this means the number of entries has changed.
// For non personalised news, dirty if homepage
// newsitems are added or edited.
// For personalised, dirty if pushed items added or edited.
public boolean isDirty() {
// has it been edited? - add in this condition when response
// from Redhat about AbstractPortletRenderer
// if not has news changed
if (getCacheKey().equals(GENERAL_NEWS_CACHE_KEY)) {
isDirty = m_portlet.isNewNews();
s_log.debug("general news: dirty? " + isDirty);
} else {
// implement later
isDirty = true;
}
}
return isDirty;
*/
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

View File

@ -0,0 +1,83 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:news-portlet="http://wsgfl.westsussex.gov.uk/portlet/news/1.0"
xmlns:portlet="http://www.uk.arsdigita.com/portlet/1.0"
xmlns:bebop="http://www.arsdigita.com/bebop/1.0"
version="1.0" >
<xsl:param name="internal-theme"/>
<xsl:template match="portlet:news">
<xsl:if test="@personalised= 'true'">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="3">
<img alt="" src="{$internal-theme}/images/spacer.gif" width="100%" />
</td>
<td class="portletText">
Latest articles for you...
</td>
</tr>
</table>
</xsl:if>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<xsl:apply-templates />
<tr>
<td colspan="3" width="100%" height="7">
<img alt="" src="{$internal-theme}/images/spacer.gif"
width="100%" height="3" />
</td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td height="20" width="" valign="middle" class="portletText">
<br/>
<img alt = "" src="/STATIC/portlet/spacer.gif" width="8" />
<a href="{@newsroom-shortcut}">News Room</a>
<img alt="" src="{$internal-theme}/images/spacer.gif" width="10"
height="1" />
<a href="{@newsroom-shortcut}">
<img src="{$internal-theme}/images/portlets/news_arrow.gif"
alt="More News" />
</a>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="news-portlet:newsItem">
<tr>
<td colspan="3" width="100%" height="7">
<img alt="" src="{$internal-theme}/images/spacer.gif" width="100%" height="3" />
</td>
</tr>
<tr>
<td height="20" width="" valign="middle" class="portletText">
<img alt = "" src="{$internal-theme}/images/portlets/arrow_bullet.gif" />
</td>
<td height="20" width="423" align="left" valign="middle" class="portletText">
<a>
<xsl:attribute name="href">
<xsl:value-of select="@url" />
</xsl:attribute>
<xsl:value-of select="@title" />
</a>
-
<xsl:value-of select="@date" />
</td>
<td height="20" valign="middle" width="2" class="portletText"></td>
</tr>
<tr>
<td></td>
<td width="423" align="left" valign="middle" class="portletText">
<xsl:value-of select="@lead" />
</td>
</tr>
</xsl:template>
</xsl:stylesheet>