/* * (c) Copyright Ascensio System SIA 2010-2023 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation. In accordance with * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect * that Ascensio System SIA expressly excludes the warranty of non-infringement * of any third-party rights. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish * street, Riga, Latvia, EU, LV-1050. * * The interactive user interfaces in modified source and object code versions * of the Program must display Appropriate Legal Notices, as required under * Section 5 of the GNU AGPL version 3. * * Pursuant to Section 7(b) of the License you must retain the original Product * logo when distributing the program. Pursuant to Section 7(e) we decline to * grant you any rights under trademark law for use of our trademarks. * * All the Product's GUI elements, including illustrations and icon sets, as * well as technical writing content are licensed under the terms of the * Creative Commons Attribution-ShareAlike 4.0 International. See the License * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ #include "OOXCommentsWriter.h" OOXCommentsWriter::OOXCommentsWriter( OOXWriter& oWriter, RtfDocument& oDocument ) : m_oWriter(oWriter), m_oDocument(oDocument) { m_oRelsWriter = OOXRelsWriterPtr( new OOXRelsWriter( _T("comments.xml"), oDocument ) ); oWriter.m_oCustomRelsWriter.push_back( m_oRelsWriter ); } void OOXCommentsWriter::SetCommentEnd(const std::wstring & ref) //for author { m_sCurrent_ref = ref; } void OOXCommentsWriter::AddComment( const std::wstring & ref, int nID) { _comment comment(nID); m_mapComments.insert(std::make_pair(ref, comment)); } void OOXCommentsWriter::AddCommentID( const std::wstring & id) { std::map::iterator pFind = m_mapComments.find(m_sCurrent_ref); if (pFind != m_mapComments.end()) { pFind->second.authorId = id; } } void OOXCommentsWriter::AddCommentAuthor( const std::wstring & author) { std::map::iterator pFind = m_mapComments.find(m_sCurrent_ref); if (pFind != m_mapComments.end()) { pFind->second.author = author; } } void OOXCommentsWriter::AddCommentContent( const std::wstring & ref, const std::wstring & paraId, const std::wstring & content) { std::map::iterator pFind = m_mapComments.find(ref); if (pFind != m_mapComments.end()) { pFind->second.content = content; pFind->second.paraId = paraId; m_mapCommentsParent.insert(std::make_pair(pFind->second.nID, paraId)); } } void OOXCommentsWriter::AddCommentParent( const std::wstring & ref, const std::wstring & parent) { std::map::iterator pFind = m_mapComments.find(ref); if (pFind != m_mapComments.end()) { pFind->second.nParentID = boost::lexical_cast(parent); } } void OOXCommentsWriter::AddCommentDate( const std::wstring & ref, const std::wstring & date) { std::map::iterator pFind = m_mapComments.find(ref); if (pFind != m_mapComments.end()) { pFind->second.date = date; } } bool OOXCommentsWriter::Save( std::wstring sFolder ) { if( m_mapComments.empty() ) return false; NSFile::CFileBinary file; if (false == file.CreateFile(sFolder + FILE_SEPARATOR_STR + _T("comments.xml"))) return false; m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"), _T("comments.xml") ); m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"), _T("/word/comments.xml") ); std::wstring sXml = CreateXml(); std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml); file.WriteFile((void*)sXmlUTF.c_str(), (DWORD)sXmlUTF.length()); file.CloseFile(); //------------------------------------------------------------------------------------------------------------------------- if (false == file.CreateFile(sFolder + FILE_SEPARATOR_STR + L"commentsExtended.xml")) return false; m_oWriter.m_oDocRels.AddRelationship( L"http://schemas.microsoft.com/office/2011/relationships/commentsExtended", L"commentsExtended.xml" ); m_oWriter.m_oContentTypes.AddContent( L"application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml", L"/word/commentsExtended.xml" ); sXml = CreateXmlExtended(); sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml); file.WriteFile((void*)sXmlUTF.c_str(), (DWORD)sXmlUTF.length()); file.CloseFile(); return true; } std::wstring OOXCommentsWriter::CreateXml() { std::wstring sResult = L"\n"; sResult += L""; for (std::map::iterator it = m_mapComments.begin(); it != m_mapComments.end(); ++it) { sResult += L"second.nID) + L"\" w:author=\"" + XmlUtils::EncodeXmlString(it->second.author) + L"\" w:date=\"" + it->second.date + L"\" w:initials=\"" + it->second.authorId + L"\">"; sResult += it->second.content; sResult += L""; //-------------------------------------------------------- m_sCommentsExtended += L"second.paraId + L"\""; if (it->second.nParentID != 0) { it->second.nParentID = it->second.nID + it->second.nParentID; std::map::iterator pFind = m_mapCommentsParent.find(it->second.nParentID); if (pFind != m_mapCommentsParent.end()) { m_sCommentsExtended += L" w15:paraIdParent=\"" + pFind->second + L"\""; } } m_sCommentsExtended += L" w15:done=\"0\"/>"; } sResult += L""; return sResult; } std::wstring OOXCommentsWriter::CreateXmlExtended() { std::wstring sResult; sResult += L"\n"; sResult += L""; sResult += m_sCommentsExtended; sResult += L""; return sResult; }