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 #include "SchXMLImport.hxx" 28 #include "SchXMLParagraphContext.hxx" 29 30 #include "xmloff/xmlnmspe.hxx" 31 #include <xmloff/xmltoken.hxx> 32 #include <xmloff/nmspmap.hxx> 33 34 using ::rtl::OUString; 35 using namespace com::sun::star; 36 using namespace ::xmloff::token; 37 38 SchXMLParagraphContext::SchXMLParagraphContext( SvXMLImport& rImport, 39 const OUString& rLocalName, 40 OUString& rText, 41 OUString * pOutId /* = 0 */ ) : 42 SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName ), 43 mrText( rText ), 44 mpId( pOutId ) 45 { 46 } 47 48 SchXMLParagraphContext::~SchXMLParagraphContext() 49 {} 50 51 void SchXMLParagraphContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList ) 52 { 53 // remember the id. It is used for storing the original cell range string in 54 // a local table (cached data) 55 if( mpId ) 56 { 57 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; 58 rtl::OUString aValue; 59 bool bHaveXmlId( false ); 60 61 for( sal_Int16 i = 0; i < nAttrCount; i++ ) 62 { 63 rtl::OUString sAttrName = xAttrList->getNameByIndex( i ); 64 rtl::OUString aLocalName; 65 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 66 67 if (IsXMLToken(aLocalName, XML_ID)) 68 { 69 if (nPrefix == XML_NAMESPACE_XML) 70 { 71 (*mpId) = xAttrList->getValueByIndex( i ); 72 bHaveXmlId = true; 73 } 74 if (nPrefix == XML_NAMESPACE_TEXT) 75 { // text:id shall be ignored if xml:id exists 76 if (!bHaveXmlId) 77 { 78 (*mpId) = xAttrList->getValueByIndex( i ); 79 } 80 } 81 } 82 } 83 } 84 } 85 86 void SchXMLParagraphContext::EndElement() 87 { 88 mrText = maBuffer.makeStringAndClear(); 89 } 90 91 SvXMLImportContext* SchXMLParagraphContext::CreateChildContext( 92 sal_uInt16 nPrefix, 93 const OUString& rLocalName, 94 const uno::Reference< xml::sax::XAttributeList >& ) 95 { 96 if( nPrefix == XML_NAMESPACE_TEXT ) 97 { 98 if( rLocalName.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_TAB_STOP ))) 99 { 100 maBuffer.append( sal_Unicode( 0x0009 )); // tabulator 101 } 102 else if( rLocalName.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_LINE_BREAK ))) 103 { 104 maBuffer.append( sal_Unicode( 0x000A )); // linefeed 105 } 106 } 107 108 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 109 } 110 111 void SchXMLParagraphContext::Characters( const OUString& rChars ) 112 { 113 maBuffer.append( rChars ); 114 } 115