com.acesoft.aceoffix
Class FileRequestPHP

java.lang.Object
  extended by com.acesoft.aceoffix.FileRequestPHP

public class FileRequestPHP
extends java.lang.Object

FileRequestPHP class is used to receive and save the document submitted by AceoffixCtrl with PHP code.

FileRequestPHP class is used to receive and save the document submitted by AceoffixCtrl with PHP code. FileRequest object must be created and used in the page assigned by AceoffixCtrl.SaveFilePage.

Version:
5.0
Author:
Acesoft Corporation

Constructor Summary
FileRequestPHP()
          Initializes a new instance of the FileRequest class.
 
Method Summary
 java.lang.String close()
          Returns a success message to AceoffixCtrl.
 java.lang.String getDocumentText()
          Gets the plain text of the document without any format.
 byte[] getFileBytes()
          Returns an array of the bytes in the file submitted by AceoffixCtrl.
 java.lang.String getFileExtName()
          Gets the file name extension of the file.
 java.lang.String getFileName()
          Gets the file name of the file submitted by AceoffixCtrl.
 int getFileSize()
          Gets the size of the file, in bytes.
 java.io.FileInputStream getFileStream()
          Returns an FileInputStream object which contains the file bytes submitted by AceoffixCtrl.
 java.lang.String getFormField(java.lang.String name)
          Gets the value with the specified name in the form fields of the page with AceoffixCtrl.
 java.lang.String getLocalFileExtName()
          Gets the file name extension of the client's local file submitted by AceoffixCtrl.
 java.lang.String getLocalFileName()
          Gets the file name of the client's local file submitted by the AceoffixCtrl.
 void load(java.lang.String Input)
          Load the request stream with PHP code.
 void saveToFile(java.lang.String saveAsFileName)
          Saves current document to the folder of server disk.
 void setCustomSaveResult(java.lang.String value)
          Sets the custom saving result defined by developer.
 void showPage(int width, int height)
          Prompts a custom dialog box to show the saving result.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileRequestPHP

public FileRequestPHP()
Initializes a new instance of the FileRequest class.

Method Detail

getFileName

public java.lang.String getFileName()
Gets the file name of the file submitted by AceoffixCtrl.

Typically, it's the file name which is opened. The file name contains the file name extension, but not including the directory path. If the document which is going to be opened is a binary stream outputted by server page, the file name will be "aceoffix" with the correct file name extension.

See Also:
FileRequestPHP.saveToFile() to learn how to save document.

getFileExtName

public java.lang.String getFileExtName()
Gets the file name extension of the file.

See Also:
FileRequestPHP.saveToFile() to learn how to save document.

getLocalFileName

public java.lang.String getLocalFileName()
Gets the file name of the client's local file submitted by the AceoffixCtrl.

This file name contains the file name extension, but not containing the folder path. When AceoffixCtrl is used to view the Office file uploaded from local client, this property can get the name of the local file.


getLocalFileExtName

public java.lang.String getLocalFileExtName()
Gets the file name extension of the client's local file submitted by AceoffixCtrl.


getFileSize

public int getFileSize()
Gets the size of the file, in bytes.

See Also:
FileRequestPHP.saveToFile() to learn how to save document.

setCustomSaveResult

public void setCustomSaveResult(java.lang.String value)
Sets the custom saving result defined by developer.

The following example shows how to use the CustomSaveResult property.

 $ip = GetHostByName($_SERVER['SERVER_NAME']);
 require_once("http://".$ip.":8080/JavaBridge/java/Java.inc");
 $freq = new Java("com.acesoft.aceoffix.FileRequestPHP");
 $freq->load(file_get_contents("php://input"));
 $filepath=realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
 $freq->saveToFile($filepath."\\doc\\".$freq->getFileName());
 freq->setCustomSaveResult("My custom result.");
 echo $freq->close();
 

Then, custom saving result can be got from the CustomSaveResult property of AceoffixCtrl with JavaScript.

 <script language="javascript" type="text/javascript">
     function SaveDocument() {
         document.getElementById("AceoffixCtrl1").SaveDocument();
         alert(document.getElementById("AceoffixCtrl1").CustomSaveResult);//You can determine the next code logic according to the value of CustomSaveResult.
     }
 </script>
 


load

public void load(java.lang.String Input)
          throws java.lang.Exception,
                 java.io.IOException
Load the request stream with PHP code.

Throws:
java.lang.Exception
java.io.IOException

close

public java.lang.String close()
                       throws java.io.IOException,
                              java.lang.Exception
Returns a success message to AceoffixCtrl.

If the code for saving document executes successfully, you should call this method to return a success message to AceoffixCtrl. Typically, the close method should be called at the end of code in SaveFilePage.

Throws:
java.io.IOException
java.lang.Exception
See Also:
FileRequestPHP.saveToFile() to learn how to save document with PHP code.

saveToFile

public void saveToFile(java.lang.String saveAsFileName)
                throws ServletException,
                       java.io.IOException,
                       java.lang.Exception
Saves current document to the folder of server disk.

Saves current document to assigned server folder. If you want to save the document to database field, please call the getFileBytes() or getFileStream() method. Note: The maximum size allowed for a request, which includes uploaded files, is 4 MB, by default. If the uploaded file is larger than its maximum size, errors may occur there.

The following code example demonstrates how to save the document that are uploaded by AceoffixCtrl to the specified folder on the Web server's disk.

In order to display all the possible exception messages when you debug your code, do not use try...catch statements in SaveFilePage. When an exception is thrown, AceoffixCtrl will show the exception dialog box.

 $ip = GetHostByName($_SERVER['SERVER_NAME']);
 require_once("http://".$ip.":8080/JavaBridge/java/Java.inc");
 $freq = new Java("com.acesoft.aceoffix.FileRequestPHP");
 $freq->load(file_get_contents("php://input"));
 $strFileName = freq->getFileName();
 $strFileExtName = freq->getFileExtName();
 $iFileSize = freq->getFileSize();
 
 // The current document can be saved to the folder on server.
 $filepath=realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
 $freq->saveToFile($filepath."\\doc\\".$freq->getFileName());
 echo $freq->close();
 

Parameters:
saveAsFileName - To save document to target location, absolute path and file name must be specified. To save document to the folder within website, you may use getRealPath() to get the absolute path.
Throws:
ServletException
java.io.IOException
java.lang.Exception

showPage

public void showPage(int width,
                     int height)
              throws java.io.IOException
Prompts a custom dialog box to show the saving result.

After save document, if you want to prompt a custom dialog box to show the saving result, you can call this method. The message page shown in the dialog box is the current SaveFilePage. By default, the SaveFilePage will display nothing. You can add friendly messages in the PHP of SaveFilePage.

The following code example shows how to use the ShowPage method to let AceoffixCtrl display a custom error dialog box to user.

 $ip = GetHostByName($_SERVER['SERVER_NAME']);
 require_once("http://".$ip.":8080/JavaBridge/java/Java.inc");
 $freq = new Java("com.acesoft.aceoffix.FileRequestPHP");
 $freq->load(file_get_contents("php://input"));
 $filepath=realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
 $type = $freq->getFileExtName();
 if((strcasecmp(".doc", $type) == 0)||(strcasecmp(".docx", $type) == 0)){ // Only save the Word documents.
     $freq->saveToFile($filepath."\\doc\\".$freq->getFileName());
 }
 else{
     echo "Failed to save. The current document is not a Word document."; // This is a simple error message, you can add friendly message to the current page.
     $freq->showPage(380, 200); // If the document is not a Word document, AceoffixCtrl will open a modal dialog to show the custom error page.
 }
 echo $freq->close();
 

Parameters:
width - The width of custom dialog, in pixels.
height - The height of custom dialog, in pixels.
Throws:
java.io.IOException

getFileBytes

public byte[] getFileBytes()
                    throws ServletException,
                           java.io.IOException,
                           java.lang.Exception
Returns an array of the bytes in the file submitted by AceoffixCtrl.

If you want to save the file to the data field of a database, you should call this FileBytes property. If you want to save the file to disk, you only need to call FileRequest.saveToFile().

Throws:
ServletException
java.io.IOException
java.lang.Exception

getFileStream

public java.io.FileInputStream getFileStream()
                                      throws ServletException,
                                             java.io.IOException,
                                             java.lang.Exception
Returns an FileInputStream object which contains the file bytes submitted by AceoffixCtrl.

Throws:
ServletException
java.io.IOException
java.lang.Exception

getDocumentText

public java.lang.String getDocumentText()
                                 throws java.io.IOException,
                                        java.lang.Exception
Gets the plain text of the document without any format. Get the text-only content and save it to database. So we can have the full-text search function in Word documents.

Note: This property only applies to Word currently.

The following code example shows how to use the DocumentText property to get the plain text of the document.

 $ip = GetHostByName($_SERVER['SERVER_NAME']);
 require_once("http://".$ip.":8080/JavaBridge/java/Java.inc");
 $freq = new Java("com.acesoft.aceoffix.FileRequestPHP");
 $freq->load(file_get_contents("php://input"));
 $strDocumentText = freq->getDocumentText(); 
 // After you get the text content, you can save it to the database.
 
 $filepath=realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
 $freq->saveToFile($filepath."\\doc\\".$freq->getFileName());
 echo $freq->close();
 

Returns:
Returns the text-only content of the document.
Throws:
java.io.IOException
java.lang.Exception

getFormField

public java.lang.String getFormField(java.lang.String name)
                              throws java.io.IOException,
                                     java.lang.Exception
Gets the value with the specified name in the form fields of the page with AceoffixCtrl.

When AceoffixCtrl is saving document, you can call this method to get the values of form fields posted from the page with AceoffixCtrl.

Note: To be able to capture the value, the form field must have a name attribute.

The Form field can be Input Box, Drop-down Box, Radio, Check Box, TextArea, Hidden Field etc..

The following code example shows how to use the GetFormField method to get the value of the form field posted from the page with AceoffixCtrl.

 $ip = GetHostByName($_SERVER['SERVER_NAME']);
 require_once("http://".$ip.":8080/JavaBridge/java/Java.inc");
 $freq = new Java("com.acesoft.aceoffix.FileRequestPHP");
 $freq->load(file_get_contents("php://input"));
 $strSubject = freq.getFormField("EditSubject"); 
 // After you get the input text, you can save it to the database.
 
 $filepath=realpath(dirname($_SERVER["SCRIPT_FILENAME"]));
 $freq->saveToFile($filepath."\\doc\\".$freq->getFileName());
 echo $freq->close();
 

Parameters:
name - The name of form field in the page.
Returns:
Returns the value of the form field.
Throws:
java.io.IOException
java.lang.Exception