PDA

View Full Version : Need custom bean help



williamsca
05-27-2004, 10:23 AM
I am very new to InstallShield and have also never written a piece of Java code in my life, but I find myself in a position where I need to write a custom bean for use in ISX.

Here's the scenario: A dialogue box prompts the installer to enter the location for CGI files. Let's say the user enters /opt/apache/cgi-bin and this information is put into a variable CGIDIR_S. I now need to create a file that will contain several lines of text, one of which includes everything after the last "/" from the location entered. For instance, the file might ultimately look like:

domain "default" {
session-dir "$PATH/data/tmp";
menu-dir "$PATH/common/admin";
cgi-url "/cgi-bin/admin.exe";
default-menu "login.mnu/login";
set-path "/opt/pmwa";
}

I know that I will probably need to use the split method of the String class to do the parsing. I have read the information in creating a custom bean in the Developer's Guide, but I honestly don't have a clue where to begin.

Has anyone written something similar or can point me to some online resource where I can find examples?

Thanks!

kflowers
06-02-2004, 02:53 PM
You can use the Custom Dialog edito to create a dialog to prompt the user for information. The custom dialog editor allows you to drag and drop UI components.

We can retrieve these values by using the $V String Resolver (i.e. $V(myvariable).

You can use the ASCII File Update Product/Wizard Action to write these valuse to file.

Please look in the User Guide in the section titled “Working with the Dialog Editor” for more information about using our custom Dialog editor.

cheers!

williamsca
06-03-2004, 07:41 AM
Hi Keith!

Thanks for the reply. I have actually already done all that you mentioned. The trick is taking the input from the user, parsing it, and using that result to put into the file. In the example I mentioned in the first post, the user would enter /opt/apache/cgi-bin, but I need only the cgi-bin portion of that to write to the file. Or as another example, if the user were to enter /opt/apache/htdocs, I would need to get just "htdocs" and write that to the file.

mholland
06-03-2004, 11:02 AM
I think you need to get a java book at this point.... you'll start running into more and more problems like this as you go. This is a pretty simple java issue that you are dealing with, and should be solvable with the right resources.

You can start here, with the java documentation:
http://java.sun.com/j2se/1.4.2/docs/api/

hint: look at the class "FileOutputStream"

mike.

williamsca
06-16-2004, 03:01 PM
I've been doing a lot of reading on this and finally have created a custom JavaBean that does the parsing that I need it to do, BUT I am now having problems with resolveString.

Given the following code from my custom bean:

import com.installshield.wizard.*;
import com.installshield.util.*;
import com.installshield.beans.*;
import java.io.*;
import java.lang.*;
import java.net.*;
import java.util.*;

public class TestBean extends WizardAction {

// private String myInstallLocation = resolveString("$P(absoluteInstallLocation)");
// private String myCgiDir = resolveString("$V(CGIDIR_S)");
private String myInstallLocation = "/opt/pmwa";
private String myCgiDir = "/tmp";
private String myCgiDirSub = "";
private String QuickCgiFile = myCgiDir + "/x.x";

public void execute(WizardBeanEvent event) {
try {
StringTokenizer st = new StringTokenizer(myCgiDir,"/");
while (st.hasMoreTokens()) {
myCgiDirSub = st.nextToken();
}
BufferedWriter out = new BufferedWriter(new FileWriter(QuickCgiFile));
out.write("domain \"default\" {\n");
out.write(" session-dir \"$PATH/data/tmp\";\n");
out.write(" menu-dir \"$PATH/common/admin\";\n");

out.write(" cgi-url \"/");
out.write(myCgiDirSub);
out.write("/admin.exe\";\n");

out.write(" default-menu \"login.mnu/login\";\n");

out.write(" set-path \"");
out.write(myInstallLocation);
out.write("\";\n");

out.write("}\n");
out.flush();
out.close();
} catch (IOException e) {
}
}
}


Using the code above as is, my output file is created as expected. If I uncomment either one of the two lines containing resolveString and comment out the corresponding hardcoded value, the bean still compiles, the project builds with no errors, but when I run the app the output file is not created at all as though the entire bean is being skipped.

The bean is currently in the PreInstall section after all of the user input has occurred. I am at a loss at this point. Can anyone point me in the right direction?

mholland
06-16-2004, 03:31 PM
You almost have it, but you are missing a key concept. You have to call resolveString from an object that contains that method - it isn't a class method on the WizardAction class.

So.... what you'd want to do is something like this:

public void execute(WizardBeanEvent event) {
try {
String myCgiDir = event.getWizard().getServices().resolveString("$P(absoluteInstallLocation)");
StringTokenizer st = new StringTokenizer(myCgiDir,"/");
while (st.hasMoreTokens()) {
myCgiDirSub = st.nextToken();
...


I haven't tested it, but that should do the trick.

mike.




resolveString("$P(absoluteInstallLocation)");
resolveString("$V(CGIDIR_S)");



Originally posted by williamsca
I've been doing a lot of reading on this and finally have created a custom JavaBean that does the parsing that I need it to do, BUT I am now having problems with resolveString.

Given the following code from my custom bean:

import com.installshield.wizard.*;
import com.installshield.util.*;
import com.installshield.beans.*;
import java.io.*;
import java.lang.*;
import java.net.*;
import java.util.*;

public class TestBean extends WizardAction {

// private String myInstallLocation = resolveString("$P(absoluteInstallLocation)");
// private String myCgiDir = resolveString("$V(CGIDIR_S)");
private String myInstallLocation = "/opt/pmwa";
private String myCgiDir = "/tmp";
private String myCgiDirSub = "";
private String QuickCgiFile = myCgiDir + "/x.x";

public void execute(WizardBeanEvent event) {
try {
StringTokenizer st = new StringTokenizer(myCgiDir,"/");
while (st.hasMoreTokens()) {
myCgiDirSub = st.nextToken();
}
BufferedWriter out = new BufferedWriter(new FileWriter(QuickCgiFile));
out.write("domain \"default\" {\n");
out.write(" session-dir \"$PATH/data/tmp\";\n");
out.write(" menu-dir \"$PATH/common/admin\";\n");

out.write(" cgi-url \"/");
out.write(myCgiDirSub);
out.write("/admin.exe\";\n");

out.write(" default-menu \"login.mnu/login\";\n");

out.write(" set-path \"");
out.write(myInstallLocation);
out.write("\";\n");

out.write("}\n");
out.flush();
out.close();
} catch (IOException e) {
}
}
}


Using the code above as is, my output file is created as expected. If I uncomment either one of the two lines containing resolveString and comment out the corresponding hardcoded value, the bean still compiles, the project builds with no errors, but when I run the app the output file is not created at all as though the entire bean is being skipped.

The bean is currently in the PreInstall section after all of the user input has occurred. I am at a loss at this point. Can anyone point me in the right direction?

williamsca
06-17-2004, 08:18 AM
Thanks Mike! That did the trick.

One other question:

If I make a change to the custom bean, after re-compiling, is it also necessary to go through an entire rebuild of the project in order for me to verify the changes, or is there some better way?

-- Curtis

williamsca
06-18-2004, 10:50 AM
An additional question: The custom bean creates a file that the uninstaller doesn't seem to know anything about, so when the uninstaller is run, the file created by the bean is left behind. What is the best way for me to have the uninstaller remove the file?

I've tried creating a new Feature and Component that has a Delete File Product Action where the Runtime is set to Uninstall time, but that doesn't seem to work. Could it be because I used $V(CGIDIR_S)/quickcgi.cfg as the filename and the uninstaller knows nothing about $V(CGIDIR_S)?

-- Curtis