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:edu.umd.cfar.lamp.viper.util.StringHelp.java

/**
 * Divides a String by its whitespace.//ww  w  .ja  va2s  .c  o m
 *
 * @param line The String to divide.
 * @return An Array of Strings taken from between the whitespace characters.
 */
public static String[] splitSpaces(String line) {
    if (line == null)
        return (new String[0]);

    int start, end;

    Vector vec = new Vector();

    end = 0;
    while (true) {
        start = findNonBlank(line, end);
        if (start == -1)
            break;
        end = findBlank(line, start);
        if (end == -1) {
            vec.addElement(line.substring(start));
            break;
        } else {
            vec.addElement(line.substring(start, end));
        }
    }

    String[] result = new String[vec.size()];
    for (int j = 0; j < vec.size(); j++) {
        result[j] = (String) vec.elementAt(j);
    }

    return (result);
}

From source file:org.apache.xmlrpc.applet.SimpleXmlRpcClient.java

/**
 * Writes the XML representation of a supported Java object to the XML writer.
 *//*ww w. j  a  v  a  2  s .  c o m*/
void writeObject(Object what, XmlWriter writer) throws IOException {
    writer.startElement("value");
    if (what instanceof String) {
        writer.write(what.toString());
    } else if (what instanceof Integer) {
        writer.startElement("int");
        writer.write(what.toString());
        writer.endElement("int");
    } else if (what instanceof Boolean) {
        writer.startElement("boolean");
        writer.write(((Boolean) what).booleanValue() ? "1" : "0");
        writer.endElement("boolean");
    } else if (what instanceof Double) {
        writer.startElement("double");
        writer.write(what.toString());
        writer.endElement("double");
    } else if (what instanceof Date) {
        writer.startElement("dateTime.iso8601");
        Date d = (Date) what;
        writer.write(format.format(d));
        writer.endElement("dateTime.iso8601");
    } else if (what instanceof byte[]) {
        writer.startElement("base64");
        try {
            writer.write((byte[]) base64.encode(what));
        } catch (EncoderException e) {
            throw new RuntimeException(
                    "Possibly incompatible version " + "of '" + Base64.class.getName() + "' used: " + e);
        }
        writer.endElement("base64");
    } else if (what instanceof Vector) {
        writer.startElement("array");
        writer.startElement("data");
        Vector v = (Vector) what;
        int l2 = v.size();
        for (int i2 = 0; i2 < l2; i2++) {
            writeObject(v.elementAt(i2), writer);
        }
        writer.endElement("data");
        writer.endElement("array");
    } else if (what instanceof Hashtable) {
        writer.startElement("struct");
        Hashtable h = (Hashtable) what;
        for (Enumeration e = h.keys(); e.hasMoreElements();) {
            String nextkey = (String) e.nextElement();
            Object nextval = h.get(nextkey);
            writer.startElement("member");
            writer.startElement("name");
            writer.write(nextkey);
            writer.endElement("name");
            writeObject(nextval, writer);
            writer.endElement("member");
        }
        writer.endElement("struct");
    } else {
        String unsupportedType = what == null ? "null" : what.getClass().toString();
        throw new IOException("unsupported Java type: " + unsupportedType);
    }
    writer.endElement("value");
}

From source file:com.madrobot.net.client.XMLRPCClient.java

/**
 * Convenience method call with a vectorized parameter (Code contributed by jahbromo from issue #14)
 * // w w  w .  j  a  va 2s.  c  o  m
 * @param method
 *            name of method to call
 * @param paramsv
 *            vector of method's parameter
 * @return deserialized method return value
 * @throws XMLRPCException
 */

public Object call(String method, Vector paramsv) throws XMLRPCException {
    Object[] params = new Object[paramsv.size()];
    for (int i = 0; i < paramsv.size(); i++) {
        params[i] = paramsv.elementAt(i);
    }
    return callEx(method, params);
}

From source file:org.jboss.dashboard.commons.text.StringUtil.java

/**
 * Return a String who contains the strings in the Vector <I>vector</I>
 * separated by <I>delimiter</I>.
 *
 * @param vector    list of tokens/*from w  ww.  j  a v a2  s .  c  om*/
 * @param delimiter String who delimiters the Strings into <I>str</I>
 * @return Composed string
 */
public static String getStringFromTokens(Vector vector, String delimiter) {
    int nelem = vector.size();
    // Initial capacity, at least include the delimiters
    StringBuffer str_ret = new StringBuffer(nelem * delimiter.length());

    for (int i = 0; i < nelem; i++) {
        str_ret.append(vector.elementAt(i));

        // The last delimiter isn't added
        if (i < nelem - 1) {
            str_ret.append(delimiter);
        }
    }
    return str_ret.toString();
}

From source file:com.netscape.cmstools.client.ClientCertRequestCLI.java

public void execute(String[] args) throws Exception {
    CommandLine cmd = parser.parse(options, args);

    String[] cmdArgs = cmd.getArgs();

    if (cmd.hasOption("help")) {
        printHelp();/*from  w  w  w . j  a  v  a2 s.  c  o  m*/
        return;
    }

    if (cmdArgs.length > 1) {
        throw new Exception("Too many arguments specified.");
    }

    String certRequestUsername = cmd.getOptionValue("username");

    String subjectDN;

    if (cmdArgs.length == 0) {
        if (certRequestUsername == null) {
            throw new Exception("Missing subject DN or request username.");
        }

        subjectDN = "UID=" + certRequestUsername;

    } else {
        subjectDN = cmdArgs[0];
    }

    // pkcs10, crmf
    String requestType = cmd.getOptionValue("type", "pkcs10");

    boolean attributeEncoding = cmd.hasOption("attribute-encoding");

    // rsa, ec
    String algorithm = cmd.getOptionValue("algorithm", "rsa");
    int length = Integer.parseInt(cmd.getOptionValue("length", "1024"));

    String curve = cmd.getOptionValue("curve", "nistp256");
    boolean sslECDH = cmd.hasOption("ssl-ecdh");
    boolean temporary = !cmd.hasOption("permanent");

    String s = cmd.getOptionValue("sensitive");
    int sensitive;
    if (s == null) {
        sensitive = -1;
    } else {
        if (!s.equalsIgnoreCase("true") && !s.equalsIgnoreCase("false")) {
            throw new IllegalArgumentException("Invalid sensitive parameter: " + s);
        }
        sensitive = Boolean.parseBoolean(s) ? 1 : 0;
    }

    s = cmd.getOptionValue("extractable");
    int extractable;
    if (s == null) {
        extractable = -1;
    } else {
        if (!s.equalsIgnoreCase("true") && !s.equalsIgnoreCase("false")) {
            throw new IllegalArgumentException("Invalid extractable parameter: " + s);
        }
        extractable = Boolean.parseBoolean(s) ? 1 : 0;
    }

    String transportCertFilename = cmd.getOptionValue("transport");

    String profileID = cmd.getOptionValue("profile");
    if (profileID == null) {
        if (algorithm.equals("rsa")) {
            profileID = "caUserCert";
        } else if (algorithm.equals("ec")) {
            profileID = "caECUserCert";
        }
    }

    boolean withPop = !cmd.hasOption("without-pop");

    AuthorityID aid = null;
    if (cmd.hasOption("issuer-id")) {
        String aidString = cmd.getOptionValue("issuer-id");
        try {
            aid = new AuthorityID(aidString);
        } catch (IllegalArgumentException e) {
            throw new Exception("Invalid issuer ID: " + aidString, e);
        }
    }

    X500Name adn = null;
    if (cmd.hasOption("issuer-dn")) {
        String adnString = cmd.getOptionValue("issuer-dn");
        try {
            adn = new X500Name(adnString);
        } catch (IOException e) {
            throw new Exception("Invalid issuer DN: " + adnString, e);
        }
    }

    if (aid != null && adn != null) {
        throw new Exception("--issuer-id and --issuer-dn options are mutually exclusive");
    }

    MainCLI mainCLI = (MainCLI) parent.getParent();
    File certDatabase = mainCLI.certDatabase;

    String password = mainCLI.config.getNSSPassword();
    if (password == null) {
        throw new Exception("Missing security database password.");
    }

    String csr;
    PKIClient client;
    if ("pkcs10".equals(requestType)) {
        if ("rsa".equals(algorithm)) {
            csr = generatePkcs10Request(certDatabase, password, algorithm, Integer.toString(length), subjectDN);
        }

        else if ("ec".equals(algorithm)) {
            csr = generatePkcs10Request(certDatabase, password, algorithm, curve, subjectDN);
        } else {
            throw new Exception("Error: Unknown algorithm: " + algorithm);
        }

        // initialize database after PKCS10Client to avoid conflict
        mainCLI.init();
        client = getClient();

    } else if ("crmf".equals(requestType)) {

        // initialize database before CRMFPopClient to load transport certificate
        mainCLI.init();
        client = getClient();

        String encoded;
        if (transportCertFilename == null) {
            SystemCertClient certClient = new SystemCertClient(client, "ca");
            encoded = certClient.getTransportCert().getEncoded();

        } else {
            encoded = new String(Files.readAllBytes(Paths.get(transportCertFilename)));
        }

        byte[] transportCertData = Cert.parseCertificate(encoded);

        CryptoManager manager = CryptoManager.getInstance();
        X509Certificate transportCert = manager.importCACertPackage(transportCertData);

        // get archival and key wrap mechanisms from CA
        String kwAlg = CRMFPopClient.getKeyWrapAlgotihm(client);
        KeyWrapAlgorithm keyWrapAlgorithm = KeyWrapAlgorithm.fromString(kwAlg);

        csr = generateCrmfRequest(transportCert, subjectDN, attributeEncoding, algorithm, length, curve,
                sslECDH, temporary, sensitive, extractable, withPop, keyWrapAlgorithm);

    } else {
        throw new Exception("Unknown request type: " + requestType);
    }

    if (verbose) {
        System.out.println("CSR:");
        System.out.println(csr);
    }

    CAClient caClient = new CAClient(client);
    CACertClient certClient = new CACertClient(caClient);

    if (verbose) {
        System.out.println("Retrieving " + profileID + " profile.");
    }

    CertEnrollmentRequest request = certClient.getEnrollmentTemplate(profileID);

    // Key Generation / Dual Key Generation
    for (ProfileInput input : request.getInputs()) {

        ProfileAttribute typeAttr = input.getAttribute("cert_request_type");
        if (typeAttr != null) {
            typeAttr.setValue(requestType);
        }

        ProfileAttribute csrAttr = input.getAttribute("cert_request");
        if (csrAttr != null) {
            csrAttr.setValue(csr);
        }
    }

    // parse subject DN and put the values in a map
    DN dn = new DN(subjectDN);
    Vector<?> rdns = dn.getRDNs();

    Map<String, String> subjectAttributes = new HashMap<String, String>();
    for (int i = 0; i < rdns.size(); i++) {
        RDN rdn = (RDN) rdns.elementAt(i);
        String type = rdn.getTypes()[0].toLowerCase();
        String value = rdn.getValues()[0];
        subjectAttributes.put(type, value);
    }

    ProfileInput sn = request.getInput("Subject Name");
    if (sn != null) {
        if (verbose)
            System.out.println("Subject Name:");

        for (ProfileAttribute attribute : sn.getAttributes()) {
            String name = attribute.getName();
            String value = null;

            if (name.equals("subject")) {
                // get the whole subject DN
                value = subjectDN;

            } else if (name.startsWith("sn_")) {
                // get value from subject DN
                value = subjectAttributes.get(name.substring(3));

            } else {
                // unknown attribute, ignore
                if (verbose)
                    System.out.println(" - " + name);
                continue;
            }

            if (value == null)
                continue;

            if (verbose)
                System.out.println(" - " + name + ": " + value);
            attribute.setValue(value);
        }
    }

    if (certRequestUsername != null) {
        request.setAttribute("uid", certRequestUsername);
    }

    if (cmd.hasOption("password")) {
        Console console = System.console();
        String certRequestPassword = new String(console.readPassword("Password: "));
        request.setAttribute("pwd", certRequestPassword);
    }

    if (verbose) {
        System.out.println("Sending certificate request.");
    }

    CertRequestInfos infos = certClient.enrollRequest(request, aid, adn);

    MainCLI.printMessage("Submitted certificate request");
    CACertCLI.printCertRequestInfos(infos);
}

