Example usage for java.util Vector elementAt

List of usage examples for java.util Vector elementAt

Introduction

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

Prototype

public synchronized E elementAt(int index) 

Source Link

Document

Returns the component at the specified index.

Usage

From source file:FileTree.java

/** Add nodes from under "dir" into curTop. Highly recursive. */
DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) {
    String curPath = dir.getPath();
    DefaultMutableTreeNode curDir = new DefaultMutableTreeNode(curPath);
    if (curTop != null) { // should only be null at root
        curTop.add(curDir);//from  w  ww  .j  a v  a2s  . co  m
    }
    Vector ol = new Vector();
    String[] tmp = dir.list();
    for (int i = 0; i < tmp.length; i++)
        ol.addElement(tmp[i]);
    Collections.sort(ol, String.CASE_INSENSITIVE_ORDER);
    File f;
    Vector files = new Vector();
    // Make two passes, one for Dirs and one for Files. This is #1.
    for (int i = 0; i < ol.size(); i++) {
        String thisObject = (String) ol.elementAt(i);
        String newPath;
        if (curPath.equals("."))
            newPath = thisObject;
        else
            newPath = curPath + File.separator + thisObject;
        if ((f = new File(newPath)).isDirectory())
            addNodes(curDir, f);
        else
            files.addElement(thisObject);
    }
    // Pass two: for files.
    for (int fnum = 0; fnum < files.size(); fnum++)
        curDir.add(new DefaultMutableTreeNode(files.elementAt(fnum)));
    return curDir;
}

From source file:dao.CollModeratorsListQuery.java

/**
 * This method lists all the moderators for a collabrum
 * @param conn the connection/*ww  w .ja  va2 s  .c om*/
 * @param collabrumId the collabrumid
 * @return HashSet the set that has the list of moderators for these collabrums.
 * @throws BaseDaoException - when error occurs
 **/
public HashSet run(Connection conn, String collabrumId) throws BaseDaoException {

    String sqlQuery = "select distinct CONCAT(hd.fname,' ',hd.lname) AS membername, "
            + "hd.login, hd.loginid, c1.collabrumid, c2.name from colladmin c1, "
            + "hdlogin hd, collabrum c2 where c1.loginid=hd.loginid "
            + "and c1.collabrumid=c2.collabrumid and c1.collabrumid=" + collabrumId + "";
    try {
        PreparedStatement stmt = conn.prepareStatement(sqlQuery);
        ResultSet rs = stmt.executeQuery();
        Vector columnNames = null;
        Collabrum collabrum = null;
        HashSet pendingSet = new HashSet();

        if (rs != null) {
            columnNames = dbutils.getColumnNames(rs);
        }

        while (rs.next()) {
            collabrum = (Collabrum) eop.newObject("collabrum");
            for (int j = 0; j < columnNames.size(); j++) {
                collabrum.setValue((String) columnNames.elementAt(j),
                        (String) rs.getString((String) columnNames.elementAt(j)));
            }
            pendingSet.add(collabrum);
        }
        return pendingSet;
    } catch (Exception e) {
        throw new BaseDaoException(
                "Error occured while executing collabrum moderatorslist run query " + sqlQuery, e);
    }
}

From source file:dao.CarryonHitsBizAwareQuery.java

/**
 * This constructor is called when the Collabrum bean makes a 
 * call to query.execute(). After the query is executed, the result set is
 * returned. For each row in the result set, the mapRow method is called by
 * Spring. In the very first call to mapRow() for the first row in the result
 * set, we make a call to RSMD to get columnNames and cache
 * them to a local array in this object. This way, we can avoid multiple calls
 * to RSMD since, spring calls mapRow many times (one per row in result set).
 *
 *///from   ww  w.  ja v  a2 s.c  om
public List run(Connection conn, String bid) throws BaseDaoException {

    if (conn == null) {
        return null;
    }

    try {
        String query = "select c1.entryid, hdlogin.login, c1.btitle, c1.hits, bid from carryonhits c1, "
                + "hdlogin where hdlogin.bid=" + bid + " and c1.loginid=hdlogin.loginid order by hits DESC";

        PreparedStatement stmt = conn.prepareStatement(query);
        if (stmt == null) {
            return null;
        }
        //rs = stmt.executeQuery("select * from carryonhits order by hits DESC");
        ResultSet rs = stmt.executeQuery();
        Vector columnNames = null;
        Photo photo = null;
        List photoList = new ArrayList();

        if (rs != null) {
            columnNames = dbutils.getColumnNames(rs);
            while (rs.next()) {
                photo = (Photo) eop.newObject(DbConstants.PHOTO);
                for (int j = 0; j < columnNames.size(); j++) {
                    photo.setValue((String) columnNames.elementAt(j),
                            (String) rs.getString((String) columnNames.elementAt(j)));
                }
                photoList.add(photo);
            }
        }
        return photoList;
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing carryonhitsbizaware run query ", e);
    }
}

From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java

private void createDataConversionRulesList() {
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(labels.getString("dateConversion.valueRead"));
    columnNames.add(labels.getString("dateConversion.valueConverted"));
    dm = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);
    dm.addRow(new Vector<String>());
    dm.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            if (ruleTable.getEditingRow() != ruleTable.getRowCount() - 1
                    && (StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                            && StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)))) {
                dm.removeRow(ruleTable.getEditingRow());
            }/*from   w w w .j a va2s.c o m*/
            if (ruleTable.getEditingRow() == ruleTable.getRowCount() - 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                        && StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    dm.addRow(new Vector<String>());
                }
            }
            if (ruleTable.getEditingColumn() == 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))
                        && !isCorrectDateFormat((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    createOptionPaneForIsoDate(ruleTable.getEditingRow(), 1);
                }
            }
        }
    });

    ruleTable = new JTable(dm);
    oldModel = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);

    JButton saveButton = new JButton(labels.getString("saveBtn"));
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            for (int i = 0; i < data.size() - 1; i++) {
                Vector<String> vector = data.elementAt(i);
                if (vector.elementAt(1) != null && !isCorrectDateFormat((String) vector.elementAt(1))) {
                    createOptionPaneForIsoDate(i, 1);
                }
            }
            xmlFilehandler.saveDataToFile(data, FILENAME);
            saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                    new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
        }
    });

    JButton closeButton = new JButton(labels.getString("quit"));
    closeButton.addActionListener(new ActionListener() {
        // boolean cancel = true;

        public void actionPerformed(ActionEvent e) {
            /*System.out.println(Boolean.toString(oldModel.getRowCount() == (ruleTable.getModel().getRowCount() - 1)) + "<<" + oldModel.getRowCount() + ", " + (ruleTable.getModel().getRowCount() - 1));
            if (oldModel.getRowCount() != ruleTable.getModel().getRowCount() - 1) {
            cancel = showUnsavedChangesDialog();
            } else {
            for (int i = 0; i < (ruleTable.getModel().getRowCount() - 1); i++) {
                for (int j = 0; j <= 1; j++) {
                    System.out.println(oldModel.getValueAt(i, j) == ruleTable.getModel().getValueAt(i, j) + " >> " + oldModel.getValueAt(i, j) + ", " + ruleTable.getModel().getValueAt(i, j));
                    if (oldModel.getValueAt(i, j) != ruleTable.getModel().getValueAt(i, j)) {
                        cancel = showUnsavedChangesDialog();
                    }
                }
            }
            }
            if (cancel) {*/
            dispose();
            //  }
        }
    });

    JButton downloadButton = new JButton(labels.getString("downloadBtn"));
    downloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            File currentLocation = new File(retrieveFromDb.retrieveOpenLocation());
            JFileChooser fileChooser = new JFileChooser(currentLocation);
            fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
            fileChooser.setFileFilter(new FileNameExtensionFilter("XML file", "xml"));
            int returnedVal = fileChooser.showSaveDialog(getParent());

            if (returnedVal == JFileChooser.APPROVE_OPTION) {
                String fileName = fileChooser.getSelectedFile().toString();
                if (!fileName.endsWith(".xml")) {
                    fileName = fileName + ".xml";
                }
                xmlFilehandler.saveDataToFile(data, fileName);
                //additionally save data to standard file
                xmlFilehandler.saveDataToFile(data, FILENAME);
                saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                        new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
            }
        }
    });

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(new JScrollPane(ruleTable));
    saveMessage = new JLabel();
    contentPanel.add(saveMessage, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(saveButton);
    buttonPanel.add(closeButton);
    buttonPanel.add(downloadButton);

    JPanel pane = new JPanel(new BorderLayout());
    pane.add(contentPanel, BorderLayout.PAGE_START);
    pane.add(buttonPanel, BorderLayout.PAGE_END);
    add(pane);
}

From source file:dao.CarryonSearchQuery.java

/**
 * This method lists all the results for the search text from directories
 * @param conn the connection/*from  w w w .  ja  v a  2s. co  m*/
 * @param collabrumId the collabrumid
 * @return HashSet the set that has the list of moderators for these collabrums.
 * @throws BaseDaoException - when error occurs
 **/
public HashSet run(Connection conn, String sString) throws BaseDaoException {

    if ((RegexStrUtil.isNull(sString) || conn == null)) {
        return null;
    }

    StringBuffer sb = new StringBuffer(
            "select hdlogin.login, ownerid, entryid, carryontag.title as btitle, usertags, category, photos from hdlogin left join displayuser on hdlogin.loginid=displayuser.loginid left join carryontag on hdlogin.loginid=ownerid where category=1 and photos=1 and (");
    ArrayList columns = new ArrayList();
    columns.add("usertags");
    columns.add("carryontag.title");
    sb.append(sqlSearch.getConstraint(columns, sString));
    sb.append(")");

    logger.info("search query string" + sb.toString());

    try {
        PreparedStatement stmt = conn.prepareStatement(sb.toString());
        ResultSet rs = stmt.executeQuery();

        Vector columnNames = null;
        Photo photo = null;
        HashSet pendingSet = new HashSet();

        if (rs != null) {
            columnNames = dbutils.getColumnNames(rs);
        }

        while (rs.next()) {
            photo = (Photo) eop.newObject(DbConstants.PHOTO);
            for (int j = 0; j < columnNames.size(); j++) {
                photo.setValue((String) columnNames.elementAt(j),
                        (String) rs.getString((String) columnNames.elementAt(j)));
            }
            pendingSet.add(photo);
        }
        return pendingSet;
    } catch (Exception e) {
        throw new BaseDaoException("Error executing CarryonSearchQuery " + sb.toString(), e);
    }
}

From source file:dao.CarryonSearchBizAwareQuery.java

/**
 * This method lists all the results for the search text from carryontag
 * @param conn the connection/*from  w w w  .  j ava2s  . co m*/
 * @param sString - search string
 * @param bid - bid
 * @return HashSet - result
 * @throws BaseDaoException - when error occurs
 **/
public HashSet run(Connection conn, String sString, String bid) throws BaseDaoException {

    if (RegexStrUtil.isNull(sString) || conn == null || RegexStrUtil.isNull(bid)) {
        return null;
    }

    StringBuffer sb = new StringBuffer(
            "select hdlogin.login, ownerid, entryid, title, usertags, hdlogin.bid, business.bsearch from business, hdlogin left join carryontag on hdlogin.loginid=ownerid where business.bid=hdlogin.bid and (");
    ArrayList columns = new ArrayList();
    columns.add("usertags");
    columns.add("title");
    sb.append(sqlSearch.getConstraint(columns, sString));
    sb.append(")");

    logger.info("search query string = " + sb.toString());

    try {
        PreparedStatement stmt = conn.prepareStatement(sb.toString());
        ResultSet rs = stmt.executeQuery();

        Vector columnNames = null;
        Photo photo = null;
        HashSet pendingSet = new HashSet();

        if (rs != null) {
            columnNames = dbutils.getColumnNames(rs);
        }

        while (rs.next()) {
            photo = (Photo) eop.newObject(DbConstants.PHOTO);
            for (int j = 0; j < columnNames.size(); j++) {
                photo.setValue((String) columnNames.elementAt(j),
                        (String) rs.getString((String) columnNames.elementAt(j)));
            }
            pendingSet.add(photo);
        }
        return pendingSet;
    } catch (Exception e) {
        throw new BaseDaoException("Error executing CarryonSearchBizAwareQuery " + sb.toString(), e);
    }
}

From source file:dao.CollBlobSearchQuery.java

/**
 * This method lists all the results for the search text from directories
 * @param conn the connection//from   ww  w  .  java  2 s  .  com
 * @param collabrumId the collabrumid
 * @return HashSet the set that has the list of moderators for these collabrums.
 * @throws BaseDaoException - when error occurs
 **/
public HashSet run(Connection conn, String sString) throws BaseDaoException {

    if ((RegexStrUtil.isNull(sString) || conn == null)) {
        return null;
    }

    StringBuffer sb = new StringBuffer(
            "select blobtype, entrydate, collblob.collabrumid, collblob.entryid, btitle from collblob left join collblobtags on collblob.entryid=collblobtags.entryid where ");
    ArrayList columns = new ArrayList();
    columns.add("usertags");
    sb.append(sqlSearch.getConstraint(columns, sString));
    try {
        PreparedStatement stmt = conn.prepareStatement(sb.toString());
        ResultSet rs = stmt.executeQuery();
        Vector columnNames = null;
        Photo photo = null;
        HashSet pendingSet = new HashSet();

        if (rs != null) {
            columnNames = dbutils.getColumnNames(rs);
        }

        while (rs.next()) {
            photo = (Photo) eop.newObject(DbConstants.PHOTO);
            for (int j = 0; j < columnNames.size(); j++) {
                if (((String) (columnNames.elementAt(j))).equalsIgnoreCase(DbConstants.ENTRY_DATE)) {
                    try {
                        photo.setValue(DbConstants.ENTRY_DATE,
                                GlobalConst.dncalendar.getDisplayDate(rs.getTimestamp(DbConstants.ENTRY_DATE)));
                    } catch (ParseException e) {
                        throw new BaseDaoException("could not parse the date for entrydate in collabrum"
                                + rs.getTimestamp(DbConstants.ENTRY_DATE), e);
                    }
                } else {
                    photo.setValue((String) columnNames.elementAt(j),
                            (String) rs.getString((String) columnNames.elementAt(j)));
                }
            }
            pendingSet.add(photo);
        }
        return pendingSet;
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing collblobsearch run query " + sb.toString(),
                e);
    }
}

From source file:com.globalsight.everest.webapp.applet.admin.customer.FileSystemApplet.java

/**
 * Zip the selected files and send the zip to the server.
 * @param p_filesToBeZipped - A list of selected files to be uploaded.
 * @param p_targetURL - The target URL representing server URL.
 * @param p_targetLocation - A string representing the link to the next page.
 *//*  ww  w. j  av  a2 s  .  co m*/
public void sendZipFile(File[] p_filesToBeZipped, String p_targetURL, final String p_targetLocation)
        throws Exception {
    StringBuffer sb = new StringBuffer();
    sb.append("GS_");
    sb.append(System.currentTimeMillis());
    sb.append(".zip");

    File targetFile = getFile(sb.toString());
    ZipIt.addEntriesToZipFile(targetFile, p_filesToBeZipped);
    m_progressBar.setValue(30);

    PostMethod filePost = new PostMethod(p_targetURL + "&doPost=true");
    filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
    filePost.setDoAuthentication(true);
    try {
        Part[] parts = { new FilePart(targetFile.getName(), targetFile) };

        m_progressBar.setValue(40);
        filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

        HttpClient client = new HttpClient();
        setUpClientForProxy(client);
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

        m_progressBar.setValue(50);
        int status = client.executeMethod(filePost);
        if (status == HttpStatus.SC_OK) {
            //no need to ask for auth again since the first upload was fine
            s_authPrompter.setAskForAuthentication(false);

            m_progressBar.setValue(60);
            InputStream is = filePost.getResponseBodyAsStream();
            m_progressBar.setValue(70);
            ObjectInputStream inputStreamFromServlet = new ObjectInputStream(is);
            Vector incomingData = (Vector) inputStreamFromServlet.readObject();

            inputStreamFromServlet.close();
            if (incomingData != null) {
                if (incomingData.elementAt(0) instanceof ExceptionMessage) {
                    resetProgressBar();
                    AppletHelper.displayErrorPage((ExceptionMessage) incomingData.elementAt(0), this);
                }
            } else {
                boolean deleted = targetFile.delete();
                m_progressBar.setValue(100);
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                }
                // now move to some other page...
                goToTargetPage(p_targetLocation);
            }
        } else {
            //authentication may have failed, reset the need to ask
            s_authPrompter.setAskForAuthentication(true);
            resetProgressBar();
            String errorMessage = "Upload failed because: (" + status + ") " + HttpStatus.getStatusText(status);
            if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
                errorMessage = "Incorrect NTDomain\\username or password entered. Hit 'upload' again to re-try.";
            }
            AppletHelper.getErrorDlg(errorMessage, null);
        }
    } catch (Exception ex) {
        //authentication may have failed, reset the need to ask
        s_authPrompter.setAskForAuthentication(true);

        resetProgressBar();
        System.err.println(ex);
        AppletHelper.getErrorDlg(ex.getMessage(), null);
    } finally {
        filePost.releaseConnection();
    }

}

From source file:dao.DirBlobSearchQuery.java

/**
 * This method lists all the results for the search text from directories
 * @param conn the connection//  w w  w .  j a v  a  2 s. c o m
 * @param collabrumId the collabrumid
 * @return HashSet the set that has the list of moderators for these collabrums.
 * @throws BaseDaoException - when error occurs
 **/
public HashSet run(Connection conn, String sString) throws BaseDaoException {

    if ((RegexStrUtil.isNull(sString) || conn == null)) {
        return null;
    }

    /*        StringBuffer sb = new StringBuffer("select blobtype, dirblob.directoryid, entrydate, dirblob.entryid, btitle from dirblob left join dirblobtags on dirblob.entryid=dirblobtags.entryid where ");
    */
    StringBuffer sb = new StringBuffer(
            "select distinct d1.btitle, d1.mimetype, d1.entryid, d1.directoryid from dirblob d1, dirblobtags d2 where ");
    ArrayList columns = new ArrayList();
    columns.add("d1.btitle");
    columns.add("d2.usertags");
    sb.append(sqlSearch.getConstraint(columns, sString));
    sb.append(" and d1.entryid=d2.entryid and d1.directoryid=d2.directoryid");
    try {
        PreparedStatement stmt = conn.prepareStatement(sb.toString());
        ResultSet rs = stmt.executeQuery();

        Vector columnNames = null;
        Photo photo = null;
        HashSet pendingSet = new HashSet();

        if (rs != null) {
            columnNames = dbutils.getColumnNames(rs);
        }

        while (rs.next()) {
            photo = (Photo) eop.newObject(DbConstants.PHOTO);
            for (int j = 0; j < columnNames.size(); j++) {
                if (((String) (columnNames.elementAt(j))).equalsIgnoreCase(DbConstants.ENTRY_DATE)) {
                    try {
                        photo.setValue(DbConstants.ENTRY_DATE,
                                GlobalConst.dncalendar.getDisplayDate(rs.getTimestamp(DbConstants.ENTRY_DATE)));
                    } catch (ParseException e) {
                        throw new BaseDaoException("could not parse the date for entrydate in dirblob "
                                + rs.getTimestamp(DbConstants.ENTRY_DATE), e);
                    }
                } else {
                    photo.setValue((String) columnNames.elementAt(j),
                            (String) rs.getString((String) columnNames.elementAt(j)));
                }
            }
            pendingSet.add(photo);
        }
        return pendingSet;
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing search dirblob run query " + sb.toString(),
                e);
    }
}

From source file:org.campware.cream.modules.util.XmlRpcHandler.java

/**
 * The client has indicated that it would like
 * to insert new customer.//ww  w.  jav  a 2  s  . com
 */
public int insertCustomer(Vector params) {
    Customer entry = new Customer();
    entry.setCustomerDisplay((String) params.elementAt(0));
    entry.setCustomerName1((String) params.elementAt(0));
    entry.setCustomerName2((String) params.elementAt(1));
    entry.setAddress1((String) params.elementAt(2));
    entry.setAddress2((String) params.elementAt(3));
    entry.setCity((String) params.elementAt(4));
    entry.setZip((String) params.elementAt(5));
    entry.setState((String) params.elementAt(6));

    try {
        entry.setCountryId(((Integer) params.elementAt(7)).intValue());
    } catch (Exception e) {
        return -1;
    }
    entry.setPhone1((String) params.elementAt(8));
    entry.setPhone2((String) params.elementAt(9));
    entry.setFax((String) params.elementAt(10));
    entry.setEmail((String) params.elementAt(11));
    entry.setLoginName((String) params.elementAt(12));
    entry.setPasswordValue((String) params.elementAt(13));

    entry.setCreatedBy("web");
    entry.setCreated(new Date());
    entry.setModifiedBy("web");
    entry.setModified(new Date());

    entry.setCustomerCode(getTempCode());

    boolean success = false;

    try {
        Connection conn = Transaction.begin(CustomerPeer.DATABASE_NAME);

        try {
            entry.save(conn);
            entry.setCustomerCode(getRowCode("CU", entry.getCustomerId()));
            entry.save(conn);
            Transaction.commit(conn);
            success = true;
            return 1;
        } finally {
            if (!success)
                Transaction.safeRollback(conn);
        }

    } catch (Exception e) {
        return -1;
    }

}