ulxr::HtmlFormHandler Class Reference
[HTTP and HTML handling]

Helper class to deal with html "post" and "get" requests. More...

#include <ulxr_htmlform_handler.h>

List of all members.

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 &)
HtmlFormHandleroperator= (const HtmlFormHandler &)

Private Attributes

CppString masterResource
std::vector< hidden::SubResourceBase * > subResources


Detailed Description

Helper class to deal with html "post" and "get" requests.

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.


Constructor & Destructor Documentation

ulxr::HtmlFormHandler::HtmlFormHandler ( const CppString resource  ) 

Construct the form handler.

The identifier which starts resource handled here.

Parameters:
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]


Member Function Documentation

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.

Parameters:
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).

Parameters:
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
Returns:
true: resource beginner matches and target contains the remainder

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.

Parameters:
value reference to value
Returns:

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.

Parameters:
data html data from the handler
Returns:
encoded data in 8bit characters

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.

Parameters:
data html data from the request
Returns:
encoded data in ulxr::CppString

Definition at line 146 of file ulxr_htmlform_handler.cpp.

References ulxr::utf8ToUnicode().

CppString ulxr::HtmlFormHandler::openForm ( const CppString name,
const CppString method 
)

Return html data which opens a form.

Parameters:
name the form name
method the http method to submit the form
Returns:
the according html sequence

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.

Returns:
the according html sequence

Definition at line 363 of file ulxr_htmlform_handler.cpp.

References ULXR_PCHAR.

CppString ulxr::HtmlFormHandler::makeAnchor ( const CppString url,
const CppString descr 
)

Creates an html anchor.

Parameters:
url the url of this anchor
descr the anchor's description
Returns:
the html sequence

Definition at line 338 of file ulxr_htmlform_handler.cpp.

References ULXR_PCHAR.

CppString ulxr::HtmlFormHandler::makeIdent ( const CppString name,
unsigned  index 
) [static]

Creates an identifier with a number.

Parameters:
name the identifiers name
index an additional index which is appended
Returns:
the name and index with an underscore between

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

Parameters:
index the number to transform
Returns:
the hex string of the number

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.

Parameters:
index the number to transform
Returns:
the decimal string of the number

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.

Parameters:
num the number string
Returns:
the number as long

Definition at line 579 of file ulxr_htmlform_handler.cpp.

References ulxr::getLatin1(), and ulxr_atoi.

CppString ulxr::HtmlFormHandler::makeText ( const CppString text  )  [static]

Make a pice of text hmtl conforming.

Dangerous characters like & and < are trasnformed into their html entities.

Parameters:
text the text to transform if needed
Returns:
the html conforming string

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.

Parameters:
name the checkbox name
value the checkbox value
checked true: set checked
Returns:
the html sequence

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).

Parameters:
name the field name
value the initial text
Returns:
the html sequence

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).

Parameters:
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)
Returns:
the html sequence

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.

Parameters:
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"
Returns:
the html sequence

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.

Parameters:
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.
Returns:
the html sequence

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.

Parameters:
name the radio name
value the radio value
checked true: radio is checked
Returns:
the html sequence

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.

Parameters:
name the submit button name
value the submit button value (the visible text)
Returns:
the html sequence

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.

Parameters:
name the reset button name
value the reset button value (the visible text)
Returns:
the html sequence

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.

Parameters:
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
Returns:
the html sequence

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.

Parameters:
prot pointer to the connecthion object
method the method (GET, PUT ..)
resource name of the resource
conn_data already received chunk from connection
Returns:
false: no resource found to handle

Definition at line 102 of file ulxr_htmlform_handler.cpp.

References ULXR_PCHAR, and ULXR_TRACE.

CppString ulxr::HtmlFormHandler::getHeader ( const CppString title  )  const [virtual]

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.

Parameters:
title the html title
Returns:
the header sequence

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.

Returns:
the tail sequence

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.

Returns:
the name of the css file.

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.

Returns:
the encoding name.

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.

Parameters:
formdata optional data from a form
mimetype [OUT] returns the mimetype of the data
Returns:
content of css file.

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.

Parameters:
formdata optional data from a form
mimetype [OUT] returns the mimetype of the data
Returns:
list of subresources.

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.

Returns:
name of the master resource.

Definition at line 87 of file ulxr_htmlform_handler.cpp.

template<class T>
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.

Parameters:
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]


Member Data Documentation

CppString ulxr::HtmlFormHandler::masterResource [private]

Definition at line 482 of file ulxr_htmlform_handler.h.

std::vector<hidden::SubResourceBase*> ulxr::HtmlFormHandler::subResources [private]

Definition at line 483 of file ulxr_htmlform_handler.h.

Referenced by ~HtmlFormHandler().


The documentation for this class was generated from the following files:
Generated on Sun Aug 19 20:09:04 2007 for ulxmlrpcpp by  doxygen 1.5.1