tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / oox / source / core / relationshandler.cxx
blob5fb39fd4e1406db1bc589c15da8abe46f3e9deaf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <string_view>
24 #include <oox/core/relationshandler.hxx>
26 #include <sal/log.hxx>
27 #include <oox/helper/attributelist.hxx>
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
31 namespace oox::core {
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::xml::sax;
36 namespace {
38 /* Build path to relations file from passed fragment path, e.g.:
39 'path/path/file.xml' -> 'path/path/_rels/file.xml.rels'
40 'file.xml' -> '_rels/file.xml.rels'
41 '' -> '_rels/.rels'
43 OUString lclGetRelationsPath( std::u16string_view rFragmentPath )
45 size_t nPathLen = rFragmentPath.rfind( '/' );
46 if (nPathLen == std::u16string_view::npos)
47 nPathLen = 0;
48 else
49 ++nPathLen;
50 return OUString::Concat(rFragmentPath.substr(0, nPathLen)) + // file path including slash
51 "_rels/" + // additional '_rels/' path
52 rFragmentPath.substr(nPathLen) + // file name after path
53 ".rels"; // '.rels' suffix
56 } // namespace
58 RelationsFragment::RelationsFragment( XmlFilterBase& rFilter, const RelationsRef& xRelations ) :
59 FragmentHandler( rFilter, lclGetRelationsPath( xRelations->getFragmentPath() ), xRelations ),
60 mxRelations( xRelations )
64 Reference< XFastContextHandler > RelationsFragment::createFastChildContext(
65 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
67 Reference< XFastContextHandler > xRet;
68 AttributeList aAttribs( rxAttribs );
69 switch( nElement )
71 case PR_TOKEN( Relationship ):
73 Relation aRelation;
74 aRelation.maId = aAttribs.getStringDefaulted( XML_Id);
75 aRelation.maType = aAttribs.getStringDefaulted( XML_Type);
76 aRelation.maTarget = aAttribs.getStringDefaulted( XML_Target);
77 if( !aRelation.maId.isEmpty() && !aRelation.maType.isEmpty() && !aRelation.maTarget.isEmpty() )
79 sal_Int32 nTargetMode = aAttribs.getToken( XML_TargetMode, XML_Internal );
80 SAL_WARN_IF( (nTargetMode != XML_Internal) && (nTargetMode != XML_External), "oox",
81 "RelationsFragment::createFastChildContext - unexpected target mode, assuming external" );
82 aRelation.mbExternal = nTargetMode != XML_Internal;
84 SAL_WARN_IF( mxRelations->count( aRelation.maId ) != 0, "oox",
85 "RelationsFragment::createFastChildContext - relation identifier exists already" );
86 mxRelations->emplace( aRelation.maId, aRelation );
89 break;
90 case PR_TOKEN( Relationships ):
91 xRet = getFastContextHandler();
92 break;
94 return xRet;
97 } // namespace oox::core
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */