Example usage for java.util Vector clear

List of usage examples for java.util Vector clear

Introduction

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

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this Vector.

Usage

From source file:edu.ku.brc.specify.rstools.SpAnalysis.java

public void checkAgents(final TableWriter tblWriter) {
    tblWriter.append("<H3>Agents</H3>");
    tblWriter.startTable();/* w w  w  .  j av a 2s  .  c o m*/
    tblWriter.append(
            "<TR><TH>AgentID</TH><TH>LastName</TH><TH>FirstName</TH><TH>MiddleInitial</TH><TH>Ids</TH></TR>");

    Statement stmt = null;
    Statement stmt2 = null;
    try {
        Integer cnt = BasicSQLUtils.getCount(
                "SELECT (COUNT(LOWER(nm)) - COUNT(DISTINCT LOWER(nm))) AS DIF  FROM (SELECT CONCAT(LN,FN,MI) NM FROM(select IFNULL(LastName, '') LN, IFNULL(FirstName, '') FN, IFNULL(MiddleInitial, '') MI from agent) T1) T2");
        if (cnt != null && cnt > 0) {
            String sql = "SELECT AgentID, LOWER(nm) C1 FROM (SELECT AgentID, CONCAT(LN,FN,MI) NM FROM (select AgentID, IFNULL(LastName, '') LN, IFNULL(FirstName, '') FN, IFNULL(MiddleInitial, '') MI from agent) T1) T2 ";

            Vector<Integer> extraIds = new Vector<Integer>();

            Connection conn = DBConnection.getInstance().getConnection();
            stmt = conn.createStatement();
            stmt2 = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql + "  ORDER BY AgentID");
            while (rs.next()) {
                int id = rs.getInt(1);
                String str = rs.getString(2);

                extraIds.clear();

                str = StringUtils.replace(str, "'", "''");
                String sql2 = sql + " WHERE LOWER(nm) = '" + str + "' AND AgentID > " + id
                        + "  ORDER BY AgentID";

                //System.err.println(sql2);

                int dupCnt = 0;
                ResultSet rs2 = stmt2.executeQuery(sql2);
                while (rs2.next()) {
                    extraIds.add(rs2.getInt(1));
                    dupCnt++;
                }
                rs2.close();

                if (dupCnt > 0) {
                    String s = "SELECT AgentID, LastName, FirstName, MiddleInitial FROM agent WHERE AgentID = "
                            + id;
                    Vector<Object[]> rows = BasicSQLUtils.query(s);
                    Object[] row = rows.get(0);
                    tblWriter.append("<TR><TD>" + row[0] + "</TD><TD>" + row[1] + "</TD><TD>" + row[2]
                            + "</TD><TD>" + row[3] + "</TD><TD>");
                    for (int i = 0; i < extraIds.size(); i++) {
                        if (i > 0)
                            tblWriter.log(", ");
                        tblWriter.append(extraIds.get(i).toString());
                    }
                    tblWriter.append("</TD></TR>");
                }
            }
            rs.close();
        }

    } catch (Exception ex) {
        ex.printStackTrace();

    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
            if (stmt2 != null) {
                stmt2.close();
            }
        } catch (Exception ex) {
        }
    }

    tblWriter.endTable();
}

From source file:edu.ku.brc.specify.rstools.SpAnalysis.java

public void checkAddress(final TableWriter tblWriter) {
    Statement stmt = null;//www  .  ja v  a2  s.  co m
    Statement stmt2 = null;
    try {
        Integer cnt = BasicSQLUtils.getCount(
                "SELECT COUNT(LOWER(ADDR)) - COUNT(DISTINCT LOWER(ADDR)) AS DIF FROM (SELECT CONCAT(ID,A1,A2,C,S,Z) ADDR FROM (SELECT AgentID ID, IFNULL(Address, '') A1, IFNULL(Address2, '') A2, IFNULL(City, '') C, IFNULL(State, '') S, IFNULL(State, ''), IFNULL(PostalCode, '') Z from address) T1) T2 ");
        if (cnt != null && cnt > 0) {
            tblWriter.append("<H3>Address</H3>");
            tblWriter.startTable();
            tblWriter.append(
                    "<TR><TH>AddressID</TH><TH>Address</TH><TH>Address2</TH><TH>City</TH><TH>State</TH><TH>PostalCode</TH><TH>Ids</TH></TR>");

            String sql = "SELECT AddressID, LOWER(ADDR) C1 FROM (SELECT AddressID, CONCAT(ID, A1,A2,C,S,Z) ADDR FROM (SELECT AddressID, AgentID ID, IFNULL(Address, '') A1, IFNULL(Address2, '') A2, IFNULL(City, '') C, IFNULL(State, '') S, IFNULL(State, ''), IFNULL(PostalCode, '') Z from address) T1) T2 ";

            Vector<Integer> extraIds = new Vector<Integer>();

            Connection conn = DBConnection.getInstance().getConnection();
            stmt = conn.createStatement();
            stmt2 = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql + "  ORDER BY AddressID");
            while (rs.next()) {
                int id = rs.getInt(1);
                String str = rs.getString(2);

                extraIds.clear();

                str = StringUtils.replace(str, "'", "''");
                String sql2 = sql + " WHERE LOWER(ADDR) = '" + str + "' AND AddressID > " + id;// +"  ORDER BY AddressID";

                int dupCnt = 0;
                ResultSet rs2 = stmt2.executeQuery(sql2);
                while (rs2.next()) {
                    extraIds.add(rs2.getInt(1));
                    dupCnt++;
                }
                rs2.close();

                if (dupCnt > 0) {
                    String s = "SELECT AddressID, Address, Address2, City, state, PostalCode FROM address WHERE AddressID = "
                            + id;
                    Vector<Object[]> rows = BasicSQLUtils.query(s);
                    Object[] row = rows.get(0);
                    tblWriter.append("<TR>");
                    for (Object data : row) {
                        tblWriter.append("<TD>" + data + "</TD>");
                    }
                    tblWriter.append("<TD>");
                    for (int i = 0; i < extraIds.size(); i++) {
                        if (i > 0)
                            tblWriter.log(", ");
                        tblWriter.append(extraIds.get(i).toString());
                    }
                    tblWriter.append("</TD></TR>");
                }
            }
            rs.close();
        }

    } catch (Exception ex) {
        ex.printStackTrace();

    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
            if (stmt2 != null) {
                stmt2.close();
            }
        } catch (Exception ex) {
        }
    }

    tblWriter.endTable();
}

From source file:edu.ku.brc.specify.tools.LocalizerSearchHelper.java

/**
 * @param baseDir/*from   ww w.j  av a2s  .  c o  m*/
 * @return
 */
public Vector<Pair<String, String>> findOldL10NKeys(final String[] fileNames) {
    initLucene(true);

    //if (srcCodeFilesDir == null)
    {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (srcCodeFilesDir != null) {
            chooser.setSelectedFile(new File(FilenameUtils.getName(srcCodeFilesDir.getAbsolutePath())));
            chooser.setSelectedFile(new File(srcCodeFilesDir.getParent()));
        }

        if (chooser.showOpenDialog(UIRegistry.getMostRecentWindow()) == JFileChooser.APPROVE_OPTION) {
            srcCodeFilesDir = new File(chooser.getSelectedFile().getAbsolutePath());
        } else {
            return null;
        }
    }

    indexSourceFiles();

    Vector<Pair<String, String>> fullNotFoundList = new Vector<Pair<String, String>>();

    try {
        ConversionLogger convLogger = new ConversionLogger();
        convLogger.initialize("resources", "Resources");

        for (String fileName : fileNames) {
            Vector<Pair<String, String>> notFoundList = new Vector<Pair<String, String>>();

            Vector<String> terms = new Vector<String>();

            String propFileName = baseDir.getAbsolutePath() + "/" + fileName;

            File resFile = new File(propFileName + ".properties");
            if (resFile.exists()) {
                List<?> lines = FileUtils.readLines(resFile);
                for (String line : (List<String>) lines) {
                    if (!line.startsWith("#")) {
                        int inx = line.indexOf("=");
                        if (inx > -1) {
                            String[] toks = StringUtils.split(line, "=");
                            if (toks.length > 1) {
                                terms.add(toks[0]);
                            }
                        }
                    }
                }
            } else {
                System.err.println("Doesn't exist: " + resFile.getAbsolutePath());
            }

            String field = "contents";
            QueryParser parser = new QueryParser(Version.LUCENE_36, field, analyzer);

            for (String term : terms) {
                Query query;
                try {
                    if (term.equals("AND") || term.equals("OR"))
                        continue;

                    query = parser.parse(term);

                    String subTerm = null;
                    int hits = getTotalHits(query, 10);
                    if (hits == 0) {
                        int inx = term.indexOf('.');
                        if (inx > -1) {
                            subTerm = term.substring(inx + 1);
                            hits = getTotalHits(parser.parse(subTerm), 10);

                            if (hits == 0) {
                                int lastInx = term.lastIndexOf('.');
                                if (lastInx > -1 && lastInx != inx) {
                                    subTerm = term.substring(lastInx + 1);
                                    hits = getTotalHits(parser.parse(subTerm), 10);
                                }
                            }
                        }
                    }

                    if (hits == 0 && !term.endsWith("_desc")) {
                        notFoundList.add(new Pair<String, String>(term, subTerm));

                        log.debug("'" + term + "' was not found "
                                + (subTerm != null ? ("SubTerm[" + subTerm + "]") : ""));
                    }

                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }

            String fullName = propFileName + ".html";
            TableWriter tblWriter = convLogger.getWriter(FilenameUtils.getName(fullName), propFileName);
            tblWriter.startTable();
            tblWriter.logHdr("Id", "Full Key", "Sub Key");
            int cnt = 1;
            for (Pair<String, String> pair : notFoundList) {
                tblWriter.log(Integer.toString(cnt++), pair.first,
                        pair.second != null ? pair.second : "&nbsp;");
            }
            tblWriter.endTable();

            fullNotFoundList.addAll(notFoundList);

            if (notFoundList.size() > 0 && resFile.exists()) {
                List<String> lines = (List<String>) FileUtils.readLines(resFile);
                Vector<String> linesCache = new Vector<String>();

                for (Pair<String, String> p : notFoundList) {
                    linesCache.clear();
                    linesCache.addAll(lines);

                    int lineInx = 0;
                    for (String line : linesCache) {
                        if (!line.startsWith("#")) {
                            int inx = line.indexOf("=");
                            if (inx > -1) {
                                String[] toks = StringUtils.split(line, "=");
                                if (toks.length > 1) {
                                    if (toks[0].equals(p.first)) {
                                        lines.remove(lineInx);
                                        break;
                                    }
                                }
                            }
                        }
                        lineInx++;
                    }
                }
                FileUtils.writeLines(resFile, linesCache);
            }

        }
        convLogger.closeAll();

    } catch (IOException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LocalizerSearchHelper.class, ex);
        ex.printStackTrace();
    }

    return fullNotFoundList;
}

From source file:edu.ku.brc.specify.utilapps.SetUpBuildDlg.java

/**
 * @param choices//www .jav  a 2  s.  c o  m
 */
public void resetDefaults(final Vector<CollectionChoice> choices) {
    choices.clear();
    fillChoicesWithDefaults();
    ((DisciplineSetupModel) choiceTable.getModel()).fireChanged();
}

From source file:org.exist.xmlrpc.XmlRpcTest.java

@Test
public void testCollectionWithAccentsAndSpaces() {
    System.out.println("---testCollectionWithAccentsAndSpaces");
    storeData();//from w  w w.  j  a va 2s  .  co  m
    try {
        System.out.println("Creating collection with accents and spaces in name ...");
        Vector<Object> params = new Vector<Object>();
        params.addElement(SPECIAL_COLLECTION.toString());
        XmlRpcClient xmlrpc = getClient();
        xmlrpc.execute("createCollection", params);

        System.out.println("Storing document " + XML_DATA);
        params.clear();
        params.addElement(XML_DATA);
        params.addElement(SPECIAL_RESOURCE.toString());
        params.addElement(Integer.valueOf(1));

        Boolean result = (Boolean) xmlrpc.execute("parse", params);
        Assert.assertTrue(result.booleanValue());

        params.clear();
        params.addElement(SPECIAL_COLLECTION.removeLastSegment().toString());

        HashMap collection = (HashMap) xmlrpc.execute("describeCollection", params);
        Object[] collections = (Object[]) collection.get("collections");
        boolean foundMatch = false;
        String targetCollectionName = SPECIAL_COLLECTION.lastSegment().toString();
        for (int i = 0; i < collections.length; i++) {
            String childName = (String) collections[i];
            System.out.println("Child collection: " + childName);
            if (childName.equals(targetCollectionName)) {
                foundMatch = true;
                break;
            }
        }
        Assert.assertTrue("added collection not found", foundMatch);

        System.out.println("Retrieving document '" + SPECIAL_RESOURCE.toString() + "'");
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("indent", "yes");
        options.put("encoding", "UTF-8");
        options.put("expand-xincludes", "yes");
        options.put("process-xsl-pi", "no");

        params.clear();
        params.addElement(SPECIAL_RESOURCE.toString());
        params.addElement(options);

        // execute the call
        byte[] data = (byte[]) xmlrpc.execute("getDocument", params);
        System.out.println(new String(data, "UTF-8"));
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

From source file:org.exist.xmlrpc.XmlRpcTest.java

private void storeData() {
    System.out.println("---storeData");
    try {//  w w  w.ja  v a  2 s . com
        System.out.println("Creating collection " + TARGET_COLLECTION);
        XmlRpcClient xmlrpc = getClient();
        Vector<Object> params = new Vector<Object>();
        params.addElement(TARGET_COLLECTION.toString());
        Boolean result = (Boolean) xmlrpc.execute("createCollection", params);
        Assert.assertTrue(result.booleanValue());

        System.out.println("Storing document " + XML_DATA);
        params.clear();
        params.addElement(XML_DATA);
        params.addElement(TARGET_RESOURCE.toString());
        params.addElement(Integer.valueOf(1));

        result = (Boolean) xmlrpc.execute("parse", params);
        Assert.assertTrue(result.booleanValue());

        System.out.println("Storing resource " + XSL_DATA);
        params.setElementAt(XSL_DATA, 0);
        params.setElementAt(TARGET_COLLECTION.append("test.xsl").toString(), 1);
        result = (Boolean) xmlrpc.execute("parse", params);
        Assert.assertTrue(result.booleanValue());

        System.out.println("Storing resource " + MODULE_DATA);
        params.setElementAt(MODULE_DATA.getBytes(UTF_8), 0);
        params.setElementAt(MODULE_RESOURCE.toString(), 1);
        params.setElementAt(MimeType.XQUERY_TYPE.getName(), 2);
        params.addElement(Boolean.TRUE);
        result = (Boolean) xmlrpc.execute("storeBinary", params);
        Assert.assertTrue(result.booleanValue());

        System.out.println("Documents stored.");
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:org.exist.xmlrpc.XmlRpcTest.java

@Test
public void testQueryWithStylesheet() {
    System.out.println("---testQueryWithStylesheet");
    storeData();//w w w.  j  a  v a2s  .  c  om
    try {
        HashMap<String, String> options = new HashMap<String, String>();
        options.put(EXistOutputKeys.STYLESHEET, "test.xsl");
        options.put(EXistOutputKeys.STYLESHEET_PARAM + ".testparam", "Test");
        options.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
        //TODO : check the number of resources before !
        Vector<Object> params = new Vector<Object>();
        String query = "//para[1]";
        params.addElement(query.getBytes(UTF_8));
        params.addElement(options);
        XmlRpcClient xmlrpc = getClient();
        Integer handle = (Integer) xmlrpc.execute("executeQuery", params);
        Assert.assertNotNull(handle);

        params.clear();
        params.addElement(handle);
        params.addElement(Integer.valueOf(0));
        params.addElement(options);
        byte[] item = (byte[]) xmlrpc.execute("retrieve", params);
        Assert.assertNotNull(item);
        Assert.assertTrue(item.length > 0);
        String out = new String(item, UTF_8);
        System.out.println("Received: " + out);
        XMLAssert.assertXMLEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<p>Test: \u00E4\u00E4\u00F6\u00F6\u00FC\u00FC\u00C4\u00C4\u00D6\u00D6\u00DC\u00DC\u00DF\u00DF</p>",
                out);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}

From source file:org.exist.xmlrpc.XmlRpcTest.java

@Test
public void testStoreAndRetrieve() {
    System.out.println("---testStoreAndRetrieve");
    try {/*from   w  ww.j  a va 2 s .  com*/
        System.out.println("Creating collection " + TARGET_COLLECTION);
        XmlRpcClient xmlrpc = getClient();
        Vector<Object> params = new Vector<Object>();
        params.addElement(TARGET_COLLECTION.toString());
        Boolean result = (Boolean) xmlrpc.execute("createCollection", params);
        Assert.assertTrue(result.booleanValue());

        System.out.println("Storing document " + XML_DATA);
        params.clear();
        params.addElement(XML_DATA);
        params.addElement(TARGET_RESOURCE.toString());
        params.addElement(new Integer(1));

        result = (Boolean) xmlrpc.execute("parse", params);
        Assert.assertTrue(result.booleanValue());

        System.out.println("Documents stored.");

        HashMap<String, String> options = new HashMap<String, String>();
        params.clear();
        params.addElement(TARGET_RESOURCE.toString());
        params.addElement(options);

        byte[] data = (byte[]) xmlrpc.execute("getDocument", params);
        System.out.println(new String(data, "UTF-8"));
        Assert.assertNotNull(data);

        params.clear();
        params.addElement(TARGET_RESOURCE.toString());
        params.addElement("UTF-8");
        params.addElement(0);

        data = (byte[]) xmlrpc.execute("getDocument", params);
        System.out.println(new String(data, "UTF-8"));
        Assert.assertNotNull(data);

        params.clear();
        params.addElement(TARGET_RESOURCE.toString());
        params.addElement(0);
        String sdata = (String) xmlrpc.execute("getDocumentAsString", params);
        System.out.println(sdata);
        Assert.assertNotNull(data);

        params.clear();
        params.addElement(TARGET_RESOURCE.toString());
        params.addElement(options);
        HashMap<?, ?> table = (HashMap<?, ?>) xmlrpc.execute("getDocumentData", params);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        int offset = ((Integer) table.get("offset")).intValue();
        data = (byte[]) table.get("data");
        os.write(data);
        while (offset > 0) {
            params.clear();
            params.add(table.get("handle"));
            params.add(Integer.valueOf(offset));
            table = (HashMap<?, ?>) xmlrpc.execute("getNextChunk", params);
            offset = ((Integer) table.get("offset")).intValue();
            data = (byte[]) table.get("data");
            os.write(data);
        }
        data = os.toByteArray();
        Assert.assertTrue(data.length > 0);
        System.out.println(new String(data, "UTF-8"));

        params.clear();
        params.addElement(TARGET_RESOURCE.toString());
        Boolean b = (Boolean) xmlrpc.execute("hasDocument", params);
        Assert.assertTrue(b.booleanValue());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:com.app.server.EJBDeployer.java

public void undeploy(URL url) {
    try {/*from  www  . j a  v a  2  s.  c  o m*/
        //System.out.println(jarEJBMap.get(url.toString()));
        Vector<Object> objs = staticObjsEjbMap.remove(url.toString());
        if (objs != null) {
            objs.clear();
        }
        Vector<EJBContext> ejbContexts = jarEJBMap.get(url.toString());
        if (ejbContexts != null && ejbContexts.size() > 0) {
            for (EJBContext ejbContext : ejbContexts) {
                if (ejbContext != null) {
                    HashMap<String, Class> bindings = ejbContext.getRemoteBindings();
                    Set<String> remoteBindings = bindings.keySet();
                    Iterator<String> remoteBinding = remoteBindings.iterator();
                    while (remoteBinding.hasNext()) {
                        String binding = (String) remoteBinding.next();
                        Object unbindstatefulObjs = ic.lookup("java:/" + binding);
                        if (unbindstatefulObjs instanceof StatefulBeanObject) {
                            Vector<Object> StatefulBeanObjects = StatefulBeanObject.statefulSessionBeanObjectMap
                                    .get(url.toString());
                            StatefulBeanObject.statefulSessionBeanObjectMap.remove(url.toString());
                            StatefulBeanObjects.clear();
                        }
                        ic.unbind("java:/" + binding);
                        System.out.println("unregistering the class" + bindings.get(binding));
                    }
                    jarEJBMap.remove(url.toString());
                }
            }
        }
        ConcurrentHashMap<String, MDBContext> mdbContexts = jarMDBMap.get(url.toString());
        MDBContext mdbContext;
        if (mdbContexts != null) {
            Iterator<String> mdbnames = mdbContexts.keySet().iterator();
            while (mdbnames.hasNext()) {
                String mdbname = mdbnames.next();
                mdbContext = mdbContexts.get(mdbname);
                if (mdbContext.getResourceAdapter() != null) {
                    mdbContext.getResourceAdapter().endpointDeactivation(mdbContext.getMessageEndPointFactory(),
                            mdbContext.getActivationSpec());
                    mdbContext.getResourceAdapter().stop();
                }
                if (mdbContext.getConsumer() != null) {
                    mdbContext.getConsumer().setMessageListener(null);
                    mdbContext.getConsumer().close();
                }
                if (mdbContext.getSession() != null)
                    mdbContext.getSession().close();
                if (mdbContext.getConnection() != null)
                    mdbContext.getConnection().close();
                mdbContexts.remove(mdbname);
            }
            jarMDBMap.remove(url.toString());
        }
        log.info(url.toString() + " UnDeployed");
    } catch (Exception ex) {
        log.error("Error in undeploying the package " + url, ex);
        //ex.printStackTrace();
    }
}

From source file:com.google.gsa.valve.rootAuth.RootAuthenticationProcess.java

/**
 * This is the main method that drives the whole authentication 
 * process. It launches each individual authentication method declared in 
 * the configuration files. Those that includes the tag "checkauthN" set to 
 * false are not processed.//from w ww.ja  va2 s. c o  m
 * <p>
 * The name of the authentication classes that need to be processed are included 
 * in a vector that is reused multiple times. Whenever a new authentication 
 * process needs to be relaunched, all these classes are processed and the 
 * individual authentication process is treated.
 * <p>
 * It returns the HTTP error code associated to the process result. If it was 
 * OK, this methods returns a 200 and 401 (unauthorized) otherwise.
 * <p>
 * There is a special repository named "root" that is treatly in a special way. 
 * If any repository is named as "root", it means this is the main authentication 
 * mechanim and that's why it's trated first. If it fails, the authentication 
 * process stops here and the return result is an error. If not, the whole 
 * processing continues.
 * <p>
 * If there is a "root" repository and the authentication process for this 
 * repository is OK, although any other repository would fail, the overall 
 * authentication method returns an OK. If there is not such a "root" 
 * repository, any authentication error will cause the authentication process 
 * to fail.
 * 
 * @param request HTTP request
 * @param response HTTP response
 * @param authCookies vector that contains the authentication cookies
 * @param url the document url
 * @param creds an array of credentials for all external sources
 * @param id the default credential id to be retrieved from creds
        
 * @return the HTTP error code
        
 * @throws HttpException
 * @throws IOException
 */
public int authenticate(HttpServletRequest request, HttpServletResponse response, Vector<Cookie> authCookies,
        String url, Credentials creds, String id) throws HttpException, IOException {

    // Initialize status code
    int rootStatusCode = HttpServletResponse.SC_UNAUTHORIZED;
    int repositoryAuthStatusCode = HttpServletResponse.SC_UNAUTHORIZED;
    //Check if authn is Ok in multiple repository
    boolean repositoryOKAuthN = false;

    //clear authCookies
    authCookies.clear();

    boolean rootAuthNDefined = false;
    logger.debug("AuthN authenticate [" + url + "]");

    //Read vars
    if (valveConf != null) {
        isKerberos = new Boolean(valveConf.getKrbConfig().isKerberos()).booleanValue();
        if (isKerberos) {
            isNegotiate = new Boolean(valveConf.getKrbConfig().isNegotiate()).booleanValue();
        }
        loginUrl = valveConf.getLoginUrl();
    } else {
        logger.error("Configuration error: Config file is not present");
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Configuration error - Kerberos is not set properly");
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }

    //ValveHost: it's the same URL as the login page, without 
    String valveHost = loginUrl.substring(0, loginUrl.lastIndexOf("/") + 1);

    RE internal = new RE(valveHost, RE.MATCH_CASEINDEPENDENT);

    // The host and URL of the GSA for the search
    //TODO add support for multiple GSA's
    RE query = new RE("/search", RE.MATCH_CASEINDEPENDENT);

    //Request has come from the same host as the valve, so must be the login authenticate
    if (internal.match(url)) {

        //Authentication vars
        String repositoryID = null;
        AuthenticationProcessImpl authProcess = null;
        ValveRepositoryConfiguration repositoryConfig = null;

        int order = 1;
        int size = authenticationImplementationsOrder.size();
        if (authenticationImplementationsOrder == null) {
            order = 0;
            logger.error(
                    "No Authentication module has been defined. Please check and add those needed at config file");
        }

        while ((1 <= order) && (order <= size)) {

            //Get the repository ID
            logger.debug("###Processing repository # " + order + " ###");
            Integer orderInt = new Integer(order);
            if (authenticationImplementationsOrder.containsKey(orderInt)) {
                repositoryID = authenticationImplementationsOrder.get(orderInt);
            } else {
                logger.error("Error during processing authentication methods. Order is not valid");
                break;
            }

            //Get the Repository config and authentication class                                                    
            authProcess = authenticationImplementations.get(repositoryID);
            repositoryConfig = valveConf.getRepository(repositoryID);

            logger.debug("Authenticating ID: " + repositoryConfig.getId());
            if (repositoryConfig.getId().equals("root")) {
                //Root should be used for main authentication against an identity repository (LDAP, DB, ..)
                //and should not be used as a content repository that contains documents
                try {
                    //add support to cookie array
                    rootAuthCookies.clear();
                    rootStatusCode = authProcess.authenticate(request, response, rootAuthCookies, url, creds,
                            "root");
                    logger.info("Repository authentication - " + repositoryConfig.getId()
                            + " completed. Response was " + rootStatusCode);
                    if (rootStatusCode == HttpServletResponse.SC_UNAUTHORIZED) {
                        logger.error("Root AuthN failed");
                    } else {
                        //Support to cookie array
                        if (rootStatusCode == HttpServletResponse.SC_OK) {
                            logger.debug("Root AuthN is SC_OK (200)");
                            if (!rootAuthCookies.isEmpty()) {
                                logger.debug("Root AuthN returns cookies");
                                for (int j = 0; j < rootAuthCookies.size(); j++) {
                                    logger.debug("Root Cookie found: " + rootAuthCookies.elementAt(j).getName()
                                            + ":" + rootAuthCookies.elementAt(j).getValue());
                                    authCookies.add(rootAuthCookies.elementAt(j));
                                }
                            } else {
                                logger.debug("Root AuthN does NOT return cookies");
                            }
                        }
                    }

                    //If no repository is defined called root then rootStatusCode must be set to OK
                    // This flag is used to indicate that a root repository has been defined.
                    rootAuthNDefined = true;
                    //
                } catch (Exception e) {
                    logger.debug("Exception with authentication for ID: " + repositoryConfig.getId() + " - "
                            + e.getMessage());
                    rootAuthNDefined = true;
                }
            } else {
                try {

                    //add support to cookie array
                    repositoryAuthCookies.clear();

                    logger.debug("Let's do the authentication");

                    repositoryAuthStatusCode = authProcess.authenticate(request, response,
                            repositoryAuthCookies, url, creds, repositoryConfig.getId());

                    //add support to cookie array
                    if (repositoryAuthStatusCode == HttpServletResponse.SC_OK) {
                        logger.debug("Repository AuthN [" + repositoryConfig.getId() + "] is SC_OK (200)");
                        //check if multiple repository is set to valid
                        if (repositoryOKAuthN == false) {
                            repositoryOKAuthN = true;
                        }
                        //check if cookie array is not empty and consume it
                        if (!repositoryAuthCookies.isEmpty()) {
                            logger.debug("Repository AuthN [" + repositoryConfig.getId() + "] returns "
                                    + repositoryAuthCookies.size() + " cookies");
                            for (int j = 0; j < repositoryAuthCookies.size(); j++) {
                                logger.debug("Repository Cookie found: "
                                        + repositoryAuthCookies.elementAt(j).getName() + ":"
                                        + repositoryAuthCookies.elementAt(j).getValue());
                                authCookies.add(repositoryAuthCookies.elementAt(j));
                            }
                        } else {
                            logger.debug("Repository AuthN [" + repositoryConfig.getId()
                                    + "] does NOT return cookies");
                        }
                    }

                    //end Krb support
                    logger.info("Repository authentication - " + repositoryConfig.getId()
                            + " completed. Response was " + repositoryAuthStatusCode);
                } catch (Exception e) {
                    logger.debug("Exception with authentication for ID: " + repositoryConfig.getId() + " - "
                            + e.getMessage());
                }
            }

            //increase order
            order++;
        }
    } else if (query.match(url)) {

        logger.debug("Query pattern [" + url + "]");

        // Don't do anything in here
        rootStatusCode = HttpServletResponse.SC_OK;

    } else {

        logger.error("No pattern defined for URL: " + url + ". It should not have been possible to get here!");

        // Protection
        rootStatusCode = HttpServletResponse.SC_UNAUTHORIZED;

    }

    //add support to multiple repositories
    if ((!rootAuthNDefined) && (repositoryOKAuthN)) {
        //If no root repository has been defined then rootStatusCode has to be set valid, to OK
        rootStatusCode = HttpServletResponse.SC_OK;
    }

    // Return status code
    logger.debug("RootAuthN Complete - Status Code: " + rootStatusCode);

    return rootStatusCode;

}