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