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 "xmlannoi.hxx"
30 : : #include "xmlimprt.hxx"
31 : : #include "xmlconti.hxx"
32 : : #include "XMLTableShapeImportHelper.hxx"
33 : :
34 : : #include <xmloff/xmltkmap.hxx>
35 : : #include <xmloff/nmspmap.hxx>
36 : : #include <xmloff/xmlnmspe.hxx>
37 : : #include <xmloff/xmltoken.hxx>
38 : :
39 : : using namespace com::sun::star;
40 : : using namespace xmloff::token;
41 : :
42 : : //------------------------------------------------------------------
43 : :
44 : 8 : ScXMLAnnotationData::ScXMLAnnotationData() :
45 : : mbUseShapePos( false ),
46 [ + - ]: 8 : mbShown( false )
47 : : {
48 : 8 : }
49 : :
50 : 8 : ScXMLAnnotationData::~ScXMLAnnotationData()
51 : : {
52 : 8 : }
53 : :
54 : : //------------------------------------------------------------------
55 : :
56 : 8 : ScXMLAnnotationContext::ScXMLAnnotationContext( ScXMLImport& rImport,
57 : : sal_uInt16 nPrfx,
58 : : const ::rtl::OUString& rLName,
59 : : const uno::Reference<xml::sax::XAttributeList>& xAttrList,
60 : : ScXMLAnnotationData& rAnnotationData,
61 : : ScXMLTableRowCellContext* pTempCellContext) :
62 : : SvXMLImportContext( rImport, nPrfx, rLName ),
63 : : mrAnnotationData( rAnnotationData ),
64 : : nParagraphCount(0),
65 : : pCellContext(pTempCellContext),
66 : 8 : pShapeContext(NULL)
67 : : {
68 [ + - ]: 8 : uno::Reference<drawing::XShapes> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
69 [ + - ]: 8 : if (xLocalShapes.is())
70 : : {
71 [ + - ][ + - ]: 8 : XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
72 : 8 : pTableShapeImport->SetAnnotation(this);
73 : 8 : pShapeContext = GetScImport().GetShapeImport()->CreateGroupChildContext(
74 [ + - ][ + - ]: 16 : GetScImport(), nPrfx, rLName, xAttrList, xLocalShapes, true);
[ + - ]
75 : : }
76 : :
77 : 8 : pCellContext = pTempCellContext;
78 [ + - ][ + - ]: 8 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
79 [ + - ]: 8 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableAnnotationAttrTokenMap();
80 [ + + ]: 37 : for( sal_Int16 i=0; i < nAttrCount; ++i )
81 : : {
82 [ + - ][ + - ]: 29 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
83 : 29 : rtl::OUString aLocalName;
84 : 29 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
85 [ + - ]: 29 : sAttrName, &aLocalName );
86 [ + - ][ + - ]: 29 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
87 : :
88 [ + - ][ - - : 29 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
- + + +
+ ]
89 : : {
90 : : case XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR:
91 : : {
92 [ # # ][ # # ]: 0 : maAuthorBuffer = sValue;
93 : : }
94 : 0 : break;
95 : : case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE:
96 : : {
97 [ # # ][ # # ]: 0 : maCreateDateBuffer = sValue;
98 : : }
99 : 0 : break;
100 : : case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING:
101 : : {
102 [ # # ][ # # ]: 0 : maCreateDateStringBuffer = sValue;
103 : : }
104 : 0 : break;
105 : : case XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY:
106 : : {
107 [ + - ]: 5 : mrAnnotationData.mbShown = IsXMLToken(sValue, XML_TRUE);
108 : : }
109 : 5 : break;
110 : : case XML_TOK_TABLE_ANNOTATION_ATTR_X:
111 : : {
112 : 3 : mrAnnotationData.mbUseShapePos = true;
113 : : }
114 : 3 : break;
115 : : case XML_TOK_TABLE_ANNOTATION_ATTR_Y:
116 : : {
117 : 3 : mrAnnotationData.mbUseShapePos = true;
118 : : }
119 : 3 : break;
120 : : }
121 : 37 : }
122 : 8 : }
123 : :
124 : 8 : ScXMLAnnotationContext::~ScXMLAnnotationContext()
125 : : {
126 [ - + ]: 16 : }
127 : :
128 : 8 : void ScXMLAnnotationContext::StartElement(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList)
129 : : {
130 [ + - ]: 8 : if (pShapeContext)
131 : 8 : pShapeContext->StartElement(xAttrList);
132 : 8 : }
133 : :
134 : 16 : SvXMLImportContext *ScXMLAnnotationContext::CreateChildContext( sal_uInt16 nPrefix,
135 : : const ::rtl::OUString& rLName,
136 : : const ::com::sun::star::uno::Reference<
137 : : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
138 : : {
139 : 16 : SvXMLImportContext *pContext = 0;
140 : :
141 [ + + ]: 16 : if( XML_NAMESPACE_DC == nPrefix )
142 : : {
143 [ - + ]: 8 : if( IsXMLToken( rLName, XML_CREATOR ) )
144 : : pContext = new ScXMLContentContext(GetScImport(), nPrefix,
145 [ # # ]: 0 : rLName, xAttrList, maAuthorBuffer);
146 [ + - ]: 8 : else if( IsXMLToken( rLName, XML_DATE ) )
147 : : pContext = new ScXMLContentContext(GetScImport(), nPrefix,
148 [ + - ]: 8 : rLName, xAttrList, maCreateDateBuffer);
149 : : }
150 [ - + ]: 8 : else if( XML_NAMESPACE_META == nPrefix )
151 : : {
152 [ # # ]: 0 : if( IsXMLToken( rLName, XML_DATE_STRING ) )
153 : : pContext = new ScXMLContentContext(GetScImport(), nPrefix,
154 [ # # ]: 0 : rLName, xAttrList, maCreateDateStringBuffer);
155 : : }
156 : :
157 [ + + ][ + - ]: 16 : if( !pContext && pShapeContext )
158 : 8 : pContext = pShapeContext->CreateChildContext(nPrefix, rLName, xAttrList);
159 : :
160 [ - + ]: 16 : if( !pContext )
161 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
162 : :
163 : 16 : return pContext;
164 : : }
165 : :
166 : 0 : void ScXMLAnnotationContext::Characters( const ::rtl::OUString& rChars )
167 : : {
168 : 0 : maTextBuffer.append(rChars);
169 : 0 : }
170 : :
171 : 8 : void ScXMLAnnotationContext::EndElement()
172 : : {
173 [ + - ]: 8 : if (pShapeContext)
174 : : {
175 : 8 : pShapeContext->EndElement();
176 [ + - ]: 8 : delete pShapeContext;
177 : 8 : pShapeContext = NULL;
178 : : }
179 : :
180 : 8 : mrAnnotationData.maAuthor = maAuthorBuffer.makeStringAndClear();
181 : 8 : mrAnnotationData.maCreateDate = maCreateDateBuffer.makeStringAndClear();
182 [ - + ]: 8 : if (mrAnnotationData.maCreateDate.isEmpty())
183 : 0 : mrAnnotationData.maCreateDate = maCreateDateStringBuffer.makeStringAndClear();
184 : 8 : mrAnnotationData.maSimpleText = maTextBuffer.makeStringAndClear();
185 : :
186 : 8 : XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
187 : 8 : pTableShapeImport->SetAnnotation(NULL);
188 : 8 : }
189 : :
190 : 8 : void ScXMLAnnotationContext::SetShape( const uno::Reference< drawing::XShape >& rxShape, const uno::Reference< drawing::XShapes >& rxShapes,
191 : : const rtl::OUString& rStyleName, const rtl::OUString& rTextStyle )
192 : : {
193 : 8 : mrAnnotationData.mxShape = rxShape;
194 : 8 : mrAnnotationData.mxShapes = rxShapes;
195 : 8 : mrAnnotationData.maStyleName = rStyleName;
196 : 8 : mrAnnotationData.maTextStyle = rTextStyle;
197 : 8 : }
198 : :
199 : 3 : void ScXMLAnnotationContext::AddContentStyle( sal_uInt16 nFamily, const rtl::OUString& rName, const ESelection& rSelection )
200 : : {
201 [ + - ]: 3 : mrAnnotationData.maContentStyles.push_back( ScXMLAnnotationStyleEntry( nFamily, rName, rSelection ) );
202 : 3 : }
203 : :
204 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|