|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.f1j.ss.DocumentOpenCallback
This class provides the information necessary to open an existing workbook.
There are two conventional ways to use this class. The simplest is to instantiate the class and set its properties as needed prior to opening the workbook. For example:
Document bookDoc = new Document(
group,
file,
new DocumentOpenCallback().setOpenPassword("what"));
In the above example, a new instance of DocumentOpenCallback was
created, initialized, and handed directly to the Document class's
constructor.
The other way to use this class is to override its getter methods. This approach is typically used to prompt the user in response to conditions that are discovered while reading the file. For example:
Document bookDoc = new Document(
group,
file,
new DocumentOpenCallback() {
protected void getOpenPassword(
String userName, Password password)
throws DocumentCancelException
{
// implementation prompts user for a password
}
});
It is also possible to mix the two approaches when some properties are already known in advance. For example:
Document bookDoc = new Document(
group,
file,
(new DocumentOpenCallback() {
protected void getOpenPassword(
String userName, Password password)
throws DocumentCancelException
{
// implementation prompts user for a password
}
}).setCodePage(DocumentOpenCallback.CODEPAGE_UTF8));
| Inner Class Summary | |
static class |
DocumentOpenCallback.Password
A class to receive and validate passwords when opening a document. |
| Field Summary | |
static int |
OBSOLETE_DATA_RANGE
Flag that indicates that the opened document contains Version 7 style Data Ranges that have been replaced by the new style Data Ranges. |
static int |
OBSOLETE_DOCUMENT_TYPE
Flag that indicates that the opened document can no longer be written by e.Spreadsheet. |
static int |
OBSOLETE_METADATA
Flag that indicates the opened document potentially contains incorrect or incomplete data set metadata. |
| Method Summary | |
int |
getCodePage()
Returns the code page to expect when reading the file. |
java.lang.String |
getModifyPassword()
Returns the password to use when document modification is password-protected. |
protected void |
getModifyPassword(java.lang.String userName,
DocumentOpenCallback.Password password)
Provides the password to use when document modification is password-protected. |
java.lang.String |
getOpenPassword()
Returns the password to use when opening a password-protected file. |
protected void |
getOpenPassword(java.lang.String userName,
DocumentOpenCallback.Password password)
Provides the password to use when opening a password-protected file. |
protected void |
notifyGUID(java.lang.String guid)
Called by the e.Spreadsheet engine to provide the workbook file's GUID to the application. |
protected void |
notifyLockedForEditing(java.lang.String userName)
Called by the e.Spreadsheet Engine to notify the application that the file is locked by another process and will be opened in read-only mode. |
protected void |
notifyObsoleteData(int obsoleteDataFlags,
boolean isDocumentReadOnly)
Called by the e.Spreadsheet Engine to notify the application that the file contains data that is obsolete may not be preserved when writing out the file in a new format. |
protected void |
notifyReadOnly()
Called by the e.Spreadsheet Engine to notify the application that the file is read-only. |
DocumentOpenCallback |
setCodePage(int nCodePage)
Sets the code page that will be returned by the getCodePage() method. |
DocumentOpenCallback |
setModifyPassword(java.lang.String modifyPassword)
Sets the password that will be provided by the getModifyPassword() method. |
DocumentOpenCallback |
setOpenPassword(java.lang.String openPassword)
Sets the password that will be provided by the getOpenPassword() method. |
| Field Detail |
public static final int OBSOLETE_DOCUMENT_TYPE
notifyObsoleteData(int, boolean)public static final int OBSOLETE_DATA_RANGE
notifyObsoleteData(int, boolean)public static final int OBSOLETE_METADATA
DataSourceCollection.refreshMetadata()
after the file is open.notifyObsoleteData(int, boolean),
DataSourceCollection.refreshMetadata(),
BookModel.getDataSourceCollection()| Method Detail |
public int getCodePage()
throws DocumentCancelException
setCodePage() method, or
it may be overridden to determine the return value on demand.CodePageConstants,
setCodePage(int)
public final java.lang.String getOpenPassword()
throws DocumentCancelException
getOpenPassword(String, Password) and returns the password
provided by that method.getOpenPassword(String, Password) is overridden and throws this exception.getOpenPassword(String, DocumentOpenCallback.Password),
setOpenPassword(String)
protected void getOpenPassword(java.lang.String userName,
DocumentOpenCallback.Password password)
throws DocumentCancelException
Provides the password to use when opening a password-protected file.
The password is not returned, but is instead submitted to the object
specified by the password parameter. This allows
implementations to prompt the user in a loop until a valid password is
entered. If the method returns without first submitting a valid
password, the open operation will fail.
To explicitly cancel the open operation, throw a
DocumentCancelException.
The default implementation of this method returns the password set by
the setOpenPassword() method, and never throws an
exception.
Example Implementation
protected void getOpenPassword(String userName, Password password)
throws DocumentCancelException
{
while (true)
{
try
{
String passwordString = JOptionPane.showInputDialog(
"Password to open the file:");
if (passwordString != null)
password.submitPassword(passwordString);
return;
}
catch (AccessDeniedException e)
{
JOptionPane.showMessageDialog(null, "Invalid password.");
}
}
}
userName - The name of the user who password-protected the file.password - An object that receives the password.setOpenPassword(String)
public final java.lang.String getModifyPassword()
throws DocumentCancelException
getModifyPassword(String, Password) and returns the
password provided by that method.getModifyPassword(String, Password) is overridden and throws this exception.getModifyPassword(String, DocumentOpenCallback.Password),
setModifyPassword(String)
protected void getModifyPassword(java.lang.String userName,
DocumentOpenCallback.Password password)
throws DocumentCancelException
Provides the password to use when document modification is
password-protected. The password is not returned, but is instead
submitted to the object specified by the password
parameter. This allows implementations to prompt the user in a loop
until a valid password is entered. If the method returns without first
submitting a valid password, the document will be opened in read-only
mode.
To explicitly cancel the open operation, throw a
DocumentCancelException.
The default implementation of this method returns the password set by
the setModifyPassword() method, and never throws an
exception.
Example Implementation
protected void getModifyPassword(String userName, Password password)
throws DocumentCancelException
{
while (true)
{
try
{
String passwordString = JOptionPane.showInputDialog(
"Password to edit the file, or cancel to open as read-only:");
if (passwordString != null)
password.submitPassword(passwordString);
return;
}
catch (AccessDeniedException e)
{
JOptionPane.showMessageDialog(null, "Invalid password.");
}
}
}
userName - The name of the user who password-protected the file.password - An object that receives the password.setModifyPassword(String)public final DocumentOpenCallback setCodePage(int nCodePage)
getCodePage() method. If getCodePage() is
overridden and does not call the default implementation, then it is not
necessary to call this method.nCodePage - The code page to be expected when reading the file.getCodePage()public final DocumentOpenCallback setOpenPassword(java.lang.String openPassword)
getOpenPassword() method. If
getOpenPassword(String, Password) is overridden and does
not call the default implementation, then it is not necessary to call
this method.openPassword - The password to use when opening a password-protected file.getOpenPassword(String, DocumentOpenCallback.Password),
getOpenPassword()public final DocumentOpenCallback setModifyPassword(java.lang.String modifyPassword)
getModifyPassword() method. If
getModifyPassword(String, Password) is overridden and does
not call the default implementation, then it is not necessary to call
this method.modifyPassword - The password to use when document modification is password-protected.getModifyPassword(String, DocumentOpenCallback.Password),
getModifyPassword()
protected void notifyLockedForEditing(java.lang.String userName)
throws DocumentCancelException
Called by the e.Spreadsheet Engine to notify the application that the file is locked by another process and will be opened in read-only mode. If this method returns, the document will be opened in read-only mode. If this method throws an exception, the open operation will be canceled.
The default implementation of this method does nothing.
userName - The name of the user who has the file locked.
protected void notifyReadOnly()
throws DocumentCancelException
Called by the e.Spreadsheet Engine to notify the application that the file is read-only. If this method returns, the document will be opened in read-only mode. If this method throws an exception, the open operation will be canceled.
The default implementation of this method does nothing.
protected void notifyObsoleteData(int obsoleteDataFlags,
boolean isDocumentReadOnly)
throws DocumentCancelException
Called by the e.Spreadsheet Engine to notify the application that the file contains data that is obsolete may not be preserved when writing out the file in a new format. If this method throws an exception, the open operation will be canceled.
The default implementation of this method does nothing.
obsoleteDataFlags - A bitmask containing flags indicated which deprecated items are contained in this file.isDocumentReadOnly - A boolean indicating if the document is read-only.OBSOLETE_DOCUMENT_TYPE,
OBSOLETE_DATA_RANGE
protected void notifyGUID(java.lang.String guid)
throws DocumentCancelException
Called by the e.Spreadsheet engine to provide the workbook file's GUID to the application. If this method returns, the document will be opened normally. If this method throws an exception, the open operation will be canceled.
This is an advanced overridable used by certain applications to implement caching of workbooks. The default implementation of this method does nothing.
guid - A string object representing the workbook file's GUID.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||