]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.message.ui/src/org/simantics/message/ui/LogSession.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.message.ui / src / org / simantics / message / ui / LogSession.java
diff --git a/bundles/org.simantics.message.ui/src/org/simantics/message/ui/LogSession.java b/bundles/org.simantics.message.ui/src/org/simantics/message/ui/LogSession.java
new file mode 100644 (file)
index 0000000..769f7aa
--- /dev/null
@@ -0,0 +1,64 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.message.ui;
+
+import com.ibm.icu.text.SimpleDateFormat;
+import java.io.PrintWriter;
+import java.text.ParseException;
+import java.util.Date;
+
+/**
+ * Group of entries with additional Session data.
+ */
+public class LogSession extends Group {
+       private String sessionData;
+       private Date date;
+
+       public LogSession() {
+               super(Messages.LogViewLabelProvider_Session);
+       }
+
+       public Date getDate() {
+               return date;
+       }
+
+       public void setDate(String dateString) {
+               SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
+               try {
+                       date = formatter.parse(dateString);
+               } catch (ParseException e) { // do nothing
+               }
+       }
+
+       public String getSessionData() {
+               return sessionData;
+       }
+
+       void setSessionData(String data) {
+               this.sessionData = data;
+       }
+
+       public void processLogLine(String line) {
+               // process "!SESSION <dateUnknownFormat> ----------------------------"
+               line = line.substring(9); // strip "!SESSION "
+               int delim = line.indexOf("----"); //$NON-NLS-1$ // single "-" may be in date, so take few for sure
+               if (delim == -1)
+                       return;
+
+               String dateBuffer = line.substring(0, delim).trim();
+               setDate(dateBuffer);
+       }
+
+       public void write(PrintWriter writer) {
+               writer.write(sessionData);
+       }
+}