1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*ca5ec200SAndrew Rist * distributed with this work for additional information
6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at
10*ca5ec200SAndrew Rist *
11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist *
13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the
17*ca5ec200SAndrew Rist * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist * under the License.
19*ca5ec200SAndrew Rist *
20*ca5ec200SAndrew Rist *************************************************************/
21*ca5ec200SAndrew Rist
22*ca5ec200SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "oox/xls/commentsfragment.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "oox/xls/richstringcontext.hxx"
27cdf0e10cSrcweir
28cdf0e10cSrcweir namespace oox {
29cdf0e10cSrcweir namespace xls {
30cdf0e10cSrcweir
31cdf0e10cSrcweir // ============================================================================
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace ::oox::core;
34cdf0e10cSrcweir
35cdf0e10cSrcweir using ::rtl::OUString;
36cdf0e10cSrcweir
37cdf0e10cSrcweir // ============================================================================
38cdf0e10cSrcweir
CommentsFragment(const WorksheetHelper & rHelper,const OUString & rFragmentPath)39cdf0e10cSrcweir CommentsFragment::CommentsFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
40cdf0e10cSrcweir WorksheetFragmentBase( rHelper, rFragmentPath )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir }
43cdf0e10cSrcweir
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)44cdf0e10cSrcweir ContextHandlerRef CommentsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir switch( getCurrentElement() )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir case XML_ROOT_CONTEXT:
49cdf0e10cSrcweir if( nElement == XLS_TOKEN( comments ) ) return this;
50cdf0e10cSrcweir break;
51cdf0e10cSrcweir case XLS_TOKEN( comments ):
52cdf0e10cSrcweir if( nElement == XLS_TOKEN( authors ) ) return this;
53cdf0e10cSrcweir if( nElement == XLS_TOKEN( commentList ) ) return this;
54cdf0e10cSrcweir break;
55cdf0e10cSrcweir case XLS_TOKEN( authors ):
56cdf0e10cSrcweir if( nElement == XLS_TOKEN( author ) ) return this; // collect author in onCharacters()
57cdf0e10cSrcweir break;
58cdf0e10cSrcweir case XLS_TOKEN( commentList ):
59cdf0e10cSrcweir if( nElement == XLS_TOKEN( comment ) ) { importComment( rAttribs ); return this; }
60cdf0e10cSrcweir break;
61cdf0e10cSrcweir case XLS_TOKEN( comment ):
62cdf0e10cSrcweir if( (nElement == XLS_TOKEN( text )) && mxComment.get() )
63cdf0e10cSrcweir return new RichStringContext( *this, mxComment->createText() );
64cdf0e10cSrcweir break;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir return 0;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
onCharacters(const OUString & rChars)69cdf0e10cSrcweir void CommentsFragment::onCharacters( const OUString& rChars )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir if( isCurrentElement( XLS_TOKEN( author ) ) )
72cdf0e10cSrcweir getComments().appendAuthor( rChars );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
onEndElement()75cdf0e10cSrcweir void CommentsFragment::onEndElement()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir if( isCurrentElement( XLS_TOKEN( comment ) ) )
78cdf0e10cSrcweir mxComment.reset();
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
onCreateRecordContext(sal_Int32 nRecId,SequenceInputStream & rStrm)81cdf0e10cSrcweir ContextHandlerRef CommentsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir switch( getCurrentElement() )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir case XML_ROOT_CONTEXT:
86cdf0e10cSrcweir if( nRecId == BIFF12_ID_COMMENTS ) return this;
87cdf0e10cSrcweir break;
88cdf0e10cSrcweir case BIFF12_ID_COMMENTS:
89cdf0e10cSrcweir if( nRecId == BIFF12_ID_COMMENTAUTHORS ) return this;
90cdf0e10cSrcweir if( nRecId == BIFF12_ID_COMMENTLIST ) return this;
91cdf0e10cSrcweir break;
92cdf0e10cSrcweir case BIFF12_ID_COMMENTAUTHORS:
93cdf0e10cSrcweir if( nRecId == BIFF12_ID_COMMENTAUTHOR ) getComments().appendAuthor( BiffHelper::readString( rStrm ) );
94cdf0e10cSrcweir break;
95cdf0e10cSrcweir case BIFF12_ID_COMMENTLIST:
96cdf0e10cSrcweir if( nRecId == BIFF12_ID_COMMENT ) { importComment( rStrm ); return this; }
97cdf0e10cSrcweir break;
98cdf0e10cSrcweir case BIFF12_ID_COMMENT:
99cdf0e10cSrcweir if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment.get() )
100cdf0e10cSrcweir mxComment->createText()->importString( rStrm, true );
101cdf0e10cSrcweir break;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir return 0;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
onEndRecord()106cdf0e10cSrcweir void CommentsFragment::onEndRecord()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir if( isCurrentElement( BIFF12_ID_COMMENT ) )
109cdf0e10cSrcweir mxComment.reset();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
getRecordInfos() const112cdf0e10cSrcweir const RecordInfo* CommentsFragment::getRecordInfos() const
113cdf0e10cSrcweir {
114cdf0e10cSrcweir static const RecordInfo spRecInfos[] =
115cdf0e10cSrcweir {
116cdf0e10cSrcweir { BIFF12_ID_COMMENT, BIFF12_ID_COMMENT + 1 },
117cdf0e10cSrcweir { BIFF12_ID_COMMENTAUTHORS, BIFF12_ID_COMMENTAUTHORS + 1 },
118cdf0e10cSrcweir { BIFF12_ID_COMMENTLIST, BIFF12_ID_COMMENTLIST + 1 },
119cdf0e10cSrcweir { BIFF12_ID_COMMENTS, BIFF12_ID_COMMENTS + 1 },
120cdf0e10cSrcweir { -1, -1 }
121cdf0e10cSrcweir };
122cdf0e10cSrcweir return spRecInfos;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
125cdf0e10cSrcweir // private --------------------------------------------------------------------
126cdf0e10cSrcweir
importComment(const AttributeList & rAttribs)127cdf0e10cSrcweir void CommentsFragment::importComment( const AttributeList& rAttribs )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir mxComment = getComments().createComment();
130cdf0e10cSrcweir mxComment->importComment( rAttribs );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
importComment(SequenceInputStream & rStrm)133cdf0e10cSrcweir void CommentsFragment::importComment( SequenceInputStream& rStrm )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir mxComment = getComments().createComment();
136cdf0e10cSrcweir mxComment->importComment( rStrm );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir // ============================================================================
140cdf0e10cSrcweir
141cdf0e10cSrcweir } // namespace xls
142cdf0e10cSrcweir } // namespace oox
143