1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLIndexTitleTemplateContext.hxx"
27 #include <xmloff/xmlictxt.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include "xmloff/xmlnmspe.hxx"
31 #include <xmloff/xmltoken.hxx>
32 
33 
34 using ::rtl::OUString;
35 using ::rtl::OUStringBuffer;
36 using ::com::sun::star::beans::XPropertySet;
37 using ::com::sun::star::uno::Any;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::xml::sax::XAttributeList;
40 using ::xmloff::token::IsXMLToken;
41 using ::xmloff::token::XML_STYLE_NAME;
42 
43 
44 const sal_Char sAPI_Title[] = "Title";
45 const sal_Char sAPI_ParaStyleHeading[] = "ParaStyleHeading";
46 
47 
48 TYPEINIT1( XMLIndexTitleTemplateContext, SvXMLImportContext );
49 
XMLIndexTitleTemplateContext(SvXMLImport & rImport,Reference<XPropertySet> & rPropSet,sal_uInt16 nPrfx,const OUString & rLocalName)50 XMLIndexTitleTemplateContext::XMLIndexTitleTemplateContext(
51 	SvXMLImport& rImport,
52 	Reference<XPropertySet> & rPropSet,
53 	sal_uInt16 nPrfx,
54 	const OUString& rLocalName)
55 :	SvXMLImportContext(rImport, nPrfx, rLocalName)
56 ,	sTitle(RTL_CONSTASCII_USTRINGPARAM(sAPI_Title))
57 ,	sParaStyleHeading(RTL_CONSTASCII_USTRINGPARAM(sAPI_ParaStyleHeading))
58 ,	bStyleNameOK(sal_False)
59 ,	rTOCPropertySet(rPropSet)
60 {
61 }
62 
63 
~XMLIndexTitleTemplateContext()64 XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext()
65 {
66 }
67 
StartElement(const Reference<XAttributeList> & xAttrList)68 void XMLIndexTitleTemplateContext::StartElement(
69 	const Reference<XAttributeList> & xAttrList)
70 {
71 	// there's only one attribute: style-name
72 	sal_Int16 nLength = xAttrList->getLength();
73 	for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
74 	{
75 		OUString sLocalName;
76 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
77 			GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
78 							  &sLocalName );
79 		if ( (XML_NAMESPACE_TEXT == nPrefix) &&
80 			 (IsXMLToken(sLocalName, XML_STYLE_NAME)) )
81 		{
82 			sStyleName = xAttrList->getValueByIndex(nAttr);
83             OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
84                 XML_STYLE_FAMILY_TEXT_PARAGRAPH, sStyleName );
85             const Reference < ::com::sun::star::container::XNameContainer >&
86                 rStyles = GetImport().GetTextImport()->GetParaStyles();
87             bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
88 		}
89 	}
90 }
91 
EndElement()92 void XMLIndexTitleTemplateContext::EndElement()
93 {
94 	Any aAny;
95 
96 	aAny <<= sContent.makeStringAndClear();
97 	rTOCPropertySet->setPropertyValue(sTitle, aAny);
98 
99 	if (bStyleNameOK)
100 	{
101 		aAny <<= GetImport().GetStyleDisplayName(
102 								XML_STYLE_FAMILY_TEXT_PARAGRAPH,
103 								sStyleName );
104 		rTOCPropertySet->setPropertyValue(sParaStyleHeading, aAny);
105 	}
106 }
107 
Characters(const OUString & sString)108 void XMLIndexTitleTemplateContext::Characters(
109 	const OUString& sString)
110 {
111 	sContent.append(sString);
112 }
113