diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /include/oox/core/relations.hxx | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/oox/core/relations.hxx')
-rw-r--r-- | include/oox/core/relations.hxx | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/include/oox/core/relations.hxx b/include/oox/core/relations.hxx new file mode 100644 index 000000000..d556d9c8c --- /dev/null +++ b/include/oox/core/relations.hxx @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_OOX_CORE_RELATIONS_HXX +#define INCLUDED_OOX_CORE_RELATIONS_HXX + +#include <cstddef> +#include <map> +#include <memory> + +#include <oox/dllapi.h> +#include <rtl/ustring.hxx> + +namespace oox { +namespace core { + + +/** Expands to an OUString containing an 'officeDocument' transitional relation type created + from the passed literal(!) ASCII(!) character array. */ +#define CREATE_OFFICEDOC_RELATION_TYPE( ascii ) \ + ( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/" ascii ) + +/** Expands to an OUString containing an 'officeDocument' strict relation type created + from the passed literal(!) ASCII(!) character array. */ +#define CREATE_OFFICEDOC_RELATION_TYPE_STRICT( ascii ) \ + ( "http://purl.oclc.org/ooxml/officeDocument/relationships/" ascii ) + +/** Expands to an OUString containing an MS Office specific relation type + created from the passed literal(!) ASCII(!) character array. */ +#define CREATE_MSOFFICE_RELATION_TYPE( ascii ) \ + ( "http://schemas.microsoft.com/office/2006/relationships/" ascii ) + +#define CREATE_XL_CONTENT_TYPE( ascii ) \ + ( "application/vnd.openxmlformats-officedocument.spreadsheetml." ascii "+xml" ) + +struct Relation +{ + OUString maId; + OUString maType; + OUString maTarget; + bool mbExternal; + + Relation() : mbExternal( false ) {} +}; + + +class Relations; +typedef std::shared_ptr< Relations > RelationsRef; + +class OOX_DLLPUBLIC Relations +{ +public: + explicit Relations( const OUString& rFragmentPath ); + + size_t size() const { return maMap.size(); } + size_t count( const OUString& rId ) const { return maMap.count( rId ); } + ::std::map< OUString, Relation >::const_iterator begin() const + { + return maMap.begin(); + } + ::std::map< OUString, Relation >::const_iterator end() const + { + return maMap.end(); + } + template<class... Args> + void emplace(Args&&... args) + { + maMap.emplace(std::forward<Args>(args)...); + } + + /** Returns the path of the fragment this relations collection is related to. */ + const OUString& getFragmentPath() const { return maFragmentPath; } + + /** Returns the relation with the passed relation identifier. */ + const Relation* getRelationFromRelId( const OUString& rId ) const; + /** Returns the first relation with the passed type. */ + const Relation* getRelationFromFirstType( const OUString& rType ) const; + /** Finds all relations associated with the passed type. */ + RelationsRef getRelationsFromTypeFromOfficeDoc( const OUString& rType ) const; + + /** Returns the external target of the relation with the passed relation identifier. */ + OUString getExternalTargetFromRelId( const OUString& rRelId ) const; + /** Returns the internal target of the relation with the passed relation identifier. */ + OUString getInternalTargetFromRelId( const OUString& rRelId ) const; + + /** Returns the full fragment path for the target of the passed relation. */ + OUString getFragmentPathFromRelation( const Relation& rRelation ) const; + /** Returns the full fragment path for the passed relation identifier. */ + OUString getFragmentPathFromRelId( const OUString& rRelId ) const; + /** Returns the full fragment path for the first relation of the passed type. */ + OUString getFragmentPathFromFirstType( const OUString& rType ) const; + OUString getFragmentPathFromFirstTypeFromOfficeDoc( const OUString& rType ) const; + +private: + ::std::map< OUString, Relation > maMap; + OUString maFragmentPath; +}; + + +} // namespace core +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |