1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 31 32 #include "XMLIndexSourceBaseContext.hxx" 33 #include <com/sun/star/beans/XPropertySet.hpp> 34 #include <com/sun/star/container/XIndexReplace.hpp> 35 #include "XMLIndexTemplateContext.hxx" 36 #include "XMLIndexTitleTemplateContext.hxx" 37 #include "XMLIndexTOCStylesContext.hxx" 38 #include <xmloff/xmlictxt.hxx> 39 #include <xmloff/xmlimp.hxx> 40 #include <xmloff/txtimp.hxx> 41 #include "xmloff/xmlnmspe.hxx" 42 #include <xmloff/nmspmap.hxx> 43 #include <xmloff/xmltoken.hxx> 44 #include <xmloff/xmluconv.hxx> 45 #include <tools/debug.hxx> 46 #include <rtl/ustring.hxx> 47 48 49 50 using namespace ::xmloff::token; 51 52 using ::rtl::OUString; 53 using ::com::sun::star::beans::XPropertySet; 54 using ::com::sun::star::uno::Reference; 55 using ::com::sun::star::uno::Any; 56 using ::com::sun::star::xml::sax::XAttributeList; 57 58 const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter"; 59 const sal_Char sAPI_IsRelativeTabstops[] = "IsRelativeTabstops"; 60 61 static __FAR_DATA SvXMLTokenMapEntry aIndexSourceTokenMap[] = 62 { 63 { XML_NAMESPACE_TEXT, 64 XML_OUTLINE_LEVEL, 65 XML_TOK_INDEXSOURCE_OUTLINE_LEVEL}, 66 { XML_NAMESPACE_TEXT, 67 XML_USE_INDEX_MARKS, 68 XML_TOK_INDEXSOURCE_USE_INDEX_MARKS }, 69 { XML_NAMESPACE_TEXT, 70 XML_INDEX_SCOPE, 71 XML_TOK_INDEXSOURCE_INDEX_SCOPE }, 72 { XML_NAMESPACE_TEXT, 73 XML_RELATIVE_TAB_STOP_POSITION, 74 XML_TOK_INDEXSOURCE_RELATIVE_TABS } , 75 { XML_NAMESPACE_TEXT, 76 XML_USE_OTHER_OBJECTS, 77 XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS }, 78 { XML_NAMESPACE_TEXT, 79 XML_USE_SPREADSHEET_OBJECTS, 80 XML_TOK_INDEXSOURCE_USE_SHEET }, 81 { XML_NAMESPACE_TEXT, 82 XML_USE_CHART_OBJECTS, 83 XML_TOK_INDEXSOURCE_USE_CHART }, 84 { XML_NAMESPACE_TEXT, 85 XML_USE_DRAW_OBJECTS, 86 XML_TOK_INDEXSOURCE_USE_DRAW }, 87 { XML_NAMESPACE_TEXT, 88 XML_USE_IMAGE_OBJECTS, 89 XML_TOK_INDEXSOURCE_USE_IMAGE }, 90 { XML_NAMESPACE_TEXT, 91 XML_USE_MATH_OBJECTS, 92 XML_TOK_INDEXSOURCE_USE_MATH }, 93 { XML_NAMESPACE_TEXT, 94 XML_MAIN_ENTRY_STYLE_NAME, 95 XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE }, 96 { XML_NAMESPACE_TEXT, 97 XML_IGNORE_CASE, 98 XML_TOK_INDEXSOURCE_IGNORE_CASE }, 99 { XML_NAMESPACE_TEXT, 100 XML_ALPHABETICAL_SEPARATORS, 101 XML_TOK_INDEXSOURCE_SEPARATORS }, 102 { XML_NAMESPACE_TEXT, 103 XML_COMBINE_ENTRIES, 104 XML_TOK_INDEXSOURCE_COMBINE_ENTRIES }, 105 { XML_NAMESPACE_TEXT, 106 XML_COMBINE_ENTRIES_WITH_DASH, 107 XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH }, 108 { XML_NAMESPACE_TEXT, 109 XML_USE_KEYS_AS_ENTRIES, 110 XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES }, 111 { XML_NAMESPACE_TEXT, 112 XML_COMBINE_ENTRIES_WITH_PP, 113 XML_TOK_INDEXSOURCE_COMBINE_WITH_PP }, 114 { XML_NAMESPACE_TEXT, 115 XML_CAPITALIZE_ENTRIES, 116 XML_TOK_INDEXSOURCE_CAPITALIZE }, 117 { XML_NAMESPACE_TEXT, 118 XML_USE_OBJECTS, 119 XML_TOK_INDEXSOURCE_USE_OBJECTS }, 120 { XML_NAMESPACE_TEXT, 121 XML_USE_GRAPHICS, 122 XML_TOK_INDEXSOURCE_USE_GRAPHICS }, 123 { XML_NAMESPACE_TEXT, 124 XML_USE_TABLES, 125 XML_TOK_INDEXSOURCE_USE_TABLES }, 126 { XML_NAMESPACE_TEXT, 127 XML_USE_FLOATING_FRAMES, 128 XML_TOK_INDEXSOURCE_USE_FRAMES }, 129 { XML_NAMESPACE_TEXT, 130 XML_COPY_OUTLINE_LEVELS, 131 XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS }, 132 { XML_NAMESPACE_TEXT, 133 XML_USE_CAPTION, 134 XML_TOK_INDEXSOURCE_USE_CAPTION }, 135 { XML_NAMESPACE_TEXT, 136 XML_CAPTION_SEQUENCE_NAME, 137 XML_TOK_INDEXSOURCE_SEQUENCE_NAME }, 138 { XML_NAMESPACE_TEXT, 139 XML_CAPTION_SEQUENCE_FORMAT, 140 XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT }, 141 { XML_NAMESPACE_TEXT, 142 XML_COMMA_SEPARATED, 143 XML_TOK_INDEXSOURCE_COMMA_SEPARATED }, 144 { XML_NAMESPACE_TEXT, 145 XML_USE_INDEX_SOURCE_STYLES, 146 XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES }, 147 { XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM, 148 XML_TOK_INDEXSOURCE_SORT_ALGORITHM }, 149 { XML_NAMESPACE_FO, XML_LANGUAGE, XML_TOK_INDEXSOURCE_LANGUAGE }, 150 { XML_NAMESPACE_FO, XML_COUNTRY, XML_TOK_INDEXSOURCE_COUNTRY }, 151 { XML_NAMESPACE_TEXT, XML_INDEX_NAME, XML_TOK_INDEXSOURCE_USER_INDEX_NAME }, 152 { XML_NAMESPACE_TEXT, 153 XML_USE_OUTLINE_LEVEL, 154 XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL}, 155 156 XML_TOKEN_MAP_END 157 }; 158 159 160 TYPEINIT1( XMLIndexSourceBaseContext, SvXMLImportContext ); 161 162 XMLIndexSourceBaseContext::XMLIndexSourceBaseContext( 163 SvXMLImport& rImport, 164 sal_uInt16 nPrfx, 165 const OUString& rLocalName, 166 Reference<XPropertySet> & rPropSet, 167 sal_Bool bLevelFormats) 168 : SvXMLImportContext(rImport, nPrfx, rLocalName) 169 , sCreateFromChapter(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromChapter)) 170 , sIsRelativeTabstops(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsRelativeTabstops)) 171 , bUseLevelFormats(bLevelFormats) 172 , bChapterIndex(sal_False) 173 , bRelativeTabs(sal_True) 174 , rIndexPropertySet(rPropSet) 175 { 176 } 177 178 XMLIndexSourceBaseContext::~XMLIndexSourceBaseContext() 179 { 180 } 181 182 void XMLIndexSourceBaseContext::StartElement( 183 const Reference<XAttributeList> & xAttrList) 184 { 185 SvXMLTokenMap aTokenMap(aIndexSourceTokenMap); 186 187 // process attributes 188 sal_Int16 nLength = xAttrList->getLength(); 189 for(sal_Int16 i=0; i<nLength; i++) 190 { 191 // map to IndexSourceParamEnum 192 OUString sLocalName; 193 sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 194 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); 195 sal_uInt16 nToken = aTokenMap.Get(nPrefix, sLocalName); 196 197 // process attribute 198 ProcessAttribute((enum IndexSourceParamEnum)nToken, 199 xAttrList->getValueByIndex(i)); 200 } 201 } 202 203 void XMLIndexSourceBaseContext::ProcessAttribute( 204 enum IndexSourceParamEnum eParam, 205 const OUString& rValue) 206 { 207 switch (eParam) 208 { 209 case XML_TOK_INDEXSOURCE_INDEX_SCOPE: 210 if ( IsXMLToken( rValue, XML_CHAPTER ) ) 211 { 212 bChapterIndex = sal_True; 213 } 214 break; 215 216 case XML_TOK_INDEXSOURCE_RELATIVE_TABS: 217 { 218 sal_Bool bTmp; 219 if (SvXMLUnitConverter::convertBool(bTmp, rValue)) 220 { 221 bRelativeTabs = bTmp; 222 } 223 break; 224 } 225 226 default: 227 // unknown attribute -> ignore 228 break; 229 } 230 } 231 232 void XMLIndexSourceBaseContext::EndElement() 233 { 234 Any aAny; 235 236 aAny.setValue(&bRelativeTabs, ::getBooleanCppuType()); 237 rIndexPropertySet->setPropertyValue(sIsRelativeTabstops, aAny); 238 239 aAny.setValue(&bChapterIndex, ::getBooleanCppuType()); 240 rIndexPropertySet->setPropertyValue(sCreateFromChapter, aAny); 241 } 242 243 SvXMLImportContext* XMLIndexSourceBaseContext::CreateChildContext( 244 sal_uInt16 nPrefix, 245 const OUString& rLocalName, 246 const Reference<XAttributeList> & xAttrList ) 247 { 248 SvXMLImportContext* pContext = NULL; 249 250 if (XML_NAMESPACE_TEXT == nPrefix) 251 { 252 if ( IsXMLToken( rLocalName, XML_INDEX_TITLE_TEMPLATE ) ) 253 { 254 pContext = new XMLIndexTitleTemplateContext(GetImport(), 255 rIndexPropertySet, 256 nPrefix, rLocalName); 257 } 258 else if ( bUseLevelFormats && 259 IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLES ) ) 260 { 261 pContext = new XMLIndexTOCStylesContext(GetImport(), 262 rIndexPropertySet, 263 nPrefix, rLocalName); 264 } 265 // else: unknown element in text namespace -> ignore 266 } 267 // else: unknown namespace -> ignore 268 269 // use default context 270 if (pContext == NULL) 271 { 272 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, 273 xAttrList); 274 } 275 276 return pContext; 277 } 278