1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/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>
31 using namespace ::com::sun::star::text
;
32 using namespace ::xmloff::token
;
34 using ::com::sun::star::beans::PropertyValue
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::Sequence
;
39 XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext(
41 XMLIndexTemplateContext
& rTemplate
) :
42 XMLIndexSimpleEntryContext(rImport
,
43 u
"TokenBibliographyDataField"_ustr
,
45 nBibliographyInfo(BibliographyDataField::IDENTIFIER
),
46 bBibliographyInfoOK(false)
50 XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
54 const SvXMLEnumMapEntry
<sal_uInt16
> aBibliographyDataFieldMap
[] =
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 }
92 void XMLIndexBibliographyEntryContext::startFastElement(
93 sal_Int32
/*nElement*/,
94 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
96 // handle both, style name and bibliography info
97 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
99 switch(aIter
.getToken())
101 case XML_ELEMENT(TEXT
, XML_STYLE_NAME
):
103 m_sCharStyleName
= aIter
.toString();
104 m_bCharStyleNameOK
= true;
107 case XML_ELEMENT(TEXT
, XML_BIBLIOGRAPHY_DATA_FIELD
):
110 if (SvXMLUnitConverter::convertEnum(nTmp
, aIter
.toView(), aBibliographyDataFieldMap
))
112 nBibliographyInfo
= nTmp
;
113 bBibliographyInfoOK
= true;
118 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
122 // if we have a style name, set it!
123 if (m_bCharStyleNameOK
)
128 // always bibliography; else element is not valid
132 void XMLIndexBibliographyEntryContext::endFastElement(sal_Int32 nElement
)
134 // only valid, if we have bibliography info
135 if (bBibliographyInfoOK
)
137 XMLIndexSimpleEntryContext::endFastElement(nElement
);
141 void XMLIndexBibliographyEntryContext::FillPropertyValues(
142 css::uno::Sequence
<css::beans::PropertyValue
> & rValues
)
144 // entry name and (optionally) style name in parent class
145 XMLIndexSimpleEntryContext::FillPropertyValues(rValues
);
147 // bibliography data field
148 sal_Int32 nIndex
= m_bCharStyleNameOK
? 2 : 1;
149 auto pValues
= rValues
.getArray();
150 pValues
[nIndex
].Name
= "BibliographyDataField";
151 pValues
[nIndex
].Value
<<= nBibliographyInfo
;
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */