📄 applicationshortcutwizardadditionaldetailsform.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.extensions.wizards.forms;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.sslexplorer.boot.PropertyDefinition;
import com.sslexplorer.extensions.ApplicationParameterDefinition;
import com.sslexplorer.extensions.ExtensionDescriptor;
import com.sslexplorer.extensions.ShortcutParameterItem;
import com.sslexplorer.extensions.store.ExtensionStore;
import com.sslexplorer.tabs.TabModel;
import com.sslexplorer.wizard.AbstractWizardSequence;
import com.sslexplorer.wizard.forms.DefaultWizardForm;
/**
* Extension of a {@link com.sslexplorer.wizard.forms.DefaultWizardForm} that
* allows an administrator to enter the application shortcut parameters for the
* selected application.
* <p>
* The list of available parameters is also categorised. This allows the
* UI to organise the items (into tabs in the default UI).
*
* @author Brett Smith <a href="mailto: brett@3sp.com"><brett@3sp.com></a>
* @version $Revision: 1.4 $
*/
public class ApplicationShortcutWizardAdditionalDetailsForm extends DefaultWizardForm implements TabModel {
final static Log log = LogFactory.getLog(ApplicationShortcutWizardAdditionalDetailsForm.class);
/**
* Key used to store the map of applicaiton shortcut parameters
*/
public final static String ATTR_PARAMETERS = "parameters";
// Private instance variables
private List parameterItems;
private List categories;
private List categoryTitles;
private String selectedTab;
/**
* Constructor
*/
public ApplicationShortcutWizardAdditionalDetailsForm() {
super(true, true, "/WEB-INF/jsp/content/extensions/applicationShortcutWizard/additionalDetails.jspf", "resourceName", true,
false, "applicationShortcutAdditionalDetails", "extensions",
"applicationShortcutWizard.applicationShortcutAdditionalDetails", 3);
}
/**
* Get the list of {@link com.sslexplorer.extensions.ShortcutParameterItem}
* objects that are appropriate for the selected application.
*
* @return list of application shortcut parameter items
*/
public List getParameterItems() {
return parameterItems;
}
/**
* Get a {@link com.sslexplorer.extensions.ShortcutParameterItem} from
* this list of objects that are appropriate for the selected application
* at the specified index.
*
* @param idx index of parameter
* @return application shortcut parameter item
*/
public ShortcutParameterItem getParameterItem(int idx) {
return (ShortcutParameterItem)parameterItems.get(idx);
}
/**
* Get a list of category IDs as {@link String} objects.
*
* @return categories
*/
public List getCategories() {
return categories;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence,
* javax.servlet.http.HttpServletRequest)
*/
public void init(AbstractWizardSequence wizardSequence, HttpServletRequest request) throws Exception {
super.init(wizardSequence, request);
//
parameterItems = (List)wizardSequence.getAttribute(ATTR_PARAMETERS, null);
// Get the application selected in the previous step and retrieve all of
// the shortcut parameter items
ExtensionDescriptor des = ExtensionStore.getInstance().getExtensionDescriptor(
(String) wizardSequence.getAttribute(ApplicationShortcutWizardApplicationForm.ATTR_SELECTED_APPLICATION, null));
if(parameterItems == null) {
parameterItems = new ArrayList();
for (Iterator i = des.getParametersAndDefaults().entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
ApplicationParameterDefinition def = (ApplicationParameterDefinition) entry.getValue();
if (!def.isHidden()) {
ShortcutParameterItem item = new ShortcutParameterItem(des, def, def.getDefaultValue().equals(
ExtensionDescriptor.UNDEFINED_PARAMETER) ? "" : def.getDefaultValue());
if (log.isDebugEnabled())
log.debug("Adding item " + item.getName());
parameterItems.add(item);
}
}
Collections.sort(parameterItems);
// Now we have a sorted list of parameter items, build up the list of categories
categories = new ArrayList();
categoryTitles = new ArrayList();
for (Iterator i = parameterItems.iterator(); i.hasNext();) {
ShortcutParameterItem spi = (ShortcutParameterItem)i.next();
String category = String.valueOf(spi.getCategory());
if(!categories.contains(category)) {
categories.add(category);
categoryTitles.add(spi.getLocalisedCategory());
}
}
}
}
/*
* (non-Javadoc)
*
* @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
* javax.servlet.http.HttpServletRequest)
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = null;
if (isCommiting()) {
for (Iterator i = parameterItems.iterator(); i.hasNext();) {
ShortcutParameterItem item = (ShortcutParameterItem) i.next();
ActionMessage err = item.validateItem();
if (err != null) {
if (errors == null) {
errors = new ActionErrors();
}
errors.add(Globals.ERROR_KEY, err);
}
}
}
return errors;
}
/*
* (non-Javadoc)
*
* @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping,
* javax.servlet.http.HttpServletRequest)
*/
public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {
if (parameterItems != null) {
for (Iterator i = parameterItems.iterator(); i.hasNext();) {
ShortcutParameterItem item = (ShortcutParameterItem) i.next();
if (item.getDefinition().getType() == PropertyDefinition.TYPE_BOOLEAN) {
item.setValue(Boolean.FALSE.toString());
} else if (item.getDefinition().getType() == PropertyDefinition.TYPE_LIST) {
item.setValue(item.getDefinition().getDefaultValue());
}
}
}
}
/* (non-Javadoc)
* @see com.sslexplorer.tabs.TabModel#getTabCount()
*/
public int getTabCount() {
return categories.size();
}
/* (non-Javadoc)
* @see com.sslexplorer.tabs.TabModel#getTabName(int)
*/
public String getTabName(int idx) {
return (String)categories.get(idx);
}
/* (non-Javadoc)
* @see com.sslexplorer.tabs.TabModel#getTabTitle(int)
*/
public String getTabTitle(int idx) {
String title = (String)categoryTitles.get(idx);
return title.equals("") ? null : title;
}
/* (non-Javadoc)
* @see com.sslexplorer.tabs.TabModel#getSelectedTab()
*/
public String getSelectedTab() {
return selectedTab;
}
/* (non-Javadoc)
* @see com.sslexplorer.tabs.TabModel#setSelectedTab(java.lang.String)
*/
public void setSelectedTab(String selectedTab) {
this.selectedTab = selectedTab;
}
public void apply(AbstractWizardSequence sequence) throws Exception {
super.apply(sequence);
sequence.putAttribute(ATTR_PARAMETERS, parameterItems);
}
/* (non-Javadoc)
* @see com.sslexplorer.tabs.TabModel#getTabBundle(int)
*/
public String getTabBundle(int idx) {
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -