📄 applicationshortcutform.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.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.boot.PropertyList;
import com.sslexplorer.extensions.ApplicationParameterDefinition;
import com.sslexplorer.extensions.ApplicationShortcut;
import com.sslexplorer.extensions.ExtensionDescriptor;
import com.sslexplorer.extensions.ShortcutParameterItem;
import com.sslexplorer.extensions.store.ExtensionStore;
import com.sslexplorer.input.MultiSelectSelectionModel;
import com.sslexplorer.policyframework.Resource;
import com.sslexplorer.policyframework.forms.AbstractFavoriteResourceForm;
import com.sslexplorer.security.User;
/**
* Extension of {@link com.sslexplorer.policyframework.forms.AbstractFavoriteResourceForm}
* that allows editing of an <i>Application Shortcut</i>.
*
* @author Brett Smith <a href="mailto: brett@3sp.com"><brett@3sp.com></a>
* @version $Revision: 1.6 $
*/
public class ApplicationShortcutForm extends AbstractFavoriteResourceForm {
static Log log = LogFactory.getLog(ApplicationShortcutForm.class);
// Private instance variables
private String selectedTab = "details";
private List parameterItems;
private List categories;
private List categoryTitles;
/**
* 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 org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
* javax.servlet.http.HttpServletRequest)
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errs = super.validate(mapping, request);
if (isCommiting()) {
for (Iterator i = parameterItems.iterator(); i.hasNext();) {
ShortcutParameterItem item = (ShortcutParameterItem) i.next();
ActionMessage err = item.validateItem();
if (err != null) {
if (errs == null) {
errs = new ActionErrors();
}
errs.add(Globals.ERROR_KEY, err);
}
}
}
return errs;
}
/* (non-Javadoc)
* @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, 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 2 + ( categories == null ? 0 : categories.size() );
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.tabs.TabModel#getTabName(int)
*/
public String getTabName(int idx) {
switch (idx) {
case 0:
return "details";
case 1:
return "policies";
default:
return (String)categories.get(idx - 2);
}
}
/* (non-Javadoc)
* @see com.sslexplorer.tabs.TabModel#getTabTitle(int)
*/
public String getTabTitle(int idx) {
return idx < 2 || ((String)categoryTitles.get(idx - 2)).equals("") ? null : (String)categoryTitles.get(idx - 2);
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.policyframework.forms.AbstractResourceForm#initialise(com.sslexplorer.security.User,
* com.sslexplorer.boot.policyframework.Resource, boolean,
* com.sslexplorer.boot.MultiSelectSelectionModel,
* com.sslexplorer.boot.PropertyList, com.sslexplorer.security.User)
*/
public void initialise(User user, Resource resource, boolean editing, MultiSelectSelectionModel policyModel,
PropertyList selectedPolicies, User owner) throws Exception {
super.initialise(user, resource, editing, policyModel, selectedPolicies, owner);
//
parameterItems = new ArrayList();
// Get the application selected in the previous step and retrieve all of
// the shortcut parameter items
ExtensionDescriptor des = ExtensionStore.getInstance().getExtensionDescriptor(((ApplicationShortcut)resource).getApplication());
if(des == null) {
throw new Exception("No descriptor named " + ((ApplicationShortcut)resource).getApplication());
}
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, (String)((ApplicationShortcut)resource).getParameters().get(def.getName()));
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 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;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.policyframework.forms.AbstractResourceForm#applyToResource()
*/
public void applyToResource() throws Exception {
ApplicationShortcut as = (ApplicationShortcut)getResource();
Map parameterMap = as.getParameters();
parameterMap.clear();
for (Iterator i = getParameterItems().iterator(); i.hasNext();) {
ShortcutParameterItem pi = (ShortcutParameterItem) i.next();
parameterMap.put(pi.getName(), pi.getPropertyValue().toString());
}
}
/* (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 + -