001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.webcontainer;
031:
032: import java.io.IOException;
033:
034: import org.w3c.dom.Element;
035:
036: import nextapp.echo2.app.ApplicationInstance;
037: import nextapp.echo2.webrender.BaseHtmlDocument;
038: import nextapp.echo2.webrender.Connection;
039: import nextapp.echo2.webrender.ContentType;
040: import nextapp.echo2.webrender.Service;
041: import nextapp.echo2.webrender.WebRenderServlet;
042: import nextapp.echo2.webrender.output.CssStyle;
043: import nextapp.echo2.webrender.service.CoreServices;
044:
045: /**
046: * Completely re-renders a browser window.
047: * This is the default service invoked when the user visits an application.
048: */
049: public class WindowHtmlService implements Service {
050:
051: public static final WindowHtmlService INSTANCE = new WindowHtmlService();
052:
053: /**
054: * Root element identifier.
055: */
056: public static final String ROOT_ID = "c_root";
057:
058: /**
059: * @see nextapp.echo2.webrender.Service#getId()
060: */
061: public String getId() {
062: return WebRenderServlet.SERVICE_ID_DEFAULT;
063: }
064:
065: /**
066: * @see nextapp.echo2.webrender.Service#getVersion()
067: */
068: public int getVersion() {
069: return DO_NOT_CACHE;
070: }
071:
072: /**
073: * @see nextapp.echo2.webrender.Service#service(nextapp.echo2.webrender.Connection)
074: */
075: public void service(Connection conn) throws IOException {
076: ContainerInstance ci = (ContainerInstance) conn
077: .getUserInstance();
078: conn.setContentType(ContentType.TEXT_HTML);
079:
080: boolean debug = !("false".equals(conn.getServlet()
081: .getInitParameter("echo2.debug")));
082:
083: BaseHtmlDocument baseDoc = new BaseHtmlDocument(ROOT_ID);
084: baseDoc.setGenarator(ApplicationInstance.ID_STRING);
085: baseDoc.addJavaScriptInclude(ci
086: .getServiceUri(CoreServices.CLIENT_ENGINE));
087:
088: // Add initialization directive.
089: baseDoc.getBodyElement().setAttribute(
090: "onload",
091: "EchoClientEngine.init('" + ci.getServletUri() + "', "
092: + debug + ");");
093:
094: Element bodyElement = baseDoc.getBodyElement();
095:
096: // Set body element CSS style.
097: CssStyle cssStyle = new CssStyle();
098: cssStyle.setAttribute("position", "absolute");
099: cssStyle.setAttribute("font-family",
100: "verdana, arial, helvetica, sans-serif");
101: cssStyle.setAttribute("font-size", "10pt");
102: cssStyle.setAttribute("height", "100%");
103: cssStyle.setAttribute("width", "100%");
104: cssStyle.setAttribute("padding", "0px");
105: cssStyle.setAttribute("margin", "0px");
106: cssStyle.setAttribute("overflow", "hidden");
107: bodyElement.setAttribute("style", cssStyle.renderInline());
108:
109: // Render.
110: baseDoc.render(conn.getWriter());
111: }
112: }
|