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:com.sittinglittleduck.DirBuster.GenBaseCase.java

/**
 * Generates the base case/*from www. ja v  a  2 s. com*/
 *
 * @param manager the manager class
 * @param url The directy or file we need a base case for
 * @param isDir true if it's dir, else false if it's a file
 * @param fileExtention File extention to be scanned, set to null if it's a dir that is to be
 *     tested
 * @return A BaseCase Object
 */
public static BaseCase genBaseCase(Manager manager, String url, boolean isDir, String fileExtention)
        throws MalformedURLException, IOException {
    String type;
    if (isDir) {
        type = "Dir";
    } else {
        type = "File";
    }

    /*
     * markers for using regex instead
     */
    boolean useRegexInstead = false;
    String regex = null;

    BaseCase tempBaseCase = manager.getBaseCase(url, isDir, fileExtention);

    if (tempBaseCase != null) {
        // System.out.println("Using prestored basecase");
        return tempBaseCase;
    }

    // System.out.println("DEBUG GenBaseCase: URL to get baseCase for: " + url + " (" + type +
    // ")");
    if (Config.debug) {
        System.out.println("DEBUG GenBaseCase: URL to get baseCase for:" + url);
    }

    BaseCase baseCase = null;
    int failcode = 0;
    String failString = Config.failCaseString;
    String baseResponce = "";
    URL failurl = null;
    if (isDir) {
        failurl = new URL(url + failString + "/");
    } else {
        if (manager.isBlankExt()) {
            fileExtention = "";
            failurl = new URL(url + failString + fileExtention);
        } else {
            if (!fileExtention.startsWith(".")) {
                fileExtention = "." + fileExtention;
            }
            failurl = new URL(url + failString + fileExtention);
        }
    }

    // System.out.println("DEBUG GenBaseCase: Getting :" + failurl + " (" + type + ")");
    if (Config.debug) {
        System.out.println("DEBUG GenBaseCase: Getting:" + failurl);
    }

    GetMethod httpget = new GetMethod(failurl.toString());
    // set the custom HTTP headers
    Vector HTTPheaders = manager.getHTTPHeaders();
    for (int a = 0; a < HTTPheaders.size(); a++) {
        HTTPHeader httpHeader = (HTTPHeader) HTTPheaders.elementAt(a);
        /*
         * Host header has to be set in a different way!
         */
        if (httpHeader.getHeader().startsWith("Host")) {
            httpget.getParams().setVirtualHost(httpHeader.getValue());
        } else {
            httpget.setRequestHeader(httpHeader.getHeader(), httpHeader.getValue());
        }
    }
    httpget.setFollowRedirects(Config.followRedirects);

    // save the http responce code for the base case
    failcode = manager.getHttpclient().executeMethod(httpget);
    manager.workDone();

    // we now need to get the content as we need a base case!
    if (failcode == 200) {
        if (Config.debug) {
            System.out.println("DEBUG GenBaseCase: base case for " + failurl.toString() + "came back as 200!");
        }

        BufferedReader input = new BufferedReader(new InputStreamReader(httpget.getResponseBodyAsStream()));
        String tempLine;
        StringBuffer buf = new StringBuffer();
        while ((tempLine = input.readLine()) != null) {
            buf.append("\r\n" + tempLine);
        }
        baseResponce = buf.toString();
        input.close();

        // HTMLparse.parseHTML();

        // HTMLparse htmlParse = new HTMLparse(baseResponce, null);
        // Thread parse  = new Thread(htmlParse);
        // parse.start();

        // clean up the base case, based on the basecase URL
        baseResponce = FilterResponce.CleanResponce(baseResponce, failurl, failString);

        httpget.releaseConnection();

        /*
         * get the base case twice more, for consisitency checking
         */
        String baseResponce1 = baseResponce;
        String baseResponce2 = getBaseCaseAgain(manager, failurl, failString);
        String baseResponce3 = getBaseCaseAgain(manager, failurl, failString);

        if (baseResponce1 != null && baseResponce2 != null && baseResponce3 != null) {
            /*
             * check that all the responces are same, if they are do nothing if not enter the if statement
             */

            if (!baseResponce1.equalsIgnoreCase(baseResponce2) || !baseResponce1.equalsIgnoreCase(baseResponce3)
                    || !baseResponce2.equalsIgnoreCase(baseResponce3)) {
                if (manager.getFailCaseRegexes().size() != 0) {

                    /*
                     * for each saved regex see if it will work, if it does then use that one
                     * if not then give the uses the dialog
                     */

                    Vector<String> failCaseRegexes = manager.getFailCaseRegexes();
                    for (int a = 0; a < failCaseRegexes.size(); a++) {

                        Pattern regexFindFile = Pattern.compile(failCaseRegexes.elementAt(a));

                        Matcher m1 = regexFindFile.matcher(baseResponce1);
                        Matcher m2 = regexFindFile.matcher(baseResponce2);
                        Matcher m3 = regexFindFile.matcher(baseResponce3);

                        boolean test1 = m1.find();
                        boolean test2 = m2.find();
                        boolean test3 = m3.find();

                        if (test1 && test2 && test3) {
                            regex = failCaseRegexes.elementAt(a);
                            useRegexInstead = true;
                            break;
                        }
                    }
                }
            } else {
                /*
                 * We have a big problem as now we have different responce codes for the same request
                 * //TODO think of a way to deal with is
                 */
            }

            if (Config.debug) {
                System.out.println("DEBUG GenBaseCase: base case was set to :" + baseResponce);
            }
        }
    }
    httpget.releaseConnection();

    baseCase = new BaseCase(new URL(url), failcode, isDir, failurl, baseResponce, fileExtention,
            useRegexInstead, regex);

    // add the new base case to the manager list
    manager.addBaseCase(baseCase);
    manager.addNumberOfBaseCasesProduced();

    return baseCase;
}

From source file:Main.java

public static String[] split(String original, String separator) {
    Vector nodes = new Vector();

    // Parse nodes into vector
    int index = original.indexOf(separator);
    while (index >= 0) {
        nodes.addElement(original.substring(0, index));
        original = original.substring(index + separator.length());
        index = original.indexOf(separator);
    }//from   w  ww  .j a  va  2s  . com
    // Get the last node
    nodes.addElement(original);

    // Create splitted string array
    String[] result = new String[nodes.size()];
    if (nodes.size() > 0) {
        for (int loop = 0; loop < nodes.size(); loop++)
            result[loop] = (String) nodes.elementAt(loop);
    }
    return result;
}

From source file:org.ariadne.oai.utils.HarvesterUtils.java

public static void removeAllTargets() {
    Vector list = HarvesterUtils.getReposList();
    for (int i = 0; i < list.size(); i++) {

        String repos = (String) list.elementAt(i);
        removeRepository(repos);//from   ww w .j  a  v a 2s . co  m
    }
}

From source file:org.intermine.bio.dataconversion.OrthodbConverter.java

/**
 * combination algorithm, return all combinations of n from m
 *///from w  ww  .ja  v  a 2s .  c  o  m
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void combination(Vector allCombinations, Vector data, Vector initialCombination, int length) {
    if (length == 1) {
        for (int i = 0; i < data.size(); i++) {
            Vector newCombination = new Vector(initialCombination);
            newCombination.add(data.elementAt(i));
            allCombinations.add(newCombination);
        }
    }

    if (length > 1) {
        for (int i = 0; i < data.size(); i++) {
            Vector newCombination = new Vector(initialCombination);
            newCombination.add(data.elementAt(i));

            Vector newData = new Vector(data);
            for (int j = 0; j <= i; j++)
                newData.remove(data.elementAt(j));

            combination(allCombinations, newData, newCombination, length - 1);
        }
    }
}

From source file:com.fluidops.iwb.deepzoom.DZConvert.java

