Example usage for java.util Vector addElement

List of usage examples for java.util Vector addElement

Introduction

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

Prototype

public synchronized void addElement(E obj) 

Source Link

Document

Adds the specified component to the end of this vector, increasing its size by one.

Usage

From source file:com.github.dactiv.common.bundle.BeanResourceBundle.java

/**
 * ?bean?mapkey//  www  .  ja  v a2 s  . c o  m
 */
@Override
public Enumeration<String> getKeys() {

    Vector<String> vector = new Vector<String>();
    PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(bean.getClass());
    //???bean
    for (PropertyDescriptor pd : propertyDescriptors) {
        //get/set???
        if ((pd.getWriteMethod() == null) || pd.getReadMethod() == null) {
            continue;
        }

        String key = pd.getName();

        /*
         * ?map?:
         * 1.include
         * 2.?exclude
         * 3.ignoreNullValuetrue,?null
         */
        if (isIncludeProperty(key) && !isExcludeProperty(key)) {

            if (ignoreNullValue && ReflectionUtils.invokeGetterMethod(bean, key) == null) {
                continue;
            }

            vector.addElement(key);
        }
    }

    //?mapkey
    return vector.elements();
}

From source file:fsi_admin.JSmtpConn.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String ERROR = null, codErr = null;

    try {/*from  w  ww . ja v a 2s.  c om*/
        Properties parametros = new Properties();
        Vector archivos = new Vector();
        DiskFileUpload fu = new DiskFileUpload();
        List items = fu.parseRequest(request);
        Iterator iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (item.isFormField())
                parametros.put(item.getFieldName(), item.getString());
            else
                archivos.addElement(item);
        }

        if (parametros.getProperty("SERVER") == null || parametros.getProperty("DATABASE") == null
                || parametros.getProperty("USER") == null || parametros.getProperty("PASSWORD") == null
                || parametros.getProperty("BODY") == null || parametros.getProperty("MIMETYPE") == null
                || parametros.getProperty("SUBJECT") == null || parametros.getProperty("EMAIL") == null
                || parametros.getProperty("SOURCEMAIL") == null) {
            System.out.println("No recibi parametros de conexin antes del correo a enviar");
            ERROR = "ERROR: El servidor no recibi todos los parametros de conexion (SERVER,DATABASE,USER,PASSWORD) antes del correo a enviar";
            codErr = "3";
            ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                    parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                    parametros.getProperty("PASSWORD"), request, ERROR, 3);
        }

        //Hasta aqui se han enviado todos los parametros ninguno nulo
        if (ERROR == null) {
            StringBuffer msj = new StringBuffer(), SMTPHOST = new StringBuffer(), SMTPPORT = new StringBuffer(),
                    SMTPUSR = new StringBuffer(), SMTPPASS = new StringBuffer();
            MutableBoolean COBRAR = new MutableBoolean(false);
            MutableDouble COSTO = new MutableDouble(0.0), SALDO = new MutableDouble(0.0);
            // Primero obtiene info del SMTP
            if (!obtenInfoSMTP(request.getRemoteAddr(), request.getRemoteHost(),
                    parametros.getProperty("SERVER"), parametros.getProperty("DATABASE"),
                    parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), SMTPHOST, SMTPPORT,
                    SMTPUSR, SMTPPASS, msj, COSTO, SALDO, COBRAR)) {
                System.out.println("El usuario y contrasea de servicio estan mal");
                ERROR = msj.toString();
                codErr = "2";
                ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                        parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                        parametros.getProperty("PASSWORD"), request, ERROR, 2);

            } else {
                if (COBRAR.booleanValue() && SALDO.doubleValue() < COSTO.doubleValue()) {
                    System.out.println("El servicio tiene un costo que no alcanza en el saldo");
                    ERROR = "El servicio SMTP tiene un costo que no alcanza en el saldo";
                    codErr = "2";
                    ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                            parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                            parametros.getProperty("PASSWORD"), request, ERROR, 2);

                } else {
                    Properties props;

                    props = System.getProperties();
                    props.put("mail.transport.protocol", "smtp");
                    props.put("mail.smtp.port", Integer.parseInt(SMTPPORT.toString()));

                    // Set properties indicating that we want to use STARTTLS to encrypt the connection.
                    // The SMTP session will begin on an unencrypted connection, and then the client
                    // will issue a STARTTLS command to upgrade to an encrypted connection.
                    props.put("mail.smtp.auth", "true");
                    props.put("mail.smtp.starttls.enable", "true");
                    props.put("mail.smtp.starttls.required", "true");

                    // Create a Session object to represent a mail session with the specified properties. 
                    Session session = Session.getDefaultInstance(props);
                    MimeMessage mmsg = new MimeMessage(session);
                    BodyPart messagebodypart = new MimeBodyPart();
                    MimeMultipart multipart = new MimeMultipart();

                    if (!prepareMsg(parametros.getProperty("SOURCEMAIL"), parametros.getProperty("EMAIL"),
                            parametros.getProperty("SUBJECT"), parametros.getProperty("MIMETYPE"),
                            parametros.getProperty("BODY"), msj, props, session, mmsg, messagebodypart,
                            multipart)) {
                        System.out.println("No se permiti preparar el mensaje");
                        ERROR = msj.toString();
                        codErr = "3";
                        ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                parametros.getProperty("PASSWORD"), request, ERROR, 3);

                    } else {
                        if (!adjuntarArchivo(msj, messagebodypart, multipart, archivos)) {
                            System.out.println("No se permiti adjuntar archivos al mensaje");
                            ERROR = msj.toString();
                            codErr = "3";
                            ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                    parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                    parametros.getProperty("PASSWORD"), request, ERROR, 3);

                        } else {
                            if (!sendMsg(SMTPHOST.toString(), SMTPUSR.toString(), SMTPPASS.toString(), msj,
                                    session, mmsg, multipart)) {
                                System.out.println("No se permiti enviar el mensaje");
                                ERROR = msj.toString();
                                codErr = "3";
                                ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(),
                                        parametros.getProperty("SERVER"), parametros.getProperty("USER"),
                                        parametros.getProperty("PASSWORD"), request, ERROR, 3);
                            } else {
                                ingresarRegistroExitoso(parametros.getProperty("SERVER"),
                                        parametros.getProperty("DATABASE"), parametros.getProperty("SUBJECT"),
                                        COSTO, SALDO, COBRAR);

                                //Devuelve la respuesta al cliente
                                Element Correo = new Element("Correo");
                                Correo.setAttribute("Subject", parametros.getProperty("SUBJECT"));
                                Correo.setAttribute("MsjError", "");
                                Document Reporte = new Document(Correo);

                                Format format = Format.getPrettyFormat();
                                format.setEncoding("utf-8");
                                format.setTextMode(TextMode.NORMALIZE);
                                XMLOutputter xmlOutputter = new XMLOutputter(format);
                                ByteArrayOutputStream out = new ByteArrayOutputStream();
                                xmlOutputter.output(Reporte, out);

                                byte[] data = out.toByteArray();
                                ByteArrayInputStream istream = new ByteArrayInputStream(data);

                                String destino = "Correo.xml";
                                JBajarArchivo fd = new JBajarArchivo();
                                fd.doDownload(response, getServletConfig().getServletContext(), istream,
                                        "text/xml", data.length, destino);

                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        ERROR = "ERROR DE EXCEPCION EN SERVIDOR PAC: " + e.getMessage();
    }

    //Genera el archivo XML de error para ser devuelto al Servidor
    if (ERROR != null) {
        Element SIGN_ERROR = new Element("SIGN_ERROR");
        SIGN_ERROR.setAttribute("CodError", codErr);
        SIGN_ERROR.setAttribute("MsjError", ERROR);
        Document Reporte = new Document(SIGN_ERROR);

        Format format = Format.getPrettyFormat();
        format.setEncoding("utf-8");
        format.setTextMode(TextMode.NORMALIZE);
        XMLOutputter xmlOutputter = new XMLOutputter(format);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        xmlOutputter.output(Reporte, out);

        byte[] data = out.toByteArray();
        ByteArrayInputStream istream = new ByteArrayInputStream(data);

        String destino = "SIGN_ERROR.xml";
        JBajarArchivo fd = new JBajarArchivo();
        fd.doDownload(response, getServletConfig().getServletContext(), istream, "text/xml", data.length,
                destino);

    }
}

From source file:EditorPaneExample10A.java

public URL[] findLinks(Document doc, String protocol) {
    Vector links = new Vector();
    Vector urlNames = new Vector();
    URL baseURL = (URL) doc.getProperty(Document.StreamDescriptionProperty);

    if (doc instanceof HTMLDocument) {
        HTMLDocument.Iterator iterator = ((HTMLDocument) doc).getIterator(HTML.Tag.A);
        for (; iterator.isValid(); iterator.next()) {
            AttributeSet attrs = iterator.getAttributes();
            Object linkAttr = attrs.getAttribute(HTML.Attribute.HREF);
            if (linkAttr instanceof String) {
                try {
                    URL linkURL = new URL(baseURL, (String) linkAttr);
                    if (protocol == null || protocol.equalsIgnoreCase(linkURL.getProtocol())) {
                        String linkURLName = linkURL.toString();
                        if (urlNames.contains(linkURLName) == false) {
                            urlNames.addElement(linkURLName);
                            links.addElement(linkURL);
                        }/*from w  w w . j  a v  a2  s .c  om*/
                    }
                } catch (MalformedURLException e) {
                    // Ignore invalid links
                }
            }
        }
    }

    URL[] urls = new URL[links.size()];
    links.copyInto(urls);
    links.removeAllElements();
    urlNames.removeAllElements();

    return urls;
}

