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 java.io.IOException;
020: import java.io.OutputStream;
021:
022: import nextapp.echo2.app.util.Uid;
023: import nextapp.echo2.webrender.Connection;
024: import nextapp.echo2.webrender.ContentType;
025: import nextapp.echo2.webrender.Service;
026: import nextapp.echo2.webrender.WebRenderServlet;
027:
028: import org.romaframework.aspect.view.echo2.look.LookAndFeelManager;
029: import org.romaframework.core.flow.ObjectContext;
030:
031: import echopointng.image.URLImageReference;
032:
033: /**
034: * Handle the custom Delay Message when user wait for a long request.
035: */
036: public class DelayMessageManager implements Service {
037: /**
038: * Constructs the manager to build custom delay messages.
039: *
040: * @param iImageName
041: * File name of image to use.
042: * @param iWidthPixel
043: * image width in pixel
044: * @param iHeightPixel
045: * image heigh in pixel
046: * @see CustomDelayMessage
047: */
048: public DelayMessageManager(String iImageName, int iWidthPixel,
049: int iHeightPixel) {
050: imageName = iImageName;
051: imageWidth = iWidthPixel;
052: imageHeight = iHeightPixel;
053:
054: if (imageName == null)
055: imageName = DEF_IMAGE_NAME;
056:
057: // REGISTER MYSELF AS RENDER SERVICE
058: WebRenderServlet.getServiceRegistry().add(this );
059: }
060:
061: private void init() {
062: // LOAD BACKGROUND IMAGE
063: imageReg = (URLImageReference) ObjectContext.getInstance()
064: .getComponent(LookAndFeelManager.class).getImage(
065: imageName);
066: }
067:
068: /**
069: * @see nextapp.echo2.webrender.Service#getId()
070: */
071: public String getId() {
072: return SERVICE_ID;
073: }
074:
075: /**
076: * @see nextapp.echo2.webrender.Service#getVersion()
077: */
078: public int getVersion() {
079: return 0;
080: }
081:
082: /**
083: * @see nextapp.echo2.webrender.Service#service(nextapp.echo2.webrender.Connection)
084: */
085: public void service(Connection conn) throws IOException {
086: conn.setContentType(ContentType.IMAGE_PNG);
087: OutputStream out = conn.getOutputStream();
088:
089: getImageReg().render(out);
090: }
091:
092: public synchronized URLImageReference getImageReg() {
093: if (imageReg == null)
094: // LOAD ONCE
095: init();
096:
097: return imageReg;
098: }
099:
100: public int getImageHeight() {
101: return imageHeight;
102: }
103:
104: public int getImageWidth() {
105: return imageWidth;
106: }
107:
108: private String imageName;
109: private int imageWidth;
110: private int imageHeight;
111:
112: private URLImageReference imageReg;
113:
114: private static final String SERVICE_ID = Uid.generateUidString();
115: private static final String DEF_IMAGE_NAME = "Object.DelayMessageBackground.gif";
116:
117: }
|