/* Author: Jeff Dalton * Updated: Thu Nov 22 18:29:56 2001 by Jeff Dalton * Copyright: (c) 2001, AIAI, University of Edinburgh */ package ix.iface.util; import java.text.SimpleDateFormat; import java.util.Date; import java.util.*; import ix.icore.Issue; import ix.icore.BasicIssue; import ix.icore.Report; import ix.util.lisp.*; import ix.util.*; /** * Class of static methods useful when reporting incoming messages etc. */ public class Reporting { static SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // We sometimes have to explicitly set the default timezone; // static { dateFormat.setTimeZone(TimeZone.getDefault()); } private Reporting() { } // no instantiation public static String messageDescription(IPC.InputMessage message) { Object contents = message.getContents(); if (contents instanceof Issue) return issueDescription((Issue)contents); else if (contents instanceof Report) return reportDescription((Report)contents); else return "Unexpected message containing: " + message; } public static String issueDescription(Issue issue) { String senderId = issue.getSenderId(); String ref = issue.getRef(); String reportBack = issue.getReportBack() ? "yes" : "no"; return dateString() + " Issue from " + senderId + (ref == null ? "" : " ref=" + ref) + (reportBack == null ? "" : " report-back=" + reportBack) + " priority=" + priorityDescription(issue.getPriority()) + ": " + Util.quote(XML.issueDescription(issue)); } public static String reportDescription(Report report) { String senderId = report.getSenderId(); String ref = report.getRef(); String type = report.getReportType(); return dateString() + " Report from " + senderId + (ref == null ? "" : " ref=" + ref) + (type == null ? "" : " type=" + type) + ": " + Util.quote(report.getText()); } public static String dateString() { return dateFormat.format(new Date()); } public static String priorityDescription(int priority) { return ViewColor.priorityName[priority].toLowerCase(); } }