JavaXT Documentation

FileManager Class

Used to serve up static files (html, javascript, css, images, etc). Ensures static files are cached properly by browsers by appending version numbers to css and js files. Also updates js and css resources referenced inside html files and application-specific xml files. Redirects requests to the most recent version of each file. Sends 304 responses as required.

Constructors

FileManager( javaxt.io.Directory web )

Public Methods

getDirectory( ) returns javaxt.io.Directory
Returns the root directory.
getFileUpdates( EventMonitor eventMonitor ) returns void
Used to monitor the web directory for changes. Calls an EventMonitor whenever a file is created, updated, moved, or deleted. Example:
    fileManager.getFileUpdates((Directory.Event event) -> {
        String op;
        int eventID = event.getEventID();
        if (eventID==Directory.Event.CREATE){
            op = "create";
        }
        else if (eventID==Directory.Event.DELETE){
            op = "delete";
        }
        else{
            op = "update";
        }
        java.io.File file = new java.io.File(event.getFile());
        console.log(op, file);
    });     
getFile( HttpServletRequest request ) returns java.io.File
Returns a file that best matches the given HttpServletRequest. See the other getFile() method for more information.
getFile( String path ) returns java.io.File
Returns a file that best matches the given path. If the path represents a directory, searches for welcome files in the directory (e.g. "index.html"). Returns null if a file is not found.
pathRelative path to a file or folder, relative to the web root.
sendFile( HttpServletRequest request, HttpServletResponse response ) returns void
Used to send a file to the client. Determines which file to send via the URL path in the HTTP request.
sendFile( String path, HttpServletRequest request, HttpServletResponse response ) returns void
Used to send a file to the client. Determines which file to send via the given path.
pathRelative path to a file or folder, relative to the web root.
request
response
sendFile( javaxt.io.File file, HttpServletRequest request, HttpServletResponse response ) returns void
Used to send a file to the client.
sendFile( java.io.File file, HttpServletRequest request, HttpServletResponse response ) returns void
Used to send a file to the client.
updateLinks( javaxt.io.File xmlFile, org.w3c.dom.Document xml ) returns long
Used to update links to scripts and css files by appending a version number to the urls (?v=12345678). This operation is multi-threaded to improve performance.
updateLinks( javaxt.io.File xmlFile, ArrayList<Node> nodes ) returns long
updateNodes( NodeList nodes, org.w3c.dom.Document xml ) returns void
Adds empty comment blocks to "childless" nodes to prevent self-enclosing tags.
updateNode( Node node, org.w3c.dom.Document xml ) returns void
Adds an empty comment block to a node to prevent self-enclosing tags.

Public Classes