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