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