List of usage examples for java.util Hashtable get
@SuppressWarnings("unchecked") public synchronized V get(Object key)
From source file:edu.harvard.i2b2.frclient.security.HighEncryption.java
public HighEncryption(String inFileName, Hashtable keys) throws Exception { String key = null;/* w ww.j a v a 2 s . c o 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"); } }
From source file:com.macrosoft.core.orm.hibernate.SimpleHibernateDao.java
/** * ?HQL?Query./* w ww. java 2 s . c om*/ * * ?find()T,?T. * * @param values ????,?. */ public Query createQuery(final String queryString, final Object... values) { Assert.hasText(queryString, "queryString?"); Query query = getSession().createQuery(queryString); if (values != null && values.length > 0) { if (values[0] instanceof Hashtable) { Hashtable temp = (Hashtable) values[0]; query = setParamHash(query, temp); } else { if (values[0] instanceof List) { List temp = (List) values[0]; int size = temp.size(); for (int i = 0; i < size; i++) { Object param = temp.get(i); //query.setParameter(i,values[i]); if (param instanceof String) { String paramValue = (String) param; query.setString(i, paramValue); } else { if (param instanceof Integer) { Integer paramValue = (Integer) param; query.setInteger(i, paramValue.intValue()); } else { if (param instanceof Long) { Long paramValue = (Long) param; query.setLong(i, paramValue.longValue()); } else { if (param instanceof Double) { Double paramValue = (Double) param; query.setDouble(i, paramValue.doubleValue()); } else { if (param instanceof Float) { Float paramValue = (Float) param; query.setFloat(i, paramValue.floatValue()); } } } } } } } else { for (int i = 0; i < values.length; i++) { query.setParameter(i, values[i]); } } } } return query; }
From source file:com.stimulus.archiva.extraction.MessageExtraction.java
private String prepareHTMLMessage(String baseURL, Hashtable<String, String> inl, Hashtable<String, String> imgs, Hashtable<String, String> nonImgs, Hashtable<String, String> ready, ArrayList<String> mimeTypes) { String str = (String) inl.get("text/html"); boolean alternative = false; for (int i = 0; i < mimeTypes.size(); i++) { if (((String) mimeTypes.get(i)).toLowerCase(Locale.ENGLISH).indexOf("multipart/alternative") > -1) { alternative = true;//from ww w .j av a2 s . co m break; } } if (!alternative && inl.containsKey("text/plain")) { String plain = activateURLs((String) inl.get("text/plain")).replaceAll("\r", "").replaceAll("\n", "<br>" + System.getProperty("line.separator")) + "<br><br>" + System.getProperty("line.separator") + "<hr><br>"; int bestStart = 0; int next = str.toLowerCase(Locale.ENGLISH).indexOf("<body"); if (next > 0) next = str.indexOf(">", next) + 1; if (next > 0 && next < str.length()) bestStart = next; if (bestStart > 0) str = str.substring(0, bestStart) + plain + str.substring(bestStart); else str = plain + str; } HashSet<String> alreadyUsed = new HashSet<String>(); Enumeration enuma = imgs.keys(); while (enuma.hasMoreElements()) { String repl = (String) enuma.nextElement(); String cidTag = (String) imgs.get(repl); if (cidTag.startsWith("<") && cidTag.endsWith(">")) { cidTag = cidTag.substring(1, cidTag.length() - 1); } if (str.indexOf("cid:" + cidTag) > -1) { alreadyUsed.add(repl); } String st = (String) ready.get(repl); str = Pattern.compile("cid:" + cidTag, Pattern.CASE_INSENSITIVE).matcher(str) .replaceAll(ready.get(repl)); } enuma = nonImgs.keys(); while (enuma.hasMoreElements()) { String repl = (String) enuma.nextElement(); String cidTag = (String) nonImgs.get(repl); if (cidTag.startsWith("<") && cidTag.endsWith(">")) cidTag = cidTag.substring(1, cidTag.length() - 1); if (str.indexOf("cid:" + cidTag) > -1) alreadyUsed.add(repl); String st = (String) ready.get(repl); str = Pattern.compile("cid:" + cidTag, Pattern.CASE_INSENSITIVE).matcher(str) .replaceAll(ready.get(repl)); } StringBuffer buff = new StringBuffer(); enuma = imgs.keys(); while (enuma.hasMoreElements()) { String fl = (String) enuma.nextElement(); if (!alreadyUsed.contains(fl)) { fl = (String) ready.get(fl); if (fl.endsWith(".tif") || fl.endsWith(".tiff")) { buff.append(System.getProperty("line.separator") + "<BR><BR><EMBED SRC=\"" + baseURL.replaceAll("\\\\", "/") + "/temp/" + fl + "\" TYPE=\"image/tiff\">"); } else { buff.append(System.getProperty("line.separator") + "<BR><BR><IMG SRC=\"" + baseURL.replaceAll("\\\\", "/") + "/temp/" + fl + "\">"); } } } String output = ""; int bestStart = 0; int next = str.toLowerCase(Locale.ENGLISH).indexOf("</body>"); if (next > 0 && next < str.length()) bestStart = next; if (bestStart > 0) output = str.substring(0, bestStart) + buff.toString() + str.substring(bestStart); else output = str + buff.toString(); if (output.indexOf("charset=") < 0) { next = output.toLowerCase(Locale.ENGLISH).indexOf("</head>"); if (next > 0) output = output.substring(0, next) + "<META http-equiv=Content-Type content=\"text/html; charset=" + serverEncoding + "\">" + output.substring(next); } else output = output.replaceFirst("charset=.*\"", "charset=" + serverEncoding + "\""); output = output.replaceAll("FONT SIZE=\\d", "FONT"); output = output.replaceAll("font size=\\d", "font"); return writeTempMessage(output, ".html"); }
From source file:edu.harvard.i2b2.im.util.HighEncryption.java
public HighEncryption(String inFileName, Hashtable keys) throws Exception { String key = null;/*ww w . j a v a 2 s . c om*/ // 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"); } }
From source file:com.web.messaging.MessagingClassConstruct.java
/** * This method parses the messagingclass.xml which is obtained after deploying the War file and metadata is constructed and kept in HashMap * @param messagedigester// ww w.j av a 2 s.c o m * @param configFile * @param customClassLoader * @param messagingClassMap * @throws ClassNotFoundException * @throws FileNotFoundException * @throws IOException * @throws SAXException */ public void getMessagingClass(Digester messagedigester, File configFile, WebClassLoader customClassLoader, Hashtable messagingClassMap) throws ClassNotFoundException, FileNotFoundException, IOException, SAXException { MessagingClasses messagingClasses = (MessagingClasses) messagedigester .parse(new InputSource(new FileInputStream(configFile))); for (MessagingClass messagingclass : messagingClasses.messagingClasses) { Class messagingClass = customClassLoader.loadClass(messagingclass.getMessagingclass()); messagingclass.setMessageClass(messagingClass); if (messagingclass.getMessagetype().equals("RandomQueue")) { ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue"); //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()); if (randomqueuemap == null) { System.out.print("No RandomQueue Available"); } else { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { queueclassList.add(messagingclass); } else { System.out.print("No RandomQueue Available"); } } } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) { ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap.get("RoundRobinQueue"); if (roundrobinqueuemap == null) { System.out.print("No RoundRobinQueue Available"); } else { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { queueclassList.add(messagingclass); } else { System.out.print("No RoundRobinQueue Available"); } } } else if (messagingclass.getMessagetype().equals("Topic")) { ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic"); if (topicmap == null) { System.out.print("No Topic Available"); } else { CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap .get(messagingclass.getMessageelemname().trim()); if (topicclassList != null) { topicclassList.add(messagingclass); } else { System.out.print("No Topic Available"); } } } } //System.out.println(messagingClassMap); }
From source file:Controller.ControllerCustomers.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from www .j a v a 2 s. co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { } else { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = null; try { items = upload.parseRequest(request); } catch (Exception e) { e.printStackTrace(); } Iterator iter = items.iterator(); Hashtable params = new Hashtable(); String fileName = null; while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { params.put(item.getFieldName(), item.getString()); } else { try { String itemName = item.getName(); fileName = itemName.substring(itemName.lastIndexOf("\\") + 1); String RealPath = getServletContext().getRealPath("/") + "upload\\" + fileName; String username = (String) params.get("txtusername"); String password = (String) params.get("txtpassword"); String hoten = (String) params.get("txthoten"); String gioitinh = (String) params.get("txtgioitinh"); String email = (String) params.get("txtemail"); String role = (String) params.get("txtrole"); String anh = (String) params.get("txtanh"); //Update product if (fileName.equals("")) { Customer Cus = new Customer(username, password, hoten, gioitinh, email, role, anh); CustomerDAO.SuaThongTinKhachHang(Cus); RequestDispatcher rd = request.getRequestDispatcher("CustomerDao.jsp"); rd.forward(request, response); } else { // bat dau ghi file File savedFile = new File(RealPath); item.write(savedFile); //ket thuc ghi Customer Cus = new Customer(username, password, hoten, gioitinh, email, role, "upload\\" + fileName); CustomerDAO.SuaThongTinKhachHang(Cus); RequestDispatcher rd = request.getRequestDispatcher("CustomerDao.jsp"); rd.forward(request, response); } } catch (Exception e) { System.out.println(e); RequestDispatcher rd = request.getRequestDispatcher("InformationError.jsp"); rd.forward(request, response); } } } } }
From source file:com.app.messaging.MessagingClassConstruct.java
public void getMessagingClass(Digester messagedigester, File configFile, WebClassLoader customClassLoader, Hashtable messagingClassMap) throws ClassNotFoundException, FileNotFoundException, IOException, SAXException { MessagingClasses messagingClasses = (MessagingClasses) messagedigester .parse(new InputSource(new FileInputStream(configFile))); for (MessagingClass messagingclass : messagingClasses.messagingClasses) { Class messagingClass = customClassLoader.loadClass(messagingclass.getMessagingclass()); messagingclass.setMessageClass(messagingClass); if (messagingclass.getMessagetype().equals("RandomQueue")) { ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue"); //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()); if (randomqueuemap == null) { System.out.print("No RandomQueue Available"); } else { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { queueclassList.add(messagingclass); } else { System.out.print("No RandomQueue Available"); }//from w w w. j av a2 s.c om } } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) { ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap.get("RoundRobinQueue"); if (roundrobinqueuemap == null) { System.out.print("No RoundRobinQueue Available"); } else { CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap .get(messagingclass.getMessageelemname().trim()); if (queueclassList != null) { queueclassList.add(messagingclass); } else { System.out.print("No RoundRobinQueue Available"); } } } else if (messagingclass.getMessagetype().equals("Topic")) { ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic"); if (topicmap == null) { System.out.print("No Topic Available"); } else { CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap .get(messagingclass.getMessageelemname().trim()); if (topicclassList != null) { topicclassList.add(messagingclass); } else { System.out.print("No Topic Available"); } } } } //System.out.println(messagingClassMap); }
From source file:net.zypr.api.Protocol.java
public String buildURL(APIVerbs apiVerb, Hashtable<String, String> parameters) { String urlString = API.SERVER_URL + apiVerb.toPath() + "/"; if (parameters != null) { boolean first = true; for (Enumeration keys = parameters.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); String value = parameters.get(key); try { urlString += (first ? "?" : "&") + URLEncoder.encode(key, "UTF-8") + "=" + URLEncoder.encode(value, "UTF-8"); first = false;//from w ww . ja v a2 s. c om } catch (UnsupportedEncodingException unsupportedEncodingException) { throw new APIRuntimeException(unsupportedEncodingException); } } } return (urlString); }
From source file:de.fzi.ALERT.actor.MessageObserver.PatternObserver.JMSPatternParser.java
public Pattern xpathParsePatternEvent(String msgString) { System.out.println("pattern event:"); String s2 = msgString.replaceAll("[\n\r]", ""); System.out.println("new message: " + s2); System.out.println(msgString); Pattern pattern = new Pattern(); StringReader in = new StringReader(s2); try {// ww w.ja va 2s.c om Document doc = this.builder.build(in); Element root = doc.getRootElement(); String wsntNsPrefix; String patternNsPrefix; String alertNsPrefix; String patternEventName = null; String patternId = null; String cepatName = null; String cepatDescription = null; Hashtable<String, String> nstable = new Hashtable<String, String>(); String rootprefix = root.getNamespacePrefix(); if (rootprefix != null) nstable.put(root.getNamespaceURI(), rootprefix); List otherNs = root.getAdditionalNamespaces(); if (otherNs != null) { for (int i = 0; i < otherNs.size(); i++) { Namespace ns = (Namespace) otherNs.get(i); nstable.put(ns.getURI(), ns.getPrefix()); } } wsntNsPrefix = nstable.get(wsntNsURI); if (wsntNsPrefix != null) { XPath xpath = XPath.newInstance("//" + wsntNsPrefix + ":Message/*"); xpath.addNamespace(wsntNsPrefix, wsntNsURI); Object result = xpath.selectSingleNode(doc); if (result != null) { Element eventElement = (Element) result; String eventElementPrefix = eventElement.getNamespacePrefix(); if (eventElementPrefix != null) nstable.put(eventElement.getNamespaceURI(), eventElementPrefix); List atrs = eventElement.getAdditionalNamespaces(); for (int j = 0; j < atrs.size(); j++) { Namespace ans = (Namespace) atrs.get(j); nstable.put(ans.getURI(), ans.getPrefix()); } patternNsPrefix = nstable.get(patternNsURI); alertNsPrefix = nstable.get(alertNsURI); if (alertNsPrefix != null && patternNsPrefix != null) { xpath.addNamespace(alertNsPrefix, alertNsURI); xpath.addNamespace(patternNsPrefix, patternNsURI); Object eventNameElementObj = XPath.selectSingleNode(eventElement, "//" + alertNsPrefix + ":eventName/text()"); if (eventNameElementObj != null) { Text eventNameElement = (Text) eventNameElementObj; patternEventName = eventNameElement.getText(); } Object patternIdElementObj = XPath.selectSingleNode(eventElement, "//" + patternNsPrefix + ":cepatUID"); if (patternIdElementObj != null) { Element patternIdElement = (Element) patternIdElementObj; patternId = patternIdElement.getAttributeValue("value"); } Object cepatNameElementObj = XPath.selectSingleNode(eventElement, "//" + patternNsPrefix + ":cepatName"); if (cepatNameElementObj != null) { Element cepatNameElement = (Element) cepatNameElementObj; cepatName = cepatNameElement.getAttributeValue("value"); } Object cepatDescriptionElementObj = XPath.selectSingleNode(eventElement, "//" + patternNsPrefix + ":cepatDescription"); if (cepatDescriptionElementObj != null) { Element cepatDescriptionElement = (Element) cepatDescriptionElementObj; cepatDescription = cepatDescriptionElement.getAttributeValue("value"); } if (patternEventName != null) { if (patternEventName.equals(PATTERN_CREATED)) pattern.setStatus(0); else if (patternEventName.equals(PATTERN_MODIFIED)) pattern.setStatus(1); else if (patternEventName.equals(PATTERN_DELETED)) pattern.setStatus(2); else { System.out.println("The action type of the Pattern Message is wrong!"); } System.out.println( "pattern event type: " + patternEventName + " status:" + pattern.getStatus()); pattern.setPatternID(patternId); pattern.setPatternName(cepatName); pattern.setDescription(cepatDescription); } } } } } catch (JDOMException e) { System.out.println(msgString + " is not valid."); System.out.println(e.getMessage()); } catch (Exception e) { // TODO Auto-generated catch block System.out.println("Could not check " + msgString); System.out.println(" because " + e.getMessage()); } return pattern; }
From source file:ucar.unidata.util.AccountManager.java
/** * _more_/*from w w w.j a va2s. co m*/ * * @return _more_ */ protected Hashtable<String, UserInfo> getTable() { if (table == null) { try { String xml = IOUtil.readContents(IOUtil.joinDir(stateDir, "authentication.xml"), (String) null); Hashtable tmp = null; if (xml != null) { tmp = (Hashtable) XmlEncoder.decodeXml(xml); } if (tmp == null) { tmp = new Hashtable(); } // table = tmp; table = new Hashtable(); //Convert to the new passwordinfo for (Enumeration keys = tmp.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); Object value = tmp.get(key); if (!(value instanceof UserInfo)) { String[] pair = decode(value); value = new UserInfo(key, pair[0], pair[1]); } table.put(key, (UserInfo) value); } } catch (Exception exc) { throw new RuntimeException(exc); } } return table; }