Changing the Please Wait status message

In progress documentation

Please note: this documentation is currently in the process of being written 

Changing the please wait status message

Changing the please wait status message requires skill, agility and depending on the method you take, coffee and a executive stress relief tool.

There are two steps involved in defining a status message for the Cooee framework:

  1. Define a delay message
    This can be done by either:
    1. Create an implementation of "ServerDelayMessage"
    2. Create an XML based template
  1. Register the delay message with the framework

The easiest mechanism for this is by far defining a template and simply registering the template with the framework. However for absolute control, you may want to go down the road of implementing your own logic for the delay message. Both methods are explained below.

Templating

ServerDelayMessage
/**
 * Creates a new concrete <code>ServerDelayMessage</code> implementation
 * based on the HTML fragment contained in the specified
 * <code>CLASSPATH</code> resource
 *
 * @param resourceName the <code>CLASSPATH</code> resource containing the
 * HTML fragment
 * @return the created <code>ServerDelayMessage</code>
 * @throws IOException if the resource cannot be found or parsed
 *
 */
public static ServerDelayMessage createFromResource(String resourceName) throws IOException;

Above is a snippet from the ServerDelayMessage class showing the method signature you'll be interested in for templating.  It's important to note that a template represents a XHTML Fragment NOT a complete XHTML class.  *Define only the section of XHTML that will be displayed on the screen*:

Be aware, any images you use as part of your template must be able to be accessed statically by the container - you won't have ImageService id's from Cooee available prior to runtime.

The old school way 

Defining an implementation of a server delay message can be as easy or as hard as you want to make it. Below is an example of a full blown implementation of a ServerDelayMessage:

CooeeCustomDelayMessage
package com.xbio.xxxxxx.cooee.config;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

import org.karora.cooee.app.util.Uid;
import org.karora.cooee.osgi.BundleServices;
import org.karora.cooee.webcontainer.ContainerContext;
import org.karora.cooee.webrender.ClientProperties;
import org.karora.cooee.webrender.Connection;
import org.karora.cooee.webrender.ContentType;
import org.karora.cooee.webrender.ServerDelayMessage;
import org.karora.cooee.webrender.Service;
import org.karora.cooee.webrender.WebRenderServlet;
import org.karora.cooee.webrender.output.HtmlDocument;
import org.karora.cooee.webrender.output.XmlDocument;
import org.osgi.framework.BundleContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * Nasty code.
 * @author dmurley
 *
 */

public class XxxxxxServerDelayMessage extends ServerDelayMessage {
    private static int BUFFER_SIZE = 4096;
    private static String IMAGE_RESOURCE_NAME = "/com/xbio/xxxxxx/cooee/resources/images/ajax-loader.gif";
    private static String TRANSLUCENT_IMAGE = "/com/xbio/xxxxxx/cooee/config/translucent_80_percent.png";


    private static Service IMAGE_SERVICE = new ImageService();
    private static Service TRANSLUCENCENT_IMAGE_SERVICE = new TranslucentImageService();
    static {
        WebRenderServlet.getServiceRegistry().add(IMAGE_SERVICE);
        WebRenderServlet.getServiceRegistry().add(TRANSLUCENCENT_IMAGE_SERVICE);
    }

    private static class TranslucentImageService extends ImageService
    {
        protected static final String SERVICE_ID = Uid.generateUidString();

        /**
         * @see org.karora.cooee.webrender.Service#getId()
         */
        public String getId() {
            return SERVICE_ID;
        }
        /**
         * @see org.karora.cooee.webrender.Service#service(org.karora.cooee.webrender.Connection)
         */
        public void service(Connection conn) throws IOException {
            conn.setContentType(ContentType.IMAGE_PNG);
            OutputStream out = conn.getOutputStream();

            InputStream in = null;
            byte[] buffer = new byte[BUFFER_SIZE];
            int bytesRead = 0;

            try {

                BundleContext ctx = BundleServices.getBundleContext();

                in = ctx.getBundle().getResource(TRANSLUCENT_IMAGE).openStream();

                /*xxxxxServerDelayMessage.class.getResourceAsStream(IMAGE_RESOURCE_NAME);*/
                if (in == null) {
                    throw new IllegalArgumentException("Specified resource does not exist: " + TRANSLUCENT_IMAGE + ".");
                }
                do {
                    bytesRead = in.read(buffer);
                    if (bytesRead > 0) {
                        out.write(buffer, 0, bytesRead);
                    }
                } while (bytesRead > 0);
            } finally {
                if (in != null) { try { in.close(); } catch (IOException ex) { } }
            }
        }
    }

    private static class ImageService implements Service {

        protected static final String SERVICE_ID = Uid.generateUidString();

        /**
         * @see org.karora.cooee.webrender.Service#getId()
         */
        public String getId() {
            return SERVICE_ID;
        }

        /**
         * @see org.karora.cooee.webrender.Service#getVersion()
         */
        public int getVersion() {
            return 0;
        }

        /**
         * @see org.karora.cooee.webrender.Service#service(org.karora.cooee.webrender.Connection)
         */
        public void service(Connection conn) throws IOException {
            conn.setContentType(ContentType.IMAGE_GIF);
            OutputStream out = conn.getOutputStream();

            InputStream in = null;
            byte[] buffer = new byte[BUFFER_SIZE];
            int bytesRead = 0;

            try {

                BundleContext ctx = BundleServices.getBundleContext();

                if (ctx == null)
                {
                	System.err.println("Context not available");
                }

                URL resource = ctx.getBundle().getResource(IMAGE_RESOURCE_NAME);
                if (resource == null)
                {
                	System.err.println ("Unable to find resource");
                }

                in = ctx.getBundle().getResource(IMAGE_RESOURCE_NAME).openStream();

                /*xxxxxxServerDelayMessage.class.getResourceAsStream(IMAGE_RESOURCE_NAME);*/
                if (in == null) {
                    throw new IllegalArgumentException("Specified resource does not exist: " + IMAGE_RESOURCE_NAME + ".");
                }
                do {
                    bytesRead = in.read(buffer);
                    if (bytesRead > 0) {
                        out.write(buffer, 0, bytesRead);
                    }
                } while (bytesRead > 0);
            } finally {
                if (in != null) { try { in.close(); } catch (IOException ex) { } }
            }
        }
    }

    private Element messageElement;

    public xxxxxxServerDelayMessage(ContainerContext containerContext, String messageText) {
        XmlDocument xmlDocument = new XmlDocument("div", null, null, HtmlDocument.XHTML_1_0_NAMESPACE_URI);
        Document document = xmlDocument.getDocument();

        // Standard Short Server Delay - Prevents clicking during loads
        Element divElement = document.getDocumentElement();
        divElement.setAttribute("id", ELEMENT_ID_MESSAGE);
        /*divElement.setAttribute("style", "position:absolute;top:0px;left:0px;width:100%;height:100%;cursor:wait;"
                + "margin:0px;padding:0px;visibility:hidden;z-index:10000;background-image:url(" + containerContext.getServiceUri(TRANSLUCENCENT_IMAGE_SERVICE) + ");"
                + "_background-image:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='" + containerContext.getServiceUri(TRANSLUCENCENT_IMAGE_SERVICE) + "');");*/

        divElement.setAttribute("style", "position:absolute;top:0px;left:0px;width:100%;height:100%;cursor:wait;"
                + "margin:0px;padding:0px;visibility:hidden;z-index:10000;");

        Element tableElement = document.createElement("table");
        tableElement.setAttribute("style", "width:100%;height:100%;border:2px;padding:5px;");
        divElement.appendChild(tableElement);

        Element tbodyElement = document.createElement("tbody");
        tableElement.appendChild(tbodyElement);

        Element trElement = document.createElement("tr");
        tbodyElement.appendChild(trElement);

        Element tdElement = document.createElement("td");
        tdElement.setAttribute("style", "width:100%;height:100%;");
        tdElement.setAttribute("valign", "middle");
        tdElement.setAttribute("align", "center");
        trElement.appendChild(tdElement);




        Element imageElement = document.createElement("img");
        imageElement.setAttribute("src", containerContext.getServiceUri(IMAGE_SERVICE));
        imageElement.setAttribute("align", "center");
        //tdElement.appendChild(imageElement);





        Element pleaseWaitElement = document.createElement("div");
        pleaseWaitElement.setAttribute("id", ELEMENT_ID_LONG_MESSAGE);
        String pleaseWaitStyleCSS = "color:#000000;width:177px;padding-top:10px;" //height:65px;
                + "font-family:verdana,arial,helvetica,sans-serif;font-size:10pt;"
                + "background-color: #FFFFFF; border: 1px solid;";


        /*divElement.setAttribute("style", "position:absolute;top:0px;left:0px;width:100%;height:100%;cursor:wait;"
        + "margin:0px;padding:0px;visibility:hidden;z-index:10000;background-image:url(" + containerContext.getServiceUri(TRANSLUCENCENT_IMAGE_SERVICE) + ");"
        + "_background-image:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='" + containerContext.getServiceUri(TRANSLUCENCENT_IMAGE_SERVICE) + "');");*/



        pleaseWaitElement.setAttribute("style", pleaseWaitStyleCSS);

        pleaseWaitElement.appendChild(imageElement);

        Element brElement = document.createElement("br");
        pleaseWaitElement.appendChild(brElement);

        pleaseWaitElement.appendChild(document.createTextNode(messageText));



        tdElement.appendChild(pleaseWaitElement);

        messageElement = divElement;
    }

    /**
     * @see org.karora.cooee.webrender.ServerDelayMessage#getMessage()
     */
    public Element getMessage() {
        return messageElement;
    }
}

Registering with the framework

ContainerContext containerContext = (ContainerContext) ApplicationInstance.getActive().getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME);
containerContext.setServerDelayMessage(new MyServerDelayMessage(containerContext, "Loading, Please Wait"));

Resources

For a comprehensive utility for creating animated gifs go to http://www.ajaxload.info/

Labels

 
(None)