From source file:com.commander4j.db.JDBUserReport.java

public Vector<JDBUserReport> getUserReportData(PreparedStatement criteria) {

    ResultSet rs;/*from www .java2s.c  o  m*/
    Vector<JDBUserReport> result = new Vector<JDBUserReport>();

    if (Common.hostList.getHost(getHostID()).toString().equals(null)) {
        result.addElement(new JDBUserReport("Report ID", "Description", "Destination", "Enabled"));
    } else {
        try {
            rs = criteria.executeQuery();

            while (rs.next()) {
                result.addElement(new JDBUserReport(rs.getString("USER_REPORT_ID"), rs.getString("DESCRIPTION"),
                        rs.getString("DESTINATION"), rs.getString("ENABLED")));
            }
            rs.close();

        } catch (Exception e) {
            setErrorMessage(e.getMessage());
        }
    }

    return result;
}

From source file:org.apache.tomcat.util.net.jsse.JSSESocketFactory.java

protected String[] getEnabledCiphers(String requestedCiphers, String[] supportedCiphers) {

    String[] enabledCiphers = null;

    if (requestedCiphers != null) {
        Vector vec = null;
        String cipher = requestedCiphers;
        int index = requestedCiphers.indexOf(',');
        if (index != -1) {
            int fromIndex = 0;
            while (index != -1) {
                cipher = requestedCiphers.substring(fromIndex, index).trim();
                if (cipher.length() > 0) {
                    /*// w  w w.jav  a 2  s .co  m
                     * Check to see if the requested cipher is among the
                     * supported ciphers, i.e., may be enabled
                     */
                    for (int i = 0; supportedCiphers != null && i < supportedCiphers.length; i++) {
                        if (supportedCiphers[i].equals(cipher)) {
                            if (vec == null) {
                                vec = new Vector();
                            }
                            vec.addElement(cipher);
                            break;
                        }
                    }
                }
                fromIndex = index + 1;
                index = requestedCiphers.indexOf(',', fromIndex);
            } // while
            cipher = requestedCiphers.substring(fromIndex);
        }

        if (cipher != null) {
            cipher = cipher.trim();
            if (cipher.length() > 0) {
                /*
                 * Check to see if the requested cipher is among the
                 * supported ciphers, i.e., may be enabled
                 */
                for (int i = 0; supportedCiphers != null && i < supportedCiphers.length; i++) {
                    if (supportedCiphers[i].equals(cipher)) {
                        if (vec == null) {
                            vec = new Vector();
                        }
                        vec.addElement(cipher);
                        break;
                    }
                }
            }
        }

        if (vec != null) {
            enabledCiphers = new String[vec.size()];
            vec.copyInto(enabledCiphers);
        }
    }

    return enabledCiphers;
}

From source file:net.anidb.udp.UdpFileFactory.java

/**
 * Returns the related episodes from the given data field.
 * @param dataField The data field.//from   www  .j  av a  2 s  .co m
 * @returnThe related episodes or <code>null</code>, of the given data field
 * is empty.
 * @throws DataFieldException If the data fields contains not the required
 * data.
 */
private List<RelatedEpisode> getRelatedEpisodes(final DataField dataField) throws DataFieldException {

    String value;
    Vector<RelatedEpisode> relatedEpisodes;
    int count;
    DataField subDataField;

    value = dataField.getValue();
    if ((value == null) || (value.length() == 0)) {
        return null;
    }
    relatedEpisodes = new Vector<RelatedEpisode>();
    count = dataField.getDataFieldCount();
    if (count > 0) {
        for (int index = 0; index < count; index++) {
            subDataField = dataField.getDataFieldAt(index);
            relatedEpisodes.addElement(this.getRelatedEpisode(subDataField));
        }
    } else {
        relatedEpisodes.addElement(this.getRelatedEpisode(dataField));
    }
    return relatedEpisodes;
}

