import com.ibm.jsdt.support.SupportBase;
import com.ibm.jsdt.support.SupportHelper;
import java.io.StringWriter;
import java.io.PrintWriter;
// First, extend the appropriate SupportBase class.
public class ExampleEntryProgram extends SupportBase
{
public ExampleEntryProgram(){}
public static void main(String args[])
{
.
.
.
// Second, create an instance of a SupportBase object.
ExampleEntryProgram base = new ExampleEntryProgram();
String path = "C:\\Program Files\\ProgramX\\";
// If you are exposing the install directory as a variable then you can
// retrieve that value here instead.
// Example Variable Retrieval:
// path = base.getInstallDir("product_install_dir");
// where "product_install_dir" is the name of the exposed variable.
// See getInstallDir method below for an implementation.
String fileName = "plugin.xml";
String oldElement = "<TagX hostname=\"localhost\">";
String newElement = "<TagX hostname=\"my.hostname\">";
base.updateXMLString(path, fileName, oldElement, newElement);
.
.
.
}
public void updateXMLString(String path, String filename,
String oldSubstring, String newSubstring)
{
// Third, call the SupportBase methods as specified by the API
// of the SupportHelper functions that you will use, and then call
// the SupportHelper functions.
//
// In this method we call setFileName to prepare for SupportHelper.readFile.
// We call setTargetString, setOldSubstring, and setNewSubstring to prepare
// for SupportHelper.replaceSubstring.
// Finally, we call setMessage and setAppend to prepare for SupportHelper.writeFile.
setFileName(path + filename);
try
{
setTargetString(getHelper().readFile(this))
}
catch (IOException e)
{
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
logMessage(sw.toString()); // See method below
}
setOldSubstring(oldSubstring); //String to replace
setNewSubstring(newSubstring);
String updatedConfigFileContents = getHelper().replaceSubstring(this);
setMessage(updatedConfigFileContents);
setAppend(false); //overwrite versus append
try
{
getHelper().writeFile(this);
}
catch (IOException e)
{
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
logMessage(sw.toString()); // See method below
}
}
public void logMessage(String message)
{
// Here we use the message logging functionality provided by the support framework.
// The usage is explained in the message logging example.
setMessage(message);
setLogFileName("ExampleEntryProgram.log");
setLogsDir(getHelper().getLogsDir(this));
getHelper().log(this);
}
public String getInstallDir(String varName)
{
setJarFile(getHelper().getProductInstallingId(this))
setVariableName(varName);
return getHelper().getIbmNsiPropValue(this);
}
}
|