📄 rssfeedslist.java
字号:
/*
* This library is part of the code for the book: OpenCms for Developers
*
* Copyright (c) 2007, 2008 Dan Liliedahl
*
* 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.deepthoughts.rss.admin;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.opencms.file.CmsResource;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsRuntimeException;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.list.A_CmsListDialog;
import org.opencms.workplace.list.CmsListColumnAlignEnum;
import org.opencms.workplace.list.CmsListColumnDefinition;
import org.opencms.workplace.list.CmsListDefaultAction;
import org.opencms.workplace.list.CmsListDirectAction;
import org.opencms.workplace.list.CmsListIndependentAction;
import org.opencms.workplace.list.CmsListItem;
import org.opencms.workplace.list.CmsListItemDetails;
import org.opencms.workplace.list.CmsListItemDetailsFormatter;
import org.opencms.workplace.list.CmsListMetadata;
import org.opencms.workplace.list.CmsListOrderEnum;
import org.opencms.workplace.list.CmsListSearchAction;
import com.deepthoughts.rss.RssChannelDef;
import com.deepthoughts.rss.RssChannelSrc;
public class RSSFeedsList extends A_CmsListDialog {
/** list id constant. */
public static final String LIST_ID = "rssfi";
/** list column name id constants */
public static final String LIST_COLUMN_NAME = "cn";
private static final String LIST_COLUMN_TYPE = "ct";
private static final String LIST_COLUMN_PATH = "cp";
public static final String LIST_COLUMN_EDIT = "ce";
public static final String LIST_COLUMN_DELETE = "cd";
public static final String LIST_COLUMN_PUBLISH = "cb";
/** list column action id constants */
public static final String LIST_ACTION_REFRESH = "rf";
public static final String LIST_ACTION_DETAILS= "de";
public static final String LIST_ACTION_EDIT = "ae";
public static final String LIST_ACTION_DELETE = "ad";
public static final String LIST_ACTION_PUBLISH = "ap";
/**
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public RSSFeedsList(PageContext context, HttpServletRequest req, HttpServletResponse res) {
super(new CmsJspActionElement(context, req, res),
LIST_ID,
Messages.get().container(Messages.GUI_RSSFEEDS_LIST_DIALOG_GROUP_NAME_0),
LIST_COLUMN_NAME,
CmsListOrderEnum.ORDER_ASCENDING, LIST_COLUMN_PATH);
}
/**
* @see org.opencms.workplace.CmsWorkplace#initMessages()
*/
protected void initMessages() {
// add specific dialog resource bundle
addMessages(Messages.get().getBundleName());
super.initMessages();
}
protected void setColumns(CmsListMetadata metadata) {
// Create a column for deletion action
CmsListColumnDefinition deleteCol = new CmsListColumnDefinition(LIST_COLUMN_DELETE);
deleteCol.setName(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_COL_DELETE_0));
deleteCol.setHelpText(Messages.get().container(Messages.GUI_LIST_COLS_RSSDELETE_HELP_0));
deleteCol.setWidth("20");
deleteCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
deleteCol.setSorteable(false);
// add delete action
CmsListDirectAction deleteAction = new CmsListDirectAction(LIST_ACTION_DELETE);
deleteAction.setName(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_ACTION_DELETE_NAME_0));
deleteAction.setHelpText(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_ACTION_DELETE_HELP_0));
deleteAction.setConfirmationMessage(new CmsMessageContainer(null, "Are you sure you want to delete the selected RSS Channel?"));
deleteAction.setIconPath(ICON_DELETE);
// add the action to the column
deleteCol.addDirectAction(deleteAction);
// add the column to the meta-data
metadata.addColumn(deleteCol);
// Create a column for publish action
CmsListColumnDefinition publishCol = new CmsListColumnDefinition(LIST_COLUMN_PUBLISH);
publishCol.setName(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_COL_PUBLISH_0));
publishCol.setHelpText(Messages.get().container(Messages.GUI_LIST_COLS_RSSPUBLISH_HELP_0));
publishCol.setWidth("20");
publishCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
publishCol.setSorteable(false);
// add publish action
CmsListDirectAction publishAction = new CmsListDirectAction(LIST_ACTION_PUBLISH);
publishAction.setName(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_ACTION_PUBLISH_NAME_0));
publishAction.setHelpText(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_ACTION_PUBLISH_HELP_0));
publishAction.setConfirmationMessage(new CmsMessageContainer(null, "Are you sure you want to publish the selected RSS Channel?"));
publishAction.setIconPath("list/rightarrow.png");
publishCol.addDirectAction(publishAction);
metadata.addColumn(publishCol);
// add column for name
CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME);
nameCol.setName(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_COL_NAME_0));
nameCol.setWidth("33%");
nameCol.setSorteable(true);
nameCol.setHelpText(Messages.get().container(Messages.GUI_LIST_COL_RSSEDIT_HELP_0));
// Add edit action by clicking on it
CmsListDefaultAction defEditAction = new CmsListDefaultAction(LIST_ACTION_EDIT);
nameCol.addDefaultAction(defEditAction);
metadata.addColumn(nameCol);
// add edit action
CmsListDirectAction editAction = new CmsListDirectAction(LIST_ACTION_EDIT);
editAction.setName(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_ACTION_EDIT_NAME_0));
editAction.setHelpText(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_ACTION_EDIT_HELP_0));
editAction.setIconPath(ICON_ADD);
// Add column for content paths
CmsListColumnDefinition pathCol = new CmsListColumnDefinition(LIST_COLUMN_PATH);
pathCol.setName(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_COL_PATH_0));
pathCol.setWidth("33%");
pathCol.setSorteable(true);
metadata.addColumn(pathCol);
// Add column for content types
CmsListColumnDefinition typeCol = new CmsListColumnDefinition(LIST_COLUMN_TYPE);
typeCol.setName(Messages.get().container(Messages.GUI_RSSFEEDS_LIST_COL_TYPE_0));
typeCol.setWidth("33%");
typeCol.setSorteable(true);
metadata.addColumn(typeCol);
}
protected List getListItems() throws CmsException {
List lstItems = new ArrayList();
// get the list of RSS Feeds
List lstFeeds = RSSFeedManager.getFeedManager(getCms()).getChannels();
if (null != lstFeeds) {
Iterator iFeeds = lstFeeds.iterator();
while (iFeeds.hasNext()) {
CmsResource feed = (CmsResource)iFeeds.next();
RssChannelDef channel = new RssChannelDef(getCms(), feed);
// name
CmsListItem item = getList().newItem(channel.getName());
item.set(LIST_COLUMN_NAME, channel.getName());
// paths
RssChannelSrc[] aSources = channel.getChannelSources();
StringBuffer sbPath = new StringBuffer();
StringBuffer sbType = new StringBuffer();
for (int i=0; i<aSources.length; i++) {
sbPath.append(aSources[i].getSourceLocation());
sbPath.append("<p>");
item.set(LIST_COLUMN_PATH, sbPath.toString());
// type
sbType.append(aSources[i].getSourceContentType());
sbType.append("<p>");
item.set(LIST_COLUMN_TYPE, sbType.toString());
}
lstItems.add(item);
}
}
return lstItems;
}
protected void setIndependentActions(CmsListMetadata metadata) {
// makes the list searchable by several columns
CmsListSearchAction searchAction = new CmsListSearchAction(metadata.getColumnDefinition(LIST_COLUMN_NAME));
searchAction.addColumn(metadata.getColumnDefinition(LIST_COLUMN_PATH));
searchAction.addColumn(metadata.getColumnDefinition(LIST_COLUMN_TYPE));
metadata.setSearchAction(searchAction);
// add feed details action
CmsListItemDetails rssItemsDetails = new CmsListItemDetails(LIST_ACTION_DETAILS);
rssItemsDetails.setAtColumn(LIST_COLUMN_NAME);
rssItemsDetails.setVisible(false);
rssItemsDetails.setShowActionName(Messages.get().container(Messages.GUI_RSSFEEDS_SHOW_DETAIL_NAME_0));
rssItemsDetails.setShowActionHelpText(Messages.get().container(Messages.GUI_RSSFEEDS_SHOW_DETAIL_HELP_0));
rssItemsDetails.setHideActionName(Messages.get().container(Messages.GUI_RSSFEEDS_HIDE_DETAIL_NAME_0));
rssItemsDetails.setHideActionHelpText(Messages.get().container(Messages.GUI_RSSFEEDS_HIDE_DETAIL_HELP_0));
rssItemsDetails.setName(Messages.get().container(Messages.GUI_RSSFEEDS_DETAIL_NAME_0));
rssItemsDetails.setFormatter(new CmsListItemDetailsFormatter(Messages.get().container(
Messages.GUI_RSSFEEDS_DETAIL_NAME_0)));
metadata.addItemDetails(rssItemsDetails);
// add refresh action
CmsListIndependentAction refreshAction = new CmsListIndependentAction(LIST_ACTION_REFRESH);
refreshAction.setName(Messages.get().container(Messages.GUI_RSSFEEDS_REFRESH_NAME_0));
refreshAction.setHelpText(Messages.get().container(Messages.GUI_RSSFEEDS_REFRESH_HELP_0));
refreshAction.setIconPath(ICON_MULTI_ADD);
metadata.addIndependentAction(refreshAction);
}
protected void setMultiActions(CmsListMetadata metadata) {
// not supported
}
/**
* Execute actions that are independant of an item
*/
public void executeListIndepActions() {
if (getParamListAction().equals(LIST_ACTION_REFRESH)) {
refreshList();
}
super.executeListIndepActions();
}
/**
* Execute actions applied to multiple items
*/
public void executeListMultiActions() throws IOException, ServletException,
CmsRuntimeException {
// (we don't support any)
throwListUnsupportedActionException();
}
/**
* Execute actions performed to single item selections
*/
public void executeListSingleActions() throws IOException,
ServletException, CmsRuntimeException {
// get the selected item row
CmsListItem item = getSelectedItem();
// get the name of the feed (VFS path)
String strFeed = item.get(LIST_COLUMN_NAME).toString();
if (getParamListAction().equals(LIST_ACTION_EDIT)) {
// go to the 'new rss' page
Map params = new HashMap();
params.put("feed", strFeed);
// set action parameter to initial dialog call
params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
getToolManager().jspForwardTool(this, getCurrentToolPath() + "/new_rsschannel", params);
} else if (LIST_ACTION_DELETE.equals(getParamListAction())) {
// delete the feed
RSSFeedManager.getFeedManager(getCms()).deleteChannel(strFeed);
} else if (LIST_ACTION_PUBLISH.equals(getParamListAction())) {
// publish the feed
RSSFeedManager.getFeedManager(getCms()).publishChannel(strFeed);
refreshList();
} else {
throwListUnsupportedActionException();
}
// save any changes
listSave();
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
*/
protected void fillDetails(String detailId) {
// get content
List users = getList().getAllContent();
Iterator itUsers = users.iterator();
while (itUsers.hasNext()) {
CmsListItem item = (CmsListItem)itUsers.next();
String feedName = item.get(LIST_COLUMN_NAME).toString();
CmsResource feed;
try {
feed = getCms().readResource(RSSFeedManager.getFeedRepositoryPath() + feedName);
StringBuffer html = new StringBuffer(512);
if (detailId.equals(LIST_ACTION_DETAILS)) {
SimpleDateFormat sdf = new SimpleDateFormat("MMM-dd-yyyy");
html.append("Last Updated On: ");
html.append(sdf.format(feed.getDateLastModified()));
html.append("<br>");
// has it changed since last publish?
if (feed.getState().isChanged() && !feed.getState().isNew()) {
html.append("<font color='red'>(needs publishing)</font>");
} else if (feed.getState().isNew()) {
html.append("<font color='red'>(never published)</font>");
}
} else {
continue;
}
item.set(detailId, html.toString());
} catch (CmsException e1) {
e1.printStackTrace();
}
}
}
/**
* @see org.opencms.workplace.list.A_CmsListDialog#customHtmlStart()
*/
protected String customHtmlStart() {
StringBuffer result = new StringBuffer(512);
result.append(dialogBlockStart(this.getMessages().key(Messages.GUI_RSSFEEDS_LIST_DIALOG_TITLE_NAME_0)));
result.append("<br><center>The RSS feeds listed below are located in the VFS at /system/shared/rssfeeds</center><br>");
result.append(dialogBlockEnd());
return result.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -