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