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/xmlictxt.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/txtimp.hxx>
25 #include <xmloff/nmspmap.hxx>
26 #include <xmloff/xmlnmspe.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <com/sun/star/text/BibliographyDataField.hpp>
32 using namespace ::com::sun::star::text
;
33 using namespace ::xmloff::token
;
35 using ::com::sun::star::beans::PropertyValue
;
36 using ::com::sun::star::beans::PropertyValues
;
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::uno::Sequence
;
39 using ::com::sun::star::uno::Any
;
40 using ::com::sun::star::xml::sax::XAttributeList
;
42 TYPEINIT1( XMLIndexBibliographyEntryContext
, XMLIndexSimpleEntryContext
);
44 XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext(
46 XMLIndexTemplateContext
& rTemplate
,
48 const OUString
& rLocalName
) :
49 XMLIndexSimpleEntryContext(rImport
,
50 rTemplate
.sTokenBibliographyDataField
,
53 nBibliographyInfo(BibliographyDataField::IDENTIFIER
),
54 bBibliographyInfoOK(false)
58 XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
62 const SvXMLEnumMapEntry aBibliographyDataFieldMap
[] =
64 { XML_ADDRESS
, BibliographyDataField::ADDRESS
},
65 { XML_ANNOTE
, BibliographyDataField::ANNOTE
},
66 { XML_AUTHOR
, BibliographyDataField::AUTHOR
},
67 { XML_BIBLIOGRAPHY_TYPE
, BibliographyDataField::BIBILIOGRAPHIC_TYPE
},
68 // #96658#: also read old documents (bib*i*liographic...)
69 { XML_BIBILIOGRAPHIC_TYPE
, BibliographyDataField::BIBILIOGRAPHIC_TYPE
},
70 { XML_BOOKTITLE
, BibliographyDataField::BOOKTITLE
},
71 { XML_CHAPTER
, BibliographyDataField::CHAPTER
},
72 { XML_CUSTOM1
, BibliographyDataField::CUSTOM1
},
73 { XML_CUSTOM2
, BibliographyDataField::CUSTOM2
},
74 { XML_CUSTOM3
, BibliographyDataField::CUSTOM3
},
75 { XML_CUSTOM4
, BibliographyDataField::CUSTOM4
},
76 { XML_CUSTOM5
, BibliographyDataField::CUSTOM5
},
77 { XML_EDITION
, BibliographyDataField::EDITION
},
78 { XML_EDITOR
, BibliographyDataField::EDITOR
},
79 { XML_HOWPUBLISHED
, BibliographyDataField::HOWPUBLISHED
},
80 { XML_IDENTIFIER
, BibliographyDataField::IDENTIFIER
},
81 { XML_INSTITUTION
, BibliographyDataField::INSTITUTION
},
82 { XML_ISBN
, BibliographyDataField::ISBN
},
83 { XML_JOURNAL
, BibliographyDataField::JOURNAL
},
84 { XML_MONTH
, BibliographyDataField::MONTH
},
85 { XML_NOTE
, BibliographyDataField::NOTE
},
86 { XML_NUMBER
, BibliographyDataField::NUMBER
},
87 { XML_ORGANIZATIONS
, BibliographyDataField::ORGANIZATIONS
},
88 { XML_PAGES
, BibliographyDataField::PAGES
},
89 { XML_PUBLISHER
, BibliographyDataField::PUBLISHER
},
90 { XML_REPORT_TYPE
, BibliographyDataField::REPORT_TYPE
},
91 { XML_SCHOOL
, BibliographyDataField::SCHOOL
},
92 { XML_SERIES
, BibliographyDataField::SERIES
},
93 { XML_TITLE
, BibliographyDataField::TITLE
},
94 { XML_URL
, BibliographyDataField::URL
},
95 { XML_VOLUME
, BibliographyDataField::VOLUME
},
96 { XML_YEAR
, BibliographyDataField::YEAR
},
97 { XML_TOKEN_INVALID
, 0 }
100 void XMLIndexBibliographyEntryContext::StartElement(
101 const Reference
<XAttributeList
> & xAttrList
)
103 // handle both, style name and bibliography info
104 sal_Int16 nLength
= xAttrList
->getLength();
105 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
108 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
109 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
111 if (XML_NAMESPACE_TEXT
== nPrefix
)
113 if ( IsXMLToken( sLocalName
, XML_STYLE_NAME
) )
115 sCharStyleName
= xAttrList
->getValueByIndex(nAttr
);
116 bCharStyleNameOK
= true;
118 else if ( IsXMLToken( sLocalName
, XML_BIBLIOGRAPHY_DATA_FIELD
) )
121 if (SvXMLUnitConverter::convertEnum(
122 nTmp
, xAttrList
->getValueByIndex(nAttr
),
123 aBibliographyDataFieldMap
))
125 nBibliographyInfo
= nTmp
;
126 bBibliographyInfoOK
= true;
132 // if we have a style name, set it!
133 if (bCharStyleNameOK
)
138 // always bibliography; else element is not valid
142 void XMLIndexBibliographyEntryContext::EndElement()
144 // only valid, if we have bibliography info
145 if (bBibliographyInfoOK
)
147 XMLIndexSimpleEntryContext::EndElement();
151 void XMLIndexBibliographyEntryContext::FillPropertyValues(
152 ::com::sun::star::uno::Sequence
<
153 ::com::sun::star::beans::PropertyValue
> & rValues
)
155 // entry name and (optionally) style name in parent class
156 XMLIndexSimpleEntryContext::FillPropertyValues(rValues
);
158 // bibliography data field
159 sal_Int32 nIndex
= bCharStyleNameOK
? 2 : 1;
160 rValues
[nIndex
].Name
= rTemplateContext
.sBibliographyDataField
;
162 aAny
<<= nBibliographyInfo
;
163 rValues
[nIndex
].Value
= aAny
;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */