Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/transform/TransformerBase.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#pragma once
21
22
#include <sal/config.h>
23
24
#include <vector>
25
#include <memory>
26
27
#include <com/sun/star/lang/XInitialization.hpp>
28
#include <com/sun/star/lang/XServiceInfo.hpp>
29
#include <com/sun/star/xml/sax/XAttributeList.hpp>
30
#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
31
#include <com/sun/star/xml/sax/XLocator.hpp>
32
#include <com/sun/star/beans/XPropertySet.hpp>
33
#include <com/sun/star/frame/XModel.hpp>
34
35
#include <cppuhelper/implbase.hxx>
36
#include <rtl/ref.hxx>
37
#include <xmloff/xmltoken.hxx>
38
#include <xmloff/namespacemap.hxx>
39
40
#include "TransformerActions.hxx"
41
#include "TransformerTokenMap.hxx"
42
43
namespace com::sun::star {
44
    namespace i18n { class XCharacterClassification; }
45
}
46
47
class XMLTransformerContext;
48
struct XMLTransformerActionInit;
49
class XMLMutableAttributeList;
50
51
const sal_uInt16 INVALID_ACTIONS = 0xffff;
52
53
class XMLTransformerBase : public cppu::WeakImplHelper<css::xml::sax::XExtendedDocumentHandler,
54
                                                       css::lang::XServiceInfo,
55
                                                       css::lang::XInitialization>
56
{
57
    friend class XMLTransformerContext;
58
59
    css::uno::Reference< css::xml::sax::XDocumentHandler >            m_xHandler;     // the handlers
60
    css::uno::Reference< css::beans::XPropertySet >                   m_xPropSet;
61
    css::uno::Reference< css::i18n::XCharacterClassification >        xCharClass;
62
63
    OUString m_aExtPathPrefix;
64
    OUString m_aClass;
65
66
    std::unique_ptr<SvXMLNamespaceMap> m_pNamespaceMap;
67
    SvXMLNamespaceMap           m_vReplaceNamespaceMap;
68
    std::vector<rtl::Reference<XMLTransformerContext>> m_vContexts;
69
    XMLTransformerActions       m_ElemActions;
70
    XMLTransformerTokenMap const m_TokenMap;
71
72
protected:
73
    css::uno::Reference< css::frame::XModel >     mxModel;
74
75
    // This method is called after the namespace map has been updated, but
76
    // before a context for the current element has been pushed.
77
    XMLTransformerContext *CreateContext( sal_uInt16 nPrefix,
78
                                      const OUString& rLocalName,
79
                                      const OUString& rQName );
80
81
public:
82
    XMLTransformerBase( XMLTransformerActionInit const *pInit,
83
                           ::xmloff::token::XMLTokenEnum const *pTKMapInit ) noexcept;
84
    virtual ~XMLTransformerBase() noexcept override;
85
86
    // css::xml::sax::XDocumentHandler
87
    virtual void SAL_CALL startDocument() override;
88
    virtual void SAL_CALL endDocument() override;
89
    virtual void SAL_CALL startElement(const OUString& aName,
90
                              const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs) override;
91
    virtual void SAL_CALL endElement(const OUString& aName) override;
92
    virtual void SAL_CALL characters(const OUString& aChars) override;
93
    virtual void SAL_CALL ignorableWhitespace(const OUString& aWhitespaces) override;
94
    virtual void SAL_CALL processingInstruction(const OUString& aTarget,
95
                                       const OUString& aData) override;
96
    virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > & xLocator) override;
97
98
    // css::xml::sax::XExtendedDocumentHandler
99
    virtual void SAL_CALL startCDATA() override;
100
    virtual void SAL_CALL endCDATA() override;
101
    virtual void SAL_CALL comment(const OUString& sComment) override;
102
    virtual void SAL_CALL allowLineBreak() override;
103
    virtual void SAL_CALL unknown(const OUString& sString) override;
104
105
    // XInitialization
106
    virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
107
108
    // C++
109
0
    const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const { return m_xHandler; }
110
111
0
    const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const { return m_xPropSet; }
112
113
114
0
    SvXMLNamespaceMap& GetNamespaceMap() { return *m_pNamespaceMap; }
115
0
    const SvXMLNamespaceMap& GetNamespaceMap() const { return *m_pNamespaceMap; }
116
0
    SvXMLNamespaceMap& GetReplaceNamespaceMap() { return m_vReplaceNamespaceMap; }
117
118
0
    XMLTransformerActions& GetElemActions() { return m_ElemActions; }
119
    virtual XMLTransformerActions *GetUserDefinedActions( sal_uInt16 n );
120
    virtual XMLTransformerContext *CreateUserDefinedContext(
121
                                      const TransformerAction_Impl& rAction,
122
                                      const OUString& rQName,
123
                                         bool bPersistent=false ) = 0;
124
    virtual OUString GetEventName( const OUString& rName,
125
                                             bool bForm = false ) = 0;
126
127
128
    XMLMutableAttributeList *ProcessAttrList( css::uno::Reference< css::xml::sax::XAttributeList >& rAttrList,
129
                         sal_uInt16 nActionMap, bool bClone );
130
131
    static bool ReplaceSingleInchWithIn( OUString& rValue );
132
    static bool ReplaceSingleInWithInch( OUString& rValue );
133
    static bool ReplaceInchWithIn( OUString& rValue );
134
    static bool ReplaceInWithInch( OUString& rValue );
135
136
    bool EncodeStyleName( OUString& rName ) const;
137
    static bool DecodeStyleName( OUString& rName );
138
    static bool NegPercent( OUString& rValue );
139
140
    void AddNamespacePrefix( OUString& rName,
141
                                 sal_uInt16 nPrefix ) const;
142
    bool RemoveNamespacePrefix( OUString& rName,
143
                                    sal_uInt16 nPrefixOnly=0xffffU ) const;
144
145
    bool ConvertURIToOASIS( OUString& rURI,
146
                                bool bSupportPackage ) const;
147
    bool ConvertURIToOOo( OUString& rURI,
148
                                bool bSupportPackage ) const;
149
150
    /** renames the given rOutAttributeValue if one of the parameters contains a
151
        matching token in its lower 16 bits.  The value is converted to the
152
        token that is given in the upper 16 bits of the matching parameter.
153
     */
154
    static bool RenameAttributeValue( OUString& rOutAttributeValue,
155
                                   sal_Int32 nParam1,
156
                                   sal_Int32 nParam2,
157
                                   sal_Int32 nParam3 );
158
159
    /** converts the '.' that separates fractions of seconds in a dateTime
160
        string into a ',' that was used in the OOo format
161
162
        @param rDateTime
163
            A dateTime string that will be parsed and changed in case a match
164
            was found.
165
        @return <TRUE/> if the given string was changed
166
     */
167
    static bool ConvertRNGDateTimeToISO( OUString& rDateTime );
168
169
    ::xmloff::token::XMLTokenEnum GetToken( const OUString& rStr ) const;
170
171
    const XMLTransformerContext *GetCurrentContext() const;
172
    const XMLTransformerContext *GetAncestorContext( sal_uInt32 i ) const;
173
174
    // C++
175
0
    void SetClass( const OUString& r ) { m_aClass = r; }
176
0
    const OUString& GetClass() const { return m_aClass; }
177
178
    bool isWriter() const;
179
180
};
181
182
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */