Getting document content
The examples below show various ways of getting document content. Please also look at the Content Handler API documentation for more information.
Document content as a byte array
Use the following example to get document content as a byte array from a file and adding to ContentHandlerResult.KEY_DOCUMENT_CONTENT
:
* This constant key should be used to store the document content as a
* byte array.
* public final static String KEY_DOCUMENT_CONTENT = "KEY_DOCUMENT_CONTENT";
public ContentHandlerResult getDocumentContent(ContentHandlerInput input)
throws FlexSnapsSIAPIException
{
String clientInstanceID = input.getClientInstanceID();
String key = input.getDocumentId();
String Logger.getInstance().log("FileContentHandler.getDocumentContent(" + key + ")");
String fullFilePath = gFilePath + URLDecoder.decode(key);
File file = new File(fullFilePath);
ContentHandlerResult result = new ContentHandlerResult();
try
{
result.put(ContentHandlerResult.KEY_DOCUMENT_CONTENT, ClientServerIO.getFileBytes(file));
}
catch (FileNotFoundException fnfe)
{
/* Removing stack trace here, as it was unnecessary */
Logger.getInstance().log(Logger.SEVERE, fnfe.getMessage());
throw new FlexSnapSIAPIException("Document not found: "
+ ClientServerIO.makeXssSafe(key));
}
catch (Exception e)
{
return null;
}
result.put(ContentHandlerResult.KEY_DOCUMENT_DISPLAY_NAME, key);
return result;
}
Document content as a file
Use the following example to get document content as a file and adding to ContentHandlerResult.KEY_DOCUMENT_FILE
:
* This constant key should be used to store the document content as
* java.io.File object.
* public final static String KEY_DOCUMENT_FILE = "KEY_DOCUMENT_FILE";
* This is used for very large files to help load quickly... this is
* read only.
*/
Large file example
public ContentHandlerResult getDocumentContent(ContentHandlerInput input)
throws FlexSnapSIAPIException
{
String clientInstanceId = input.getClientInstanceId();
String key = input.getDocumentId();
String fullFilePath = gFilePath + URLDecoder.decode(key);
File file = new File(fullFilePath);
ContentHandlerResult result = new ContentHandlerResult();
try
{
result.put(ContentHandlerResult.KEY_DOCUMENT_FILE, file);
catch (Exception e)
{
return null;
}
result.put(ContentHandlerResult.KEY_DOCUMENT_DISPLAY_NAME, key); return result;
}
Document content as a vector
Use the following example to get document content as a vector and adding to ContentHandlerResult.KEY_DOCUMENT_CONTENT_ELEMENTS
:
* This constant key should be used to store the content of the various
* elements of the document if the document is made of more than one file.
* If this key is not null, then the KEY_DOCUMENT_ CONTENT will be ignored.
public final static String KEY_DOCUMENT_CONTENT_ELEMENTS = "KEY_ DOCUMENT_CONTENT_ELEMENTS";
*/
filenet example:
public ContentHandlerResult getDocumentContent(ContentHandlerInput input)
throws VirtualViewerAPIException
{
gLogger.log("FileNetContentHandler.getDocumentContent"); String documentId = input.getDocumentId(); gLogger.log("documentId is " + documentId);
Document filenetDocument = getFilenetDocument(input); Vector vectorOfBytes = getFilenetContentBytes(documentId, filenetDocument);
ContentHandlerResult result = new ContentHandlerResult(); try
{
result.put(ContentHandlerResult.KEY_DOCUMENT_CONTENT_ELEMENTS, vectorOfBytes); result.put(ContentHandlerResult.KEY_DOCUMENT_DISPLAY_NAME, filenetDocument.getName());
}
catch (Exception e)
{
e.printStackTrace();
}
return result;
}
Have questions, corrections, or concerns about this topic? Please let us know!