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.eurac.commul.pepperModules.mmax2.MMAX22SaltMapper.java

private int[] getStartAndEnd(String BaseDataUnitId, Hashtable<String, int[]> indicesTokens) {
    if ((indicesTokens.containsKey(BaseDataUnitId)) && (indicesTokens.containsKey(BaseDataUnitId))) {
        Integer start = indicesTokens.get(BaseDataUnitId)[0];
        Integer end = indicesTokens.get(BaseDataUnitId)[1];
        int[] result = { start, end };
        return (result);
    } else {/*from w  w  w . j ava 2 s .com*/
        if (!indicesTokens.containsKey(BaseDataUnitId))
            throw new PepperModuleDataException(this,
                    "An error in data was found: Cannot find start offset of base data unit '" + BaseDataUnitId
                            + "'.");
        if (!indicesTokens.containsKey(BaseDataUnitId))
            throw new PepperModuleDataException(this,
                    "An error in data was found: Cannot find end offset of base data unit '" + BaseDataUnitId
                            + "'.");
        return (null);
    }
}

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

/**
 * Method transfer EcoGridService(base on endpoint) vector to SearchScope
 * (base on namespace) vector//from ww w  .j av  a 2  s. c o  m
 * 
 * @return vector - may be empty.
 */
private Vector transformEcoGridServiceToSearchScope() {
    Vector searchScopeVector = new Vector();

    int size = searchServicesVector.size();
    // this hashtable will stored the namespace and its searchscope
    Hashtable namespaceAndSearhScopeMap = new Hashtable();
    for (int i = 0; i < size; i++) {
        SelectableEcoGridService service = (SelectableEcoGridService) searchServicesVector.elementAt(i);
        if (service == null) {
            continue;
        }
        String endPoint = service.getEndPoint();
        if (endPoint == null || endPoint.trim().equals("")) {
            continue;
        }
        DocumentType[] typeList = service.getSelectedDocumentTypeList();
        if (typeList == null) {
            continue;
        }
        // go through every type
        for (int j = 0; j < typeList.length; j++) {
            DocumentType type = typeList[j];
            String namespaceStr = type.getNamespace();
            String metadataClassName = type.getMetadataSpecificationClassName();
            if (namespaceStr != null && !namespaceStr.trim().equals("") && metadataClassName != null
                    && !metadataClassName.trim().equals("")) {
                if (!namespaceAndSearhScopeMap.containsKey(namespaceStr)) {
                    // if this is first namespace we found, create a new
                    // searchscope
                    Vector endPointsVector = new Vector();
                    endPointsVector.add(endPoint);
                    try {
                        SearchScope newScope = new SearchScope(namespaceStr, metadataClassName,
                                endPointsVector);
                        namespaceAndSearhScopeMap.put(namespaceStr, newScope);
                        log.debug("add " + namespaceStr + " " + metadataClassName + " " + endPoint
                                + " into SearchScope");
                    } catch (Exception e) {
                        log.debug("error create search scope ", e);
                        continue;
                    }
                } else {
                    // if we already has a SearchScope for this namespace,
                    // add this endpoints to endpoints vector
                    SearchScope existedScope = (SearchScope) namespaceAndSearhScopeMap.get(namespaceStr);
                    log.debug("Add endpoint " + endPoint + " to a existed searchscope object");
                    existedScope.addSearchEndPoint(endPoint);
                    // overwrite the old value
                    namespaceAndSearhScopeMap.put(namespaceStr, existedScope);
                }
            } // if
        } // for
    } // for

    // transfer the hashtable to a vector
    Enumeration en = namespaceAndSearhScopeMap.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        SearchScope scope = (SearchScope) namespaceAndSearhScopeMap.get(key);
        if (scope != null) {
            searchScopeVector.add(scope);
        }
    }

    return searchScopeVector;
}

From source file:org.hdiv.filter.ValidatorHelperRequest.java

/**
 * Checks if repeated values have been received for the parameter <code>parameter</code>.
 * /*from  w  ww  . j a  va 2 s. c  o  m*/
 * @param target
 *            Part of the url that represents the target action
 * @param parameter
 *            parameter name
 * @param values
 *            Parameter <code>parameter</code> values
 * @param stateValues
 *            real values for <code>parameter</code>
 * @return True If repeated values have been received for the parameter <code>parameter</code>.
 */
private ValidatorHelperResult hasConfidentialIncorrectValues(String target, String parameter, String[] values,
        List stateValues) {

    Hashtable receivedValues = new Hashtable();

    for (int i = 0; i < values.length; i++) {

        if (this.hdivConfig.isParameterWithoutConfidentiality(parameter)) {
            return ValidatorHelperResult.VALID;
        }

        if (!this.isInRange(target, parameter, values[i], stateValues)) {
            return new ValidatorHelperResult(HDIVErrorCodes.CONFIDENTIAL_VALUE_INCORRECT);
        }

        if (receivedValues.containsKey(values[i])) {
            this.logger.log(HDIVErrorCodes.REPEATED_VALUES, target, parameter, values[i]);
            return new ValidatorHelperResult(HDIVErrorCodes.REPEATED_VALUES);
        }

        receivedValues.put(values[i], values[i]);
    }
    return ValidatorHelperResult.VALID;
}

From source file:com.stimulus.archiva.extraction.MessageExtraction.java

protected String extractMessage(Email message) throws MessageExtractionException {

    if (message == null)
        throw new MessageExtractionException("assertion failure: null message", logger);

    logger.debug("extracted message {" + message + "}");

    Hashtable<String, Part> att = new Hashtable<String, Part>();
    Hashtable<String, String> inl = new Hashtable<String, String>();
    Hashtable<String, String> imgs = new Hashtable<String, String>();
    Hashtable<String, String> nonImgs = new Hashtable<String, String>();
    Hashtable<String, String> ready = new Hashtable<String, String>();
    ArrayList<String> mimeTypes = new ArrayList<String>();
    String viewFileName;/*  w ww  . j a v a2s .  com*/
    try {
        dumpPart(message, att, inl, imgs, nonImgs, mimeTypes, message.getSubject());
        for (String attachFileName : att.keySet()) {
            Part p = (Part) att.get(attachFileName);
            writeAttachment(p, attachFileName);
            ready.put(attachFileName, attachFileName);
            //if (!imgs.containsKey(attachFileName) && !nonImgs.containsKey(attachFileName))
            addAttachment(attachFileName, p);
        }

        if (inl.containsKey("text/html")) {
            viewFileName = prepareHTMLMessage(baseURL, inl, imgs, nonImgs, ready, mimeTypes);
        } else if (inl.containsKey("text/plain")) {
            viewFileName = preparePlaintextMessage(inl, imgs, nonImgs, ready, mimeTypes);
        } else {
            logger.debug(
                    "unable to extract message since the content type is unsupported. returning empty message body.");
            return writeTempMessage("<html><head><META http-equiv=Content-Type content=\"text/html; charset="
                    + serverEncoding + "\"></head><body></body></html>", ".html");
        }
    } catch (Exception ex) {
        throw new MessageExtractionException(ex.getMessage(), ex, logger);
    }
    logger.debug("message successfully extracted {filename='" + fileName + "' " + message + "}");
    return viewFileName;
}

From source file:org.ecoinformatics.seek.datasource.eml.eml2.EML2MetadataSpecification.java

/**
 * This method will transfer ResultsetType java object to array of
 * ResultRecord java object. The ResultRecord object can be shown in kepler.
 * If the results is null or there is no record in the result, null will be
 * return/*  www  .java2 s.c  o  m*/
 * 
 * @param ResultsetType
 *            results the result need to be transform
 * @param String
 *            endpoints the search end point
 * @return ResultRecord[] the resultrecord need be returned.
 */
public ResultRecord[] transformResultset(ResultsetType results, String endpoint, CompositeEntity container)
        throws SAXException, IOException, EcoGridException, NameDuplicationException, IllegalActionException {
    Eml200DataSource[] resultRecordArray = null;
    if (results == null) {
        return resultRecordArray;
    }

    // get titlstring and entity name string from configure file
    String titleReturnFieldString = null;
    String entityReturnFieldString = null;
    // xpath for config file
    String titlePath = "//" + ECOGRIDPATH + "/" + RETURNFIELDTYPELIST + "/" + RETURNFIELD + "[@" + NAMESPACE
            + "='" + namespace + "' and @" + RETURNFIELDTYPE + "='" + RETURNFIELDTITLE + "']";

    String entityPath = "//" + ECOGRIDPATH + "/" + RETURNFIELDTYPELIST + "/" + RETURNFIELD + "[@" + NAMESPACE
            + "='" + namespace + "' and @" + RETURNFIELDTYPE + "='" + RETURNFIELDENTITY + "']";

    List titlePathList = null;
    List entityPathList = null;

    //get the specific configuration we want
    ConfigurationProperty ecogridProperty = ConfigurationManager.getInstance()
            .getProperty(ConfigurationManager.getModule("ecogrid"));
    ConfigurationProperty returnFieldTypeList = ecogridProperty.getProperty("returnFieldTypeList");
    //findthe namespace properties
    List returnFieldTypeNamespaceList = returnFieldTypeList.findProperties(NAMESPACE, namespace, true);
    //find the properties out of the correct namespace properties that also have the correct returnfieldtype
    titlePathList = ConfigurationProperty.findProperties(returnFieldTypeNamespaceList, RETURNFIELDTYPE,
            RETURNFIELDTITLE, false);
    //get the value list for the properties
    titlePathList = ConfigurationProperty.getValueList(titlePathList, "value", true);

    if (titlePathList.isEmpty()) {
        log.debug("Couldn't get title from config Eml200EcoGridQueryTransfer.transformResultset");
        throw new EcoGridException("Couldn't get title returnfield from config");
    }

    entityPathList = ConfigurationProperty.findProperties(returnFieldTypeNamespaceList, RETURNFIELDTYPE,
            RETURNFIELDENTITY, false);
    //get the value list for the properties
    entityPathList = ConfigurationProperty.getValueList(entityPathList, "value", true);

    if (entityPathList.isEmpty()) {
        log.debug("Couldn't get entity returnfield from config Eml200EcoGridQueryTransfer.transformResultset");
        throw new EcoGridException("Couldn't get entity returnfield from config");
    }
    // only choose the first one in vector as title returnfied or
    // entityreturn
    // field
    titleReturnFieldString = (String) titlePathList.get(0);
    entityReturnFieldString = (String) entityPathList.get(0);

    // transfer ResultType to a vector of eml2resultsetItem and
    // sorted the vector
    Vector resultsetItemList = transformResultsetType(results, titleReturnFieldString, entityReturnFieldString);
    // transfer the sored vector (contains eml2resultsetitem object to an
    // array
    // of ResultRecord
    int arraySize = resultsetItemList.size();
    _numResults = arraySize;

    resultRecordArray = new Eml200DataSource[arraySize];
    Hashtable titleList = new Hashtable();// This hashtable is for keeping
    // track
    // if there is a duplicate title

    KeplerLSID EML200ActorLSID = null;
    for (int i = 0; i < arraySize; i++) {
        try {
            SortableResultRecord source = (SortableResultRecord) resultsetItemList.elementAt(i);
            String title = source.getTitle();
            log.debug("The title is " + title);
            String id = source.getId();
            log.debug("The id is " + id);
            Vector entityList = source.getEntityList();
            // if couldn't find id, skip this record
            if (id == null || id.trim().equals("")) {
                continue;
            }

            // if couldn't find title, assign a one to it -- <j>
            if (title == null || title.trim().equals("")) {
                title = "<" + i + ">";
            }
            if (titleList.containsKey(title)) {
                title = title + " " + i;
            }
            //make it unique in the result tree
            if (container.getEntity(title) != null) {
                String hint = "another service";
                if (endpoint.lastIndexOf("/") > -1) {
                    hint = endpoint.substring(endpoint.lastIndexOf("/") + 1);
                }
                title = title + " (" + hint + ")";
            }
            titleList.put(title, title);
            Eml200DataSource newRecord = new Eml200DataSource(container, title);
            newRecord.setRecordId(id);
            newRecord.setEndpoint(endpoint);
            newRecord.setNamespace(namespace);
            for (int j = 0; j < entityList.size(); j++) {
                String entityNameString = (String) entityList.elementAt(j);
                log.debug("The entiy name will be " + entityNameString);
                newRecord.addRecordDetail(entityNameString);

            }
            Eml200DataSource.generateDocumentationForInstance(newRecord);

            // look up EML200DataSource class LSID and create and add
            // NamedObjID attribute to instance
            if (EML200ActorLSID == null) {
                KARCacheManager kcm = KARCacheManager.getInstance();
                Vector<KARCacheContent> list = kcm.getKARCacheContents();
                for (KARCacheContent content : list) {
                    if (content.getCacheContent().getClassName().equals(Eml200DataSource.class.getName())) {
                        EML200ActorLSID = content.getLsid();
                    }
                }
            }
            NamedObjId lsidSA = new NamedObjId(newRecord, NamedObjId.NAME);
            lsidSA.setExpression(EML200ActorLSID);

            resultRecordArray[i] = newRecord;
        } catch (Exception e) {
            continue;
        }
    } // for
    return resultRecordArray;
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
 * Remove series from the list where the names are the same, but one entry has a null or empty position.
 * eg. the followig list should be processed as indicated:
 * /*w  w  w .  j  av a 2s.com*/
 * fred(5)
 * fred <-- delete
 * bill <-- delete
 * bill <-- delete
 * bill(1)
 * 
 * @param list
 */
public static boolean pruneSeriesList(ArrayList<Series> list) {
    ArrayList<Series> toDelete = new ArrayList<Series>();
    Hashtable<String, Series> index = new Hashtable<String, Series>();

    for (Series s : list) {
        final boolean emptyNum = s.num == null || s.num.trim().equals("");
        final String lcName = s.name.trim().toLowerCase();
        final boolean inNames = index.containsKey(lcName);
        if (!inNames) {
            // Just add and continue
            index.put(lcName, s);
        } else {
            // See if we can purge either
            if (emptyNum) {
                // Always delete series with empty numbers if an equally or more specific one exists
                toDelete.add(s);
            } else {
                // See if the one in 'index' also has a num
                Series orig = index.get(lcName);
                if (orig.num == null || orig.num.trim().equals("")) {
                    // Replace with this one, and mark orig for delete
                    index.put(lcName, s);
                    toDelete.add(orig);
                } else {
                    // Both have numbers. See if they are the same.
                    if (s.num.trim().toLowerCase().equals(orig.num.trim().toLowerCase())) {
                        // Same exact series, delete this one
                        toDelete.add(s);
                    } else {
                        // Nothing to do: this is a different series position                     
                    }
                }
            }
        }
    }

    for (Series s : toDelete)
        list.remove(s);

    return (toDelete.size() > 0);

}

From source file:org.hdiv.filter.AbstractValidatorHelper.java

/**
 * Checks if the cookies received in the request are correct. For that, it
 * checks if they are in the user session.
 * /* w  ww .  ja  v  a2s. c  o  m*/
 * @param request HttpServletRequest to validate
 * @param target Part of the url that represents the target action
 * @return True if all the cookies received in the request are correct. They
 *         must have been previously stored in the user session by HDIV to
 *         be correct. False otherwise.
 * @since HDIV 1.1
 */
public boolean validateRequestCookies(HttpServletRequest request, String target) {

    Cookie[] requestCookies = request.getCookies();

    if ((requestCookies == null) || (requestCookies.length == 0)) {
        return true;
    }

    Hashtable sessionCookies = (Hashtable) request.getSession().getAttribute(Constants.HDIV_COOKIES_KEY);

    if (sessionCookies == null) {
        return true;
    }

    boolean cookiesConfidentiality = Boolean.TRUE.equals(this.hdivConfig.getConfidentiality())
            && this.hdivConfig.isCookiesConfidentialityActivated();

    for (int i = 0; i < requestCookies.length; i++) {

        boolean found = false;
        if (requestCookies[i].getName().equals(Constants.JSESSIONID)) {
            continue;
        }

        if (sessionCookies.containsKey(requestCookies[i].getName())) {

            SavedCookie savedCookie = (SavedCookie) sessionCookies.get(requestCookies[i].getName());
            if (savedCookie.equals(requestCookies[i], cookiesConfidentiality)) {

                found = true;
                if (cookiesConfidentiality) {
                    if (savedCookie.getValue() != null) {
                        requestCookies[i].setValue(savedCookie.getValue());
                    }
                }
            }
        }

        if (!found) {
            this.logger.log(HDIVErrorCodes.COOKIE_INCORRECT, target, "cookie:" + requestCookies[i].getName(),
                    requestCookies[i].getValue());
            return false;
        }
    }
    return true;
}

From source file:org.hdiv.filter.ValidatorHelperRequest.java

/**
 * Checks if repeated or no valid values have been received for the parameter <code>parameter</code>.
 * //from w w  w .j  a  v a2  s . co m
 * @param target
 *            Part of the url that represents the target action
 * @param parameter
 *            parameter name
 * @param values
 *            Parameter <code>parameter</code> values
 * @param tempStateValues
 *            values stored in state for <code>parameter</code>
 * @return True If repeated or no valid values have been received for the parameter <code>parameter</code>.
 */
private ValidatorHelperResult hasNonConfidentialIncorrectValues(String target, String parameter,
        String[] values, List tempStateValues) {

    Hashtable receivedValues = new Hashtable();

    for (int i = 0; i < values.length; i++) {

        boolean exists = false;
        for (int j = 0; j < tempStateValues.size() && !exists; j++) {

            String tempValue = (String) tempStateValues.get(j);

            if (tempValue.equalsIgnoreCase(values[i])) {
                tempStateValues.remove(j);
                exists = true;
            }
        }

        if (!exists) {

            if (receivedValues.containsKey(values[i])) {
                this.logger.log(HDIVErrorCodes.REPEATED_VALUES, target, parameter, values[i]);
                return new ValidatorHelperResult(HDIVErrorCodes.REPEATED_VALUES);
            }
            this.logger.log(HDIVErrorCodes.PARAMETER_VALUE_INCORRECT, target, parameter, values[i]);
            return new ValidatorHelperResult(HDIVErrorCodes.PARAMETER_VALUE_INCORRECT);
        }

        receivedValues.put(values[i], values[i]);
    }
    return ValidatorHelperResult.VALID;
}

From source file:at.ac.tuwien.auto.iotsys.gateway.connectors.knx.KNXDeviceLoaderETSImpl.java

private void parseGroupAddressConfig(HierarchicalConfiguration groupConfig,
        Hashtable<String, String> groupAddressByDatapointId) {
    // if there are no group elements return
    for (int groupsIdx = 0; groupsIdx < sizeOfConfiguration(
            groupConfig.getProperty("group.[@id]")); groupsIdx++) {
        String groupAddress = groupConfig.getString("group(" + groupsIdx + ").[@address]");

        // find instance elements for this group
        HierarchicalConfiguration concreteGroup = groupConfig.configurationAt("group(" + groupsIdx + ")");

        for (int instanceIdx = 0; instanceIdx < sizeOfConfiguration(
                concreteGroup.getProperty("instance.[@id]")); instanceIdx++) {
            String instanceId = concreteGroup.getString("instance(" + instanceIdx + ").[@id]");
            log.info("Mapping instanceID: " + instanceId + " to " + groupAddress);

            if (!groupAddressByDatapointId.containsKey(instanceId))
                groupAddressByDatapointId.put(instanceId, groupAddress);
        }/*from w  w w . ja va2  s. c o  m*/

        // recursively perform this method for nested groups
        parseGroupAddressConfig(concreteGroup, groupAddressByDatapointId);
    }
}

From source file:net.sourceforge.dvb.projectx.common.Common.java

/**
 *
 *//*  w w w . j  av  a2 s  . c  o m*/
public static Hashtable getUserColourTable(String model) throws IOException {
    Hashtable user_table = new Hashtable();

    URL url = Resource.getResourceURL(COLOUR_TABLES_FILENAME);

    if (url == null)
        return user_table;

    BufferedReader table = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;
    boolean table_match = false;

    while ((line = table.readLine()) != null) {
        if (line.trim().length() == 0)
            continue;

        if (line.startsWith("table"))
            table_match = line.substring(line.indexOf("=") + 1).trim().equals(model);

        else if (table_match) {
            if (line.startsWith("model"))
                user_table.put("model", line.substring(line.indexOf("=") + 1).trim());

            else
                user_table.put(line.substring(0, line.indexOf("=")).trim(),
                        line.substring(line.indexOf("=") + 1).trim());
        }
    }

    table.close();

    if (!user_table.isEmpty() && !user_table.containsKey("model"))
        user_table.put("model", "16");

    return user_table;
}