update dev300-m58
[ooovba.git] / xmloff / source / text / XMLIndexBibliographyEntryContext.cxx
blob41ecbc32f08959cb46cec90d9d96ba9d828ba38f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexBibliographyEntryContext.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "XMLIndexBibliographyEntryContext.hxx"
36 #include "XMLIndexTemplateContext.hxx"
37 #include <xmloff/xmlictxt.hxx>
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/txtimp.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include <com/sun/star/text/BibliographyDataField.hpp>
47 using namespace ::com::sun::star::text;
48 using namespace ::xmloff::token;
50 using ::rtl::OUString;
51 using ::com::sun::star::beans::PropertyValue;
52 using ::com::sun::star::beans::PropertyValues;
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::Sequence;
55 using ::com::sun::star::uno::Any;
56 using ::com::sun::star::xml::sax::XAttributeList;
59 const sal_Char sAPI_TokenType[] = "TokenType";
60 const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
62 TYPEINIT1( XMLIndexBibliographyEntryContext, XMLIndexSimpleEntryContext);
64 XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext(
65 SvXMLImport& rImport,
66 XMLIndexTemplateContext& rTemplate,
67 sal_uInt16 nPrfx,
68 const OUString& rLocalName ) :
69 XMLIndexSimpleEntryContext(rImport,
70 rTemplate.sTokenBibliographyDataField,
71 rTemplate,
72 nPrfx, rLocalName),
73 nBibliographyInfo(BibliographyDataField::IDENTIFIER),
74 bBibliographyInfoOK(sal_False)
78 XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
82 const SvXMLEnumMapEntry aBibliographyDataFieldMap[] =
84 { XML_ADDRESS, BibliographyDataField::ADDRESS },
85 { XML_ANNOTE, BibliographyDataField::ANNOTE },
86 { XML_AUTHOR, BibliographyDataField::AUTHOR },
87 { XML_BIBLIOGRAPHY_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
88 // #96658#: also read old documents (bib*i*liographic...)
89 { XML_BIBILIOGRAPHIC_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
90 { XML_BOOKTITLE, BibliographyDataField::BOOKTITLE },
91 { XML_CHAPTER, BibliographyDataField::CHAPTER },
92 { XML_CUSTOM1, BibliographyDataField::CUSTOM1 },
93 { XML_CUSTOM2, BibliographyDataField::CUSTOM2 },
94 { XML_CUSTOM3, BibliographyDataField::CUSTOM3 },
95 { XML_CUSTOM4, BibliographyDataField::CUSTOM4 },
96 { XML_CUSTOM5, BibliographyDataField::CUSTOM5 },
97 { XML_EDITION, BibliographyDataField::EDITION },
98 { XML_EDITOR, BibliographyDataField::EDITOR },
99 { XML_HOWPUBLISHED, BibliographyDataField::HOWPUBLISHED },
100 { XML_IDENTIFIER, BibliographyDataField::IDENTIFIER },
101 { XML_INSTITUTION, BibliographyDataField::INSTITUTION },
102 { XML_ISBN, BibliographyDataField::ISBN },
103 { XML_JOURNAL, BibliographyDataField::JOURNAL },
104 { XML_MONTH, BibliographyDataField::MONTH },
105 { XML_NOTE, BibliographyDataField::NOTE },
106 { XML_NUMBER, BibliographyDataField::NUMBER },
107 { XML_ORGANIZATIONS, BibliographyDataField::ORGANIZATIONS },
108 { XML_PAGES, BibliographyDataField::PAGES },
109 { XML_PUBLISHER, BibliographyDataField::PUBLISHER },
110 { XML_REPORT_TYPE, BibliographyDataField::REPORT_TYPE },
111 { XML_SCHOOL, BibliographyDataField::SCHOOL },
112 { XML_SERIES, BibliographyDataField::SERIES },
113 { XML_TITLE, BibliographyDataField::TITLE },
114 { XML_URL, BibliographyDataField::URL },
115 { XML_VOLUME, BibliographyDataField::VOLUME },
116 { XML_YEAR, BibliographyDataField::YEAR },
117 { XML_TOKEN_INVALID, 0 }
120 void XMLIndexBibliographyEntryContext::StartElement(
121 const Reference<XAttributeList> & xAttrList)
123 // handle both, style name and bibliography info
124 sal_Int16 nLength = xAttrList->getLength();
125 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
127 OUString sLocalName;
128 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
129 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
130 &sLocalName );
131 if (XML_NAMESPACE_TEXT == nPrefix)
133 if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
135 sCharStyleName = xAttrList->getValueByIndex(nAttr);
136 bCharStyleNameOK = sal_True;
138 else if ( IsXMLToken( sLocalName, XML_BIBLIOGRAPHY_DATA_FIELD ) )
140 sal_uInt16 nTmp;
141 if (SvXMLUnitConverter::convertEnum(
142 nTmp, xAttrList->getValueByIndex(nAttr),
143 aBibliographyDataFieldMap))
145 nBibliographyInfo = nTmp;
146 bBibliographyInfoOK = sal_True;
152 // if we have a style name, set it!
153 if (bCharStyleNameOK)
155 nValues++;
158 // always bibliography; else element is not valid
159 nValues++;
162 void XMLIndexBibliographyEntryContext::EndElement()
164 // only valid, if we have bibliography info
165 if (bBibliographyInfoOK)
167 XMLIndexSimpleEntryContext::EndElement();
171 void XMLIndexBibliographyEntryContext::FillPropertyValues(
172 ::com::sun::star::uno::Sequence<
173 ::com::sun::star::beans::PropertyValue> & rValues)
175 // entry name and (optionally) style name in parent class
176 XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
178 // bibliography data field
179 sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
180 rValues[nIndex].Name = rTemplateContext.sBibliographyDataField;
181 Any aAny;
182 aAny <<= nBibliographyInfo;
183 rValues[nIndex].Value = aAny;