diff options
Diffstat (limited to 'netx/net/sourceforge/jnlp')
9 files changed, 571 insertions, 85 deletions
diff --git a/netx/net/sourceforge/jnlp/util/logging/FileLog.java b/netx/net/sourceforge/jnlp/util/logging/FileLog.java index 3ac048b..962e4ab 100644 --- a/netx/net/sourceforge/jnlp/util/logging/FileLog.java +++ b/netx/net/sourceforge/jnlp/util/logging/FileLog.java @@ -46,6 +46,7 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; import net.sourceforge.jnlp.util.FileUtils; +import net.sourceforge.jnlp.util.logging.headers.Header; /** * This class writes log information to file. @@ -90,7 +91,7 @@ public final class FileLog implements SingleStreamLogger { impl = Logger.getLogger(loggerName); impl.setLevel(Level.ALL); impl.addHandler(fh); - log(OutputController.getHeader(null, null)); + log(new Header(OutputController.Level.WARNING_ALL, Thread.currentThread().getStackTrace(), Thread.currentThread(), false).toString()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java b/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java index 52bc1aa..2ee601e 100644 --- a/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java +++ b/netx/net/sourceforge/jnlp/util/logging/JavaConsole.java @@ -46,6 +46,11 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -63,6 +68,10 @@ import javax.swing.border.TitledBorder; import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.util.ImageResources; +import net.sourceforge.jnlp.util.logging.headers.Header; +import net.sourceforge.jnlp.util.logging.headers.JavaMessage; +import net.sourceforge.jnlp.util.logging.headers.MessageWithHeader; +import net.sourceforge.jnlp.util.logging.headers.PluginMessage; /** * A simple Java console for IcedTeaPlugin and JavaWS @@ -392,7 +401,7 @@ public class JavaConsole { final JavaConsole console = new JavaConsole(); - boolean toShowConsole = false; + boolean toShowConsole = true; for (String arg : args) { if ("--show-console".equals(arg)) { @@ -406,11 +415,73 @@ public class JavaConsole { } - void logOutput(String s) { - stdOutText.setText(stdOutText.getText() + s + "\n"); + + void addMessage(Header header, String message) { + if (!LogConfig.getLogConfig().isEnableHeaders()){ + if (header.level.isError()){ + stdErrText.setText(stdErrText.getText() + message + "\n"); + } + if (header.level.isOutput()){ + stdOutText.setText(stdOutText.getText() + message + "\n"); + } + } else { + if (header.level.isError()){ + stdErrText.setText(stdErrText.getText( )+ header.toString() + message +"\n"); + } + if (header.level.isOutput()){ + stdOutText.setText(stdOutText.getText() + header.toString() + message + "\n"); + } + } + } + + /** + * parse plugin message and add it as header+message to data + * @param s string to be parsed + */ + private void processPluginMessage(String s) { + PluginMessage pm = new PluginMessage(s); + addMessage(pm.getHeader(), pm.getMessage()); } - void logError(String s) { - stdErrText.setText(stdErrText.getText() + s + "\n"); + + public void createPluginReader(final File file) { + OutputController.getLogger().log("Starting processing of plugin-debug-to-console " + file.getAbsolutePath()); + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + BufferedReader br = null; + try { + br = new BufferedReader(new InputStreamReader(new FileInputStream(file), + Charset.forName("UTF-8"))); + //never ending loop + while (true) { + try{ + String s = br.readLine(); + if (s == null) { + break; + } + processPluginMessage(s); + }catch(Exception ex){ + OutputController.getLogger().log(ex); + } + } + } catch (Exception ex) { + OutputController.getLogger().log(ex); + if (br != null) { + try { + br.close(); + } catch (Exception exx) { + OutputController.getLogger().log(exx); + } + } + } + OutputController.getLogger().log("Ended processing of plugin-debug-to-console " + file.getAbsolutePath()); + } + }, "plugin-debug-to-console reader thread"); + t.setDaemon(true); + t.start(); + + OutputController.getLogger().log("Started processing of plugin-debug-to-console " + file.getAbsolutePath()); } } diff --git a/netx/net/sourceforge/jnlp/util/logging/LogConfig.java b/netx/net/sourceforge/jnlp/util/logging/LogConfig.java index 2c98cd2..72941f3 100644 --- a/netx/net/sourceforge/jnlp/util/logging/LogConfig.java +++ b/netx/net/sourceforge/jnlp/util/logging/LogConfig.java @@ -55,12 +55,13 @@ public class LogConfig { private boolean logToFile; private boolean logToStreams; private boolean logToSysLog; + private DeploymentConfiguration config; private static LogConfig logConfig; public LogConfig() { try { - DeploymentConfiguration config = JNLPRuntime.getConfiguration(); + config = JNLPRuntime.getConfiguration(); if (config.getRaw().isEmpty()){ config = new DeploymentConfiguration();//JNLPRuntime.getConfiguration() cannotbe loaded time config.load(); //read one prior @@ -161,7 +162,11 @@ public class LogConfig { return JavaConsole.isEnabled(); } - - + /* + * logging stuff may be interested in used config + */ + public DeploymentConfiguration getConfig() { + return config; + } } diff --git a/netx/net/sourceforge/jnlp/util/logging/OutputController.java b/netx/net/sourceforge/jnlp/util/logging/OutputController.java index 6a6dcd6..d84950a 100644 --- a/netx/net/sourceforge/jnlp/util/logging/OutputController.java +++ b/netx/net/sourceforge/jnlp/util/logging/OutputController.java @@ -54,20 +54,37 @@ public class OutputController { ERROR_ALL, // - stderr/log in all cases (default for ERROR_DEBUG; // - stderr/log in verbose/debug mode //ERROR_DEBUG is default for Throwable - //MESSAGE_VERBOSE is defautrl for String + //MESSAGE_DEBUG is default for String - private static boolean isOutput(MessageWithLevel s) { - return s.level == Level.MESSAGE_ALL - || s.level == Level.MESSAGE_DEBUG - || s.level == Level.WARNING_ALL - || s.level == Level.WARNING_DEBUG; + public boolean isOutput() { + return this == Level.MESSAGE_ALL + || this == Level.MESSAGE_DEBUG + || this == Level.WARNING_ALL + || this == Level.WARNING_DEBUG; } - private static boolean isError(MessageWithLevel s) { - return s.level == Level.ERROR_ALL - || s.level == Level.ERROR_DEBUG - || s.level == Level.WARNING_ALL - || s.level == Level.WARNING_DEBUG; + public boolean isError() { + return this == Level.ERROR_ALL + || this == Level.ERROR_DEBUG + || this == Level.WARNING_ALL + || this == Level.WARNING_DEBUG; + } + + public boolean isWarning() { + return this == Level.WARNING_ALL + || this == Level.WARNING_DEBUG; + } + + public boolean isDebug() { + return this == Level.ERROR_DEBUG + || this == Level.MESSAGE_DEBUG + || this == Level.WARNING_DEBUG; + } + + public boolean isInfo() { + return this == Level.ERROR_ALL + || this == Level.WARNING_ALL + || this == Level.MESSAGE_ALL; } } @@ -76,6 +93,8 @@ public class OutputController { public final String message; public final Level level; public final StackTraceElement[] stack = Thread.currentThread().getStackTrace(); + public final Thread thread = Thread.currentThread(); + public final Date loggedAt = new Date(); public MessageWithLevel(String message, Level level) { this.message = message; @@ -132,6 +151,11 @@ public class OutputController { private void consume() { MessageWithLevel s = messageQue.get(0); messageQue.remove(0); + net.sourceforge.jnlp.util.logging.headers.Header header = new net.sourceforge.jnlp.util.logging.headers.Header(s.level, s.stack, s.thread, s.loggedAt, false); + //filtering is done in console during runtime + if (LogConfig.getLogConfig().isLogToConsole()) { + JavaConsole.getConsole().addMessage(header, s.message); + } if (!JNLPRuntime.isDebug() && (s.level == Level.MESSAGE_DEBUG || s.level == Level.WARNING_DEBUG || s.level == Level.ERROR_DEBUG)) { @@ -142,16 +166,16 @@ public class OutputController { String message = s.message; if (LogConfig.getLogConfig().isEnableHeaders()) { if (message.contains("\n")) { - message = getHeader(s.level, s.stack) + "\n" + message; + message = header.toString() + "\n" + message; } else { - message = getHeader(s.level, s.stack) + " " + message; + message = header.toString() + " " + message; } } if (LogConfig.getLogConfig().isLogToStreams()) { - if (Level.isOutput(s)) { + if (s.level.isOutput()) { outLog.log(message); } - if (Level.isError(s)) { + if (s.level.isError()) { errLog.log(message); } } @@ -161,14 +185,6 @@ public class OutputController { if (LogConfig.getLogConfig().isLogToSysLog()) { getSystemLog().log(message); } - if (LogConfig.getLogConfig().isLogToConsole()) { - if (Level.isOutput(s)){ - JavaConsole.getConsole().logOutput(message); - } - if (Level.isError(s)){ - JavaConsole.getConsole().logError(message); - } - } } @@ -344,59 +360,6 @@ public class OutputController { printOut(e); printError(e); } - - public static String getHeader(Level level, StackTraceElement[] stack) { - StringBuilder sb = new StringBuilder(); - try { - String user = System.getProperty("user.name"); - sb.append("[").append(user).append("]"); - if (JNLPRuntime.isWebstartApplication()) { - sb.append("[ITW-JAVAWS]"); - } else { - sb.append("[ITW]"); - } - if (level != null) { - sb.append('[').append(level.toString()).append(']'); - } - sb.append('[').append(new Date().toString()).append(']'); - if (stack != null) { - sb.append('[').append(getCallerClass(stack)).append(']'); - } - sb.append(" NETX Thread# ") - .append(Integer.toHexString(((Object)Thread.currentThread()).hashCode())) - .append(", name ") - .append(Thread.currentThread().getName()); - } catch (Exception ex) { - getLogger().log(ex); - } - return sb.toString(); - - } - - static String getCallerClass(StackTraceElement[] stack) { - try { - //0 is always thread - //1..? is OutputController itself - //pick up first after. - StackTraceElement result = stack[0]; - int i = 1; - for (; i < stack.length; i++) { - result = stack[i];//at least moving up - if (stack[i].getClassName().contains(OutputController.class.getName()) || - //PluginDebug.class.getName() not avaiable during netx make - stack[i].getClassName().contains("sun.applet.PluginDebug") ) { - continue; - } else { - break; - } - } - return result.toString(); - } catch (Exception ex) { - getLogger().log(ex); - return "Unknown caller"; - } - } - //package private setters for testing diff --git a/netx/net/sourceforge/jnlp/util/logging/headers/Header.java b/netx/net/sourceforge/jnlp/util/logging/headers/Header.java new file mode 100644 index 0000000..a87a14f --- /dev/null +++ b/netx/net/sourceforge/jnlp/util/logging/headers/Header.java @@ -0,0 +1,161 @@ +/* +Copyright (C) 2009, 2013 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +package net.sourceforge.jnlp.util.logging.headers; + +import java.util.Date; +import net.sourceforge.jnlp.runtime.JNLPRuntime; +import net.sourceforge.jnlp.util.logging.OutputController; +import net.sourceforge.jnlp.util.logging.OutputController.Level; + +public class Header { + + public String user; + public boolean application; + public Level level; + public Date date = new Date(); + public boolean isC;//false=> java + public String caller; + public String thread1; + public String thread2; + + //to alow simple inheritance + public Header() { + } + + public Header(Level level, StackTraceElement[] stack, Thread thread, boolean isC) { + this(level, stack, thread, new Date(), isC); + } + + public Header(Level level, StackTraceElement[] stack, Thread thread, Date d, boolean isC) { + this.user = System.getProperty("user.name"); + this.application = JNLPRuntime.isWebstartApplication(); + this.level = level; + this.date = d; + this.isC = isC; + if (stack != null) { + this.caller = getCallerClass(stack); + } + this.thread1 = Integer.toHexString(((Object) thread).hashCode()); + this.thread2 = thread.getName(); + } + + @Override + public String toString() { + return toString(true, true, true, true, true, true, true); + } + + public String toString(boolean userb, boolean originb, boolean levelb, boolean dateb, boolean callerb, boolean thread1b, boolean thread2b) { + StringBuilder sb = new StringBuilder(); + try { + if (userb){ + sb.append("[").append(user).append("]"); + } + if(originb){ + sb.append("[").append(getOrigin()).append("]"); + } + + if (levelb && level != null) { + sb.append('[').append(level.toString()).append(']'); + } + if (dateb){ + sb.append('[').append(date.toString()).append(']'); + } + if (callerb && caller != null) { + sb.append('[').append(caller).append(']'); + } + if (thread1b && thread2b){ + sb.append(threadsToString()); + }else if (thread1b) { + sb.append(thread1ToString()); + }else if (thread2b) { + sb.append(thread2ToString()); + } + } catch (Exception ex) { + OutputController.getLogger().log(ex); + } + return sb.toString(); + } + + public String thread1ToString() { + return " NETX Thread# " + thread1; + } + + public String thread2ToString() { + return "name " + thread2; + } + + public String threadsToString() { + return thread1ToString() + + ", " + thread2ToString(); + } + + public String getOrigin() { + if (application) { + return "ITW-JAVAWS"; + } else { + if (isC) { + return "ITW-C-PLUGIN"; + } else { + return "ITW-APPLET"; + } + } + } + + static String getCallerClass(StackTraceElement[] stack) { + try { + //0 is always thread + //1..? is OutputController itself + //pick up first after. + StackTraceElement result = stack[0]; + int i = 1; + for (; i < stack.length; i++) { + result = stack[i];//at least moving up + if (stack[i].getClassName().contains(OutputController.class.getName()) + || //PluginDebug.class.getName() not avaiable during netx make + stack[i].getClassName().contains("sun.applet.PluginDebug")) { + continue; + } else { + break; + } + } + return result.toString(); + } catch (Exception ex) { + OutputController.getLogger().log(ex); + return "Unknown caller"; + } + } +} diff --git a/netx/net/sourceforge/jnlp/util/logging/headers/JavaMessage.java b/netx/net/sourceforge/jnlp/util/logging/headers/JavaMessage.java new file mode 100644 index 0000000..6994f9e --- /dev/null +++ b/netx/net/sourceforge/jnlp/util/logging/headers/JavaMessage.java @@ -0,0 +1,63 @@ +/* +Copyright (C) 2009, 2013 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package net.sourceforge.jnlp.util.logging.headers; + + + +public class JavaMessage implements MessageWithHeader{ + + public Header header; + public String message; + + public JavaMessage(Header header, String message) { + this.header = header; + this.message = message; + } + + + + @Override + public String getMessage() { + return message; + } + + @Override + public Header getHeader() { + return header; + } +} diff --git a/netx/net/sourceforge/jnlp/util/logging/headers/MessageWithHeader.java b/netx/net/sourceforge/jnlp/util/logging/headers/MessageWithHeader.java new file mode 100644 index 0000000..5af997b --- /dev/null +++ b/netx/net/sourceforge/jnlp/util/logging/headers/MessageWithHeader.java @@ -0,0 +1,46 @@ +/* +Copyright (C) 2009, 2013 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package net.sourceforge.jnlp.util.logging.headers; + + +public interface MessageWithHeader { + + String getMessage(); + Header getHeader(); + +} diff --git a/netx/net/sourceforge/jnlp/util/logging/headers/PluginHeader.java b/netx/net/sourceforge/jnlp/util/logging/headers/PluginHeader.java new file mode 100644 index 0000000..31ed19d --- /dev/null +++ b/netx/net/sourceforge/jnlp/util/logging/headers/PluginHeader.java @@ -0,0 +1,82 @@ +/* +Copyright (C) 2009, 2013 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. * + */ +package net.sourceforge.jnlp.util.logging.headers; + +import java.util.Date; +import java.util.regex.Pattern; + +public class PluginHeader extends Header { + + public boolean preinit; + public Date originalTimeStamp; + static final String PLUGIN_DEBUG = "plugindebug "; + static final String PLUGIN_DEBUG_PREINIT = "preinit_plugindebug "; + static final String PLUGIN_ERROR = "pluginerror "; + static final String PLUGIN_ERROR_PREINIT = "preinit_pluginerror "; + static final Pattern bracketsPattern = Pattern.compile("(\\]\\s*\\[)|(\\s*\\[)|(\\]\\s*)"); + static final Pattern whiteSpaces = Pattern.compile("\\s+"); + static final Pattern threadsPattern = Pattern.compile("\\s+|,\\s*|:"); + + @Override + public String toString() { + if (preinit) { + return "!" + super.toString(); + } else { + return super.toString(); + } + } + + @Override + public String toString(boolean userb, boolean originb, boolean levelb, boolean dateb, boolean callerb, boolean thread1b, boolean thread2b) { + if (preinit) { + return "!" + super.toString(userb, originb, levelb, dateb, callerb, thread1b, thread2b); + } else { + return super.toString(userb, originb, levelb, dateb, callerb, thread1b, thread2b); + } + } + + @Override + public String thread1ToString() { + return " ITNPP Thread# " + thread1; + } + + @Override + public String thread2ToString() { + return "gthread " + thread2; + } +} diff --git a/netx/net/sourceforge/jnlp/util/logging/headers/PluginMessage.java b/netx/net/sourceforge/jnlp/util/logging/headers/PluginMessage.java new file mode 100644 index 0000000..098d258 --- /dev/null +++ b/netx/net/sourceforge/jnlp/util/logging/headers/PluginMessage.java @@ -0,0 +1,94 @@ +/* +Copyright (C) 2009, 2013 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package net.sourceforge.jnlp.util.logging.headers; + +import java.util.Date; +import net.sourceforge.jnlp.util.logging.FileLog; +import net.sourceforge.jnlp.util.logging.OutputController; + +public class PluginMessage implements MessageWithHeader{ + + public PluginHeader header; + public String restOfMessage; + public boolean wasError = false; + + public PluginMessage(String orig) { + restOfMessage = orig; + header = new PluginHeader(); + String s = orig.trim(); + PluginHeader p = this.header; + try { + p.isC = true; + p.application = false; + if (s.startsWith("preinit_plugin")) { + p.preinit = true; + } + if (s.startsWith(PluginHeader.PLUGIN_DEBUG) || s.startsWith(PluginHeader.PLUGIN_DEBUG_PREINIT)) { + p.level = OutputController.Level.MESSAGE_DEBUG; + } else if (s.startsWith(PluginHeader.PLUGIN_ERROR) || s.startsWith(PluginHeader.PLUGIN_ERROR_PREINIT)) { + p.level = OutputController.Level.ERROR_ALL; + } else { + p.level = OutputController.Level.WARNING_ALL; + } + String[] init = PluginHeader.whiteSpaces.split(s); + p.originalTimeStamp = new Date(Long.parseLong(init[1]) / 1000); + String[] main = PluginHeader.bracketsPattern.split(s); + p.user = main[1]; + p.caller = main[5]; + p.date = FileLog.getPluginSharedFormatter().parse(main[4]); + String[] threads = PluginHeader.threadsPattern.split(main[6]); + p.thread1 = threads[2]; + p.thread2 = threads[4]; + int i = orig.indexOf(p.thread2); + restOfMessage = orig.substring(i + p.thread2.length() + 2); //+": " + } catch (Exception ex) { + OutputController.getLogger().log(ex); + this.wasError = true; + } + } + + @Override + public String getMessage() { + return restOfMessage; + } + + @Override + public Header getHeader() { + return header; + } +} |