Teaching an old dog new Tricks

The Application Programming Interface and the OASIS Open Document Format

Teaching an old dog new Tricks

Postby DrewJensen » Sun Jun 01, 2008 5:14 am

new_dog.gif
new_dog.gif (8.93 KiB) Viewed 4425 times

Funny picture for the title, huh?

Well, let me explain it by way of saying this - I had two ideas for the title "Teaching an old dog new tricks" or "Teaching a new dog old tricks" - I decided to compromise.

Today, someone I call friend referred to me as a Luddite..jokingly, but the timing was perfect as they say.
Perfect as in "perfectly ironic" or as in "the start to a perfect storm" is yet to be seen. ( It had nothing to do with this little project by the way - it was because I had the audacity to say that when I think of the word Machine I think of Silicon...did I mention that I setup SUN's VirtualBox software on my machine today.)

OK - Enough silly metaphor, all this post is intended to do is allow you to follow along as I write my first OpenOffice.org uno component using the NetBeansTM IDE. The component is supposed to do one really simple thing. Allow an OOoBasic script to determine all the printers setup on the users machine. That's it.

To do it my plan is to let someone else do as much of the work as I possibly can - Who? Well, who ever wrote the Print Services library for Java.

Here then is my plan:
  1. Do the entire project using Linux ( Ubuntu Hardy ) [ I am not really a Linux guy yet..so it fits our metaphor ]
  2. Use Java [I already said that - but I not a Java programmer, so again the metaphor]
  3. Use the latest NetBeansTM Integrated Development Environment (IDE) - that would be 6.1 [maybe]
  4. Use the latest OpenOffice.org plugin for NetBeansTM
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Setting up NetBeans

Postby DrewJensen » Sun Jun 01, 2008 5:39 am

First thing to do is install the NetBeans IDE.

Like I said the current version that SUN has out is 6.1 - but remember I am using Canonical's Linux, Ubuntu 8.04 (Hardy) and running it on an HP PC with an AMD 64bit processor. I have SUN's Java Runtime installed for use with Canonical's build of OpenOffice.org and so far it seems to be running pretty good.

So, instead of just blindly downloading the SUN NetBeans I decided to see if there is a version for Ubuntu.

[Linux newbie tip] - To do this I used the Synaptic Package Manager supplied with the OS. You find this under the menu System>Administration>Synapitc Package Manager

After opening the package manager you are presented with a list of all this software that you can download from a repository that Canonical maintains...and it lits it all! So, the best way is to use the Search function and sure enough there it is: netbeans 6.0.1-0ubuntu2. Does this equal SUN 6.1 - no idea, haven't really figured out how you match canonical version numbers to other organizations version numbers. Only one way to find out I suppose...lets install it.

[Linux newbie tip] - to do this, you simply place a tick mark in the check box next to the package name - the package manager then determins if any other packages are needed to make what you want function.
Screenshot-Synaptic Package Manager .png
The screen shot doesn't show all the packages, only those that matched our search for the word netbeans, remember.

All you do now is click on the Apply button..and it is all automatic after that. When you do, a dialog box opens - just making sure that you really wanted to do this I suppose, and you can have it list details on what is about to be installed. Looking at that screen shot above it appears that only about a dozen other packages where going to be installed, but the detail information tells me that 34 items will be.
Screenshot-Summary.png


[Linux newbie tip] - Why the difference. The first screen shot was only showing me the files that matched the search I did for the word netbeans, remember.

Fine - 169 Megs total disk space, 56.7 Megs download...hmmm...not exactly lightweight huh...
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

The IDE - First contact

Postby DrewJensen » Sun Jun 01, 2008 6:23 am

OK - well the install went like clock work.

Let's fire her up and see what we have..

[Linux newbie tip] - The package manager also added a new menu item for the netbeans package under Applications>Programming>netbeans
Screenshot-NetBeans IDE 6.0.1.png


Well, sure enough it is Version 6.0.1, not the latest 6.1. What does that mean really. Well, I notice that 6.1 has this new feature, JavaScript Editor..with a video... Watched the videa and this looks really cool.
The voice of the guy on the video says he is an evangelist - When he is done talking I suppose I am to jump and yell "I believe!", but for now I can live without it.

So, in the spirit of single vendor sourcing...decide to stay with this Canonical supplied version .

Next thing - I want to install that plugin for creating OpenOffice.org extensions.
[Documentation Tip] - I can find specific information about it the OpenOffice.org wiki: OpenOffice NetBeans Integration

One thing the wiki page points out is that I also need the OpenOffice.org Software Development Kit. So, it is back to the Synaptic Package Manager once again. This time I search fo OpenOffice.org and sure enough there it is.

[Linux newbie tip] - The Canonical name for the package is "OpenOffice.org-dev", not OpenOffice.org SDK, but that is in the description. Remember I have the Canonical supplied version of OpenOffice.org 2.4 and therefore the Canonical supplied SDK makes sense.

While I am at it, I might as well install the docs file also.

[Documentation Tip] The latest copy of the Developers Guide is now maintained on the OpenOffice.org WIKI also at: OpenOffice.org Developers Guide

The detail dialog tells me that these two packages are going to take another 108 Megs of my disk space. Fine.

Back to NetBeans and lets install the plugin. To do this I select Tools>plugins from the netbeans menu. This opens the Plugins dialog and right off the bat it tell me that I have 6 plugins for which there are updates. Jees...this is where I get a little confused. I have the Canonical supplied netbeans will the updates be fine? Again only one way to find out...ok. install the updates.. ( I believe in staying current )

After the current plugins are updated then netbeans wants to restart...ok..and finally I am back to the Plugins dialog again. But this time when the Dialog opens it goes to the "Available Plugins" tab and sure enough there is the plugin I want in the middle of the list.
Screenshot-Plugins.png


Last step then...before I can think to begin, or begin to think. Tell the plugin where OpenOffice.org is installed and where the SDK is installed. The wiki page told me that I had to do that. Damn...remember I am not really a linux guy, where the hell is OpenOffice.org installed?
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Configure the OpenOffice.org betbeans plugin

Postby DrewJensen » Sun Jun 01, 2008 3:43 pm

Alright - well, time to finish setting up the netbeans plugin..

Following the instructions from the wiki page referenced yesterday I see that to finish the installation I need to tell the plugin where the local copy of OpenOffice.org and the SDK is located.
Select the netbeans menus ( The actual name of the plguin has changed slightly with the 1.1.x release under netbeans 6.x it turns out )
Tools -> Options -> Miscellaneous -> OpenOffice.org API Plugin Settings

Now - for those old time Linux users you are laughing at the final comment yesterday - Where is OpenOffice.org installed? But for someone coming from MS Windows that is a serious question. Turns out the real answer is dependent on which version of OpenOffice.org one is using. In my case it is the version that came with the OS, supplied by Canonical in other words, and for this the files can be found at /usr/lib/openoffice and the OpenOffice.org SDK again the one supplied by the Ubuntu repository is found at /usr/lib/openoffice/sdk

If on the other hand a person installs the OpenOffice.org packages found at the main web site http://download.openoffice.org that is not the case. Then the files will be found under the /opt directory. Now that is sooo obvious.

Anyway - That's done now.
Screenshot-Options.png


A little later this afternoon then I will try to perform the steps outlined in this article on the WIKI:
General UNO Component Project Type
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Finding a tutorial to work with...

Postby DrewJensen » Tue Jun 03, 2008 5:59 am

Well, didn't make it back for a post last night, sorry, but did get a chance to work with this a bit. When I decided to create this topic, during a discussion on the Base mailing list I said I'd let anyone that cared to watch me "BUMBLE" my way along...so no holding back..maybe should have said Bumble and Stumble... :)

Many, many years ago in a college course an instructor made a comment that has always stuck with me - "Every decision involves a trade off of some kind!"

Well this little project has already found one of the trade offs surrounding one of the decisions.

The decision: I would work on this project only under Linux ( Ubuntu 8.04 ) and I would use only the development tools supplied in the Ubuntu repositories.

The trade off: The development tools are not the most current releases.

The effect: Not everything is going to work as the examples available say they should.

Case in point -
The latest release of NetBeans on the Sun Server is 6.1, but the lastest version in the Ubuntu repository is 6.0.1.
If I had downloaded the SUN supplied NetBeans/JDK bundle I would have the actual Java Development Kit 1.6, but using the Ubuntu build it came with OpenJDK
Finally - the OpenOffice.org Plugin for NetBeans - if I had NB 6.1 then I would have version 1.1.2 of the plugin, but with 6.0.1 I apparently can only use 1.1.1 (beta) of the plugin.

What does that mean - overall, I don't know - last night it meant that the first example would not build until I figured out the bug that was in the plugin and not my code...a fun time for someone that doesn't really know the environment yet. Then again maybe it makes for an even better learning experience.

OK - here is what I did. First I went and looked at that example on the wiki for building an UnoComponent. First comment "WTFrack - Over!". Can do the first 2 steps and then it just leaves you hanging...fine I can imitate a deer in the head lights with the best of them when needs be...but being undaunted wen in search of a real tutorial..and I found it.

It is a hands on lab that was available at the Java-One conference this year called OpenOffice.org Extensions with NetBeans. If you register with the Sun Developers Network , then the lab material is available for download.

So - I did and I did. My first impression from running through, some not all, of the exercises is - if you are interested in learning this stuff then this is where you want to start.

OK - back to My Decision - the Trade Off - the Consequences

The very first exercise is to create a "OpenOffice Client Application" that 'eats' ODF documents and 'spits out' PDF documents.
[ POINT of confusion here - since SUN made me register to download the lab package I am not sure if I can post parts of it here...hmmm... well doesn't really matter I can show what I did, right]

Step one - create a new project. File>New project
Excellent on the new project dialog is the OpenOffice.org entry - just point click, and a couple of simple questions, like give the project a name and Voila it builds the basic project structure...
The attachment Screenshot-New Project.png is no longer available


This project now includes one source code file, consisting of:
Code: Select all   Expand viewCollapse view
/*
* DocumentConverter.java
*
* Created on 2008.05.02 - 23:49:50
*
*/

package com.example;

import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;

/**
*
* @author hardydrew
*/
public class DocumentConverter {
   
    /** Creates a new instance of DocumentConverter */
    public DocumentConverter() {
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
        }
        catch (java.lang.Exception e){
            e.printStackTrace();
        }
        finally {
            System.exit( 0 );
        }
    }
   
}


Wonderful - one small thing I noticed was that the code in my editor was a little bit, just a little, different from the code that was shown n the Lab documentation...and no the difference is not in the authors name alone...but hey that won't be a problem right... :|
new_dog2.gif
new_dog2.gif (5 KiB) Viewed 4307 times
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
DrewJensen
Volunteer
 
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest