xref: /trunk/main/sc/source/filter/xml/xmlannoi.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 // INCLUDE ---------------------------------------------------------------
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 
ScXMLAnnotationData()44 ScXMLAnnotationData::ScXMLAnnotationData() :
45     mbUseShapePos( false ),
46     mbShown( false )
47 {
48 }
49 
~ScXMLAnnotationData()50 ScXMLAnnotationData::~ScXMLAnnotationData()
51 {
52 }
53 
54 //------------------------------------------------------------------
55 
ScXMLAnnotationContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,ScXMLAnnotationData & rAnnotationData,ScXMLTableRowCellContext * pTempCellContext)56 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 	bHasTextP(sal_False),
66     pCellContext(pTempCellContext),
67     pShapeContext(NULL)
68 {
69 	uno::Reference<drawing::XShapes> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
70 	if (xLocalShapes.is())
71 	{
72 	    XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
73 	    pTableShapeImport->SetAnnotation(this);
74 	    pShapeContext = GetScImport().GetShapeImport()->CreateGroupChildContext(
75 		    GetScImport(), nPrfx, rLName, xAttrList, xLocalShapes, sal_True);
76     }
77 
78 	pCellContext = pTempCellContext;
79 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
80 	const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableAnnotationAttrTokenMap();
81 	for( sal_Int16 i=0; i < nAttrCount; ++i )
82 	{
83         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
84 		rtl::OUString aLocalName;
85 		sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
86 											sAttrName, &aLocalName );
87 		const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
88 
89 		switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
90 		{
91 			case XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR:
92 			{
93                 maAuthorBuffer = sValue;
94 			}
95 			break;
96 			case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE:
97 			{
98                 maCreateDateBuffer = sValue;
99 			}
100 			break;
101 			case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING:
102 			{
103                 maCreateDateStringBuffer = sValue;
104 			}
105 			break;
106 			case XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY:
107 			{
108                 mrAnnotationData.mbShown = IsXMLToken(sValue, XML_TRUE);
109 			}
110 			break;
111 			case XML_TOK_TABLE_ANNOTATION_ATTR_X:
112 			{
113                 mrAnnotationData.mbUseShapePos = true;
114 			}
115 			break;
116 			case XML_TOK_TABLE_ANNOTATION_ATTR_Y:
117 			{
118                 mrAnnotationData.mbUseShapePos = true;
119 			}
120 			break;
121 		}
122 	}
123 }
124 
~ScXMLAnnotationContext()125 ScXMLAnnotationContext::~ScXMLAnnotationContext()
126 {
127 }
128 
StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> & xAttrList)129 void ScXMLAnnotationContext::StartElement(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList)
130 {
131     if (pShapeContext)
132         pShapeContext->StartElement(xAttrList);
133 }
134 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)135 SvXMLImportContext *ScXMLAnnotationContext::CreateChildContext( sal_uInt16 nPrefix,
136 											const ::rtl::OUString& rLName,
137 											const ::com::sun::star::uno::Reference<
138 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList )
139 {
140 	SvXMLImportContext *pContext = 0;
141 
142 	if( XML_NAMESPACE_DC == nPrefix )
143 	{
144 		if( IsXMLToken( rLName, XML_CREATOR ) )
145 			pContext = new ScXMLContentContext(GetScImport(), nPrefix,
146                                             rLName, xAttrList, maAuthorBuffer);
147 		else if( IsXMLToken( rLName, XML_DATE ) )
148 			pContext = new ScXMLContentContext(GetScImport(), nPrefix,
149                                             rLName, xAttrList, maCreateDateBuffer);
150 	}
151 	else if( XML_NAMESPACE_META == nPrefix )
152     {
153 		if( IsXMLToken( rLName, XML_DATE_STRING ) )
154 			pContext = new ScXMLContentContext(GetScImport(), nPrefix,
155                                             rLName, xAttrList, maCreateDateStringBuffer);
156     }
157 /*	else if ((nPrefix == XML_NAMESPACE_TEXT) && IsXMLToken(rLName, XML_P) )
158 	{
159 		if (!bHasTextP)
160 		{
161 			bHasTextP = sal_True;
162             maTextBuffer.setLength(0);
163 		}
164 		if(nParagraphCount)
165             maTextBuffer.append(static_cast<sal_Unicode>('\n'));
166 		++nParagraphCount;
167         pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, maTextBuffer);
168 	}*/
169 
170 	if( !pContext && pShapeContext )
171         pContext = pShapeContext->CreateChildContext(nPrefix, rLName, xAttrList);
172 
173 	if( !pContext )
174 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
175 
176 	return pContext;
177 }
178 
Characters(const::rtl::OUString & rChars)179 void ScXMLAnnotationContext::Characters( const ::rtl::OUString& rChars )
180 {
181 	if (!bHasTextP)
182         maTextBuffer.append(rChars);
183 }
184 
EndElement()185 void ScXMLAnnotationContext::EndElement()
186 {
187     if (pShapeContext)
188     {
189         pShapeContext->EndElement();
190         delete pShapeContext;
191     }
192 
193     mrAnnotationData.maAuthor = maAuthorBuffer.makeStringAndClear();
194     mrAnnotationData.maCreateDate = maCreateDateBuffer.makeStringAndClear();
195     if (!mrAnnotationData.maCreateDate.getLength())
196         mrAnnotationData.maCreateDate = maCreateDateStringBuffer.makeStringAndClear();
197     mrAnnotationData.maSimpleText = maTextBuffer.makeStringAndClear();
198 
199     XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
200 	pTableShapeImport->SetAnnotation(NULL);
201 }
202 
SetShape(const uno::Reference<drawing::XShape> & rxShape,const uno::Reference<drawing::XShapes> & rxShapes,const rtl::OUString & rStyleName,const rtl::OUString & rTextStyle)203 void ScXMLAnnotationContext::SetShape( const uno::Reference< drawing::XShape >& rxShape, const uno::Reference< drawing::XShapes >& rxShapes,
204                                        const rtl::OUString& rStyleName, const rtl::OUString& rTextStyle )
205 {
206     mrAnnotationData.mxShape = rxShape;
207     mrAnnotationData.mxShapes = rxShapes;
208     mrAnnotationData.maStyleName = rStyleName;
209     mrAnnotationData.maTextStyle = rTextStyle;
210 }
211 
AddContentStyle(sal_uInt16 nFamily,const rtl::OUString & rName,const ESelection & rSelection)212 void ScXMLAnnotationContext::AddContentStyle( sal_uInt16 nFamily, const rtl::OUString& rName, const ESelection& rSelection )
213 {
214     mrAnnotationData.maContentStyles.push_back( ScXMLAnnotationStyleEntry( nFamily, rName, rSelection ) );
215 }
216 
217