Example usage for java.util Hashtable get

List of usage examples for java.util Hashtable get

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public synchronized V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.macrosoft.core.orm.hibernate.SimpleHibernateDao.java

/**
 * //  w w w .  j  av  a 2s.  c om
 * @param query
 * @param values
 * @return
 */
private Query setParamHash(Query query, Hashtable<String, ?> values) {
    if (values != null) {
        //query.setProperties(values);
        Enumeration parameterNames = values.keys();
        while (parameterNames.hasMoreElements() == true) {
            String pName = (String) parameterNames.nextElement();
            Object param = values.get(pName);
            if (param instanceof String) {
                String paramValue = (String) param;
                query.setString(pName, paramValue);
            } else {
                if (param instanceof Integer) {
                    Integer paramValue = (Integer) param;
                    query.setInteger(pName, paramValue.intValue());
                } else {
                    if (param instanceof Double) {
                        Double paramValue = (Double) param;
                        query.setDouble(pName, paramValue.doubleValue());
                    }
                }

            }

        }

    }
    return query;
}

From source file:de.berlios.gpon.wui.actions.data.ItemSearchAction.java

private void addAssociatedProperties(List idMapped, HashMap associatedPropertyMap) {

    // build up a pathDigest -> ipd-List mapping
    final Hashtable pathAndProperties = new Hashtable();

    CollectionUtils.forAllDo(associatedPropertyMap.keySet(), new Closure() {
        // foreach key in associatedPropertyMap do:
        public void execute(Object o) {
            String key = (String) o;

            String[] keySplit = ItemSearchForm.splitAssociatedPropertyKey(key);

            String pathDigest = keySplit[0];
            String ipdId = keySplit[1];

            if (!pathAndProperties.containsKey(pathDigest)) {
                pathAndProperties.put(pathDigest, new ArrayList());
            }/*from  ww  w. ja  v  a  2s .  com*/

            ((List) pathAndProperties.get(pathDigest)).add(new Long(ipdId));
        }
    });

    final String[] digests = (String[]) Collections.list(pathAndProperties.keys()).toArray(new String[0]);

    final PathResolver pathResolver = (PathResolver) getObjectForBeanId("pathResolver");

    CollectionUtils.forAllDo(idMapped, new Closure() {

        public void execute(Object o) {

            ItemMap im = (ItemMap) o;

            // foreach digest

            for (int digIdx = 0; digIdx < digests.length; digIdx++) {
                String digest = digests[digIdx];

                Set items = pathResolver.getItemsForPath(im.getItem().getId(), digest);

                if (items != null && items.size() > 0) {
                    if (items.size() > 1) {
                        throw new RuntimeException("more than one associated item found");
                    }

                    // get one & only item
                    Item item = ((Item[]) items.toArray(new Item[0]))[0];

                    Long[] ipds = (Long[]) ((List) pathAndProperties.get(digest)).toArray(new Long[0]);

                    ItemMappedById associatedImbi = new ItemMappedById(item);

                    for (int ipdIdx = 0; ipdIdx < ipds.length; ipdIdx++) {
                        Value value = associatedImbi.getValueObject(ipds[ipdIdx] + "");

                        if (value != null) {
                            im.addAdditionalAttribute(digest + "|" + ipds[ipdIdx], value);
                        }
                    }
                }
            }

        }
    });
}

From source file:fr.paris.lutece.plugins.search.solr.business.SolrSearchEngine.java

/**
 * Get a matrice from all the fields with their values
  * @param myValues//from w w  w  . j a  va2  s  . com
  * @return
  */
private Hashtable<Field, List<String>> getFieldArrange(String myValues[],
        Hashtable<Field, List<String>> myTab) {
    Hashtable<Field, List<String>> lstReturn = myTab;
    Field tmpField = getField(lstReturn, myValues[0]);
    if (tmpField != null) {
        boolean bAddField = true;
        List<String> getValuesFromFrield = lstReturn.get(tmpField);
        for (String strField : getValuesFromFrield)
            if (strField.equalsIgnoreCase(myValues[1]))
                bAddField = false;
        if (bAddField) {
            getValuesFromFrield.add(myValues[1]);
            lstReturn.put(tmpField, getValuesFromFrield);
        }
    }
    return lstReturn;
}

From source file:fi.hip.sicx.store.HIPStoreClient.java

@Override
public boolean storeFile(String localInputFilename, String fileInTheCloud, StorageClientObserver sco) {

    HttpURLConnection conn = null;
    boolean ret = false;
    String boundary = Long.toHexString(System.currentTimeMillis());
    String crlf = "\r\n";
    try {//from   w  ww . j a  v  a  2s  .  c  o m
        // create the preamble to the file stream (incl. the other parameters ..)
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(bos, "UTF-8"));

        Hashtable<String, String> params = new Hashtable<String, String>();
        params.put("permissions", "");
        params.put("path", fileInTheCloud); // this could be set in the filename

        for (Enumeration<String> e = params.keys(); e.hasMoreElements();) {
            String k = (String) e.nextElement();
            String v = params.get(k);
            writer.print("--" + boundary + crlf);
            writer.print("Content-Disposition: form-data; name=\"" + k + "\"" + crlf);
            writer.print("Content-Type: text/plain; charset=UTF-8" + crlf + crlf);
            writer.print(v + crlf);
        }

        writer.print("--" + boundary + crlf);
        writer.print(
                "Content-Disposition: form-data; name=\"data\"; filename=\"" + fileInTheCloud + "\"" + crlf);
        writer.print("Content-Type: application/octet-stream" + crlf + crlf);
        writer.close();
        byte[] preamble = bos.toByteArray();

        bos = new ByteArrayOutputStream();
        writer = new PrintWriter(new OutputStreamWriter(bos, "UTF-8"));
        writer.print(crlf + "--" + boundary + "--" + crlf);
        writer.close();
        byte[] postamble = bos.toByteArray();

        File f = new File(localInputFilename);
        long total = preamble.length + f.length() + postamble.length;
        long sent = 0;

        // do a multipart post
        conn = getConnection("/store/store");
        conn.setDoOutput(true); // do POST
        conn.setFixedLengthStreamingMode((int) total);
        conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);

        OutputStream out = conn.getOutputStream();
        FileInputStream fis = new FileInputStream(f);
        byte[] buf = new byte[1024 * 64];
        int r = 0;

        /* note: we need to bundle the first bytes from the file with the preamble,
           becase the apache commons fileupload used on the other side is buggy. */
        while ((r = fis.read(buf)) > 0) {
            if (preamble != null) {
                byte[] tmp = new byte[preamble.length + r];
                System.arraycopy(preamble, 0, tmp, 0, preamble.length);
                System.arraycopy(buf, 0, tmp, preamble.length, r);

                r = preamble.length + r;
                out.write(tmp, 0, r);
                preamble = null;
            } else {
                out.write(buf, 0, r);
            }
            sent += r;
            sco.progressMade((int) ((sent * 100) / total));
        }

        fis.close();

        out.write(postamble);
        sent += postamble.length;
        sco.progressMade((int) ((sent * 100) / total));
        out.flush();

        ret = true;
    } catch (Exception ex) {
        System.out.println("Error connecting, " + ex);
        ex.printStackTrace();
        failed = true;
    }
    closeConnection(conn);
    return ret;
}

From source file:com.icesoft.faces.webapp.parser.ComponentRuleSet.java

/**
 * Adds rules for each tag in the map.//w w  w.j  a  v  a 2 s.  c  om
 *
 * @param digester The digester to which rules are added.
 */
public void addRuleInstances(Digester digester) {

    Hashtable table = map.getTagToComponentMap();
    Enumeration keys = table.keys();
    TagRule tagRule = new TagRule();
    XhtmlTagRule xhtmlTagRule = new XhtmlTagRule();
    ViewTagRule viewTagRule = new ViewTagRule();

    digester.setRuleNamespaceURI(ruleNamespace);

    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String tagType = (String) table.get(key);

        if (!key.equals("view")) {

            // Want to create tag object regardless of type;
            digester.addObjectCreate(TAG_NEST + key, tagType);

            if (tagType.equals(XhtmlTag.class.getName())) {
                // Rules for Xhtml Tags;
                digester.addObjectCreate(TAG_NEST + key, "com.icesoft.faces.webapp.parser.TagWire");
                digester.addRule(TAG_NEST + key, xhtmlTagRule);
            } else {
                // Rules for JSF Tags;
                try {
                    digester.addRule(TAG_NEST + key, (Rule) setPropertiesRuleClass.newInstance());
                } catch (Exception e) {
                    if (log.isDebugEnabled()) {
                        log.debug(e.getMessage(), e);
                    }
                }
                digester.addObjectCreate(TAG_NEST + key, "com.icesoft.faces.webapp.parser.TagWire");
                digester.addRule(TAG_NEST + key, tagRule);
            }
        } else {

            // #2551 we do want to create the tag and wire for the viewTag
            digester.addObjectCreate(TAG_NEST + key, tagType);
            try {
                digester.addRule(TAG_NEST + key, (Rule) setPropertiesRuleClass.newInstance());
            } catch (Exception e) {
                if (log.isDebugEnabled()) {
                    log.debug(e.getMessage(), e);
                }
            }
            digester.addObjectCreate(TAG_NEST + key, "com.icesoft.faces.webapp.parser.TagWire");
            digester.addRule(TAG_NEST + key, viewTagRule);

            // Capture the view tag class;
            ((JsfJspDigester) digester).setViewTagClassName(tagType);
            viewTagClass = tagType;
        }
    }
}

From source file:hu.sztaki.lpds.pgportal.portlets.workflow.WorkflowUploadPortlet.java

@Override
public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    try {//from   w w  w .  j av  a2 s . c  om
        PortletSession ps = request.getPortletSession();
        Hashtable<String, ProgressListener> tmp = (Hashtable<String, ProgressListener>) ps
                .getAttribute("uploads", ps.APPLICATION_SCOPE);
        Enumeration<String> enm = tmp.keys();
        String key;
        FileUploadProgressListener lisener;//=(FileUploadProgressListener)((PortletFileUpload)ps.getAttribute("upload",ps.APPLICATION_SCOPE)).getProgressListener();
        while (enm.hasMoreElements()) {
            key = enm.nextElement();
            response.getWriter().write(key + "</br>");
            lisener = (FileUploadProgressListener) tmp.get(key);
            response.getWriter().write(lisener.getFileuploadstatus() + "%");

        }
        //            response.getWriter().write(lisener.getFileuploadstatus());
    } catch (Exception e) {
        response.getWriter().write("N/A");
    }

}

From source file:gov.loc.www.zing.srw.srw_bindings.SRWSoapBindingImpl.java

public ScanResponseType scanOperation(ScanRequestType request) throws java.rmi.RemoteException {
    log.debug("Enter: scanOperation");
    if (log.isInfoEnabled()) {
        log.info("request: maximumTerms:" + request.getMaximumTerms() + " scanClause:" + request.getScanClause()
                + " stylesheet:" + request.getStylesheet() + " responsePosition:"
                + request.getResponsePosition() + " version:" + request.getVersion());
    }//from   w  w  w.  jav  a 2  s  . c om
    MessageContext msgContext = MessageContext.getCurrentContext();
    ScanResponseType response;
    String dbname = (String) msgContext.getProperty("dbname");
    SRWDatabase db = (SRWDatabase) msgContext.getProperty("db");
    if (log.isDebugEnabled())
        log.debug("db=" + db);
    if (request.getScanClause() == null) {
        response = new ScanResponseType();
        db.diagnostic(SRWDiagnostic.MandatoryParameterNotSupplied, "scanClause", response);
    } else if (request.getResponsePosition() != null
            && request.getResponsePosition().intValue() == Integer.MAX_VALUE) {
        response = new ScanResponseType();
        db.diagnostic(SRWDiagnostic.UnsupportedParameterValue, "responsePosition", response);
    } else if (request.getMaximumTerms() != null && request.getMaximumTerms().intValue() == Integer.MAX_VALUE) {
        response = new ScanResponseType();
        db.diagnostic(SRWDiagnostic.UnsupportedParameterValue, "maximumTerms", response);
    } else
        try {
            response = db.doRequest(request);

            // set extraResponseData
            StringBuffer extraResponseData = new StringBuffer();

            // we're going to stick the database name in extraResponseData every time
            if (db.databaseTitle != null)
                extraResponseData.append("<databaseTitle>").append(db.databaseTitle).append("</databaseTitle>");
            else
                extraResponseData.append("<databaseTitle>").append(dbname).append("</databaseTitle>");

            Hashtable extraRequestDataElements = SRWDatabase.parseElements(request.getExtraRequestData());
            String s = (String) extraRequestDataElements.get("returnTargetURL");
            log.info("returnTargetURL=" + s);
            if (s != null && !s.equals("false")) {
                String targetStr = (String) msgContext.getProperty("targetURL");
                log.info("targetStr=" + targetStr);
                if (targetStr != null && targetStr.length() > 0) {
                    URL target = new URL(targetStr);
                    extraResponseData.append("<targetURL>").append("<host>").append(target.getHost())
                            .append("</host>").append("<port>").append(target.getPort()).append("</port>")
                            .append("<path>").append(target.getPath()).append("</path>").append("<query>")
                            .append(Utilities.xmlEncode(target.getQuery())).append("</query>")
                            .append("</targetURL>");
                }
            }

            // set extraResponseData
            SRWDatabase.setExtraResponseData(response, extraResponseData.toString());
        } catch (Exception e) {
            log.error(e, e);
            throw new RemoteException(e.getMessage(), e);
        } finally {
            SRWDatabase.putDb(dbname, db);
        }
    if (response != null) {
        log.info("calling setEchoedScanRequestType");
        setEchoedScanRequestType(request, response);
        log.info("called setEchoedScanRequestType");
        response.setVersion("1.1");
    }
    log.debug("Exit: scanOperation");
    return response;
}

From source file:jeeves.resources.dbms.Dbms.java

private Element buildElement(ResultSet rs, int col, String name, int type, Hashtable<String, String> formats)
        throws SQLException {
    String value = null;//from w w w . j a v  a  2s .  c om

    switch (type) {
    case Types.DATE:
        Date date = rs.getDate(col + 1);
        if (date == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_DATE_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(date);
        }
        break;

    case Types.TIME:
        Time time = rs.getTime(col + 1);
        if (time == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_TIME_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(time);
        }
        break;

    case Types.TIMESTAMP:
        Timestamp timestamp = rs.getTimestamp(col + 1);
        if (timestamp == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_TIMESTAMP_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(timestamp);
        }
        break;

    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
        long l = rs.getLong(col + 1);
        if (rs.wasNull())
            value = null;
        else {
            String format = formats.get(name);
            if (format == null)
                value = l + "";
            else {
                DecimalFormat df = new DecimalFormat(format);
                value = df.format(l);
            }
        }
        break;

    case Types.DECIMAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
    case Types.NUMERIC:
        double n = rs.getDouble(col + 1);

        if (rs.wasNull())
            value = null;
        else {
            String format = formats.get(name);

            if (format == null) {
                value = n + "";

                // --- this fix is mandatory for oracle
                // --- that shit returns integers like xxx.0

                if (value.endsWith(".0"))
                    value = value.substring(0, value.length() - 2);
            } else {
                DecimalFormat df = new DecimalFormat(format);
                value = df.format(n);
            }
        }
        break;

    default:
        value = rs.getString(col + 1);
        if (value != null) {
            value = stripIllegalChars(value);
        }

        break;
    }
    return new Element(name).setText(value);
}

From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java

/**
 * Gets an instance of {@code com.fasterxml.jackson.databind.MappingJsonFactory} based on the resource configuration
 * in the application server. The parameter {@code environment} contains MappingJsonFactory configuration properties,
 * and accepts the following properties:
 * <ul>/* ww w.j  a va 2 s .  com*/
 * <li>jsonFactoryFeatures: JsonFactory features as defined in com.fasterxml.jackson.core.JsonFactory.Feature
 * <li>mapperFeatures: ObjectMapper features as defined in com.fasterxml.jackson.databind.MapperFeature
 * <li>deserializationFeatures:
 * <li>serializationFeatures:
 * <li>customDeserializers:
 * <li>customSerializers:
 * <li>deserializationProblemHandlers:
 * <li>customDataTypeModules:
 * <li>inputDecorator: fully-qualified name of a class that extends {@code com.fasterxml.jackson.core.io.InputDecorator}
 * <li>outputDecorator: fully-qualified name of a class that extends {@code com.fasterxml.jackson.core.io.OutputDecorator}
 * </ul>
 *
 * @param obj         the JNDI name of {@code com.fasterxml.jackson.databind.MappingJsonFactory} resource
 * @param name        always null
 * @param nameCtx     always null
 * @param environment a {@code Hashtable} of configuration properties
 * @return an instance of {@code com.fasterxml.jackson.databind.MappingJsonFactory}
 * @throws Exception any exception occurred
 */
@Override
public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx,
        final Hashtable<?, ?> environment) throws Exception {
    MappingJsonFactory jsonFactory = jsonFactoryCached;
    if (jsonFactory == null) {
        synchronized (this) {
            jsonFactory = jsonFactoryCached;
            if (jsonFactory == null) {
                jsonFactoryCached = jsonFactory = new MappingJsonFactory();
            }

            final ClassLoader classLoader = MappingJsonFactoryObjectFactory.class.getClassLoader();
            final ObjectMapper objectMapper = jsonFactory.getCodec();

            final Object jsonFactoryFeatures = environment.get("jsonFactoryFeatures");
            if (jsonFactoryFeatures != null) {
                NoMappingJsonFactoryObjectFactory.configureJsonFactoryFeatures(jsonFactory,
                        (String) jsonFactoryFeatures);
            }

            final Object mapperFeatures = environment.get("mapperFeatures");
            if (mapperFeatures != null) {
                configureMapperFeatures(objectMapper, (String) mapperFeatures);
            }

            final Object deserializationFeatures = environment.get("deserializationFeatures");
            if (deserializationFeatures != null) {
                configureDeserializationFeatures(objectMapper, (String) deserializationFeatures);
            }

            final Object serializationFeatures = environment.get("serializationFeatures");
            if (serializationFeatures != null) {
                configureSerializationFeatures(objectMapper, (String) serializationFeatures);
            }

            final Object deserializationProblemHandlers = environment.get("deserializationProblemHandlers");
            if (deserializationProblemHandlers != null) {
                configureDeserializationProblemHandlers(objectMapper, (String) deserializationProblemHandlers,
                        classLoader);
            }

            configureCustomSerializersAndDeserializers(objectMapper,
                    (String) environment.get("customSerializers"),
                    (String) environment.get("customDeserializers"),
                    (String) environment.get("customDataTypeModules"), classLoader);
            NoMappingJsonFactoryObjectFactory.configureInputDecoratorAndOutputDecorator(jsonFactory,
                    environment);
        }
    }
    return jsonFactory;
}

From source file:edu.harvard.i2b2.analysis.security.HighEncryption.java

public HighEncryption(String inFileName, Hashtable keys) throws Exception {
    String key = null;// w  w w.java  2 s  .  co  m
    //   makearray64(); // create the array regardless of how key will be acquired AHA@20011016
    if ((keys != null) && (keys.size() > 0))
        key = keys.get(inFileName).toString();

    if ((key == null) || (key.length() == 0)) {
        byte baBuffer[] = new byte[2056];
        try {
            FileInputStream oFileIn = new FileInputStream(inFileName);
            //int iBytes = oFileIn.read(baBuffer,0,2056);
            String sString = new String(baBuffer);
            //new String(baBuffer,0,0,iBytes);
            key = sString;
        } catch (FileNotFoundException fnfe) {
            log.fatal("HighEncryption initialization file-not-found error");
            throw new Exception("HighEncryption initialization error");
        } catch (Exception e) {
            log.fatal("HighEncryption initialization error");
            throw new Exception("HighEncryption initialization error");
        }
    }

    try {
        key = key.trim();
        cipher = new RijndaelAlgorithm(key, 128); //, "AES");  //long version for dates
    } catch (Exception ex) {
        //Lib.TError("HighEncryption initialization error");
        ex.printStackTrace();
        throw new Exception("HighEncryption initialization error");
    }
}