From source file:org.ecoinformatics.seek.ecogrid.quicksearch.QuickSearchAction.java

/**
 * The todo Implementation of abstract method. It will search ecogrid site
 * /*from w  ww . j a  v  a 2  s  .  c  o  m*/
 * @param e
 *            ActionEvent
 */
public synchronized void actionPerformed(ActionEvent e) {
    datasetPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    CacheManager cm;
    try {
        cm = CacheManager.getInstance();
        //cm.showDB();
    } catch (CacheException e1) {
        e1.printStackTrace();
    }
    String searchValue = null;
    if (datasetPanel != null) {
        searchValue = datasetPanel.getSearchTextFieldValue();
        // searchType = datasetPanel.getSearchDataSrcType();
        resultRoot = datasetPanel.getResultRoot();
    }

    //
    // If no search term is entered, return immediately.
    if (searchValue == null || searchValue.trim().equals("")) {
        return;
    }

    System.out.println("searching..");

    searchServicesVector = controller.getSelectedServicesList();
    actionList = new Vector();

    // transfer endpoint based EcoGridService to namespace based Search
    // Scope
    Vector searchScopeVector = transformEcoGridServiceToSearchScope();
    if (!searchScopeVector.isEmpty() && resultRoot != null) {
        resultRoot.removeAllEntities();
        // go through every namespace in search scope
        for (int i = 0; i < searchScopeVector.size(); i++) {
            // vecotr to store the ResultRecord for one search scope
            SearchScope searchScope = (SearchScope) searchScopeVector.elementAt(i);
            // String namespace = searchScope.getNamespace();
            // get quick search query from metadata specification class
            MetadataSpecificationInterface metadataSpecClass = searchScope.getMetadataSpecification();

            // *** Temporary Code
            String namespace = searchScope.getNamespace();

            QueryType quickSearchQuery = null;
            try {
                quickSearchQuery = metadataSpecClass.getQuickSearchEcoGridQuery(searchValue);
            } catch (InvalidEcogridQueryException inE) {
                log.debug("The error to generate quick search query ", inE);
                return;
            }
            Vector searchEndPoints = searchScope.getEndPoints();
            if (searchEndPoints == null) {
                log.debug("No search end points can be found");
                return;
            }

            // go through the end points vector and create query action

            searchEndPointsVector(searchEndPoints, quickSearchQuery, searchValue, metadataSpecClass, namespace);

        } // for
        log.debug("Initial query action ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " + actionList.size());
        completedRequests = new CountDown(actionList.size());
        // start query action
        datasetPanel.resetResultsPanel();

        boolean forRegistryQuery = false;
        datasetPanel.startSearchProgressBar(forRegistryQuery);
        for (int i = 0; i < actionList.size(); i++) {
            QueryAction queryAction = (QueryAction) actionList.elementAt(i);
            queryAction.actionPerformed(null);
        }

    } // if
    datasetPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}

