com.sas.util
Class ContentServer

com.sas.util.ContentServer
All Implemented Interfaces:
java.lang.Runnable

public class ContentServer
implements java.lang.Runnable

A class for sending content to a browser (either through applet.showDocument or directly invoking the browser) or directly to an application. It communicates to a browser through a socket; for an application, it writes the data to a file first.
Example usage:

        ContentServer.export(pdfString.getBytes(), "application/pdf",
                          "", "", "pdf");

    or
        ContentServer.export("1, 2, 3, 4".getBytes(), "application/x-comma-separated-values",
                          "", "", "csv");
 
or a more elaborate version:
    class SomeClass {
        protected final static String _excelArgs = " /r ";  // read-only
        protected final static String _fileExt = "csv";
        protected final static String EXCEL = "Excel";

        // assumes that something sets a system property called "Excel"
        protected static String getExcelEXE() {
            return System.getProperty(EXCEL, "C:\\Microsoft Office\\Office\\Excel.exe");
        }

        public static void export(StaticTableInterface table) {
            if (!ContentServer.isExportAllowed() || table == null)
                return;

            // set type for spreadsheet
            ContentServer.export(com.sas.table.TableWriter.getCSVAsByteArray(table), "application/x-comma-separated-values",
                                 getExcelEXE(), _excelArgs, _fileExt);
        }
    }
 


Field Summary
protected  java.lang.String _application
          The path of the application if using sendToApplication
protected  java.lang.String _browser
          The path of the browser if using sendToBrowserApp
protected static boolean _canWriteToDisk
          Are we allowed to write to disk?
protected static boolean _checked
          Have we checked if we can export and by what method?
protected  byte[] _content
          The content to be served as a byte array
protected static int _counter
          How many exports have we done?
protected static java.lang.String _echoURL
          The url of the echocgi.exe that we found
protected static java.lang.String[] _echoURLs
          The possible URLs for echocgi.exe - by default either Windows or Unix at /sasweb/cgi-bin/echocgi
protected  java.lang.String _extension
          The extension of the file (eg csv)
protected  java.lang.String _fileName
          The file name of the file to be Written to disk if using sendToApplication Requested from our internal mini-web server if using sendToBrowserServerSocket or sendToBrowserApp
protected static boolean _isInApplet
          Are we in an applet but not in appletviewer?
protected  int _localPort
          The local port of the server socket to listen on if we use a server socket, otherwise -1
protected  int _maxPort
          The maximum port to have the the server socket listen to if we use a server socket, defaults to 0 which will randomly choose an open port
protected  java.lang.String _mimeType
          The mime type of the content
protected  int _minPort
          The minimum port to have the the server socket listen to if we use a server socket, defaults to 0 which will randomly choose an open port
protected  java.lang.StringBuffer _printBuf
          A StringBuffer where verbose debugging text gets accumulated before being written to the text area.
protected  java.awt.Dialog _printDialog
          The dialog for holding a text area where verbose debug info gets written.
protected  java.awt.TextArea _printText
          The text area to write to in the dialog
protected  java.net.ServerSocket _server
          The server socket we listen on if we use a server socket
protected static boolean _useEcho
          Should we be using echocgi.exe?
protected static boolean _useSockets
          Should we be using sockets?
protected static boolean _verbose
          Should we be writing out debugging info to a dialog we create?
protected static java.lang.String BROWSER
          Name of the java.lang.System property which tells us which web browser we're in.
static int CANT_ACCEPT
          Can't accept server connection.
static int CANT_GET_OUTPUT_STREAM
          Can't get output stream.
static int CANT_GET_REQUEST
          Can't get the full HTTP request from the client.
static int CANT_OPEN_SERVERSOCKET
          Can't open server socket.
static int ERROR_CREATING_URL
          Error while creating URL.
static int ERROR_INVOKING_APP
          Error while invoking application.
static int ERROR_SENDING_CONTENT
          Error while sending content.
static int ERROR_SENDING_HEADER
          Error while sending content header.
static int ERROR_WRITING_FILE
          Error while writing data to file.
static java.lang.String[] errorMsgs
           
static java.lang.String RB_KEY
           
protected static int serverTimeOut
          The time out value in milli seconds set on the server socket, default value is 30000 (30 secs)
static int SUCCESS
          Success.
static int TIMED_OUT
          Timed out waiting for connection.
 
Constructor Summary
ContentServer()
          Constructs a ContentServer object.
ContentServer(java.lang.String contentType, byte[] content, java.lang.String fileName)
           
ContentServer(java.lang.String contentType, java.lang.StringBuffer content, java.lang.String fileName)
           
ContentServer(java.lang.String contentType, java.lang.String content, java.lang.String fileName)
           
 
Method Summary
protected  void dumpSysProps()
          Debugging -- dumps system properties.
static void export(byte[] content, java.lang.String contentType, java.lang.String browser, java.lang.String fileExt)
          Exports the content given with a suggestion of a browser application.
static void export(byte[] content, java.lang.String contentType, java.lang.String browser, java.lang.String fileExt, int timeOut)
          Exports the content given with a suggestion of a browser application.
static void export(byte[] content, java.lang.String contentType, java.lang.String app, java.lang.String args, java.lang.String fileExt)
          Exports the content given with a suggestion of an application.
static void export(byte[] content, java.lang.String contentType, java.lang.String app, java.lang.String args, java.lang.String fileExt, int timeOut)
          Exports the content given with a suggestion of an application.
static void export(byte[] content, java.lang.String contentType, java.lang.String app, java.lang.String args, java.lang.String browser, java.lang.String fileExt)
          Exports the content given with suggestions for an application and a browser application (potentially null).
static void export(byte[] content, java.lang.String contentType, java.lang.String app, java.lang.String args, java.lang.String browser, java.lang.String fileExt, int timeOut)
          Exports the content given with suggestions for an application and a browser application (potentially null).
static void export(byte[] content, java.lang.String contentType, java.lang.String app, java.lang.String args, java.lang.String browser, java.lang.String fileExt, int timeOut, int minPort, int maxPort)
          Exports the content given with suggestions for an application and a browser application (potentially null).
static void export(java.lang.String content, java.lang.String contentType, java.lang.String browser, java.lang.String fileExt)
          Exports the content given with the suggestion of a browser application.
static void export(java.lang.String content, java.lang.String contentType, java.lang.String browser, java.lang.String fileExt, int timeOut)
          Exports the content given with the suggestion of a browser application.
static void export(java.lang.String content, java.lang.String contentType, java.lang.String app, java.lang.String args, java.lang.String fileExt)
          Exports the content given with the suggestion of an application.
static void export(java.lang.String content, java.lang.String contentType, java.lang.String app, java.lang.String args, java.lang.String fileExt, int timeOut)
          Exports the content given with the suggestion of an application.
 java.lang.String getBaseTempFileName()
          Returns the prefix used for creating filenames for temporary files.
 byte[] getContent()
          Returns the content to export.
static java.lang.String getEchoURL()
           
 java.lang.String getFileExtension()
           
 java.lang.String getFileName()
           
 int getLocalPort()
          only valid after openServer() is called
 int getMaxPort()
          Returns the maximum port to be used when opening up a ServerSocket, the default is 0.
 java.lang.String getMIMEType()
          Returns the MIME type we will use.
 int getMinPort()
          Returns the minimum port to be used when opening up a ServerSocket, the default is 0.
static java.lang.String[] getPossibleEchoURLs()
          Returns the possible urls to look for echocgi on the originating web server.
static int getTimeOut()
           
static boolean isExportAllowed()
          Determines if exporting is allowed.
static boolean isExportToDiskAllowed()
          Determines if exporting to disk is allowed.
static boolean isExportUsingEchoCGIAllowed()
          Determines if exporting using echocgi is allowed.
static boolean isExportUsingSocketsAllowed()
          Determines if exporting using sockets is allowed.
static void main(java.lang.String[] args)
          test code
 int openServer()
          Starts the socket server.
protected  boolean pathExists(java.lang.String path)
          Used to check whether a file exists.
protected  void println(java.lang.String s)
          For debugging -- creates a dialog with a TextArea and sends a lot of debugging status information to it.
protected  void printStackTrace(java.lang.Throwable t)
          For debugging -- sends the stack trace to the debug dialog.
protected  void readInputStream(java.net.Socket s)
          Not currently used; really not useful for anything other than debugging
static void resetCheck()
          Before any exporting we call isExportAllowed() to check if we are allowed to export.
 void run()
          The mini-web server thread - just serve content requested.
protected  void sendContent(java.io.OutputStream os)
          Sends the Content to the client.
protected  java.lang.String sendCreateCmd()
          Sends the content to the echocgi.
protected  void sendDeleteCmd(java.lang.String resultsFile)
          Sends the delete command to echocgi to tell it to delete the content.
protected  void sendHeader(java.io.OutputStream os)
          Sends the HTTP header to the client.
protected  void sendShowCmd(java.lang.String resultsFile)
          Sends the show command to a new browser window.
 int sendToApplication(boolean deleteFile)
          Writes the content to a file on the disk and opens the application pointing to that file.
 int sendToBrowser()
          Sends the content to the browser either with a socket or with echocgi.
 int sendToBrowserApp()
          Send to browser where browser must first be invoked.
protected  int sendToBrowserEcho()
          Sends the content to the browser by bouncing it off the server using echocgi.
protected  int sendToBrowserServerSocket()
          Serves the content to the browser via an internal web server.
 int serveContent()
          Serves the content in response to a request to this mini-web server.
protected  int serveContentImpl()
          Does the work of serving the content in reponse to a request to this mini-web server.
 boolean setApplication(java.lang.String application, java.lang.String args)
          Sets the application name for exporting to an application.
 void setBaseTempFileName(java.lang.String prefix)
          Sets the prefix used for creating filenames for temporary files.
 boolean setBrowser(java.lang.String browser)
          Sets the name of the browser.
 void setContent(byte[] content)
          Sets the content to export.
 void setContent(java.lang.String content)
          Sets the content to export.
 void setContent(java.lang.StringBuffer content)
          Sets the content to export.
 void setContentType(java.lang.String contentType)
          Deprecated. use setMIMEType
 void setFileExtension(java.lang.String extension)
          File extension, such as csv, doc, or pdf
 void setFileName(java.lang.String fileName)
          Sets the filename to be used with sendToApplication.
 void setMaxPort(int maxPort)
          Sets the maximum port to be used when opening up a ServerSocket.
 void setMIMEType(java.lang.String mimeType)
          Sets the MIME type to use when exporting.
 void setMinPort(int minPort)
          Sets the minimum port to be used when opening up a ServerSocket.
static void setPossibleEchoURLs(java.lang.String[] echoURLs)
          Sets the urls to search for echocgi.
static void setTimeOut(int newTimeOut)
          Sets the time out value for the server socket in milli seconds.
static ContentServer setupTest()
           
static void setVerbose(boolean verbose)
          Indicates whether debug information should be sent to a debugging dialog.
 void showStatus(java.lang.String status)
          Displays a message in the browser's status bar
static void test()
           
static void testApplet(java.applet.Applet applet)
           
static void testBrowser(java.lang.String browserPath)
           
static void testExcel(java.lang.String excelPath)
           
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

_content

protected byte[] _content
The content to be served as a byte array


_mimeType

protected java.lang.String _mimeType
The mime type of the content


_server

protected java.net.ServerSocket _server
The server socket we listen on if we use a server socket


_localPort

protected int _localPort
The local port of the server socket to listen on if we use a server socket, otherwise -1


_minPort

protected int _minPort
The minimum port to have the the server socket listen to if we use a server socket, defaults to 0 which will randomly choose an open port


_maxPort

protected int _maxPort
The maximum port to have the the server socket listen to if we use a server socket, defaults to 0 which will randomly choose an open port


serverTimeOut

protected static int serverTimeOut
The time out value in milli seconds set on the server socket, default value is 30000 (30 secs)


_fileName

protected java.lang.String _fileName
The file name of the file to be


_extension

protected java.lang.String _extension
The extension of the file (eg csv)


_browser

protected java.lang.String _browser
The path of the browser if using sendToBrowserApp


_application

protected java.lang.String _application
The path of the application if using sendToApplication


_isInApplet

protected static boolean _isInApplet
Are we in an applet but not in appletviewer?


_useSockets

protected static boolean _useSockets
Should we be using sockets?


_useEcho

protected static boolean _useEcho
Should we be using echocgi.exe?


_echoURL

protected static java.lang.String _echoURL
The url of the echocgi.exe that we found


_echoURLs

protected static java.lang.String[] _echoURLs
The possible URLs for echocgi.exe - by default either Windows or Unix at /sasweb/cgi-bin/echocgi


_checked

protected static boolean _checked
Have we checked if we can export and by what method?

See Also:
isExportAllowed(), resetCheck()

_canWriteToDisk

protected static boolean _canWriteToDisk
Are we allowed to write to disk?


_counter

protected static int _counter
How many exports have we done?


BROWSER

protected static final java.lang.String BROWSER
Name of the java.lang.System property which tells us which web browser we're in.

See Also:
Constant Field Values

_verbose

protected static boolean _verbose
Should we be writing out debugging info to a dialog we create?


_printBuf

protected java.lang.StringBuffer _printBuf
A StringBuffer where verbose debugging text gets accumulated before being written to the text area.


_printText

protected java.awt.TextArea _printText
The text area to write to in the dialog


_printDialog

protected java.awt.Dialog _printDialog
The dialog for holding a text area where verbose debug info gets written.


SUCCESS

public static final int SUCCESS
Success.

See Also:
sendToApplication(boolean), sendToBrowserApp(), sendToBrowser(), sendToBrowserEcho(), sendToBrowserServerSocket(), openServer(), serveContent(), serveContentImpl(), Constant Field Values

CANT_OPEN_SERVERSOCKET

public static final int CANT_OPEN_SERVERSOCKET
Can't open server socket.

See Also:
sendToBrowserApp(), sendToBrowser(), sendToBrowserServerSocket(), openServer(), Constant Field Values

CANT_ACCEPT

public static final int CANT_ACCEPT
Can't accept server connection.

See Also:
sendToBrowser(), serveContent(), serveContentImpl(), Constant Field Values

CANT_GET_OUTPUT_STREAM

public static final int CANT_GET_OUTPUT_STREAM
Can't get output stream.

See Also:
serveContent(), serveContentImpl(), Constant Field Values

TIMED_OUT

public static final int TIMED_OUT
Timed out waiting for connection.

See Also:
serveContent(), serveContentImpl(), Constant Field Values

ERROR_SENDING_HEADER

public static final int ERROR_SENDING_HEADER
Error while sending content header.

See Also:
serveContent(), serveContentImpl(), Constant Field Values

ERROR_SENDING_CONTENT

public static final int ERROR_SENDING_CONTENT
Error while sending content.

See Also:
sendToBrowser(), sendToBrowserEcho(), sendToBrowserServerSocket(), serveContent(), serveContentImpl(), Constant Field Values

ERROR_CREATING_URL

public static final int ERROR_CREATING_URL
Error while creating URL.

See Also:
sendToBrowserServerSocket(), sendToBrowser(), Constant Field Values

ERROR_WRITING_FILE

public static final int ERROR_WRITING_FILE
Error while writing data to file.

See Also:
sendToApplication(boolean), Constant Field Values

ERROR_INVOKING_APP

public static final int ERROR_INVOKING_APP
Error while invoking application.

See Also:
sendToApplication(boolean), sendToBrowserApp(), Constant Field Values

CANT_GET_REQUEST

public static final int CANT_GET_REQUEST
Can't get the full HTTP request from the client.

See Also:
serveContent(), serveContentImpl(), Constant Field Values

errorMsgs

public static final java.lang.String[] errorMsgs
Constructor Detail

ContentServer

public ContentServer()
Constructs a ContentServer object.


ContentServer

public ContentServer(java.lang.String contentType,
                     byte[] content,
                     java.lang.String fileName)
Parameters:
contentType - The content's MIME type
content - The content to be sent
fileName - The file name to be used in a URL (when sendToBrowser is called) or the file to be written to disk (when sendToApplication is called)

ContentServer

public ContentServer(java.lang.String contentType,
                     java.lang.StringBuffer content,
                     java.lang.String fileName)
Parameters:
contentType - The content's MIME type
content - The content to be sent
fileName - The file name to be used in a URL (when sendToBrowser is called) or the file to be written to disk (when sendToApplication is called)

ContentServer

public ContentServer(java.lang.String contentType,
                     java.lang.String content,
                     java.lang.String fileName)
Parameters:
contentType - The content's MIME type
content - The content to be sent
fileName - The file name to be used in a URL (when sendToBrowser is called) or the file to be written to disk (when sendToApplication is called)
Method Detail

resetCheck

public static void resetCheck()
Before any exporting we call isExportAllowed() to check if we are allowed to export. Calling resetCheck() forces isExportAllowed() to determine afresh whether exporting is in fact allowed and what method to use.

See Also:
isExportAllowed()

getBaseTempFileName

public java.lang.String getBaseTempFileName()
Returns the prefix used for creating filenames for temporary files.


setBaseTempFileName

public void setBaseTempFileName(java.lang.String prefix)
Sets the prefix used for creating filenames for temporary files. The temporary filename(s) will be named as: prefix + counter value (initial value of 0, incremented each time a file is created) + file extension. The prefix must have a minimum length of 3 characters.

Parameters:
prefix - filename prefix

isExportUsingSocketsAllowed

public static boolean isExportUsingSocketsAllowed()
Determines if exporting using sockets is allowed.

See Also:
export(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), sendToBrowser(), sendToBrowserServerSocket()

isExportUsingEchoCGIAllowed

public static boolean isExportUsingEchoCGIAllowed()
Determines if exporting using echocgi is allowed.

See Also:
export(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), sendToBrowser(), sendToBrowserEcho()

isExportToDiskAllowed

public static boolean isExportToDiskAllowed()
Determines if exporting to disk is allowed.

See Also:
export(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), sendToApplication(boolean), sendToBrowserApp()

isExportAllowed

public static boolean isExportAllowed()
Determines if exporting is allowed. This is accomplished by performing the following:

if an applet NOT running in appletviewer:


if an application or an applet running in appletviewer:



This method will return a boolean indicating whether export is allowed; it does not return any information as to which method it determined should be used for export. To determine whether a method is permissible for export, the user can invoke one of the methods listed below (.ie call isExportToDiskAllowed if you wish to know if you can write to disk).

See Also:
sendToBrowser(), sendToBrowserServerSocket(), sendToBrowserEcho(), sendToApplication(boolean), sendToBrowserApp(), export(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String), resetCheck()

export

public static void export(java.lang.String content,
                          java.lang.String contentType,
                          java.lang.String app,
                          java.lang.String args,
                          java.lang.String fileExt)
Exports the content given with the suggestion of an application.

Parameters:
content - The content to be served as a String
contentType - The MIME type of the content
app - The name of the application to export to
args - The arguments to pass to the application
fileExt - The extension of the file to pass it - eg csv

export

public static void export(java.lang.String content,
                          java.lang.String contentType,
                          java.lang.String app,
                          java.lang.String args,
                          java.lang.String fileExt,
                          int timeOut)
Exports the content given with the suggestion of an application.

Parameters:
content - The content to be served as a String
contentType - The MIME type of the content
app - The name of the application to export to
args - The arguments to pass to the application
fileExt - The extension of the file to pass it - eg csv
timeOut - The time out value to use on the ServerSocket

export

public static void export(java.lang.String content,
                          java.lang.String contentType,
                          java.lang.String browser,
                          java.lang.String fileExt)
Exports the content given with the suggestion of a browser application.

Parameters:
content - The content to be served as a String
contentType - The MIME type of the content
browser - The name of the browser to use - eg "iexplore.exe"
fileExt - The extension of the file to pass it - eg csv

export

public static void export(java.lang.String content,
                          java.lang.String contentType,
                          java.lang.String browser,
                          java.lang.String fileExt,
                          int timeOut)
Exports the content given with the suggestion of a browser application.

Parameters:
content - The content to be served as a String
contentType - The MIME type of the content
browser - The name of the browser to use - eg "iexplore.exe"
fileExt - The extension of the file to pass it - eg csv
timeOut - The time out value to use on the ServerSocket

export

public static void export(byte[] content,
                          java.lang.String contentType,
                          java.lang.String app,
                          java.lang.String args,
                          java.lang.String fileExt)
Exports the content given with a suggestion of an application.

Parameters:
content - The content to be served as an array of bytes.
contentType - The MIME type of the content
app - The name of the application to export to
args - The arguments to pass to the application
fileExt - The extension of the file to pass it - eg csv

export

public static void export(byte[] content,
                          java.lang.String contentType,
                          java.lang.String app,
                          java.lang.String args,
                          java.lang.String fileExt,
                          int timeOut)
Exports the content given with a suggestion of an application.

Parameters:
content - The content to be served as an array of bytes.
contentType - The MIME type of the content
app - The name of the application to export to
args - The arguments to pass to the application
fileExt - The extension of the file to pass it - eg csv
timeOut - The time out value to use on the ServerSocket

export

public static void export(byte[] content,
                          java.lang.String contentType,
                          java.lang.String browser,
                          java.lang.String fileExt)
Exports the content given with a suggestion of a browser application.

Parameters:
content - The content to be served as an array of bytes.
contentType - The MIME type of the content
browser - The name of the browser to use - eg "iexplore.exe"
fileExt - The extension of the file to pass it - eg csv

export

public static void export(byte[] content,
                          java.lang.String contentType,
                          java.lang.String browser,
                          java.lang.String fileExt,
                          int timeOut)
Exports the content given with a suggestion of a browser application.

Parameters:
content - The content to be served as an array of bytes.
contentType - The MIME type of the content
browser - The name of the browser to use - eg "iexplore.exe"
fileExt - The extension of the file to pass it - eg csv
timeOut - The time out value to use on the ServerSocket

export

public static void export(byte[] content,
                          java.lang.String contentType,
                          java.lang.String app,
                          java.lang.String args,
                          java.lang.String browser,
                          java.lang.String fileExt)
Exports the content given with suggestions for an application and a browser application (potentially null).

Parameters:
content - The content to be served as an array of bytes.
contentType - The MIME type of the content
app - The name of the application to export to
args - The arguments to pass to the application
browser - The name of the browser to use - eg "iexplore.exe"
fileExt - The extension of the file to pass it - eg csv

export

public static void export(byte[] content,
                          java.lang.String contentType,
                          java.lang.String app,
                          java.lang.String args,
                          java.lang.String browser,
                          java.lang.String fileExt,
                          int timeOut)
Exports the content given with suggestions for an application and a browser application (potentially null).

Parameters:
content - The content to be served as an array of bytes.
contentType - The MIME type of the content
app - The name of the application to export to
args - The arguments to pass to the application
browser - The name of the browser to use - eg "iexplore.exe"
fileExt - The extension of the file to pass it - eg csv
timeOut - The time out value to use on the ServerSocket

export

public static void export(byte[] content,
                          java.lang.String contentType,
                          java.lang.String app,
                          java.lang.String args,
                          java.lang.String browser,
                          java.lang.String fileExt,
                          int timeOut,
                          int minPort,
                          int maxPort)
Exports the content given with suggestions for an application and a browser application (potentially null).

Parameters:
content - The content to be served as an array of bytes.
contentType - The MIME type of the content
app - The name of the application to export to
args - The arguments to pass to the application
browser - The name of the browser to use - eg "iexplore.exe"
fileExt - The extension of the file to pass it - eg csv
timeOut - The time out value to use on the ServerSocket
minPort - The minimum port to open the ServerSocket on if a ServerSocket is used, default is 0 which causes a random port to be used
maxPort - The maximum port to open the ServerSocket on if a ServerSocket is used, default is 0 which causes a random port to be used

setTimeOut

public static void setTimeOut(int newTimeOut)
Sets the time out value for the server socket in milli seconds. Default value is 30000 (30 seconds).

Parameters:
newTimeOut - The time out value to use
See Also:
getTimeOut()

getTimeOut

public static int getTimeOut()

setPossibleEchoURLs

public static void setPossibleEchoURLs(java.lang.String[] echoURLs)
Sets the urls to search for echocgi.

Parameters:
echoURLs - Array of strings of relative urls to the nase URL of the originating web server.

getPossibleEchoURLs

public static java.lang.String[] getPossibleEchoURLs()
Returns the possible urls to look for echocgi on the originating web server.


getEchoURL

public static java.lang.String getEchoURL()

setApplication

public boolean setApplication(java.lang.String application,
                              java.lang.String args)
Sets the application name for exporting to an application.

Parameters:
The - name of the application we want to export to. eg quot;C:\\Microsoft Office\\Office\\Excel.exe"
args - The arguments to pass to the application

setBrowser

public boolean setBrowser(java.lang.String browser)
Sets the name of the browser.

Parameters:
The - name of the browser program or null for the system defined browser. Eg "c:\\Program Files\\Plus!\\Microsoft Internet\\iexplore.exe".

setVerbose

public static void setVerbose(boolean verbose)
Indicates whether debug information should be sent to a debugging dialog.

Parameters:
verbose - true means turn debugging on, false means turn it off.

sendToApplication

public int sendToApplication(boolean deleteFile)
Writes the content to a file on the disk and opens the application pointing to that file.

Parameters:
deleteFile - true means delete the temporary file when finished.
See Also:
SUCCESS, ERROR_WRITING_FILE, ERROR_INVOKING_APP

sendToBrowserApp

public int sendToBrowserApp()
Send to browser where browser must first be invoked.

See Also:
SUCCESS, ERROR_INVOKING_APP, CANT_OPEN_SERVERSOCKET

sendToBrowser

public int sendToBrowser()
Sends the content to the browser either with a socket or with echocgi.

See Also:
SUCCESS, CANT_ACCEPT, ERROR_SENDING_CONTENT, CANT_OPEN_SERVERSOCKET, ERROR_CREATING_URL

sendCreateCmd

protected java.lang.String sendCreateCmd()
                                  throws java.lang.Exception
Sends the content to the echocgi.

Throws:
java.lang.Exception - - MalformedURLException, IOException etc.

sendShowCmd

protected void sendShowCmd(java.lang.String resultsFile)
                    throws java.lang.Exception
Sends the show command to a new browser window.

Parameters:
resultsFile - The filename echocgi told us to ask for.
Throws:
java.lang.Exception - MalformedURLException, IOException, etc.

sendDeleteCmd

protected void sendDeleteCmd(java.lang.String resultsFile)
Sends the delete command to echocgi to tell it to delete the content. This waits for 1 minute for exporting to work and then deletes. It does this in a separate thread so this method returns immediately.

Parameters:
resultsFile - The file echocgi originally gave to us to identify our content.

sendToBrowserEcho

protected int sendToBrowserEcho()
Sends the content to the browser by bouncing it off the server using echocgi. A socket is opened to echocgi and data is written to the web server. A browser is then opened pointing to echocgi to load the data back.

See Also:
ERROR_SENDING_CONTENT, SUCCESS

sendToBrowserServerSocket

protected int sendToBrowserServerSocket()
Serves the content to the browser via an internal web server. This is accomplished by opening a web server on a random high local port within the applet and making a new browser window asking for the content from this server.

See Also:
SUCCESS, CANT_OPEN_SERVERSOCKET, ERROR_CREATING_URL, ERROR_SENDING_CONTENT

setFileName

public void setFileName(java.lang.String fileName)
Sets the filename to be used with sendToApplication. NOTE: File name with the file extension

Parameters:
fileName - The filename to use
See Also:
sendToApplication(boolean)

getFileName

public java.lang.String getFileName()

setFileExtension

public void setFileExtension(java.lang.String extension)
File extension, such as csv, doc, or pdf


getFileExtension

public java.lang.String getFileExtension()

setContentType

public void setContentType(java.lang.String contentType)
Deprecated. use setMIMEType


setMIMEType

public void setMIMEType(java.lang.String mimeType)
Sets the MIME type to use when exporting.

Parameters:
mimeType - The MIME type to use.

getMIMEType

public java.lang.String getMIMEType()
Returns the MIME type we will use.


setContent

public void setContent(byte[] content)
Sets the content to export.

Parameters:
content - The content.

setContent

public void setContent(java.lang.StringBuffer content)
Sets the content to export.

Parameters:
content - The content.

setContent

public void setContent(java.lang.String content)
Sets the content to export.

Parameters:
content - The content.

getContent

public byte[] getContent()
Returns the content to export.


getLocalPort

public int getLocalPort()
only valid after openServer() is called


setMinPort

public void setMinPort(int minPort)
Sets the minimum port to be used when opening up a ServerSocket. The default is 0 which will cause a random port number to be used. If the maximum port number is less then the new minimum port number, the maximum will be set equal to the minimum port.

Parameters:
minPort - the new minimum port number to be used
See Also:
getMinPort()

getMinPort

public int getMinPort()
Returns the minimum port to be used when opening up a ServerSocket, the default is 0.

Returns:
the minimum port number to use when opening a ServerSocket, users can use this to set a specfic port to open a ServerSocket on
See Also:
setMinPort(int)

setMaxPort

public void setMaxPort(int maxPort)
Sets the maximum port to be used when opening up a ServerSocket. The default is 0 which will cause a random port number to be used. If the minimum port number is more then the new maximum port number, the minimum will be set equal to the maximum port.

Parameters:
maxPort - the new maximum port number to be used
See Also:
getMaxPort()

getMaxPort

public int getMaxPort()
Returns the maximum port to be used when opening up a ServerSocket, the default is 0.

Returns:
the maximum port number to use when opening a ServerSocket, users can use this to set a specfic port to open a ServerSocket on
See Also:
setMaxPort(int)

openServer

public int openServer()
Starts the socket server.

See Also:
SUCCESS, CANT_OPEN_SERVERSOCKET

run

public void run()
The mini-web server thread - just serve content requested.

Specified by:
run in interface java.lang.Runnable

serveContent

public int serveContent()
Serves the content in response to a request to this mini-web server.

See Also:
SUCCESS, TIMED_OUT, CANT_ACCEPT, CANT_GET_OUTPUT_STREAM, ERROR_SENDING_HEADER, ERROR_SENDING_CONTENT, CANT_GET_REQUEST

serveContentImpl

protected int serveContentImpl()
Does the work of serving the content in reponse to a request to this mini-web server.

See Also:
SUCCESS, TIMED_OUT, CANT_ACCEPT, CANT_GET_OUTPUT_STREAM, ERROR_SENDING_HEADER, ERROR_SENDING_CONTENT, CANT_GET_REQUEST

sendHeader

protected void sendHeader(java.io.OutputStream os)
                   throws java.io.IOException
Sends the HTTP header to the client.

Parameters:
os - The output stream to write the header to.
Throws:
java.io.IOException - If there was an I/O problem.

sendContent

protected void sendContent(java.io.OutputStream os)
                    throws java.io.IOException
Sends the Content to the client.

Parameters:
os - The output stream to write the header to.
Throws:
java.io.IOException - If there was an I/O problem.

pathExists

protected boolean pathExists(java.lang.String path)
Used to check whether a file exists.

Parameters:
path - The path we want to check existence on.

showStatus

public void showStatus(java.lang.String status)
Displays a message in the browser's status bar

Parameters:
status - The message to display.

readInputStream

protected void readInputStream(java.net.Socket s)
Not currently used; really not useful for anything other than debugging

Parameters:
s - The socket to read input from.

println

protected void println(java.lang.String s)
For debugging -- creates a dialog with a TextArea and sends a lot of debugging status information to it.

Parameters:
s - The string to write.

printStackTrace

protected void printStackTrace(java.lang.Throwable t)
For debugging -- sends the stack trace to the debug dialog.

Parameters:
t - The error or exception to print a stack trace of.

dumpSysProps

protected void dumpSysProps()
Debugging -- dumps system properties.


setupTest

public static ContentServer setupTest()

testApplet

public static void testApplet(java.applet.Applet applet)

testExcel

public static void testExcel(java.lang.String excelPath)

testBrowser

public static void testBrowser(java.lang.String browserPath)

test

public static void test()

main

public static void main(java.lang.String[] args)
test code




Copyright © 2009 SAS Institute Inc. All Rights Reserved.