1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include <tools/debug.hxx> 27cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 28cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 29cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 30cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 31cdf0e10cSrcweir #include "txtparai.hxx" 32cdf0e10cSrcweir #include "txtlists.hxx" 33cdf0e10cSrcweir #include "XMLTextListBlockContext.hxx" 34cdf0e10cSrcweir #include <xmloff/txtimp.hxx> 35cdf0e10cSrcweir // --> OD 2008-05-08 #refactorlists# 36cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 37cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp> 38cdf0e10cSrcweir #include <xmloff/xmlnumi.hxx> 39cdf0e10cSrcweir // <-- 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include "XMLTextListItemContext.hxx" 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir using ::rtl::OUString; 45cdf0e10cSrcweir using ::rtl::OUStringBuffer; 46cdf0e10cSrcweir 47cdf0e10cSrcweir using namespace ::com::sun::star; 48cdf0e10cSrcweir using namespace ::com::sun::star::uno; 49cdf0e10cSrcweir using namespace ::xmloff::token; 50cdf0e10cSrcweir 51cdf0e10cSrcweir TYPEINIT1( XMLTextListItemContext, SvXMLImportContext ); 52cdf0e10cSrcweir 53cdf0e10cSrcweir XMLTextListItemContext::XMLTextListItemContext( 54cdf0e10cSrcweir SvXMLImport& rImport, 55cdf0e10cSrcweir XMLTextImportHelper& rTxtImp, 56cdf0e10cSrcweir const sal_uInt16 nPrfx, 57cdf0e10cSrcweir const OUString& rLName, 58cdf0e10cSrcweir const Reference< xml::sax::XAttributeList > & xAttrList, 59cdf0e10cSrcweir const sal_Bool bIsHeader ) 60cdf0e10cSrcweir : SvXMLImportContext( rImport, nPrfx, rLName ), 61cdf0e10cSrcweir rTxtImport( rTxtImp ), 62cdf0e10cSrcweir nStartValue( -1 ), 63cdf0e10cSrcweir // --> OD 2008-05-07 #refactorlists# 64cdf0e10cSrcweir mnSubListCount( 0 ), 65cdf0e10cSrcweir mxNumRulesOverride() 66cdf0e10cSrcweir // <-- 67cdf0e10cSrcweir { 68cdf0e10cSrcweir static ::rtl::OUString s_NumberingRules( 69cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("NumberingRules")); 70cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 71cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir const OUString& rAttrName = xAttrList->getNameByIndex( i ); 74cdf0e10cSrcweir const OUString& rValue = xAttrList->getValueByIndex( i ); 75cdf0e10cSrcweir 76cdf0e10cSrcweir OUString aLocalName; 77cdf0e10cSrcweir sal_uInt16 nPrefix = 78cdf0e10cSrcweir GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, 79cdf0e10cSrcweir &aLocalName ); 80cdf0e10cSrcweir if( !bIsHeader && XML_NAMESPACE_TEXT == nPrefix && 81cdf0e10cSrcweir IsXMLToken( aLocalName, XML_START_VALUE ) ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir sal_Int32 nTmp = rValue.toInt32(); 84cdf0e10cSrcweir if( nTmp >= 0 && nTmp <= SHRT_MAX ) 85cdf0e10cSrcweir nStartValue = (sal_Int16)nTmp; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir // --> OD 2008-05-08 #refactorlists# 88cdf0e10cSrcweir else if ( nPrefix == XML_NAMESPACE_TEXT && 89cdf0e10cSrcweir IsXMLToken( aLocalName, XML_STYLE_OVERRIDE ) ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir const ::rtl::OUString sListStyleOverrideName = rValue; 92cdf0e10cSrcweir if ( sListStyleOverrideName.getLength() > 0 ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir OUString sDisplayStyleName( 95cdf0e10cSrcweir GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST, 96cdf0e10cSrcweir sListStyleOverrideName ) ); 97cdf0e10cSrcweir const Reference < container::XNameContainer >& rNumStyles = 98cdf0e10cSrcweir rTxtImp.GetNumberingStyles(); 99cdf0e10cSrcweir if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir Reference < style::XStyle > xStyle; 102cdf0e10cSrcweir Any aAny = rNumStyles->getByName( sDisplayStyleName ); 103cdf0e10cSrcweir aAny >>= xStyle; 104cdf0e10cSrcweir 105cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY ); 106cdf0e10cSrcweir aAny = xPropSet->getPropertyValue(s_NumberingRules); 107cdf0e10cSrcweir aAny >>= mxNumRulesOverride; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir else 110cdf0e10cSrcweir { 111cdf0e10cSrcweir const SvxXMLListStyleContext* pListStyle = 112cdf0e10cSrcweir rTxtImp.FindAutoListStyle( sListStyleOverrideName ); 113cdf0e10cSrcweir if( pListStyle ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir mxNumRulesOverride = pListStyle->GetNumRules(); 116cdf0e10cSrcweir if( !mxNumRulesOverride.is() ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir pListStyle->CreateAndInsertAuto(); 119cdf0e10cSrcweir mxNumRulesOverride = pListStyle->GetNumRules(); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir } 125cdf0e10cSrcweir // <-- 126cdf0e10cSrcweir else if ( (XML_NAMESPACE_XML == nPrefix) && 127cdf0e10cSrcweir IsXMLToken(aLocalName, XML_ID) ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir (void) rValue; 130cdf0e10cSrcweir //FIXME: there is no UNO API for list items 131cdf0e10cSrcweir } 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir // If this is a <text:list-item> element, then remember it as a sign 135cdf0e10cSrcweir // that a bullet has to be generated. 136cdf0e10cSrcweir if( !bIsHeader ) { 137cdf0e10cSrcweir rTxtImport.GetTextListHelper().SetListItem( this ); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir XMLTextListItemContext::~XMLTextListItemContext() 143cdf0e10cSrcweir { 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir void XMLTextListItemContext::EndElement() 147cdf0e10cSrcweir { 148cdf0e10cSrcweir // finish current list item 149cdf0e10cSrcweir rTxtImport.GetTextListHelper().SetListItem( 0 ); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir SvXMLImportContext *XMLTextListItemContext::CreateChildContext( 153cdf0e10cSrcweir sal_uInt16 nPrefix, 154cdf0e10cSrcweir const OUString& rLocalName, 155cdf0e10cSrcweir const Reference< xml::sax::XAttributeList > & xAttrList ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir SvXMLImportContext *pContext = 0; 158cdf0e10cSrcweir 159cdf0e10cSrcweir const SvXMLTokenMap& rTokenMap = rTxtImport.GetTextElemTokenMap(); 160cdf0e10cSrcweir sal_Bool bHeading = sal_False; 161cdf0e10cSrcweir switch( rTokenMap.Get( nPrefix, rLocalName ) ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir case XML_TOK_TEXT_H: 164cdf0e10cSrcweir bHeading = sal_True; 165cdf0e10cSrcweir case XML_TOK_TEXT_P: 166cdf0e10cSrcweir pContext = new XMLParaContext( GetImport(), 167cdf0e10cSrcweir nPrefix, rLocalName, 168cdf0e10cSrcweir xAttrList, bHeading ); 169cdf0e10cSrcweir if (rTxtImport.IsProgress()) 170cdf0e10cSrcweir GetImport().GetProgressBarHelper()->Increment(); 171cdf0e10cSrcweir 172cdf0e10cSrcweir break; 173cdf0e10cSrcweir case XML_TOK_TEXT_LIST: 174cdf0e10cSrcweir // --> OD 2008-05-07 #refactorlists# 175cdf0e10cSrcweir // pContext = new XMLTextListBlockContext( GetImport(), rTxtImport, 176cdf0e10cSrcweir // nPrefix, rLocalName, 177cdf0e10cSrcweir // xAttrList ); 178cdf0e10cSrcweir ++mnSubListCount; 179cdf0e10cSrcweir pContext = new XMLTextListBlockContext( GetImport(), rTxtImport, 180cdf0e10cSrcweir nPrefix, rLocalName, 181cdf0e10cSrcweir xAttrList, 182cdf0e10cSrcweir (mnSubListCount > 1) ); 183cdf0e10cSrcweir // <-- 184cdf0e10cSrcweir break; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir if( !pContext ) 188cdf0e10cSrcweir pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 189cdf0e10cSrcweir 190cdf0e10cSrcweir return pContext; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir 194