2009
08.06
To use the Source Code HTML Formatter simpy do the following:
Include the code2webdisplay.jar file in your classpath
The API can be accessed in a simple way:
ISourceCodeParser parser = new JavaParser(); // This can also be: CPlusPlusParser, CSharpParser
parser.setCSSPath(”http://www.mysite.com/css/default.css”);
String html = parser.codeToHtml(new File(”c:/path/MyClass.java”));
Here is the code for the CSS file. Of course you may change the styles to whatever you like:
root {
display: block;
}
.keyword{
color:rgb(0,0,255);
font-family:’Arial’;
}
.comment{
color:rgb(0,255,0);
font-family:’Arial’;
}
.string{
color:rgb(255,0,0);
font-family:’Arial’;
}
.compiler_def{
color:rgb(0,200,50);
font-family:’Arial’;
}
.normal{
font-family:’Arial’;
}
body {
font-family: ‘Arial’; font-size:13
}
2009
08.06
This project offers a Java API for parsing source code written in C/C++, Java, C# and generating well formatted HTML. This allows developers to present their code on a web page and can be used in Servlets or JSP pages to dynamically generate HTML from source code files.
This project is written entirely in pure Java and no special JAR’s, J2EE stuff or third party libraries are required.
Download JAR file: code2webdisplay.jar
Download Sources (Java): code2webdisplay-src.rar
Documentation
Developed By: Shlomo Schwarcz
2009
08.06
How the Log4J Viewer works
Technologies
Language: Pure Java Script
UI Library: YUI
Architecture: 100% Client Side
Typically log files may contain thousands of lines and can be quite large. This is why the log4j viewer was designed to handle all processing on the client side so there is not client-server interaction at all. Another reason is security issues. Since log files might contain confidential information, users prefer not to send logging information across the network.
Limitations
There is no safe way to parse a log4j file according to its pattern. This is a kind of reverse engineering which is not possible.
Consider the following example:
Log pattern = “%t %m%n”
This means that each line will contain the thread name a white space and the message followed by a new line.
Now, say we have a message where
thread name = “worker 1” and message = “hello world”
The result will be “worker 1 hello world“.
But the parser won’t know where the thread name ends and where the message starts. It could be any of the following combinations:
“worker“, “1 hello world”
“worker 1“, “hello world”
“worker 1 hello“, “world”
So as you can see the main limitations are using pattern attributes that contain white spaces in them. So here is the list of limitations that might cause log4j viewer to work improperly:
- Message (%m) must be at the end of line
- Pattern must end with a new line break (%n)
- Multi line messages are not supported
- Attributes that might contain spaces: for example (%t) are problematic. You can use them if they don’t contain spaces (like thread names without white spaces) but if the log line will have an extra white space it will probably mess up the output table.
- Attributes that might be in the pattern but don’t always appear in the log: %x, %X usually work but might cause problems.
This seems like a long list of limitations but the log4j viewer does cover most common log4j cases.
So, enjoy!
Developed by: Shlomo Schwarcz