Pledgie



if you think this library has been useful, feel free to give any help. Don't be shy.


Click here to lend your support to: Java2word, coding for fun! and make a donation at www.pledgie.com !

Wednesday, February 5, 2014

java2word soon in github

It is time!!!

I am gonna move this library to Github to allow better collaboration.

Url will be: https://github.com/leonardoanalista/java2word

I will perform the changes in a couple of days.


I am now doing front-end development. So I don't have enough time to maintain the code base. Collaborators are welcome!


Leonardo Correa

Friday, February 10, 2012

huge ms word documents with java2word

Someone a while ago asked if Java2word can generate huge MS Word documents. I guess the limit is on the MS Word itself and space on your hard-disk.

Take a look at the screenshot:

There are 187 pages on this document. I also opened on Word Viewer running on Linux Ubuntu via Wine.

This is the code that generates this document:


        IDocument myDoc = new Document2004();
        TableV2 tbl = new TableV2();
        
        tbl.addRow( TableRow.with("Table Header in all Pages", "Usefull for reports").withStyle().repeatTableHeaderOnEveryPage().create() );
        
        tbl.addRow( TableRow.with("Simple String cell", "Another simple String cell") ); 
        tbl.addRow( TableRow.with( TableCell.with(Paragraph.with("TableCell- Style to the whole cell, Par").create()), "Simple String" ).withStyle().bold().create() );
        tbl.addRow( TableRow.with("Style to the whole cell, Str", "String").withStyle().bold().create() );
        tbl.addRow( TableRow.with( TableCell.with(Paragraph.with("TableRowV2 with merge").create()).withStyle().gridSpan(2).create() ).withStyle().bold().create() );
        tbl.addRow( TableRow.with( TableCell.with(Paragraph.withPieces( ParagraphPiece.with("Paragraph with Style inside TableCell").withStyle().bold().fontSize("20").create() ).create()).withStyle().bgColor("00FFFF").create(), "String"  ));
        
        String img = Image.from_WEB_URL("http://www.google.com/images/logos/ps_logo2.png").setHeight("100").setWidth("300").create().getContent();
        tbl.addRow( TableRow.with("this google logo: ", "Image here: "+ img + " == image before") );
        
        for (int i = 0; i < 8000; i++) {
            tbl.addRow( TableRow.with("111 ", "222") );            
        }
        
        tbl.addRow( TableRow.with("LAST", "LAST") );            
                
        myDoc.addEle(tbl.getContent());

By the way this is the new Table V2 (coming soon, thanks Fabio Cordeiro) where you'll be able to apply style and do a lot more with it.

cheers

Leonardo Correa

Wednesday, February 1, 2012

java2word version 3.1 released


============= Version 3.1 - 01-Feb-2012  =============

Applied patch for Identation and hiperlinks by whoahbot, Added some comments on methods, work in progress for special characters in Utils.java.


    - Issue 70: Created a method on Utils.class called replaceSpecialCharacters. This is under experiments.
    - Issue 82: Alternative for those who want to use paragraphs in table.
              Now you can NOT pass null to a table cell, which doens't make sense anyway. You have to pass "".
     
    - Issue 46:   Adding indentation
    - Issue 45:   Adding hyperlinks to the document
   
    - Removed all deprecated methods

Upgrade steps:
    - download this version or checkout the latest code and build your own jar file.

Download it here:

http://java2word.googlecode.com/files/java2word-3.1.jar


cheers
Leonardo Correa

Tuesday, January 24, 2012

java2word new website

I have moved all documentation to this blog. Issues and SVN source code will remain in google code for a while.

checkout the new java2word doc page: http://java2word.blogspot.com/p/documentation.html

What else will this change cause?
  • Blogger provides a very good mobile version of the blog (I am a Mobile Web Developer!)
  • Better user interface, templates and colors are easy to modify
  • Separate my own things from java2word

Project will always be open source and fully free.


cheers
Leonardo Correa

Tuesday, October 25, 2011

Web Mobile iPhone and Androids Inconsistencies

As I wrote in my profile, I am currently working as a Web Mobile Developer, focussed on high-end devices and will start to share my experiences and hacks to get the work done.

It has been a great experience working with HTML5, CSS3 and Javascript. Most people thinks this is all about rounded corner divs but we can build powerful web mobiles applications with HTML5 and CSS3.

