KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > resource > DynamicCodeResource


1 /*
2  * $Id: DynamicCodeResource.java,v 1.6 2005/05/07 16:40:51 oliverscheck Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.resource;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.wings.Resource;
19 import org.wings.SFrame;
20 import org.wings.io.Device;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.Date JavaDoc;
27
28 /**
29  * Traverses the component hierarchy of a frame and lets the CGs compose
30  * the document.
31  *
32  * @author <a HREF="mailto:hengels@mercatis.de">Holger Engels</a>
33  * @version $Revision: 1.6 $
34  */

35 public class DynamicCodeResource extends DynamicResource {
36     private final transient static Log log = LogFactory.getLog(DynamicCodeResource.class);
37
38     private static final ArrayList JavaDoc DEFAULT_CODE_HEADER = new ArrayList JavaDoc();
39     static {
40         DEFAULT_CODE_HEADER.add(new Resource.HeaderEntry("Expires", new Date JavaDoc(1000)));
41         DEFAULT_CODE_HEADER.add(new Resource.HeaderEntry("Cache-Control", "no-store, no-cache, must-revalidate"));
42         DEFAULT_CODE_HEADER.add(new Resource.HeaderEntry("Cache-Control", "post-check=0, pre-check=0"));
43         DEFAULT_CODE_HEADER.add(new Resource.HeaderEntry("Pragma", "no-cache"));
44     }
45
46
47     /**
48      * Create a code resource for the specified frame.
49      * <p>The MIME-type for this frame will be <code>text/html; charset=<i>current encoding</i></code>
50      */

51     public DynamicCodeResource(SFrame f) {
52         super(f, null, provideMimeType(f));
53     }
54
55     /**
56      * The MIME-type for this {@link Resource}.
57      *
58      * @return
59      */

60     private static String JavaDoc provideMimeType(SFrame frame) {
61         return "text/html; charset=" + frame.getSession().getCharacterEncoding();
62     }
63
64     /**
65      * Renders and write the code of the {@link SFrame} attached to this <code>DynamicCodeResource</code>.
66      */

67     public void write(Device out) throws IOException JavaDoc {
68         try {
69             getFrame().write(out);
70         } catch (IOException JavaDoc e) {
71             throw e;
72         } catch (Exception JavaDoc e) {
73             log.fatal("resource: " + getId(), e);
74             throw new IOException JavaDoc(e.getMessage()); // UndeclaredThrowable
75
}
76     }
77
78     /**
79      * The HTTP header parameteres attached to this dynamic code ressource.
80      * This <b>static</b> list will by default contain entries to disable caching
81      * on the server side. Call <code>getHeaders().clear()</code> to avoid this
82      * i.e. if you want to enable back buttons.
83      *
84      * @return A <code>Collection</code> of {@link org.wings.Resource.HeaderEntry} objects.
85      */

86     public Collection JavaDoc getHeaders() {
87         if (getFrame().isNoCaching())
88             return DEFAULT_CODE_HEADER;
89         else
90             return Collections.EMPTY_SET;
91     }
92 }
93
94
95
Popular Tags