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