1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: commentsfragment.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/xls/commentsfragment.hxx"
32 #include "oox/xls/richstringcontext.hxx"
34 using ::rtl::OUString
;
35 using ::oox::core::ContextHandlerRef
;
36 using ::oox::core::RecordInfo
;
41 // ============================================================================
43 OoxCommentsFragment::OoxCommentsFragment( const WorksheetHelper
& rHelper
, const OUString
& rFragmentPath
) :
44 OoxWorksheetFragmentBase( rHelper
, rFragmentPath
)
48 // oox.core.ContextHandler2Helper interface -----------------------------------
50 ContextHandlerRef
OoxCommentsFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
52 switch( getCurrentElement() )
54 case XML_ROOT_CONTEXT
:
55 if( nElement
== XLS_TOKEN( comments
) ) return this;
57 case XLS_TOKEN( comments
):
58 if( nElement
== XLS_TOKEN( authors
) ) return this;
59 if( nElement
== XLS_TOKEN( commentList
) ) return this;
61 case XLS_TOKEN( authors
):
62 if( nElement
== XLS_TOKEN( author
) ) return this; // collect author in onEndElement()
64 case XLS_TOKEN( commentList
):
65 if( nElement
== XLS_TOKEN( comment
) ) { importComment( rAttribs
); return this; }
67 case XLS_TOKEN( comment
):
68 if( (nElement
== XLS_TOKEN( text
)) && mxComment
.get() )
69 return new OoxRichStringContext( *this, mxComment
->createText() );
75 void OoxCommentsFragment::onEndElement( const OUString
& rChars
)
77 switch( getCurrentElement() )
79 case XLS_TOKEN( author
):
80 getComments().appendAuthor( rChars
);
82 case XLS_TOKEN( comment
):
88 ContextHandlerRef
OoxCommentsFragment::onCreateRecordContext( sal_Int32 nRecId
, RecordInputStream
& rStrm
)
90 switch( getCurrentElement() )
92 case XML_ROOT_CONTEXT
:
93 if( nRecId
== OOBIN_ID_COMMENTS
) return this;
95 case OOBIN_ID_COMMENTS
:
96 if( nRecId
== OOBIN_ID_COMMENTAUTHORS
) return this;
97 if( nRecId
== OOBIN_ID_COMMENTLIST
) return this;
99 case OOBIN_ID_COMMENTAUTHORS
:
100 if( nRecId
== OOBIN_ID_COMMENTAUTHOR
) getComments().appendAuthor( rStrm
.readString() );
102 case OOBIN_ID_COMMENTLIST
:
103 if( nRecId
== OOBIN_ID_COMMENT
) { importComment( rStrm
); return this; }
105 case OOBIN_ID_COMMENT
:
106 if( (nRecId
== OOBIN_ID_COMMENTTEXT
) && mxComment
.get() )
107 mxComment
->createText()->importString( rStrm
, true );
113 void OoxCommentsFragment::onEndRecord()
115 switch( getCurrentElement() )
117 case OOBIN_ID_COMMENT
:
123 // oox.core.FragmentHandler2 interface ----------------------------------------
125 const RecordInfo
* OoxCommentsFragment::getRecordInfos() const
127 static const RecordInfo spRecInfos
[] =
129 { OOBIN_ID_COMMENT
, OOBIN_ID_COMMENT
+ 1 },
130 { OOBIN_ID_COMMENTAUTHORS
, OOBIN_ID_COMMENTAUTHORS
+ 1 },
131 { OOBIN_ID_COMMENTLIST
, OOBIN_ID_COMMENTLIST
+ 1 },
132 { OOBIN_ID_COMMENTS
, OOBIN_ID_COMMENTS
+ 1 },
138 // private --------------------------------------------------------------------
140 void OoxCommentsFragment::importComment( const AttributeList
& rAttribs
)
142 mxComment
= getComments().createComment();
143 mxComment
->importComment( rAttribs
);
146 void OoxCommentsFragment::importComment( RecordInputStream
& rStrm
)
148 mxComment
= getComments().createComment();
149 mxComment
->importComment( rStrm
);
152 // ============================================================================