xref: /AOO41X/main/xmloff/source/text/XMLIndexBibliographyEntryContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 
28 #include "XMLIndexBibliographyEntryContext.hxx"
29 #include "XMLIndexTemplateContext.hxx"
30 #include <xmloff/xmlictxt.hxx>
31 #include <xmloff/xmlimp.hxx>
32 #include <xmloff/txtimp.hxx>
33 #include <xmloff/nmspmap.hxx>
34 #include "xmloff/xmlnmspe.hxx"
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <com/sun/star/text/BibliographyDataField.hpp>
38 
39 
40 using namespace ::com::sun::star::text;
41 using namespace ::xmloff::token;
42 
43 using ::rtl::OUString;
44 using ::com::sun::star::beans::PropertyValue;
45 using ::com::sun::star::beans::PropertyValues;
46 using ::com::sun::star::uno::Reference;
47 using ::com::sun::star::uno::Sequence;
48 using ::com::sun::star::uno::Any;
49 using ::com::sun::star::xml::sax::XAttributeList;
50 
51 
52 const sal_Char sAPI_TokenType[] = "TokenType";
53 const sal_Char sAPI_CharacterStyleName[] = "CharacterStyleName";
54 
55 TYPEINIT1( XMLIndexBibliographyEntryContext, XMLIndexSimpleEntryContext);
56 
XMLIndexBibliographyEntryContext(SvXMLImport & rImport,XMLIndexTemplateContext & rTemplate,sal_uInt16 nPrfx,const OUString & rLocalName)57 XMLIndexBibliographyEntryContext::XMLIndexBibliographyEntryContext(
58     SvXMLImport& rImport,
59     XMLIndexTemplateContext& rTemplate,
60     sal_uInt16 nPrfx,
61     const OUString& rLocalName ) :
62         XMLIndexSimpleEntryContext(rImport,
63                                    rTemplate.sTokenBibliographyDataField,
64                                    rTemplate,
65                                    nPrfx, rLocalName),
66         nBibliographyInfo(BibliographyDataField::IDENTIFIER),
67         bBibliographyInfoOK(sal_False)
68 {
69 }
70 
~XMLIndexBibliographyEntryContext()71 XMLIndexBibliographyEntryContext::~XMLIndexBibliographyEntryContext()
72 {
73 }
74 
75 const SvXMLEnumMapEntry aBibliographyDataFieldMap[] =
76 {
77     { XML_ADDRESS,              BibliographyDataField::ADDRESS },
78     { XML_ANNOTE,               BibliographyDataField::ANNOTE },
79     { XML_AUTHOR,               BibliographyDataField::AUTHOR },
80     { XML_BIBLIOGRAPHY_TYPE,    BibliographyDataField::BIBILIOGRAPHIC_TYPE },
81     // #96658#: also read old documents (bib*i*liographic...)
82     { XML_BIBILIOGRAPHIC_TYPE,  BibliographyDataField::BIBILIOGRAPHIC_TYPE },
83     { XML_BOOKTITLE,            BibliographyDataField::BOOKTITLE },
84     { XML_CHAPTER,              BibliographyDataField::CHAPTER },
85     { XML_CUSTOM1,              BibliographyDataField::CUSTOM1 },
86     { XML_CUSTOM2,              BibliographyDataField::CUSTOM2 },
87     { XML_CUSTOM3,              BibliographyDataField::CUSTOM3 },
88     { XML_CUSTOM4,              BibliographyDataField::CUSTOM4 },
89     { XML_CUSTOM5,              BibliographyDataField::CUSTOM5 },
90     { XML_EDITION,              BibliographyDataField::EDITION },
91     { XML_EDITOR,               BibliographyDataField::EDITOR },
92     { XML_HOWPUBLISHED,         BibliographyDataField::HOWPUBLISHED },
93     { XML_IDENTIFIER,           BibliographyDataField::IDENTIFIER },
94     { XML_INSTITUTION,          BibliographyDataField::INSTITUTION },
95     { XML_ISBN,                 BibliographyDataField::ISBN },
96     { XML_JOURNAL,              BibliographyDataField::JOURNAL },
97     { XML_MONTH,                BibliographyDataField::MONTH },
98     { XML_NOTE,                 BibliographyDataField::NOTE },
99     { XML_NUMBER,               BibliographyDataField::NUMBER },
100     { XML_ORGANIZATIONS,        BibliographyDataField::ORGANIZATIONS },
101     { XML_PAGES,                BibliographyDataField::PAGES },
102     { XML_PUBLISHER,            BibliographyDataField::PUBLISHER },
103     { XML_REPORT_TYPE,          BibliographyDataField::REPORT_TYPE },
104     { XML_SCHOOL,               BibliographyDataField::SCHOOL },
105     { XML_SERIES,               BibliographyDataField::SERIES },
106     { XML_TITLE,                BibliographyDataField::TITLE },
107     { XML_URL,                  BibliographyDataField::URL },
108     { XML_VOLUME,               BibliographyDataField::VOLUME },
109     { XML_YEAR,                 BibliographyDataField::YEAR },
110     { XML_TOKEN_INVALID, 0 }
111 };
112 
StartElement(const Reference<XAttributeList> & xAttrList)113 void XMLIndexBibliographyEntryContext::StartElement(
114     const Reference<XAttributeList> & xAttrList)
115 {
116     // handle both, style name and bibliography info
117     sal_Int16 nLength = xAttrList->getLength();
118     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
119     {
120         OUString sLocalName;
121         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
122             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
123                               &sLocalName );
124         if (XML_NAMESPACE_TEXT == nPrefix)
125         {
126             if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
127             {
128                 sCharStyleName = xAttrList->getValueByIndex(nAttr);
129                 bCharStyleNameOK = sal_True;
130             }
131             else if ( IsXMLToken( sLocalName, XML_BIBLIOGRAPHY_DATA_FIELD ) )
132             {
133                 sal_uInt16 nTmp;
134                 if (SvXMLUnitConverter::convertEnum(
135                     nTmp, xAttrList->getValueByIndex(nAttr),
136                     aBibliographyDataFieldMap))
137                 {
138                     nBibliographyInfo = nTmp;
139                     bBibliographyInfoOK = sal_True;
140                 }
141             }
142         }
143     }
144 
145     // if we have a style name, set it!
146     if (bCharStyleNameOK)
147     {
148         nValues++;
149     }
150 
151     // always bibliography; else element is not valid
152     nValues++;
153 }
154 
EndElement()155 void XMLIndexBibliographyEntryContext::EndElement()
156 {
157     // only valid, if we have bibliography info
158     if (bBibliographyInfoOK)
159     {
160         XMLIndexSimpleEntryContext::EndElement();
161     }
162 }
163 
FillPropertyValues(::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> & rValues)164 void XMLIndexBibliographyEntryContext::FillPropertyValues(
165     ::com::sun::star::uno::Sequence<
166         ::com::sun::star::beans::PropertyValue> & rValues)
167 {
168     // entry name and (optionally) style name in parent class
169     XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
170 
171     // bibliography data field
172     sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1;
173     rValues[nIndex].Name = rTemplateContext.sBibliographyDataField;
174     Any aAny;
175     aAny <<= nBibliographyInfo;
176     rValues[nIndex].Value = aAny;
177 }
178