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