Therefore nothing comes without some reasonable hassle. If you were one that complains about inconsistence on standard web site like Internet Explorer versus firefox, you need relax. You should be really happy where you are.

Web Mobiles is ten times more inconsistent than web for desktop. IPhones run safari mobile, which is not the same as safari desktop.  Androids behave slightly differently over device manufacturers (Eg.: annoying -webkit-tap-highlight-color css3 property) and totally different from iPhones.  


Please don't get me wrong: I love mobiles! that's why I didn't kill myself when I found out that safari mobile does not implement fixed position, neither div overlay scroll.

Can you do anything on web for desktop without fixed position and overflow scroll? In mobiles we have to do it. Find a good work-around is part of your role.

Worse yet, here comes safari mobile - the new Internet Explorer headache in mobiles.


But there are things that both iPhone and Androids sucks:

input type="search"

This code is supposed to give you that "clear on demand", the same on iphone apps but without any extra code. This is specified on HTML5 but they don't implement it.


Safari mobile does not implement overflow scroll for divs. Luckily there is the fantastic iScroll (http://cubiq.org/iscroll-4) that "fixes" this problem.


There are consistent things as well like geoLocation:
    navigator.geolocation.getCurrentPosition(foundLocationFunc, noLocationFunc); 
works for both devides and in a second you'll .


Next time I will share how to implement like a centralized spinner with a full screen semi-transparent overlay locking the page background. There are some tricks when the page is bigger than the screen and you have scroll.

Later on, I will share how to use full screen for iphone, take the most of this huge screen height.


cheers
Leonardo

Saturday, February 19, 2011

Java2word covariant return type

When I was studying for SCJP exam, in 2007, I had to learn a lot of things that didn't make sense and I thought that I would never use. 

Today, in my Java2word library, I utilized Covariant Return Type.

This basically is when you override some method, you can return any subtype of the original return type. Eg.:

The class ParagraphPieceStyle extends AbstractStyle and overrides the method create().

public abstract class AbstractStyle implements ISuperStylin {

    private IElement element;
   
    public void setElement(IElement element) {
        this.element = element;
    }
   
    public IElement create() {
        return this.element;
    }
   
}

public class ParagraphPieceStyle extends AbrstractStyle{

    @Override
    public ParagraphPiece create() {
        return (ParagraphPiece) super.create();
    }

}


The original return type is "IElement" but returns "ParagraphPieceStyle".The advantage of this is the flexibility to return any subtype of the original type.

this is the code without Covariant:

ParagraphPiece myParPiece01 = (ParagraphPiece) ParagraphPiece.with("...");


This is with covariant:

ParagraphPiece myParPiece01 = ParagraphPiece.with("..."); 

Now I don't need to do a type cast (downcast) of the type.





cheers

Leonardo Correa

Tuesday, November 30, 2010

best vi vim macvim command reference

I have recently started using MacVim for my Ruby stuff I write for fun. It is amazing things you can do using this text editor combined with all those plugins.

I installed Janus version (https://github.com/carlhuda/janus) of MacVim and turned it to a proper IDE for ruby code.

I found this website that has absolutely everything about vi - best VI reference:
http://www.rayninfo.co.uk/vimtips.html

I use Janus on Linux as well and works perfectly as well.


cheers

Leonardo

Monday, November 22, 2010

Java Sun JDK 1.5 or 1.6 no Ubuntu 10.10 or 11.04 (updated: 01 Jun 2011)

As we know, Java 1.5 has not been maintained anymore and Java 6, has been hanging around for a while and Java 7 is coming soon. But it doesn't mean everybody has to move on to Java 1.6. The problem in Ubuntu is they force you to use OpenJDK. Worse yet, they don't let you downgrade to 1.5.

There are lots of legacy systems running on Java 5 and we can't forget that. It is also about freedom of choice. If you want to install Sun JDK 5 or 6 Ubuntu should not make your life difficult.

Ubuntu 10 and 11 don't allow us to natively (or easily) install Sun JDK's via apt-get.

It is so frustrate when we try to install it on Ubuntu 10.10 and have no luck:

sudo apt-get install sun-java5-jdk (or sudo apt-get install sun-java6-jdk)

After installed, the JDK will go to this directory: /usr/lib/jvm/java-6-sun

You can see all JDK's installed running the following command:

sudo update-java-alternatives -l


After a while, finally got the solution for this:

sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse"

sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse"

sudo apt-get update

sudo apt-get install sun-java5-jdk



Check it out just to confirm:

sudo update-java-alternatives -l


The commands above worked for me in Ubuntu 10 and 11, installing Sun JDK 1.5 and 1.6.
If it doesn't work, try to add the following repositories and repeat the process: (anonymous suggestion - thanks a lot):

sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse"
sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates multiverse"


Cheers

Leonardo

Thursday, July 22, 2010

Java2Word Microsoft Word Document Generator from Java code without any "special" components or libraries

I had a problem in my work a few weeks ago which was how to generate one Microsoft Word Document from Java code. Reports were composite by 40 pages around and over 30 database queries to bring data. It also had cover page, table of contents, header, footer and many tables.

We tried a lot of things but they were all crap solution. We had to delivery those "word" reports so the solution was pretty bad: Generate Jasper RTF and open as an Word Document.

When you open this rtf, the result is just horrible. You can't properly edit those dodge tables generated by jasper. Other problem is when you save this document as .doc, file size increased from 5 MB to 40 MB.

So... there were I again... playing around with the problem...

I decide to create an API in Java to generate Word documents from Java code. The Document generated HAS to be compatible with Microsoft Word and can't have any manipulation - so has to be ready for the end user!

I wrote two implementations: one for Word 97 - 2003 and another for Word 2004 +.

To be honest I spent more time in W2004 because this is the current standard.

I have created the java project and hosted in Google code:

http://code.google.com/p/java2word/

The philosophy is have something in Java and really easy like:

   IDocument myDoc = new Document2004();
myDoc.getBody().addEle(new Heading1("Heading01"));
myDoc.getBody().addEle(new Paragraph("This is a paragraph..."));



You are Java dev and deal with this API. You Don't need to worry about the implementation!

*Project has 97% of code test coverage.

** When I say no "special" components I mean not using any MS library.
In order to use the Java2Word you will need in your classpath xstream (if you use images) and log4j (for other than JBoss server).
Please refer to dependencies section in the project page.


Sunday, May 30, 2010

SQL Server performs very well on data warehouse

I personally don't like .net, ms office, windows and all this shit. Maybe because I love open source, Linux, Java, Mac.

In a data warehouse project, we utilized MySql as first option but the database was considerably slow with 90 Gigabytes database (We are using "star schema" for the data warehouse).

In order to solve this problem, the database was switched to SQL Server . After the initial historical loading, the SQL Server database has got 460 Gigabytes of data and I am very impressed with the response time.

Considering the amount of data processed, I have to admit that SQL Server is a great database for huge data warehouse projects.

It is difficult to sit on your hands when the SQL Server performs comfortably well in a 460 GB database.

Friday, August 14, 2009

java.lang.OutOfMemoryError: PermGen space, JBoss running JBoss Seam

Who has never faced to "java.lang.OutOfMemoryError: PermGen space" using JBoss Application Server and JBoss Seam Framework?

I have faced to this problem more frequently in production environment because the application has expanded considerably. I remember I had the same problem in Brazil when we were doing our final project of Post Graduate APGS at PUC University. When I got this job, the fist thing I did was change JVM settings to fix this problem in my workstation.

You are going to see in many sites and blogs people saying that increasing the PermSize will solve the problem. This way you just postpone this exception.

By default, the Collect Garbage cleans the Heap but does NOT clean the Permanent Generation.

The default value for PermSize is 64 MB which is not enough neither for development nor production environment. You definitely should not use the default configuration for professional applications involving JBoss Application Server and JBoss Seam Freamework.

The only way to really resolve this issue is enabling CG to clean the Permanent Generation space as well.

I haven't had this problem since I started using those configuration:

-Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000


I run JBoss in my computer inside Eclipse but if you run outside or for production environment you have to put those parameters on the file JBOSS_HOME/bin/run.conf .

#
# Specify options to pass to the Java VM.
#
if [ "x$JAVA_OPTS" = "x" ]; then
#JAVA_OPTS="-Xms1024m -Xmx1024m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"
JAVA_OPTS="-Xms1024m -Xmx1024m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -XX:PermSize=192m -XX:MaxPermSize=192m -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled"
fi

I am sure you will never see PermGen space again!

cheers
Leonardo Pinho Correa
Java Analyst/Developer, soccer player and beer drinker