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

📄 propertylist.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 */
package com.sslexplorer.boot;

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

/**
 * Extension of an {@link java.util.ArrayList} that is used to store lists
 * of strings. This class is used with SSL-Explorers custom input components
 * such as the {@link com.sslexplorer.input.tags.MultiSelectListBoxTag} and
 * {@link com.sslexplorer.input.tags.MultiEntryListBoxTag}. 
 * <p>
 * This list of strings may be created from or converted to and from 
 * either <i>Text Field Text</i> (a newline separated list of strings) or 
 * <i>Property Text</i> (a ! delimited list).
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.1 $
 */
public class PropertyList extends ArrayList {

    private static final long serialVersionUID = -6816117522796660457L;

    /**
     * Constructor. Create empty property list
     */
    public PropertyList() {
        super();
    }

    /**
     * Constructor. 
     * 
     * @param propertyList string in the <i>Property List</i> format.
     * @see #setAsPropertyText(String) 
     */
    public PropertyList(String propertyList) {
        this();
        setAsPropertyText(propertyList);
    }

    /**
     * Get the string item at the specified index
     * 
     * @param i index
     * @return string item
     */
    public String getPropertyItem(int i) {
        return (String) get(i);
    }

    /**
     * Set list of strings from a string in the <i>Property Text</i> format.
     * This is a bang (!) delimited list of string elements. Strings containing ! should escape this
     * character with a backslash (\).
     * 
     * @param propertyText property list string
     */
    public void setAsPropertyText(String propertyText) {
        clear();
        StringBuffer buf = new StringBuffer();
        char ch = ' ';
        boolean escaped = false;
        for (int i = 0; i < propertyText.length(); i++) {
            ch = propertyText.charAt(i);
            if (ch == '\\' && !escaped) {
                escaped = true;
            } else {
                if (ch == '!' && !escaped) {
                    add(buf.toString());
                    buf.setLength(0);
                } else {
                    buf.append(ch);
                    escaped = false;
                }
            }
        }
        if (buf.length() > 0) {
            add(buf.toString());
        }
    }

    /**
     * Get the list of strings in <i>Property Text</i> format. This is a  
     * strings in which each string element is delimited by a bang (!) character.
     * <p>
     * Strings containing the ! character escape it using a backslash (\). 
     * 
     * @return list of strings in property text format
     */
    public String getAsPropertyText() {
        StringBuffer buf = new StringBuffer();
        for (Iterator i = iterator(); i.hasNext();) {
            if (buf.length() > 0) {
                buf.append("!");
            }
            buf.append(i.next().toString().replaceAll("\\!", "!!"));
        }
        return buf.toString();
    }

    /**
     * Set list of strings from a string in the <i>Text Field Text</i> format.
     * This is a newline (\n) delimited list of string elements. 
     * 
     * @param textFieldText string in text field text format
     */
    public void setAsTextFieldText(String textFieldText) {
        clear();
        StringTokenizer t = new StringTokenizer(textFieldText, "\r\n");
        while (t.hasMoreTokens()) {
            add(((String) t.nextToken()).trim());
        }
    }

    /**
     * Get the list of strings in <i>Property Text</i> format. This is a  
     * strings in which each string element is delimited by a newline (\n) character. It is often
     * used as the request parameter used to pass a value into and out from
     * one of SSL-Explorers custom input components such as {@link com.sslexplorer.input.tags.MultiEntryListBoxTag}
     * or {@link com.sslexplorer.input.tags.MultiSelectListBoxTag}.
     * 
     * @return list of strings in property text format
     */
    public String getAsTextFieldText() {
        StringBuffer buf = new StringBuffer();
        for (Iterator i = iterator(); i.hasNext();) {
            if (buf.length() > 0) {
                buf.append("\n");
            }
            buf.append(i.next().toString());
        }
        return buf.toString();
    }
    
    /**
     * Utility method to create a list from a string in the <i>Text Field Text</i>
     * format.
     * 
     * @param textFieldText list of strings in text field text format.
     * @return property list
     * @see #setAsTextFieldText(String)
     */
    public static PropertyList createFromTextFieldText(String textFieldText) {
        PropertyList l = new PropertyList();
        l.setAsTextFieldText(textFieldText);
        return l;
    }
    
    /**
     * Create a property list from an array of strings
     * 
     * @param strings array of strings
     * @return property list
     */
    public static PropertyList createFromArray(String[] strings) {
        PropertyList l = new PropertyList();
        if (strings != null) {
            for (int i = 0; i < strings.length; i++) {
                l.add(strings[i]);
            }
        }
        return l;
    }

    /**
     * Get this property list as an array of strings
     * 
     * @return property list as array of strings
     */
    public String[] asArray() {
        String[] arr = new String[size()];
        toArray(arr);
        return arr;
    }

    /**
     * Get this property list as an array of primitive integers. If any
     * string is not an integer then an exception will be thrown
     * 
     * @return property list as array of primitive integers
     * @throws NumberFormatException
     */
    public int[] toIntArray() throws NumberFormatException {
        int[] arr = new int[size()];
        for(int i = size() - 1 ; i >=0 ; i--) {
            arr[i] = Integer.parseInt(get(i).toString());
        }
        return arr;
    }

    /**
     * Create a new property list from an array of primitive integers.
     * 
     * @param integers array of primitive integers 
     * @return property list
     */
    public static PropertyList createFromArray(int[] integers) {
        PropertyList l = new PropertyList();
        if (integers != null) {
            for (int i = 0; i < integers.length; i++) {
                l.add(String.valueOf(integers[i]));
            }
        }
        return l;
    }

    /**
     * Return a new list as a list of {@link Integer} objects
     * 
     * @return property list as list of Integer objects
     */
    public List getIntegerObjectList() {
        List l =new ArrayList();
        for(Iterator i = iterator(); i.hasNext(); ) {
            l.add(new Integer((String)i.next()));
        }
        return l;
    }

}

⌨️ 快捷键说明

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