Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "commentsfragment.hxx"
30 : :
31 : : #include "richstringcontext.hxx"
32 : :
33 : : namespace oox {
34 : : namespace xls {
35 : :
36 : : // ============================================================================
37 : :
38 : : using namespace ::oox::core;
39 : :
40 : : using ::rtl::OUString;
41 : :
42 : : // ============================================================================
43 : :
44 : 3 : CommentsFragment::CommentsFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
45 [ + - ]: 3 : WorksheetFragmentBase( rHelper, rFragmentPath )
46 : : {
47 : 3 : }
48 : :
49 : 54 : ContextHandlerRef CommentsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
50 : : {
51 [ + + + + : 54 : switch( getCurrentElement() )
+ + + +
- ]
52 : : {
53 : : case XML_ROOT_CONTEXT:
54 [ + - ]: 3 : if( nElement == XLS_TOKEN( comments ) ) return this;
55 : 0 : break;
56 : : case XLS_TOKEN( comments ):
57 [ + + ]: 6 : if( nElement == XLS_TOKEN( authors ) ) return this;
58 [ + - ]: 3 : if( nElement == XLS_TOKEN( commentList ) ) return this;
59 : 0 : break;
60 : : case XLS_TOKEN( authors ):
61 [ + - ]: 3 : if( nElement == XLS_TOKEN( author ) ) return this; // collect author in onCharacters()
62 : 0 : break;
63 : : case XLS_TOKEN( commentList ):
64 [ + - ]: 3 : if( nElement == XLS_TOKEN( comment ) ) { importComment( rAttribs ); return this; }
65 : 0 : break;
66 : : case XLS_TOKEN( commentPr ):
67 [ + - ]: 3 : if( nElement == XLS_TOKEN( anchor ) )
68 : 3 : return this;
69 : 0 : break;
70 : : case XLS_TOKEN( anchor ):
71 [ + + ][ + - ]: 6 : if( nElement == XDR_TOKEN( from ) || nElement == XDR_TOKEN( to ) )
72 : 6 : return this;
73 : 0 : break;
74 : : case XDR_TOKEN( from ):
75 : : case XDR_TOKEN( to ):
76 : 24 : return this;
77 : : case XLS_TOKEN( comment ):
78 [ + + ][ + - ]: 6 : if( (nElement == XLS_TOKEN( text )) && mxComment.get() )
[ + + ]
79 [ + - ]: 3 : return new RichStringContext( *this, mxComment->createText() );
80 [ + - ]: 3 : if( nElement == XLS_TOKEN( commentPr ) ) { mxComment->importCommentPr( rAttribs ); return this; }
81 : 0 : break;
82 : : }
83 : 54 : return 0;
84 : : }
85 : :
86 : 24 : void CommentsFragment::onCharacters( const OUString& rChars )
87 : : {
88 [ - + ]: 24 : if( isCurrentElement( XLS_TOKEN( author ) ) )
89 : 0 : getComments().appendAuthor( rChars );
90 : 24 : }
91 : :
92 : 57 : void CommentsFragment::onEndElement()
93 : : {
94 [ + + ]: 57 : if( isCurrentElement( XLS_TOKEN( comment ) ) )
95 : 9 : mxComment.reset();
96 : 57 : }
97 : :
98 : 0 : ContextHandlerRef CommentsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
99 : : {
100 [ # # # # : 0 : switch( getCurrentElement() )
# # ]
101 : : {
102 : : case XML_ROOT_CONTEXT:
103 [ # # ]: 0 : if( nRecId == BIFF12_ID_COMMENTS ) return this;
104 : 0 : break;
105 : : case BIFF12_ID_COMMENTS:
106 [ # # ]: 0 : if( nRecId == BIFF12_ID_COMMENTAUTHORS ) return this;
107 [ # # ]: 0 : if( nRecId == BIFF12_ID_COMMENTLIST ) return this;
108 : 0 : break;
109 : : case BIFF12_ID_COMMENTAUTHORS:
110 [ # # ][ # # ]: 0 : if( nRecId == BIFF12_ID_COMMENTAUTHOR ) getComments().appendAuthor( BiffHelper::readString( rStrm ) );
[ # # ]
111 : 0 : break;
112 : : case BIFF12_ID_COMMENTLIST:
113 [ # # ]: 0 : if( nRecId == BIFF12_ID_COMMENT ) { importComment( rStrm ); return this; }
114 : 0 : break;
115 : : case BIFF12_ID_COMMENT:
116 [ # # ][ # # ]: 0 : if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment.get() )
[ # # ]
117 [ # # ]: 0 : mxComment->createText()->importString( rStrm, true );
118 : 0 : break;
119 : : }
120 : 0 : return 0;
121 : : }
122 : :
123 : 0 : void CommentsFragment::onEndRecord()
124 : : {
125 [ # # ]: 0 : if( isCurrentElement( BIFF12_ID_COMMENT ) )
126 : 0 : mxComment.reset();
127 : 0 : }
128 : :
129 : 0 : const RecordInfo* CommentsFragment::getRecordInfos() const
130 : : {
131 : : static const RecordInfo spRecInfos[] =
132 : : {
133 : : { BIFF12_ID_COMMENT, BIFF12_ID_COMMENT + 1 },
134 : : { BIFF12_ID_COMMENTAUTHORS, BIFF12_ID_COMMENTAUTHORS + 1 },
135 : : { BIFF12_ID_COMMENTLIST, BIFF12_ID_COMMENTLIST + 1 },
136 : : { BIFF12_ID_COMMENTS, BIFF12_ID_COMMENTS + 1 },
137 : : { -1, -1 }
138 : : };
139 : 0 : return spRecInfos;
140 : : }
141 : :
142 : : // private --------------------------------------------------------------------
143 : :
144 : 3 : void CommentsFragment::importComment( const AttributeList& rAttribs )
145 : : {
146 [ + - ]: 3 : mxComment = getComments().createComment();
147 : 3 : mxComment->importComment( rAttribs );
148 : 3 : }
149 : :
150 : 0 : void CommentsFragment::importComment( SequenceInputStream& rStrm )
151 : : {
152 [ # # ]: 0 : mxComment = getComments().createComment();
153 : 0 : mxComment->importComment( rStrm );
154 : 0 : }
155 : :
156 : : // ============================================================================
157 : :
158 : : } // namespace xls
159 [ + - ][ + - ]: 24 : } // namespace oox
160 : :
161 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|