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 #include "XMLLineNumberingImportContext.hxx" 27 #include "XMLLineNumberingSeparatorImportContext.hxx" 28 #include "com/sun/star/beans/XPropertySet.hpp" 29 #include "com/sun/star/text/XLineNumberingProperties.hpp" 30 #include <com/sun/star/style/LineNumberPosition.hpp> 31 #include <com/sun/star/style/NumberingType.hpp> 32 #include <xmloff/xmlimp.hxx> 33 #include <xmloff/xmluconv.hxx> 34 #include "xmloff/xmlnmspe.hxx" 35 #include <xmloff/nmspmap.hxx> 36 #include <xmloff/xmltoken.hxx> 37 #include <xmloff/xmlnumi.hxx> 38 39 40 using namespace ::com::sun::star; 41 using namespace ::com::sun::star::uno; 42 using namespace ::com::sun::star::style; 43 using namespace ::xmloff::token; 44 45 using ::com::sun::star::beans::XPropertySet; 46 using ::com::sun::star::xml::sax::XAttributeList; 47 using ::com::sun::star::text::XLineNumberingProperties; 48 using ::rtl::OUString; 49 50 TYPEINIT1( XMLLineNumberingImportContext, SvXMLStyleContext ); 51 52 53 XMLLineNumberingImportContext::XMLLineNumberingImportContext( 54 SvXMLImport& rImport, 55 sal_uInt16 nPrfx, 56 const OUString& rLocalName, 57 const Reference<XAttributeList> & xAttrList) 58 : SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG) 59 , sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")) 60 , sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines")) 61 , sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames")) 62 , sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance")) 63 , sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval")) 64 , sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText")) 65 , sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition")) 66 , sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")) 67 , sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn")) 68 , sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage")) 69 , sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval")) 70 , sNumFormat(GetXMLToken(XML_1)) 71 , sNumLetterSync(GetXMLToken(XML_FALSE)) 72 , nOffset(-1) 73 , nNumberPosition(style::LineNumberPosition::LEFT) 74 , nIncrement(-1) 75 , nSeparatorIncrement(-1) 76 , bNumberLines(sal_True) 77 , bCountEmptyLines(sal_True) 78 , bCountInFloatingFrames(sal_False) 79 , bRestartNumbering(sal_False) 80 { 81 } 82 83 XMLLineNumberingImportContext::~XMLLineNumberingImportContext() 84 { 85 } 86 87 void XMLLineNumberingImportContext::StartElement( 88 const Reference<XAttributeList> & xAttrList) 89 { 90 static SvXMLTokenMapEntry aLineNumberingTokenMap[] = 91 { 92 { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_LINENUMBERING_STYLE_NAME }, 93 { XML_NAMESPACE_TEXT, XML_NUMBER_LINES, 94 XML_TOK_LINENUMBERING_NUMBER_LINES }, 95 { XML_NAMESPACE_TEXT, XML_COUNT_EMPTY_LINES, 96 XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES }, 97 { XML_NAMESPACE_TEXT, XML_COUNT_IN_TEXT_BOXES, 98 XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES }, 99 { XML_NAMESPACE_TEXT, XML_RESTART_ON_PAGE, 100 XML_TOK_LINENUMBERING_RESTART_NUMBERING }, 101 { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_LINENUMBERING_OFFSET }, 102 { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_LINENUMBERING_NUM_FORMAT }, 103 { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, 104 XML_TOK_LINENUMBERING_NUM_LETTER_SYNC }, 105 { XML_NAMESPACE_TEXT, XML_NUMBER_POSITION, 106 XML_TOK_LINENUMBERING_NUMBER_POSITION }, 107 { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT }, 108 // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION, 109 // XML_TOK_LINENUMBERING_LINENUMBERING_CONFIGURATION }, 110 // { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT }, 111 // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_SEPARATOR, 112 // XML_TOK_LINENUMBERING_LINENUMBERING_SEPARATOR }, 113 114 XML_TOKEN_MAP_END 115 }; 116 117 SvXMLTokenMap aTokenMap(aLineNumberingTokenMap); 118 119 // process attributes 120 sal_Int16 nLength = xAttrList->getLength(); 121 for(sal_Int16 i=0; i<nLength; i++) 122 { 123 OUString sLocalName; 124 sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 125 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); 126 127 ProcessAttribute( 128 (enum LineNumberingToken)aTokenMap.Get(nPrefix, sLocalName), 129 xAttrList->getValueByIndex(i)); 130 } 131 } 132 133 void XMLLineNumberingImportContext::ProcessAttribute( 134 enum LineNumberingToken eToken, 135 OUString sValue) 136 { 137 sal_Bool bTmp; 138 sal_Int32 nTmp; 139 140 switch (eToken) 141 { 142 case XML_TOK_LINENUMBERING_STYLE_NAME: 143 sStyleName = sValue; 144 break; 145 146 case XML_TOK_LINENUMBERING_NUMBER_LINES: 147 if (SvXMLUnitConverter::convertBool(bTmp, sValue)) 148 { 149 bNumberLines = bTmp; 150 } 151 break; 152 153 case XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES: 154 if (SvXMLUnitConverter::convertBool(bTmp, sValue)) 155 { 156 bCountEmptyLines = bTmp; 157 } 158 break; 159 160 case XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES: 161 if (SvXMLUnitConverter::convertBool(bTmp, sValue)) 162 { 163 bCountInFloatingFrames = bTmp; 164 } 165 break; 166 167 case XML_TOK_LINENUMBERING_RESTART_NUMBERING: 168 if (SvXMLUnitConverter::convertBool(bTmp, sValue)) 169 { 170 bRestartNumbering = bTmp; 171 } 172 break; 173 174 case XML_TOK_LINENUMBERING_OFFSET: 175 if (GetImport().GetMM100UnitConverter(). 176 convertMeasure(nTmp, sValue)) 177 { 178 nOffset = nTmp; 179 } 180 break; 181 182 case XML_TOK_LINENUMBERING_NUM_FORMAT: 183 sNumFormat = sValue; 184 break; 185 186 case XML_TOK_LINENUMBERING_NUM_LETTER_SYNC: 187 sNumLetterSync = sValue; 188 break; 189 190 case XML_TOK_LINENUMBERING_NUMBER_POSITION: 191 { 192 static const SvXMLEnumMapEntry aLineNumberPositionMap[] = 193 { 194 { XML_LEFT, style::LineNumberPosition::LEFT }, 195 { XML_RIGHT, style::LineNumberPosition::RIGHT }, 196 { XML_INSIDE, style::LineNumberPosition::INSIDE }, 197 { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE }, 198 { XML_TOKEN_INVALID, 0 } 199 }; 200 201 sal_uInt16 nTmp16; 202 if (SvXMLUnitConverter::convertEnum(nTmp16, sValue, 203 aLineNumberPositionMap)) 204 { 205 nNumberPosition = nTmp16; 206 } 207 break; 208 } 209 210 case XML_TOK_LINENUMBERING_INCREMENT: 211 if (SvXMLUnitConverter::convertNumber(nTmp, sValue, 0)) 212 { 213 nIncrement = (sal_Int16)nTmp; 214 } 215 break; 216 } 217 } 218 219 void XMLLineNumberingImportContext::CreateAndInsert(sal_Bool) 220 { 221 // insert and block mode is handled in insertStyleFamily 222 223 // we'll try to get the LineNumberingProperties 224 Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(), 225 UNO_QUERY); 226 if (xSupplier.is()) 227 { 228 Reference<XPropertySet> xLineNumbering = 229 xSupplier->getLineNumberingProperties(); 230 231 if (xLineNumbering.is()) 232 { 233 Any aAny; 234 235 // set style name (if it exists) 236 if ( GetImport().GetStyles()->FindStyleChildContext( 237 XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ) != NULL ) 238 { 239 aAny <<= GetImport().GetStyleDisplayName( 240 XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ); 241 xLineNumbering->setPropertyValue(sCharStyleName, aAny); 242 } 243 244 aAny <<= sSeparator; 245 xLineNumbering->setPropertyValue(sSeparatorText, aAny); 246 247 aAny <<= nOffset; 248 xLineNumbering->setPropertyValue(sDistance, aAny); 249 250 aAny <<= nNumberPosition; 251 xLineNumbering->setPropertyValue(sNumberPosition, aAny); 252 253 if (nIncrement >= 0) 254 { 255 aAny <<= nIncrement; 256 xLineNumbering->setPropertyValue(sInterval, aAny); 257 } 258 259 if (nSeparatorIncrement >= 0) 260 { 261 aAny <<= nSeparatorIncrement; 262 xLineNumbering->setPropertyValue(sSeparatorInterval, aAny); 263 } 264 265 aAny.setValue(&bNumberLines, ::getBooleanCppuType()); 266 xLineNumbering->setPropertyValue(sIsOn, aAny); 267 268 aAny.setValue(&bCountEmptyLines, ::getBooleanCppuType()); 269 xLineNumbering->setPropertyValue(sCountEmptyLines, aAny); 270 271 aAny.setValue(&bCountInFloatingFrames, ::getBooleanCppuType()); 272 xLineNumbering->setPropertyValue(sCountLinesInFrames, aAny); 273 274 aAny.setValue(&bRestartNumbering, ::getBooleanCppuType()); 275 xLineNumbering->setPropertyValue(sRestartAtEachPage, aAny); 276 277 sal_Int16 nNumType = NumberingType::ARABIC; 278 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, 279 sNumFormat, 280 sNumLetterSync ); 281 aAny <<= nNumType; 282 xLineNumbering->setPropertyValue(sNumberingType, aAny); 283 } 284 } 285 } 286 287 SvXMLImportContext* XMLLineNumberingImportContext::CreateChildContext( 288 sal_uInt16 nPrefix, 289 const OUString& rLocalName, 290 const Reference<XAttributeList> & xAttrList ) 291 { 292 if ( (nPrefix == XML_NAMESPACE_TEXT) && 293 IsXMLToken(rLocalName, XML_LINENUMBERING_SEPARATOR) ) 294 { 295 return new XMLLineNumberingSeparatorImportContext(GetImport(), 296 nPrefix, rLocalName, 297 *this); 298 } 299 else 300 { 301 // unknown element: default context 302 return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, 303 xAttrList); 304 } 305 } 306 307 void XMLLineNumberingImportContext::SetSeparatorText( 308 const OUString& sText) 309 { 310 sSeparator = sText; 311 } 312 313 void XMLLineNumberingImportContext::SetSeparatorIncrement( 314 sal_Int16 nIncr) 315 { 316 nSeparatorIncrement = nIncr; 317 } 318 319