mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-11 06:22:44 +08:00
Co-authored-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com> Co-committed-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
233 lines
7.0 KiB
C++
233 lines
7.0 KiB
C++
/*
|
|
* Copyright (C) Ascensio System SIA, 2009-2026
|
|
*
|
|
* 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, together with the
|
|
* additional terms provided in the LICENSE file.
|
|
*
|
|
* 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: https://www.gnu.org/licenses/agpl-3.0.html
|
|
*
|
|
* You can contact Ascensio System SIA by email at info@onlyoffice.com
|
|
* or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga,
|
|
* LV-1050, Latvia, European Union.
|
|
*
|
|
* The interactive user interfaces in modified versions of the Program
|
|
* are required to display Appropriate Legal Notices in accordance with
|
|
* Section 5 of the GNU AGPL version 3.
|
|
*
|
|
* No trademark rights are granted under this License.
|
|
*
|
|
* All non-code elements of the Product, including illustrations,
|
|
* icon sets, and technical writing content, are licensed under the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License:
|
|
* https://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
*
|
|
* This license applies only to such non-code elements and does not
|
|
* modify or replace the licensing terms applicable to the Program's
|
|
* source code, which remains licensed under the GNU Affero General
|
|
* Public License v3.
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
#include "external_items.h"
|
|
|
|
#include "../../../OOXML/Base/Unit.h"
|
|
#include "../../Common/Utils/simple_xml_writer.h"
|
|
|
|
#include "oox_rels.h"
|
|
#include "mediaitems_utils.h"
|
|
|
|
#include "../../../OOXML/Base/Base.h"
|
|
#include "../../../OOXML/Base/Unit.h"
|
|
|
|
#include "../../../DesktopEditor/common/Directory.h"
|
|
|
|
namespace oox {
|
|
|
|
|
|
external_items::item::item( std::wstring const & _uri, Type _type, bool _mediaInternal, int _id, std::wstring const & _rId )
|
|
: uri(_uri), type(_type), mediaInternal(_mediaInternal), id(_id), rId(_rId)
|
|
{
|
|
}
|
|
|
|
std::wstring static get_default_file_name(external_items::Type type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case external_items::typeImage:
|
|
return L"image";
|
|
case external_items::typeChart:
|
|
return L"chart";
|
|
case external_items::typeMedia:
|
|
return L"media";
|
|
case external_items::typeActiveX:
|
|
return L"activeX";
|
|
case external_items::typeControlProps:
|
|
return L"ctrlProp";
|
|
default:
|
|
return L"";
|
|
}
|
|
}
|
|
|
|
std::wstring external_items::add_image(const std::wstring & image, int bin_id)
|
|
{
|
|
const bool isMediaInternal = true;
|
|
|
|
std::wstring rId = std::wstring(L"picId") + std::to_wstring(count_image + 1);
|
|
count_image++;
|
|
|
|
items_.push_back( item(image, typeImage, isMediaInternal, bin_id, rId) );
|
|
|
|
return rId;
|
|
}
|
|
std::wstring external_items::add_chart(std::wstring & oox_target)
|
|
{
|
|
const bool isMediaInternal = true;
|
|
|
|
count_charts++;
|
|
|
|
std::wstring rId = std::wstring(L"chartId") + std::to_wstring(count_charts);
|
|
oox_target = std::wstring(L"charts/chart") + std::to_wstring(count_charts) + L".xml";
|
|
|
|
items_.push_back( item(oox_target, typeChart, isMediaInternal, -1, rId) );
|
|
|
|
return rId;
|
|
}
|
|
std::wstring external_items::add_control_activeX(std::wstring & oox_target_bin)
|
|
{
|
|
const bool isMediaInternal = true;
|
|
|
|
count_activeX++;
|
|
|
|
std::wstring rId = std::wstring(L"ocxId") + std::to_wstring(count_activeX);
|
|
|
|
oox_target_bin = std::wstring(L"activeX") + std::to_wstring(count_activeX) + L".bin";
|
|
|
|
items_.push_back( item(oox_target_bin, typeActiveX, isMediaInternal, -1, rId) );
|
|
return rId;
|
|
}
|
|
std::wstring external_items::add_control_props(std::wstring & oox_target)
|
|
{
|
|
const bool isMediaInternal = true;
|
|
|
|
count_controls++;
|
|
|
|
std::wstring rId = std::wstring(L"ctrlId") + std::to_wstring(count_controls);
|
|
|
|
oox_target = std::wstring(L"ctrlProp") + std::to_wstring(count_controls) + L".xml";
|
|
|
|
items_.push_back( item(oox_target, typeControlProps, isMediaInternal, -1, rId) );
|
|
return rId;
|
|
}
|
|
std::wstring external_items::add_embedding(std::wstring & oox_target, const std::wstring & info)
|
|
{
|
|
const bool isMediaInternal = true;
|
|
|
|
count_embeddings++;
|
|
|
|
std::wstring rId = std::wstring(L"objId") + std::to_wstring(count_embeddings);
|
|
|
|
std::wstring lowerInfo = XmlUtils::GetLower(info);
|
|
|
|
std::wstring extension;
|
|
|
|
if ( false == oox_target.empty()) extension = oox_target;
|
|
else if (std::wstring::npos != lowerInfo.find(L"excel")) extension = L".xls";
|
|
else if (std::wstring::npos != lowerInfo.find(L"word")) extension = L".doc";
|
|
else extension = L".bin";
|
|
|
|
oox_target = std::wstring(L"oleObject") + std::to_wstring(count_embeddings) + extension;
|
|
|
|
items_.push_back( item(oox_target, typeOleObject, isMediaInternal, -1, rId) );
|
|
return rId;
|
|
}
|
|
std::wstring external_items::find_image(int _id, std::wstring & oox_target, bool & isInternal)
|
|
{
|
|
for (size_t i=0 ; i <items_.size(); i ++)
|
|
{
|
|
if (items_[i].type == typeImage && items_[i].id == _id)
|
|
{
|
|
oox_target = items_[i].uri;
|
|
isInternal = items_[i].mediaInternal;
|
|
return items_[i].rId;
|
|
}
|
|
}
|
|
return L"";
|
|
}
|
|
std::wstring external_items::find_image(const std::wstring & oox_target, bool & isInternal)
|
|
{
|
|
for (size_t i = 0; i <items_.size(); i ++)
|
|
{
|
|
if (items_[i].type == typeImage && items_[i].uri == oox_target)
|
|
{
|
|
isInternal = items_[i].mediaInternal;
|
|
return items_[i].rId;
|
|
}
|
|
}
|
|
return L"";
|
|
}
|
|
void external_items::dump_rels(rels & Rels)
|
|
{
|
|
for (size_t i = 0 ; i <items_.size(); i ++)
|
|
{
|
|
Rels.add( relationship(
|
|
items_[i].rId,
|
|
utils::media::get_rel_type(items_[i].type),
|
|
items_[i].uri,
|
|
items_[i].mediaInternal ? L"" : L"External" )
|
|
);
|
|
}
|
|
}
|
|
|
|
std::wstring external_items::media_path()
|
|
{
|
|
return media_path_;
|
|
}
|
|
void external_items::create_media_path(const std::wstring & out_path)
|
|
{
|
|
if (!media_path_.empty()) return;
|
|
|
|
std::wstring xl_path = out_path + FILE_SEPARATOR_STR + L"xl";
|
|
NSDirectory::CreateDirectory(xl_path.c_str());
|
|
|
|
NSDirectory::CreateDirectory((xl_path + FILE_SEPARATOR_STR + L"media").c_str());
|
|
|
|
media_path_ = xl_path + FILE_SEPARATOR_STR + L"media" + FILE_SEPARATOR_STR;
|
|
}
|
|
std::wstring external_items::activeX_path()
|
|
{
|
|
return activeX_path_;
|
|
}
|
|
void external_items::create_activeX_path(const std::wstring & out_path)
|
|
{
|
|
if (!activeX_path_.empty()) return;
|
|
|
|
std::wstring xl_path = out_path + FILE_SEPARATOR_STR + L"xl";
|
|
NSDirectory::CreateDirectory(xl_path.c_str());
|
|
|
|
NSDirectory::CreateDirectory((xl_path + FILE_SEPARATOR_STR + L"activeX").c_str());
|
|
|
|
activeX_path_ = xl_path + FILE_SEPARATOR_STR + L"activeX" + FILE_SEPARATOR_STR;
|
|
}
|
|
void external_items::create_embeddings_path(const std::wstring & out_path)
|
|
{
|
|
if (!embeddings_path_.empty()) return;
|
|
|
|
std::wstring xl_path = out_path + FILE_SEPARATOR_STR + L"xl";
|
|
NSDirectory::CreateDirectory(xl_path.c_str());
|
|
|
|
NSDirectory::CreateDirectory((xl_path + FILE_SEPARATOR_STR + L"embeddings").c_str());
|
|
|
|
embeddings_path_ = xl_path + FILE_SEPARATOR_STR + L"embeddings" + FILE_SEPARATOR_STR;
|
|
}
|
|
std::wstring external_items::embeddings_path()
|
|
{
|
|
return embeddings_path_;
|
|
}
|
|
|
|
}
|