LibreOffice Module xmloff (master)  1
XMLIndexBibliographyEntryContext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/txtimp.hxx>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <xmloff/xmlement.hxx>
29 #include <com/sun/star/text/BibliographyDataField.hpp>
30 
31 
32 using namespace ::com::sun::star::text;
33 using namespace ::xmloff::token;
34 
35 using ::com::sun::star::beans::PropertyValue;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::Sequence;
38 using ::com::sun::star::xml::sax::XAttributeList;
39 
40 
42  SvXMLImport& rImport,
43  XMLIndexTemplateContext& rTemplate,
44  sal_uInt16 nPrfx,
45  const OUString& rLocalName ) :
47  "TokenBibliographyDataField",
48  rTemplate,
49  nPrfx, rLocalName),
50  nBibliographyInfo(BibliographyDataField::IDENTIFIER),
51  bBibliographyInfoOK(false)
52 {
53 }
54 
56 {
57 }
58 
60 {
61  { XML_ADDRESS, BibliographyDataField::ADDRESS },
62  { XML_ANNOTE, BibliographyDataField::ANNOTE },
63  { XML_AUTHOR, BibliographyDataField::AUTHOR },
64  { XML_BIBLIOGRAPHY_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
65  // #96658#: also read old documents (bib*i*liographic...)
66  { XML_BIBILIOGRAPHIC_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
67  { XML_BOOKTITLE, BibliographyDataField::BOOKTITLE },
68  { XML_CHAPTER, BibliographyDataField::CHAPTER },
69  { XML_CUSTOM1, BibliographyDataField::CUSTOM1 },
70  { XML_CUSTOM2, BibliographyDataField::CUSTOM2 },
71  { XML_CUSTOM3, BibliographyDataField::CUSTOM3 },
72  { XML_CUSTOM4, BibliographyDataField::CUSTOM4 },
73  { XML_CUSTOM5, BibliographyDataField::CUSTOM5 },
74  { XML_EDITION, BibliographyDataField::EDITION },
75  { XML_EDITOR, BibliographyDataField::EDITOR },
76  { XML_HOWPUBLISHED, BibliographyDataField::HOWPUBLISHED },
77  { XML_IDENTIFIER, BibliographyDataField::IDENTIFIER },
78  { XML_INSTITUTION, BibliographyDataField::INSTITUTION },
79  { XML_ISBN, BibliographyDataField::ISBN },
80  { XML_JOURNAL, BibliographyDataField::JOURNAL },
81  { XML_MONTH, BibliographyDataField::MONTH },
82  { XML_NOTE, BibliographyDataField::NOTE },
83  { XML_NUMBER, BibliographyDataField::NUMBER },
84  { XML_ORGANIZATIONS, BibliographyDataField::ORGANIZATIONS },
85  { XML_PAGES, BibliographyDataField::PAGES },
86  { XML_PUBLISHER, BibliographyDataField::PUBLISHER },
87  { XML_REPORT_TYPE, BibliographyDataField::REPORT_TYPE },
88  { XML_SCHOOL, BibliographyDataField::SCHOOL },
89  { XML_SERIES, BibliographyDataField::SERIES },
90  { XML_TITLE, BibliographyDataField::TITLE },
91  { XML_URL, BibliographyDataField::URL },
92  { XML_VOLUME, BibliographyDataField::VOLUME },
93  { XML_YEAR, BibliographyDataField::YEAR },
94  { XML_TOKEN_INVALID, 0 }
95 };
96 
98  const Reference<XAttributeList> & xAttrList)
99 {
100  // handle both, style name and bibliography info
101  sal_Int16 nLength = xAttrList->getLength();
102  for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
103  {
104  OUString sLocalName;
105  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
106  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
107  &sLocalName );
108  if (XML_NAMESPACE_TEXT == nPrefix)
109  {
110  if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) )
111  {
112  m_sCharStyleName = xAttrList->getValueByIndex(nAttr);
113  m_bCharStyleNameOK = true;
114  }
115  else if ( IsXMLToken( sLocalName, XML_BIBLIOGRAPHY_DATA_FIELD ) )
116  {
117  sal_uInt16 nTmp;
119  nTmp, xAttrList->getValueByIndex(nAttr),
121  {
122  nBibliographyInfo = nTmp;
123  bBibliographyInfoOK = true;
124  }
125  }
126  }
127  }
128 
129  // if we have a style name, set it!
130  if (m_bCharStyleNameOK)
131  {
132  m_nValues++;
133  }
134 
135  // always bibliography; else element is not valid
136  m_nValues++;
137 }
138 
140 {
141  // only valid, if we have bibliography info
143  {
145  }
146 }
147 
149  css::uno::Sequence<css::beans::PropertyValue> & rValues)
150 {
151  // entry name and (optionally) style name in parent class
153 
154  // bibliography data field
155  sal_Int32 nIndex = m_bCharStyleNameOK ? 2 : 1;
156  rValues[nIndex].Name = "BibliographyDataField";
157  rValues[nIndex].Value <<= nBibliographyInfo;
158 }
159 
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
sal_Int32 nIndex
static bool convertEnum(EnumT &rEnum, const OUString &rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:128
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues) override
fill property values for this template entry
virtual void EndElement() override
call FillPropertyValues and insert into template
virtual void EndElement() override
call FillPropertyValues and insert into template
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues)
fill property values for this template entry
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
Import index entry templates.
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
XMLIndexBibliographyEntryContext(SvXMLImport &rImport, XMLIndexTemplateContext &rTemplate, sal_uInt16 nPrfx, const OUString &rLocalName)
constexpr sal_uInt16 XML_NAMESPACE_TEXT
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
process parameters
Import index entry templates.
const SvXMLEnumMapEntry< sal_uInt16 > aBibliographyDataFieldMap[]
Handling of tokens in XML:
sal_Int32 nLength
Definition: xmltoken.cxx:36