📄 defaultpropertiesform.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.properties.forms;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionMapping;
import com.sslexplorer.boot.PropertyDefinition;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.EntryIterator;
import com.sslexplorer.core.forms.CoreForm;
import com.sslexplorer.properties.PropertyItem;
import com.sslexplorer.properties.PropertyProfile;
import com.sslexplorer.security.Constants;
/**
* @author Brett Smith
* @version $Revision: 1.3 $
*/
public class DefaultPropertiesForm extends CoreForm implements PropertiesForm {
static Log log = LogFactory.getLog(DefaultPropertiesForm.class);
private PropertyItem[] propertyItems;
private String profileScope;
private String forwardTo;
private int parentCategory;
private String input;
private boolean redirect;
private List propertyProfiles;
private int selectedPropertyProfile;
private String updateAction;
private List categoryDefinitions;
private int selectedCategory;
private HashMap store;
private int newSelectedCategory;
private List subCategories;
private List path;
public DefaultPropertiesForm() {
super();
store = new HashMap();
path = new ArrayList();
}
public boolean getEnabled() {
if (Constants.SCOPE_SETUP.equals(getProfileScope())) {
return true;
}
try {
PropertyProfile profile = CoreServlet.getServlet().getPropertyDatabase().getPropertyProfile(
getSelectedPropertyProfile());
boolean global = profile.getOwnerUsername() == null || profile.getOwnerUsername().equals("");
return (Constants.SCOPE_PERSONAL.equals(getProfileScope()) && !global)
|| (Constants.SCOPE_GLOBAL.equals(getProfileScope()) && global);
} catch (Exception e) {
log.error("Failed to get property profile details. Disabling form.", e);
return false;
}
}
public String getForwardTo() {
return forwardTo;
}
public void setForwardTo(String forwardTo) {
this.forwardTo = forwardTo;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {
if (log.isDebugEnabled())
log.debug("Reseting properties form");
super.reset(mapping, request);
if (propertyItems != null) {
for (int i = 0; i < propertyItems.length; i++) {
if (propertyItems[i].getDefinition().getType() == PropertyDefinition.TYPE_BOOLEAN) {
propertyItems[i].setValue(Boolean.FALSE.toString());
} else if (propertyItems[i].getDefinition().getType() == PropertyDefinition.TYPE_LIST) {
propertyItems[i].setValue(propertyItems[i].getDefinition().getDefaultValue());
}
}
}
}
public String getUpdateAction() {
return updateAction;
}
public PropertyItem[] getPropertyItems() {
return propertyItems;
}
public void setCategoryDefinitions(List categoryDefinitions) {
this.categoryDefinitions = categoryDefinitions;
}
public void setPropertyItems(PropertyItem[] propertyItems) {
this.propertyItems = propertyItems;
;
}
public void setPropertyItem(int idx, PropertyItem item) {
propertyItems[idx] = item;
}
public PropertyItem getPropertyItem(int idx) {
return propertyItems[idx];
}
public void setProfileScope(String profileScope) {
this.profileScope = profileScope;
}
public String getProfileScope() {
return profileScope;
}
public void setParentCategory(int parentCategory) {
this.parentCategory = parentCategory;
}
public int getParentCategory() {
return parentCategory;
}
public void setRedirect(boolean redirect) {
this.redirect = redirect;
}
public boolean isRedirect() {
return redirect;
}
public void setPropertyProfiles(List propertyProfiles) {
this.propertyProfiles = propertyProfiles;
}
public List getPropertyProfiles() {
return propertyProfiles;
}
public void setSelectedPropertyProfile(int id) {
selectedPropertyProfile = id;
}
public int getSelectedPropertyProfile() {
return selectedPropertyProfile;
}
public void setUpdateAction(String updateAction) {
this.updateAction = updateAction;
}
public boolean getHasProfiles() {
return propertyProfiles != null && !Constants.SCOPE_SETUP.equals(profileScope);
}
public List getCategoryDefinitions() {
return categoryDefinitions;
}
public void setSelectedCategory(int selectedCategory) {
this.selectedCategory = selectedCategory;
}
public int getSelectedCategory() {
return selectedCategory;
}
public PropertyItem retrieveItem(String name, PropertyItem defaultValue) {
PropertyItem val = (PropertyItem)store.get(name);
return val == null ? defaultValue : val;
}
public void clearValues() {
store.clear();
}
public void storeItem(PropertyItem item) {
store.put(item.getName(), item);
}
public int getNewSelectedCategory() {
return newSelectedCategory;
}
public void setNewSelectedCategory(int newSelectedCategory) {
this.newSelectedCategory = newSelectedCategory;
}
public List getSubCategories() {
return subCategories;
}
public void setSubCategories(List subCategories) {
this.subCategories = subCategories;
}
public void pushCategory(int parentCategory) {
path.add(new Integer(parentCategory));
}
public int popCategory() {
if(path.size() > 0) {
int parentCategory = ((Integer)path.remove(path.size() - 1)).intValue();
return parentCategory;
}
return -1;
}
public void storeItems() {
PropertyItem[] items = getPropertyItems();
for (int i = 0; i < items.length; i++) {
PropertyDefinition def = items[i].getDefinition();
if (def.getCategory() == getSelectedCategory()) {
storeItem(items[i]);
}
}
}
public Iterator storedItems() {
return new EntryIterator(store);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -