My blog has moved! Redirecting...

You should be automatically redirected. If not, visit http://mindsiview.wordpress.com/ and update your bookmarks.

Monday, September 18, 2006

Installing Eventum on Windows XP

A few weeks ago I posted and entry about installing the MySQL Eventum project on Mac OS X. Having successfully created an Eventum test environment on my Mac, I needed to install a production instance of it on a Windows XP VMware server. As it turns out, this process can prove rather difficult unless you follow the steps below.

Step 1: Install Apache 2.0

Installing Apache 2.0 is fairly straightforward. It is important to note that as of this post, the current version of PHP (5.1.6) does not yet support Apache 2.2. Save yourself some grief and load Apache 2.0.

Step 2: Install MySQL 5.0

Installing MySQL is the simplest of all the steps. No special configuration needs to be done. I would recommend installing the MySQL Tools also.

Step 3: Install PHP 5.1.6

I'm embarrassed to say that this turned out to be the most difficult step of the process...that is until I realized that this PHP version does not run with Apache 2.2. After installing PHP, you will need to modify the following:

  • httpd.conf. This file is found in your Apache folder. Add the following lines to the end of the file:
    # PHP
    LoadModule php5_module d:/php5.1.6/php5apache2.dll
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php-source .phps
    PHPIniDir "c:/php5.1.6" (or whatever directory you loaded php in)
    
  • php.ini. This file is found in your PHP folder. Add a doc_root line. It should look something like the following:
    doc_root ="C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
    
    Take the ";" (denotes a comment in PHP) from in front of the following lines:
    extension=php_gd2.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll
    
If any of these lines do not exist, add them.

Step 4: Install Eventum

After you download Eventum, unzip it to the htdocs folder of your Apache installation. To start the installation process, go to your browser and type the URL of the Eventum site in the address line. It should look something like this: "//localhost/eventum-1.7.1/".

Once the installation is complete modify the following line in the config.inc file (found in the Eventum directory):

from

@define("APP_COOKIE_DOMAIN", APP_HOSTNAME);

to

@define("APP_COOKIE_DOMAIN", NULL);

Best of luck! Let me know if you have any problems with this. R

Saturday, September 02, 2006

New Blog Format

Those of you who have visited before may have noticed a change in the format of my blog. Having grown weary of making java code examples fit within the confines of Blogger's supplied templates, I decided to create one that better suits my needs. While not necessarily the most aesthetically pleasing blog ever, it is more practical for showing code examples.

Monday, August 28, 2006

Exporting JTable data to Excel

Recently I wanted to find a way to export JTable data to Excel. I found an excellent example of how to do this in Swing Hacks by Joshusa Marinacci and Chris Adamson. The authors show an example of saving JTable data to a tab delimited file with a ".xls" extension. The file can then be opened by Excel and converted to a spreadsheet.

I liked their approach, but I also wanted to provide the capability to launch Excel with the file opened in it as I've seen in other applications. So, I added some code to create a JPopupMenu component with options for saving the data or opening in Excel.

I also wanted to keep Excel from converting product numbers (specifically ISBN numbers) to numeric data in the spreadsheet. The reason for this is that leading zeros can be part of an ISBN.

My example along with the Marinaccci's and Admanson's JTable to Excel code follows. One caveat, I offer no explanation of the authors' code. After all, it's in their book. For a complete explanation see Swing Hacks. It is an excellent book full of tricks that every Swing developer should have.

Enjoy.

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import java.io.*;
import javax.swing.table.*;


public class ExcelTest {

 /**
  * @param args
  */
 public static void main(String[] args) {
//  An array of book titles and their associated ISBN numbers
  String [][] data = {
    {"Summerall","0785214925"},
    {"The Secret Message of Jesus","084990000X"},
    {"Buck Wild","159555064X"},
    {"25 Ways to Win with People","0785260943"},
    {"Aesop and the CEO ","0785260102"},
    {"ALL Business is Show Business ","0785206086"},
    {"Becoming A Person of Influence","0785271007"},
    {"Checklist for Life for Leaders","0785260013"},
    {"Duct Tape Marketing ","078522100X"},
    {"38 Values to Live By ","0849916631"},
    {"Blue Moon","0785260641"},
    {"Blue Like Jazz ","9780785263708"},
    {"Wild at Heart ","0785262989"},
    {"Wild Men, Wild Alaska ","078521772X "},
    {"The Duct Tape Bible, NCV","0718018249"}
  };
  String [] headers = {"Title","ISBN"};
  final JFrame frame = new JFrame("JTable to Excel Hack");
  DefaultTableModel model = new DefaultTableModel(data,headers);
  final JTable table = new JTable(model);
  JScrollPane scroll = new JScrollPane(table);

//  my JPopupMenu component
  final JPopupMenu popup = new JPopupMenu();

//  the save JMenuItem and its associated ActionListener
  JMenuItem save = new JMenuItem("save to file");
  save.addActionListener(new
    ActionListener() {
   public void actionPerformed(ActionEvent action){
    try {
     ExcelExporter exp = new ExcelExporter();
     exp.exportTable(table, new File("results.xls"));
    }
    catch (IOException ex) {
     System.out.println(ex.getMessage());
     ex.printStackTrace();
    }
   }
  });
  popup.add(save);

//  The open JMenuItem and its associated ActionListener
  JMenuItem open = new JMenuItem("open in Excel");
  open.addActionListener(new
    ActionListener() {
   public void actionPerformed(ActionEvent action){
    try {
//     Note that i'm actually saving the file first
     ExcelExporter exp = new ExcelExporter();
     File file = new File("results1.xls");
     exp.exportTable(table, file);
     ExcelOpener opn = new ExcelOpener();
     opn.openTable(file);
    }
    catch (IOException ex) {
     System.out.println(ex.getMessage());
     ex.printStackTrace();
    }

   }
  });
  popup.add(open);

//  the following method only works in JDK 5.0 or greater
//  table.setComponentPopupMenu(popup);

  JLabel label1 = new JLabel("Right Click to Export Data...", JLabel.CENTER);

//  the following code is needed for JDK 1.4
  table.addMouseListener(new MouseAdapter() {
   public void mousePressed(MouseEvent event){
    if(popup.isPopupTrigger(event)){
     popup.show(event.getComponent(), event.getX(),event.getY());
    }
   }
   public void mouseReleased(MouseEvent event){
    if(popup.isPopupTrigger(event)){
     popup.show(event.getComponent(), event.getX(),event.getY());
    }
   }
  });

  frame.getContentPane().add("Center",scroll);
  frame.getContentPane().add("South",label1);
  frame.pack();
  frame.setVisible(true);
 }
}
class ExcelExporter {
 public ExcelExporter() {}
 public void exportTable(JTable table, File file) throws IOException {
  TableModel model = table.getModel();
  FileWriter out = new FileWriter(file);

  for(int i=0; i < model.getColumnCount();i++) {
   out.write(model.getColumnName(i)+"\t");
 }
 out.write("\n");
 
 for(int i=0; i < model.getRowCount();i++){
  for(int j=0;j < model.getColumnCount();j++){
//   I added this check for the ISBN conversion
   if(j==0) {
//    the book Title
    out.write(model.getValueAt(i,j).toString() + "\t");
   } else {
/*
the ISBN Number
Note that I added a \" to the front of the string
and a \t followed by a closing \" to let Excel know
that this field is to be converted as text
     */
    out.write("\""+model.getValueAt(i, j).toString()+"\t"+"\"");
   }
  }
  out.write("\n");
 }
 out.close();
 System.out.println("write to " + file);
}
}
class ExcelOpener {
 public ExcelOpener() {}
 public void openTable(File file) throws IOException {
  Runtime run = Runtime.getRuntime();
//  I make the assumption that the client has Excel and
//  the file type .XLS is associated with Excel

//  This is a simple check to find out the operating system
  String lcOSName = System.getProperty("os.name").toLowerCase();
  boolean MAC_OS_X = lcOSName.startsWith("mac os x");
  if(MAC_OS_X){
   run.exec("open "+ file);
  } else {
   run.exec("cmd.exe /c start " + file);
  }
  System.out.println(file + " opened");
 }
}

Saturday, August 26, 2006

A Mac in a Windows World

Remember that Mac commercial, no not that one, the other one. I'm talking about the one where the PC and Mac are holding hands to show how compatible they are. Never mind the disturbing image of the young woman pulling a picture from her backside. Nope, I'm talking about the compatibility thing. In general the Macs are compatible, but there are some challenges to running a Mac in a Windows world.

Issue 1: WINS (Windows Internet Naming Service). Like DNS, WINS provides a way to name network devices such as servers and printers instead of referring to them by an IP address. Why does this matter? It makes life easier for us IT guys...and ultimately easier for you.

Using WINS not only makes it easier to find and categorize network devices (much like typing a URL in your browser as opposed to typing the IP address), it also makes it easier to manage the network. You see, IT guys are constantly tweaking the network to do things like add and remove servers, update segments, and move equipment from one location to another.

What does this have to do with the Mac? Well, Macs don't always recognize WINS names, sometimes you have to use the IP address or create a host file that contains both the WINS name and associated IP address. What's the big deal? The big deal is that every time the a network device you're connecting to changes IP addresses in the network, WINS is updated and Windows PCs don't know the difference. You, on the other hand, have to make the corresponding network changes on the Mac.

Issue 2: Windows Network Password Expiration. If your company is like ours it has a password expiration policy. This policy requires passwords to periodically expire, forcing you to create a new one. Now I know that you believe that the only reason your company has this policy is because your IT department is evil. While I can't speak about the intent of your IT department, the reason this policy exists is that it helps reduce incidents of hacking. It's also required by your auditors.

Now, the Mac is blissfully unaware of the Windows network password expiration policy. When your Windows network password expires, the first time you find out about it is when you try to connect to a network device. And, you don't get the opportunity to change your password. Instead, you have to find a Windows PC and us it to change your password.

One solution to this problem is to set to set the Mac users' passwords to never expire. As an evil IT guy (insert maniacal laughter here), I personally think this is a poor practice.

Issue 3: Fantasy Football Live Draft Applications. This is undoubtedly the most egregious compatibility issue. Tonight while trying to access my fantasy football league's draft I found out that the live draft app didn't work correctly. Fortunately I was able to use my wife's Windows XP laptop and all was well.

----------
Lest you think I'm dissing the Macs, I'm not really. My primary business computer is a MacBook Pro. I'm just pointing out some of the challenges IT departments face as Macs become more popular in the corporate world. If you've resolved some of these issues I'd love to hear from you. Also, as I find solutions I'll pass them along.

In the meantime, I wonder if there's a way I can steal Shaun Alexander for my fantasy football team...

Tuesday, August 22, 2006

Installing Eventum on Mac OS X

Last weekend while attempting to install Eventum, a MySQL/PhP based issues tracking system, on my Mac, I ran into a common problem. I say common because of the number of questions I found on the web relating to it. In order to successfully install the software, you have to modify your php.ini file and set allow_call_time_pass_reference = On...which turns out is not an easy task.

First, it's not easy to find the php.ini file. The Finder app will not find it. The best way to locate the file is to create a one line php file on your webserver that contains a php.phpinfo() ? statement. Chances are you did this as part of your php installation anyway, particularly if you used Entropy PhP for the Mac. Running this php app will reveal the location of your php.ini file. On my system, php.ini is located at /usr/local/php5/lib/php.ini (the location on your system may vary).

The next issue becomes, how to get to /usr/local/php5/lib. The easiest way to do this (and maybe the only way) is by pulling up the Terminal application found in your Utilities folder. This app takes you into the Unix shell. Note: Before you do this, make sure that a) you are signed in as the Administrator, b) you are comfortable working in Unix. To get to the directory in Unix, you type cd /usr/local/php5/lib. Once you're there you'll quickly realize that you the php.ini file is read only. In fact, the entire directory is read only. To modify the file, you'll need to back up one level to the /usr/local/php5/ directory and do a chmod 755 lib to allow the files to be modified. Next, go back to the lib directory and vi the php.ini file. Now you're ready to successfully install Eventum.

Good luck, and let me know if you have a better solution.

Tuesday, June 06, 2006

Javax.comm Jar for Windows MIA

It seems that Sun has removed the Javax.comm jar file for Windows from their site (no comment). Anyway, for those Windows developers out there, here's a link to it.

