Branch data 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 : :
21 : : #include <com/sun/star/beans/StringPair.hpp>
22 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 : : #include <com/sun/star/io/XActiveDataSource.hpp>
24 : : #include <com/sun/star/xml/sax/XParser.hpp>
25 : : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
26 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 : :
28 : : #include <comphelper/ofopxmlhelper.hxx>
29 : : #include <comphelper/attributelist.hxx>
30 : :
31 : : #define RELATIONINFO_FORMAT 0
32 : : #define CONTENTTYPE_FORMAT 1
33 : : #define FORMAT_MAX_ID CONTENTTYPE_FORMAT
34 : :
35 : : using namespace ::com::sun::star;
36 : :
37 : : namespace comphelper {
38 : :
39 : : // -----------------------------------
40 : 600 : uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::ReadRelationsInfoSequence( const uno::Reference< io::XInputStream >& xInStream, const ::rtl::OUString aStreamName, const uno::Reference< lang::XMultiServiceFactory > xFactory )
41 : : throw( uno::Exception )
42 : : {
43 [ + - ]: 600 : ::rtl::OUString aStringID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/" ) );
44 : 600 : aStringID += aStreamName;
45 [ + - ]: 600 : return ReadSequence_Impl( xInStream, aStringID, RELATIONINFO_FORMAT, xFactory );
46 : : }
47 : :
48 : : // -----------------------------------
49 : 406 : uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::ReadContentTypeSequence( const uno::Reference< io::XInputStream >& xInStream, const uno::Reference< lang::XMultiServiceFactory > xFactory )
50 : : throw( uno::Exception )
51 : : {
52 [ + - ]: 406 : ::rtl::OUString aStringID = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "[Content_Types].xml" ) );
53 [ + - ]: 406 : return ReadSequence_Impl( xInStream, aStringID, CONTENTTYPE_FORMAT, xFactory );
54 : : }
55 : :
56 : : // -----------------------------------
57 : 114 : void SAL_CALL OFOPXMLHelper::WriteRelationsInfoSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< uno::Sequence< beans::StringPair > >& aSequence, const uno::Reference< lang::XMultiServiceFactory > xFactory )
58 : : throw( uno::Exception )
59 : : {
60 [ - + ]: 114 : if ( !xOutStream.is() )
61 [ # # ]: 0 : throw uno::RuntimeException();
62 : :
63 : : uno::Reference< io::XActiveDataSource > xWriterSource(
64 [ + - ]: 114 : xFactory->createInstance(
65 : 114 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ),
66 [ + - ][ + - ]: 114 : uno::UNO_QUERY_THROW );
[ + - ]
67 [ + - ]: 114 : uno::Reference< xml::sax::XDocumentHandler > xWriterHandler( xWriterSource, uno::UNO_QUERY_THROW );
68 : :
69 [ + - ][ + - ]: 114 : xWriterSource->setOutputStream( xOutStream );
70 : :
71 [ + - ]: 114 : ::rtl::OUString aRelListElement( RTL_CONSTASCII_USTRINGPARAM( "Relationships" ) );
72 [ + - ]: 114 : ::rtl::OUString aRelElement( RTL_CONSTASCII_USTRINGPARAM( "Relationship" ) );
73 [ + - ]: 114 : ::rtl::OUString aIDAttr( RTL_CONSTASCII_USTRINGPARAM( "Id" ) );
74 [ + - ]: 114 : ::rtl::OUString aTypeAttr( RTL_CONSTASCII_USTRINGPARAM( "Type" ) );
75 [ + - ]: 114 : ::rtl::OUString aTargetModeAttr( RTL_CONSTASCII_USTRINGPARAM( "TargetMode" ) );
76 [ + - ]: 114 : ::rtl::OUString aTargetAttr( RTL_CONSTASCII_USTRINGPARAM( "Target" ) );
77 [ + - ]: 114 : ::rtl::OUString aCDATAString( RTL_CONSTASCII_USTRINGPARAM ( "CDATA" ) );
78 [ + - ]: 114 : ::rtl::OUString aWhiteSpace( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
79 : :
80 : : // write the namespace
81 [ + - ]: 114 : AttributeList* pRootAttrList = new AttributeList;
82 [ + - ][ + - ]: 114 : uno::Reference< xml::sax::XAttributeList > xRootAttrList( pRootAttrList );
83 : : pRootAttrList->AddAttribute(
84 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "xmlns" ) ),
85 : : aCDATAString,
86 [ + - ][ + - ]: 114 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "http://schemas.openxmlformats.org/package/2006/relationships" ) ) );
[ + - ]
87 : :
88 [ + - ][ + - ]: 114 : xWriterHandler->startDocument();
89 [ + - ][ + - ]: 114 : xWriterHandler->startElement( aRelListElement, xRootAttrList );
90 : :
91 [ + + ]: 459 : for ( sal_Int32 nInd = 0; nInd < aSequence.getLength(); nInd++ )
92 : : {
93 [ + - ]: 345 : AttributeList *pAttrList = new AttributeList;
94 [ + - ][ + - ]: 345 : uno::Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
95 [ + + ]: 1380 : for( sal_Int32 nSecInd = 0; nSecInd < aSequence[nInd].getLength(); nSecInd++ )
96 : : {
97 [ + + + + : 2415 : if ( aSequence[nInd][nSecInd].First.equals( aIDAttr )
+ - + - ]
[ + - ]
98 : 690 : || aSequence[nInd][nSecInd].First.equals( aTypeAttr )
99 : 345 : || aSequence[nInd][nSecInd].First.equals( aTargetModeAttr )
100 : 345 : || aSequence[nInd][nSecInd].First.equals( aTargetAttr ) )
101 : : {
102 [ + - ]: 1035 : pAttrList->AddAttribute( aSequence[nInd][nSecInd].First, aCDATAString, aSequence[nInd][nSecInd].Second );
103 : : }
104 : : else
105 : : {
106 : : // TODO/LATER: should the extensions be allowed?
107 [ # # ]: 0 : throw lang::IllegalArgumentException();
108 : : }
109 : : }
110 : :
111 [ + - ][ + - ]: 345 : xWriterHandler->startElement( aRelElement, xAttrList );
112 [ + - ][ + - ]: 345 : xWriterHandler->ignorableWhitespace( aWhiteSpace );
113 [ + - ][ + - ]: 345 : xWriterHandler->endElement( aRelElement );
114 : 345 : }
115 : :
116 [ + - ][ + - ]: 114 : xWriterHandler->ignorableWhitespace( aWhiteSpace );
117 [ + - ][ + - ]: 114 : xWriterHandler->endElement( aRelListElement );
118 [ + - ][ + - ]: 114 : xWriterHandler->endDocument();
119 : 114 : }
120 : :
121 : : // -----------------------------------
122 : 57 : void SAL_CALL OFOPXMLHelper::WriteContentSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< beans::StringPair >& aDefaultsSequence, const uno::Sequence< beans::StringPair >& aOverridesSequence, const uno::Reference< lang::XMultiServiceFactory > xFactory )
123 : : throw( uno::Exception )
124 : : {
125 [ - + ]: 57 : if ( !xOutStream.is() )
126 [ # # ]: 0 : throw uno::RuntimeException();
127 : :
128 : : uno::Reference< io::XActiveDataSource > xWriterSource(
129 [ + - ]: 57 : xFactory->createInstance(
130 : 57 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ),
131 [ + - ][ + - ]: 57 : uno::UNO_QUERY_THROW );
[ + - ]
132 [ + - ]: 57 : uno::Reference< xml::sax::XDocumentHandler > xWriterHandler( xWriterSource, uno::UNO_QUERY_THROW );
133 : :
134 [ + - ][ + - ]: 57 : xWriterSource->setOutputStream( xOutStream );
135 : :
136 [ + - ]: 57 : ::rtl::OUString aTypesElement( RTL_CONSTASCII_USTRINGPARAM( "Types" ) );
137 [ + - ]: 57 : ::rtl::OUString aDefaultElement( RTL_CONSTASCII_USTRINGPARAM( "Default" ) );
138 [ + - ]: 57 : ::rtl::OUString aOverrideElement( RTL_CONSTASCII_USTRINGPARAM( "Override" ) );
139 [ + - ]: 57 : ::rtl::OUString aExtensionAttr( RTL_CONSTASCII_USTRINGPARAM( "Extension" ) );
140 [ + - ]: 57 : ::rtl::OUString aPartNameAttr( RTL_CONSTASCII_USTRINGPARAM( "PartName" ) );
141 [ + - ]: 57 : ::rtl::OUString aContentTypeAttr( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) );
142 [ + - ]: 57 : ::rtl::OUString aCDATAString( RTL_CONSTASCII_USTRINGPARAM ( "CDATA" ) );
143 [ + - ]: 57 : ::rtl::OUString aWhiteSpace( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
144 : :
145 : : // write the namespace
146 [ + - ]: 57 : AttributeList* pRootAttrList = new AttributeList;
147 [ + - ][ + - ]: 57 : uno::Reference< xml::sax::XAttributeList > xRootAttrList( pRootAttrList );
148 : : pRootAttrList->AddAttribute(
149 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "xmlns" ) ),
150 : : aCDATAString,
151 [ + - ][ + - ]: 57 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "http://schemas.openxmlformats.org/package/2006/content-types" ) ) );
[ + - ]
152 : :
153 [ + - ][ + - ]: 57 : xWriterHandler->startDocument();
154 [ + - ][ + - ]: 57 : xWriterHandler->startElement( aTypesElement, xRootAttrList );
155 : :
156 [ - + ]: 57 : for ( sal_Int32 nInd = 0; nInd < aDefaultsSequence.getLength(); nInd++ )
157 : : {
158 [ # # ]: 0 : AttributeList *pAttrList = new AttributeList;
159 [ # # ][ # # ]: 0 : uno::Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
160 [ # # ]: 0 : pAttrList->AddAttribute( aExtensionAttr, aCDATAString, aDefaultsSequence[nInd].First );
161 [ # # ]: 0 : pAttrList->AddAttribute( aContentTypeAttr, aCDATAString, aDefaultsSequence[nInd].Second );
162 : :
163 [ # # ][ # # ]: 0 : xWriterHandler->startElement( aDefaultElement, xAttrList );
164 [ # # ][ # # ]: 0 : xWriterHandler->ignorableWhitespace( aWhiteSpace );
165 [ # # ][ # # ]: 0 : xWriterHandler->endElement( aDefaultElement );
166 : 0 : }
167 : :
168 [ + + ]: 516 : for ( sal_Int32 nInd = 0; nInd < aOverridesSequence.getLength(); nInd++ )
169 : : {
170 [ + - ]: 459 : AttributeList *pAttrList = new AttributeList;
171 [ + - ][ + - ]: 459 : uno::Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
172 [ + - ]: 459 : pAttrList->AddAttribute( aPartNameAttr, aCDATAString, aOverridesSequence[nInd].First );
173 [ + - ]: 459 : pAttrList->AddAttribute( aContentTypeAttr, aCDATAString, aOverridesSequence[nInd].Second );
174 : :
175 [ + - ][ + - ]: 459 : xWriterHandler->startElement( aOverrideElement, xAttrList );
176 [ + - ][ + - ]: 459 : xWriterHandler->ignorableWhitespace( aWhiteSpace );
177 [ + - ][ + - ]: 459 : xWriterHandler->endElement( aOverrideElement );
178 : 459 : }
179 : :
180 [ + - ][ + - ]: 57 : xWriterHandler->ignorableWhitespace( aWhiteSpace );
181 [ + - ][ + - ]: 57 : xWriterHandler->endElement( aTypesElement );
182 [ + - ][ + - ]: 57 : xWriterHandler->endDocument();
183 : :
184 : 57 : }
185 : :
186 : : // ==================================================================================
187 : :
188 : : // -----------------------------------
189 : 1006 : uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::ReadSequence_Impl( const uno::Reference< io::XInputStream >& xInStream, const ::rtl::OUString& aStringID, sal_uInt16 nFormat, const uno::Reference< lang::XMultiServiceFactory > xFactory )
190 : : throw( uno::Exception )
191 : : {
192 [ + - ][ + - ]: 1006 : if ( !xFactory.is() || !xInStream.is() || nFormat > FORMAT_MAX_ID )
[ - + ][ - + ]
193 [ # # ]: 0 : throw uno::RuntimeException();
194 : :
195 [ + - ]: 1006 : uno::Sequence< uno::Sequence< beans::StringPair > > aResult;
196 : :
197 [ + - ][ + - ]: 1006 : uno::Reference< xml::sax::XParser > xParser( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" ) ) ), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
198 : :
199 [ + - ]: 1006 : OFOPXMLHelper* pHelper = new OFOPXMLHelper( nFormat );
200 [ + - ][ + - ]: 1006 : uno::Reference< xml::sax::XDocumentHandler > xHelper( static_cast< xml::sax::XDocumentHandler* >( pHelper ) );
201 [ + - ]: 1006 : xml::sax::InputSource aParserInput;
202 [ + - ]: 1006 : aParserInput.aInputStream = xInStream;
203 : 1006 : aParserInput.sSystemId = aStringID;
204 [ + - ][ + - ]: 1006 : xParser->setDocumentHandler( xHelper );
205 [ + - ][ + - ]: 1006 : xParser->parseStream( aParserInput );
206 [ + - ][ + - ]: 1006 : xParser->setDocumentHandler( uno::Reference < xml::sax::XDocumentHandler > () );
207 : :
208 [ + - ][ + - ]: 1006 : return pHelper->GetParsingResult();
[ + - ]
209 : : }
210 : :
211 : : // -----------------------------------
212 : 1006 : OFOPXMLHelper::OFOPXMLHelper( sal_uInt16 nFormat )
213 : : : m_nFormat( nFormat )
214 : : , m_aRelListElement( RTL_CONSTASCII_USTRINGPARAM( "Relationships" ) )
215 : : , m_aRelElement( RTL_CONSTASCII_USTRINGPARAM( "Relationship" ) )
216 : : , m_aIDAttr( RTL_CONSTASCII_USTRINGPARAM( "Id" ) )
217 : : , m_aTypeAttr( RTL_CONSTASCII_USTRINGPARAM( "Type" ) )
218 : : , m_aTargetModeAttr( RTL_CONSTASCII_USTRINGPARAM( "TargetMode" ) )
219 : : , m_aTargetAttr( RTL_CONSTASCII_USTRINGPARAM( "Target" ) )
220 : : , m_aTypesElement( RTL_CONSTASCII_USTRINGPARAM( "Types" ) )
221 : : , m_aDefaultElement( RTL_CONSTASCII_USTRINGPARAM( "Default" ) )
222 : : , m_aOverrideElement( RTL_CONSTASCII_USTRINGPARAM( "Override" ) )
223 : : , m_aExtensionAttr( RTL_CONSTASCII_USTRINGPARAM( "Extension" ) )
224 : : , m_aPartNameAttr( RTL_CONSTASCII_USTRINGPARAM( "PartName" ) )
225 [ + - ][ + - ]: 1006 : , m_aContentTypeAttr( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
226 : : {
227 : 1006 : }
228 : :
229 : : // -----------------------------------
230 [ + - ][ + - ]: 1006 : OFOPXMLHelper::~OFOPXMLHelper()
231 : : {
232 [ - + ]: 2012 : }
233 : :
234 : : // -----------------------------------
235 : 1006 : uno::Sequence< uno::Sequence< beans::StringPair > > OFOPXMLHelper::GetParsingResult()
236 : : {
237 [ - + ]: 1006 : if ( m_aElementsSeq.getLength() )
238 [ # # ]: 0 : throw uno::RuntimeException(); // the parsing has still not finished!
239 : :
240 : 1006 : return m_aResultSeq;
241 : : }
242 : :
243 : : // -----------------------------------
244 : 1006 : void SAL_CALL OFOPXMLHelper::startDocument()
245 : : throw(xml::sax::SAXException, uno::RuntimeException)
246 : : {
247 : 1006 : }
248 : :
249 : : // -----------------------------------
250 : 1006 : void SAL_CALL OFOPXMLHelper::endDocument()
251 : : throw(xml::sax::SAXException, uno::RuntimeException)
252 : : {
253 : 1006 : }
254 : :
255 : : // -----------------------------------
256 : 6918 : void SAL_CALL OFOPXMLHelper::startElement( const ::rtl::OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs )
257 : : throw( xml::sax::SAXException, uno::RuntimeException )
258 : : {
259 [ + + ]: 6918 : if ( m_nFormat == RELATIONINFO_FORMAT )
260 : : {
261 [ + + ]: 2665 : if ( aName == m_aRelListElement )
262 : : {
263 : 600 : sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1;
264 : :
265 [ - + ]: 600 : if ( nNewLength != 1 )
266 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: this element must be the first level element
267 : :
268 : 600 : m_aElementsSeq.realloc( nNewLength );
269 : 600 : m_aElementsSeq[nNewLength-1] = aName;
270 : :
271 : 6918 : return; // nothing to do
272 : : }
273 [ + - ]: 2065 : else if ( aName == m_aRelElement )
274 : : {
275 : 2065 : sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1;
276 [ - + ]: 2065 : if ( nNewLength != 2 )
277 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: this element must be the second level element
278 : :
279 [ + - ]: 2065 : m_aElementsSeq.realloc( nNewLength );
280 [ + - ]: 2065 : m_aElementsSeq[nNewLength-1] = aName;
281 : :
282 : 2065 : sal_Int32 nNewEntryNum = m_aResultSeq.getLength() + 1;
283 [ + - ]: 2065 : m_aResultSeq.realloc( nNewEntryNum );
284 : 2065 : sal_Int32 nAttrNum = 0;
285 [ + - ][ + - ]: 2065 : m_aResultSeq[nNewEntryNum-1].realloc( 4 ); // the maximal expected number of arguments is 4
286 : :
287 [ + - ][ + - ]: 2065 : ::rtl::OUString aIDValue = xAttribs->getValueByName( m_aIDAttr );
288 [ - + ]: 2065 : if ( aIDValue.isEmpty() )
289 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: the ID value must present
290 : :
291 [ + - ][ + - ]: 2065 : ::rtl::OUString aTypeValue = xAttribs->getValueByName( m_aTypeAttr );
292 [ + - ][ + - ]: 2065 : ::rtl::OUString aTargetValue = xAttribs->getValueByName( m_aTargetAttr );
293 [ + - ][ + - ]: 2065 : ::rtl::OUString aTargetModeValue = xAttribs->getValueByName( m_aTargetModeAttr );
294 : :
295 [ + - ][ + - ]: 2065 : m_aResultSeq[nNewEntryNum-1][++nAttrNum - 1].First = m_aIDAttr;
296 [ + - ][ + - ]: 2065 : m_aResultSeq[nNewEntryNum-1][nAttrNum - 1].Second = aIDValue;
297 : :
298 [ + - ]: 2065 : if ( !aTypeValue.isEmpty() )
299 : : {
300 [ + - ][ + - ]: 2065 : m_aResultSeq[nNewEntryNum-1][++nAttrNum - 1].First = m_aTypeAttr;
301 [ + - ][ + - ]: 2065 : m_aResultSeq[nNewEntryNum-1][nAttrNum - 1].Second = aTypeValue;
302 : : }
303 : :
304 [ + - ]: 2065 : if ( !aTargetValue.isEmpty() )
305 : : {
306 [ + - ][ + - ]: 2065 : m_aResultSeq[nNewEntryNum-1][++nAttrNum - 1].First = m_aTargetAttr;
307 [ + - ][ + - ]: 2065 : m_aResultSeq[nNewEntryNum-1][nAttrNum - 1].Second = aTargetValue;
308 : : }
309 : :
310 [ - + ]: 2065 : if ( !aTargetModeValue.isEmpty() )
311 : : {
312 [ # # ][ # # ]: 0 : m_aResultSeq[nNewEntryNum-1][++nAttrNum - 1].First = m_aTargetModeAttr;
313 [ # # ][ # # ]: 0 : m_aResultSeq[nNewEntryNum-1][nAttrNum - 1].Second = aTargetModeValue;
314 : : }
315 : :
316 [ + - ][ + - ]: 2065 : m_aResultSeq[nNewEntryNum-1].realloc( nAttrNum );
317 : : }
318 : : else
319 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: no other elements expected!
320 : : }
321 [ + - ]: 4253 : else if ( m_nFormat == CONTENTTYPE_FORMAT )
322 : : {
323 [ + + ]: 4253 : if ( aName == m_aTypesElement )
324 : : {
325 : 406 : sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1;
326 : :
327 [ - + ]: 406 : if ( nNewLength != 1 )
328 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: this element must be the first level element
329 : :
330 : 406 : m_aElementsSeq.realloc( nNewLength );
331 : 406 : m_aElementsSeq[nNewLength-1] = aName;
332 : :
333 [ + - ]: 406 : if ( !m_aResultSeq.getLength() )
334 : 406 : m_aResultSeq.realloc( 2 );
335 : :
336 : 406 : return; // nothing to do
337 : : }
338 [ + + ]: 3847 : else if ( aName == m_aDefaultElement )
339 : : {
340 : 377 : sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1;
341 [ - + ]: 377 : if ( nNewLength != 2 )
342 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: this element must be the second level element
343 : :
344 [ + - ]: 377 : m_aElementsSeq.realloc( nNewLength );
345 [ + - ]: 377 : m_aElementsSeq[nNewLength-1] = aName;
346 : :
347 [ - + ]: 377 : if ( !m_aResultSeq.getLength() )
348 [ # # ]: 0 : m_aResultSeq.realloc( 2 );
349 : :
350 [ - + ]: 377 : if ( m_aResultSeq.getLength() != 2 )
351 [ # # ]: 0 : throw uno::RuntimeException();
352 : :
353 [ + - ][ + - ]: 377 : ::rtl::OUString aExtensionValue = xAttribs->getValueByName( m_aExtensionAttr );
354 [ - + ]: 377 : if ( aExtensionValue.isEmpty() )
355 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: the Extension value must present
356 : :
357 [ + - ][ + - ]: 377 : ::rtl::OUString aContentTypeValue = xAttribs->getValueByName( m_aContentTypeAttr );
358 [ - + ]: 377 : if ( aContentTypeValue.isEmpty() )
359 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: the ContentType value must present
360 : :
361 [ + - ]: 377 : sal_Int32 nNewResultLen = m_aResultSeq[0].getLength() + 1;
362 [ + - ][ + - ]: 377 : m_aResultSeq[0].realloc( nNewResultLen );
363 : :
364 [ + - ][ + - ]: 377 : m_aResultSeq[0][nNewResultLen-1].First = aExtensionValue;
365 [ + - ][ + - ]: 377 : m_aResultSeq[0][nNewResultLen-1].Second = aContentTypeValue;
366 : : }
367 [ + - ]: 3470 : else if ( aName == m_aOverrideElement )
368 : : {
369 : 3470 : sal_Int32 nNewLength = m_aElementsSeq.getLength() + 1;
370 [ - + ]: 3470 : if ( nNewLength != 2 )
371 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: this element must be the second level element
372 : :
373 [ + - ]: 3470 : m_aElementsSeq.realloc( nNewLength );
374 [ + - ]: 3470 : m_aElementsSeq[nNewLength-1] = aName;
375 : :
376 [ - + ]: 3470 : if ( !m_aResultSeq.getLength() )
377 [ # # ]: 0 : m_aResultSeq.realloc( 2 );
378 : :
379 [ - + ]: 3470 : if ( m_aResultSeq.getLength() != 2 )
380 [ # # ]: 0 : throw uno::RuntimeException();
381 : :
382 [ + - ][ + - ]: 3470 : ::rtl::OUString aPartNameValue = xAttribs->getValueByName( m_aPartNameAttr );
383 [ - + ]: 3470 : if ( aPartNameValue.isEmpty() )
384 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: the PartName value must present
385 : :
386 [ + - ][ + - ]: 3470 : ::rtl::OUString aContentTypeValue = xAttribs->getValueByName( m_aContentTypeAttr );
387 [ - + ]: 3470 : if ( aContentTypeValue.isEmpty() )
388 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: the ContentType value must present
389 : :
390 [ + - ]: 3470 : sal_Int32 nNewResultLen = m_aResultSeq[1].getLength() + 1;
391 [ + - ][ + - ]: 3470 : m_aResultSeq[1].realloc( nNewResultLen );
392 : :
393 [ + - ][ + - ]: 3470 : m_aResultSeq[1][nNewResultLen-1].First = aPartNameValue;
394 [ + - ][ + - ]: 3470 : m_aResultSeq[1][nNewResultLen-1].Second = aContentTypeValue;
395 : : }
396 : : else
397 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: no other elements expected!
398 : : }
399 : : else
400 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: no other elements expected!
401 : : }
402 : :
403 : : // -----------------------------------
404 : 6918 : void SAL_CALL OFOPXMLHelper::endElement( const ::rtl::OUString& aName )
405 : : throw( xml::sax::SAXException, uno::RuntimeException )
406 : : {
407 [ + + ][ + - ]: 6918 : if ( m_nFormat == RELATIONINFO_FORMAT || m_nFormat == CONTENTTYPE_FORMAT )
408 : : {
409 : 6918 : sal_Int32 nLength = m_aElementsSeq.getLength();
410 [ - + ]: 6918 : if ( nLength <= 0 )
411 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: no other end elements expected!
412 : :
413 [ - + ]: 6918 : if ( !m_aElementsSeq[nLength-1].equals( aName ) )
414 [ # # ]: 0 : throw xml::sax::SAXException(); // TODO: unexpected element ended
415 : :
416 : 6918 : m_aElementsSeq.realloc( nLength - 1 );
417 : : }
418 : 6918 : }
419 : :
420 : : // -----------------------------------
421 : 576 : void SAL_CALL OFOPXMLHelper::characters( const ::rtl::OUString& /*aChars*/ )
422 : : throw(xml::sax::SAXException, uno::RuntimeException)
423 : : {
424 : 576 : }
425 : :
426 : : // -----------------------------------
427 : 0 : void SAL_CALL OFOPXMLHelper::ignorableWhitespace( const ::rtl::OUString& /*aWhitespaces*/ )
428 : : throw(xml::sax::SAXException, uno::RuntimeException)
429 : : {
430 : 0 : }
431 : :
432 : : // -----------------------------------
433 : 0 : void SAL_CALL OFOPXMLHelper::processingInstruction( const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ )
434 : : throw(xml::sax::SAXException, uno::RuntimeException)
435 : : {
436 : 0 : }
437 : :
438 : : // -----------------------------------
439 : 1006 : void SAL_CALL OFOPXMLHelper::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ )
440 : : throw(xml::sax::SAXException, uno::RuntimeException)
441 : : {
442 : 1006 : }
443 : :
444 : : } // namespace comphelper
445 : :
446 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|