mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
added WebWidgets
This commit is contained in:
149
WebWidgets/src/WebApplication.cpp
Normal file
149
WebWidgets/src/WebApplication.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
//
|
||||
// WebApplication.cpp
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/src/WebApplication.cpp#5 $
|
||||
//
|
||||
// Library: WebWidgets
|
||||
// Package: Core
|
||||
// Module: WebApplication
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/WebApplication.h"
|
||||
#include "Poco/WebWidgets/RequestProcessor.h"
|
||||
#include "Poco/Net/HTMLForm.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
Poco::ThreadLocal<WebApplication*> WebApplication::_pInstance;
|
||||
|
||||
|
||||
WebApplication::WebApplication(const Poco::URI& uri):
|
||||
_pLookAndFeel(),
|
||||
_pCurrentPage(),
|
||||
_uri(uri)
|
||||
{
|
||||
attachToThread();
|
||||
}
|
||||
|
||||
|
||||
WebApplication::~WebApplication()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void WebApplication::setLookAndFeel(LookAndFeel::Ptr pLookAndFeel)
|
||||
{
|
||||
_pLookAndFeel = pLookAndFeel;
|
||||
}
|
||||
|
||||
|
||||
void WebApplication::setCurrentPage(Page::Ptr pPage)
|
||||
{
|
||||
_pCurrentPage = pPage;
|
||||
_requestProcessorMap.clear();
|
||||
_ajaxProcessorMap.clear();
|
||||
}
|
||||
|
||||
|
||||
void WebApplication::attachToThread()
|
||||
{
|
||||
*_pInstance = this;
|
||||
}
|
||||
|
||||
|
||||
WebApplication& WebApplication::instance()
|
||||
{
|
||||
WebApplication* pWebApp = *_pInstance;
|
||||
poco_check_ptr (pWebApp);
|
||||
return *pWebApp;
|
||||
}
|
||||
|
||||
|
||||
void WebApplication::registerFormProcessor(const std::string& fieldName, RequestProcessor* pProc)
|
||||
{
|
||||
std::pair<RequestProcessorMap::iterator, bool> res = _requestProcessorMap.insert(std::make_pair(fieldName, pProc));
|
||||
if (!res.second)
|
||||
res.first->second = pProc;
|
||||
}
|
||||
|
||||
|
||||
RequestProcessor* WebApplication::getFormProcessor(const std::string& fieldName)
|
||||
{
|
||||
RequestProcessorMap::iterator it = _requestProcessorMap.find(fieldName);
|
||||
if (it == _requestProcessorMap.end())
|
||||
return 0;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
void WebApplication::registerAjaxProcessor(const std::string& id, RequestProcessor* pProc)
|
||||
{
|
||||
std::pair<RequestProcessorMap::iterator, bool> res = _ajaxProcessorMap.insert(std::make_pair(id, pProc));
|
||||
if (!res.second)
|
||||
res.first->second = pProc;
|
||||
}
|
||||
|
||||
|
||||
RequestProcessor* WebApplication::getAjaxProcessor(const std::string& id)
|
||||
{
|
||||
RequestProcessorMap::iterator it = _ajaxProcessorMap.find(id);
|
||||
if (it == _ajaxProcessorMap.end())
|
||||
return 0;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
void WebApplication::handleForm(const Poco::Net::HTMLForm& form)
|
||||
{
|
||||
Poco::Net::NameValueCollection::ConstIterator it = form.begin();
|
||||
for (;it != form.end(); ++it)
|
||||
{
|
||||
const std::string& key = it->first;
|
||||
RequestProcessorMap::iterator itR = _requestProcessorMap.find(key);
|
||||
if (itR != _requestProcessorMap.end())
|
||||
{
|
||||
itR->second->handleForm(key, it->second);
|
||||
_requestProcessorMap.erase(itR);
|
||||
}
|
||||
}
|
||||
//those that are not included are either deselected or empty
|
||||
RequestProcessorMap::iterator itR = _requestProcessorMap.begin();
|
||||
std::string empty;
|
||||
for (; itR != _requestProcessorMap.end(); ++itR)
|
||||
{
|
||||
itR->second->handleForm(itR->first, empty);
|
||||
}
|
||||
_requestProcessorMap.clear();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
Reference in New Issue
Block a user