List of usage examples for java.util Hashtable get
@SuppressWarnings("unchecked") public synchronized V get(Object key)
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 ww w . j ava 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:com.kevinquan.google.activityrecoginition.model.MotionHelper.java
public static List<MotionSnapshot> parseMotionSnapshots(Cursor result, final boolean sortDescending) { if (!CursorUtils.hasResults(result)) { Log.d(TAG, "No results were provided to parse motion snapshots from"); return new ArrayList<MotionSnapshot>(); }/* w w w . j a va 2 s .c o m*/ Hashtable<Long, MotionSnapshot> snapshots = new Hashtable<Long, MotionSnapshot>(); do { Motion thisMotion = new Motion(result); if (thisMotion.getTimestamp() == 0) { Log.w(TAG, "Current motion seems corrupt: " + thisMotion); continue; } if (!snapshots.containsKey(thisMotion.getTimestamp())) { MotionSnapshot snapshot = new MotionSnapshot(thisMotion); snapshots.put(snapshot.getTimestamp(), snapshot); } else { if (!snapshots.get(thisMotion.getTimestamp()).addMotion(thisMotion)) { Log.w(TAG, "Could not add motion to snapshot: " + thisMotion.toString()); } } } while (result.moveToNext()); List<MotionSnapshot> results = new ArrayList<MotionSnapshot>(); results.addAll(snapshots.values()); Collections.sort(results, new Comparator<MotionSnapshot>() { @Override public int compare(MotionSnapshot lhs, MotionSnapshot rhs) { int result = ((Long) lhs.getTimestamp()).compareTo((Long) rhs.getTimestamp()); return sortDescending ? -1 * result : result; } }); return results; }
From source file:io.card.development.recording.Recording.java
public static Recording[] parseRecordings(InputStream recordingStream) throws IOException, JSONException { Hashtable<String, byte[]> recordingFiles = unzipFiles(recordingStream); Hashtable<String, byte[]> manifestFiles = findManifestFiles(recordingFiles); int recordingIndex = 0; Recording[] recordings = new Recording[manifestFiles.size()]; Enumeration<String> manifestFilenames = manifestFiles.keys(); while (manifestFilenames.hasMoreElements()) { String manifestFilename = manifestFilenames.nextElement(); String manifestDirName = manifestFilename.substring(0, manifestFilename.lastIndexOf("/")); byte[] manifestData = manifestFiles.get(manifestFilename); ManifestEntry[] manifestEntries = buildManifest(manifestDirName, manifestData, recordingFiles); recordings[recordingIndex] = new Recording(manifestEntries); recordingIndex++;/*from ww w . j a v a 2s .c om*/ } return recordings; }
From source file:com.softlayer.objectstorage.Client.java
/** * Utility for adding form params to a restlet representation * /* w w w . ja v a 2 s.com*/ * @param params * Hashtable of params to be converted to form params * @return the restlet Representation with the form added */ private static Representation getRepresentation(Hashtable<String, String> params) { // Gathering informations into a Web form. Form form = new Form(); Enumeration<String> en = params.keys(); while (en.hasMoreElements()) { String key = en.nextElement(); String value = params.get(key); form.add(key, value); } return form.getWebRepresentation(); }
From source file:gdt.data.grain.Support.java
/** * Get value from the hash table by key string * @param keyName key string//from w w w .j a v a 2 s . c om * @param tab hash table. * @return found value or null. */ public static Object getValue(String keyName, Hashtable<String, ?> tab) { if (keyName == null) return null; if (tab == null) return null; Enumeration<String> en = tab.keys(); String curKey = null; while (en.hasMoreElements()) { curKey = (String) en.nextElement(); if (keyName.compareTo(curKey) == 0) return tab.get(curKey); } return null; }
From source file:com.googlecode.flyway.ant.MigrateTask.java
/** * Adds the additional placeholders contained in these properties to the existing list. * * @param placeholders The existing list of placeholders. * @param properties The properties containing additional placeholders. *//*w w w. j ava 2 s . c o m*/ private static void addPlaceholdersFromProperties(Map<String, String> placeholders, Hashtable properties) { for (Object property : properties.keySet()) { String propertyName = (String) property; if (propertyName.startsWith(PLACEHOLDERS_PROPERTY_PREFIX) && propertyName.length() > PLACEHOLDERS_PROPERTY_PREFIX.length()) { String placeholderName = propertyName.substring(PLACEHOLDERS_PROPERTY_PREFIX.length()); String placeholderValue = (String) properties.get(propertyName); placeholders.put(placeholderName, placeholderValue); } } }
From source file:edu.ku.brc.specify.tasks.SecurityAdminTask.java
/** * Enables the User to change password./*from ww w.j a v a 2 s. c o m*/ */ public static void changePassword(final boolean isStartingEmpty) { final ViewBasedDisplayDialog dlg = new ViewBasedDisplayDialog((Frame) UIRegistry.getTopWindow(), "SystemSetup", "ChangePassword", null, getResourceString(getKey("CHG_PWD_TITLE")), "OK", null, null, true, MultiView.HIDE_SAVE_BTN | MultiView.DONT_ADD_ALL_ALTVIEWS | MultiView.USE_ONLY_CREATION_MODE | MultiView.IS_EDITTING); dlg.setWhichBtns(CustomDialog.OK_BTN | CustomDialog.CANCEL_BTN); dlg.setFormAdjuster(new FormPane.FormPaneAdjusterIFace() { @Override public void adjustForm(final FormViewObj fvo) { final ValPasswordField oldPwdVTF = fvo.getCompById("1"); final ValPasswordField newPwdVTF = fvo.getCompById("2"); final ValPasswordField verPwdVTF = fvo.getCompById("3"); final PasswordStrengthUI pwdStrenthUI = fvo.getCompById("4"); if (isStartingEmpty && pwdStrenthUI != null) { pwdStrenthUI.setDoPainting(true); } Institution institution = AppContextMgr.getInstance().getClassObject(Institution.class); int minPwdLen = (int) institution.getMinimumPwdLength(); newPwdVTF.setMinLen(minPwdLen); verPwdVTF.setMinLen(minPwdLen); pwdStrenthUI.setMinPwdLen(minPwdLen); DocumentAdaptor da = new DocumentAdaptor() { @Override protected void changed(final DocumentEvent e) { super.changed(e); // Need to invoke later so the da gets to set the enabled state last. SwingUtilities.invokeLater(new Runnable() { @Override public void run() { String pwdStr = new String(newPwdVTF.getPassword()); String verStr = new String(verPwdVTF.getPassword()); boolean pwdOK = pwdStrenthUI.checkStrength(pwdStr) && pwdStr.equals(verStr) && newPwdVTF.getState() == UIValidatable.ErrorType.Valid; dlg.getOkBtn().setEnabled(pwdOK); pwdStrenthUI.repaint(); } }); } }; oldPwdVTF.getDocument().addDocumentListener(da); verPwdVTF.getDocument().addDocumentListener(da); newPwdVTF.getDocument().addDocumentListener(da); } }); Hashtable<String, String> valuesHash = new Hashtable<String, String>(); dlg.setData(valuesHash); UIHelper.centerAndShow(dlg); if (!dlg.isCancelled()) { int pwdLen = 6; String oldPwd = valuesHash.get("OldPwd"); String newPwd1 = valuesHash.get("NewPwd1"); String newPwd2 = valuesHash.get("NewPwd2"); if (newPwd1.equals(newPwd2)) { if (newPwd1.length() >= pwdLen) { SpecifyUser spUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); //String username = spUser.getName(); String spuOldPwd = spUser.getPassword(); String newEncryptedPwd = null; String oldDecryptedPwd = Encryption.decrypt(spuOldPwd, oldPwd); if (oldDecryptedPwd != null && oldDecryptedPwd.equals(oldPwd)) { newEncryptedPwd = Encryption.encrypt(newPwd2, newPwd2); spUser.setPassword(newEncryptedPwd); if (!DataModelObjBase.save(spUser)) { UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString(getKey("PWD_ERR_SAVE")), Color.RED); } } else { UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString(getKey("PWD_ERR_BAD")), Color.RED); } if (newEncryptedPwd != null) { Pair<String, String> masterPwd = UserAndMasterPasswordMgr.getInstance() .getUserNamePasswordForDB(); String encryptedMasterUP = UserAndMasterPasswordMgr.encrypt(masterPwd.first, masterPwd.second, newPwd2); if (StringUtils.isNotEmpty(encryptedMasterUP)) { AppPreferences.getLocalPrefs().put( UserAndMasterPasswordMgr.getInstance().getMasterPrefPath(true), encryptedMasterUP); UIHelper.setTextToClipboard(encryptedMasterUP); UIRegistry.showLocalizedMsg(JOptionPane.INFORMATION_MESSAGE, "INFORMATION", "SPUSR_NEWPWD"); } else { UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString(getKey("PWD_ERR_RTRV")), Color.RED); } } else { UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString(getKey("PWD_ERR_BAD")), Color.RED); } } else { UIRegistry.writeTimedSimpleGlassPaneMsg(getFormattedResStr(getKey("PWD_ERR_LEN"), pwdLen), Color.RED); } } else { UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString(getKey("PWD_ERR_NOTSAME")), Color.RED); } } }
From source file:ext.tmt.utils.LWCUtil.java
/** * ?Key,Value?/*from w w w. j a va 2s.c o m*/ * @param key IBA * @param value IBA * @param type * @return */ public static List<Persistable> getObjectByIBA(Map<String, String> ibaValues, String type) { Debug.P("---getObjectByIBA: ibaValues:" + ibaValues); List<Persistable> result = null; String sql = null; if (ibaValues != null && ibaValues.size() > 0) { StringBuffer bf = new StringBuffer(); List<String> paramList = new ArrayList<String>(); bf.append("and ("); //IBA? for (Iterator<?> ite = ibaValues.keySet().iterator(); ite.hasNext();) { String key = (String) ite.next(); bf.append("d1.name=?"); paramList.add(key); String value = ibaValues.get(key); if (StringUtils.isEmpty(value)) { bf.append("and ").append("v1.value is Null"); } else { bf.append("and ").append("v1.value=?"); paramList.add(value); } } bf.append(")"); //IBA? String queryIBACond = bf.toString(); Debug.P("--->>Query IBA Param:" + queryIBACond); if ("wt.part.WTPart".contains(type)) {// sql = "select M1.NAME,M1.WTPARTNUMBER as OBJECTNUMBER FROM STRINGVALUE v1 ,STRINGDEFINITION d1,WTPART p1,WTPARTMASTER m1 where D1.IDA2A2=v1.ida3a6 and v1.IDA3A4=p1.IDA2A2 and p1.IDA3MASTERREFERENCE=M1.IDA2A2 and d1.name=? and v1.value=?"; } else if ("wt.epm.EPMDocument".contains(type)) { sql = "select M1.NAME,M1.DOCUMENTNUMBER as OBJECTNUMBER FROM STRINGVALUE v1 ,STRINGDEFINITION d1,EPMDOCUMENT e1,EPMDOCUMENTMASTER m1 where D1.IDA2A2=v1.ida3a6 and v1.IDA3A4=e1.IDA2A2 and e1.IDA3MASTERREFERENCE=M1.IDA2A2 and d1.name=? and v1.value=? "; } else if ("wt.doc.WTDocument".contains(type)) { sql = "select M1.NAME,M1.WTDOCUMENTNUMBER as OBJECTNUMBER FROM STRINGVALUE v1 ,STRINGDEFINITION d1,WTDOCUMENT t1,WTDOCUMENTMASTER m1 where D1.IDA2A2=v1.ida3a6 and v1.IDA3A4=t1.IDA2A2 and t1.IDA3MASTERREFERENCE=M1.IDA2A2 and d1.name=? and v1.value=?"; } String[] params = new String[paramList.size()]; params = paramList.toArray(params); Debug.P("---->>>SQL:" + sql); Debug.P("------>>>>SQL param:" + paramList); try { List<Hashtable<String, String>> datas = UserDefQueryUtil.commonQuery(sql, params); if (datas != null && datas.size() > 0) { Debug.P("---->>getObjectIBA Size:" + datas.size()); result = new ArrayList<Persistable>(); for (int i = 0; i < datas.size(); i++) { Hashtable<String, String> data_rows = datas.get(i); for (Iterator<?> ite = data_rows.keySet().iterator(); ite.hasNext();) { String keyStr = (String) ite.next(); if (keyStr.equalsIgnoreCase("OBJECTNUMBER")) { String valueStr = data_rows.get("OBJECTNUMBER"); Persistable object = GenericUtil.getObjectByNumber(valueStr); result.add(object); } } } } } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } return result; }
From source file:io.card.development.recording.ManifestEntry.java
public static ManifestEntry[] getManifest(Hashtable<String, byte[]> recordingData) { Enumeration<String> keys = recordingData.keys(); String manifestKey = null;//from www . jav a 2 s . c o m while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.endsWith("manifest.json")) { manifestKey = key; break; } } if (manifestKey == null) { return null; } String manifestDirName = manifestKey.substring(0, manifestKey.lastIndexOf("/")); String manifestString = new String(recordingData.get(manifestKey)); JSONArray manifestData; try { manifestData = new JSONArray(manifestString); } catch (JSONException e1) { Log.e(TAG, "Exception parsing JSON array: " + e1.getMessage()); return null; } ManifestEntry[] manifest = new ManifestEntry[manifestData.length()]; for (int i = 0; i < manifestData.length(); i++) { try { JSONObject jo = manifestData.getJSONObject(i); manifest[i] = new ManifestEntry(manifestDirName, jo, recordingData); } catch (JSONException e) { Log.e(TAG, "Couldn't parse JSON: " + e.getMessage()); } } return manifest; }
From source file:edu.ku.brc.dbsupport.DatabaseDriverInfo.java
/** * Reads the Form Registry. The forms are loaded when needed and onlu one ViewSet can be the "core" ViewSet which is where most of the forms * reside. This could also be thought of as the "default" set of forms. * @return the list of info objects// w ww.j a va2 s. co m */ protected static Vector<DatabaseDriverInfo> loadDatabaseDriverInfo() { Vector<DatabaseDriverInfo> dbDrivers = new Vector<DatabaseDriverInfo>(); try { Element root = XMLHelper .readFileToDOM4J(new FileInputStream(XMLHelper.getConfigDirPath("dbdrivers.xml"))); //$NON-NLS-1$ if (root != null) { Hashtable<String, String> hash = new Hashtable<String, String>(); for (Iterator<?> i = root.elementIterator("db"); i.hasNext();) //$NON-NLS-1$ { Element dbElement = (Element) i.next(); String name = getAttr(dbElement, "name", null); //$NON-NLS-1$ if (hash.get(name) == null) { hash.put(name, name); String driver = getAttr(dbElement, "driver", null); //$NON-NLS-1$ String dialect = getAttr(dbElement, "dialect", null); //$NON-NLS-1$ String port = getAttr(dbElement, "port", null); //$NON-NLS-1$ boolean isEmbedded = getAttr(dbElement, "embedded", false); //$NON-NLS-1$ if (UIRegistry.isEmbedded() || UIRegistry.isMobile()) // Application is Embedded { if (!isEmbedded) { continue; } } else if (isEmbedded) { continue; } // these can go away once we validate the XML if (StringUtils.isEmpty(driver)) { throw new RuntimeException("Driver cannot be null!"); //$NON-NLS-1$ } if (StringUtils.isEmpty(driver)) { throw new RuntimeException("Dialect cannot be null!"); //$NON-NLS-1$ } DatabaseDriverInfo drv = new DatabaseDriverInfo(name, driver, dialect, isEmbedded, port); // Load up the Connection Types for (Iterator<?> connIter = dbElement.elementIterator("connection"); connIter.hasNext();) //$NON-NLS-1$ { Element connElement = (Element) connIter.next(); String typeStr = getAttr(connElement, "type", null); //$NON-NLS-1$ String connFormat = connElement.getTextTrim(); ConnectionType type = ConnectionType.valueOf(StringUtils.capitalize(typeStr)); drv.addFormat(type, connFormat); } /*if (drv.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, " ", " ", " ", " ", " ") == null) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ { log.error("Meg might've screwed up generating connection strings, contact her if you get this error"); //$NON-NLS-1$ throw new RuntimeException("Dialect ["+name+"] has no 'Open' connection type!"); //$NON-NLS-1$ //$NON-NLS-2$ }*/ dbDrivers.add(drv); } else { log.error("Database Driver Name[" + name + "] is in use."); //$NON-NLS-1$ //$NON-NLS-2$ } } } else { String msg = "The root element for the document was null!"; //$NON-NLS-1$ log.error(msg); throw new ConfigurationException(msg); } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatabaseDriverInfo.class, ex); ex.printStackTrace(); log.error(ex); } Collections.sort(dbDrivers); return dbDrivers; }