List of usage examples for java.util Hashtable containsKey
public synchronized boolean containsKey(Object key)
From source file:eionet.acl.PersistenceDB.java
PersistenceDB(Hashtable props) throws DbNotSupportedException { this.props = props; try {//from w w w .ja va 2s . c o m if (props != null) { if (props.containsKey("db.datasource")) { dataSource = (DataSource) props.get("db.datasource"); } else { dbUrl = (String) props.get("db.url"); dbDriver = (String) props.get("db.driver"); dbUser = (String) props.get("db.user"); dbPwd = (String) props.get("db.pwd"); } } checkAclTables(); } catch (MissingResourceException mre) { LOGGER.info("Database property not configured, assuming no database support " + mre); throw new DbNotSupportedException(); } catch (DbNotSupportedException dbne) { LOGGER.info("Database Not supported " + dbne); throw dbne; } catch (SQLException sqle) { LOGGER.error("Error in database checking " + sqle); throw new DbNotSupportedException(); } catch (Exception e) { LOGGER.error("Error in database checking " + e); throw new DbNotSupportedException(); } }
From source file:com.alfaariss.oa.engine.attribute.gather.processor.file.FileGatherer.java
private Hashtable<String, FileAttribute> getFileAttributes(ConfigurationManager fileConfig, Element eSection) throws AttributeException { Hashtable<String, FileAttribute> htAttributes = new Hashtable<String, FileAttribute>(); try {/* ww w . ja v a2 s . c o m*/ Element eAttribute = fileConfig.getSection(eSection, "attribute"); while (eAttribute != null) { String sNameID = fileConfig.getParam(eAttribute, "id"); if (sNameID == null) { _logger.error("No 'id' parameter in 'attribute' section found"); throw new AttributeException(SystemErrors.ERROR_CONFIG_READ); } if (htAttributes.containsKey(sNameID)) { _logger.error("Duplicatie 'id' parameter in 'attribute' section found: " + sNameID); throw new AttributeException(SystemErrors.ERROR_CONFIG_READ); } String sFormat = fileConfig.getParam(eAttribute, "format"); FileAttribute fAttr = new FileAttribute(sNameID, sFormat); Element eValue = fileConfig.getSection(eAttribute, "value"); while (eValue != null) { String sValueID = fileConfig.getParam(eValue, "id"); if (sValueID == null) { _logger.error("No 'id' parameter in 'value' section found"); throw new AttributeException(SystemErrors.ERROR_CONFIG_READ); } fAttr.addValue(sValueID); eValue = fileConfig.getNextSection(eValue); } htAttributes.put(sNameID, fAttr); eAttribute = fileConfig.getNextSection(eAttribute); } } catch (AttributeException e) { throw e; } catch (Exception e) { _logger.fatal("Internal error during attribute reading", e); throw new AttributeException(SystemErrors.ERROR_INTERNAL); } return htAttributes; }
From source file:com.stimulus.archiva.extraction.MessageExtraction.java
private static void dumpPart(Part p, Hashtable<String, Part> attachments, Hashtable<String, String> inlines, Hashtable<String, String> images, Hashtable<String, String> nonImages, ArrayList<String> mimeTypes, String subject) throws Exception { mimeTypes.add(p.getContentType());//w ww. j a v a 2s. c om if (!p.isMimeType("multipart/*")) { String disp = p.getDisposition(); String fname = p.getFileName(); if (fname != null) { try { fname = MimeUtility.decodeText(fname); } catch (Exception e) { logger.debug("cannot decode filename:" + e.getMessage()); } } if ((disp != null && Compare.equalsIgnoreCase(disp, Part.ATTACHMENT)) || fname != null) { String filename = getFilename(subject, p); if (!filename.equalsIgnoreCase("winmail.dat")) { attachments.put(filename, p); } /*if (p.isMimeType("image/*")) { String str[] = p.getHeader("Content-ID"); if (str != null) images.put(filename,str[0]); else images.put(filename, filename); } return;*/ } } if (p.isMimeType("text/plain")) { String str = ""; if (inlines.containsKey("text/plain")) str = (String) inlines.get("text/plain") + "\n\n-------------------------------\n"; inlines.put("text/plain", str + getTextContent(p)); } else if (p.isMimeType("text/html")) { inlines.put("text/html", getTextContent(p)); } else if (p.isMimeType("text/xml")) { attachments.put(getFilename(subject, p), p); } else if (p.isMimeType("multipart/*")) { Multipart mp = (Multipart) p.getContent(); for (int i = 0; i < mp.getCount(); i++) dumpPart(mp.getBodyPart(i), attachments, inlines, images, nonImages, mimeTypes, subject); } else if (p.isMimeType("message/rfc822")) { dumpPart((Part) p.getContent(), attachments, inlines, images, nonImages, mimeTypes, subject); } else if (p.isMimeType("application/ms-tnef")) { Part tnefpart = TNEFMime.convert(null, p, false); if (tnefpart != null) { dumpPart((Part) tnefpart, attachments, inlines, images, nonImages, mimeTypes, subject); } } else if (p.isMimeType("application/*")) { String filename = getFilename("application", p); attachments.put(filename, p); String str[] = p.getHeader("Content-ID"); if (str != null) nonImages.put(filename, str[0]); } else if (p.isMimeType("image/*")) { String fileName = getFilename("image", p); attachments.put(fileName, p); String str[] = p.getHeader("Content-ID"); if (str != null) images.put(fileName, str[0]); else images.put(fileName, fileName); } else { String contentType = p.getContentType(); Object o = p.getContent(); if (o instanceof String) { String str = ""; if (inlines.containsKey("text/plain")) str = (String) inlines.get("text/plain") + "\n\n-------------------------------\n"; inlines.put(contentType, str + (String) o); } else { String fileName = getFilenameFromContentType("attach", contentType); attachments.put(fileName, p); } } }
From source file:com.alfaariss.oa.authentication.remote.AbstractRemoteMethod.java
/** * Converts the supplied message String in a Hashtable containing the parameters and values. * //from ww w .j av a2 s . c o m * @param sMessage The message string. * @return Returns a <code>Hashtable</code> containing the message parameters and values. * @throws OAException if conversion fails. */ protected Hashtable<String, String> convertCGI(String sMessage) throws OAException { Hashtable<String, String> htResult = new Hashtable<String, String>(); try { String[] saMessage = sMessage.split("&"); for (int i = 0; i < saMessage.length; i++) { String sPart = saMessage[i]; int iIndex = sPart.indexOf('='); String sKey = sPart.substring(0, iIndex); sKey = sKey.trim(); String sValue = sPart.substring(iIndex + 1); sValue = URLDecoder.decode(sValue.trim(), CHARSET); if (htResult.containsKey(sKey)) { _logger.error("Key is not unique in message: " + sKey); throw new OAException(SystemErrors.ERROR_INTERNAL); } htResult.put(sKey, sValue); } } catch (OAException e) { throw e; } catch (Exception e) { _logger.fatal("Internal error during conversion of message: " + sMessage, e); throw new OAException(SystemErrors.ERROR_INTERNAL); } return htResult; }
From source file:edu.uga.cs.fluxbuster.features.FeatureCalculator.java
/** * Calculates the cluster novelty feature for each cluster generated * on a specific run date./*w ww .j a v a2 s. c o m*/ * * @param log_date the run date * @param window the number of days previous to use in feature calculation * @return a table of values where the keys are cluster ids and the values * are the feature values * @throws SQLException if there is an error calculating the feature values */ public Map<Integer, Double> calculateNoveltyFeature(Date log_date, int window) throws SQLException { HashMap<Integer, Double> retval = new HashMap<Integer, Double>(); ArrayList<Date> prevDates = getPrevDates(log_date, window); if (prevDates.size() > 0) { StringBuffer querybuf = new StringBuffer(); Formatter formatter = new Formatter(querybuf); String curdatestr = df.format(log_date); formatter.format(properties.getProperty(NOVELTY_QUERY1_1KEY), curdatestr, curdatestr, curdatestr, curdatestr); for (Date prevDate : prevDates) { formatter.format(" " + properties.getProperty(NOVELTY_QUERY1_2KEY) + " ", df.format(prevDate)); } formatter.format(properties.getProperty(NOVELTY_QUERY1_3KEY), curdatestr, curdatestr); ResultSet rs2 = null; Hashtable<Integer, Hashtable<String, Long>> new_resolved_ips = new Hashtable<Integer, Hashtable<String, Long>>(); try { rs2 = dbi.executeQueryWithResult(querybuf.toString()); while (rs2.next()) { int cluster_id = rs2.getInt(2); if (!new_resolved_ips.containsKey(cluster_id)) { new_resolved_ips.put(cluster_id, new Hashtable<String, Long>()); } String secondLevelDomainName = rs2.getString(1); long newips = rs2.getLong(3); Hashtable<String, Long> clustertable = new_resolved_ips.get(cluster_id); clustertable.put(secondLevelDomainName, newips); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error(e); } } finally { if (rs2 != null && !rs2.isClosed()) { rs2.close(); } formatter.close(); } Hashtable<String, List<Integer>> numDays = new Hashtable<String, List<Integer>>(); for (Date prevDate : prevDates) { String prevDateStr = df.format(prevDate); querybuf = new StringBuffer(); formatter = new Formatter(querybuf); formatter.format(properties.getProperty(NOVELTY_QUERY2KEY), curdatestr, prevDateStr, curdatestr, prevDateStr); ResultSet rs3 = null; try { rs3 = dbi.executeQueryWithResult(querybuf.toString()); while (rs3.next()) { String sldn = rs3.getString(1); if (!numDays.containsKey(sldn)) { numDays.put(sldn, new ArrayList<Integer>()); } Date pd = rs3.getDate(2); DateTime start = new DateTime(pd.getTime()); DateTime end = new DateTime(log_date.getTime()); Days d = Days.daysBetween(start, end); int diffDays = d.getDays(); numDays.get(sldn).add(diffDays); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error(e); } } finally { if (rs3 != null && !rs3.isClosed()) { rs3.close(); } formatter.close(); } } Hashtable<Integer, List<Float>> clusterValues = new Hashtable<Integer, List<Float>>(); for (int clusterID : new_resolved_ips.keySet()) { clusterValues.put(clusterID, new ArrayList<Float>()); Hashtable<String, Long> sldnValues = new_resolved_ips.get(clusterID); for (String sldn : sldnValues.keySet()) { if (numDays.keySet().contains(sldn)) { long newIPCount = sldnValues.get(sldn); float f = ((float) newIPCount) / Collections.max(numDays.get(sldn)); clusterValues.get(clusterID).add(f); } } } for (int clusterID : clusterValues.keySet()) { if (clusterValues.get(clusterID) == null) { //I dont think it is possible for this to ever be true retval.put(clusterID, null); } else { double sum = 0; for (double d : clusterValues.get(clusterID)) { sum += d; } double val = 0; if (clusterValues.get(clusterID).size() > 0) { val = sum / clusterValues.get(clusterID).size(); } retval.put(clusterID, val); } } } return retval; }
From source file:de.suse.swamp.core.util.BugzillaTools.java
public void fetchBugzillaInfo(Dataset dataset, int bugid) throws Exception { ArrayList excludeFields = new ArrayList(); if (dataset != null && !dataset.containsDatabit("description")) { excludeFields.add("long_desc"); }//w w w . j a v a 2 s . co m Hashtable bug = getBugData(bugid, excludeFields); // only store if a dataset is provided if (dataset != null) { for (Iterator it = dataset.getDatabits().iterator(); it.hasNext();) { Databit bit = (Databit) it.next(); String bitName = bit.getName(); if (bitName.equals("people")) { if (bit.setValue(((SWAMPHashSet) bug.get("people")).toString(", "), SWAMPUser.SYSTEMUSERNAME)) { Logger.LOG("Bugzilla copy: " + bitName + "=" + bug.get(bitName), log); } } else if (bitName.equals("delta_time") && bug.containsKey("delta")) { DateFormat df1 = new SimpleDateFormat(dateDatabit.dateFormat); bit.setValue(df1.format((Date) bug.get("delta")), SWAMPUser.SYSTEMUSERNAME); } else if (bug.containsKey(bitName)) { if (bit.setValue((String) bug.get(bitName), SWAMPUser.SYSTEMUSERNAME)) { Logger.DEBUG("Bugzilla copy: " + bitName + "=" + bug.get(bitName), log); } } } } }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
private void setVariablesFromXML(String prefix, String key, Element element, Hashtable predecessors) { int pos = 1;//from ww w. j a v a 2 s . c om if (predecessors.containsKey(key)) { pos = (Integer) predecessors.get(key) + 1; } predecessors.put(key, pos); String path = prefix + "/" + key; if (pos > 1) { path = path + "[" + pos + "]"; } // Add element text addVariable(path, element.getText()); // Add value of all attributes List attributes = element.getAttributes(); for (Object attribute1 : attributes) { Attribute attribute = (Attribute) attribute1; String value = attribute.getValue(); if (value != null && value.length() > 0) { addVariable(path + "/@" + getNamespacePrefix(attribute.getNamespace()) + attribute.getName(), value); } } // Add values of all children predecessors = new Hashtable(); List children = element.getChildren(); for (Object aChildren : children) { Element child = (Element) aChildren; setVariablesFromXML(path, child, predecessors); } }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a pie graph representing average build execution times across * all builds in the list. /* ww w. j a v a 2 s . com*/ * * @param builds List of builds * * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAverageMetricChart(Vector<CMnDbBuildData> builds) { JFreeChart chart = null; // Get a list of all possible build metrics int[] metricTypes = CMnDbMetricData.getAllTypes(); Hashtable metricAvg = new Hashtable(metricTypes.length); DefaultPieDataset dataset = new DefaultPieDataset(); if ((builds != null) && (builds.size() > 0)) { // Collect build metrics for each of the builds in the list Enumeration buildList = builds.elements(); while (buildList.hasMoreElements()) { // Process the build metrics for the current build CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement(); Vector metrics = build.getMetrics(); if ((metrics != null) && (metrics.size() > 0)) { // Collect data for each of the build metrics in the current build Enumeration metricList = metrics.elements(); while (metricList.hasMoreElements()) { CMnDbMetricData currentMetric = (CMnDbMetricData) metricList.nextElement(); // Get elapsed time in "minutes" Long elapsedTime = new Long(currentMetric.getElapsedTime() / (1000 * 60)); String metricName = CMnDbMetricData.getMetricType(currentMetric.getType()); Long avgValue = null; if (metricAvg.containsKey(metricName)) { Long oldAvg = (Long) metricAvg.get(metricName); avgValue = oldAvg + elapsedTime; } else { avgValue = elapsedTime; } metricAvg.put(metricName, avgValue); } // while build has metrics } // if has metrics } // while list has elements // Populate the data set with the average values for each metric Enumeration keys = metricAvg.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Long total = (Long) metricAvg.get(key); Long avg = new Long(total.longValue() / (long) builds.size()); //dataset.setValue(key, (Long) metricAvg.get(key)); dataset.setValue(key, avg); } } // if list has elements // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Average Build Metrics", dataset, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatMetricChart(plot, "min"); return chart; }
From source file:net.timbusproject.extractors.debiansoftwareextractor.Engine.java
private void extractInstallers(Hashtable<String, JSONObject> packages) throws InterruptedException, JSchException, IOException, JSONException { if (!isCommandAvailable("apt-cache")) { log.warn("Installers could not be extracted."); return;//w w w . java 2 s . c om } final Pattern ppaPattern = Pattern.compile("(\\S+) (\\S+) (.+)"); for (String control : doCommand(commands.getProperty("apt-show-installed")).getProperty("stdout") .split("\\n\\n")) { JSONObject object = extractPackage(control); String pkgname = object.getString("Package"); for (int i = 0; i != object.names().length(); ++i) { String property = object.names().getString(i); if (packages.containsKey(pkgname) && !packages.get(pkgname).has(property)) packages.get(pkgname).put(property.equals("Filename") ? "Installer" : property, object.getString(property)); } } for (String line : doCommand(commands.getProperty("ppa-installed")).getProperty("stdout").split("\\n")) { Matcher matcher = ppaPattern.matcher(line); matcher.find(); if (packages.containsKey(matcher.group(1)) && packages.get(matcher.group(1)).getString("Version").equals(matcher.group(2)) && packages.get(matcher.group(1)).has("Installer")) packages.get(matcher.group(1)).put("Installer", matcher.group(3) + packages.get(matcher.group(1)).getString("Installer")); } }
From source file:tvraterplugin.Updater.java
/** * Runs thru all Days and Channels, creates a List of Programs that need to * get a rating//from w ww . ja v a 2 s . c o m * * @return Hashtable filled with Programs to rate */ private Hashtable<String, Program> createUpdateList() { Hashtable<String, Program> table = new Hashtable<String, Program>(); Channel[] channels = Plugin.getPluginManager().getSubscribedChannels(); Date date = new Date(); date = date.addDays(-1); for (int d = 0; d < 32; d++) { for (Channel channel : channels) { for (Iterator<Program> it = Plugin.getPluginManager().getChannelDayProgram(date, channel); it .hasNext();) { Program program = it.next(); if ((program != null) && mPlugin.isProgramRateable(program)) { if (!table.containsKey(program.getTitle())) { table.put(program.getTitle(), program); } } } } date = date.addDays(1); } return table; }