Commit fe57f56f authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

рефакторинг

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@61965 954022d7-b5bf-4e40-9824-e11837661b57
parent bcf37600
// xmlread.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cpdoccore/xml/sax.h>
#include <cpdoccore/xml/attributes.h>
#include <cpdoccore/xml/serialize_attributes.h>
#include <cpdoccore/CPSharedPtr.h>
#include <utf8cpp/utf8.h>
#include <boost/timer.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cpdoccore/../../src/odf/odf_document.h>
int _tmain(int argc, _TCHAR* argv[])
{
//const std::wstring odfFolder = L"f:/Projects/Documents/cpdocument/test/odf/SimpleList/";
//const std::wstring odfFolder = L"f:/Projects/Documents/cpdocument/test/odf/TextProperties/";
//const std::wstring odfFolder = L"f:/Projects/Documents/cpdocument/test/odf/generaltest/";
const std::wstring odfFolder = L"f:/Projects/Documents/cpdocument/test/odf/ivanova/";
boost::timer t;
cpdoccore::odf::odf_document d(odfFolder);
std::cout << "open: " << t.elapsed() << "\n";
//std::wcout << "\n\n";
{
std::wstringstream out;
//std::wofstream fOut(L"f:/Projects/Documents/cpdocument/bin/01.xml");
t.restart();
d.xml_to_stream(out);
std::cout << "serialize: " << t.elapsed() << "\n";
t.restart();
std::wstring s = out.str();
std::string res;
utf8::utf16to8(s.begin(), s.end(), std::back_inserter(res));
FILE * f = fopen("f:/Projects/Documents/cpdocument/bin/01.xml", "wb");
fwrite(res.c_str(), res.size(), 1, f);
fclose(f);
std::cout << "save: " << t.elapsed() << "\n";
}
//std::wstringstream strm;
//d.xml_to_stream(strm);
//std::wstring xmlString = strm.str();
char ch;
std::cin >> ch;
return 0;
}
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="odf_open_1"
ProjectGUID="{16668048-27AC-4BC0-9A56-1D547DF218B5}"
RootNamespace="odf_open_1"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)bin"
IntermediateDirectory="$(SolutionDir)output/$(ConfigurationName)/$(ProjectName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(SolutionDir)include&quot;;&quot;$(SolutionDir)3dparty/utf8cpp/include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib xmllite.lib cpxml-static.lib $(NOINHERIT)"
LinkIncremental="2"
AdditionalLibraryDirectories="$(SolutionDir)bin"
GenerateDebugInformation="true"
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|Win32"
OutputDirectory="$(SolutionDir)bin"
IntermediateDirectory="$(SolutionDir)output/$(ConfigurationName)/$(ProjectName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(SolutionDir)include&quot;;&quot;$(SolutionDir)3dparty/utf8cpp/include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib xmllite.lib cpxml-static.lib $(NOINHERIT)"
LinkIncremental="1"
AdditionalLibraryDirectories="$(SolutionDir)bin"
GenerateDebugInformation="true"
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>
<File
RelativePath=".\odf_open_1.cpp"
>
</File>
<File
RelativePath=".\stdafx.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
// stdafx.cpp : source file that includes just the standard includes
// xmlread.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
// stdafx.cpp : source file that includes just the standard includes
// xmlread.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
// xmlread.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cpdoccore/xml/sax.h>
#include <cpdoccore/xml/attributes.h>
#include <cpdoccore/xml/serialize_attributes.h>
#include <cpdoccore/CPSharedPtr.h>
#include <iostream>
#include <sstream>
#include <fstream>
std::string wchar_to_ansi(const std::wstring & _String)
{
::setlocale(LC_ALL, "");
size_t size = wcstombs(NULL, _String.c_str(), 0);
std::string res;
res.resize(size);
size = wcstombs(&res[0], _String.c_str(), res.length());
return res;
}
using namespace cpdoccore;
void skip_attributes(xml::sax_ptr & reader)
{
reader->moveToAttrFirst();
while (reader->moveToAttrNext());
}
void print_attributes(xml::sax_ptr & reader)
{
if (reader->moveToAttrFirst())
{
for(;;)
{
if (!reader->attrDefault())
{
const std::string prefix = wchar_to_ansi(reader->namespacePrefix());
const std::string name = wchar_to_ansi(reader->nodeLocalName());
const std::string value = wchar_to_ansi(reader->value());
std::cout << "attr: " << prefix << (prefix.size() ? ":" : "") << name << "=" << value << "\n";
}
if (!reader->moveToAttrNext())
break;
}
}
}
void parse_attributes(xml::sax_ptr & reader)
{
xml::attributes_wc_ptr attrb = xml::read_attributes( reader.get() );
::std::wostringstream strm;
xml::serialize_attributes(strm, attrb.get() );
std::cout << "attr: [" << wchar_to_ansi(strm.str()) << "]\n";
}
int TestRead(xml::sax_ptr reader)
{
try
{
xml::NodeType nodeType;
while ( (nodeType = reader->next()) != xml::typeEOF )
{
switch(nodeType)
{
case xml::typeXmlDeclaration:
parse_attributes(reader);
break;
case xml::typeElement:
{
const std::string prefix = wchar_to_ansi(reader->namespacePrefix());
std::cout << "element: [" << prefix << (prefix.size() ? ":" : "") << wchar_to_ansi(reader->nodeLocalName()) << "]\n";
}
parse_attributes(reader);
break;
case xml::typeEndElement:
{
const std::string prefix = wchar_to_ansi(reader->namespacePrefix());
std::cout << "end element: [" << prefix << (prefix.size() ? ":" : "") << ":" << wchar_to_ansi(reader->nodeLocalName()) << "]\n";
}
break;
case xml::typeText:
case xml::typeWhitespace:
std::cout << "text: [" << wchar_to_ansi(reader->value()) << "]\n";
break;
case xml::typeCDATA:
std::cout << "CDATA: [" << wchar_to_ansi(reader->value()) << "]\n";
break;
case xml::typeProcessingInstruction:
std::cout << "instruction: [" << wchar_to_ansi(reader->nodeLocalName()) << "] - [" << wchar_to_ansi(reader->value()) << "]\n";
break;
case xml::typeComment:
std::cout << "comment: [" << wchar_to_ansi(reader->value()) << "]\n";
case xml::typeDocumentType:
break;
}
}
}
catch( xml::sax::error & er)
{
std::cerr << "error " << er.code() << "\n";
}
catch(...)
{
std::cerr << "error " << "unexpected" << "\n";
}
return 0;
}
int TestReadFromFile(int argc, _TCHAR* argv[])
{
if (argc < 2)
{
::std::cerr << "Usage: xmlread.exe [InputXml]";
return -1;
}
try
{
xml::sax_ptr reader = xml::create_sax(argv[1]);
return TestRead(reader);
}
catch( xml::sax::error & er)
{
std::cerr << "error " << er.code() << "\n";
}
catch(...)
{
std::cerr << "error " << "unexpected" << "\n";
}
return 0;
}
int TestReadFromStream(int argc, _TCHAR* argv[])
{
if (argc < 2)
{
::std::cerr << "Usage: xmlread.exe [InputXml]";
return -1;
}
std::ifstream stream(argv[1]);
try
{
xml::sax_ptr reader = xml::create_sax(stream);
return TestRead(reader);
}
catch( xml::sax::error & er)
{
std::cerr << "error " << er.code() << "\n";
}
catch(...)
{
std::cerr << "error " << "unexpected" << "\n";
}
return 0;
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
TestReadFromStream(argc, argv);
char ch;
std::cin >> ch;
return 0;
}
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="xmlread"
ProjectGUID="{D33E0EA2-BA9B-4674-A904-EF93CE2DD2B7}"
RootNamespace="xmlread"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)bin/Debug"
IntermediateDirectory="$(SolutionDir)output/$(ConfigurationName)/$(ProjectName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="$(SolutionDir)include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib xmllite.lib cpxml-static.lib $(NOINHERIT)"
LinkIncremental="2"
AdditionalLibraryDirectories="$(SolutionDir)bin"
GenerateDebugInformation="true"
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|Win32"
OutputDirectory="$(SolutionDir)bin/Release"
IntermediateDirectory="$(SolutionDir)output/$(ConfigurationName)/$(ProjectName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="$(SolutionDir)include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="kernel32.lib xmllite.lib cpxml-static.lib $(NOINHERIT)"
LinkIncremental="1"
AdditionalLibraryDirectories="$(SolutionDir)bin"
GenerateDebugInformation="true"
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>
<File
RelativePath=".\stdafx.h"
>
</File>
<File
RelativePath=".\xmlread.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment