001: /*
002: * Title: Page
003: * Description:
004: *
005: * This software is published under the terms of the OpenSymphony Software
006: * License version 1.1, of which a copy has been included with this
007: * distribution in the LICENSE.txt file.
008: */
009:
010: package com.opensymphony.module.sitemesh;
011:
012: import javax.servlet.http.HttpServletRequest;
013: import java.io.IOException;
014: import java.io.Writer;
015: import java.util.Map;
016:
017: /**
018: * The Page object wraps the contents of the original (undecorated) page.
019: *
020: * <p>The original data in its entirity can be written using the writePage()
021: * methods. It may also contain a set of properties - these vary among
022: * different {@link com.opensymphony.module.sitemesh.PageParser} implementations.</p>
023: *
024: * <p>Typically a Page is no use to a {@link com.opensymphony.module.sitemesh.Decorator} as it needs
025: * specific details relevant to the content-type of that page (<i>e.g.</i> HTML
026: * pages). The appropriate {@link com.opensymphony.module.sitemesh.PageParser} is responsible
027: * for returning extended implementations of pages such as {@link com.opensymphony.module.sitemesh.HTMLPage}
028: * which are of more use to the Decorator. New media types (<i>e.g.</i> WML) could
029: * be added to the system by extending Page and implementing an appropriate PageParser.</p>
030: *
031: * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
032: * @version $Revision: 1.4 $
033: */
034: public interface Page {
035: /**
036: * Write the entire contents of the <code>Page</code>, in the format before
037: * it was parsed, to the <code>Writer</code>.
038: *
039: * @param out Writer to write to.
040: * @exception java.io.IOException Rethrown if cannot write to writer.
041: */
042: void writePage(Writer out) throws IOException;
043:
044: /**
045: * Convenience method to return the contents of the <code>Page</code> in its original format.
046: *
047: * @since 2.1.1
048: * @see #writePage(java.io.Writer)
049: */
050: String getPage();
051:
052: /**
053: * Write the contents of the <code><body></code> tag.
054: */
055: void writeBody(Writer out) throws IOException;
056:
057: /**
058: * Convenience method to return the contents of the <code><body></code> tag.
059: *
060: * @since 2.1.1
061: * @see #writeBody(java.io.Writer)
062: */
063: String getBody();
064:
065: /**
066: * Get the Title of the document
067: */
068: String getTitle();
069:
070: /**
071: * Length of the <code>Page</code>, in the format before
072: * it was parsed.
073: *
074: * @return Length of page data (in number of bytes).
075: */
076: int getContentLength();
077:
078: /**
079: * Get a property embedded into the <code>Page</code> as a <code>String</code>.
080: *
081: * @param name Name of property
082: * @return Property value
083: */
084: String getProperty(String name);
085:
086: /**
087: * Get a property embedded into the <code>Page</code> as an <code>int</code>.
088: * Returns 0 if property not specified or not valid number.
089: *
090: * @param name Name of property
091: * @return Property value
092: */
093: int getIntProperty(String name);
094:
095: /**
096: * Get a property embedded into the <code>Page</code> as a <code>long</code>.
097: * Returns 0L if property not specified or not valid number.
098: *
099: * @param name Name of property
100: * @return Property value
101: */
102: long getLongProperty(String name);
103:
104: /**
105: * Get a property embedded into the <code>Page</code> as a <code>boolean</code>.
106: * Returns true if value starts with '1', 't' or 'y' (case-insensitive) -
107: * otherwise returns false.
108: *
109: * @param name Name of property
110: * @return Property value
111: */
112: boolean getBooleanProperty(String name);
113:
114: /**
115: * Determine whether a property embedded into the <code>Page</code> has been set.
116: *
117: * @param name Name of property
118: * @return Whether it has been set
119: */
120: boolean isPropertySet(String name);
121:
122: /**
123: * Get all available property keys for the <code>Page</code>.
124: *
125: * @return Property keys
126: */
127: String[] getPropertyKeys();
128:
129: /**
130: * Get a <code>Map</code> representing all the properties in the <code>Page</code>.
131: *
132: * @return Properties map
133: */
134: Map getProperties();
135:
136: /**
137: * Return the request of the original page.
138: */
139: HttpServletRequest getRequest();
140:
141: /**
142: * Create snapshot of Request. Subsequent modifications to the request by
143: * the servlet container will not be returned by {@link #getRequest()}
144: */
145: void setRequest(HttpServletRequest request);
146:
147: /**
148: * Manually add a property to page.
149: */
150: void addProperty(String name, String value);
151: }
|