⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applicationparameterdefinition.java

📁 这是linux下ssl vpn的实现程序
💻 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;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.sslexplorer.boot.PropertyDefinition;
import com.sslexplorer.boot.TypeMetaListItem;
import com.sslexplorer.security.UserAttributeDefinition;

/**
 * Implementation of {@link com.sslexplorer.boot.PropertyDefinition}
 * to be used for <i>Application Shortcut Parameters</i>.
 * <p>
 * These parameters are constructed from the the entries in an 
 * <i>Application Descriptor</i> that is embedded in the 
 * <i>Extension Descriptor</i>.
 * <p>
 * As the interface used implies, shortcut parameters support <i>Confidentials Properties</i>,
 * in the case known as <i>Confidential Application Shortcut Parameters</i>.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.9 $
 */
public class ApplicationParameterDefinition implements PropertyDefinition, Comparable {

    // Private instance variables
    
    private int type;
    private int sequence;
    private String name;
    private String typeMeta;
    private boolean hidden;
    private int category;
    private String defaultValue;
    private boolean optional;
    private Object typeMetaObject;
    private int visibility;

    /**
     * Constructor
     * 
     * @param element XML element to construct parameter from
     * @throws JDOMException on invalid XML
     */
    public ApplicationParameterDefinition(Element element) throws JDOMException {
        super();
        name = element.getAttributeValue("name");
        if (name == null || name.equals("")) {
            throw new JDOMException("Missing or empty name attribute in <parameter>");
        }
        try {
            type = Integer.parseInt(element.getAttributeValue("type"));
        } catch (Exception e) {
            throw new JDOMException("Missing or invalid type attribute in <parameter>");
        }
        try {
            sequence = Integer.parseInt(element.getAttributeValue("sequence"));
        } catch (Exception e) {
            sequence = 0;
        }
        typeMeta = element.getAttributeValue("typeMeta");
        hidden = "true".equalsIgnoreCase(element.getAttributeValue("hidden"));
        visibility = "true".equalsIgnoreCase(element.getAttributeValue("confidential")) ? UserAttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE : UserAttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE;
        optional = "true".equalsIgnoreCase(element.getAttributeValue("optional"));
        try {
            String c = element.getAttributeValue("category");
            if (c != null) {
                category = Integer.parseInt(c);
            }
        } catch (Exception e) {
            throw new JDOMException("Invalid category attribute in <parameter>");
        }
        defaultValue = element.getAttributeValue("default");
        defaultValue = defaultValue == null ? ExtensionDescriptor.UNDEFINED_PARAMETER : defaultValue;

        switch (type) {
        case TYPE_BOOLEAN:            
            typeMetaObject = new ArrayList();
            StringTokenizer t = typeMeta != null ? new StringTokenizer(typeMeta, ",") : null;
            if (t != null && t.hasMoreTokens()) {
                ((List) typeMetaObject).add(t.nextToken());
                ((List) typeMetaObject).add(t.nextToken());
            } else {
                ((List) typeMetaObject).add("true");
                ((List) typeMetaObject).add("false");
            }
            break;
        case TYPE_LIST:
            typeMetaObject = new ArrayList();
            StringTokenizer t2 = new StringTokenizer(typeMeta, ",");
            while (t2.hasMoreTokens()) {
                ((List) typeMetaObject).add(new TypeMetaListItem(t2.nextToken(), null));
            }
            break;

        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getType()
     */
    public int getType() {
        return type;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getName()
     */
    public String getName() {
        return name;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getTypeMeta()
     */
    public String getTypeMeta() {
        return typeMeta;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getDefaultValue()
     */
    public String getDefaultValue() {
        return defaultValue;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getCategory()
     */
    public int getCategory() {
        return category;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getVisibility()
     */
    public int getVisibility() {
        return visibility;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(Object obj) {
        int i = new Integer(getCategory()).compareTo(new Integer(((ApplicationParameterDefinition) obj).getCategory()));
        return i == 0 ? new Integer(sequence).compareTo(new Integer(((ApplicationParameterDefinition) obj).sequence)) : i;
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.boot.PropertyDefinition#isHidden()
     */
    public boolean isHidden() {
        return hidden;
    }

    /**
     * Get if this is an optional parameter.
     * 
     * @return optional
     */
    public boolean isOptional() {
        return optional;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#setTypeMeta(java.lang.String)
     */
    public void setTypeMeta(String typeMeta) {
        this.typeMeta = typeMeta;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getSortOrder()
     */
    public int getSortOrder() {
        return sequence;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#setDefaultValue(java.lang.String)
     */
    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getTypeMetaObject()
     */
    public Object getTypeMetaObject() {
        return typeMetaObject;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.boot.PropertyDefinition#getMessageResourcesKey()
     */
    public String getMessageResourcesKey() {
        return null;
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.boot.PropertyDefinition#setCategory(int)
     */
    public void setCategory(int category) {
        this.category = category;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -