xref: /trunk/main/xmloff/source/text/XMLIndexTitleTemplateContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLIndexTitleTemplateContext.hxx"
31 #include <xmloff/xmlictxt.hxx>
32 #include <xmloff/xmlimp.hxx>
33 #include <xmloff/nmspmap.hxx>
34 #include "xmloff/xmlnmspe.hxx"
35 #include <xmloff/xmltoken.hxx>
36 
37 
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 using ::com::sun::star::beans::XPropertySet;
41 using ::com::sun::star::uno::Any;
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::xml::sax::XAttributeList;
44 using ::xmloff::token::IsXMLToken;
45 using ::xmloff::token::XML_STYLE_NAME;
46 
47 
48 const sal_Char sAPI_Title[] = "Title";
49 const sal_Char sAPI_ParaStyleHeading[] = "ParaStyleHeading";
50 
51 
52 TYPEINIT1( XMLIndexTitleTemplateContext, SvXMLImportContext );
53 
54 XMLIndexTitleTemplateContext::XMLIndexTitleTemplateContext(
55     SvXMLImport& rImport,
56     Reference<XPropertySet> & rPropSet,
57     sal_uInt16 nPrfx,
58     const OUString& rLocalName)
59 :   SvXMLImportContext(rImport, nPrfx, rLocalName)
60 ,   sTitle(RTL_CONSTASCII_USTRINGPARAM(sAPI_Title))
61 ,   sParaStyleHeading(RTL_CONSTASCII_USTRINGPARAM(sAPI_ParaStyleHeading))
62 ,   bStyleNameOK(sal_False)
63 ,   rTOCPropertySet(rPropSet)
64 {
65 }
66 
67 
68 XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext()
69 {
70 }
71 
72 void XMLIndexTitleTemplateContext::StartElement(
73     const Reference<XAttributeList> & xAttrList)
74 {
75     // there's only one attribute: style-name
76     sal_Int16 nLength = xAttrList->getLength();
77     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
78     {
79         OUString sLocalName;
80         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
81             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
82                               &sLocalName );
83         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
84              (IsXMLToken(sLocalName, XML_STYLE_NAME)) )
85         {
86             sStyleName = xAttrList->getValueByIndex(nAttr);
87             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
88                 XML_STYLE_FAMILY_TEXT_PARAGRAPH, sStyleName );
89             const Reference < ::com::sun::star::container::XNameContainer >&
90                 rStyles = GetImport().GetTextImport()->GetParaStyles();
91             bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
92         }
93     }
94 }
95 
96 void XMLIndexTitleTemplateContext::EndElement()
97 {
98     Any aAny;
99 
100     aAny <<= sContent.makeStringAndClear();
101     rTOCPropertySet->setPropertyValue(sTitle, aAny);
102 
103     if (bStyleNameOK)
104     {
105         aAny <<= GetImport().GetStyleDisplayName(
106                                 XML_STYLE_FAMILY_TEXT_PARAGRAPH,
107                                 sStyleName );
108         rTOCPropertySet->setPropertyValue(sParaStyleHeading, aAny);
109     }
110 }
111 
112 void XMLIndexTitleTemplateContext::Characters(
113     const OUString& sString)
114 {
115     sContent.append(sString);
116 }
117