Source code: com/sitemesh/Page.java
1 package com.sitemesh;
2
3 import java.io.IOException;
4 import java.io.OutputStream;
5 import java.io.Writer;
6 import java.util.Date;
7 import javax.servlet.http.HttpServletRequest;
8
9 /**
10 * The Page object wraps the contents of the original (undecorated) page.
11 *
12 * <p>The original data in its entirity can be written using the writePage()
13 * methods. It may also contain a set of properties - these vary among
14 * different {@link com.sitemesh.PageParser} implementations.</p>
15 *
16 * <p>Typically a Page is no use to a {@link com.sitemesh.Decorator} as it needs
17 * specific details relevant to the content-type of that page (<i>e.g.</i> HTML
18 * pages). The appropriate {@link com.sitemesh.PageParser} is responsible
19 * for returning extended implementations of pages such as {@link com.sitemesh.HTMLPage}
20 * which are of more use to the Decorator. New media types (<i>e.g.</i> WML) could
21 * be added to the system by extending Page and implementing an appropriate PageParser.</p>
22 *
23 * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
24 * @version $Revision: 1.8 $
25 */
26 public interface Page {
27
28 /**
29 * Write the entire contents of the <code>Page</code>, in the format before
30 * it was parsed, to the <code>OutputStream</code>.
31 *
32 * @param out OutputStream to write to.
33 * @exception java.io.IOException Rethrown if cannot write to stream.
34 *
35 * @see #writePage(java.io.Writer)
36 */
37 void writePage( OutputStream out ) throws IOException;
38
39 /**
40 * Write the entire contents of the <code>Page</code>, in the format before
41 * it was parsed, to the <code>Writer</code>.
42 *
43 * @param out Writer to write to.
44 * @exception java.io.IOException Rethrown if cannot write to writer.
45 *
46 * @see #writePage(java.io.OutputStream)
47 */
48 void writePage( Writer out ) throws IOException;
49
50 /**
51 * Length of the <code>Page</code>, in the format before
52 * it was parsed.
53 *
54 * @return Length of page data (in number of bytes).
55 */
56 int getContentLength();
57
58 /**
59 * Get a property embedded into the <code>Page</code> as a <code>String</code>.
60 *
61 * @param name Name of property
62 * @return Property value
63 */
64 String getProperty( String name );
65
66 /**
67 * Get a property embedded into the <code>Page</code> as an <code>int</code>.
68 * Returns 0 if property not specified or not valid number.
69 *
70 * @param name Name of property
71 * @return Property value
72 */
73 int getIntProperty( String name );
74
75 /**
76 * Get a property embedded into the <code>Page</code> as a <code>long</code>.
77 * Returns 0L if property not specified or not valid number.
78 *
79 * @param name Name of property
80 * @return Property value
81 */
82 long getLongProperty( String name );
83
84 /**
85 * Get a property embedded into the <code>Page</code> as a <code>boolean</code>.
86 * Returns true if value starts with '1', 't' or 'y' (case-insensitive) -
87 * otherwise returns false.
88 *
89 * @param name Name of property
90 * @return Property value
91 */
92 boolean getBooleanProperty( String name );
93
94 /**
95 * Get properties embedded into the <code>Page</code> as a <code>String[]</code>.
96 * Returns zero length array if no properties set.
97 *
98 * @param name Name of property
99 * @return Property values
100 */
101 String[] getProperties( String name );
102
103 /**
104 * Determine whether a property embedded into the <code>Page</code> has been set.
105 *
106 * @param name Name of property
107 * @return Whether it has been set
108 */
109 boolean isPropertySet( String name );
110
111 /**
112 * Determine the number of properties embedded into the <code>Page</code> with
113 * a given name.
114 *
115 * @param name Name of property
116 * @return Number of properties set with given name.
117 */
118 int getPropertySize( String name );
119
120 /**
121 * Get all available property keys for the <code>Page</code>.
122 *
123 * @return Property keys
124 */
125 String[] getPropertyKeys();
126
127 /**
128 * Determine whether this <code>Page</code> can be cached or not. If allowed to
129 * be cached for a specified period of time, <code>true</code> should be initially
130 * returned, and repeated calls to this method will determine whether the page
131 * is still allowed to remain cached.
132 */
133 boolean shouldCache();
134
135 /**
136 * Return the request of the original page.
137 */
138 HttpServletRequest getRequest();
139
140 /**
141 * Create snapshot of Request. Subsequent modifications to the request by
142 * the servlet container will not be returned by {@link #getRequest()}
143 */
144 void setRequest(HttpServletRequest request);
145
146 }