001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.romaframework.aspect.view.echo2.message;
018:
019: import nextapp.echo2.webcontainer.ContainerContext;
020: import nextapp.echo2.webrender.ClientProperties;
021: import nextapp.echo2.webrender.ServerDelayMessage;
022: import nextapp.echo2.webrender.output.HtmlDocument;
023: import nextapp.echo2.webrender.output.XmlDocument;
024:
025: import org.romaframework.core.flow.ObjectContext;
026: import org.w3c.dom.Document;
027: import org.w3c.dom.Element;
028:
029: /**
030: * An example of a more creative <code>ServerDelayMessage</code>.
031: * <p>
032: * Creating a custom <code>ServerDelayMessage</code> is a fairly advanced
033: * activity that requires working with the Echo Web Render Engine API.
034: */
035: public class CustomDelayMessage extends ServerDelayMessage {
036: public CustomDelayMessage(ContainerContext containerContext,
037: String messageText) {
038: XmlDocument xmlDocument = new XmlDocument("div", null, null,
039: HtmlDocument.XHTML_1_0_NAMESPACE_URI);
040: Document document = xmlDocument.getDocument();
041: Element divElement = document.getDocumentElement();
042: divElement.setAttribute("id", ELEMENT_ID_MESSAGE);
043: divElement
044: .setAttribute(
045: "style",
046: "position:absolute;top:0px;left:0px;width:100%;height:100%;cursor:wait;"
047: + "margin:0px;padding:0px;visibility:hidden;z-index:10000;");
048:
049: Element tableElement = document.createElement("table");
050: tableElement.setAttribute("style",
051: "width:100%;height:100%;border:0px;padding:0px;");
052: divElement.appendChild(tableElement);
053:
054: Element tbodyElement = document.createElement("tbody");
055: tableElement.appendChild(tbodyElement);
056:
057: Element trElement = document.createElement("tr");
058: tbodyElement.appendChild(trElement);
059:
060: Element tdElement = document.createElement("td");
061: tdElement.setAttribute("style", "width:100%;height:100%;");
062: tdElement.setAttribute("valign", "middle");
063: tdElement.setAttribute("align", "center");
064: trElement.appendChild(tdElement);
065:
066: DelayMessageManager delayMgr = ObjectContext.getInstance()
067: .getComponent(DelayMessageManager.class);
068:
069: int paddingTop = 0;//delayMgr.getImageHeight() / 2 - 25;
070: int height = delayMgr.getImageHeight() - paddingTop;
071: int width = delayMgr.getImageWidth();
072:
073: Element longDivElement = document.createElement("div");
074: longDivElement.setAttribute("id", ELEMENT_ID_LONG_MESSAGE);
075: String longDivStyleText = "color:#4f4f4f;width:"
076: + width
077: + "px;padding-top:"
078: + paddingTop
079: + "px;height:"
080: + height
081: + "px;"
082: + "font-family:verdana,arial,helvetica,sans-serif;font-size:14pt;font-weight:bold;font-style:italic;"
083: + "text-align:center;";
084:
085: String serviceUri = containerContext.getServiceUri(delayMgr);
086:
087: if (containerContext
088: .getClientProperties()
089: .getBoolean(
090: ClientProperties.PROPRIETARY_IE_PNG_ALPHA_FILTER_REQUIRED)) {
091: // Use Internet Explorer PNG filter hack to achieve transparency.
092: longDivStyleText += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
093: + serviceUri + "', sizingMethod='scale')";
094: } else {
095: longDivStyleText += "background-image:url(" + serviceUri
096: + ");";
097: }
098: longDivElement.setAttribute("style", longDivStyleText);
099: tdElement.appendChild(longDivElement);
100:
101: messageElement = divElement;
102: }
103:
104: /**
105: * @see nextapp.echo2.webrender.ServerDelayMessage#getMessage()
106: */
107: @Override
108: public Element getMessage() {
109: return messageElement;
110: }
111:
112: private Element messageElement;
113: }
|