📄 rssnewchanneldialog.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.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.widgets.CmsCalendarWidget;
import org.opencms.widgets.CmsDisplayWidget;
import org.opencms.widgets.CmsInputWidget;
import org.opencms.widgets.CmsVfsFileWidget;
import org.opencms.workplace.CmsWidgetDialog;
import org.opencms.workplace.CmsWidgetDialogParameter;
import org.opencms.workplace.CmsWorkplaceSettings;
import com.deepthoughts.rss.RssChannelDef;
public class RSSNewChannelDialog extends CmsWidgetDialog {
/** prefix for localized strings */
public static final String KEY_PREFIX = "rssadmin";
/** Defines which pages are valid for this dialog. */
public static final String[] PAGE_ARRAY = {"channel_info", "channel_name"};
/** The allowed pages for this dialog in a List. */
public static final List PAGE_LIST = Arrays.asList(PAGE_ARRAY);
/** The RSS Channel */
RssChannelDef m_channel;
/** Informational text */
String infoText;
public String getInfoText() {
return infoText;
}
public void setInfoText(String infoText) {
this.infoText = infoText;
}
/**
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public RSSNewChannelDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
super(new CmsJspActionElement(context, req, res));
}
/**
* @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
*/
protected String[] getPageArray() {
return PAGE_ARRAY;
}
/**
* @see org.opencms.workplace.CmsWidgetDialog#initMessages()
*/
protected void initMessages() {
// add default resource bundles
addMessages(Messages.get().getBundleName());
super.initMessages();
}
/**
* @see CmsWidgetDialog#initWorkplaceSettings(org.opencms.file.CmsObject, CmsWorkplaceSettings, boolean)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
// set the dialog message prefix
setKeyPrefix(KEY_PREFIX);
super.initWorkplaceRequestValues(settings, request);
// save the current state of the job (may be changed because of the widget values)
setDialogObject(m_channel);
}
/**
* Creates the list of widgets for this dialog.<p>
*/
protected void defineWidgets() {
// get the data fields from the context
getDialogData();
// Page 1
addWidget(new CmsWidgetDialogParameter(m_channel, "title", PAGE_ARRAY[0], new CmsInputWidget()));
addWidget(new CmsWidgetDialogParameter(m_channel, "description", PAGE_ARRAY[0], new CmsInputWidget()));
addWidget(new CmsWidgetDialogParameter(m_channel, "copyright", null, PAGE_ARRAY[0], new CmsInputWidget(), 0, 1 ));
addWidget(new CmsWidgetDialogParameter(m_channel, "author", null, PAGE_ARRAY[0], new CmsInputWidget(), 0, 1 ));
addWidget(new CmsWidgetDialogParameter(m_channel, "publishedDate", null, PAGE_ARRAY[0], new CmsCalendarWidget(), 0, 1));
addWidget(new CmsWidgetDialogParameter(m_channel, "image", null, PAGE_ARRAY[0], new CmsVfsFileWidget(), 0, 1));
addWidget(new CmsWidgetDialogParameter(m_channel, "imageTitle", null, PAGE_ARRAY[0], new CmsInputWidget(), 0, 1));
// Page 2
infoText = "Please enter a file name for this channel";
addWidget(new CmsWidgetDialogParameter(this, "infoText", null, PAGE_ARRAY[1], new CmsDisplayWidget()));
addWidget(new CmsWidgetDialogParameter(m_channel, "filename", null, PAGE_ARRAY[1], new CmsInputWidget()));
}
private boolean editChannelClicked() {
// see if the edit icon was clicked on
String strFeed = getJsp().getRequest().getParameter("feed");
if (null != strFeed) {
try {
// load the channel into the bean
m_channel = new RssChannelDef(getCms(), RSSFeedManager.getFeedRepositoryPath() + strFeed);
return true;
} catch (CmsException e) {
e.printStackTrace();
}
}
return false;
}
/**
* Obtains the dialog data from the context.
*/
private void getDialogData() {
Object o = getSettings().getDialogObject();
if (null == o) {
// first time, handle edit or new
// either a new channel or invoked from 'edit'
if (! editChannelClicked()) {
m_channel = new RssChannelDef(getCms());
}
} else {
// non-null dialog object, retrieve bean from state
Object existingChannel = ((Hashtable)o).get(this.getClass().getName());
if (null != existingChannel) {
m_channel = (RssChannelDef) existingChannel;
} else {
if (! editChannelClicked()) {
m_channel = new RssChannelDef(getCms());
}
}
}
}
/**
* Save the RSSChannelDef to a resource
*/
public void actionCommit() throws IOException, ServletException {
// Save the channel
RSSFeedManager.getFeedManager(getCms()).saveOrUpdateChannel(getJsp().getJspContext(), m_channel);
// clear the object
getSettings().setDialogObject(null);
m_channel = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -