Saturday, May 28, 2011

PMD Maven problem

Can't use generics unless running in JDK 1.5 mode!
Can't use annotations when running in JDK 1.4 mode!

Just add
1.5

to properties tag in Maven pom file.



<properties>
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
<compileSource>1.5</compileSource>
<targetJdk>1.5</targetJdk>
</properties>

Friday, May 27, 2011

Generating html from xml using xsl


<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}

function displayResult()
{
xml=loadXMLDoc("findbugsXml.xml");
xsl=loadXMLDoc("fancy.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById("example").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(resultDocument);
}
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
</html>

Converting raw html to escaped html

Converting raw html to escaped html
Add formatting to code in blogger

maven reports


<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<links>
<link>http://java.sun.com/j2se/1.5.0/docs/api</link>
</links>
</configuration>
</plugin>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.0</version>
</plugin>
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.4</version> <reportSets> <reportSet> <reports> <report>dependencies</report>
<report>project-team</report> <report>mailing-list</report> <report>cim</report>
<report>issue-tracking</report> <report>license</report> <report>scm</report>
</reports> </reportSet> </reportSets> </plugin> -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.3-SNAPSHOT</version>
</plugin>

</plugins>
</reporting>


Maven Build targets
mvn findbugs:findbugs
mvn jxr:test-jxr
mvn jxr:jxr
mvn surefire-report:report
mvn surefire:tests
mvn checkstyle:checkstyle
mvn project-info-reports:dependencies
mvn project-info-reports:cim
mvn project-info-reports:index
mvn javadoc:javadoc
mvn site:run
mvn help:effective-pom

java code to transform xml to html using xsl



package com.trans;

import javax.xml.transform.*;
import java.net.*;
import java.io.*;

public class HowToXSLT {
public static void main(String[] args) {
try {

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer transformer =
tFactory.newTransformer
(new javax.xml.transform.stream.StreamSource
("C:\\xampp\\htdocs\\s3\\fancy-hist.xsl"));

transformer.transform
(new javax.xml.transform.stream.StreamSource
("C:\\xampp\\htdocs\\s3\\findbugsXml.xml"),
new javax.xml.transform.stream.StreamResult
( new FileOutputStream("C:\\howto.html")));
}
catch (Exception e) {
e.printStackTrace( );
}
}
}