Line data Source code
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 :
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>
26 :
27 :
28 : using ::rtl::OUString;
29 : using ::rtl::OUStringBuffer;
30 : using ::com::sun::star::beans::XPropertySet;
31 : using ::com::sun::star::uno::Any;
32 : using ::com::sun::star::uno::Reference;
33 : using ::com::sun::star::xml::sax::XAttributeList;
34 : using ::xmloff::token::IsXMLToken;
35 : using ::xmloff::token::XML_STYLE_NAME;
36 :
37 :
38 0 : TYPEINIT1( XMLIndexTitleTemplateContext, SvXMLImportContext );
39 :
40 0 : XMLIndexTitleTemplateContext::XMLIndexTitleTemplateContext(
41 : SvXMLImport& rImport,
42 : Reference<XPropertySet> & rPropSet,
43 : sal_uInt16 nPrfx,
44 : const OUString& rLocalName)
45 : : SvXMLImportContext(rImport, nPrfx, rLocalName)
46 : , sTitle("Title")
47 : , sParaStyleHeading("ParaStyleHeading")
48 : , bStyleNameOK(sal_False)
49 0 : , rTOCPropertySet(rPropSet)
50 : {
51 0 : }
52 :
53 :
54 0 : XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext()
55 : {
56 0 : }
57 :
58 0 : void XMLIndexTitleTemplateContext::StartElement(
59 : const Reference<XAttributeList> & xAttrList)
60 : {
61 : // there's only one attribute: style-name
62 0 : sal_Int16 nLength = xAttrList->getLength();
63 0 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
64 : {
65 0 : OUString sLocalName;
66 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
67 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
68 0 : &sLocalName );
69 0 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
70 0 : (IsXMLToken(sLocalName, XML_STYLE_NAME)) )
71 : {
72 0 : sStyleName = xAttrList->getValueByIndex(nAttr);
73 0 : OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
74 0 : XML_STYLE_FAMILY_TEXT_PARAGRAPH, sStyleName );
75 : const Reference < ::com::sun::star::container::XNameContainer >&
76 0 : rStyles = GetImport().GetTextImport()->GetParaStyles();
77 0 : bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
78 : }
79 0 : }
80 0 : }
81 :
82 0 : void XMLIndexTitleTemplateContext::EndElement()
83 : {
84 0 : Any aAny;
85 :
86 0 : aAny <<= sContent.makeStringAndClear();
87 0 : rTOCPropertySet->setPropertyValue(sTitle, aAny);
88 :
89 0 : if (bStyleNameOK)
90 : {
91 0 : aAny <<= GetImport().GetStyleDisplayName(
92 : XML_STYLE_FAMILY_TEXT_PARAGRAPH,
93 0 : sStyleName );
94 0 : rTOCPropertySet->setPropertyValue(sParaStyleHeading, aAny);
95 0 : }
96 0 : }
97 :
98 0 : void XMLIndexTitleTemplateContext::Characters(
99 : const OUString& sString)
100 : {
101 0 : sContent.append(sString);
102 0 : }
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|