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 : #include "commentsfragment.hxx"
21 :
22 : #include "richstringcontext.hxx"
23 :
24 : namespace oox {
25 : namespace xls {
26 :
27 : // ============================================================================
28 :
29 : using namespace ::oox::core;
30 :
31 : using ::rtl::OUString;
32 :
33 : // ============================================================================
34 :
35 2 : CommentsFragment::CommentsFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
36 2 : WorksheetFragmentBase( rHelper, rFragmentPath )
37 : {
38 2 : }
39 :
40 36 : ContextHandlerRef CommentsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
41 : {
42 36 : switch( getCurrentElement() )
43 : {
44 : case XML_ROOT_CONTEXT:
45 2 : if( nElement == XLS_TOKEN( comments ) ) return this;
46 0 : break;
47 : case XLS_TOKEN( comments ):
48 4 : if( nElement == XLS_TOKEN( authors ) ) return this;
49 2 : if( nElement == XLS_TOKEN( commentList ) ) return this;
50 0 : break;
51 : case XLS_TOKEN( authors ):
52 2 : if( nElement == XLS_TOKEN( author ) ) return this; // collect author in onCharacters()
53 0 : break;
54 : case XLS_TOKEN( commentList ):
55 2 : if( nElement == XLS_TOKEN( comment ) ) { importComment( rAttribs ); return this; }
56 0 : break;
57 : case XLS_TOKEN( commentPr ):
58 2 : if( nElement == XLS_TOKEN( anchor ) )
59 2 : return this;
60 0 : break;
61 : case XLS_TOKEN( anchor ):
62 4 : if( nElement == XDR_TOKEN( from ) || nElement == XDR_TOKEN( to ) )
63 4 : return this;
64 0 : break;
65 : case XDR_TOKEN( from ):
66 : case XDR_TOKEN( to ):
67 16 : return this;
68 : case XLS_TOKEN( comment ):
69 4 : if( (nElement == XLS_TOKEN( text )) && mxComment.get() )
70 2 : return new RichStringContext( *this, mxComment->createText() );
71 2 : if( nElement == XLS_TOKEN( commentPr ) ) { mxComment->importCommentPr( rAttribs ); return this; }
72 0 : break;
73 : }
74 0 : return 0;
75 : }
76 :
77 16 : void CommentsFragment::onCharacters( const OUString& rChars )
78 : {
79 16 : if( isCurrentElement( XLS_TOKEN( author ) ) )
80 0 : getComments().appendAuthor( rChars );
81 16 : }
82 :
83 38 : void CommentsFragment::onEndElement()
84 : {
85 38 : if( isCurrentElement( XLS_TOKEN( comment ) ) )
86 6 : mxComment.reset();
87 38 : }
88 :
89 0 : ContextHandlerRef CommentsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
90 : {
91 0 : switch( getCurrentElement() )
92 : {
93 : case XML_ROOT_CONTEXT:
94 0 : if( nRecId == BIFF12_ID_COMMENTS ) return this;
95 0 : break;
96 : case BIFF12_ID_COMMENTS:
97 0 : if( nRecId == BIFF12_ID_COMMENTAUTHORS ) return this;
98 0 : if( nRecId == BIFF12_ID_COMMENTLIST ) return this;
99 0 : break;
100 : case BIFF12_ID_COMMENTAUTHORS:
101 0 : if( nRecId == BIFF12_ID_COMMENTAUTHOR ) getComments().appendAuthor( BiffHelper::readString( rStrm ) );
102 0 : break;
103 : case BIFF12_ID_COMMENTLIST:
104 0 : if( nRecId == BIFF12_ID_COMMENT ) { importComment( rStrm ); return this; }
105 0 : break;
106 : case BIFF12_ID_COMMENT:
107 0 : if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment.get() )
108 0 : mxComment->createText()->importString( rStrm, true );
109 0 : break;
110 : }
111 0 : return 0;
112 : }
113 :
114 0 : void CommentsFragment::onEndRecord()
115 : {
116 0 : if( isCurrentElement( BIFF12_ID_COMMENT ) )
117 0 : mxComment.reset();
118 0 : }
119 :
120 0 : const RecordInfo* CommentsFragment::getRecordInfos() const
121 : {
122 : static const RecordInfo spRecInfos[] =
123 : {
124 : { BIFF12_ID_COMMENT, BIFF12_ID_COMMENT + 1 },
125 : { BIFF12_ID_COMMENTAUTHORS, BIFF12_ID_COMMENTAUTHORS + 1 },
126 : { BIFF12_ID_COMMENTLIST, BIFF12_ID_COMMENTLIST + 1 },
127 : { BIFF12_ID_COMMENTS, BIFF12_ID_COMMENTS + 1 },
128 : { -1, -1 }
129 : };
130 0 : return spRecInfos;
131 : }
132 :
133 : // private --------------------------------------------------------------------
134 :
135 2 : void CommentsFragment::importComment( const AttributeList& rAttribs )
136 : {
137 2 : mxComment = getComments().createComment();
138 2 : mxComment->importComment( rAttribs );
139 2 : }
140 :
141 0 : void CommentsFragment::importComment( SequenceInputStream& rStrm )
142 : {
143 0 : mxComment = getComments().createComment();
144 0 : mxComment->importComment( rStrm );
145 0 : }
146 :
147 : // ============================================================================
148 :
149 : } // namespace xls
150 24 : } // namespace oox
151 :
152 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|