package page;

import org.wikiwebserver.core.WareHouse;
import org.wikiwebserver.handler.http.interfaces.HTTPResponder;

import page.config.SiteTemplatedPage;

import static org.wikiwebserver.html.HTMLHelper.*;

public class Index extends SiteTemplatedPage implements HTTPResponder {
	
    public void generate() {
        
        // For Google 
        appendToHead(meta("verify-v1", "cOnZ8ItRs3J1f+ma52ddCGGfdDS04c+RxmXCpwgVNO4="));

        // Extra CSS for nice layout
        addResourceRoot("/templates/default/home/");
        addCSSLink("home.css");  
        
        setTitle("WikiWebServer.org - The dynamic, rewritable Java web server");
        
        setDescription("A Java web server that provides a lightweight framework" +
                       " for rapidly creating advanced web applications.");

        
        String wikiMarkupLink = "http://en.wikipedia.org/wiki/" +
                                "Wikipedia:How_to_edit_a_page#Wiki_markup";

        String javaLink = "http://en.wikipedia.org/wiki/Java_(programming_language)";        
        String javaSourceLink = "http://en.wikipedia.org/wiki/Java_source_code";
        
        String coreOverview = WareHouse.getUrlPathForClass(page.misc.CoreOverview.class);
        String register = WareHouse.getUrlPathForClass(page.tools.admin.UserProfile.class);
        String develop = WareHouse.getUrlPathForClass(page.tools.management.SandBox.class);
        String distribute = WareHouse.getUrlPathForClass(page.misc.DistributeWikiWebServer.class);
        
        append(
            h(1, "What is <em>WikiWebServer</em>?") +
            image("HandDrawingHand.jpg", "The Drawing Hands", "id='wikiWayLogo'") +
            p("WikiWebServer is a lightweight " + a(javaLink, "Java") + " web server " +
            " that provides a framework for rapidly developing advanced web " +
            " applications.") +
            p("By incorporating web-based code editing facilities, dynamic recompilation" +
            " and automatic class reloading, WikiWebServer can be programmed to do almost" +
            " anything using just an Internet browser from anywhere in the world!") +
            p("WikiWebServer can handle HTTP requests quickly and efficiently making " +
            " it ideal for developing interactive Ajax web pages.") +
            p("WikiWebServer was created by " + 
              a("http://www.michaelgardiner.info/", "Michael Gardiner") +
            " and is used as a playground to develop, test and demonstrate new ideas.") +            
            h(2, "To learn more") +
            ul(new String[] {
                    a(coreOverview, "View") + " the core Java classes",
                    a(register, "Register") + " a user account and " +
                        a(develop, "develop") + " dynamic pages",
                    a(distribute, "Launch") + " WikiWebServer on your own computer"
            })
        );      
        
        
        append(
            h(1, "What makes WikiWebServer special?") +
            image("DukeWithHelmet.png", "Open Source Duke", "id='dukeLogo'") +   
            ul(new String[] {
                
                "Speed" + br() +
                "<span class='liInfo'>WikiWebServer compiles dynamic pages to Java" +
                " binaries that can be executed rapidly. Most web servers generate" +
                " dynamic pages by interpreting scripts, e.g. PHP, Perl, ASP etc, which" +
                " is much slower. WikiWebServer can respond to over 2,000 requests for " +
                " dynamic content every second on an entry level computer.</span>",
                
                "Versatility" + br() +
                "<span class='liInfo'>WikiWebServer can be modified while it is running" +
                " to perform complicated tasks that would otherwise be impossible due to" +
                " web server or scripting language limitations. No need for complicated" +
                " configurations, write and compile logic straight into the server!</span>",
                
                "High level functionality" + br() +
                "<span class='liInfo'>WikiWebServer makes high level operations much" +
                " easier. For example, returning a dynamic image (java.awt.image.BufferedImage)" +
                " automatically compresses the image to JPEG or GIF, updates the headers " +
                " (Content-Type and Content-Length) and sends the binary data to the client." +
                "</span>",
            
                "Low level support" + br() +      
                "<span class='liInfo'>WikiWebServer makes it possible to read and write" +
                " directly to a connection byte by byte - should you need to.</span>",
            
                "Simplicity" + br() +      
                "<span class='liInfo'>Everything is kept simple. No complicated API's or" +
                " libraries have been used, just plain old Java objects.</span>", 
            
                "Tools included" + br() +    
                "<span class='liInfo'>Dynamic pages can be written directly from within" +
                " the browser. WikiWebServer saves and compiles the page and will alert of" +
                " any syntax errors.</span>",
                
                "Managed persistence" + br() +   
                "<span class='liInfo'>WikiWebServer makes it easy to store and retrieve" +
                " data from long term storage without the overheads of database or file-" +
                "based data transfers.</span>",     
                
                "Mobile device enhancements" + br() +   
                "<span class='liInfo'>Page classes extending a WikiWebServer TemplatedPage" +
                " are automatically formatted for mobile devices. This includes changing" +
                " page content such as images to fit small screens. WikiWebServer can even" +
                " provide an audio version of TemplatedPages!</span>",    
            
                "Error handling" + br() +
                "<span class='liInfo'>Exceptions thrown by errors on dynamic pages are" +
                " handled and displayed with links directly to the source code that caused" +
                " the error, making debugging very easy.</span>",
            
                "Self contained" + br() +
                "<span class='liInfo'>WikiWebServer does not rely on other applications" +
                " or use a servlet container. WikiWebServer processes raw socket connections" +
                " from clients, processes HTTP requests and returns responses.</span>",
            
                "Light weight" + br() +
                "<span class='liInfo'>WikiWebServer typically consumes less than 4MB RAM" +
                " while idle and less than 32MB while processing 100 simultaneous requests." +
                "</span>",                           
            
                "Easy to follow" + br() +
                "<span class='liInfo'>The entire code for WikiWebServer is viewable from" +
                " within a web browser which makes tracing execution easy.</span>",
                
                "Reliability" + br() +
                "<span class='liInfo'>WikiWebServer.org and several other web sites have been" +
                " hosted on a development version of WikiWebServer which has provided " +
                " a 99.998% up time for the last year.  WikiWebServer is an incredibly stable" +
                " platform which can self heal within 3 seconds after a software fault." +
                "</span>",
                
                "Disaster Recovery" + br() +
                "<span class='liInfo'>Periodic automatic synchronisation of internal data" +
                " with backup WikiWebServers makes it easy to fail over to another server without" +
                " loosing persistent data." +
                "</span>",                
                
                "Handles traffic surges" + br() +
                "<span class='liInfo'>Managed internal caching of response objects makes it" +
                " possible to handle thousands of requests per second and deliver over 3GB/s" +
                " throughput. Velocity enforcement actively blocks bad traffic patterns and" +
                " maintains stability in the event of an attack." +
                "</span>",                 
                
                "Easy to update" + br() +
                "<span class='liInfo'>Updates to dynamic pages or classes outside the core" +
                " can be made without taking WikiWebServer offline.  Class reloading is" +
                " connection isolated meaning that active connections are not affected" +
                " by class updates.  Even a complete JVM restart after a core modification" +
                " results in less than 3 seconds down time and does not lose session data." +
                " This makes WikiWebServer ideal for evolving server applications." +
                "</span>"                
                
            })
        );
                   
        
        String fractalLink = WareHouse.getUrlPathForClass(page.example.FractalGallery.class);
        
        append(
            h(1, "Featured Examples") + h(2, "Dynamic Fractal Gallery") +
            a(fractalLink, image("fractal.jpg", "FractalGallery Image", "id='featuredImage'")) + 
            p("Fractal Gallery is a WikiWebServer page that dynamically generates fractal images.") +
            p("It is built from two classes, FractalGallery and Fractal. The FractalGallery" +
            " class is responsible for generating an HTML page containing the dynamic" +
            " fractal image and a gallery of snapshots taken by users. The dynamic" +
            " fractal image is rendered by the Fractal class, which accepts" +
            " a number of parameters to alter location and zoom level.  By clicking" +
            " the image, the parameters are set to zoom into the clicked region. " +
            a(fractalLink, "Navigate Fractal Gallery") + ".") + cleardiv()
        );
        
        String mobiliserLink = WareHouse.getUrlPathForClass(page.example.Mobiliser.class);
        
        append(
                h(2, "Mobiliser") +
                p("Reformats web sites for mobile devices. Strips web pages of complicated" +
                " formatting and resizes embedded images so that standard pages can be viewed" +
                " on portable devices using minimal bandwidth. " + 
                a(mobiliserLink, "Surf within Mobiliser")) +
                cleardiv()
            );   
        
        String imageGalleryLink = WareHouse.getUrlPathForClass(page.example.ImageGallery.class);
        
        append(
                h(2, "Image Gallery") +
                p("Generates thumbnails for directories containing images. Previewed images" +
                " are dynamically scaled to fit the browser and links are provided to download" +
                " each image in a range of resolutions. " + a(imageGalleryLink, "Image Gallery")) + 
                cleardiv()
            );          
        
        String text2speechLink = WareHouse.getUrlPathForClass(page.example.TextToSpeech.class);
        
        append(
                h(2, "Text to speech") +
                p("Uses the free Java text to speech library, FreeTTS, to convert a" +
                " passage of text into an audio stream. As with all WikiWebServer " +
                " components, the text to speech capability can be used within other " +
                " WikiWebServer classes. " + a(text2speechLink, "Text to speech")) + 
                cleardiv()
            );          
    

        append(
            h(1, "How does WikiWebServer differ from other Wiki-based sites?") +
            p("Most Wiki-based sites online allow users to create page content in" +
            " a predefined way using " + a(wikiMarkupLink, "Wiki markup") + "." +
            " WikiWebServer allows users to write " + a(javaSourceLink, "Java source code") +
            " which is compiled and executed by WikiWebServer to generate page content." +
            " Dynamic recompilation and class loading makes it possible to change" +
            " the core functionality of any part of WikiWebServer while it is still" +
            " running (depending on start-up configuration).") +
            p("Essentially this means that users are not restricted to creating" +
            " static pages of text and images. Instead pages rich in functionality" +
            " incorporating dynamic text, images and complicated Ajax features can" +
            " be created.")
        );
        
        append(
                h(1, "Sites hosted on this WikiWebServer") +
                p("The following sites are hosted on WikiWebServer.") +
                ul(new String[] {
                    a("http://www.mydisk.co.uk", "MyDisk") + 
                        " Share your hard disk online.",                		
                    a("http://www.googleoids.com", "Googleoids") + 
                        " A crazy game crossing Scrabble and Searching.",
                    a("http://www.jfilerecovery.com", "JFileRecovery") + 
                        " Useful software utility for reading damaged data.",
                    a("http://www.jrsstray.com", "JRSSTray") + 
                        " Monitors RSS news feeds and displays new items in the tray.",
                    /* a("http://www.jfirewalltest.com", "JFirewallTest") + 
                        " Lists open ports and possible trojans that might be using them." */
                })
        );          

        String counterUrl = WareHouse.getUrlPathForClass(page.image.Counter.class) + "?size=11&amp;name=Home";
        append(image(counterUrl, "Page hits", "id='counterImage'") + cleardiv());
    }
}