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