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.webrender;
031:
032: import java.util.Properties;
033: import javax.xml.transform.OutputKeys;
034: import org.w3c.dom.Document;
035: import org.w3c.dom.Element;
036:
037: import nextapp.echo2.webrender.output.HtmlDocument;
038:
039: /**
040: * The initial document rendered when a user visits an application.
041: */
042: public class BaseHtmlDocument extends HtmlDocument {
043:
044: /**
045: * <code>OutputProperties</code> used for XML transformation.
046: */
047: private static final Properties OUTPUT_PROPERTIES = new Properties();
048: static {
049: // The XML declaration is omitted as Internet Explorer 6 will operate in quirks mode if it is present.
050: OUTPUT_PROPERTIES.setProperty(OutputKeys.OMIT_XML_DECLARATION,
051: "yes");
052:
053: OUTPUT_PROPERTIES.setProperty(OutputKeys.DOCTYPE_PUBLIC,
054: XHTML_1_0_TRANSITIONAL_PUBLIC_ID);
055: OUTPUT_PROPERTIES.setProperty(OutputKeys.DOCTYPE_SYSTEM,
056: XHTML_1_0_TRANSITIONAL_SYSTSEM_ID);
057: }
058:
059: private String contentId;
060:
061: /**
062: * Creates a new <code>BaseHtmlDocument</code>.
063: *
064: * @param contentId The desired id which will be used for the element to
065: * which content should be added, i.e., the FORM element.
066: */
067: public BaseHtmlDocument(String contentId) {
068: super (XHTML_1_0_TRANSITIONAL_PUBLIC_ID,
069: XHTML_1_0_TRANSITIONAL_SYSTSEM_ID,
070: XHTML_1_0_NAMESPACE_URI);
071: setOutputProperties(OUTPUT_PROPERTIES);
072: this .contentId = contentId;
073: Document document = getDocument();
074:
075: Element styleElement = document.createElement("style");
076: styleElement.setAttribute("type", "text/css");
077: styleElement.appendChild(document.createTextNode(" "));
078: getHeadElement().appendChild(styleElement);
079:
080: Element formElement = document.createElement("form");
081: formElement.setAttribute("style", "padding:0px;margin:0px;");
082: formElement.setAttribute("action", "#");
083: formElement.setAttribute("id", contentId);
084: formElement.setAttribute("onsubmit", "return false;");
085:
086: Element loadingDiv = document.createElement("div");
087: loadingDiv.setAttribute("id", "loadstatus");
088: loadingDiv.appendChild(document.createTextNode("//"));
089: formElement.appendChild(loadingDiv);
090:
091: getBodyElement().appendChild(formElement);
092: }
093:
094: /**
095: * Retrieves the element of the document to which content should be added,
096: * i.e., the FORM element.
097: *
098: * @return the element to which content should be added.
099: */
100: public Element getContentElement() {
101: return getDocument().getElementById(contentId);
102: }
103: }
|