|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.melati.Melati
public class Melati
This is the main entry point for using the Melati framework. A Melati exists once per request, or command from an application.
It provides a central container for all the relevant objects that a Servlet or command line application needs to create textual output, optionally using a Template Engine or a Database.
You will need to create a MelatiConfig in order to construct a Melati.
If you are using servlets, you will want to construct a Melati with a request and response object. Otherwise, simply pass in a Writer.
If you are using a template engine outside of a servlets context you will still need the servlets jar in your classpath, annoyingly, as Velocity and WebMacro introspect all possible methods and throw a ClassNotFound exception if the servlets classes are not available.
Melati is typically used with Servlets, POEM (Persistent Object Engine for Melati) and a Template Engine
MelatiConfig
,
ConfigServlet
,
PoemServlet
,
TemplateServlet
Field Summary | |
---|---|
protected String |
contentType
|
static String |
DEFAULT_ENCODING
UTF-8. |
protected String |
responseCharset
Suggested character encoding for use in responses. |
Constructor Summary | |
---|---|
Melati(MelatiConfig config,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Construct a Melati for use with Servlets. |
|
Melati(MelatiConfig config,
MelatiWriter writer)
Construct a Melati for use in 'stand alone' mode. |
Method Summary | |
---|---|
void |
establishCharsets()
Suggest a response character encoding and if necessary choose a request encoding. |
String[] |
getArguments()
Get the Arguments array. |
MelatiConfig |
getConfig()
Get the MelatiConfig associated with this Request. |
String |
getContentType()
|
Object |
getContextUtil(String className)
Get a named context utility eg org.melati.admin.AdminUtils. |
Database |
getDatabase()
Get the POEM Database for this Request. |
String |
getDatabaseName()
|
String |
getEncoding()
Return the encoding that is used for writing. |
HTMLMarkupLanguage |
getHTMLMarkupLanguage()
Get a HTMLMarkupLanguage. |
Object |
getInstance(String className)
Get a named context utility eg org.melati.admin.AdminUtils. |
String |
getJavascriptLibraryURL()
Get the URL for the JavascriptLibrary. |
Vector<String> |
getKnownDatabaseNames()
Return the names of other databases known at the moment. |
String |
getLoginURL()
Get the URL for the Login Page. |
String |
getLogoutURL()
Get the URL for the Logout Page. |
MarkupLanguage |
getMarkupLanguage()
Get a MarkupLanguage for use generating output from templates. |
String |
getMethod()
Get the Method (if any) that has been set for this Request. |
Persistent |
getObject()
Get the POEM Object (if any) in use for this Request. |
String[] |
getPathInfoParts()
Get the PathInfo for this Request split into Parts by '/'. |
PoemContext |
getPoemContext()
Get the PoemContext for this Request. |
PoemLocale |
getPoemLocale()
Returns a PoemLocale object based on the Accept-Language header of this request. |
String |
getRelativeZoneURL()
|
javax.servlet.http.HttpServletRequest |
getRequest()
Get the servlet request object. |
javax.servlet.http.HttpServletResponse |
getResponse()
Get the servlet response object. |
String |
getSameURL()
The URL of the servlet request associated with this Melati. |
ServletTemplateContext |
getServletTemplateContext()
Get the TemplateContext used for this Request. |
String |
getServletURL()
Get the URL for this request. |
javax.servlet.http.HttpSession |
getSession()
Get the Session for this Request. |
MelatiWriter |
getStringWriter()
Get a StringWriter. |
Table |
getTable()
Get the POEM Table (if any) in use for this Request. |
TemplateContext |
getTemplateContext()
Get the TemplateContext used for this Request. |
TemplateEngine |
getTemplateEngine()
Get the template engine in use for this Request. |
String |
getURLQueryEncoding()
Return the encoding that is used for URL encoded query strings. |
User |
getUser()
Get a User for this request (if they are logged in). |
MelatiWriter |
getWriter()
Get a Writer for this request. |
String |
getZoneURL()
Get the URL for this Servlet Zone. |
boolean |
isReferencePoemType(Field field)
Establish if field is a ReferencePoemType field. |
void |
loadTableAndObject()
Load a POEM Table and POEM Object for use in this request. |
String |
sameURLWith(String field)
The URL of the servlet request associated with this Melati, with a modified or added form flag setting (query string component). |
String |
sameURLWith(String field,
String value)
The URL of the servlet request associated with this Melati, with a modified or added form parameter setting (query string component). |
void |
setArguments(String[] args)
Set the aruments array from the commandline. |
void |
setBufferingOff()
Turn off buffering of the output stream. |
void |
setFlushingOn()
Turn on flushing of the output stream. |
void |
setMarkupLanguage(MarkupLanguage ml)
Use this method if you wish to use a different MarkupLanguage, WMLMarkupLanguage for example. |
void |
setPassbackExceptionHandling()
This allows an Exception to be handled inline during Template expansion for example, if you would like to render AccessPoemExceptions to a String to be displayed on the page that is returned to the client. |
void |
setPoemContext(PoemContext context)
Set the PoemContext for this request. |
void |
setPropagateExceptionHandling()
The normal state of affairs: an exception is thrown and it is handled by the servlet. |
void |
setRequest(javax.servlet.http.HttpServletRequest request)
It is sometimes convenient to reconstruct the request object and reset it, for example when returning from a log-in page. |
void |
setResponse(javax.servlet.http.HttpServletResponse response)
Used to set response mock in tests. |
void |
setResponseContentType(String type)
Sets the content type for use in the response. |
void |
setTemplateContext(TemplateContext tc)
Set the TemplateContext to be used for this Request. |
void |
setTemplateEngine(TemplateEngine te)
Set the template engine to be used for this Request. |
void |
setWriter(MelatiWriter writerP)
|
String |
templateName(String key)
Find a db specific template if it exists, otherwise a non-specific one, searching through all template paths. |
String |
urlEncode(String string)
|
void |
write()
Write the buffered output to the Writer we also need to stop the flusher if it has started. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_ENCODING
protected String responseCharset
protected String contentType
Constructor Detail |
---|
public Melati(MelatiConfig config, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
config
- - the MelatiConfigrequest
- - the Servlet Requestresponse
- - the Servlet Responsepublic Melati(MelatiConfig config, MelatiWriter writer)
config
- - the MelatiConfigwriter
- - the Writer that all output is written toMethod Detail |
---|
public javax.servlet.http.HttpServletRequest getRequest()
public void setRequest(javax.servlet.http.HttpServletRequest request)
request
- - new request objectHttpSessionAccessHandler
public void setResponse(javax.servlet.http.HttpServletResponse response)
response
- - mock response objectHttpSessionAccessHandler
public javax.servlet.http.HttpServletResponse getResponse()
public void setPoemContext(PoemContext context) throws DatabaseInitException
PoemContext
for this request. If the Context has a
LogicalDatabase set, this will be used to establish a connection
to the database.
context
- - a PoemContext
DatabaseInitException
- - if the database fails to initialise for
some reasonLogicalDatabase
,
PoemServlet
public void loadTableAndObject()
Admin
,
PoemServlet
public PoemContext getPoemContext()
public Database getDatabase()
setPoemContext(org.melati.PoemContext)
public String getDatabaseName()
public Vector<String> getKnownDatabaseNames()
public Table getTable()
loadTableAndObject()
public Persistent getObject()
loadTableAndObject()
public String getMethod()
PoemContext
,
ConfigServlet.poemContext(org.melati.Melati)
,
PoemServlet.poemContext(org.melati.Melati)
public void setTemplateEngine(TemplateEngine te)
te
- - the template engine to be usedTemplateServlet
public TemplateEngine getTemplateEngine()
public void setTemplateContext(TemplateContext tc)
tc
- - the template context to be usedTemplateServlet
public TemplateContext getTemplateContext()
public ServletTemplateContext getServletTemplateContext()
public MelatiConfig getConfig()
public String[] getPathInfoParts()
public void setArguments(String[] args)
args
- public String[] getArguments()
public javax.servlet.http.HttpSession getSession()
public Object getContextUtil(String className)
className
- Name of a class with a single argument Melati constructor
public Object getInstance(String className)
className
- Name of a class with a single argument Melati constructor
public String getLogoutURL()
Logout
public String getLoginURL()
Login
public String getZoneURL()
HttpUtil.zoneURL(javax.servlet.http.HttpServletRequest)
public String getRelativeZoneURL()
public String getServletURL()
HttpUtil.servletURL(javax.servlet.http.HttpServletRequest)
public String getJavascriptLibraryURL()
MelatiConfig.getJavascriptLibraryURL()
public PoemLocale getPoemLocale()
public void establishCharsets() throws CharsetException
If the request encoding is provided then we choose a response
encoding to meet our preferences on the assumption that the
client will also indicate next time what its request
encoding is.
The result can optionally be set in code or possibly in
templates using setResponseContentType(String)
.
Otherwise we tread carefully. We assume that the encoding is the first supported encoding of the client's preferences for responses, as indicated by Accept-Charsets, and avoid giving it any reason to change.
Actually, the server preference is a bit dodgy for the response because if it does persuade the client to change encodings and future requests include query strings that we are providing now then we may end up with the query strings being automatically decoded using the wrong encoding by request.getParameter(). But by the time we end up with values in such parameters the client and server will probably have settled on particular encodings.
CharsetException
public void setResponseContentType(String type)
Use of this method is optional and only makes sense in a Servlet context. If the response is null then this is a no-op.
If the type starts with "text/" and does not contain a semicolon and a good response character set has been established based on the request Accept-Charset header and server preferences, then this and semicolon separator are automatically appended to the type.
Whether this function should be called at all may depend on the application and templates.
It should be called before any calls to getEncoding()
and before writing the response.
establishCharsets()
public String getContentType()
public void setMarkupLanguage(MarkupLanguage ml)
ml
- The ml to set.public MarkupLanguage getMarkupLanguage()
MarkupLanguage
for use generating output from templates.
Defaults to HTMLMarkupLanguage.
TempletLoader
,
PoemLocale
public HTMLMarkupLanguage getHTMLMarkupLanguage()
public String sameURLWith(String field, String value)
field
- The name of the form parametervalue
- The new value for the parameter (unencoded)
Form
public String sameURLWith(String field)
field
- The name of the form parameter
Form
public String getSameURL()
public void setBufferingOff() throws IOException
IOException
- if a writer has already been selectedFlushingServletTest
public void setFlushingOn() throws IOException
IOException
- if there is a problem with the writerpublic String getURLQueryEncoding()
The requirement here is that parameters can be encoded in
query strings included in URLs in the body of responses.
User interaction may result in subsequent requests with such
a URL. The HTML spec. describes encoding of non-alphanumeric
ASCII using % and ASCII hex codes and, in the case of forms.
says the client may use the response encoding by default.
Sun's javadoc for java.net.URLEncoder
recommends UTF-8 but the default is the Java platform
encoding. Most significantly perhaps,
org.mortbay.http.HttpRequest uses the request encoding.
We should check that this is correct in the servlet specs.
So we assume that the servlet runner may dictate the encoding that will work for multi-national characters in field values encoded in URL's (but not necessarily forms).
If the request encoding is used then we have to try and
predict it. It will be the same for a session unless a client
has some reason to change it. E.g. if we respond to a request
in a different encoding and the client is influenced.
(See establishCharsets()
.
But that is only a problem if the first or second request
in a session includes field values encoded in the URL and
user options include manually entering the same in a form
or changing their browser configuration.
Or we can change the server configuration.
It would be better if we had control over what encoding the servlet runner used to decode parameters. Perhaps one day we will.
So this method implements the current policy and currently
returns the current request encoding.
It assumes establishCharsets()
has been called to
set the request encoding if necessary.
see also org.melati.admin.Admin#selection(ServletTemplateContext, Melati)
public String urlEncode(String string)
string
- the String to encode
public String getEncoding()
This should always return an encoding and it should be the same for duration of use of an instance.
setResponseContentType(String)
public MelatiWriter getWriter()
public void setWriter(MelatiWriter writerP)
writerP
- the MelatiWriter to setpublic MelatiWriter getStringWriter()
public void write()
public void setPassbackExceptionHandling()
MarkupLanguage.rendered(Object)
,
TailoredQuery
public void setPropagateExceptionHandling()
public User getUser()
public boolean isReferencePoemType(Field field)
field
- the field to check
public String templateName(String key)
key
- fileName of template, without extension
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |