org.csstudio.opibuilder.scriptUtil
Class FileUtil

The Utility class to help file operating.

Author:
Xihui Chen

Method Summary
static java.io.InputStream getInputStreamFromFile(java.lang.String filePath, org.csstudio.opibuilder.editparts.AbstractBaseEditPart widget)
          Return an InputStream of the file on the specified path.
static org.jdom.Element loadXMLFile(java.lang.String filePath)
          Load the root element of an XML file.
static org.jdom.Element loadXMLFile(java.lang.String filePath, org.csstudio.opibuilder.editparts.AbstractBaseEditPart widget)
          Load the root element of an XML file.
static java.lang.String openFileDialog(boolean inWorkspace)
          Open a file select dialog.
static java.lang.String readTextFile(java.lang.String filePath)
          Read a text file.
static java.lang.String readTextFile(java.lang.String filePath, org.csstudio.opibuilder.editparts.AbstractBaseEditPart widget)
          Read a text file.
static void writeTextFile(java.lang.String filePath, boolean inWorkspace, org.csstudio.opibuilder.editparts.AbstractBaseEditPart widget, java.lang.String text, boolean append)
          Write a text file.
static void writeTextFile(java.lang.String filePath, boolean inWorkspace, java.lang.String text, boolean append)
          Write a text file.

Method Detail

loadXMLFile

public static org.jdom.Element loadXMLFile(java.lang.String filePath)
                                    throws java.lang.Exception
Load the root element of an XML file with an absolute path. The element is a JDOM Element.

Parameters:
filePath - path of the file. It must be an absolute path which can be either
a workspace path such as /BOY Examples/Scripts/myfile.xml
a local file system path such as C:\myfile.xml
or an URL path such as http://mysite.com/myfile.xml. *
Returns:
root element of the XML file.
Throws:
java.lang.Exception - if the file does not exist or is not a correct XML file.

loadXMLFile

public static org.jdom.Element loadXMLFile(java.lang.String filePath,
                                           org.csstudio.opibuilder.editparts.AbstractBaseEditPart widget)
                                    throws java.lang.Exception
Load the root element of an XML file with either an absolute path or relative path to the widget. The element is a JDOM Element.

Parameters:
filePath - path of the file. It can be an absolute path or a relative path to the OPI that contains the specified widget. If it is an absolute path, it can be either
a workspace path such as /BOY Examples/Scripts/myfile.xml
a local file system path such as C:\myfile.xml
or an URL path such as http://mysite.com/myfile.xml.
widget - a widget in the OPI, which is used to provide relative path reference. It can be null if the path is an absolute path.
Returns:
root element of the XML file.
Throws:
java.lang.Exception - if the file does not exist or is not a correct XML file.

getInputStreamFromFile

public static java.io.InputStream getInputStreamFromFile(java.lang.String filePath,
                                                         org.csstudio.opibuilder.editparts.AbstractBaseEditPart widget)
                                                  throws java.lang.Exception
Return an InputStream of the file on the specified path. The client is responsible for closing the stream when finished.

Parameters:
filePath - path of the file. It can be an absolute path or a relative path to the OPI that contains the specified widget. If it is an absolute path, it can be either
a workspace path such as /BOY Examples/Scripts/myfile.xml
a local file system path such as C:\myfile.xml
or an URL path such as http://mysite.com/myfile.xml.
widget - a widget in the OPI, which is used to provide relative path reference. It can be null if the path is an absolute path.
Returns:
java.io.InputStream of the file.
Throws:
java.lang.Exception - if the file does not exist.

readTextFile

public static java.lang.String readTextFile(java.lang.String filePath)
                                     throws java.lang.Exception
Read a text file with an absolute path.

Parameters:
filePath - path of the file. It must be an absolute path which can be either
a workspace path such as /BOY Examples/Scripts/myfile.xml
a local file system path such as C:\myfile.xml
or an URL path such as http://mysite.com/myfile.xml.
Returns:
a string of the text.
Throws:
java.lang.Exception - if the file does not exist or is not a correct text file.

readTextFile

public static java.lang.String readTextFile(java.lang.String filePath,
                                            org.csstudio.opibuilder.editparts.AbstractBaseEditPart widget)
                                     throws java.lang.Exception
Read a text file with either an absolute path or relative path to the widget.

Parameters:
filePath - path of the file. It can be an absolute path or a relative path to the OPI that contains the specified widget. If it is an absolute path, it can be either
a workspace path such as /BOY Examples/Scripts/myfile.xml
a local file system path such as C:\myfile.xml
or an URL path such as http://mysite.com/myfile.xml.
widget - a widget in the OPI, which is used to provide relative path reference. It can be null if the path is an absolute path.
Returns:
a string of the text.
Throws:
java.lang.Exception - if the file does not exist or is not a correct text file.

writeTextFile

public static void writeTextFile(java.lang.String filePath,
                                 boolean inWorkspace,
                                 java.lang.String text,
                                 boolean append)
                          throws java.lang.Exception
Write a text file with absolute path.

Parameters:
filePath - path of the file. It must be an absolute path which can be either
a workspace path such as /BOY Examples/Scripts/myfile.xml
or a local file system path such as C:\myfile.xml.
inWorkspace - true if the file path is a workspace file path. Otherwise, it will be recognized as a local file system file.
text - the text to be written to the file.
append - true if the text should be appended to the end of the file.
Throws:
java.lang.Exception - if error happens.

writeTextFile

public static void writeTextFile(java.lang.String filePath,
                                 boolean inWorkspace,
                                 org.csstudio.opibuilder.editparts.AbstractBaseEditPart widget,
                                 java.lang.String text,
                                 boolean append)
                          throws java.lang.Exception
Write a text file with either an absolute path or relative path to the widget.

Parameters:
filePath - path of the file. It can be an absolute path or a relative path to the OPI that contains the specified widget. If it is an absolute path, it can be either
a workspace path such as /BOY Examples/Scripts/myfile.xml
a local file system path such as C:\myfile.xml
or an URL path such as http://mysite.com/myfile.xml.
inWorkspace - true if the file path is a workspace file path. Otherwise, it will be recognized as a local file system file.
widget - a widget in the OPI, which is used to provide relative path reference. It can be null if the path is an absolute path.
text - the text to be written to the file.
append - true if the text should be appended to the end of the file.
Throws:
java.lang.Exception - if error happens.

openFileDialog

public static java.lang.String openFileDialog(boolean inWorkspace)
Open a file select dialog.

Parameters:
inWorkspace - true if it is a workspace file dialog; Otherwise, it is a local file system file dialog.
Returns:
the full file path. Or null if it is canceled.