Commit 73f5c565 authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

mail merge. начало

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62615 954022d7-b5bf-4e40-9824-e11837661b57
parent 3c30871f
......@@ -93,6 +93,10 @@ namespace NSDoctRenderer
m_strDstFilePath = L"";
m_nCountChangesItems = -1;
m_strMailMergeDatabasePath = L"";
m_nMailMergeIndexStart = -1;
m_nMailMergeIndexEnd = -1;
}
CExecuteParams::~CExecuteParams()
{
......@@ -133,6 +137,14 @@ namespace NSDoctRenderer
}
}
XmlUtils::CXmlNode oNodeMailMerge;
if (oNode.GetNode(L"MailMergeData", oNodeMailMerge))
{
m_strMailMergeDatabasePath = string2std_string( oNodeMailMerge.ReadValueString(L"DatabasePath") );
m_nMailMergeIndexStart = oNodeMailMerge.ReadAttributeInt(L"Start", -1);
m_nMailMergeIndexEnd = oNodeMailMerge.ReadAttributeInt(L"End", -1);
}
return true;
}
}
......@@ -224,6 +236,196 @@ namespace NSDoctRenderer
return sReturn;
}
///
/// \brief Save File method
///
static bool Doct_renderer_SaveFile(CExecuteParams* pParams,
CNativeControl* pNative,
v8::Isolate* isolate,
v8::Local<v8::Object>& global_js,
v8::Handle<v8::Value>* args,
v8::TryCatch& try_catch,
std::wstring& strError)
{
bool bIsBreak = false;
switch (pParams->m_eDstFormat)
{
case DoctRendererFormat::DOCT:
case DoctRendererFormat::PPTT:
case DoctRendererFormat::XLST:
{
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileData"));
if (js_func_get_file_s->IsFunction())
{
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"save_code", strCode)
_LOGGING_ERROR_(L"save", strException)
strError = L"code=\"save\"";
bIsBreak = true;
}
else
{
v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2);
BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data();
NSFile::CFileBinary oFile;
if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
{
oFile.WriteFile((BYTE*)pNative->m_sHeader.c_str(), (DWORD)pNative->m_sHeader.length());
char* pDst64 = NULL;
int nDstLen = 0;
NSFile::CBase64Converter::Encode(pData, pNative->m_nSaveBinaryLen, pDst64, nDstLen, NSBase64::B64_BASE64_FLAG_NOCRLF);
oFile.WriteFile((BYTE*)pDst64, (DWORD)nDstLen);
RELEASEARRAYOBJECTS(pDst64);
oFile.CloseFile();
}
}
}
break;
}
case DoctRendererFormat::HTML:
{
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileDataHtml"));
if (js_func_get_file_s->IsFunction())
{
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"save_code", strCode)
_LOGGING_ERROR_(L"save", strException)
strError = L"code=\"save\"";
bIsBreak = true;
}
else
{
std::string sHTML_Utf8 = to_cstringA(js_result2);
NSFile::CFileBinary oFile;
if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
{
oFile.WriteFile((BYTE*)sHTML_Utf8.c_str(), (DWORD)sHTML_Utf8.length());
oFile.CloseFile();
}
}
}
break;
}
case DoctRendererFormat::PDF:
{
v8::Handle<v8::Value> js_func_calculate = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeCalculateFile"));
v8::Handle<v8::Value> js_func_pages_count = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeCountPages"));
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeFileDataPDF"));
// CALCULATE
if (js_func_calculate->IsFunction())
{
v8::Handle<v8::Function> func_calculate = v8::Handle<v8::Function>::Cast(js_func_calculate);
func_calculate->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"calculate_code", strCode)
_LOGGING_ERROR_(L"calculate", strException)
strError = L"code=\"calculate\"";
bIsBreak = true;
}
}
LONG lPagesCount = 0;
// PAGESCOUNT
if (!bIsBreak)
{
if (js_func_pages_count->IsFunction())
{
v8::Handle<v8::Function> func_pages_count = v8::Handle<v8::Function>::Cast(js_func_pages_count);
v8::Local<v8::Value> js_result1 = func_pages_count->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"calculate_code", strCode)
_LOGGING_ERROR_(L"calculate", strException)
strError = L"code=\"calculate\"";
bIsBreak = true;
}
else
{
v8::Local<v8::Int32> intValue = js_result1->ToInt32();
lPagesCount = (LONG)intValue->Value();
}
}
}
// RENDER
if (!bIsBreak)
{
if (js_func_get_file_s->IsFunction())
{
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"save_code", strCode)
_LOGGING_ERROR_(L"save", strException)
strError = L"code=\"save\"";
bIsBreak = true;
}
else
{
v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2);
BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data();
NSFile::CFileBinary oFile;
if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
{
oFile.WriteFile(pData, (DWORD)pNative->m_nSaveBinaryLen);
oFile.CloseFile();
}
}
}
}
break;
}
default:
break;
}
return bIsBreak;
}
///
bool CDoctrenderer::Execute(const std::wstring& strXml, std::wstring& strError)
{
strError = L"";
......@@ -522,6 +724,9 @@ namespace NSDoctRenderer
// SAVE
if (!bIsBreak)
{
#if 1
bIsBreak = NSDoctRenderer::Doct_renderer_SaveFile(&m_oParams, pNative, isolate, global_js, args, try_catch, strError);
#else
switch (m_oParams.m_eDstFormat)
{
case DoctRendererFormat::DOCT:
......@@ -568,13 +773,141 @@ namespace NSDoctRenderer
}
break;
}
case DoctRendererFormat::HTML:
{
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileDataHtml"));
if (js_func_get_file_s->IsFunction())
{
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"save_code", strCode)
_LOGGING_ERROR_(L"save", strException)
strError = L"code=\"save\"";
bIsBreak = true;
}
else
{
std::string sHTML_Utf8 = to_cstringA(js_result2);
NSFile::CFileBinary oFile;
if (true == oFile.CreateFileW(m_oParams.m_strDstFilePath))
{
oFile.WriteFile((BYTE*)sHTML_Utf8.c_str(), (DWORD)sHTML_Utf8.length());
oFile.CloseFile();
}
}
}
break;
}
case DoctRendererFormat::PDF:
{
// TODO: !!!
v8::Handle<v8::Value> js_func_calculate = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeCalculateFile"));
v8::Handle<v8::Value> js_func_pages_count = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeCountPages"));
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeFileDataPDF"));
// CALCULATE
if (js_func_calculate->IsFunction())
{
v8::Handle<v8::Function> func_calculate = v8::Handle<v8::Function>::Cast(js_func_calculate);
func_calculate->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"calculate_code", strCode)
_LOGGING_ERROR_(L"calculate", strException)
strError = L"code=\"calculate\"";
bIsBreak = true;
}
}
LONG lPagesCount = 0;
// PAGESCOUNT
if (!bIsBreak)
{
if (js_func_pages_count->IsFunction())
{
v8::Handle<v8::Function> func_pages_count = v8::Handle<v8::Function>::Cast(js_func_pages_count);
v8::Local<v8::Value> js_result1 = func_pages_count->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"calculate_code", strCode)
_LOGGING_ERROR_(L"calculate", strException)
strError = L"code=\"calculate\"";
bIsBreak = true;
}
else
{
v8::Local<v8::Int32> intValue = js_result1->ToInt32();
lPagesCount = (LONG)intValue->Value();
}
}
}
// RENDER
if (!bIsBreak)
{
if (js_func_get_file_s->IsFunction())
{
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"save_code", strCode)
_LOGGING_ERROR_(L"save", strException)
strError = L"code=\"save\"";
bIsBreak = true;
}
else
{
v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2);
BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data();
NSFile::CFileBinary oFile;
if (true == oFile.CreateFileW(m_oParams.m_strDstFilePath))
{
oFile.WriteFile((BYTE*)pNative->m_sHeader.c_str(), (DWORD)pNative->m_sHeader.length());
char* pDst64 = NULL;
int nDstLen = 0;
NSFile::CBase64Converter::Encode(pData, pNative->m_nSaveBinaryLen, pDst64, nDstLen, NSBase64::B64_BASE64_FLAG_NOCRLF);
oFile.WriteFile((BYTE*)pDst64, (DWORD)nDstLen);
RELEASEARRAYOBJECTS(pDst64);
oFile.CloseFile();
}
}
}
}
break;
}
default:
break;
}
#endif
}
}
......
......@@ -17,6 +17,7 @@ namespace NSDoctRenderer
XLST = 1,
PPTT = 2,
PDF = 3,
HTML = 4,
INVALID = 255
};
......@@ -38,6 +39,10 @@ namespace NSDoctRenderer
CArray<std::wstring> m_arChanges;
int m_nCountChangesItems;
std::wstring m_strMailMergeDatabasePath;
int m_nMailMergeIndexStart;
int m_nMailMergeIndexEnd;
public:
CExecuteParams();
~CExecuteParams();
......
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