From source file:gov.nih.nci.evs.browser.utils.TreeUtils.java

public HashMap getSubconcepts(String scheme, String version, String code) {
    //String assocName = "hasSubtype";
    String hierarchicalAssoName = "hasSubtype";
    Vector hierarchicalAssoName_vec = getHierarchyAssociationId(scheme, version);
    if (hierarchicalAssoName_vec != null && hierarchicalAssoName_vec.size() > 0) {
        hierarchicalAssoName = (String) hierarchicalAssoName_vec.elementAt(0);
    }//from  w  ww  . j a va2s  .  co m
    return getAssociationTargets(scheme, version, code, hierarchicalAssoName);
}

From source file:org.ecoinformatics.seek.ecogrid.EcogridPreferencesTab.java

/**
 * Method to update service in controller base on the user selection in the
 * panel/*from w ww  . j  a va 2  s  . c o m*/
 */
public void updateController() {
    // currently we just set new service into controller(memory), later will
    // need to
    // save to jar configure file
    if (servicesDisplayPanel != null && controller != null) {
        // removed the all unselected serivce
        Vector allUnSelectedList = servicesDisplayPanel.getAllUnSelectedServicesList();
        if (allUnSelectedList != null) {
            int size = allUnSelectedList.size();
            for (int i = 0; i < size; i++) {
                SelectableEcoGridService service = (SelectableEcoGridService) allUnSelectedList.elementAt(i);
                controller.removeService(service);
            }
        }
        // updated partial selected services
        // this vector is a service list with the selected document type
        Vector partialSelectedList = servicesDisplayPanel.getPartialSelectedServicesList();
        if (partialSelectedList != null) {
            int length = partialSelectedList.size();
            for (int j = 0; j < length; j++) {
                SelectableEcoGridService service = (SelectableEcoGridService) partialSelectedList.elementAt(j);
                try {
                    controller.updateService(service);
                } catch (Exception ee) {
                    log.debug("Could not update a service " + service.getServiceName(), ee);
                }
            } // for
        } // if
    }
}

From source file:org.ecoinformatics.seek.ecogrid.EcoGridServicesController.java

private static int isDuplicateService(EcoGridService service, Vector serviceList)
        throws InvalidEcoGridServiceException {
    int duplicateIndex = -1;
    if (service == null || serviceList == null) {
        throw new InvalidEcoGridServiceException("The service or service list is"
                + " null and couldn't judge if the given service is duplicate in list");
    }//from w w w  .j a  v  a  2  s.  co m
    String givenEndPoint = service.getEndPoint();
    if (givenEndPoint == null || givenEndPoint.trim().equals("")) {
        throw new InvalidEcoGridServiceException("The given service doesn't have "
                + "endpoint and couldn't judge if the given service is duplicate in list");
    }
    int size = serviceList.size();
    for (int i = 0; i < size; i++) {
        EcoGridService currentService = (EcoGridService) serviceList.elementAt(i);
        String currentEndPoint = currentService.getEndPoint();
        if (currentEndPoint != null && currentEndPoint.equals(givenEndPoint)) {
            duplicateIndex = i;
            break;
        } // if
    } // for
    return duplicateIndex;
}

From source file:at.tuwien.ifs.somtoolbox.apps.helper.DataSetGenerator.java

/**
 * @param points vector of dataPoints// w  w w  . jav  a 2  s  .com
 */
private void makeNonNegative(Vector<DataPoint> points) {
    double minXValue = Double.MAX_VALUE;
    double minYValue = Double.MAX_VALUE;
    for (DataPoint d : points) {
        if (d.getX() < minXValue) {
            minXValue = d.getX();
        }
        if (d.getY() < minYValue) {
            minYValue = d.getY();
        }
    }

    double xoff = 0, yoff = 0;
    if (minXValue < 0) {
        xoff = Math.abs(minXValue);
    }
    if (minYValue < 0) {
        yoff = Math.abs(minYValue);
    }
    for (int i = 0; i < points.size(); i++) {
        DataPoint d = points.elementAt(i);
        d.setLocation(d.getX() + xoff, d.getY() + yoff);
    }
}