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_sw.hxx" 30 #include <SwXMLBlockListContext.hxx> 31 #include <SwXMLBlockImport.hxx> 32 #include <SwXMLTextBlocks.hxx> 33 #include <xmloff/nmspmap.hxx> 34 #include <xmloff/xmlnmspe.hxx> 35 #include <unotools/charclass.hxx> 36 #include <swtypes.hxx> 37 38 using namespace ::com::sun::star::uno; 39 using namespace ::com::sun::star; 40 using namespace ::xmloff::token; 41 using ::rtl::OUString; 42 43 SwXMLBlockListContext::SwXMLBlockListContext( 44 SwXMLBlockListImport& rImport, 45 sal_uInt16 nPrefix, 46 const OUString& rLocalName, 47 const uno::Reference< 48 xml::sax::XAttributeList > & xAttrList ) : 49 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 50 rLocalRef (rImport) 51 { 52 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 53 for (sal_Int16 i=0; i < nAttrCount; i++) 54 { 55 const OUString& rAttrName = xAttrList->getNameByIndex( i ); 56 OUString aLocalName; 57 sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName); 58 const OUString& rAttrValue = xAttrList->getValueByIndex( i ); 59 if ( XML_NAMESPACE_BLOCKLIST == nPrefx ) 60 { 61 if ( IsXMLToken ( aLocalName, XML_LIST_NAME ) ) 62 { 63 rImport.getBlockList().SetName(rAttrValue); 64 break; 65 } 66 } 67 } 68 } 69 70 SwXMLBlockListContext::~SwXMLBlockListContext ( void ) 71 { 72 } 73 74 SvXMLImportContext *SwXMLBlockListContext::CreateChildContext( 75 sal_uInt16 nPrefix, 76 const OUString& rLocalName, 77 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 78 { 79 SvXMLImportContext *pContext = 0; 80 if (nPrefix == XML_NAMESPACE_BLOCKLIST && 81 IsXMLToken ( rLocalName, XML_BLOCK ) ) 82 pContext = new SwXMLBlockContext (rLocalRef, nPrefix, rLocalName, xAttrList); 83 else 84 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName); 85 return pContext; 86 } 87 88 SwXMLBlockContext::SwXMLBlockContext( 89 SwXMLBlockListImport& rImport, 90 sal_uInt16 nPrefix, 91 const OUString& rLocalName, 92 const uno::Reference< 93 xml::sax::XAttributeList > & xAttrList ) : 94 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 95 rLocalRef(rImport) 96 { 97 static const CharClass & rCC = GetAppCharClass(); 98 String aShort, aLong, aPackageName; 99 sal_Bool bTextOnly = sal_False; 100 101 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 102 for (sal_Int16 i=0; i < nAttrCount; i++) 103 { 104 const OUString& rAttrName = xAttrList->getNameByIndex( i ); 105 OUString aLocalName; 106 sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName); 107 const OUString& rAttrValue = xAttrList->getValueByIndex( i ); 108 if (XML_NAMESPACE_BLOCKLIST == nPrefx) 109 { 110 if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) ) 111 { 112 aShort = rCC.upper(rAttrValue); 113 } 114 else if ( IsXMLToken ( aLocalName, XML_NAME ) ) 115 { 116 aLong = rAttrValue; 117 } 118 else if ( IsXMLToken ( aLocalName, XML_PACKAGE_NAME ) ) 119 { 120 aPackageName = rAttrValue; 121 } 122 else if ( IsXMLToken ( aLocalName, XML_UNFORMATTED_TEXT ) ) 123 { 124 if ( IsXMLToken ( rAttrValue, XML_TRUE ) ) 125 bTextOnly = sal_True; 126 } 127 } 128 } 129 if (!aShort.Len() || !aLong.Len() || !aPackageName.Len()) 130 return; 131 rImport.getBlockList().AddName( aShort, aLong, aPackageName, bTextOnly); 132 } 133 134 SwXMLBlockContext::~SwXMLBlockContext ( void ) 135 { 136 } 137 138 SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext( 139 SwXMLTextBlockImport& rImport, 140 sal_uInt16 nPrefix, 141 const OUString& rLocalName, 142 const uno::Reference< 143 xml::sax::XAttributeList > & ) : 144 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 145 rLocalRef(rImport) 146 { 147 } 148 149 SvXMLImportContext *SwXMLTextBlockDocumentContext::CreateChildContext( 150 sal_uInt16 nPrefix, 151 const OUString& rLocalName, 152 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 153 { 154 SvXMLImportContext *pContext = 0; 155 if (nPrefix == XML_NAMESPACE_OFFICE && 156 IsXMLToken ( rLocalName, XML_BODY ) ) 157 pContext = new SwXMLTextBlockBodyContext (rLocalRef, nPrefix, rLocalName, xAttrList); 158 else 159 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName); 160 return pContext; 161 } 162 SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void ) 163 { 164 } 165 166 167 SwXMLTextBlockTextContext::SwXMLTextBlockTextContext( 168 SwXMLTextBlockImport& rImport, 169 sal_uInt16 nPrefix, 170 const OUString& rLocalName, 171 const uno::Reference< 172 xml::sax::XAttributeList > & ) : 173 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 174 rLocalRef(rImport) 175 { 176 } 177 178 SvXMLImportContext *SwXMLTextBlockTextContext::CreateChildContext( 179 sal_uInt16 nPrefix, 180 const OUString& rLocalName, 181 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 182 { 183 SvXMLImportContext *pContext = 0; 184 if (nPrefix == XML_NAMESPACE_TEXT && 185 IsXMLToken ( rLocalName, XML_P ) ) 186 pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList); 187 else 188 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName); 189 return pContext; 190 } 191 SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void ) 192 { 193 } 194 195 196 SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext( 197 SwXMLTextBlockImport& rImport, 198 sal_uInt16 nPrefix, 199 const OUString& rLocalName, 200 const uno::Reference< 201 xml::sax::XAttributeList > & ) : 202 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 203 rLocalRef(rImport) 204 { 205 } 206 207 SvXMLImportContext *SwXMLTextBlockBodyContext::CreateChildContext( 208 sal_uInt16 nPrefix, 209 const OUString& rLocalName, 210 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 211 { 212 SvXMLImportContext *pContext = 0; 213 if (nPrefix == XML_NAMESPACE_OFFICE && 214 IsXMLToken ( rLocalName, XML_TEXT ) ) 215 pContext = new SwXMLTextBlockTextContext (rLocalRef, nPrefix, rLocalName, xAttrList); 216 else if (nPrefix == XML_NAMESPACE_TEXT && 217 IsXMLToken ( rLocalName, XML_P ) ) 218 pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList); 219 else 220 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName); 221 return pContext; 222 } 223 SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void ) 224 { 225 } 226 SwXMLTextBlockParContext::SwXMLTextBlockParContext( 227 SwXMLTextBlockImport& rImport, 228 sal_uInt16 nPrefix, 229 const OUString& rLocalName, 230 const uno::Reference< 231 xml::sax::XAttributeList > & ) : 232 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 233 rLocalRef(rImport) 234 { 235 } 236 237 void SwXMLTextBlockParContext::Characters( const ::rtl::OUString& rChars ) 238 { 239 rLocalRef.m_rText.Append ( rChars.getStr()); 240 } 241 SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void ) 242 { 243 if (rLocalRef.bTextOnly) 244 rLocalRef.m_rText.AppendAscii( "\015" ); 245 else 246 { 247 if (rLocalRef.m_rText.GetChar ( rLocalRef.m_rText.Len()) != ' ' ) 248 rLocalRef.m_rText.AppendAscii( " " ); 249 } 250 } 251