/**
 * Saves strings as text to the given file
 * @param lines the image to be saved// w ww  . j a  va2 s  .  c om
 * @param file the file to which it is saved
 */
private static void saveText(Vector lines, File file) throws IOException {
    PrintStream ps = null;
    try {
        FileOutputStream fos = new FileOutputStream(file);
        ps = new PrintStream(fos);
        for (int i = 0; i < lines.size(); i++)
            ps.println((String) lines.elementAt(i));
    } catch (IOException e) {
        throw new IOException("Unable to write to text file: " + file);
    } finally {
        IOUtils.closeQuietly(ps);
    }
}

From source file:org.ariadne.oai.utils.HarvesterUtils.java

public static void removeRepository(String repository) {
    PropertiesManager.getInstance().removeKeyFromPropertiesFile(repository + ".");

    Vector list = HarvesterUtils.getReposList();
    String newRepositories = "";
    for (int i = 0; i < list.size(); i++) {

        String repos = (String) list.elementAt(i);
        if (!repos.equals(repository)) {
            if (!newRepositories.equals("")) {
                newRepositories = newRepositories + ";";
            }/*from   www.  j av  a2 s.  c om*/
            newRepositories = newRepositories + repos;
        }
    }

    PropertiesManager.getInstance().saveProperty("AllTargets.list", newRepositories);
}

From source file:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java

/**
 * Returns a list of all Staining  /*from   w w  w .  j a va2s  .c  o m*/
 * Used for submission and search screens
 * 
 * @return Staining
 * @throws Exception
 */
private static List getQueryStainingList(HttpServletRequest inRequest, String inAddBlank) throws Exception {
    log.debug("Entering NewDropdownUtil.getQueryStainingList");

    // Get values for dropdown lists for Staining
    List<DropdownOption> theReturnList = new ArrayList<DropdownOption>();
    Stain st = new Stain();
    Vector stain = st.retrieveAllWhere("stain_name IS NOT NULL ORDER BY stain_description");
    for (int j = 0; j < stain.size(); j++) {
        Stain St = (Stain) stain.elementAt(j);
        if (St.getStain_id() != null) {
            DropdownOption theOption = new DropdownOption(St.getStain_description(),
                    St.getStain_id().toString());
            theReturnList.add(theOption);
        }
    }
    log.debug("Exiting getQueryStainingList.size " + theReturnList.size());
    return theReturnList;
}

From source file:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java

/**
 * Returns a list of all Strain  /*  w  w w.java  2  s  .c o m*/
 * Used for submission and search screens
 * 
 * @return Strain
 * @throws Exception
 */
private static List getQueryStrainList(HttpServletRequest inRequest, String inAddBlank) throws Exception {
    log.debug("Entering NewDropdownUtil.getQueryStrainList");

    // Get values for dropdown lists for Strain
    List<DropdownOption> theReturnList = new ArrayList<DropdownOption>();
    Strain str = new Strain();
    Vector strain = str.retrieveAllWhere("strain_name IS NOT NULL ORDER BY strain_name");
    for (int j = 0; j < strain.size(); j++) {
        Strain Str = (Strain) strain.elementAt(j);
        if (Str.getStrain_id() != null) {
            DropdownOption theOption = new DropdownOption(Str.getStrain_name(), Str.getStrain_id().toString());
            theReturnList.add(theOption);
        }
    }
    log.debug("Exiting getQueryStrainList.size " + theReturnList.size());
    return theReturnList;
}

From source file:org.ariadne.oai.utils.HarvesterUtils.java

public static Vector<ReposProperties> getReposProperties() {
    Vector<String> list = HarvesterUtils.getReposList();
    Vector<ReposProperties> repositories = new Vector<ReposProperties>();
    for (int i = 0; i < list.size(); i++) {
        String ident = list.elementAt(i);
        ReposProperties repos = getReposProperties(ident);
        repositories.add(repos);/*from   ww  w .  j a  v  a2  s  .  c om*/
    }
    return repositories;
}

From source file:com.funambol.framework.tools.WBXMLTools.java

private static String parseWBXML(SyncMLParser parser, boolean[] inTag) throws IOException {
    /**//from  w  ww .j a v a2 s.  c  o  m
     * inTag[0]: flag for tag <Put> or <Results>
     * inTag[1]: flag for tag <Item> not in Put or Results
     * inTag[2]: flag for tag <Data> (inside a Item not in Put or Results)
     * inTag[3]: flag for tag <Cred>
     * inTag[4]: set if tag Meta inside Cred contains "b64"
     * inTag[5]: set if tag Meta inside Cred contains "auth-md5"
     */
    StringBuffer buf = new StringBuffer();
    boolean leave = false;

    String tagName = null;
    String text = null;

    do {
        ParseEvent event = parser.read();
        switch (event.getType()) {
        case Xml.START_TAG:
            tagName = event.getName();

            buf.append("<");
            buf.append(tagName);
            Vector attrs = event.getAttributes();
            if (attrs != null) {
                for (int i = 0; i < attrs.size(); i++) {
                    Attribute attr = (Attribute) attrs.elementAt(i);
                    buf.append(" ");
                    buf.append(attr.getName());
                    buf.append("='");
                    buf.append(attr.getValue());
                    buf.append("'");
                }
            }
            buf.append(">");

            //
            //This is util for replace the Data content if contains
            //illegal character
            //
            if (!inTag[0]) {
                inTag[0] = ("Put".equals(tagName) || "Results".equals(tagName));
            }

            if (!inTag[0]) {
                if (!inTag[1]) {
                    inTag[1] = "Item".equals(tagName);
                } else if (inTag[1]) {
                    inTag[2] = "Data".equals(tagName);
                }
            }

            //
            //This is util to establish if the auth-md5 credential are
            //encoded in Base64
            //
            if (!inTag[3]) {
                inTag[3] = "Cred".equals(tagName);
            }

            text = parseWBXML(parser, inTag);

            if (inTag[3]) {
                if ("Meta".equals(tagName)) {
                    inTag[4] = (text.indexOf("b64") >= 0);
                    inTag[5] = (text.indexOf("auth-md5") >= 0);
                    buf.append(text);
                    text = parseWBXML(parser, inTag);
                }
            }

            buf.append(text);
            break;

        case Xml.END_TAG:
            tagName = event.getName();
            if (tagName != null) {
                if (tagName.equals("Put") || tagName.equals("Results")) {
                    if (inTag[0]) {
                        inTag[0] = false;
                    }
                } else if (tagName.equals("Cred")) {
                    if (inTag[3]) {
                        inTag[3] = false;
                        inTag[4] = false;
                        inTag[5] = false;
                    }
                } else if (tagName.equals("Item")) {
                    if (inTag[1]) {
                        inTag[1] = false;
                    }
                } else if (tagName.equals("Data")) {
                    if (inTag[2]) {
                        inTag[2] = false;
                    }
                }
            }
            buf.append("</");
            buf.append(event.getName());
            buf.append(">");
            leave = true;
            break;

        case Xml.END_DOCUMENT:
            leave = true;
            break;

        case Xml.TEXT:
            text = event.getText();

            if (!inTag[0] && inTag[1] && inTag[2]) {
                text = replaceDataContent(text);
            }
            buf.append(text);
            break;

        case Xml.WAP_EXTENSION:
            text = event.getText();

            if (!inTag[0] && inTag[1] && inTag[2]) {
                text = replaceDataContent(text);
            }

            if (event instanceof WapExtensionEvent) {
                WapExtensionEvent e = (WapExtensionEvent) event;
                Object content = e.getContent();

                if (inTag[5] && !inTag[4] && content != null) {
                    if (content instanceof byte[]) {
                        text = new String(Base64.encode((byte[]) content));
                    }
                }
            }

            buf.append(text);
            break;

        case Xml.WHITESPACE:
            break;

        default:
        }
    } while (!leave);

    return buf.toString();
}