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