diff --git a/DesktopEditor/doctrenderer/doctrenderer.cpp b/DesktopEditor/doctrenderer/doctrenderer.cpp index 0c4ad57eb9..14ee1b3b9c 100644 --- a/DesktopEditor/doctrenderer/doctrenderer.cpp +++ b/DesktopEditor/doctrenderer/doctrenderer.cpp @@ -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& global_js, + v8::Handle* 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 js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileData")); + if (js_func_get_file_s->IsFunction()) + { + v8::Handle func_get_file_s = v8::Handle::Cast(js_func_get_file_s); + v8::Local 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 pArray = v8::Local::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 js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileDataHtml")); + if (js_func_get_file_s->IsFunction()) + { + v8::Handle func_get_file_s = v8::Handle::Cast(js_func_get_file_s); + v8::Local 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 js_func_calculate = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeCalculateFile")); + v8::Handle js_func_pages_count = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeCountPages")); + v8::Handle js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeFileDataPDF")); + + // CALCULATE + if (js_func_calculate->IsFunction()) + { + v8::Handle func_calculate = v8::Handle::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 func_pages_count = v8::Handle::Cast(js_func_pages_count); + v8::Local 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 intValue = js_result1->ToInt32(); + lPagesCount = (LONG)intValue->Value(); + } + } + } + + // RENDER + if (!bIsBreak) + { + if (js_func_get_file_s->IsFunction()) + { + v8::Handle func_get_file_s = v8::Handle::Cast(js_func_get_file_s); + v8::Local 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 pArray = v8::Local::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 js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileDataHtml")); + if (js_func_get_file_s->IsFunction()) + { + v8::Handle func_get_file_s = v8::Handle::Cast(js_func_get_file_s); + v8::Local 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 js_func_calculate = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeCalculateFile")); + v8::Handle js_func_pages_count = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeCountPages")); + v8::Handle js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeFileDataPDF")); + + // CALCULATE + if (js_func_calculate->IsFunction()) + { + v8::Handle func_calculate = v8::Handle::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 func_pages_count = v8::Handle::Cast(js_func_pages_count); + v8::Local 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 intValue = js_result1->ToInt32(); + lPagesCount = (LONG)intValue->Value(); + } + } + } + + // RENDER + if (!bIsBreak) + { + if (js_func_get_file_s->IsFunction()) + { + v8::Handle func_get_file_s = v8::Handle::Cast(js_func_get_file_s); + v8::Local 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 pArray = v8::Local::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 } } diff --git a/DesktopEditor/doctrenderer/doctrenderer.h b/DesktopEditor/doctrenderer/doctrenderer.h index 152616f189..fb6a9c806f 100644 --- a/DesktopEditor/doctrenderer/doctrenderer.h +++ b/DesktopEditor/doctrenderer/doctrenderer.h @@ -17,6 +17,7 @@ namespace NSDoctRenderer XLST = 1, PPTT = 2, PDF = 3, + HTML = 4, INVALID = 255 }; @@ -38,6 +39,10 @@ namespace NSDoctRenderer CArray m_arChanges; int m_nCountChangesItems; + std::wstring m_strMailMergeDatabasePath; + int m_nMailMergeIndexStart; + int m_nMailMergeIndexEnd; + public: CExecuteParams(); ~CExecuteParams();