bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLIndexTitleTemplateContext.cxx
blob3a780ac2e6920625b13435abae44a9c242823edd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLIndexTitleTemplateContext.hxx"
21 #include <xmloff/xmlictxt.hxx>
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmltoken.hxx>
28 using ::com::sun::star::beans::XPropertySet;
29 using ::com::sun::star::uno::Any;
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::xml::sax::XAttributeList;
32 using ::xmloff::token::IsXMLToken;
33 using ::xmloff::token::XML_STYLE_NAME;
36 TYPEINIT1( XMLIndexTitleTemplateContext, SvXMLImportContext );
38 XMLIndexTitleTemplateContext::XMLIndexTitleTemplateContext(
39 SvXMLImport& rImport,
40 Reference<XPropertySet> & rPropSet,
41 sal_uInt16 nPrfx,
42 const OUString& rLocalName)
43 : SvXMLImportContext(rImport, nPrfx, rLocalName)
44 , sTitle("Title")
45 , sParaStyleHeading("ParaStyleHeading")
46 , bStyleNameOK(false)
47 , rTOCPropertySet(rPropSet)
52 XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext()
56 void XMLIndexTitleTemplateContext::StartElement(
57 const Reference<XAttributeList> & xAttrList)
59 // there's only one attribute: style-name
60 sal_Int16 nLength = xAttrList->getLength();
61 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
63 OUString sLocalName;
64 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
65 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
66 &sLocalName );
67 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
68 (IsXMLToken(sLocalName, XML_STYLE_NAME)) )
70 sStyleName = xAttrList->getValueByIndex(nAttr);
71 OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
72 XML_STYLE_FAMILY_TEXT_PARAGRAPH, sStyleName );
73 const Reference < ::com::sun::star::container::XNameContainer >&
74 rStyles = GetImport().GetTextImport()->GetParaStyles();
75 bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
80 void XMLIndexTitleTemplateContext::EndElement()
82 Any aAny;
84 aAny <<= sContent.makeStringAndClear();
85 rTOCPropertySet->setPropertyValue(sTitle, aAny);
87 if (bStyleNameOK)
89 aAny <<= GetImport().GetStyleDisplayName(
90 XML_STYLE_FAMILY_TEXT_PARAGRAPH,
91 sStyleName );
92 rTOCPropertySet->setPropertyValue(sParaStyleHeading, aAny);
96 void XMLIndexTitleTemplateContext::Characters(
97 const OUString& sString)
99 sContent.append(sString);
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */