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 27 28 #include "XMLIndexChapterInfoEntryContext.hxx" 29 #include "XMLIndexTemplateContext.hxx" 30 #include <xmloff/xmlictxt.hxx> 31 #include <xmloff/xmlimp.hxx> 32 #include <xmloff/txtimp.hxx> 33 #include <xmloff/nmspmap.hxx> 34 #include "xmloff/xmlnmspe.hxx" 35 #include <xmloff/xmltoken.hxx> 36 #include <xmloff/xmluconv.hxx> 37 #include <com/sun/star/text/ChapterFormat.hpp> 38 39 40 using namespace ::com::sun::star::text; 41 using namespace ::xmloff::token; 42 43 using ::rtl::OUString; 44 using ::com::sun::star::beans::PropertyValue; 45 using ::com::sun::star::beans::PropertyValues; 46 using ::com::sun::star::uno::Reference; 47 using ::com::sun::star::uno::Sequence; 48 using ::com::sun::star::uno::Any; 49 using ::com::sun::star::xml::sax::XAttributeList; 50 51 52 53 TYPEINIT1( XMLIndexChapterInfoEntryContext, XMLIndexSimpleEntryContext); 54 55 XMLIndexChapterInfoEntryContext::XMLIndexChapterInfoEntryContext( 56 SvXMLImport& rImport, 57 XMLIndexTemplateContext& rTemplate, 58 sal_uInt16 nPrfx, 59 const OUString& rLocalName, 60 sal_Bool bT ) : 61 XMLIndexSimpleEntryContext(rImport, 62 (bT ? rTemplate.sTokenEntryNumber 63 : rTemplate.sTokenChapterInfo), 64 rTemplate, nPrfx, rLocalName), 65 nChapterInfo(ChapterFormat::NAME_NUMBER), 66 bChapterInfoOK(sal_False), 67 bTOC( bT ), 68 nOutlineLevel( 0 ), 69 bOutlineLevelOK(sal_False) 70 { 71 } 72 73 XMLIndexChapterInfoEntryContext::~XMLIndexChapterInfoEntryContext() 74 { 75 } 76 77 static const SvXMLEnumMapEntry aChapterDisplayMap[] = 78 { 79 { XML_NAME, ChapterFormat::NAME }, 80 { XML_NUMBER, ChapterFormat::NUMBER }, 81 { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER }, 82 //---> i89791 83 // enabled for ODF 1.2, full index support in 3.0 84 { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX }, 85 //<--- 86 { XML_PLAIN_NUMBER, ChapterFormat::DIGIT }, 87 { XML_TOKEN_INVALID, 0 } 88 }; 89 90 void XMLIndexChapterInfoEntryContext::StartElement( 91 const Reference<XAttributeList> & xAttrList) 92 { 93 // handle both, style name and bibliography info 94 sal_Int16 nLength = xAttrList->getLength(); 95 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) 96 { 97 OUString sLocalName; 98 sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 99 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), 100 &sLocalName ); 101 if (XML_NAMESPACE_TEXT == nPrefix) 102 { 103 if ( IsXMLToken( sLocalName, XML_STYLE_NAME ) ) 104 { 105 sCharStyleName = xAttrList->getValueByIndex(nAttr); 106 bCharStyleNameOK = sal_True; 107 } 108 else if ( IsXMLToken( sLocalName, XML_DISPLAY ) )//i53420, always true, in TOC as well 109 { 110 sal_uInt16 nTmp; 111 if (SvXMLUnitConverter::convertEnum( 112 nTmp, xAttrList->getValueByIndex(nAttr), 113 aChapterDisplayMap)) 114 { 115 nChapterInfo = nTmp; 116 bChapterInfoOK = sal_True; 117 } 118 } 119 else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) ) 120 { 121 sal_Int32 nTmp; 122 123 if (SvXMLUnitConverter::convertNumber(nTmp, xAttrList->getValueByIndex(nAttr))) 124 { 125 //control on range is carried out in the UNO level 126 nOutlineLevel = static_cast<sal_uInt16>(nTmp); 127 bOutlineLevelOK = sal_True; 128 } 129 } 130 } 131 } 132 133 // if we have a style name, set it! 134 if (bCharStyleNameOK) 135 { 136 nValues++; 137 } 138 139 // if we have chaper info, set it! 140 if (bChapterInfoOK) 141 { 142 nValues++; 143 // --> OD 2008-06-26 #i89791# 144 if ( !bTOC ) 145 { 146 bool bConvert( false ); 147 { 148 sal_Int32 nUPD( 0 ); 149 sal_Int32 nBuild( 0 ); 150 const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild ); 151 if ( GetImport().IsTextDocInOOoFileFormat() || 152 ( bBuildIdFound && 153 ( nUPD== 680 || nUPD == 645 || nUPD == 641 ) ) ) 154 { 155 bConvert = true; 156 } 157 } 158 if ( bConvert ) 159 { 160 if ( nChapterInfo == ChapterFormat::NUMBER ) 161 { 162 nChapterInfo = ChapterFormat::DIGIT; 163 } 164 else if ( nChapterInfo == ChapterFormat::NAME_NUMBER ) 165 { 166 nChapterInfo = ChapterFormat::NO_PREFIX_SUFFIX; 167 } 168 } 169 } 170 // <-- 171 } 172 if (bOutlineLevelOK) 173 nValues++; 174 } 175 176 void XMLIndexChapterInfoEntryContext::FillPropertyValues( 177 ::com::sun::star::uno::Sequence< 178 ::com::sun::star::beans::PropertyValue> & rValues) 179 { 180 // entry name and (optionally) style name in parent class 181 XMLIndexSimpleEntryContext::FillPropertyValues(rValues); 182 183 sal_Int32 nIndex = bCharStyleNameOK ? 2 : 1; 184 185 if( bChapterInfoOK ) 186 { 187 // chapter info field 188 rValues[nIndex].Name = rTemplateContext.sChapterFormat; 189 Any aAny; 190 aAny <<= nChapterInfo; 191 rValues[nIndex].Value = aAny; 192 nIndex++; 193 } 194 if( bOutlineLevelOK ) 195 { 196 rValues[nIndex].Name = rTemplateContext.sChapterLevel; 197 Any aAny; 198 aAny <<= nOutlineLevel; 199 rValues[nIndex].Value = aAny; 200 } 201 } 202