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