public abstract class Toadlet
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
HANDLE_METHOD_PREFIX |
Modifier | Constructor and Description |
---|---|
protected |
Toadlet(HighLevelSimpleClient client) |
Modifier and Type | Method and Description |
---|---|
protected static void |
addHomepageLink(HTMLNode content) |
boolean |
allowPOSTWithoutPassword()
Override to return true if the toadlet should handle POSTs that don't have the correct form
password.
|
java.lang.String |
findSupportedMethods()
Which methods are supported by this Toadlet.
|
protected HighLevelSimpleClient |
getClientImpl()
Get the client impl.
|
abstract void |
handleMethodGET(java.net.URI uri,
HTTPRequest request,
ToadletContext ctx)
Handle a GET request.
|
abstract java.lang.String |
path() |
protected void |
sendErrorPage(ToadletContext ctx,
int code,
java.lang.String desc,
HTMLNode message)
Send a slightly more complex error page.
|
protected void |
sendErrorPage(ToadletContext ctx,
int code,
java.lang.String desc,
java.lang.String message)
Send a simple error page.
|
protected void |
sendErrorPage(ToadletContext ctx,
java.lang.String desc,
java.lang.String message,
java.lang.Throwable t)
Send an error page from an exception.
|
Toadlet |
showAsToadlet()
Deprecated.
Use
showAsToadlet(ToadletContext) instead. Internally fred will always call that function, which calls this function by default,
so old code which only overrides this function still works.
TODO: When removing this deprecated function, change showAsToadlet(ToadletContext) to return this by default, as
already specified in its JavaDoc. |
Toadlet |
showAsToadlet(ToadletContext context)
Primary purpose of this function is being overridden in your Toadlet implementations - for the following purpose:
When displaying this Toadlet, the web interface should show the menu from which it was selected as opened, and mark the
appropriate entry as selected in the menu.
|
protected void |
writeHTMLReply(ToadletContext ctx,
int code,
java.lang.String desc,
MultiValueTable<java.lang.String,java.lang.String> headers,
java.lang.String reply)
Write an HTTP response as HTML, possibly with custom headers, for example, we may want to
send a redirect, or a file with a specified filename.
|
protected void |
writeHTMLReply(ToadletContext ctx,
int code,
java.lang.String desc,
MultiValueTable<java.lang.String,java.lang.String> headers,
java.lang.String reply,
boolean forceDisableJavascript)
Write an HTTP response as HTML, possibly with custom headers, for example, we may want to
send a redirect, or a file with a specified filename.
|
protected void |
writeHTMLReply(ToadletContext ctx,
int code,
java.lang.String desc,
java.lang.String reply)
Write an HTTP response as HTML.
|
protected void |
writeInternalError(java.lang.Throwable t,
ToadletContext ctx) |
protected void |
writeReply(ToadletContext ctx,
int code,
java.lang.String mimeType,
java.lang.String desc,
Bucket data)
Write an HTTP response, e.g.
|
protected void |
writeReply(ToadletContext ctx,
int code,
java.lang.String mimeType,
java.lang.String desc,
byte[] data,
int offset,
int length)
Write an HTTP response, e.g.
|
protected void |
writeReply(ToadletContext context,
int code,
java.lang.String mimeType,
java.lang.String desc,
MultiValueTable<java.lang.String,java.lang.String> headers,
Bucket data)
Write an HTTP response, e.g.
|
protected void |
writeReply(ToadletContext context,
int code,
java.lang.String mimeType,
java.lang.String desc,
MultiValueTable<java.lang.String,java.lang.String> headers,
java.lang.String reply) |
protected void |
writeReply(ToadletContext context,
int code,
java.lang.String mimeType,
java.lang.String desc,
MultiValueTable<java.lang.String,java.lang.String> headers,
java.lang.String reply,
boolean forceDisableJavascript) |
protected void |
writeReply(ToadletContext ctx,
int code,
java.lang.String mimeType,
java.lang.String desc,
java.lang.String reply)
Write a text-based HTTP response, e.g.
|
protected void |
writeTemporaryRedirect(ToadletContext ctx,
java.lang.String msg,
java.lang.String location)
Do a temporary redirect (HTTP Status 302).
|
protected void |
writeTextReply(ToadletContext ctx,
int code,
java.lang.String desc,
MultiValueTable<java.lang.String,java.lang.String> headers,
java.lang.String reply)
Write an HTTP response as plain text, possibly with custom headers, for example, we may want
to send a redirect, or a file with a specified filename.
|
protected void |
writeTextReply(ToadletContext ctx,
int code,
java.lang.String desc,
java.lang.String reply)
Write an HTTP response as plain text.
|
public static final java.lang.String HANDLE_METHOD_PREFIX
protected Toadlet(HighLevelSimpleClient client)
public abstract void handleMethodGET(java.net.URI uri, HTTPRequest request, ToadletContext ctx) throws ToadletContextClosedException, java.io.IOException, RedirectException
uri
- The URI being fetched.request
- The original HTTPRequest, convenient for e.g. fetching ?blah=blah parameters.ctx
- The request context. Mainly used for sending a reply; this identifies which
request we are replying to. Also gives access to lots of important objects e.g. PageMaker.ToadletContextClosedException
java.io.IOException
RedirectException
public abstract java.lang.String path()
public Toadlet showAsToadlet(ToadletContext context)
Toadlet.this
as selected:
Some Toadlets won't be added to a menu. They will be only accessible through other Toadlets. For example
a Toadlet for deleting a single download might only be accessible through the Toadlet which shows all downloads.
For still being able to figure out the menu entry through which those so-called invisible Toadlets where accessed,
this function is necessary.context
- Can be used to decide the return value, for example to check session cookies using SessionManager
.showAsToadlet()
, which is this
by default.@Deprecated public Toadlet showAsToadlet()
showAsToadlet(ToadletContext)
instead. Internally fred will always call that function, which calls this function by default,
so old code which only overrides this function still works.
TODO: When removing this deprecated function, change showAsToadlet(ToadletContext)
to return this
by default, as
already specified in its JavaDoc.this
public boolean allowPOSTWithoutPassword()
public final java.lang.String findSupportedMethods()
protected void writeReply(ToadletContext ctx, int code, java.lang.String mimeType, java.lang.String desc, byte[] data, int offset, int length) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.mimeType
- The MIME type of the data we are returning.desc
- The HTTP response description for the code.data
- The data to write as the response body.offset
- The offset within data of the first byte to send.length
- The number of bytes of data to send as the response body.ToadletContextClosedException
java.io.IOException
protected void writeReply(ToadletContext ctx, int code, java.lang.String mimeType, java.lang.String desc, Bucket data) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.mimeType
- The MIME type of the data we are returning.desc
- The HTTP response description for the code.data
- The Bucket which contains the reply data. This
function assumes ownership of the Bucket, calling free()
on it when done. If this behavior is undesired, callers
can wrap their Bucket in a NoFreeBucket.ToadletContextClosedException
java.io.IOException
NoFreeBucket
protected void writeReply(ToadletContext context, int code, java.lang.String mimeType, java.lang.String desc, MultiValueTable<java.lang.String,java.lang.String> headers, Bucket data) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.mimeType
- The MIME type of the data we are returning.desc
- The HTTP response description for the code.headers
- The additional HTTP headers to send.data
- The Bucket which contains the reply data. This
function assumes ownership of the Bucket, calling free()
on it when done. If this behavior is undesired, callers
can wrap their Bucket in a NoFreeBucket.ToadletContextClosedException
java.io.IOException
NoFreeBucket
protected void writeReply(ToadletContext ctx, int code, java.lang.String mimeType, java.lang.String desc, java.lang.String reply) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.mimeType
- The MIME type of the data we are returning.desc
- The HTTP response description for the code.reply
- The reply data, as a String (so only use this for text-based replies, e.g.
HTML, plain text etc).ToadletContextClosedException
java.io.IOException
protected void writeHTMLReply(ToadletContext ctx, int code, java.lang.String desc, java.lang.String reply) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.desc
- The HTTP response description for the code.reply
- The HTML page, as a String.ToadletContextClosedException
java.io.IOException
protected void writeTextReply(ToadletContext ctx, int code, java.lang.String desc, java.lang.String reply) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.desc
- The HTTP response description for the code.reply
- The text of the page, as a String.ToadletContextClosedException
java.io.IOException
protected void writeHTMLReply(ToadletContext ctx, int code, java.lang.String desc, MultiValueTable<java.lang.String,java.lang.String> headers, java.lang.String reply) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.desc
- The HTTP response description for the code.headers
- The additional HTTP headers to send.reply
- The HTML page, as a String.ToadletContextClosedException
java.io.IOException
protected void writeHTMLReply(ToadletContext ctx, int code, java.lang.String desc, MultiValueTable<java.lang.String,java.lang.String> headers, java.lang.String reply, boolean forceDisableJavascript) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.desc
- The HTTP response description for the code.headers
- The additional HTTP headers to send.reply
- The HTML page, as a String.ToadletContextClosedException
java.io.IOException
protected void writeTextReply(ToadletContext ctx, int code, java.lang.String desc, MultiValueTable<java.lang.String,java.lang.String> headers, java.lang.String reply) throws ToadletContextClosedException, java.io.IOException
ctx
- The specific request to reply to.code
- The HTTP reply code to use.desc
- The HTTP response description for the code.headers
- The additional HTTP headers to send.reply
- The text of the page, as a String.ToadletContextClosedException
java.io.IOException
protected void writeReply(ToadletContext context, int code, java.lang.String mimeType, java.lang.String desc, MultiValueTable<java.lang.String,java.lang.String> headers, java.lang.String reply) throws ToadletContextClosedException, java.io.IOException
ToadletContextClosedException
java.io.IOException
protected void writeReply(ToadletContext context, int code, java.lang.String mimeType, java.lang.String desc, MultiValueTable<java.lang.String,java.lang.String> headers, java.lang.String reply, boolean forceDisableJavascript) throws ToadletContextClosedException, java.io.IOException
ToadletContextClosedException
java.io.IOException
protected void writeTemporaryRedirect(ToadletContext ctx, java.lang.String msg, java.lang.String location) throws ToadletContextClosedException, java.io.IOException
ctx
- msg
- Message to be used in HTML (not visible in general).location
- New location (URL)ToadletContextClosedException
java.io.IOException
protected void sendErrorPage(ToadletContext ctx, int code, java.lang.String desc, java.lang.String message) throws ToadletContextClosedException, java.io.IOException
ToadletContextClosedException
java.io.IOException
protected void sendErrorPage(ToadletContext ctx, int code, java.lang.String desc, HTMLNode message) throws ToadletContextClosedException, java.io.IOException
ToadletContextClosedException
java.io.IOException
protected void sendErrorPage(ToadletContext ctx, java.lang.String desc, java.lang.String message, java.lang.Throwable t) throws ToadletContextClosedException, java.io.IOException
ctx
- The context object for this request.desc
- The title of the error pagemessage
- The message to be sent to the user. The stack trace will follow.t
- The Throwable which caused the error.java.io.IOException
- If there is an error writing the reply.ToadletContextClosedException
- If the context has already been closed.protected void writeInternalError(java.lang.Throwable t, ToadletContext ctx) throws ToadletContextClosedException, java.io.IOException
ToadletContextClosedException
java.io.IOException
protected static void addHomepageLink(HTMLNode content)
protected HighLevelSimpleClient getClientImpl()