Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLIndexBibliographyEntryContext.cxx
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
#include "XMLIndexBibliographyEntryContext.hxx"
21
#include "XMLIndexTemplateContext.hxx"
22
#include <xmloff/xmlimp.hxx>
23
#include <xmloff/xmlnamespace.hxx>
24
#include <xmloff/xmltoken.hxx>
25
#include <xmloff/xmluconv.hxx>
26
#include <xmloff/xmlement.hxx>
27
#include <com/sun/star/text/BibliographyDataField.hpp>
28
#include <sal/log.hxx>
29
30
31
using namespace ::com::sun::star::text;
32
using namespace ::xmloff::token;
33
34
using ::com::sun::star::beans::PropertyValue;
35
using ::com::sun::star::uno::Reference;
36
using ::com::sun::star::uno::Sequence;
37
38
39
XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext(
40
    SvXMLImport& rImport,
41
    XMLIndexTemplateContext& rTemplate ) :
42
4.86k
        XMLIndexSimpleEntryContext(rImport,
43
4.86k
                                   u"TokenBibliographyDataField"_ustr,
44
4.86k
                                   rTemplate),
45
4.86k
        nBibliographyInfo(BibliographyDataField::IDENTIFIER),
46
4.86k
        bBibliographyInfoOK(false)
47
4.86k
{
48
4.86k
}
49
50
XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
51
4.86k
{
52
4.86k
}
53
54
const SvXMLEnumMapEntry<sal_uInt16> aBibliographyDataFieldMap[] =
55
{
56
    { XML_ADDRESS,              BibliographyDataField::ADDRESS },
57
    { XML_ANNOTE,               BibliographyDataField::ANNOTE },
58
    { XML_AUTHOR,               BibliographyDataField::AUTHOR },
59
    { XML_BIBLIOGRAPHY_TYPE,    BibliographyDataField::BIBILIOGRAPHIC_TYPE },
60
    // #96658#: also read old documents (bib*i*liographic...)
61
    { XML_BIBILIOGRAPHIC_TYPE,  BibliographyDataField::BIBILIOGRAPHIC_TYPE },
62
    { XML_BOOKTITLE,            BibliographyDataField::BOOKTITLE },
63
    { XML_CHAPTER,              BibliographyDataField::CHAPTER },
64
    { XML_CUSTOM1,              BibliographyDataField::CUSTOM1 },
65
    { XML_CUSTOM2,              BibliographyDataField::CUSTOM2 },
66
    { XML_CUSTOM3,              BibliographyDataField::CUSTOM3 },
67
    { XML_CUSTOM4,              BibliographyDataField::CUSTOM4 },
68
    { XML_CUSTOM5,              BibliographyDataField::CUSTOM5 },
69
    { XML_EDITION,              BibliographyDataField::EDITION },
70
    { XML_EDITOR,               BibliographyDataField::EDITOR },
71
    { XML_HOWPUBLISHED,         BibliographyDataField::HOWPUBLISHED },
72
    { XML_IDENTIFIER,           BibliographyDataField::IDENTIFIER },
73
    { XML_INSTITUTION,          BibliographyDataField::INSTITUTION },
74
    { XML_ISBN,                 BibliographyDataField::ISBN },
75
    { XML_JOURNAL,              BibliographyDataField::JOURNAL },
76
    { XML_MONTH,                BibliographyDataField::MONTH },
77
    { XML_NOTE,                 BibliographyDataField::NOTE },
78
    { XML_NUMBER,               BibliographyDataField::NUMBER },
79
    { XML_ORGANIZATIONS,        BibliographyDataField::ORGANIZATIONS },
80
    { XML_PAGES,                BibliographyDataField::PAGES },
81
    { XML_PUBLISHER,            BibliographyDataField::PUBLISHER },
82
    { XML_REPORT_TYPE,          BibliographyDataField::REPORT_TYPE },
83
    { XML_SCHOOL,               BibliographyDataField::SCHOOL },
84
    { XML_SERIES,               BibliographyDataField::SERIES },
85
    { XML_TITLE,                BibliographyDataField::TITLE },
86
    { XML_URL,                  BibliographyDataField::URL },
87
    { XML_VOLUME,               BibliographyDataField::VOLUME },
88
    { XML_YEAR,                 BibliographyDataField::YEAR },
89
    { XML_TOKEN_INVALID, 0 }
90
};
91
92
void XMLIndexBibliographyEntryContext::startFastElement(
93
    sal_Int32 /*nElement*/,
94
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
95
4.86k
{
96
    // handle both, style name and bibliography info
97
4.86k
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
98
5.69k
    {
99
5.69k
        switch(aIter.getToken())
100
5.69k
        {
101
889
            case XML_ELEMENT(TEXT, XML_STYLE_NAME):
102
889
            {
103
889
                m_sCharStyleName = aIter.toString();
104
889
                m_bCharStyleNameOK = true;
105
889
                break;
106
0
            }
107
4.76k
            case XML_ELEMENT(TEXT, XML_BIBLIOGRAPHY_DATA_FIELD):
108
4.76k
            {
109
4.76k
                sal_uInt16 nTmp;
110
4.76k
                if (SvXMLUnitConverter::convertEnum(nTmp, aIter.toView(), aBibliographyDataFieldMap))
111
4.71k
                {
112
4.71k
                    nBibliographyInfo = nTmp;
113
4.71k
                    bBibliographyInfoOK = true;
114
4.71k
                }
115
4.76k
                break;
116
0
            }
117
38
            default:
118
38
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
119
5.69k
        }
120
5.69k
    }
121
122
    // if we have a style name, set it!
123
4.86k
    if (m_bCharStyleNameOK)
124
889
    {
125
889
        m_nValues++;
126
889
    }
127
128
    // always bibliography; else element is not valid
129
4.86k
    m_nValues++;
130
4.86k
}
131
132
void XMLIndexBibliographyEntryContext::endFastElement(sal_Int32 nElement)
133
4.86k
{
134
    // only valid, if we have bibliography info
135
4.86k
    if (bBibliographyInfoOK)
136
4.71k
    {
137
4.71k
        XMLIndexSimpleEntryContext::endFastElement(nElement);
138
4.71k
    }
139
4.86k
}
140
141
void XMLIndexBibliographyEntryContext::FillPropertyValues(
142
    css::uno::Sequence<css::beans::PropertyValue> & rValues)
143
4.71k
{
144
    // entry name and (optionally) style name in parent class
145
4.71k
    XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
146
147
    // bibliography data field
148
4.71k
    sal_Int32 nIndex = m_bCharStyleNameOK ? 2 : 1;
149
4.71k
    auto pValues = rValues.getArray();
150
4.71k
    pValues[nIndex].Name = "BibliographyDataField";
151
4.71k
    pValues[nIndex].Value <<= nBibliographyInfo;
152
4.71k
}
153
154
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */