{curl 7.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
{applet manifest = "manifest.mcurl", curl-root = ".",
    {compiler-directives careful? = true}
}
|| Copywrite (C) Bob Marriott 2008 - You are granted permission to do anything you would like with this source code provided you assume all liability. 

|| Lets make it an OCC App

{do {occ-install-or-update occ-root-installer}}

|| Couldn't help it!
Hello World!

|| Lets show where the Data will go
The location of 'curl://local-data' is '{{url "curl://local-data"}.canonicalize}'.

|| Lets run the app - If we are connected lets get the data from the server and save it
|| if we are not lets read the copy we last saved.  Note - there is no error catching if
|| this is run disconnected the first time
{value || instead of do - this allows me to show a value in the browser (see the "vb" at the bottom)
    let vb:VBox = {VBox} || a place to hold what we have done
    {if not {network-disconnected?} then || we are connected
        {vb.add "Data from Web"}
        let buff:String = ""
        let data:{Array-of String} = {{Array-of String}}

        || A handy way to open and close files - lets get the web version
        {with-open-streams in = {read-open {url "http://www.westboro.org/occ1/data.php"}} do
            {while not in.end-of-stream? do || read all of the lines/save/display - note csv format
                set buff = {{in.read-line}.to-String}
                {data.append buff}
                {vb.add buff}
            }
        }
        || now save to local storeage
        {with-open-streams out = {write-open {url "curl://local-data/local.dat"}} do
            {for buff in data do
                {out.write-one-string buff}
                {out.write-one '\n'}
            }
        }
    }
    
    || oops no connection - lets read from local
    {if {network-disconnected?} then
        {vb.add "Data from local"}
        let buff:String = ""
        let data:{Array-of String} = {{Array-of String}}
        
        {with-open-streams in = {read-open {url "curl://local-data/local.dat"}} do
            {while not in.end-of-stream? do
                set buff = {{in.read-line}.to-String}
                {data.append buff}
                {vb.add buff}
            }
        }
     
    }
    || lets show what we have
    vb
}