Wednesday, April 19, 2006

From 101 Geeky Things to Do With Your PC: Number 11

Ok, I'll admit it. I'm a computer geek. Not only that but I also hold a ham radio license. My callsign is KG4ZNV. Recently I downloaded a program developed by Simon Brown, HB9DRV called Ham Radio Deluxe. Using this program, I can control my Yaesu FT-817. For the uninitiated, the FT-817 is handy little portable radio that covers 160m - 70cm bands.

Anyway, while playing with the software I found out that it could be used to remotely connect to the radio via the Internet. The geek that I am, I decided to try it out. All it took was connecting the radio to my webserver's serial port, loading a copy of Ham Radio Deluxe, and setting some configuration parameters for security and ports and I was in business. The only problem, I needed a way to stream the audio back and forth between the computers.

No biggie really. My webserver is set up with Darwin, Flash Communication Server, and JMF. I started to use one of those options to create a live streaming setup. And then, I came across a simpler solution: Skype. I set up a Skype client on my server with an auto answer option. I also set up a Skype client on my laptop. Using a mic adapter from Heil, I was able to connect the microphone to the line out jack on my webserver and connected the speaker to my webserver's mic jack. Now, I can use Ham Radio Deluxe on my laptop and Skype to connect to my ham shack when I'm away from the house...ok I confess...I also use it when I'm elsewhere in the house via a wireless network.

Geeky huh...

Tuesday, March 07, 2006

Interesting Poll on Java Coders

Geek nirvana...programmer paradise...whatever. Developers and those who manage developers have been looking for the "right" software development process for as long as there's been software to develop. Whole segments of the software industry have been built around the latest development process. A recent Java.net poll asked the question: What term best describes your software development process? The most popular answer: No process (cowboy coding).

Truthfully, is anyone surprised by this answer? I'm not. Most development shops do not have the time or resources to adequately enforce a software development methodology. The ones that do are usually seen by those they serve as being slow to deliver solutions. Any of the established processes (XP, Waterfall, etc.) can and do work as long as things run smoothly. Introduce a problem that has to be resolved in the middle of the night, and most of us will revert to what we know best...do whatever it takes to fix the problem. In other words, no process.

Friday, February 17, 2006

Borland To Drop JBuilder

Those of you who've read my Java articles know that I'm a big fan of Borland's JBuilder IDE. Recently, though, my open systems development manager Nick vanMaarth has been working on me to switch to Eclipse. Personally I have nothing against Eclipse...it's just I've been using the JBuilder IDE for a long time and don't want to learn something new. Well it seems that Borland has helped Nick push me to start using Eclipse. ComputerWorld has recently reported that, as part of its new strategic direction, Borland is selling off it's development tools such as JBuilder and C++Builder. Don't be surprised when my next Java articles feature examples developed using Eclipse.

Click here for more on Borland's stated direction.

Tuesday, February 07, 2006

Ajax in Action

I just finished reading Ajax in Action by Dave Crane and Eric Pascarello. I was surprised to find that I'm already incorporating pieces of Ajax into sites I've developed...I just didn't know what I was doing had another name. And, if you're like me, you've been attempting to create rich (fat) client interfaces into your web applications using CSS, JavaScript, and DHTML for some time. The book's examples involving these concepts will be very familiar to you.

I particularly enjoyed examples involving the XmlDocument and XMLHttpRequest objects. The authors did an excellent job of explaining the use of these objects within the Ajax framework...some of you may object to my calling Ajax a framework, but that's how I categorize it. Crane and Pascarello also do a good job of tying Ajax into the MVC pattern. Another bonus, for me at least, was an introduction to the X library of JavaScript functions for handling JavaScript across multiple browsers. You can find out more about the X library at cross-browser.com

If you're looking for a good book on Ajax, try Ajax in Action. It's money well spent.

Thursday, January 26, 2006

Blackberry Blues

Here's a couple of ComputerWorld articles concerning the potential Blackberry injunction that I was recently interviewed for: Exemption for government BlackBerry users riles others facing shutdown and BlackBerry users 'wiggin' out' over RIM/NTP patent battle.

Technorati search