#include <ulxr_htmlform_handler.h>
Public Member Functions | |
HtmlFormHandler (const CppString &resource) | |
Construct the form handler. | |
virtual | ~HtmlFormHandler () |
Destroys the handler. | |
HtmlFormData | extractFormElements (HttpProtocol *prot, const CppString &method, const CppString &resource, const Cpp8BitString &conn_data) |
Extracts the form elements that come within the http request. | |
virtual std::string | encodeForHtml (const CppString &data) |
Encodes the html data into the desired encoding for transmission. | |
virtual CppString | encodeFromHtml (const std::string &data) |
Encodes the html data for use in the hanlder. | |
CppString | openForm (const CppString &name, const CppString &method) |
Return html data which opens a form. | |
CppString | makeAnchor (const CppString &url, const CppString &descr) |
Creates an html anchor. | |
virtual bool | handler (HttpProtocol *prot, const CppString &method, const CppString &resource, const Cpp8BitString &conn_data) |
The default handler. | |
virtual CppString | getHeader (const CppString &title) const |
Gets the default html header. | |
virtual CppString | getTail () const |
Gets the default html tail. | |
virtual CppString | getCssName () const |
Gets the default name for the css file. | |
virtual CppString | getEncoding () const |
Gets the prefered encoding for this handler. | |
virtual CppString | handle_css_file (const HtmlFormData &formdata, CppString &mimetype) |
Returns the common css file content. | |
CppString | handle_subresource_list (const HtmlFormData &formdata, CppString &mimetype) |
Returns html page with a list of the subresources. | |
CppString | getMasterResource () const |
Returns the name of the master resource. | |
template<class T> | |
void | addSubResource (const CppString &name, T *obj, CppString(T::*pmf)(const HtmlFormData &, CppString &), const CppString &descr=ULXR_PCHAR("")) |
Adds another sub-resource below the master reource. | |
Static Public Member Functions | |
static bool | resourceSplit (const CppString &method, const CppString &resource, const CppString &rsc_start, CppString &target) |
Split an incoming resource into the base part and the extension. | |
static std::string | formDecode (std::string &value) |
Decodes the form data into normal characters. | |
static CppString | closeForm () |
Return html data which closes a form. | |
static CppString | makeIdent (const CppString &name, unsigned index) |
Creates an identifier with a number. | |
static CppString | makeHexNumber (unsigned index) |
Turns a number into a hex string. | |
static CppString | makeNumber (unsigned index) |
Turns a number into a decimal string. | |
static long | getLong (const CppString &num) |
Turns a strin into a long value. | |
static CppString | makeText (const CppString &text) |
Make a pice of text hmtl conforming. | |
static CppString | makeCheckBox (const CppString &name, const CppString &value, bool checked=false) |
Creates a html sequence for a checkbox. | |
static CppString | makeTextField (const CppString &name, const CppString &value) |
Creates a html sequence for a text field (one single line). | |
static CppString | makeTextArea (const CppString &name, const CppString &value, int cols=-1, int rows=-1) |
Creates a html sequence for a text area (one or more lines). | |
static CppString | openSelect (const CppString &name, int size=1, bool multi=false) |
Return data which opens a select element. | |
static CppString | makeOption (const CppString &data, const CppString &value=ULXR_PCHAR(""), bool selected=false) |
Creates an data entry for a select element. | |
static CppString | closeSelect () |
Closes the select element. | |
static CppString | makeRadioButton (const CppString &name, const CppString &value, bool checked=false) |
Creates a html sequence for a radio button. | |
static CppString | makeSubmitButton (const CppString &name, const CppString &value) |
Creates a html sequence for a submit button. | |
static CppString | makeResetButton (const CppString &name, const CppString &value) |
Creates a html sequence for a reset button. | |
static CppString | makeLineBreak () |
Inserts a line break tag. | |
static CppString | applyTags (const CppString &data, const CppString &tag, bool newline=false) |
Surrounds a piece of text with a start and end tag. | |
Private Member Functions | |
HtmlFormHandler (const HtmlFormHandler &) | |
HtmlFormHandler & | operator= (const HtmlFormHandler &) |
Private Attributes | |
CppString | masterResource |
std::vector< hidden::SubResourceBase * > | subResources |
Intended to be added to a HttpServer
object as handler for one or more special resources. All transfered content is expected to be in UTF-8 encoding when unicode is enabled, otherwise you need to take care of your local 8bit encoding (8859-1 as default).
Definition at line 193 of file ulxr_htmlform_handler.h.
ulxr::HtmlFormHandler::HtmlFormHandler | ( | const CppString & | resource | ) |
Construct the form handler.
The identifier which starts resource handled here.
resource | name of the resource that is handled here. |
Definition at line 79 of file ulxr_htmlform_handler.cpp.
References addSubResource(), getCssName(), handle_css_file(), and ULXR_PCHAR.
ulxr::HtmlFormHandler::~HtmlFormHandler | ( | ) | [virtual] |
Destroys the handler.
Definition at line 93 of file ulxr_htmlform_handler.cpp.
References subResources.
ulxr::HtmlFormHandler::HtmlFormHandler | ( | const HtmlFormHandler & | ) | [private] |
HtmlFormData ulxr::HtmlFormHandler::extractFormElements | ( | HttpProtocol * | prot, | |
const CppString & | method, | |||
const CppString & | resource, | |||
const Cpp8BitString & | conn_data | |||
) |
Extracts the form elements that come within the http request.
prot | pointer to the according connection | |
method | the method in use | |
resource | the requested resource | |
conn_data | already received chunk of the message body. |
Definition at line 181 of file ulxr_htmlform_handler.cpp.
References ulxr::HtmlFormData::addElement(), ulxr::getLatin1(), ULXR_CHAR, ULXR_GET_STRING, ULXR_PCHAR, ULXR_RECV_BUFFER_SIZE, and ULXR_TRACE.
bool ulxr::HtmlFormHandler::resourceSplit | ( | const CppString & | method, | |
const CppString & | resource, | |||
const CppString & | rsc_start, | |||
CppString & | target | |||
) | [static] |
Split an incoming resource into the base part and the extension.
This method assumes that the resource consists of two main parts, usually regarded as a "file within a path": a directory-like part (the resource start) and a file-like part (the target).
method | the method in use | |
resource | request resource from a client | |
rsc_start | the main part of the resource which is handled | |
target | the special part |
Definition at line 156 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
std::string ulxr::HtmlFormHandler::formDecode | ( | std::string & | value | ) | [static] |
Decodes the form data into normal characters.
Incoming form data is encoded according to RFC2396.
value | reference to value |
Definition at line 243 of file ulxr_htmlform_handler.cpp.
References ULXR_GET_STRING, ULXR_PCHAR, ulxr_toupper, and ULXR_TRACE.
std::string ulxr::HtmlFormHandler::encodeForHtml | ( | const CppString & | data | ) | [virtual] |
Encodes the html data into the desired encoding for transmission.
data | html data from the handler |
Definition at line 136 of file ulxr_htmlform_handler.cpp.
References ulxr::unicodeToUtf8().
CppString ulxr::HtmlFormHandler::encodeFromHtml | ( | const std::string & | data | ) | [virtual] |
Encodes the html data for use in the hanlder.
data | html data from the request |
Definition at line 146 of file ulxr_htmlform_handler.cpp.
References ulxr::utf8ToUnicode().
Return html data which opens a form.
name | the form name | |
method | the http method to submit the form |
Definition at line 351 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::closeForm | ( | ) | [static] |
Return html data which closes a form.
Definition at line 363 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
Creates an html anchor.
url | the url of this anchor | |
descr | the anchor's description |
Definition at line 338 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
Creates an identifier with a number.
name | the identifiers name | |
index | an additional index which is appended |
Definition at line 345 of file ulxr_htmlform_handler.cpp.
CppString ulxr::HtmlFormHandler::makeHexNumber | ( | unsigned | index | ) | [static] |
Turns a number into a hex string.
the string includes the C-style "0x" prefix
index | the number to transform |
Definition at line 553 of file ulxr_htmlform_handler.cpp.
References ulxr_sprintf, and ulxr_swprintf.
Referenced by ulxr::binaryDebugOutput(), ulxr::WbXmlParser::parse(), ulxr::WbXmlParser::testStartElement(), ulxr::ValueParserWb::testStartElement(), ulxr::MethodResponseParserWb::testStartElement(), ulxr::MethodCallParserWb::testStartElement(), ulxr::unicodeToUtf8(), ulxr::utf8ToAscii(), and ulxr::utf8ToUnicode().
CppString ulxr::HtmlFormHandler::makeNumber | ( | unsigned | index | ) | [static] |
Turns a number into a decimal string.
index | the number to transform |
Definition at line 536 of file ulxr_htmlform_handler.cpp.
References ulxr_sprintf, and ulxr_swprintf.
Referenced by ulxr::TcpIpConnection::accept(), ulxr::HtmlFormData::getElement(), ulxr::HtmlFormData::hasElement(), ulxr::TcpIpConnection::open(), ulxr::padded(), ulxr::WbXmlParser::parse(), ulxr::Connection::read(), and ulxr::Log4JSender::send().
long ulxr::HtmlFormHandler::getLong | ( | const CppString & | num | ) | [static] |
Turns a strin into a long value.
num | the number string |
Definition at line 579 of file ulxr_htmlform_handler.cpp.
References ulxr::getLatin1(), and ulxr_atoi.
Make a pice of text hmtl conforming.
Dangerous characters like & and < are trasnformed into their html entities.
text | the text to transform if needed |
Definition at line 530 of file ulxr_htmlform_handler.cpp.
References ulxr::xmlEscape().
CppString ulxr::HtmlFormHandler::makeCheckBox | ( | const CppString & | name, | |
const CppString & | value, | |||
bool | checked = false | |||
) | [static] |
Creates a html sequence for a checkbox.
name | the checkbox name | |
value | the checkbox value | |
checked | true: set checked |
Definition at line 396 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::makeTextField | ( | const CppString & | name, | |
const CppString & | value | |||
) | [static] |
Creates a html sequence for a text field (one single line).
name | the field name | |
value | the initial text |
Definition at line 479 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::makeTextArea | ( | const CppString & | name, | |
const CppString & | value, | |||
int | cols = -1 , |
|||
int | rows = -1 | |||
) | [static] |
Creates a html sequence for a text area (one or more lines).
name | the field name | |
value | the initial text | |
cols | the number of colums the field shall have (-1 = let browser decide) | |
rows | the number of rows the field shall have (-1 = let browser decide) |
Definition at line 457 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::openSelect | ( | const CppString & | name, | |
int | size = 1 , |
|||
bool | multi = false | |||
) | [static] |
Return data which opens a select element.
name | the field name | |
size | number of elements that are visible at the same time. 1 results usually in a listbox | |
multi | true: add attribute "multiple" |
Definition at line 414 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::makeOption | ( | const CppString & | data, | |
const CppString & | value = ULXR_PCHAR("") , |
|||
bool | selected = false | |||
) | [static] |
Creates an data entry for a select element.
data | the visible text for this option | |
value | the value which is returned with the form data. Only needed if you don't want to return the option data. | |
selected | the option is pre-selected in the list element. |
Definition at line 433 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::closeSelect | ( | ) | [static] |
Closes the select element.
Definition at line 451 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::makeRadioButton | ( | const CppString & | name, | |
const CppString & | value, | |||
bool | checked = false | |||
) | [static] |
Creates a html sequence for a radio button.
name | the radio name | |
value | the radio value | |
checked | true: radio is checked |
Definition at line 490 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::makeSubmitButton | ( | const CppString & | name, | |
const CppString & | value | |||
) | [static] |
Creates a html sequence for a submit button.
name | the submit button name | |
value | the submit button value (the visible text) |
Definition at line 508 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::makeResetButton | ( | const CppString & | name, | |
const CppString & | value | |||
) | [static] |
Creates a html sequence for a reset button.
name | the reset button name | |
value | the reset button value (the visible text) |
Definition at line 519 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::makeLineBreak | ( | ) | [static] |
Inserts a line break tag.
Definition at line 390 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::applyTags | ( | const CppString & | data, | |
const CppString & | tag, | |||
bool | newline = false | |||
) | [static] |
Surrounds a piece of text with a start and end tag.
The brackets < > are inserted.
data | the piece of text to be surrounded | |
tag | the tag name. Additional attributes for the start tag are allowed and removed for the ending tag. | |
newline | true: append a newline for ease of reading |
Definition at line 369 of file ulxr_htmlform_handler.cpp.
References ULXR_CHAR, and ULXR_PCHAR.
bool ulxr::HtmlFormHandler::handler | ( | HttpProtocol * | prot, | |
const CppString & | method, | |||
const CppString & | resource, | |||
const Cpp8BitString & | conn_data | |||
) | [virtual] |
The default handler.
The master and subresources are searched and their handlers are invoked after ectracting optional post data.
prot | pointer to the connecthion object | |
method | the method (GET, PUT ..) | |
resource | name of the resource | |
conn_data | already received chunk from connection |
Definition at line 102 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR, and ULXR_TRACE.
Gets the default html header.
The header contains the html dtd sequence, the link to the css file, sets the charset to utf8, includes the title and the opening body
tag.
title | the html title |
Definition at line 319 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::getTail | ( | ) | const [virtual] |
Gets the default html tail.
The default tail includes the closing body
and html
tags.
Definition at line 332 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::getCssName | ( | ) | const [virtual] |
Gets the default name for the css file.
By using a sngle css file you achive a common look for all the pages from this handler.
Definition at line 313 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
Referenced by HtmlFormHandler().
CppString ulxr::HtmlFormHandler::getEncoding | ( | ) | const [virtual] |
Gets the prefered encoding for this handler.
When in Unicode mode, UTF-8 is returned by default, otherwise we use ISO-8859-1 which should work in most cases on the world.
Definition at line 590 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::handle_css_file | ( | const HtmlFormData & | formdata, | |
CppString & | mimetype | |||
) | [virtual] |
Returns the common css file content.
formdata | optional data from a form | |
mimetype | [OUT] returns the mimetype of the data |
Definition at line 306 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
Referenced by HtmlFormHandler().
CppString ulxr::HtmlFormHandler::handle_subresource_list | ( | const HtmlFormData & | formdata, | |
CppString & | mimetype | |||
) |
Returns html page with a list of the subresources.
formdata | optional data from a form | |
mimetype | [OUT] returns the mimetype of the data |
Definition at line 286 of file ulxr_htmlform_handler.cpp.
References ULXR_PCHAR.
CppString ulxr::HtmlFormHandler::getMasterResource | ( | ) | const |
Returns the name of the master resource.
Definition at line 87 of file ulxr_htmlform_handler.cpp.
void ulxr::HtmlFormHandler::addSubResource | ( | const CppString & | name, | |
T * | obj, | |||
CppString(T::*)(const HtmlFormData &, CppString &) | pmf, | |||
const CppString & | descr = ULXR_PCHAR("") | |||
) | [inline] |
Adds another sub-resource below the master reource.
name | name of the subresource | |
obj | pointer of the object which handles it | |
pmf | pointer of a member function in the object | |
descr | human readable description for this resource |
Definition at line 465 of file ulxr_htmlform_handler.h.
References ulxr::ApplicationError, and ULXR_PCHAR.
Referenced by HtmlFormHandler().
HtmlFormHandler& ulxr::HtmlFormHandler::operator= | ( | const HtmlFormHandler & | ) | [private] |
Definition at line 482 of file ulxr_htmlform_handler.h.
std::vector<hidden::SubResourceBase*> ulxr::HtmlFormHandler::subResources [private] |