Line data Source code
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/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>
30 :
31 :
32 : using namespace ::com::sun::star::text;
33 : using namespace ::xmloff::token;
34 :
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;
41 :
42 :
43 : const sal_Char sAPI_TokenType[] = "TokenType";
44 : const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
45 :
46 0 : TYPEINIT1( XMLIndexBibliographyEntryContext, XMLIndexSimpleEntryContext);
47 :
48 178 : XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext(
49 : SvXMLImport& rImport,
50 : XMLIndexTemplateContext& rTemplate,
51 : sal_uInt16 nPrfx,
52 : const OUString& rLocalName ) :
53 : XMLIndexSimpleEntryContext(rImport,
54 : rTemplate.sTokenBibliographyDataField,
55 : rTemplate,
56 : nPrfx, rLocalName),
57 : nBibliographyInfo(BibliographyDataField::IDENTIFIER),
58 178 : bBibliographyInfoOK(sal_False)
59 : {
60 178 : }
61 :
62 356 : XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
63 : {
64 356 : }
65 :
66 : const SvXMLEnumMapEntry aBibliographyDataFieldMap[] =
67 : {
68 : { XML_ADDRESS, BibliographyDataField::ADDRESS },
69 : { XML_ANNOTE, BibliographyDataField::ANNOTE },
70 : { XML_AUTHOR, BibliographyDataField::AUTHOR },
71 : { XML_BIBLIOGRAPHY_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
72 : // #96658#: also read old documents (bib*i*liographic...)
73 : { XML_BIBILIOGRAPHIC_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
74 : { XML_BOOKTITLE, BibliographyDataField::BOOKTITLE },
75 : { XML_CHAPTER, BibliographyDataField::CHAPTER },
76 : { XML_CUSTOM1, BibliographyDataField::CUSTOM1 },
77 : { XML_CUSTOM2, BibliographyDataField::CUSTOM2 },
78 : { XML_CUSTOM3, BibliographyDataField::CUSTOM3 },
79 : { XML_CUSTOM4, BibliographyDataField::CUSTOM4 },
80 : { XML_CUSTOM5, BibliographyDataField::CUSTOM5 },
81 : { XML_EDITION, BibliographyDataField::EDITION },
82 : { XML_EDITOR, BibliographyDataField::EDITOR },
83 : { XML_HOWPUBLISHED, BibliographyDataField::HOWPUBLISHED },
84 : { XML_IDENTIFIER, BibliographyDataField::IDENTIFIER },
85 : { XML_INSTITUTION, BibliographyDataField::INSTITUTION },
86 : { XML_ISBN, BibliographyDataField::ISBN },
87 : { XML_JOURNAL, BibliographyDataField::JOURNAL },
88 : { XML_MONTH, BibliographyDataField::MONTH },
89 : { XML_NOTE, BibliographyDataField::NOTE },
90 : { XML_NUMBER, BibliographyDataField::NUMBER },
91 : { XML_ORGANIZATIONS, BibliographyDataField::ORGANIZATIONS },
92 : { XML_PAGES, BibliographyDataField::PAGES },
93 : { XML_PUBLISHER, BibliographyDataField::PUBLISHER },
94 : { XML_REPORT_TYPE, BibliographyDataField::REPORT_TYPE },
95 : { XML_SCHOOL, BibliographyDataField::SCHOOL },
96 : { XML_SERIES, BibliographyDataField::SERIES },
97 : { XML_TITLE, BibliographyDataField::TITLE },
98 : { XML_URL, BibliographyDataField::URL },
99 : { XML_VOLUME, BibliographyDataField::VOLUME },
100 : { XML_YEAR, BibliographyDataField::YEAR },
101 : { XML_TOKEN_INVALID, 0 }
102 : };
103 :
104 178 : void XMLIndexBibliographyEntryContext::StartElement(
105 : const Reference<XAttributeList> & xAttrList)
106 : {
107 : // handle both, style name and bibliography info
108 178 : sal_Int16 nLength = xAttrList->getLength();
109 356 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
110 : {
111 178 : OUString sLocalName;
112 178 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
113 178 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
114 356 : &sLocalName );
115 178 : if (XML_NAMESPACE_TEXT == nPrefix)
116 : {
117 178 : if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
118 : {
119 0 : sCharStyleName = xAttrList->getValueByIndex(nAttr);
120 0 : bCharStyleNameOK = sal_True;
121 : }
122 178 : else if ( IsXMLToken( sLocalName, XML_BIBLIOGRAPHY_DATA_FIELD ) )
123 : {
124 : sal_uInt16 nTmp;
125 356 : if (SvXMLUnitConverter::convertEnum(
126 178 : nTmp, xAttrList->getValueByIndex(nAttr),
127 356 : aBibliographyDataFieldMap))
128 : {
129 178 : nBibliographyInfo = nTmp;
130 178 : bBibliographyInfoOK = sal_True;
131 : }
132 : }
133 : }
134 178 : }
135 :
136 : // if we have a style name, set it!
137 178 : if (bCharStyleNameOK)
138 : {
139 0 : nValues++;
140 : }
141 :
142 : // always bibliography; else element is not valid
143 178 : nValues++;
144 178 : }
145 :
146 178 : void XMLIndexBibliographyEntryContext::EndElement()
147 : {
148 : // only valid, if we have bibliography info
149 178 : if (bBibliographyInfoOK)
150 : {
151 178 : XMLIndexSimpleEntryContext::EndElement();
152 : }
153 178 : }
154 :
155 178 : void XMLIndexBibliographyEntryContext::FillPropertyValues(
156 : ::com::sun::star::uno::Sequence<
157 : ::com::sun::star::beans::PropertyValue> & rValues)
158 : {
159 : // entry name and (optionally) style name in parent class
160 178 : XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
161 :
162 : // bibliography data field
163 178 : sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
164 178 : rValues[nIndex].Name = rTemplateContext.sBibliographyDataField;
165 178 : Any aAny;
166 178 : aAny <<= nBibliographyInfo;
167 178 : rValues[nIndex].Value = aAny;
168 178 : }
169 :
170 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|