Bump for 3.6-28
[LibreOffice.git] / xmloff / source / text / XMLIndexBibliographyEntryContext.cxx
blob220d721bffdc4cb1dff876b53d47d7d60e7e5c97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include "XMLIndexBibliographyEntryContext.hxx"
32 #include "XMLIndexTemplateContext.hxx"
33 #include <xmloff/xmlictxt.hxx>
34 #include <xmloff/xmlimp.hxx>
35 #include <xmloff/txtimp.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include "xmloff/xmlnmspe.hxx"
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/xmluconv.hxx>
40 #include <com/sun/star/text/BibliographyDataField.hpp>
43 using namespace ::com::sun::star::text;
44 using namespace ::xmloff::token;
46 using ::rtl::OUString;
47 using ::com::sun::star::beans::PropertyValue;
48 using ::com::sun::star::beans::PropertyValues;
49 using ::com::sun::star::uno::Reference;
50 using ::com::sun::star::uno::Sequence;
51 using ::com::sun::star::uno::Any;
52 using ::com::sun::star::xml::sax::XAttributeList;
55 const sal_Char sAPI_TokenType[] = "TokenType";
56 const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
58 TYPEINIT1( XMLIndexBibliographyEntryContext, XMLIndexSimpleEntryContext);
60 XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext(
61 SvXMLImport& rImport,
62 XMLIndexTemplateContext& rTemplate,
63 sal_uInt16 nPrfx,
64 const OUString& rLocalName ) :
65 XMLIndexSimpleEntryContext(rImport,
66 rTemplate.sTokenBibliographyDataField,
67 rTemplate,
68 nPrfx, rLocalName),
69 nBibliographyInfo(BibliographyDataField::IDENTIFIER),
70 bBibliographyInfoOK(sal_False)
74 XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
78 const SvXMLEnumMapEntry aBibliographyDataFieldMap[] =
80 { XML_ADDRESS, BibliographyDataField::ADDRESS },
81 { XML_ANNOTE, BibliographyDataField::ANNOTE },
82 { XML_AUTHOR, BibliographyDataField::AUTHOR },
83 { XML_BIBLIOGRAPHY_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
84 // #96658#: also read old documents (bib*i*liographic...)
85 { XML_BIBILIOGRAPHIC_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
86 { XML_BOOKTITLE, BibliographyDataField::BOOKTITLE },
87 { XML_CHAPTER, BibliographyDataField::CHAPTER },
88 { XML_CUSTOM1, BibliographyDataField::CUSTOM1 },
89 { XML_CUSTOM2, BibliographyDataField::CUSTOM2 },
90 { XML_CUSTOM3, BibliographyDataField::CUSTOM3 },
91 { XML_CUSTOM4, BibliographyDataField::CUSTOM4 },
92 { XML_CUSTOM5, BibliographyDataField::CUSTOM5 },
93 { XML_EDITION, BibliographyDataField::EDITION },
94 { XML_EDITOR, BibliographyDataField::EDITOR },
95 { XML_HOWPUBLISHED, BibliographyDataField::HOWPUBLISHED },
96 { XML_IDENTIFIER, BibliographyDataField::IDENTIFIER },
97 { XML_INSTITUTION, BibliographyDataField::INSTITUTION },
98 { XML_ISBN, BibliographyDataField::ISBN },
99 { XML_JOURNAL, BibliographyDataField::JOURNAL },
100 { XML_MONTH, BibliographyDataField::MONTH },
101 { XML_NOTE, BibliographyDataField::NOTE },
102 { XML_NUMBER, BibliographyDataField::NUMBER },
103 { XML_ORGANIZATIONS, BibliographyDataField::ORGANIZATIONS },
104 { XML_PAGES, BibliographyDataField::PAGES },
105 { XML_PUBLISHER, BibliographyDataField::PUBLISHER },
106 { XML_REPORT_TYPE, BibliographyDataField::REPORT_TYPE },
107 { XML_SCHOOL, BibliographyDataField::SCHOOL },
108 { XML_SERIES, BibliographyDataField::SERIES },
109 { XML_TITLE, BibliographyDataField::TITLE },
110 { XML_URL, BibliographyDataField::URL },
111 { XML_VOLUME, BibliographyDataField::VOLUME },
112 { XML_YEAR, BibliographyDataField::YEAR },
113 { XML_TOKEN_INVALID, 0 }
116 void XMLIndexBibliographyEntryContext::StartElement(
117 const Reference<XAttributeList> & xAttrList)
119 // handle both, style name and bibliography info
120 sal_Int16 nLength = xAttrList->getLength();
121 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
123 OUString sLocalName;
124 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
125 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
126 &sLocalName );
127 if (XML_NAMESPACE_TEXT == nPrefix)
129 if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
131 sCharStyleName = xAttrList->getValueByIndex(nAttr);
132 bCharStyleNameOK = sal_True;
134 else if ( IsXMLToken( sLocalName, XML_BIBLIOGRAPHY_DATA_FIELD ) )
136 sal_uInt16 nTmp;
137 if (SvXMLUnitConverter::convertEnum(
138 nTmp, xAttrList->getValueByIndex(nAttr),
139 aBibliographyDataFieldMap))
141 nBibliographyInfo = nTmp;
142 bBibliographyInfoOK = sal_True;
148 // if we have a style name, set it!
149 if (bCharStyleNameOK)
151 nValues++;
154 // always bibliography; else element is not valid
155 nValues++;
158 void XMLIndexBibliographyEntryContext::EndElement()
160 // only valid, if we have bibliography info
161 if (bBibliographyInfoOK)
163 XMLIndexSimpleEntryContext::EndElement();
167 void XMLIndexBibliographyEntryContext::FillPropertyValues(
168 ::com::sun::star::uno::Sequence<
169 ::com::sun::star::beans::PropertyValue> & rValues)
171 // entry name and (optionally) style name in parent class
172 XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
174 // bibliography data field
175 sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
176 rValues[nIndex].Name = rTemplateContext.sBibliographyDataField;
177 Any aAny;
178 aAny <<= nBibliographyInfo;
179 rValues[nIndex].Value = aAny;
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */