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 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "XMLIndexTOCSourceContext.hxx" 29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 30cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp> 31cdf0e10cSrcweir #include "XMLIndexTemplateContext.hxx" 32cdf0e10cSrcweir #include "XMLIndexTitleTemplateContext.hxx" 33cdf0e10cSrcweir #include "XMLIndexTOCStylesContext.hxx" 34cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx> 35cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 36cdf0e10cSrcweir #include <xmloff/txtimp.hxx> 37cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 38cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 39cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 40cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 41cdf0e10cSrcweir #include <tools/debug.hxx> 42cdf0e10cSrcweir #include <rtl/ustring.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace ::xmloff::token; 47cdf0e10cSrcweir 48cdf0e10cSrcweir using ::rtl::OUString; 49cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 50cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 51cdf0e10cSrcweir using ::com::sun::star::uno::Any; 52cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList; 53cdf0e10cSrcweir 54cdf0e10cSrcweir const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter"; 55cdf0e10cSrcweir const sal_Char sAPI_CreateFromOutline[] = "CreateFromOutline"; 56cdf0e10cSrcweir const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks"; 57cdf0e10cSrcweir const sal_Char sAPI_Level[] = "Level"; 58cdf0e10cSrcweir const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles"; 59cdf0e10cSrcweir 60cdf0e10cSrcweir 61cdf0e10cSrcweir TYPEINIT1( XMLIndexTOCSourceContext, XMLIndexSourceBaseContext ); 62cdf0e10cSrcweir 63cdf0e10cSrcweir XMLIndexTOCSourceContext::XMLIndexTOCSourceContext( 64cdf0e10cSrcweir SvXMLImport& rImport, 65cdf0e10cSrcweir sal_uInt16 nPrfx, 66cdf0e10cSrcweir const OUString& rLocalName, 67cdf0e10cSrcweir Reference<XPropertySet> & rPropSet) 68cdf0e10cSrcweir : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, rPropSet, sal_True) 69cdf0e10cSrcweir , sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks)) 70cdf0e10cSrcweir , sLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_Level)) 71cdf0e10cSrcweir , sCreateFromOutline(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromOutline)) 72cdf0e10cSrcweir , sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLevelParagraphStyles)) 73cdf0e10cSrcweir // use all chapters by default 74cdf0e10cSrcweir , nOutlineLevel(rImport.GetTextImport()->GetChapterNumbering()->getCount()) 75cdf0e10cSrcweir , bUseOutline(sal_True) 76cdf0e10cSrcweir , bUseMarks(sal_True) 77cdf0e10cSrcweir , bUseParagraphStyles(sal_False) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir XMLIndexTOCSourceContext::~XMLIndexTOCSourceContext() 82cdf0e10cSrcweir { 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir void XMLIndexTOCSourceContext::ProcessAttribute( 86cdf0e10cSrcweir enum IndexSourceParamEnum eParam, 87cdf0e10cSrcweir const OUString& rValue) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir switch (eParam) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir case XML_TOK_INDEXSOURCE_OUTLINE_LEVEL: 92cdf0e10cSrcweir if ( IsXMLToken( rValue, XML_NONE ) ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir // #104651# use OUTLINE_LEVEL and USE_OUTLINE_LEVEL instead of 95cdf0e10cSrcweir // OUTLINE_LEVEL with values none|1..10. For backwards 96cdf0e10cSrcweir // compatibility, 'none' must still be read. 97cdf0e10cSrcweir bUseOutline = sal_False; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir else 100cdf0e10cSrcweir { 101cdf0e10cSrcweir sal_Int32 nTmp; 102cdf0e10cSrcweir if (SvXMLUnitConverter::convertNumber( 103cdf0e10cSrcweir nTmp, rValue, 1, GetImport().GetTextImport()-> 104cdf0e10cSrcweir GetChapterNumbering()->getCount())) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir bUseOutline = sal_True; 107cdf0e10cSrcweir nOutlineLevel = nTmp; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir break; 111cdf0e10cSrcweir 112cdf0e10cSrcweir case XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL: 113cdf0e10cSrcweir { 114cdf0e10cSrcweir sal_Bool bTmp; 115cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, rValue)) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir bUseOutline = bTmp; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir break; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir 123cdf0e10cSrcweir case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS: 124cdf0e10cSrcweir { 125cdf0e10cSrcweir sal_Bool bTmp; 126cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, rValue)) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir bUseMarks = bTmp; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir break; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES: 134cdf0e10cSrcweir { 135cdf0e10cSrcweir sal_Bool bTmp; 136cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, rValue)) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir bUseParagraphStyles = bTmp; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir break; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir default: 144cdf0e10cSrcweir // default: ask superclass 145cdf0e10cSrcweir XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue); 146cdf0e10cSrcweir break; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir void XMLIndexTOCSourceContext::EndElement() 151cdf0e10cSrcweir { 152cdf0e10cSrcweir Any aAny; 153cdf0e10cSrcweir 154cdf0e10cSrcweir aAny.setValue(&bUseMarks, ::getBooleanCppuType()); 155cdf0e10cSrcweir rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny); 156cdf0e10cSrcweir 157cdf0e10cSrcweir aAny.setValue(&bUseOutline, ::getBooleanCppuType()); 158cdf0e10cSrcweir rIndexPropertySet->setPropertyValue(sCreateFromOutline, aAny); 159cdf0e10cSrcweir 160cdf0e10cSrcweir aAny.setValue(&bUseParagraphStyles, ::getBooleanCppuType()); 161cdf0e10cSrcweir rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny); 162cdf0e10cSrcweir 163cdf0e10cSrcweir aAny <<= (sal_Int16)nOutlineLevel; 164cdf0e10cSrcweir rIndexPropertySet->setPropertyValue(sLevel, aAny); 165cdf0e10cSrcweir 166cdf0e10cSrcweir // process common attributes 167cdf0e10cSrcweir XMLIndexSourceBaseContext::EndElement(); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir 171cdf0e10cSrcweir SvXMLImportContext* XMLIndexTOCSourceContext::CreateChildContext( 172cdf0e10cSrcweir sal_uInt16 nPrefix, 173cdf0e10cSrcweir const OUString& rLocalName, 174cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir if ( (XML_NAMESPACE_TEXT == nPrefix) && 177cdf0e10cSrcweir IsXMLToken(rLocalName, XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE) ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, 180cdf0e10cSrcweir nPrefix, rLocalName, 181cdf0e10cSrcweir aLevelNameTOCMap, 182cdf0e10cSrcweir XML_OUTLINE_LEVEL, 183cdf0e10cSrcweir aLevelStylePropNameTOCMap, 184cdf0e10cSrcweir aAllowedTokenTypesTOC, sal_True ); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir else 187cdf0e10cSrcweir { 188cdf0e10cSrcweir return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, 189cdf0e10cSrcweir rLocalName, 190cdf0e10cSrcweir xAttrList); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193