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 "XMLIndexTableSourceContext.hxx" 29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 30cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TEXT_REFERENCEFIELD_PART_HPP 33cdf0e10cSrcweir #include <com/sun/star/text/ReferenceFieldPart.hpp> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #include "XMLIndexTemplateContext.hxx" 36cdf0e10cSrcweir #include "XMLIndexTitleTemplateContext.hxx" 37cdf0e10cSrcweir #include "XMLIndexTOCStylesContext.hxx" 38cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx> 39cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 40cdf0e10cSrcweir #include <xmloff/txtimp.hxx> 41cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 42cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 43cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 44cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 45cdf0e10cSrcweir #include <tools/debug.hxx> 46cdf0e10cSrcweir #include <rtl/ustring.hxx> 47cdf0e10cSrcweir 48cdf0e10cSrcweir 49cdf0e10cSrcweir using namespace ::com::sun::star::text; 50cdf0e10cSrcweir using namespace ::xmloff::token; 51cdf0e10cSrcweir 52cdf0e10cSrcweir using ::rtl::OUString; 53cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 54cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 55cdf0e10cSrcweir using ::com::sun::star::uno::Any; 56cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList; 57cdf0e10cSrcweir 58cdf0e10cSrcweir const sal_Char sAPI_CreateFromLabels[] = "CreateFromLabels"; 59cdf0e10cSrcweir const sal_Char sAPI_LabelCategory[] = "LabelCategory"; 60cdf0e10cSrcweir const sal_Char sAPI_LabelDisplayType[] = "LabelDisplayType"; 61cdf0e10cSrcweir 62cdf0e10cSrcweir 63cdf0e10cSrcweir TYPEINIT1(XMLIndexTableSourceContext, XMLIndexSourceBaseContext); 64cdf0e10cSrcweir 65cdf0e10cSrcweir 66cdf0e10cSrcweir XMLIndexTableSourceContext::XMLIndexTableSourceContext( 67cdf0e10cSrcweir SvXMLImport& rImport, 68cdf0e10cSrcweir sal_uInt16 nPrfx, 69cdf0e10cSrcweir const OUString& rLocalName, 70cdf0e10cSrcweir Reference<XPropertySet> & rPropSet) : 71cdf0e10cSrcweir XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName, 72cdf0e10cSrcweir rPropSet, sal_False), 73cdf0e10cSrcweir sCreateFromLabels(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLabels)), 74cdf0e10cSrcweir sLabelCategory(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelCategory)), 75cdf0e10cSrcweir sLabelDisplayType(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelDisplayType)), 76cdf0e10cSrcweir bSequenceOK(sal_False), 77cdf0e10cSrcweir bDisplayFormatOK(sal_False), 78cdf0e10cSrcweir bUseCaption(sal_True) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir XMLIndexTableSourceContext::~XMLIndexTableSourceContext() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir static SvXMLEnumMapEntry __READONLY_DATA lcl_aReferenceTypeTokenMap[] = 87cdf0e10cSrcweir { 88cdf0e10cSrcweir 89cdf0e10cSrcweir { XML_TEXT, ReferenceFieldPart::TEXT }, 90cdf0e10cSrcweir { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER }, 91cdf0e10cSrcweir { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION }, 92cdf0e10cSrcweir 93cdf0e10cSrcweir // wrong values that previous versions wrote: 94cdf0e10cSrcweir { XML_CHAPTER, ReferenceFieldPart::CATEGORY_AND_NUMBER }, 95cdf0e10cSrcweir { XML_PAGE, ReferenceFieldPart::ONLY_CAPTION }, 96cdf0e10cSrcweir 97cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 } 98cdf0e10cSrcweir }; 99cdf0e10cSrcweir 100cdf0e10cSrcweir void XMLIndexTableSourceContext::ProcessAttribute( 101cdf0e10cSrcweir enum IndexSourceParamEnum eParam, 102cdf0e10cSrcweir const OUString& rValue) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir sal_Bool bTmp; 105cdf0e10cSrcweir 106cdf0e10cSrcweir switch (eParam) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir case XML_TOK_INDEXSOURCE_USE_CAPTION: 109cdf0e10cSrcweir if (SvXMLUnitConverter::convertBool(bTmp, rValue)) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir bUseCaption = bTmp; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir break; 114cdf0e10cSrcweir 115cdf0e10cSrcweir case XML_TOK_INDEXSOURCE_SEQUENCE_NAME: 116cdf0e10cSrcweir sSequence = rValue; 117cdf0e10cSrcweir bSequenceOK = sal_True; 118cdf0e10cSrcweir break; 119cdf0e10cSrcweir 120cdf0e10cSrcweir case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT: 121cdf0e10cSrcweir { 122cdf0e10cSrcweir sal_uInt16 nTmp; 123cdf0e10cSrcweir if (SvXMLUnitConverter::convertEnum(nTmp, rValue, 124cdf0e10cSrcweir lcl_aReferenceTypeTokenMap)) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir nDisplayFormat = nTmp; 127cdf0e10cSrcweir bDisplayFormatOK = sal_True; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir break; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir default: 133cdf0e10cSrcweir XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue); 134cdf0e10cSrcweir break; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir 139cdf0e10cSrcweir void XMLIndexTableSourceContext::EndElement() 140cdf0e10cSrcweir { 141cdf0e10cSrcweir Any aAny; 142cdf0e10cSrcweir 143cdf0e10cSrcweir aAny.setValue(&bUseCaption, ::getBooleanCppuType()); 144cdf0e10cSrcweir rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny); 145cdf0e10cSrcweir 146cdf0e10cSrcweir if (bSequenceOK) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir aAny <<= sSequence; 149cdf0e10cSrcweir rIndexPropertySet->setPropertyValue(sLabelCategory, aAny); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir if (bDisplayFormatOK) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir aAny <<= nDisplayFormat; 155cdf0e10cSrcweir rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir XMLIndexSourceBaseContext::EndElement(); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir 162cdf0e10cSrcweir SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext( 163cdf0e10cSrcweir sal_uInt16 nPrefix, 164cdf0e10cSrcweir const OUString& rLocalName, 165cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir if ( ( XML_NAMESPACE_TEXT == nPrefix ) && 168cdf0e10cSrcweir ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet, 171cdf0e10cSrcweir nPrefix, rLocalName, 172cdf0e10cSrcweir aLevelNameTableMap, 173cdf0e10cSrcweir XML_TOKEN_INVALID, // no outline-level attr 174cdf0e10cSrcweir aLevelStylePropNameTableMap, 175cdf0e10cSrcweir aAllowedTokenTypesTable); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir else 178cdf0e10cSrcweir { 179cdf0e10cSrcweir return XMLIndexSourceBaseContext::CreateChildContext(nPrefix, 180cdf0e10cSrcweir rLocalName, 181cdf0e10cSrcweir xAttrList); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir } 185