Example usage for java.util Hashtable containsKey

List of usage examples for java.util Hashtable containsKey

Introduction

In this page you can find the example usage for java.util Hashtable containsKey.

Prototype

public synchronized boolean containsKey(Object key) 

Source Link

Document

Tests if the specified object is a key in this hashtable.

Usage

From source file:edu.ucsb.nceas.metacat.util.RequestUtil.java

/**
 * Get the session data from a request. The Scenarios we can run across
 * here: //from   www.  j av  a  2  s.  c o  m
 * -- the session id parameter was set in the request parameters 
 * -- request.getSession returns a new session. There is a chance that the
 *    session id was set in a cookie. Check for a JSESSIONID cookie and use
 *    that id if provided. 
 * -- request.getSession returns a session that is a)
 *    preexisting or b) new but without a JSESSIONID cookie. Use the session id
 *    from this session
 * 
 * @param request
 *            the request from which to get the session data
 * @return the session data object representing the active session for this
 *         request. If there is no active session, the public session data
 *         is returned
 */
public static SessionData getSessionData(HttpServletRequest request) {
    SessionData sessionData = null;
    String sessionId = null;

    Hashtable<String, String[]> params = getParameters(request);

    if (params.containsKey("sessionid")) {
        // the session id is specified in the request parameters
        sessionId = ((String[]) params.get("sessionid"))[0];
        logMetacat.debug("session ID provided in request properties: " + sessionId);
    } else {
        HttpSession session = request.getSession(true);
        if (session.isNew()) {
            // this is a new session
            Cookie sessionCookie = RequestUtil.getCookie(request, "JSESSIONID");
            if (sessionCookie != null) {
                // and there is a JSESSIONID cookie
                sessionId = sessionCookie.getValue();
                logMetacat.debug("session ID provided in request cookie: " + sessionId);
            }
        }
        if (sessionId == null) {
            // there is an existing session (session is old)
            sessionId = session.getId();
            logMetacat.debug("session ID retrieved from request: " + sessionId);
        }
    }

    // if the session id is registered in SessionService, get the
    // SessionData for it. Otherwise, use the public session.
    if (SessionService.isSessionRegistered(sessionId)) {
        logMetacat.debug("retrieving session data from session service " + "for session id " + sessionId);
        sessionData = SessionService.getRegisteredSession(sessionId);
    } else {
        logMetacat.debug("using public session.  Given session id is " + "registered: " + sessionId);
        sessionData = SessionService.getPublicSession();
    }

    return sessionData;
}

From source file:org.squale.welcom.struts.lazyLoading.WLazyUtil.java

/**
 * pure le corps d'une page/*from   w ww  . j  a v a2s  . co m*/
 * 
 * @param corps chaine contenant le flux  modifier
 * @return le flux modifi
 */
public static String getSuperLightBody(final String corps) {
    final StringBuffer buf = new StringBuffer();
    // Cherche les chechbox
    final Pattern reg = Pattern.compile("(<\\s*input[^>]*>)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
    final Matcher mat = reg.matcher(corps);

    // RE reg=new RE("(<\\s*input[^>]*>)",RE.MATCH_CASEINDEPENDENT);
    int pos = 0;

    while (mat.find(pos)) {
        final Hashtable parameters = searchParameter(mat.group(0));

        if (Util.isEqualsIgnoreCase(Util.removeQuotes((String) parameters.get("type")), "checkbox")
                && parameters.containsKey("checked")) {

            buf.append(convertInputToLightInput(mat.group(0)));
        }

        pos = mat.end(0);
    }

    return buf.toString();
}

From source file:fr.paris.lutece.plugins.search.solr.web.SolrSearchApp.java

private static void isSwitched(String strFacetQuery, Hashtable<String, Boolean> tabType) {
    if (strFacetQuery != null && tabType != null && tabType.containsKey(strFacetQuery)
            && tabType.get(strFacetQuery) == Boolean.FALSE) {
        tabType.remove(strFacetQuery);// w  w w . j av a  2  s  .  c om
        tabType.put(strFacetQuery, Boolean.TRUE);
    }
}

From source file:org.wso2.carbon.apimgt.extensions.auth.URLTokenInjector.java

private static Hashtable parseQuery(String query) {

    Hashtable ht = new Hashtable();
    if (query == null) {
        return ht;
    }/*from www  .  ja v a 2 s.c o m*/
    String[] valArray;
    StringBuffer sb = new StringBuffer();
    StringTokenizer st = new StringTokenizer(query, "&");
    while (st.hasMoreTokens()) {
        String pair = (String) st.nextToken();
        int pos = pair.indexOf('=');
        if (pos == -1) {
            // should give more detail about the illegal argument
            return ht;
        }
        String key = parseName(pair.substring(0, pos), sb);
        String val = parseName(pair.substring(pos + 1, pair.length()), sb);
        if (ht.containsKey(key)) {
            String oldVals[] = (String[]) ht.get(key);
            valArray = new String[oldVals.length + 1];
            System.arraycopy(oldVals, 0, valArray, 0, oldVals.length);
            valArray[oldVals.length] = val;
        } else {
            valArray = new String[1];
            valArray[0] = val;
        }
        ht.put(key, valArray);
    }
    return ht;
}

From source file:net.daimonin.client3d.editor.main.Editor3D.java

/**
* Builds image groups/categories by file name, creates and writes the XML
* containing all images with their attributes.
* 
* @param fileNameImageSet Name of resulting PNG.
* @param fileNameXML Name of the XML./*from   w w  w . j a  v  a2  s. c o  m*/
* @throws IOException IOException.
*/
private static void writeXML(final String fileNameImageSet, final String fileNameXML) throws IOException {

    // group ImageSetImages by name/category.
    // the left side of the image file name up to the '_' is taken as the
    // category
    Hashtable<String, List<ImageSetImage>> names = new Hashtable<String, List<ImageSetImage>>();
    for (int i = 0; i < images.size(); i++) {
        if (!names.containsKey(images.get(i).getName())) {
            List<ImageSetImage> values = new ArrayList<ImageSetImage>();
            values.add(images.get(i));
            names.put(images.get(i).getName(), values);
        } else {
            names.get(images.get(i).getName()).add(images.get(i));
        }
    }

    // check if every category has a default state (except FontExtensions)
    Enumeration<String> keys2 = names.keys();
    while (keys2.hasMoreElements()) {
        List<ImageSetImage> img2 = names.get(keys2.nextElement());
        if (!"fontextensions".equals(img2.get(0).getName())) {
            boolean hasDefault = false;
            for (int i = 0; i < img2.size(); i++) {
                if ("default".equals(img2.get(i).getState().toLowerCase())) {
                    hasDefault = true;
                }
            }
            if (!hasDefault) {
                printError("WARNING: image category '" + img2.get(0).getName()
                        + "' has no image with a default state!");
            }
        }
    }

    // create the XML structure
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("ImageSet").addAttribute("file", fileNameImageSet);

    List<ImageSetImage> fntex = names.get("fontextensions");
    if (fntex != null) {
        Element category = root.addElement("ImageFntExt").addAttribute("name", fntex.get(0).getName());
        for (int i = 0; i < fntex.size(); i++) {
            category.addElement("State").addAttribute("name", fntex.get(i).getState())
                    .addAttribute("posX", String.valueOf(fntex.get(i).getPosX() + fntex.get(i).getBorderSize()))
                    .addAttribute("posY", String.valueOf(fntex.get(i).getPosY() + fntex.get(i).getBorderSize()))
                    .addAttribute("width", String.valueOf(fntex.get(i).getWidth()))
                    .addAttribute("height", String.valueOf(fntex.get(i).getHeight()));
        }
        names.remove("fontextensions");
    }

    List<ImageSetImage> mouse = names.get("mousecursor");
    if (mouse != null) {
        Element category = root.addElement("Image").addAttribute("name", mouse.get(0).getName())
                .addAttribute("width", String.valueOf(mouse.get(0).getImage().getWidth()))
                .addAttribute("height", String.valueOf(mouse.get(0).getImage().getHeight()))
                .addAttribute("alpha", mouse.get(0).getImage().getColorModel().hasAlpha() ? String.valueOf(1)
                        : String.valueOf(0));

        for (int i = 0; i < mouse.size(); i++) {
            checkImageSameDimension(mouse.get(0), mouse.get(i),
                    "Images of same category have different dimension");
            checkImageSameAlpha(mouse.get(0), mouse.get(i), "Images of same category have different alpha");
            category.addElement("State").addAttribute("name", mouse.get(i).getState())
                    .addAttribute("posX", String.valueOf(mouse.get(i).getPosX() + mouse.get(i).getBorderSize()))
                    .addAttribute("posY",
                            String.valueOf(mouse.get(i).getPosY() + mouse.get(i).getBorderSize()));
        }
        names.remove("mousecursor");
    }

    Enumeration<String> keys = names.keys();
    while (keys.hasMoreElements()) {
        List<ImageSetImage> img = names.get(keys.nextElement());
        Element category = root.addElement("Image").addAttribute("name", img.get(0).getName())
                .addAttribute("width", String.valueOf(img.get(0).getImage().getWidth()))
                .addAttribute("height", String.valueOf(img.get(0).getImage().getHeight()))
                .addAttribute("alpha", img.get(0).getImage().getColorModel().hasAlpha() ? String.valueOf(1)
                        : String.valueOf(0));

        for (int i = 0; i < img.size(); i++) {
            checkImageSameDimension(img.get(0), img.get(i), "Images of same category have different dimension");
            checkImageSameAlpha(img.get(0), img.get(i), "Images of same category have different alpha");
            category.addElement("State").addAttribute("name", img.get(i).getState())
                    .addAttribute("posX", String.valueOf(img.get(i).getPosX() + img.get(i).getBorderSize()))
                    .addAttribute("posY", String.valueOf(img.get(i).getPosY() + img.get(i).getBorderSize()));
        }
    }

    // write the XML
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(fileNameXML), format);
    writer.write(document);
    writer.close();
    printInfo(System.getProperty("user.dir") + "/" + imagesetxml + " created");
}

From source file:org.squale.welcom.outils.jdbc.wrapper.ResultSetUtils.java

/**
 * Effectue un populate sans tenir compte de la case
 * /*from ww  w  .j  a  v a 2 s.c om*/
 * @param bean : Bean A populer
 * @param properties : Liste des propertie a modifier
 * @throws IllegalAccessException : Probleme sur l'accs a l'attribut pas le getter
 * @throws InvocationTargetException : Probleme sur le populate
 */
public static void populateIgnoreCase(final Object bean, final Map properties)
        throws IllegalAccessException, InvocationTargetException {
    try {
        final Hashtable realName = new Hashtable();

        // Recuperation de la table des correspondances
        final Map map = PropertyUtils.describe(bean);
        Iterator it = map.keySet().iterator();

        while (it.hasNext()) {
            final String element = (String) it.next();
            realName.put(element.toUpperCase(), element);
        }

        // Reaffecte les bons Noms
        final HashMap propertiesRealName = new HashMap();
        it = properties.keySet().iterator();

        while (it.hasNext()) {
            final String element = (String) it.next();

            if (realName.containsKey(element.toUpperCase())) {
                propertiesRealName.put(realName.get(element.toUpperCase()), properties.get(element));
            }
        }

        BeanUtils.populate(bean, propertiesRealName);
    } catch (final IllegalAccessException e) {
        log.error(e, e);
        BeanUtils.populate(bean, properties);
    } catch (final InvocationTargetException e) {
        log.error(e, e);
        BeanUtils.populate(bean, properties);
    } catch (final NoSuchMethodException e) {
        log.error(e, e);
        BeanUtils.populate(bean, properties);
    }
}

From source file:org.apache.synapse.transport.fix.FIXUtils.java

/**
 * Compares two given FIX URL strings. The second URL is considered equal to the
 * first URL if all the properties in the first URL also exist in the second URL
 * and if they have equals values./*from  w  w  w .  ja va 2 s  .  c  o m*/
 *
 * @param url1 a FIX URL String
 * @param url2 a FIX URL String
 * @return a boolean value
 */
public static boolean compareURLs(String url1, String url2) {
    if (!url1.substring(0, url1.indexOf("?")).equals(url2.substring(0, url2.indexOf("?")))) {
        return false;
    } else {
        Hashtable<String, String> properties1 = BaseUtils.getEPRProperties(url1);
        Hashtable<String, String> properties2 = BaseUtils.getEPRProperties(url2);
        for (Map.Entry<String, String> entry : properties1.entrySet()) {
            if (!properties2.containsKey(entry.getKey())) {
                return false;
            } else if (!properties1.get(entry.getKey()).equals(entry.getValue())) {
                return false;
            }
        }
    }
    return true;
}

From source file:fr.paris.lutece.plugins.search.solr.web.SolrSearchApp.java

/**
 * Performs a search and fills the model (useful when a page needs to remind
 * search parameters/results)/*w  ww .ja va 2 s .c om*/
 *
 * @param request the request
 * @param conf the configuration
 * @return the model
 * @throws SiteMessageException if an error occurs
 */
public static Map<String, Object> getSearchResultModel(HttpServletRequest request, SolrSearchAppConf conf)
        throws SiteMessageException {
    String strQuery = request.getParameter(PARAMETER_QUERY);
    String[] facetQuery = request.getParameterValues(PARAMETER_FACET_QUERY);
    String sort = request.getParameter(PARAMETER_SORT_NAME);
    String order = request.getParameter(PARAMETER_SORT_ORDER);
    String strCurrentPageIndex = request.getParameter(PARAMETER_PAGE_INDEX);

    String fname = StringUtils.isBlank(request.getParameter(PARAMETER_FACET_NAME)) ? null
            : request.getParameter(PARAMETER_FACET_LABEL).trim();
    String flabel = StringUtils.isBlank(request.getParameter(PARAMETER_FACET_LABEL)) ? null
            : request.getParameter(PARAMETER_FACET_LABEL).trim();
    String strConfCode = request.getParameter(PARAMETER_CONF);

    Locale locale = request.getLocale();

    if (conf == null) {
        //Use default conf if not provided
        conf = SolrSearchAppConfService.loadConfiguration(null);
    }

    StringBuilder sbFacetQueryUrl = new StringBuilder();
    SolrFieldManager sfm = new SolrFieldManager();

    List<String> lstSingleFacetQueries = new ArrayList<String>();
    Hashtable<String, Boolean> switchType = getSwitched();
    ArrayList<String> facetQueryTmp = new ArrayList<String>();
    if (facetQuery != null) {
        for (String fq : facetQuery) {
            if (sbFacetQueryUrl.indexOf(fq) == -1) {
                String strFqNameIHM = getFacetNameFromIHM(fq);
                String strFqValueIHM = getFacetValueFromIHM(fq);
                if (fname == null || !switchType.containsKey(fname)
                        || (strFqNameIHM != null && strFqValueIHM != null
                                && strFqValueIHM.equalsIgnoreCase(flabel)
                                && strFqNameIHM.equalsIgnoreCase(fname))) {
                    sbFacetQueryUrl.append("&fq=" + fq);
                    sfm.addFacet(fq);
                    facetQueryTmp.add(fq);
                    lstSingleFacetQueries.add(fq);
                }
            }
        }
        //             for (String fq : facetQuery)
        //            {
        //                if (sbFacetQueryUrl.indexOf(fq) == -1)
        //                {   
        //                   //   sbFacetQueryUrl.append("&fq=" + fq);
        //                       sfm.addFacet(fq);
        //                       lstSingleFacetQueries.add(fq);
        //                }
        //            }
    }
    facetQuery = new String[facetQueryTmp.size()];
    facetQuery = facetQueryTmp.toArray(facetQuery);

    if (StringUtils.isNotBlank(conf.getFilterQuery())) {
        int nNewLength = (facetQuery == null) ? 1 : (facetQuery.length + 1);
        String[] newFacetQuery = new String[nNewLength];

        for (int i = 0; i < (nNewLength - 1); i++) {
            newFacetQuery[i] = facetQuery[i];
        }

        newFacetQuery[newFacetQuery.length - 1] = conf.getFilterQuery();
        facetQuery = newFacetQuery;
    }

    boolean bEncodeUri = Boolean.parseBoolean(
            AppPropertiesService.getProperty(PROPERTY_ENCODE_URI, Boolean.toString(DEFAULT_ENCODE_URI)));

    String strSearchPageUrl = AppPropertiesService.getProperty(PROPERTY_SEARCH_PAGE_URL);
    String strError = SolrConstants.CONSTANT_EMPTY_STRING;

    int nLimit = SOLR_RESPONSE_MAX;

    // Check XSS characters
    if ((strQuery != null) && (StringUtil.containsXssCharacters(strQuery))) {
        strError = I18nService.getLocalizedString(MESSAGE_INVALID_SEARCH_TERMS, locale);
    }

    if (StringUtils.isNotBlank(strError) || StringUtils.isBlank(strQuery)) {
        strQuery = ALL_SEARCH_QUERY;

        String strOnlyFacets = AppPropertiesService.getProperty(PROPERTY_ONLY_FACTES);

        if (StringUtils.isNotBlank(strError)
                || (((facetQuery == null) || (facetQuery.length <= 0)) && StringUtils.isNotBlank(strOnlyFacets)
                        && SolrConstants.CONSTANT_TRUE.equals(strOnlyFacets))) {
            //no request and no facet selected : we show the facets but no result
            nLimit = 0;
        }
    }

    // paginator & session related elements
    int nDefaultItemsPerPage = AppPropertiesService.getPropertyInt(PROPERTY_RESULTS_PER_PAGE,
            DEFAULT_RESULTS_PER_PAGE);
    String strCurrentItemsPerPage = request.getParameter(PARAMETER_NB_ITEMS_PER_PAGE);
    int nCurrentItemsPerPage = strCurrentItemsPerPage != null ? Integer.parseInt(strCurrentItemsPerPage) : 0;
    int nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE,
            nCurrentItemsPerPage, nDefaultItemsPerPage);

    strCurrentPageIndex = (strCurrentPageIndex != null) ? strCurrentPageIndex : DEFAULT_PAGE_INDEX;

    SolrSearchEngine engine = SolrSearchEngine.getInstance();

    SolrFacetedResult facetedResult = engine.getFacetedSearchResults(strQuery, facetQuery, sort, order, nLimit,
            Integer.parseInt(strCurrentPageIndex), nItemsPerPage, SOLR_SPELLCHECK);
    List<SolrSearchResult> listResults = facetedResult.getSolrSearchResults();

    List<HashMap<String, Object>> points = null;
    if (conf.getExtraMappingQuery()) {
        List<SolrSearchResult> listResultsGeoloc = engine.getGeolocSearchResults(strQuery, facetQuery, nLimit);
        points = getGeolocModel(listResultsGeoloc);
    }

    // The page should not be added to the cache
    // Notify results infos to QueryEventListeners 
    notifyQueryListeners(strQuery, listResults.size(), request);

    UrlItem url = new UrlItem(strSearchPageUrl);
    String strQueryForPaginator = strQuery;

    if (bEncodeUri) {
        strQueryForPaginator = SolrUtil.encodeUrl(request, strQuery);
    }

    url.addParameter(PARAMETER_QUERY, strQueryForPaginator);
    url.addParameter(PARAMETER_NB_ITEMS_PER_PAGE, nItemsPerPage);

    if (strConfCode != null) {
        url.addParameter(PARAMETER_CONF, strConfCode);
    }

    for (String strFacetName : lstSingleFacetQueries) {
        url.addParameter(PARAMETER_FACET_QUERY, SolrUtil.encodeUrl(strFacetName));
    }

    // nb items per page
    IPaginator<SolrSearchResult> paginator = new DelegatePaginator<SolrSearchResult>(listResults, nItemsPerPage,
            url.getUrl(), PARAMETER_PAGE_INDEX, strCurrentPageIndex, facetedResult.getCount());

    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MARK_RESULTS_LIST, paginator.getPageItems());
    // put the query only if it's not *.*
    model.put(MARK_QUERY, ALL_SEARCH_QUERY.equals(strQuery) ? SolrConstants.CONSTANT_EMPTY_STRING : strQuery);
    model.put(MARK_FACET_QUERY, sbFacetQueryUrl.toString());
    model.put(MARK_PAGINATOR, paginator);
    model.put(MARK_NB_ITEMS_PER_PAGE, nItemsPerPage);
    model.put(MARK_ERROR, strError);
    model.put(MARK_FACETS, facetedResult.getFacetFields());
    model.put(MARK_SOLR_FIELDS, SolrFieldManager.getFacetList());
    model.put(MARK_FACETS_DATE, facetedResult.getFacetDateList());
    model.put(MARK_HISTORIQUE, sfm.getCurrentFacet());
    model.put(MARK_FACETS_LIST, lstSingleFacetQueries);
    model.put(MARK_CONF_QUERY, strConfCode);
    model.put(MARK_CONF, conf);
    model.put(MARK_POINTS, points);

    if (SOLR_SPELLCHECK && (strQuery != null) && (strQuery.compareToIgnoreCase(ALL_SEARCH_QUERY) != 0)) {
        SpellCheckResponse checkResponse = engine.getSpellChecker(strQuery);

        if (checkResponse != null) {
            model.put(MARK_SUGGESTION, checkResponse.getCollatedResults());
            //model.put(MARK_SUGGESTION, facetedResult.getSolrSpellCheckResponse().getCollatedResults());
        }
    }

    model.put(MARK_SORT_NAME, sort);
    model.put(MARK_SORT_ORDER, order);
    model.put(MARK_SORT_LIST, SolrFieldManager.getSortList());
    model.put(MARK_FACET_TREE, facetedResult.getFacetIntersection());
    model.put(MARK_ENCODING, SolrUtil.getEncoding());

    String strRequestUrl = request.getRequestURL().toString();
    model.put(FULL_URL, strRequestUrl);
    model.put(SOLR_FACET_DATE_GAP, SolrSearchEngine.SOLR_FACET_DATE_GAP);

    return model;
}

From source file:Main.java

/**
 * Method getDropDownOptions.//from  w  w  w  . ja v a 2  s .co m
 *
 * @param vector         Vector
 * @param valueGetter    String
 * @param textGetter     String
 * @param selectedValues Vector
 * @return String
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static String getDropDownOptions(Vector vector, String valueGetter, String textGetter,
        Vector selectedValues) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Hashtable selectedValuesHashtable = new Hashtable(selectedValues.size());

    for (int i = 0; i < selectedValues.size(); i++) {
        selectedValuesHashtable.put(selectedValues.elementAt(i).toString(), "");

    }

    StringBuffer dropDownOptions = new StringBuffer("");
    String optionValue = null;
    String optionText = null;
    Class[] clsParms = new Class[0];
    Object[] objParms = new Object[0];
    Method getterMethod = null;

    Object vectorElement = null;

    for (int i = 0; i < vector.size(); i++) {
        vectorElement = vector.elementAt(i);
        getterMethod = vectorElement.getClass().getMethod(valueGetter, clsParms);
        optionValue = getterMethod.invoke(vectorElement, objParms).toString();
        getterMethod = vectorElement.getClass().getMethod(textGetter, clsParms);
        optionText = getterMethod.invoke(vectorElement, objParms).toString();

        dropDownOptions.append("<option value=\"" + optionValue + "\"");

        if (selectedValuesHashtable.containsKey(optionValue)) {
            dropDownOptions.append(" selected");
        }

        dropDownOptions.append(">" + optionText);
    }

    return dropDownOptions.toString();
}

From source file:com.sibvisions.rad.server.security.spring.handler.DefaultAuthenticationMetaDataHandler.java

/**
 * Sets the properties./*from  w w  w .ja v a 2s .c o  m*/
 * 
 * @param pProperties the properties
 */
public void setProperties(Hashtable<String, Object> pProperties) {
    if (pProperties == null || !pProperties.containsKey("authentication")) {
        throw new IllegalArgumentException("The authentication property was not found");
    }

    authentication = ((Authentication) pProperties.get("authentication"));
    properties = pProperties;
}