Example usage for java.util Vector elements

List of usage examples for java.util Vector elements

Introduction

In this page you can find the example usage for java.util Vector elements.

Prototype

public Enumeration<E> elements() 

Source Link

Document

Returns an enumeration of the components of this vector.

Usage

From source file:examples.mail.java

public final static void main(String[] args) {
    String sender, recipient, subject, filename, server, cc;
    Vector ccList = new Vector();
    BufferedReader stdin;//from  w ww  .j  av a2s . co  m
    FileReader fileReader = null;
    Writer writer;
    SimpleSMTPHeader header;
    SMTPClient client;
    Enumeration en;

    if (args.length < 1) {
        System.err.println("Usage: mail smtpserver");
        System.exit(1);
    }

    server = args[0];

    stdin = new BufferedReader(new InputStreamReader(System.in));

    try {
        System.out.print("From: ");
        System.out.flush();

        sender = stdin.readLine();

        System.out.print("To: ");
        System.out.flush();

        recipient = stdin.readLine();

        System.out.print("Subject: ");
        System.out.flush();

        subject = stdin.readLine();

        header = new SimpleSMTPHeader(sender, recipient, subject);

        while (true) {
            System.out.print("CC <enter one address per line, hit enter to end>: ");
            System.out.flush();

            // Of course you don't want to do this because readLine() may be null
            cc = stdin.readLine().trim();

            if (cc.length() == 0)
                break;

            header.addCC(cc);
            ccList.addElement(cc);
        }

        System.out.print("Filename: ");
        System.out.flush();

        filename = stdin.readLine();

        try {
            fileReader = new FileReader(filename);
        } catch (FileNotFoundException e) {
            System.err.println("File not found. " + e.getMessage());
        }

        client = new SMTPClient();
        client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        client.connect(server);

        if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) {
            client.disconnect();
            System.err.println("SMTP server refused connection.");
            System.exit(1);
        }

        client.login();

        client.setSender(sender);
        client.addRecipient(recipient);

        en = ccList.elements();

        while (en.hasMoreElements())
            client.addRecipient((String) en.nextElement());

        writer = client.sendMessageData();

        if (writer != null) {
            writer.write(header.toString());
            Util.copyReader(fileReader, writer);
            writer.close();
            client.completePendingCommand();
        }

        fileReader.close();

        client.logout();

        client.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:Main.java

public static Vector tail(Vector v) {
    Vector result = new Vector();
    Enumeration e = v.elements();
    e.nextElement();//from   w  w  w .j  ava2s  .  co m
    while (e.hasMoreElements())
        result.addElement(e.nextElement());

    return result;
}

From source file:Main.java

public static Vector appendInto(Vector dest, Vector src) {
    Enumeration e = src.elements();
    while (e.hasMoreElements())
        dest.addElement(e.nextElement());
    return dest;//from   w w w .  ja v a2  s .c om
}

From source file:Main.java

/**
 * Create a Hashtable from a key, value, key, value... style
 * Vector./*w  ww. j  ava 2s . c  o m*/
 */
public static Hashtable createHashtable(Vector v) {
    return createHashtable(v.elements());
}

From source file:Main.java

/**
 * Create a Hashtable by pairing the given keys with the given values.
 * Equivalent to python code <code>dict(zip(keys, values))</code>
 *///from  w  w  w.  ja  va2  s. c o m
public static Hashtable createHashtable(Vector keys, Vector values) {
    Enumeration keyEnum = keys.elements();
    Enumeration valEnum = values.elements();

    Hashtable result = new Hashtable();
    while (keyEnum.hasMoreElements() && valEnum.hasMoreElements())
        result.put(keyEnum.nextElement(), valEnum.nextElement());

    return result;
}

From source file:Main.java

public static Vector copy(Vector v) {
    Vector copy = new Vector();
    synchronized (v) {
        for (Enumeration en = v.elements(); en.hasMoreElements();) {
            copy.addElement(en.nextElement());
        }/*from  w ww  .  java  2  s.  c  o  m*/
    }
    return copy;
}

From source file:Main.java

public static Enumeration getAllFilesIn(File dir) {
    File[] files;//w w w . ja  v a2s  .c o  m
    if (dir.isDirectory()) {
        files = dir.listFiles(new FileFilter() {
            public boolean accept(File f) {
                if (f.isDirectory())
                    return false;
                return (f.getName().endsWith(".txt"));
            }
        });
        Arrays.sort(files);
    } else {
        files = new File[] { dir };
    }
    Vector vect = new Vector(files.length);
    for (int i = 0; i < files.length; ++i)
        vect.addElement(files[i]);
    return vect.elements();
}

From source file:BoxSample.java

private static void tweak(Vector buttons) {
    // calc max preferred width
    JButton button;/*ww  w .j  a v a 2  s. c  om*/
    Dimension dim;
    int maxWidth = 0;
    Enumeration e = buttons.elements();
    while (e.hasMoreElements()) {
        button = (JButton) e.nextElement();
        dim = button.getPreferredSize();
        if (dim.width > maxWidth)
            maxWidth = dim.width;
    }
    // set max preferred width
    e = buttons.elements();
    while (e.hasMoreElements()) {
        button = (JButton) e.nextElement();
        dim = button.getPreferredSize();
        dim.width = maxWidth;
        button.setPreferredSize(dim);
    }
}

From source file:org.openxdata.server.util.XmlUtil.java

/**
 * Gets the text value of a node as pointed to by an xpath expression in an xml document.
 * //from ww  w.  j a  v  a  2 s .co m
 * @param doc the xml document.
 * @param xpath the xpath expression.
 * @return the text value.
 */
public static String getNodeValue(Document doc, String xpath) {
    //xpath = new String(xpath.toCharArray(), 1, xpath.length()-1);
    int pos = xpath.lastIndexOf('@');
    String attributeName = null;
    if (pos > 0) {
        attributeName = xpath.substring(pos + 1, xpath.length());
        xpath = xpath.substring(0, pos - 1);
    }

    XPathExpression xpls = new XPathExpression(doc.getDocumentElement(), xpath);
    Vector<?> result = xpls.getResult();
    for (Enumeration<?> e = result.elements(); e.hasMoreElements();) {
        Object obj = e.nextElement();
        if (obj instanceof Element) {
            if (pos > 0) //Check if we are to set attribute value.
                return ((Element) obj).getAttribute(attributeName);
            else
                return ((Element) obj).getTextContent();
        }
    }
    return null;
}

From source file:org.openxdata.server.util.XmlUtil.java

/**
 * Gets the text value of a node as pointed to by an xpath expression in an xml document
 * whose root node is given./* w  w  w .ja  v a2s. c om*/
 * 
 * @param node the root node.
 * @param xpath the xpath expression.
 * @return the text value.
 */
private static String getValue(Element node, String xpath) {
    int pos = xpath.lastIndexOf('@');
    String attributeName = null;
    if (pos > 0) {
        attributeName = xpath.substring(pos + 1, xpath.length());
        xpath = xpath.substring(0, pos - 1);
    }

    XPathExpression xpls = new XPathExpression(node, xpath);
    Vector<?> result = xpls.getResult();

    for (Enumeration<?> e = result.elements(); e.hasMoreElements();) {
        Object obj = e.nextElement();
        if (obj instanceof Element) {
            if (pos > 0) //Check if we are to set attribute value.
                return ((Element) obj).getAttribute(attributeName);
            else
                return ((Element) obj).getTextContent();
        }
    }

    return null;
}