Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "SchXMLImport.hxx"
22 : #include "SchXMLParagraphContext.hxx"
23 :
24 : #include <xmloff/xmlnmspe.hxx>
25 : #include <xmloff/xmltoken.hxx>
26 : #include <xmloff/nmspmap.hxx>
27 :
28 : using namespace com::sun::star;
29 : using namespace ::xmloff::token;
30 :
31 1631 : SchXMLParagraphContext::SchXMLParagraphContext( SvXMLImport& rImport,
32 : const OUString& rLocalName,
33 : OUString& rText,
34 : OUString * pOutId /* = 0 */ ) :
35 : SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName ),
36 : mrText( rText ),
37 1631 : mpId( pOutId )
38 : {
39 1631 : }
40 :
41 3262 : SchXMLParagraphContext::~SchXMLParagraphContext()
42 3262 : {}
43 :
44 1631 : void SchXMLParagraphContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
45 : {
46 : // remember the id. It is used for storing the original cell range string in
47 : // a local table (cached data)
48 1631 : if( mpId )
49 : {
50 1506 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
51 1506 : bool bHaveXmlId( false );
52 :
53 1506 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
54 : {
55 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
56 0 : OUString aLocalName;
57 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
58 :
59 0 : if (IsXMLToken(aLocalName, XML_ID))
60 : {
61 0 : if (nPrefix == XML_NAMESPACE_XML)
62 : {
63 0 : (*mpId) = xAttrList->getValueByIndex( i );
64 0 : bHaveXmlId = true;
65 : }
66 0 : if (nPrefix == XML_NAMESPACE_TEXT)
67 : { // text:id shall be ignored if xml:id exists
68 0 : if (!bHaveXmlId)
69 : {
70 0 : (*mpId) = xAttrList->getValueByIndex( i );
71 : }
72 : }
73 : }
74 0 : }
75 : }
76 1631 : }
77 :
78 1631 : void SchXMLParagraphContext::EndElement()
79 : {
80 1631 : mrText = maBuffer.makeStringAndClear();
81 1631 : }
82 :
83 0 : SvXMLImportContext* SchXMLParagraphContext::CreateChildContext(
84 : sal_uInt16 nPrefix,
85 : const OUString& rLocalName,
86 : const uno::Reference< xml::sax::XAttributeList >& )
87 : {
88 0 : if( nPrefix == XML_NAMESPACE_TEXT )
89 : {
90 0 : if( rLocalName.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_TAB_STOP )))
91 : {
92 0 : maBuffer.append( sal_Unicode( 0x0009 )); // tabulator
93 : }
94 0 : else if( rLocalName.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_LINE_BREAK )))
95 : {
96 0 : maBuffer.append( sal_Unicode( 0x000A )); // linefeed
97 : }
98 : }
99 :
100 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
101 : }
102 :
103 1543 : void SchXMLParagraphContext::Characters( const OUString& rChars )
104 : {
105 1543 : maBuffer.append( rChars );
106 1543 : }
107 :
108 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|