Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/logging/BrowserAsLogSyncFactory.java

Diff revisions: vs.
  @@ -1,176 +1,176 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.logging;
3 -
4 - import org.litesoft.GWT.client.*;
5 - import org.litesoft.commonfoundation.typeutils.*;
6 - import org.litesoft.logger.*;
7 - import org.litesoft.logger.nonpublic.*;
8 -
9 - import com.google.gwt.user.client.*;
10 -
11 - public class BrowserAsLogSyncFactory implements ProxyLoggerFactory {
12 - public static final int MAX_LOG_LINES_TO_CACHE = 100;
13 -
14 - public static final BrowserAsLogSyncFactory INSTANCE = new BrowserAsLogSyncFactory();
15 -
16 - public static final Command COMMAND = new Command() {
17 - @Override
18 - public void execute() {
19 - BrowserAsLogSyncFactory.open();
20 - }
21 - };
22 -
23 - private BrowserAsLogSyncFactory() {
24 - }
25 -
26 - public static void open() {
27 - if ( (sOpen = openLogSyncBrowser( UtilsGwt.CHROMELESS_SCROLLED, CLIENT_LOGGING_HTML )) ) {
28 - sOpen = addToLogSyncBrowser( "" );
29 - while ( sOpen && sSavedLines.hasLines() ) {
30 - if ( (sOpen = addToLogSyncBrowser( sSavedLines.peekLine() )) ) {
31 - sSavedLines.dropLine();
32 - }
33 - }
34 - }
35 - }
36 -
37 - public static void log( String pText ) {
38 - if ( sOpen ) {
39 - if ( addToLogSyncBrowser( pText ) ) {
40 - return;
41 - }
42 - sOpen = false;
43 - }
44 - sSavedLines.add( pText );
45 - }
46 -
47 - private static LogLinkedList sSavedLines = new LogLinkedList();
48 - private static boolean sOpen = false;
49 -
50 - public static native boolean openLogSyncBrowser( String pFeatures, String pHTML ) /*-{
51 - $wnd.loggingWindow = $wnd.open( "", "", pFeatures );
52 - if ( !$wnd.loggingWindow )
53 - {
54 - return false;
55 - }
56 - $wnd.loggingWindow.document.write( pHTML );
57 - $wnd.loggingWindow.document.close();
58 - return true;
59 - }-*/;
60 -
61 - public static native boolean addToLogSyncBrowser( String pText )/*-{
62 - if ( $wnd.loggingWindow )
63 - {
64 - try
65 - {
66 - var zThierLog = $wnd.loggingWindow.appendToLog;
67 - if ( zThierLog )
68 - {
69 - zThierLog( pText );
70 - return true;
71 - }
72 - }
73 - catch ( e )
74 - {
75 - }
76 - $wnd.loggingWindow = null;
77 - }
78 - return false;
79 - }-*/;
80 -
81 - private static class LogLinkedList {
82 - private int mNodes = 0;
83 - private Node mHead = null;
84 - private Node mTail = null;
85 -
86 - public boolean hasLines() {
87 - return (mNodes != 0);
88 - }
89 -
90 - public String peekLine() {
91 - return (mHead != null) ? mHead.getText() : null;
92 - }
93 -
94 - public void dropLine() {
95 - if ( hasLines() ) {
96 - mNodes--;
97 - if ( null == (mHead = mHead.getNext()) ) {
98 - mTail = null;
99 - }
100 - }
101 - }
102 -
103 - public void add( String pText ) {
104 - if ( mTail == null ) {
105 - mHead = mTail = new Node( pText );
106 - } else {
107 - mTail = mTail.add( pText );
108 - }
109 - if ( ++mNodes > MAX_LOG_LINES_TO_CACHE ) {
110 - mNodes--;
111 - mHead = mHead.getNext();
112 - }
113 - }
114 -
115 - private static class Node {
116 - private Node mNext = null;
117 - private String mText;
118 -
119 - public Node( String pText ) {
120 - mText = pText;
121 - }
122 -
123 - public Node getNext() {
124 - return mNext;
125 - }
126 -
127 - public String getText() {
128 - return mText;
129 - }
130 -
131 - public Node add( String pText ) {
132 - return mNext = new Node( pText );
133 - }
134 - }
135 - }
136 -
137 - private static final String CLIENT_LOGGING_HTML = "<html><head><title>Client Side Log</title><script>\n" + //
138 - "function appendToLog( pLogEntry )\n" + //
139 - "{\n" + //
140 - " var myBody = document.body;\n" + //
141 - " var preNode = document.createElement( 'pre' );\n" + //
142 - " preNode.style.margin = '0';\n" + //
143 - " myBody.appendChild( preNode );\n" + //
144 - " var txtNode = document.createTextNode( pLogEntry );\n" + //
145 - " preNode.appendChild( txtNode );\n" + //
146 - " document.close();\n" + //
147 - "}\n" + //
148 - "</script></head><body style='margin:0; padding:0;'>" + //
149 - "<center>Client Side Logging<br>" + //
150 - "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " +
151 - "- - - - - -" +
152 - "</center></body></html>";
153 -
154 - @Override
155 - public ImplLoggerAdapter createImplLoggerAdapter( int pLevel, String pClassname ) {
156 - return new Logger( pLevel, pClassname );
157 - }
158 -
159 - private static class Logger extends SystemOutLoggerAdapter {
160 - public Logger( int pLevel, String pClassname ) {
161 - super( LoggerLevel.LEVELS[pLevel], pClassname );
162 - }
163 -
164 - @Override
165 - protected void println( Throwable pThrowable ) {
166 - super.println( pThrowable );
167 - BrowserAsLogSyncFactory.log( Throwables.printStackTraceToString( pThrowable ) );
168 - }
169 -
170 - @Override
171 - protected void println( boolean pHasThrowable, String pText ) {
172 - super.println( pHasThrowable, pText );
173 - BrowserAsLogSyncFactory.log( pText );
174 - }
175 - }
176 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.logging;
3 +
4 + import org.litesoft.GWT.client.*;
5 + import org.litesoft.commonfoundation.typeutils.*;
6 + import org.litesoft.logger.*;
7 + import org.litesoft.logger.nonpublic.*;
8 +
9 + import com.google.gwt.user.client.*;
10 +
11 + public class BrowserAsLogSyncFactory implements ProxyLoggerFactory {
12 + public static final int MAX_LOG_LINES_TO_CACHE = 100;
13 +
14 + public static final BrowserAsLogSyncFactory INSTANCE = new BrowserAsLogSyncFactory();
15 +
16 + public static final Command COMMAND = new Command() {
17 + @Override
18 + public void execute() {
19 + BrowserAsLogSyncFactory.open();
20 + }
21 + };
22 +
23 + private BrowserAsLogSyncFactory() {
24 + }
25 +
26 + public static void open() {
27 + if ( (sOpen = openLogSyncBrowser( UtilsGwt.CHROMELESS_SCROLLED, CLIENT_LOGGING_HTML )) ) {
28 + sOpen = addToLogSyncBrowser( "" );
29 + while ( sOpen && sSavedLines.hasLines() ) {
30 + if ( (sOpen = addToLogSyncBrowser( sSavedLines.peekLine() )) ) {
31 + sSavedLines.dropLine();
32 + }
33 + }
34 + }
35 + }
36 +
37 + public static void log( String pText ) {
38 + if ( sOpen ) {
39 + if ( addToLogSyncBrowser( pText ) ) {
40 + return;
41 + }
42 + sOpen = false;
43 + }
44 + sSavedLines.add( pText );
45 + }
46 +
47 + private static LogLinkedList sSavedLines = new LogLinkedList();
48 + private static boolean sOpen = false;
49 +
50 + public static native boolean openLogSyncBrowser( String pFeatures, String pHTML ) /*-{
51 + $wnd.loggingWindow = $wnd.open( "", "", pFeatures );
52 + if ( !$wnd.loggingWindow )
53 + {
54 + return false;
55 + }
56 + $wnd.loggingWindow.document.write( pHTML );
57 + $wnd.loggingWindow.document.close();
58 + return true;
59 + }-*/;
60 +
61 + public static native boolean addToLogSyncBrowser( String pText )/*-{
62 + if ( $wnd.loggingWindow )
63 + {
64 + try
65 + {
66 + var zThierLog = $wnd.loggingWindow.appendToLog;
67 + if ( zThierLog )
68 + {
69 + zThierLog( pText );
70 + return true;
71 + }
72 + }
73 + catch ( e )
74 + {
75 + }
76 + $wnd.loggingWindow = null;
77 + }
78 + return false;
79 + }-*/;
80 +
81 + private static class LogLinkedList {
82 + private int mNodes = 0;
83 + private Node mHead = null;
84 + private Node mTail = null;
85 +
86 + public boolean hasLines() {
87 + return (mNodes != 0);
88 + }
89 +
90 + public String peekLine() {
91 + return (mHead != null) ? mHead.getText() : null;
92 + }
93 +
94 + public void dropLine() {
95 + if ( hasLines() ) {
96 + mNodes--;
97 + if ( null == (mHead = mHead.getNext()) ) {
98 + mTail = null;
99 + }
100 + }
101 + }
102 +
103 + public void add( String pText ) {
104 + if ( mTail == null ) {
105 + mHead = mTail = new Node( pText );
106 + } else {
107 + mTail = mTail.add( pText );
108 + }
109 + if ( ++mNodes > MAX_LOG_LINES_TO_CACHE ) {
110 + mNodes--;
111 + mHead = mHead.getNext();
112 + }
113 + }
114 +
115 + private static class Node {
116 + private Node mNext = null;
117 + private String mText;
118 +
119 + public Node( String pText ) {
120 + mText = pText;
121 + }
122 +
123 + public Node getNext() {
124 + return mNext;
125 + }
126 +
127 + public String getText() {
128 + return mText;
129 + }
130 +
131 + public Node add( String pText ) {
132 + return mNext = new Node( pText );
133 + }
134 + }
135 + }
136 +
137 + private static final String CLIENT_LOGGING_HTML = "<html><head><title>Client Side Log</title><script>\n" + //
138 + "function appendToLog( pLogEntry )\n" + //
139 + "{\n" + //
140 + " var myBody = document.body;\n" + //
141 + " var preNode = document.createElement( 'pre' );\n" + //
142 + " preNode.style.margin = '0';\n" + //
143 + " myBody.appendChild( preNode );\n" + //
144 + " var txtNode = document.createTextNode( pLogEntry );\n" + //
145 + " preNode.appendChild( txtNode );\n" + //
146 + " document.close();\n" + //
147 + "}\n" + //
148 + "</script></head><body style='margin:0; padding:0;'>" + //
149 + "<center>Client Side Logging<br>" + //
150 + "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " +
151 + "- - - - - -" +
152 + "</center></body></html>";
153 +
154 + @Override
155 + public ImplLoggerAdapter createImplLoggerAdapter( int pLevel, String pClassname ) {
156 + return new Logger( pLevel, pClassname );
157 + }
158 +
159 + private static class Logger extends SystemOutLoggerAdapter {
160 + public Logger( int pLevel, String pClassname ) {
161 + super( LoggerLevel.LEVELS[pLevel], pClassname );
162 + }
163 +
164 + @Override
165 + protected void println( Throwable pThrowable ) {
166 + super.println( pThrowable );
167 + BrowserAsLogSyncFactory.log( Throwables.printStackTraceToString( pThrowable ) );
168 + }
169 +
170 + @Override
171 + protected void println( boolean pHasThrowable, String pText ) {
172 + super.println( pHasThrowable, pText );
173 + BrowserAsLogSyncFactory.log( pText );
174 + }
175 + }
176 + }