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 <tools/debug.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <xmloff/nmspmap.hxx>
29 #include "xmloff/xmlnmspe.hxx"
30 #include <xmloff/xmltoken.hxx>
31 #include "txtparai.hxx"
32 #include "txtlists.hxx"
33 #include "XMLTextListBlockContext.hxx"
34 #include <xmloff/txtimp.hxx>
35 // --> OD 2008-05-08 #refactorlists#
36 #include <com/sun/star/container/XNameContainer.hpp>
37 #include <com/sun/star/style/XStyle.hpp>
38 #include <xmloff/xmlnumi.hxx>
39 // <--
40 
41 #include "XMLTextListItemContext.hxx"
42 
43 
44 using ::rtl::OUString;
45 using ::rtl::OUStringBuffer;
46 
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::uno;
49 using namespace ::xmloff::token;
50 
51 TYPEINIT1( XMLTextListItemContext, SvXMLImportContext );
52 
XMLTextListItemContext(SvXMLImport & rImport,XMLTextImportHelper & rTxtImp,const sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,const sal_Bool bIsHeader)53 XMLTextListItemContext::XMLTextListItemContext(
54                         SvXMLImport& rImport,
55                         XMLTextImportHelper& rTxtImp,
56                         const sal_uInt16 nPrfx,
57                         const OUString& rLName,
58                         const Reference< xml::sax::XAttributeList > & xAttrList,
59                         const sal_Bool bIsHeader )
60     : SvXMLImportContext( rImport, nPrfx, rLName ),
61       rTxtImport( rTxtImp ),
62       nStartValue( -1 ),
63       // --> OD 2008-05-07 #refactorlists#
64       mnSubListCount( 0 ),
65       mxNumRulesOverride()
66       // <--
67 {
68     static ::rtl::OUString s_NumberingRules(
69         RTL_CONSTASCII_USTRINGPARAM("NumberingRules"));
70 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
71 	for( sal_Int16 i=0; i < nAttrCount; i++ )
72 	{
73 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
74 		const OUString& rValue = xAttrList->getValueByIndex( i );
75 
76 		OUString aLocalName;
77 		sal_uInt16 nPrefix =
78 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
79 															&aLocalName );
80 		if( !bIsHeader && XML_NAMESPACE_TEXT == nPrefix &&
81 			IsXMLToken( aLocalName, XML_START_VALUE ) )
82 		{
83 			sal_Int32 nTmp = rValue.toInt32();
84 			if( nTmp >= 0 && nTmp <= SHRT_MAX )
85 				nStartValue = (sal_Int16)nTmp;
86 		}
87         // --> OD 2008-05-08 #refactorlists#
88         else if ( nPrefix == XML_NAMESPACE_TEXT &&
89                   IsXMLToken( aLocalName, XML_STYLE_OVERRIDE ) )
90         {
91             const ::rtl::OUString sListStyleOverrideName = rValue;
92             if ( sListStyleOverrideName.getLength() > 0 )
93             {
94                 OUString sDisplayStyleName(
95                         GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
96                                                          sListStyleOverrideName ) );
97                 const Reference < container::XNameContainer >& rNumStyles =
98                                                     rTxtImp.GetNumberingStyles();
99                 if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
100                 {
101                     Reference < style::XStyle > xStyle;
102                     Any aAny = rNumStyles->getByName( sDisplayStyleName );
103                     aAny >>= xStyle;
104 
105                     uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY );
106                     aAny = xPropSet->getPropertyValue(s_NumberingRules);
107                     aAny >>= mxNumRulesOverride;
108                 }
109                 else
110                 {
111                     const SvxXMLListStyleContext* pListStyle =
112                                         rTxtImp.FindAutoListStyle( sListStyleOverrideName );
113                     if( pListStyle )
114                     {
115                         mxNumRulesOverride = pListStyle->GetNumRules();
116                         if( !mxNumRulesOverride.is() )
117                         {
118                             pListStyle->CreateAndInsertAuto();
119                             mxNumRulesOverride = pListStyle->GetNumRules();
120                         }
121                     }
122                 }
123             }
124         }
125         // <--
126 		else if ( (XML_NAMESPACE_XML == nPrefix) &&
127 			 IsXMLToken(aLocalName, XML_ID)   )
128 		{
129 			(void) rValue;
130 //FIXME: there is no UNO API for list items
131 		}
132 	}
133 
134 	// If this is a <text:list-item> element, then remember it as a sign
135 	// that a bullet has to be generated.
136 	if( !bIsHeader ) {
137 		rTxtImport.GetTextListHelper().SetListItem( this );
138     }
139 
140 }
141 
~XMLTextListItemContext()142 XMLTextListItemContext::~XMLTextListItemContext()
143 {
144 }
145 
EndElement()146 void XMLTextListItemContext::EndElement()
147 {
148 	// finish current list item
149 	rTxtImport.GetTextListHelper().SetListItem( 0 );
150 }
151 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)152 SvXMLImportContext *XMLTextListItemContext::CreateChildContext(
153 		sal_uInt16 nPrefix,
154 		const OUString& rLocalName,
155 		const Reference< xml::sax::XAttributeList > & xAttrList )
156 {
157 	SvXMLImportContext *pContext = 0;
158 
159 	const SvXMLTokenMap& rTokenMap = rTxtImport.GetTextElemTokenMap();
160 	sal_Bool bHeading = sal_False;
161 	switch( rTokenMap.Get( nPrefix, rLocalName ) )
162 	{
163 	case XML_TOK_TEXT_H:
164 		bHeading = sal_True;
165 	case XML_TOK_TEXT_P:
166 		pContext = new XMLParaContext( GetImport(),
167 									   nPrefix, rLocalName,
168 									   xAttrList, bHeading );
169         if (rTxtImport.IsProgress())
170             GetImport().GetProgressBarHelper()->Increment();
171 
172 		break;
173 	case XML_TOK_TEXT_LIST:
174         // --> OD 2008-05-07 #refactorlists#
175 //        pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
176 //                                            nPrefix, rLocalName,
177 //                                            xAttrList );
178         ++mnSubListCount;
179 		pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
180                                                 nPrefix, rLocalName,
181                                                 xAttrList,
182                                                 (mnSubListCount > 1) );
183         // <--
184 		break;
185 	}
186 
187 	if( !pContext )
188 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
189 
190 	return pContext;
191 }
192 
193 
194