List of usage examples for java.util Hashtable putAll
public synchronized void putAll(Map<? extends K, ? extends V> t)
From source file:pl.otros.logview.parser.log4j.Log4jPatternMultilineLogParser.java
/** * Convert a keyword-to-values map to a LoggingEvent * /*from w ww .ja v a 2 s . co m*/ * @param fieldMap * @param exception * * @return logging event */ private LoggingEvent convertToEvent(Map fieldMap, String[] exception, DateFormat dateFormat) { if (fieldMap == null) { return null; } // a logger must exist at a minimum for the event to be processed if (!fieldMap.containsKey(LOGGER)) { fieldMap.put(LOGGER, "Unknown"); } if (exception == null) { exception = emptyException; } Logger logger = null; long timeStamp = 0L; String level = null; String threadName = null; Object message = null; String ndc = null; String className = null; String methodName = null; String eventFileName = null; String lineNumber = null; Hashtable properties = new Hashtable(); logger = Logger.getLogger((String) fieldMap.remove(LOGGER)); if ((dateFormat != null) && fieldMap.containsKey(TIMESTAMP)) { String dateString = (String) fieldMap.remove(TIMESTAMP); try { timeStamp = dateFormat.parse(dateString).getTime(); } catch (Exception e) { LOG.log(java.util.logging.Level.WARNING, "Error parsing date with format \"" + dateFormat + "\" with String \"" + dateString + "\"", e); } } // use current time if timestamp not parseable if (timeStamp == 0L) { timeStamp = System.currentTimeMillis(); } message = fieldMap.remove(MESSAGE); if (message == null) { message = ""; } level = (String) fieldMap.remove(LEVEL); Level levelImpl; if (level == null) { levelImpl = Level.DEBUG; } else { // first try to resolve against custom level definition map, then // fall back to regular levels level = level.trim(); levelImpl = customLevelDefinitionMap.get(level); if (levelImpl == null) { levelImpl = Level.toLevel(level.trim()); if (!level.equals(levelImpl.toString())) { // check custom level map levelImpl = Level.DEBUG; LOG.fine("found unexpected level: " + level + ", logger: " + logger.getName() + ", msg: " + message); // make sure the text that couldn't match a level is // added to the message message = level + " " + message; } } } threadName = (String) fieldMap.remove(THREAD); if (threadName == null) { threadName = ""; } ndc = (String) fieldMap.remove(NDC); className = (String) fieldMap.remove(CLASS); methodName = (String) fieldMap.remove(METHOD); eventFileName = (String) fieldMap.remove(FILE); lineNumber = (String) fieldMap.remove(LINE); // properties.put(Constants.HOSTNAME_KEY, host); // properties.put(Constants.APPLICATION_KEY, path); // properties.put(Constants.RECEIVER_NAME_KEY, getName()); // all remaining entries in fieldmap are properties properties.putAll(fieldMap); LocationInfo info = null; if ((eventFileName != null) || (className != null) || (methodName != null) || (lineNumber != null)) { info = new LocationInfo(eventFileName, className, methodName, lineNumber); } else { info = LocationInfo.NA_LOCATION_INFO; } // LoggingEvent event = new LoggingEvent(null, // logger, timeStamp, levelImpl, message, // threadName, // new ThrowableInformation(exception), // ndc, // info, // properties); // LoggingEvent event = new LoggingEvent(); LoggingEvent event = new LoggingEvent(null, logger, timeStamp, levelImpl, message, threadName, new ThrowableInformation(exception), ndc, info, properties); // event.setLogger(logger); // event.setTimeStamp(timeStamp); // event.setLevel(levelImpl); // event.setMessage(message); // event.setThreadName(threadName); // event.setThrowableInformation(new ThrowableInformation(exception)); // event.setNDC(ndc); // event.setLocationInformation(info); // event.setProperties(properties); return event; }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Merge all of the proeprties together//w w w . ja va 2 s.c o m * * @return The properties */ private Hashtable getAllProperties() { Hashtable props = new Hashtable(); for (int i = 0; i < propertiesStack.size(); i++) { Hashtable properties = (Hashtable) propertiesStack.get(i); props.putAll(properties); } return props; }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Do the macro substitution//from w w w . ja v a 2 s .co m * * @param s The string * @param props Properties * @param doTime process time macros * * @return The expanded string */ private String applyMacros(String s, Hashtable props, boolean doTime) { if (s == null) { return null; } if (props == null) { props = new Hashtable(); } else { Hashtable tmp = props; props = new Hashtable(); props.putAll(tmp); } props.putAll(getAllProperties()); putIndex(props, PROP_LOOPINDEX, currentLoopIndex); props.put(PROP_LOOPINDEX_PAD2, StringUtil.padLeft("" + currentLoopIndex, 2, "0")); props.put(PROP_LOOPINDEX_PAD3, StringUtil.padLeft("" + currentLoopIndex, 3, "0")); props.put(PROP_LOOPINDEX_PAD4, StringUtil.padLeft("" + currentLoopIndex, 4, "0")); Date now = new Date(Misc.getCurrentTime()); if (DATE_FORMATS == null) { TimeZone timeZone = TimeZone.getTimeZone("GMT"); DATE_FORMATS = new ArrayList(); for (int i = 0; i < DATE_PROPS.length; i++) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_PROPS[i]); sdf.setTimeZone(timeZone); DATE_FORMATS.add(sdf); } } for (int i = 0; i < DATE_FORMATS.size(); i++) { SimpleDateFormat sdf = (SimpleDateFormat) DATE_FORMATS.get(i); props.put(DATE_PROPS[i], sdf.format(now)); } props.put("memory", "" + Misc.usedMemory()); /* if (s.indexOf("${anim:") >= 0) { now = getAnimationTime(); if (now != null) { for (int i = 0; i < DATE_FORMATS.size(); i++) { SimpleDateFormat sdf = (SimpleDateFormat) DATE_FORMATS.get(i); props.put("anim:" + DATE_PROPS[i], sdf.format(now)); } } }*/ TimeZone tz = getIdv().getPreferenceManager().getDefaultTimeZone(); s = StringUtil.replaceDate(s, "now:", now, tz); if ((s.indexOf("anim:") >= 0) || (s.indexOf("time:") >= 0)) { Date animationTime = getAnimationTime(); if (animationTime == null) { animationTime = now; } if (doTime) { s = StringUtil.replaceDate(s, "anim:", animationTime, tz); s = StringUtil.replaceDate(s, "time:", animationTime, tz); s = StringUtil.replaceDate(s, "now:", now, tz); } } s = StringUtil.applyMacros(s, props, false); //Now use the idv properties s = StringUtil.applyMacros(s, getStateManager().getProperties(), false); if (s.indexOf("${") >= 0) { throw new BadIslException("Undefined macro in: " + s); } if (s.startsWith("jython:")) { Object result = getInterpreter().eval(s.substring(7)); s = result.toString(); } if (s.startsWith("interp.")) { Object result = getInterpreter().eval(s); s = result.toString(); } if (s.startsWith("islInterpreter.")) { Object result = getInterpreter().eval(s); s = result.toString(); } s = s.replace("\\n", "\n"); return s; }