From source file:net.anidb.udp.UdpFileFactory.java

/**
 * <p>Returns the files from the response.</p>
 * <p>For each file the method/* w ww. j ava 2s .  co  m*/
 * {@link #getFile(long, FileMask, AnimeFileMask)} will be called.</p>
 * @param response The response.
 * @param fileMask The file mask.
 * @param animeFileMask The anime file mask.
 * @return The files.
 * @throws UdpConnectionException If a connection problem occured.
 * @throws AniDbException If a problem with AniDB occured.
 * @see UdpReturnCodes#NO_SUCH_FILE
 */
private List<File> getFiles(final UdpResponse response, final FileMask fileMask,
        final AnimeFileMask animeFileMask) throws UdpConnectionException, AniDbException {

    UdpResponseEntry entry;
    long fileId;
    Vector<File> files;

    entry = response.getEntryAt(0);
    files = new Vector<File>();
    for (int index = 0; index < entry.getDataFieldCount(); index++) {
        try {
            fileId = entry.getDataFieldAt(index).getValueAsLongValue();
        } catch (DataFieldException dfe) {
            throw new UdpConnectionException(
                    "Received invalid response to the command FILE: " + response.toString(), dfe);
        }
        files.addElement(this.getFile(fileId, fileMask, animeFileMask));
    }
    return files;
}

From source file:org.apache.roller.weblogger.webservices.xmlrpc.MetaWeblogAPIHandler.java

/**
 * Get a list of recent posts for a category
 *
 * @param blogid Unique identifier of the blog the post will be added to
 * @param userid Login for a Blogger user who has permission to post to the blog
 * @param password Password for said username
 * @param numposts Number of Posts to Retrieve
 * @throws XmlRpcException/*from  www. ja v  a 2  s.  c om*/
 * @return
 */
public Object getRecentPosts(String blogid, String userid, String password, int numposts) throws Exception {

    mLogger.debug("getRecentPosts() Called ===========[ SUPPORTED ]=====");
    mLogger.debug("     BlogId: " + blogid);
    mLogger.debug("     UserId: " + userid);
    mLogger.debug("     Number: " + numposts);

    Weblog website = validate(blogid, userid, password);

    try {
        Vector results = new Vector();

        Weblogger roller = WebloggerFactory.getWeblogger();
        WeblogEntryManager weblogMgr = roller.getWeblogEntryManager();
        if (website != null) {
            List entries = weblogMgr.getWeblogEntries(website, // website
                    null, null, // startDate
                    null, // endDate
                    null, // catName
                    null, // tags
                    null, // status
                    null, // text
                    "updateTime", // sortby
                    null, null, 0, numposts);

            Iterator iter = entries.iterator();
            while (iter.hasNext()) {
                WeblogEntry entry = (WeblogEntry) iter.next();
                results.addElement(createPostStruct(entry, userid));
            }
        }
        return results;

    } catch (Exception e) {
        String msg = "ERROR in MetaWeblogAPIHandler.getRecentPosts";
        mLogger.error(msg, e);
        throw new XmlRpcException(UNKNOWN_EXCEPTION, msg);
    }
}

From source file:org.apache.slide.store.ExtendedStore.java

public void putLock(Uri uri, NodeLock lock) throws ServiceAccessException {
    super.putLock(uri, lock);
    if (lockStore.cacheResults()) {
        enlist(this);
        try {/*w w w .j  a  va2s  .c o m*/
            Vector locks = fillLocksCache(uri);
            // operate on a copy
            Vector tempLocks = (Vector) locks.clone();
            tempLocks.addElement(lock.cloneObject());
            locksCache.put(uri.toString(), tempLocks);
        } finally {
            delist(this);
        }
    }
}

From source file:org.apache.slide.store.ExtendedStore.java

public void grantPermission(Uri uri, NodePermission permission) throws ServiceAccessException {
    super.grantPermission(uri, permission);
    if (securityStore.cacheResults()) {
        enlist(this);
        try {/*from w w w .  ja v a  2 s .  c om*/
            Vector permissionsVector = fillPermissionsCache(uri);
            // operate on a copy
            Vector tempPermissions = (Vector) permissionsVector.clone();
            tempPermissions.addElement(permission);
            permissionsCache.put(uri.toString(), tempPermissions);
        } finally {
            delist(this);
        }
    }
}