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

HtmlFile New Interface

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63923 954022d7-b5bf-4e40-9824-e11837661b57
parent b20ce927
...@@ -131,6 +131,11 @@ namespace NSStringUtils ...@@ -131,6 +131,11 @@ namespace NSStringUtils
m_lSizeCur += 2; m_lSizeCur += 2;
} }
inline void WriteEncodeXmlString(const std::wstring& sString)
{
WriteEncodeXmlString(sString.c_str(), (int)sString.length());
}
inline void WriteEncodeXmlString(const wchar_t* pString, int nCount = -1) inline void WriteEncodeXmlString(const wchar_t* pString, int nCount = -1)
{ {
const wchar_t* pData = pString; const wchar_t* pData = pString;
......
...@@ -23,7 +23,41 @@ CHtmlFile::~CHtmlFile() ...@@ -23,7 +23,41 @@ CHtmlFile::~CHtmlFile()
} }
int CHtmlFile::Convert(const std::wstring& sXml, const std::wstring& sPathInternal) static std::wstring GetSdkPath()
{
std::wstring sProcess = NSFile::GetProcessDirectory() + L"/";
std::wstring sPathConfig = sProcess + L"DoctRenderer.config";
XmlUtils::CXmlNode oNode;
if (!oNode.FromXmlFile(sPathConfig))
return L"";
std::wstring sPath = oNode.ReadValueString(L"DoctSdk");
if (NSFile::CFileBinary::Exists(sPath))
return sPath;
return sProcess + sPath;
}
static std::wstring CorrectHtmlPath(const std::wstring& sPath)
{
std::wstring sReturn = sPath;
NSStringExt::Replace(sReturn, L"\\", L"/");
if (std::wstring::npos != sReturn.find(L"://"))
return sReturn;
if (sReturn.find(L"//") == 0)
return L"file:" + sReturn;
if (!sPath.empty())
{
wchar_t c = sPath.c_str()[0];
if (c == wchar_t('/'))
return L"file://" + sPath;
}
return L"file:///" + sPath;
}
int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstring& sDstfolder, const std::wstring& sPathInternal)
{ {
std::wstring sInternal = sPathInternal; std::wstring sInternal = sPathInternal;
if (sInternal.empty()) if (sInternal.empty())
...@@ -37,6 +71,36 @@ int CHtmlFile::Convert(const std::wstring& sXml, const std::wstring& sPathIntern ...@@ -37,6 +71,36 @@ int CHtmlFile::Convert(const std::wstring& sXml, const std::wstring& sPathIntern
int nReturnCode = 0; int nReturnCode = 0;
NSStringUtils::CStringBuilder oBuilder;
oBuilder.WriteString(L"<html>");
// sdk
oBuilder.WriteString(L"<sdk>");
oBuilder.WriteEncodeXmlString(CorrectHtmlPath(GetSdkPath()));
oBuilder.WriteString(L"</sdk>");
// destination
oBuilder.WriteString(L"<destination>");
oBuilder.WriteEncodeXmlString(sDstfolder);
if (!sDstfolder.empty())
{
wchar_t _c = sDstfolder.c_str()[sDstfolder.length() - 1];
if (_c != '\\' && _c != '/')
oBuilder.AddCharSafe('/');
}
oBuilder.WriteString(L"</destination>");
for (std::vector<std::wstring>::const_iterator iter = arFiles.begin(); iter != arFiles.end(); iter++)
{
oBuilder.WriteString(L"<file>");
oBuilder.WriteEncodeXmlString(CorrectHtmlPath(*iter));
oBuilder.WriteString(L"</file>");
}
oBuilder.WriteString(L"</html>");
#ifdef WIN32 #ifdef WIN32
STARTUPINFO sturtupinfo; STARTUPINFO sturtupinfo;
ZeroMemory(&sturtupinfo,sizeof(STARTUPINFO)); ZeroMemory(&sturtupinfo,sizeof(STARTUPINFO));
...@@ -45,12 +109,12 @@ int CHtmlFile::Convert(const std::wstring& sXml, const std::wstring& sPathIntern ...@@ -45,12 +109,12 @@ int CHtmlFile::Convert(const std::wstring& sXml, const std::wstring& sPathIntern
std::wstring sTempFileForParams = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"XML"); std::wstring sTempFileForParams = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"XML");
NSFile::CFileBinary oFile; NSFile::CFileBinary oFile;
oFile.CreateFileW(sTempFileForParams); oFile.CreateFileW(sTempFileForParams);
oFile.WriteStringUTF8(sXml, true); oFile.WriteStringUTF8(oBuilder.GetData(), true);
oFile.CloseFile(); oFile.CloseFile();
std::wstring sApp = L"HtmlFileInternal <html>" + sTempFileForParams; std::wstring sApp = L"HtmlFileInternal <html>" + sTempFileForParams;
wchar_t* pCommandLine = NULL; wchar_t* pCommandLine = NULL;
if (!sXml.empty()) if (true)
{ {
pCommandLine = new wchar_t[sApp.length() + 1]; pCommandLine = new wchar_t[sApp.length() + 1];
memcpy(pCommandLine, sApp.c_str(), sApp.length() * sizeof(wchar_t)); memcpy(pCommandLine, sApp.c_str(), sApp.length() * sizeof(wchar_t));
...@@ -294,7 +358,7 @@ static std::vector<std::wstring> ParseEpub(const std::wstring& sPackagePath, std ...@@ -294,7 +358,7 @@ static std::vector<std::wstring> ParseEpub(const std::wstring& sPackagePath, std
return arHtmls; return arHtmls;
} }
int CHtmlFile::ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, const std::wstring& sXmlPart, const std::wstring& sPathInternal) int CHtmlFile::ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, const std::wstring& sDstfolder, const std::wstring& sPathInternal)
{ {
std::wstring sFolderWithSlash = sFolder; std::wstring sFolderWithSlash = sFolder;
NSStringExt::Replace(sFolderWithSlash, L"\\", L"/"); NSStringExt::Replace(sFolderWithSlash, L"\\", L"/");
...@@ -348,20 +412,5 @@ int CHtmlFile::ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, ...@@ -348,20 +412,5 @@ int CHtmlFile::ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo,
if (arHtmls.size() == 0) if (arHtmls.size() == 0)
return 1; return 1;
NSStringUtils::CStringBuilder oBuilder; return this->Convert(arHtmls, sDstfolder, sPathInternal);
for (std::vector<std::wstring>::iterator iter = arHtmls.begin(); iter != arHtmls.end(); iter++)
{
oBuilder.WriteString(L"<file>", 6);
wchar_t c = iter->c_str()[0];
if (c == '/')
oBuilder.WriteString(L"file://", 7);
else
oBuilder.WriteString(L"file:///", 8);
oBuilder.WriteEncodeXmlString(iter->c_str(), iter->length());
oBuilder.WriteString(L"</file>", 7);
}
return this->Convert(L"<html>" + oBuilder.GetData() + sXmlPart + L"</html>", sPathInternal);
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define _HTMLFILE_HTMLFILE_H_ #define _HTMLFILE_HTMLFILE_H_
#include <string> #include <string>
#include <vector>
#ifndef HTMLFILE_USE_DYNAMIC_LIBRARY #ifndef HTMLFILE_USE_DYNAMIC_LIBRARY
#define HTMLFILE_DECL_EXPORT #define HTMLFILE_DECL_EXPORT
...@@ -19,30 +20,11 @@ public: ...@@ -19,30 +20,11 @@ public:
CHtmlFile(); CHtmlFile();
~CHtmlFile(); ~CHtmlFile();
///
/// \brief Convert
/// \param sXml -
/// <html>
/// <sdk>file:///D:/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Word/sdk-all.js</sdk>
/// <file>file:///C:/Users/oleg.korshul/Desktop/original_message%20(5).html</file>
/// <file>file://192.168.3.208/allusers/Files/HTML/AllHTML/cars.html</file>
/// <destination>D:/test/Document/</destination> (end /!!!)
/// </html>\
/// \param sPathInternal - path (subprocesspath = path + HtmlFileInternal.exe) ("" -> GetProcessDirectory()/HtmlFileInternal/HtmlFileInternal.exe) /// \param sPathInternal - path (subprocesspath = path + HtmlFileInternal.exe) ("" -> GetProcessDirectory()/HtmlFileInternal/HtmlFileInternal.exe)
/// \return 1 error, 0 - success /// \return 1 error, 0 - success
///
int Convert(const std::wstring& sXml, const std::wstring& sPathInternal = L""); int Convert(const std::vector<std::wstring>& arFiles, const std::wstring& sDstfolder, const std::wstring& sPathInternal = L"");
int ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, const std::wstring& sDstfolder, const std::wstring& sPathInternal = L"");
///
/// \brief ConvertEpub
/// \param sFolder - unzip folder (slash or without slash)
/// \param sMetaInfo - epub meta data
/// \param sXmlPart - <sdk>file:///D:/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Word/sdk-all.js</sdk><destination>D:/test/Document/</destination> (end /!!!)
/// \param sPathInternal - like Convert html
/// \return 1 error, 0 - success
///
int ConvertEpub(const std::wstring& sFolder, std::wstring& sMetaInfo, const std::wstring& sXmlPart, const std::wstring& sPathInternal = L"");
}; };
#endif // _HTMLFILE_HTMLFILE_H_ #endif // _HTMLFILE_HTMLFILE_H_
...@@ -3,58 +3,36 @@ ...@@ -3,58 +3,36 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if 0 #if 1
#ifdef WIN32 #ifdef WIN32
std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../Internal/windows/Release/"; std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../Internal/windows/Release/";
std::wstring sXml = L"\ std::vector<std::wstring> arFiles;
<html>\ arFiles.push_back(L"file:///C:/Users/oleg.korshul/Desktop/original_message%20(5).html");
<sdk>file:///D:/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Word/sdk-all.js</sdk>\ std::wstring sDstFolder = L"D:/test/Document";
<file>file:///C:/Users/oleg.korshul/Desktop/original_message%20(5).html</file>\
<destination>D:/test/Document/</destination>\
</html>\
";
#else #else
std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../Internal/linux/Release/"; std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../Internal/linux/Release/";
std::wstring sDstFolder = L"/home/oleg/activex/1/";
std::wstring sXml = L"\
<html>\
<sdk>file:///home/oleg/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Word/sdk-all.js</sdk>\
<file>file:///home/oleg/activex/test.html</file>\
<destination>/home/oleg/activex/1/</destination>\
</html>\
";
#endif #endif
CHtmlFile oFile; CHtmlFile oFile;
int nResult = oFile.Convert(sXml, sPath); int nResult = oFile.Convert(arFiles, sDstFolder, sPath);
nResult; nResult;
#else #else
#ifdef WIN32 #ifdef WIN32
std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../Internal/windows/Release/"; std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../Internal/windows/Release/";
std::wstring sDstFolder = L"D:/test/Document";
std::wstring sXml = L"\
<sdk>file:///D:/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Word/sdk-all.js</sdk>\
<destination>D:/test/Document/</destination>\
";
#else #else
std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../Internal/linux/Release/"; std::wstring sPath = NSFile::GetProcessDirectory() + L"/../../Internal/linux/Release/";
std::wstring sDstFolder = L"/home/oleg/activex/1/";
std::wstring sXml = L"\
<html>\
<sdk>file:///home/oleg/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb/Word/sdk-all.js</sdk>\
<file>file:///home/oleg/activex/test.html</file>\
<destination>/home/oleg/activex/1/</destination>\
</html>\
";
#endif #endif
CHtmlFile oFile; CHtmlFile oFile;
std::wstring sMetaInfo; std::wstring sMetaInfo;
int nResult = oFile.ConvertEpub(L"D:\\37898EB", sMetaInfo, sXml, sPath); int nResult = oFile.ConvertEpub(L"D:\\37898EB", sMetaInfo, sDstFolder, sPath);
nResult; nResult;
#endif #endif
......
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