added WebWidgets

This commit is contained in:
Peter Schojer
2008-05-12 13:12:39 +00:00
parent 9661e08347
commit 6c80fe82c1
577 changed files with 34601 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
#
# Makefile
#
# $Id: //poco/Main/WebWidgets/ExtJS/samples/Server/Makefile#1 $
#
# Makefile for Poco Server
#
include $(POCO_BASE)/build/rules/global
objects = Server
target = Server
target_version = 1
target_libs = PocoFoundation PocoXML PocoNet PocoUtil
include $(POCO_BASE)/build/rules/exec

View File

@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="Server"
ProjectGUID="{b0ffa5df-1420-460f-8e87-e4debe801a05}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/Serverd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="bin/Serverd.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForWindowsApplication="TRUE"
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\XML\include;..\..\..\Net\include;..\..\..\Util\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/Server.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="FALSE"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
Filter="">
</Filter>
<Filter
Name="Source Files"
Filter="">
<File
RelativePath=".\src\Server.cpp">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,211 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="Server"
ProjectGUID="{B0FFA5DF-1420-460F-8E87-E4DEBE801A05}"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="debug_shared|Win32"
OutputDirectory="obj\debug_shared"
IntermediateDirectory="obj\debug_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\include;..\..\..\..\Foundation\include;..\..\..\..\XML\include;..\..\..\..\Net\include;..\..\..\..\Util\include;..\..\..\..\WebWidgets\include;..\..\..\..\WebWidgets\ExtJS\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="true"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundationd.lib PocoXMLd.lib PocoNetd.lib PocoUtild.lib"
OutputFile="bin/Serverd.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\..\lib"
GenerateDebugInformation="true"
ProgramDatabaseFile="bin/Serverd.pdb"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="release_shared|Win32"
OutputDirectory="obj\release_shared"
IntermediateDirectory="obj\release_shared"
ConfigurationType="1"
UseOfMFC="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="4"
InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories=".\include;..\..\..\..\Foundation\include;..\..\..\..\XML\include;..\..\..\..\Net\include;..\..\..\..\Util\include;..\..\..\..\WebWidgets\include;..\..\..\..\WebWidgets\ExtJS\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
StringPooling="true"
RuntimeLibrary="2"
BufferSecurityCheck="false"
TreatWChar_tAsBuiltInType="true"
ForceConformanceInForLoopScope="true"
RuntimeTypeInfo="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="PocoFoundation.lib PocoXML.lib PocoNet.lib PocoUtil.lib"
OutputFile="bin/Server.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\..\lib"
GenerateDebugInformation="false"
ProgramDatabaseFile=""
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\Server.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,222 @@
//
// Server.cpp
//
// $Id: //poco/Main/WebWidgets/ExtJS/samples/Server/src/Server.cpp#4 $
//
// This sample demonstrates the XYZ class.
//
// Copyright (c) 2007, 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/Util/ServerApplication.h"
#include "Poco/Util/Option.h"
#include "Poco/Util/OptionException.h"
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h"
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/Net/HTTPRequestHandler.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerParams.h"
#include "Poco/WebWidgets/RequestHandler.h"
#include "Poco/WebWidgets/WebApplication.h"
#include "Poco/WebWidgets/ExtJS/Utility.h"
#include "Poco/WebWidgets/Table.h"
#include "Poco/WebWidgets/SubmitButton.h"
#include "Poco/WebWidgets/CheckButton.h"
#include "Poco/WebWidgets/SimpleTableModel.h"
#include "Poco/WebWidgets/Form.h"
#include "Poco/WebWidgets/DataRetriever.h"
#include "Poco/WebWidgets/TextField.h"
#include "Poco/File.h"
#include "Poco/Path.h"
#include <iostream>
using Poco::Util::Application;
using Poco::Util::ServerApplication;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::OptionCallback;
using Poco::Util::HelpFormatter;
using Poco::Net::HTTPRequestHandlerFactory;
using Poco::Net::HTTPRequestHandler;
using Poco::Net::HTTPServerRequest;
using Poco::Net::ServerSocket;
using Poco::Net::HTTPServer;
using Poco::Net::HTTPServerParams;
using namespace Poco::WebWidgets;
class WebAppHandlerFactory: public HTTPRequestHandlerFactory
{
public:
WebAppHandlerFactory(WebApplication& app, const Poco::Path& dataPath, Poco::Logger* pLogger):
_app(app),
_dataRoot(dataPath),
_aliases(),
_pLogger(pLogger)
{
_aliases.insert(std::make_pair("", _dataRoot));
}
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
{
const std::string& uri = request.getURI();
Poco::URI url(uri);
const std::string& path = url.getPath();
const std::string& appPath = _app.getURI().getPath();
if (path == appPath ||
(path.size() > appPath.size() && path.find(appPath) == 0 && path[appPath.size()] == ';')
)
return new RequestHandler(_app);
return new DataRetriever(_aliases, _pLogger);
}
private:
WebApplication& _app;
Poco::Path _dataRoot;
DataRetriever::Aliases _aliases;
Poco::Logger* _pLogger;
};
class WebServer: public ServerApplication
{
public:
WebServer(): _helpRequested(false)
{
}
~WebServer()
{
}
protected:
void initialize(Application& self)
{
loadConfiguration(); // load default configuration files, if present
ServerApplication::initialize(self);
logger().information("starting up");
}
void uninitialize()
{
logger().information("shutting down");
ServerApplication::uninitialize();
}
void defineOptions(OptionSet& options)
{
ServerApplication::defineOptions(options);
options.addOption(
Option("help", "h", "display help information on command line arguments")
.required(false)
.repeatable(false)
.callback(OptionCallback<WebServer>(this, &WebServer::handleHelp)));
}
void handleHelp(const std::string& name, const std::string& value)
{
_helpRequested = true;
displayHelp();
stopOptionsProcessing();
}
void displayHelp()
{
HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader("A sample server application that demonstrates some of the features of the Util::ServerApplication class.");
helpFormatter.format(std::cout);
}
int main(const std::vector<std::string>& args)
{
if (!_helpRequested)
{
WebApplication webApp(Poco::URI("/"));
LookAndFeel::Ptr laf(new LookAndFeel());
Poco::WebWidgets::ExtJS::Utility::initialize(laf);
webApp.setLookAndFeel(laf);
Page::Ptr ptr = new Page("test");
Form::Ptr pForm = new Form("form1", Poco::URI("/"));
//pForm->setURL(...);
Table::TableColumns tc;
TextField::Ptr pTxt(new TextField("txt"));
tc.push_back(new TableColumn(pTxt->getCell(), "StaticText"));
CheckButton::Ptr ptrCheck(new CheckButton("check", "Const", true));
tc.push_back(new TableColumn(ptrCheck->getCell(), "CheckButton"));
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2));
///init simpletablemodel
pTable->setValue(std::string("one"), 0,0);
pTable->setValue(std::string("two"), 1,0);
pTable->setValue(std::string("three"), 2,0);
pTable->setValue(true, 0,1);
pTable->setValue(false, 1,1);
pTable->setValue(true, 2,1);
pForm->add(pTable);
pForm->add(new TextField("txtfield"));
CheckButton::Ptr ptrCheck2(new CheckButton("checkbutton", "CheckButton", false));
pForm->add(ptrCheck2);
SubmitButton::Ptr ptrBut(new SubmitButton("Submit"));
ptrBut->setText("Submit");
pForm->add(ptrBut);
ptr->add(pForm);
webApp.setCurrentPage(ptr);
unsigned short port = (unsigned short) config().getInt("WebServer.port", 9980);
std::string data = config().getString("WebServer.dataRoot", ".");
Poco::Path aPath(data);
aPath.makeAbsolute();
aPath.makeDirectory();
Poco::File aFile(aPath);
if (!aFile.exists() || aFile.isFile())
throw Poco::Util::InvalidArgumentException("dataRoot is either a file or doesn't exist: must be directory!");
ServerSocket svs(port);
HTTPServer srv(new WebAppHandlerFactory(webApp, aPath, &logger()), svs, new HTTPServerParams);
srv.start();
waitForTerminationRequest();
srv.stop();
}
return Application::EXIT_OK;
}
private:
bool _helpRequested;
};
POCO_SERVER_MAIN(WebServer)