1e1d5bd03SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3e1d5bd03SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4e1d5bd03SAndrew Rist * or more contributor license agreements. See the NOTICE file 5e1d5bd03SAndrew Rist * distributed with this work for additional information 6e1d5bd03SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7e1d5bd03SAndrew Rist * to you under the Apache License, Version 2.0 (the 8e1d5bd03SAndrew Rist * "License"); you may not use this file except in compliance 9e1d5bd03SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11e1d5bd03SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13e1d5bd03SAndrew Rist * Unless required by applicable law or agreed to in writing, 14e1d5bd03SAndrew Rist * software distributed under the License is distributed on an 15e1d5bd03SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16e1d5bd03SAndrew Rist * KIND, either express or implied. See the License for the 17e1d5bd03SAndrew Rist * specific language governing permissions and limitations 18e1d5bd03SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20e1d5bd03SAndrew Rist *************************************************************/ 21e1d5bd03SAndrew Rist 22e1d5bd03SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmlscript.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "osl/diagnose.h" 28cdf0e10cSrcweir #include "osl/mutex.hxx" 29cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 30cdf0e10cSrcweir #include "cppuhelper/factory.hxx" 31cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx" 32cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx" 33cdf0e10cSrcweir #include "cppuhelper/implbase3.hxx" 34*b63233d8Sdamjan #include "xml_import.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include "com/sun/star/xml/input/XAttributes.hpp" 37cdf0e10cSrcweir #include "com/sun/star/lang/XInitialization.hpp" 38cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <vector> 41cdf0e10cSrcweir #include <hash_map> 42cdf0e10cSrcweir 43cdf0e10cSrcweir #include <memory> 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace ::rtl; 47cdf0e10cSrcweir using namespace ::osl; 48cdf0e10cSrcweir using namespace ::com::sun::star; 49cdf0e10cSrcweir using namespace ::com::sun::star::uno; 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace xmlscript 52cdf0e10cSrcweir { 53cdf0e10cSrcweir 54cdf0e10cSrcweir const sal_Int32 UID_UNKNOWN = -1; 55cdf0e10cSrcweir 56cdf0e10cSrcweir Sequence< OUString > getSupportedServiceNames_DocumentHandlerImpl() 57cdf0e10cSrcweir { 58cdf0e10cSrcweir OUString name( RTL_CONSTASCII_USTRINGPARAM( 59cdf0e10cSrcweir "com.sun.star.xml.input.SaxDocumentHandler") ); 60cdf0e10cSrcweir return Sequence< OUString >( &name, 1 ); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir OUString getImplementationName_DocumentHandlerImpl() 64cdf0e10cSrcweir { 65cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( 66cdf0e10cSrcweir "com.sun.star.comp.xml.input.SaxDocumentHandler") ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir typedef ::std::hash_map< OUString, sal_Int32, OUStringHash > t_OUString2LongMap; 70cdf0e10cSrcweir typedef ::std::hash_map< sal_Int32, OUString > t_Long2OUStringMap; 71cdf0e10cSrcweir 72cdf0e10cSrcweir struct PrefixEntry 73cdf0e10cSrcweir { 74cdf0e10cSrcweir ::std::vector< sal_Int32 > m_Uids; 75cdf0e10cSrcweir 76cdf0e10cSrcweir inline PrefixEntry() SAL_THROW( () ) 77cdf0e10cSrcweir { m_Uids.reserve( 4 ); } 78cdf0e10cSrcweir }; 79cdf0e10cSrcweir 80cdf0e10cSrcweir typedef ::std::hash_map< 81cdf0e10cSrcweir OUString, PrefixEntry *, OUStringHash > t_OUString2PrefixMap; 82cdf0e10cSrcweir 83cdf0e10cSrcweir struct ElementEntry 84cdf0e10cSrcweir { 85cdf0e10cSrcweir Reference< xml::input::XElement > m_xElement; 86cdf0e10cSrcweir ::std::vector< OUString > m_prefixes; 87cdf0e10cSrcweir 88cdf0e10cSrcweir inline ElementEntry() 89cdf0e10cSrcweir { m_prefixes.reserve( 2 ); } 90cdf0e10cSrcweir }; 91cdf0e10cSrcweir 92cdf0e10cSrcweir typedef ::std::vector< ElementEntry * > t_ElementVector; 93cdf0e10cSrcweir 94cdf0e10cSrcweir class ExtendedAttributes; 95cdf0e10cSrcweir 96cdf0e10cSrcweir //============================================================================== 97cdf0e10cSrcweir struct MGuard 98cdf0e10cSrcweir { 99cdf0e10cSrcweir Mutex * m_pMutex; 100cdf0e10cSrcweir explicit MGuard( Mutex * pMutex ) 101cdf0e10cSrcweir : m_pMutex( pMutex ) 102cdf0e10cSrcweir { if (m_pMutex) m_pMutex->acquire(); } 103cdf0e10cSrcweir ~MGuard() throw () 104cdf0e10cSrcweir { if (m_pMutex) m_pMutex->release(); } 105cdf0e10cSrcweir }; 106cdf0e10cSrcweir 107cdf0e10cSrcweir //============================================================================== 108cdf0e10cSrcweir class DocumentHandlerImpl : 109cdf0e10cSrcweir public ::cppu::WeakImplHelper3< xml::sax::XDocumentHandler, 110cdf0e10cSrcweir xml::input::XNamespaceMapping, 111cdf0e10cSrcweir lang::XInitialization > 112cdf0e10cSrcweir { 113cdf0e10cSrcweir friend class ExtendedAttributes; 114cdf0e10cSrcweir 115cdf0e10cSrcweir Reference< xml::input::XRoot > m_xRoot; 116cdf0e10cSrcweir 117cdf0e10cSrcweir t_OUString2LongMap m_URI2Uid; 118cdf0e10cSrcweir sal_Int32 m_uid_count; 119cdf0e10cSrcweir 120cdf0e10cSrcweir OUString m_sXMLNS_PREFIX_UNKNOWN; 121cdf0e10cSrcweir OUString m_sXMLNS; 122cdf0e10cSrcweir 123cdf0e10cSrcweir sal_Int32 m_nLastURI_lookup; 124cdf0e10cSrcweir OUString m_aLastURI_lookup; 125cdf0e10cSrcweir 126cdf0e10cSrcweir t_OUString2PrefixMap m_prefixes; 127cdf0e10cSrcweir sal_Int32 m_nLastPrefix_lookup; 128cdf0e10cSrcweir OUString m_aLastPrefix_lookup; 129cdf0e10cSrcweir 130cdf0e10cSrcweir t_ElementVector m_elements; 131cdf0e10cSrcweir sal_Int32 m_nSkipElements; 132cdf0e10cSrcweir 133cdf0e10cSrcweir Mutex * m_pMutex; 134cdf0e10cSrcweir 135cdf0e10cSrcweir inline Reference< xml::input::XElement > getCurrentElement() const; 136cdf0e10cSrcweir 137cdf0e10cSrcweir inline sal_Int32 getUidByURI( OUString const & rURI ); 138cdf0e10cSrcweir inline sal_Int32 getUidByPrefix( OUString const & rPrefix ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir inline void pushPrefix( 141cdf0e10cSrcweir OUString const & rPrefix, OUString const & rURI ); 142cdf0e10cSrcweir inline void popPrefix( OUString const & rPrefix ); 143cdf0e10cSrcweir 144cdf0e10cSrcweir inline void getElementName( 145cdf0e10cSrcweir OUString const & rQName, sal_Int32 * pUid, OUString * pLocalName ); 146cdf0e10cSrcweir 147cdf0e10cSrcweir public: 148cdf0e10cSrcweir DocumentHandlerImpl( 149cdf0e10cSrcweir Reference< xml::input::XRoot > const & xRoot, 150cdf0e10cSrcweir bool bSingleThreadedUse ); 151cdf0e10cSrcweir virtual ~DocumentHandlerImpl() throw (); 152cdf0e10cSrcweir 153cdf0e10cSrcweir // XServiceInfo 154cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName() 155cdf0e10cSrcweir throw (RuntimeException); 156cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( 157cdf0e10cSrcweir OUString const & servicename ) 158cdf0e10cSrcweir throw (RuntimeException); 159cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() 160cdf0e10cSrcweir throw (RuntimeException); 161cdf0e10cSrcweir 162cdf0e10cSrcweir // XInitialization 163cdf0e10cSrcweir virtual void SAL_CALL initialize( 164cdf0e10cSrcweir Sequence< Any > const & arguments ) 165cdf0e10cSrcweir throw (Exception); 166cdf0e10cSrcweir 167cdf0e10cSrcweir // XDocumentHandler 168cdf0e10cSrcweir virtual void SAL_CALL startDocument() 169cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 170cdf0e10cSrcweir virtual void SAL_CALL endDocument() 171cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 172cdf0e10cSrcweir virtual void SAL_CALL startElement( 173cdf0e10cSrcweir OUString const & rQElementName, 174cdf0e10cSrcweir Reference< xml::sax::XAttributeList > const & xAttribs ) 175cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 176cdf0e10cSrcweir virtual void SAL_CALL endElement( 177cdf0e10cSrcweir OUString const & rQElementName ) 178cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 179cdf0e10cSrcweir virtual void SAL_CALL characters( 180cdf0e10cSrcweir OUString const & rChars ) 181cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 182cdf0e10cSrcweir virtual void SAL_CALL ignorableWhitespace( 183cdf0e10cSrcweir OUString const & rWhitespaces ) 184cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 185cdf0e10cSrcweir virtual void SAL_CALL processingInstruction( 186cdf0e10cSrcweir OUString const & rTarget, OUString const & rData ) 187cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 188cdf0e10cSrcweir virtual void SAL_CALL setDocumentLocator( 189cdf0e10cSrcweir Reference< xml::sax::XLocator > const & xLocator ) 190cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException); 191cdf0e10cSrcweir 192cdf0e10cSrcweir // XNamespaceMapping 193cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getUidByUri( OUString const & Uri ) 194cdf0e10cSrcweir throw (RuntimeException); 195cdf0e10cSrcweir virtual OUString SAL_CALL getUriByUid( sal_Int32 Uid ) 196cdf0e10cSrcweir throw (container::NoSuchElementException, RuntimeException); 197cdf0e10cSrcweir }; 198cdf0e10cSrcweir 199cdf0e10cSrcweir //______________________________________________________________________________ 200cdf0e10cSrcweir DocumentHandlerImpl::DocumentHandlerImpl( 201cdf0e10cSrcweir Reference< xml::input::XRoot > const & xRoot, 202cdf0e10cSrcweir bool bSingleThreadedUse ) 203cdf0e10cSrcweir : m_xRoot( xRoot ), 204cdf0e10cSrcweir m_uid_count( 0 ), 205cdf0e10cSrcweir m_sXMLNS_PREFIX_UNKNOWN( 206cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("<<< unknown prefix >>>") ), 207cdf0e10cSrcweir m_sXMLNS( RTL_CONSTASCII_USTRINGPARAM("xmlns") ), 208cdf0e10cSrcweir m_nLastURI_lookup( UID_UNKNOWN ), 209cdf0e10cSrcweir m_aLastURI_lookup( RTL_CONSTASCII_USTRINGPARAM("<<< unknown URI >>>") ), 210cdf0e10cSrcweir m_nLastPrefix_lookup( UID_UNKNOWN ), 211cdf0e10cSrcweir m_aLastPrefix_lookup( 212cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("<<< unknown URI >>>") ), 213cdf0e10cSrcweir m_nSkipElements( 0 ), 214cdf0e10cSrcweir m_pMutex( 0 ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir m_elements.reserve( 10 ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir if (! bSingleThreadedUse) 219cdf0e10cSrcweir m_pMutex = new Mutex(); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir //______________________________________________________________________________ 223cdf0e10cSrcweir DocumentHandlerImpl::~DocumentHandlerImpl() throw () 224cdf0e10cSrcweir { 225cdf0e10cSrcweir if (m_pMutex != 0) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir delete m_pMutex; 228cdf0e10cSrcweir #if OSL_DEBUG_LEVEL == 0 229cdf0e10cSrcweir m_pMutex = 0; 230cdf0e10cSrcweir #endif 231cdf0e10cSrcweir } 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir //______________________________________________________________________________ 235cdf0e10cSrcweir inline Reference< xml::input::XElement > 236cdf0e10cSrcweir DocumentHandlerImpl::getCurrentElement() const 237cdf0e10cSrcweir { 238cdf0e10cSrcweir MGuard aGuard( m_pMutex ); 239cdf0e10cSrcweir if (m_elements.empty()) 240cdf0e10cSrcweir return Reference< xml::input::XElement >(); 241cdf0e10cSrcweir else 242cdf0e10cSrcweir return m_elements.back()->m_xElement; 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir //______________________________________________________________________________ 246cdf0e10cSrcweir inline sal_Int32 DocumentHandlerImpl::getUidByURI( OUString const & rURI ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir MGuard guard( m_pMutex ); 249cdf0e10cSrcweir if (m_nLastURI_lookup == UID_UNKNOWN || m_aLastURI_lookup != rURI) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir t_OUString2LongMap::const_iterator iFind( m_URI2Uid.find( rURI ) ); 252cdf0e10cSrcweir if (iFind != m_URI2Uid.end()) // id found 253cdf0e10cSrcweir { 254cdf0e10cSrcweir m_nLastURI_lookup = iFind->second; 255cdf0e10cSrcweir m_aLastURI_lookup = rURI; 256cdf0e10cSrcweir } 257cdf0e10cSrcweir else 258cdf0e10cSrcweir { 259cdf0e10cSrcweir m_nLastURI_lookup = m_uid_count; 260cdf0e10cSrcweir ++m_uid_count; 261cdf0e10cSrcweir m_URI2Uid[ rURI ] = m_nLastURI_lookup; 262cdf0e10cSrcweir m_aLastURI_lookup = rURI; 263cdf0e10cSrcweir } 264cdf0e10cSrcweir } 265cdf0e10cSrcweir return m_nLastURI_lookup; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir //______________________________________________________________________________ 269cdf0e10cSrcweir inline sal_Int32 DocumentHandlerImpl::getUidByPrefix( 270cdf0e10cSrcweir OUString const & rPrefix ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir // commonly the last added prefix is used often for several tags... 273cdf0e10cSrcweir // good guess 274cdf0e10cSrcweir if (m_nLastPrefix_lookup == UID_UNKNOWN || m_aLastPrefix_lookup != rPrefix) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir t_OUString2PrefixMap::const_iterator iFind( 277cdf0e10cSrcweir m_prefixes.find( rPrefix ) ); 278cdf0e10cSrcweir if (iFind != m_prefixes.end()) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir const PrefixEntry & rPrefixEntry = *iFind->second; 281cdf0e10cSrcweir OSL_ASSERT( ! rPrefixEntry.m_Uids.empty() ); 282cdf0e10cSrcweir m_nLastPrefix_lookup = rPrefixEntry.m_Uids.back(); 283cdf0e10cSrcweir m_aLastPrefix_lookup = rPrefix; 284cdf0e10cSrcweir } 285cdf0e10cSrcweir else 286cdf0e10cSrcweir { 287cdf0e10cSrcweir m_nLastPrefix_lookup = UID_UNKNOWN; 288cdf0e10cSrcweir m_aLastPrefix_lookup = m_sXMLNS_PREFIX_UNKNOWN; 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir return m_nLastPrefix_lookup; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir //______________________________________________________________________________ 295cdf0e10cSrcweir inline void DocumentHandlerImpl::pushPrefix( 296cdf0e10cSrcweir OUString const & rPrefix, OUString const & rURI ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir // lookup id for URI 299cdf0e10cSrcweir sal_Int32 nUid = getUidByURI( rURI ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir // mark prefix with id 302cdf0e10cSrcweir t_OUString2PrefixMap::const_iterator iFind( m_prefixes.find( rPrefix ) ); 303cdf0e10cSrcweir if (iFind == m_prefixes.end()) // unused prefix 304cdf0e10cSrcweir { 305cdf0e10cSrcweir PrefixEntry * pEntry = new PrefixEntry(); 306cdf0e10cSrcweir pEntry->m_Uids.push_back( nUid ); // latest id for prefix 307cdf0e10cSrcweir m_prefixes[ rPrefix ] = pEntry; 308cdf0e10cSrcweir } 309cdf0e10cSrcweir else 310cdf0e10cSrcweir { 311cdf0e10cSrcweir PrefixEntry * pEntry = iFind->second; 312cdf0e10cSrcweir OSL_ASSERT( ! pEntry->m_Uids.empty() ); 313cdf0e10cSrcweir pEntry->m_Uids.push_back( nUid ); 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir m_aLastPrefix_lookup = rPrefix; 317cdf0e10cSrcweir m_nLastPrefix_lookup = nUid; 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir //______________________________________________________________________________ 321cdf0e10cSrcweir inline void DocumentHandlerImpl::popPrefix( 322cdf0e10cSrcweir OUString const & rPrefix ) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir t_OUString2PrefixMap::iterator iFind( m_prefixes.find( rPrefix ) ); 325cdf0e10cSrcweir if (iFind != m_prefixes.end()) // unused prefix 326cdf0e10cSrcweir { 327cdf0e10cSrcweir PrefixEntry * pEntry = iFind->second; 328cdf0e10cSrcweir pEntry->m_Uids.pop_back(); // pop last id for prefix 329cdf0e10cSrcweir if (pEntry->m_Uids.empty()) // erase prefix key 330cdf0e10cSrcweir { 331cdf0e10cSrcweir m_prefixes.erase( iFind ); 332cdf0e10cSrcweir delete pEntry; 333cdf0e10cSrcweir } 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir m_nLastPrefix_lookup = UID_UNKNOWN; 337cdf0e10cSrcweir m_aLastPrefix_lookup = m_sXMLNS_PREFIX_UNKNOWN; 338cdf0e10cSrcweir } 339cdf0e10cSrcweir 340cdf0e10cSrcweir //______________________________________________________________________________ 341cdf0e10cSrcweir inline void DocumentHandlerImpl::getElementName( 342cdf0e10cSrcweir OUString const & rQName, sal_Int32 * pUid, OUString * pLocalName ) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir sal_Int32 nColonPos = rQName.indexOf( (sal_Unicode)':' ); 345cdf0e10cSrcweir *pLocalName = (nColonPos >= 0 ? rQName.copy( nColonPos +1 ) : rQName); 346cdf0e10cSrcweir *pUid = getUidByPrefix( 347cdf0e10cSrcweir nColonPos >= 0 ? rQName.copy( 0, nColonPos ) : OUString() ); 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir 351cdf0e10cSrcweir //============================================================================== 352cdf0e10cSrcweir class ExtendedAttributes : 353cdf0e10cSrcweir public ::cppu::WeakImplHelper1< xml::input::XAttributes > 354cdf0e10cSrcweir { 355cdf0e10cSrcweir sal_Int32 m_nAttributes; 356cdf0e10cSrcweir sal_Int32 * m_pUids; 357cdf0e10cSrcweir OUString * m_pPrefixes; 358cdf0e10cSrcweir OUString * m_pLocalNames; 359cdf0e10cSrcweir OUString * m_pQNames; 360cdf0e10cSrcweir OUString * m_pValues; 361cdf0e10cSrcweir 362cdf0e10cSrcweir DocumentHandlerImpl * m_pHandler; 363cdf0e10cSrcweir 364cdf0e10cSrcweir public: 365cdf0e10cSrcweir inline ExtendedAttributes( 366cdf0e10cSrcweir sal_Int32 nAttributes, 367cdf0e10cSrcweir sal_Int32 * pUids, OUString * pPrefixes, 368cdf0e10cSrcweir OUString * pLocalNames, OUString * pQNames, 369cdf0e10cSrcweir Reference< xml::sax::XAttributeList > const & xAttributeList, 370cdf0e10cSrcweir DocumentHandlerImpl * pHandler ); 371cdf0e10cSrcweir virtual ~ExtendedAttributes() throw (); 372cdf0e10cSrcweir 373cdf0e10cSrcweir // XAttributes 374cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getLength() 375cdf0e10cSrcweir throw (RuntimeException); 376cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getIndexByQName( 377cdf0e10cSrcweir OUString const & rQName ) 378cdf0e10cSrcweir throw (RuntimeException); 379cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getIndexByUidName( 380cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName ) 381cdf0e10cSrcweir throw (RuntimeException); 382cdf0e10cSrcweir virtual OUString SAL_CALL getQNameByIndex( 383cdf0e10cSrcweir sal_Int32 nIndex ) 384cdf0e10cSrcweir throw (RuntimeException); 385cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getUidByIndex( 386cdf0e10cSrcweir sal_Int32 nIndex ) 387cdf0e10cSrcweir throw (RuntimeException); 388cdf0e10cSrcweir virtual OUString SAL_CALL getLocalNameByIndex( 389cdf0e10cSrcweir sal_Int32 nIndex ) 390cdf0e10cSrcweir throw (RuntimeException); 391cdf0e10cSrcweir virtual OUString SAL_CALL getValueByIndex( 392cdf0e10cSrcweir sal_Int32 nIndex ) 393cdf0e10cSrcweir throw (RuntimeException); 394cdf0e10cSrcweir virtual OUString SAL_CALL getValueByUidName( 395cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName ) 396cdf0e10cSrcweir throw (RuntimeException); 397cdf0e10cSrcweir virtual OUString SAL_CALL getTypeByIndex( 398cdf0e10cSrcweir sal_Int32 nIndex ) 399cdf0e10cSrcweir throw (RuntimeException); 400cdf0e10cSrcweir }; 401cdf0e10cSrcweir 402cdf0e10cSrcweir //______________________________________________________________________________ 403cdf0e10cSrcweir inline ExtendedAttributes::ExtendedAttributes( 404cdf0e10cSrcweir sal_Int32 nAttributes, 405cdf0e10cSrcweir sal_Int32 * pUids, OUString * pPrefixes, 406cdf0e10cSrcweir OUString * pLocalNames, OUString * pQNames, 407cdf0e10cSrcweir Reference< xml::sax::XAttributeList > const & xAttributeList, 408cdf0e10cSrcweir DocumentHandlerImpl * pHandler ) 409cdf0e10cSrcweir : m_nAttributes( nAttributes ) 410cdf0e10cSrcweir , m_pUids( pUids ) 411cdf0e10cSrcweir , m_pPrefixes( pPrefixes ) 412cdf0e10cSrcweir , m_pLocalNames( pLocalNames ) 413cdf0e10cSrcweir , m_pQNames( pQNames ) 414cdf0e10cSrcweir , m_pValues( new OUString[ nAttributes ] ) 415cdf0e10cSrcweir , m_pHandler( pHandler ) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir m_pHandler->acquire(); 418cdf0e10cSrcweir 419cdf0e10cSrcweir for ( sal_Int16 nPos = 0; nPos < nAttributes; ++nPos ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir m_pValues[ nPos ] = xAttributeList->getValueByIndex( nPos ); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir //______________________________________________________________________________ 426cdf0e10cSrcweir ExtendedAttributes::~ExtendedAttributes() throw () 427cdf0e10cSrcweir { 428cdf0e10cSrcweir m_pHandler->release(); 429cdf0e10cSrcweir 430cdf0e10cSrcweir delete [] m_pUids; 431cdf0e10cSrcweir delete [] m_pPrefixes; 432cdf0e10cSrcweir delete [] m_pLocalNames; 433cdf0e10cSrcweir delete [] m_pQNames; 434cdf0e10cSrcweir delete [] m_pValues; 435cdf0e10cSrcweir } 436cdf0e10cSrcweir 437cdf0e10cSrcweir 438cdf0e10cSrcweir //############################################################################## 439cdf0e10cSrcweir 440cdf0e10cSrcweir // XServiceInfo 441cdf0e10cSrcweir 442cdf0e10cSrcweir //______________________________________________________________________________ 443cdf0e10cSrcweir OUString DocumentHandlerImpl::getImplementationName() 444cdf0e10cSrcweir throw (RuntimeException) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir return getImplementationName_DocumentHandlerImpl(); 447cdf0e10cSrcweir } 448cdf0e10cSrcweir 449cdf0e10cSrcweir //______________________________________________________________________________ 450cdf0e10cSrcweir sal_Bool DocumentHandlerImpl::supportsService( 451cdf0e10cSrcweir OUString const & servicename ) 452cdf0e10cSrcweir throw (RuntimeException) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir Sequence< OUString > names( getSupportedServiceNames_DocumentHandlerImpl() ); 455cdf0e10cSrcweir for ( sal_Int32 nPos = names.getLength(); nPos--; ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir if (names[ nPos ].equals( servicename )) 458cdf0e10cSrcweir return sal_True; 459cdf0e10cSrcweir } 460cdf0e10cSrcweir return sal_False; 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir //______________________________________________________________________________ 464cdf0e10cSrcweir Sequence< OUString > DocumentHandlerImpl::getSupportedServiceNames() 465cdf0e10cSrcweir throw (RuntimeException) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir return getSupportedServiceNames_DocumentHandlerImpl(); 468cdf0e10cSrcweir } 469cdf0e10cSrcweir 470cdf0e10cSrcweir // XInitialization 471cdf0e10cSrcweir 472cdf0e10cSrcweir //______________________________________________________________________________ 473cdf0e10cSrcweir void DocumentHandlerImpl::initialize( 474cdf0e10cSrcweir Sequence< Any > const & arguments ) 475cdf0e10cSrcweir throw (Exception) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir MGuard guard( m_pMutex ); 478cdf0e10cSrcweir Reference< xml::input::XRoot > xRoot; 479cdf0e10cSrcweir if (arguments.getLength() == 1 && 480cdf0e10cSrcweir (arguments[ 0 ] >>= xRoot) && 481cdf0e10cSrcweir xRoot.is()) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir m_xRoot = xRoot; 484cdf0e10cSrcweir } 485cdf0e10cSrcweir else 486cdf0e10cSrcweir { 487cdf0e10cSrcweir throw RuntimeException( 488cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( 489cdf0e10cSrcweir "missing root instance!") ), 490cdf0e10cSrcweir Reference< XInterface >() ); 491cdf0e10cSrcweir } 492cdf0e10cSrcweir } 493cdf0e10cSrcweir 494cdf0e10cSrcweir 495cdf0e10cSrcweir // XNamespaceMapping 496cdf0e10cSrcweir 497cdf0e10cSrcweir //______________________________________________________________________________ 498cdf0e10cSrcweir sal_Int32 DocumentHandlerImpl::getUidByUri( OUString const & Uri ) 499cdf0e10cSrcweir throw (RuntimeException) 500cdf0e10cSrcweir { 501cdf0e10cSrcweir sal_Int32 uid = getUidByURI( Uri ); 502cdf0e10cSrcweir OSL_ASSERT( uid != UID_UNKNOWN ); 503cdf0e10cSrcweir return uid; 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir //______________________________________________________________________________ 507cdf0e10cSrcweir OUString DocumentHandlerImpl::getUriByUid( sal_Int32 Uid ) 508cdf0e10cSrcweir throw (container::NoSuchElementException, RuntimeException) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir MGuard guard( m_pMutex ); 511cdf0e10cSrcweir t_OUString2LongMap::const_iterator iPos( m_URI2Uid.begin() ); 512cdf0e10cSrcweir t_OUString2LongMap::const_iterator const iEnd( m_URI2Uid.end() ); 513cdf0e10cSrcweir for ( ; iPos != iEnd; ++iPos ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir if (iPos->second == Uid) 516cdf0e10cSrcweir return iPos->first; 517cdf0e10cSrcweir } 518cdf0e10cSrcweir throw container::NoSuchElementException( 519cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("no such xmlns uid!") ), 520cdf0e10cSrcweir static_cast< OWeakObject * >(this) ); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir 524cdf0e10cSrcweir // XDocumentHandler 525cdf0e10cSrcweir 526cdf0e10cSrcweir //______________________________________________________________________________ 527cdf0e10cSrcweir void DocumentHandlerImpl::startDocument() 528cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir m_xRoot->startDocument( 531cdf0e10cSrcweir static_cast< xml::input::XNamespaceMapping * >( this ) ); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir //______________________________________________________________________________ 535cdf0e10cSrcweir void DocumentHandlerImpl::endDocument() 536cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir m_xRoot->endDocument(); 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir //______________________________________________________________________________ 542cdf0e10cSrcweir void DocumentHandlerImpl::startElement( 543cdf0e10cSrcweir OUString const & rQElementName, 544cdf0e10cSrcweir Reference< xml::sax::XAttributeList > const & xAttribs ) 545cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir Reference< xml::input::XElement > xCurrentElement; 548cdf0e10cSrcweir Reference< xml::input::XAttributes > xAttributes; 549cdf0e10cSrcweir sal_Int32 nUid; 550cdf0e10cSrcweir OUString aLocalName; 551cdf0e10cSrcweir ::std::auto_ptr< ElementEntry > elementEntry( new ElementEntry ); 552cdf0e10cSrcweir 553cdf0e10cSrcweir { // guard start: 554cdf0e10cSrcweir MGuard aGuard( m_pMutex ); 555cdf0e10cSrcweir // currently skipping elements and waiting for end tags? 556cdf0e10cSrcweir if (m_nSkipElements > 0) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir ++m_nSkipElements; // wait for another end tag 559cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 560cdf0e10cSrcweir OString aQName( 561cdf0e10cSrcweir OUStringToOString( rQElementName, RTL_TEXTENCODING_ASCII_US ) ); 562cdf0e10cSrcweir OSL_TRACE( "### no context given on createChildElement() " 563cdf0e10cSrcweir "=> ignoring element \"%s\" ...", aQName.getStr() ); 564cdf0e10cSrcweir #endif 565cdf0e10cSrcweir return; 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir sal_Int16 nAttribs = xAttribs->getLength(); 569cdf0e10cSrcweir 570cdf0e10cSrcweir // save all namespace ids 571cdf0e10cSrcweir sal_Int32 * pUids = new sal_Int32[ nAttribs ]; 572cdf0e10cSrcweir OUString * pPrefixes = new OUString[ nAttribs ]; 573cdf0e10cSrcweir OUString * pLocalNames = new OUString[ nAttribs ]; 574cdf0e10cSrcweir OUString * pQNames = new OUString[ nAttribs ]; 575cdf0e10cSrcweir 576cdf0e10cSrcweir // first recognize all xmlns attributes 577cdf0e10cSrcweir sal_Int16 nPos; 578cdf0e10cSrcweir for ( nPos = 0; nPos < nAttribs; ++nPos ) 579cdf0e10cSrcweir { 580cdf0e10cSrcweir // mark attribute to be collected further 581cdf0e10cSrcweir // on with attribute's uid and current prefix 582cdf0e10cSrcweir pUids[ nPos ] = 0; // modified 583cdf0e10cSrcweir 584cdf0e10cSrcweir pQNames[ nPos ] = xAttribs->getNameByIndex( nPos ); 585cdf0e10cSrcweir OUString const & rQAttributeName = pQNames[ nPos ]; 586cdf0e10cSrcweir 587cdf0e10cSrcweir if (rQAttributeName.compareTo( m_sXMLNS, 5 ) == 0) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir if (rQAttributeName.getLength() == 5) // set default namespace 590cdf0e10cSrcweir { 591cdf0e10cSrcweir OUString aDefNamespacePrefix; 592cdf0e10cSrcweir pushPrefix( 593cdf0e10cSrcweir aDefNamespacePrefix, 594cdf0e10cSrcweir xAttribs->getValueByIndex( nPos ) ); 595cdf0e10cSrcweir elementEntry->m_prefixes.push_back( aDefNamespacePrefix ); 596cdf0e10cSrcweir pUids[ nPos ] = UID_UNKNOWN; 597cdf0e10cSrcweir pPrefixes[ nPos ] = m_sXMLNS; 598cdf0e10cSrcweir pLocalNames[ nPos ] = aDefNamespacePrefix; 599cdf0e10cSrcweir } 600cdf0e10cSrcweir else if ((sal_Unicode)':' == rQAttributeName[ 5 ]) // set prefix 601cdf0e10cSrcweir { 602cdf0e10cSrcweir OUString aPrefix( rQAttributeName.copy( 6 ) ); 603cdf0e10cSrcweir pushPrefix( aPrefix, xAttribs->getValueByIndex( nPos ) ); 604cdf0e10cSrcweir elementEntry->m_prefixes.push_back( aPrefix ); 605cdf0e10cSrcweir pUids[ nPos ] = UID_UNKNOWN; 606cdf0e10cSrcweir pPrefixes[ nPos ] = m_sXMLNS; 607cdf0e10cSrcweir pLocalNames[ nPos ] = aPrefix; 608cdf0e10cSrcweir } 609cdf0e10cSrcweir // else just a name starting with xmlns, but no prefix 610cdf0e10cSrcweir } 611cdf0e10cSrcweir } 612cdf0e10cSrcweir 613cdf0e10cSrcweir // now read out attribute prefixes (all namespace prefixes have been set) 614cdf0e10cSrcweir for ( nPos = 0; nPos < nAttribs; ++nPos ) 615cdf0e10cSrcweir { 616cdf0e10cSrcweir if (pUids[ nPos ] >= 0) // no xmlns: attribute 617cdf0e10cSrcweir { 618cdf0e10cSrcweir OUString const & rQAttributeName = pQNames[ nPos ]; 619cdf0e10cSrcweir OSL_ENSURE( 620cdf0e10cSrcweir rQAttributeName.compareToAscii( 621cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("xmlns:") ) != 0, 622cdf0e10cSrcweir "### unexpected xmlns!" ); 623cdf0e10cSrcweir 624cdf0e10cSrcweir // collect attribute's uid and current prefix 625cdf0e10cSrcweir sal_Int32 nColonPos = rQAttributeName.indexOf( (sal_Unicode) ':' ); 626cdf0e10cSrcweir if (nColonPos >= 0) 627cdf0e10cSrcweir { 628cdf0e10cSrcweir pPrefixes[ nPos ] = rQAttributeName.copy( 0, nColonPos ); 629cdf0e10cSrcweir pLocalNames[ nPos ] = rQAttributeName.copy( nColonPos +1 ); 630cdf0e10cSrcweir } 631cdf0e10cSrcweir else 632cdf0e10cSrcweir { 633cdf0e10cSrcweir pPrefixes[ nPos ] = OUString(); 634cdf0e10cSrcweir pLocalNames[ nPos ] = rQAttributeName; 635cdf0e10cSrcweir // leave local names unmodified 636cdf0e10cSrcweir } 637cdf0e10cSrcweir pUids[ nPos ] = getUidByPrefix( pPrefixes[ nPos ] ); 638cdf0e10cSrcweir } 639cdf0e10cSrcweir } 640cdf0e10cSrcweir // ownership of arrays belongs to attribute list 641cdf0e10cSrcweir xAttributes = static_cast< xml::input::XAttributes * >( 642cdf0e10cSrcweir new ExtendedAttributes( 643cdf0e10cSrcweir nAttribs, pUids, pPrefixes, pLocalNames, pQNames, 644cdf0e10cSrcweir xAttribs, this ) ); 645cdf0e10cSrcweir 646cdf0e10cSrcweir getElementName( rQElementName, &nUid, &aLocalName ); 647cdf0e10cSrcweir 648cdf0e10cSrcweir // create new child context and append to list 649cdf0e10cSrcweir if (! m_elements.empty()) 650cdf0e10cSrcweir xCurrentElement = m_elements.back()->m_xElement; 651cdf0e10cSrcweir } // :guard end 652cdf0e10cSrcweir 653cdf0e10cSrcweir if (xCurrentElement.is()) 654cdf0e10cSrcweir { 655cdf0e10cSrcweir elementEntry->m_xElement = 656cdf0e10cSrcweir xCurrentElement->startChildElement( nUid, aLocalName, xAttributes ); 657cdf0e10cSrcweir } 658cdf0e10cSrcweir else 659cdf0e10cSrcweir { 660cdf0e10cSrcweir elementEntry->m_xElement = 661cdf0e10cSrcweir m_xRoot->startRootElement( nUid, aLocalName, xAttributes ); 662cdf0e10cSrcweir } 663cdf0e10cSrcweir 664cdf0e10cSrcweir { 665cdf0e10cSrcweir MGuard aGuard( m_pMutex ); 666cdf0e10cSrcweir if (elementEntry->m_xElement.is()) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir m_elements.push_back( elementEntry.release() ); 669cdf0e10cSrcweir } 670cdf0e10cSrcweir else 671cdf0e10cSrcweir { 672cdf0e10cSrcweir ++m_nSkipElements; 673cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 674cdf0e10cSrcweir OString aQName( 675cdf0e10cSrcweir OUStringToOString( rQElementName, RTL_TEXTENCODING_ASCII_US ) ); 676cdf0e10cSrcweir OSL_TRACE( 677cdf0e10cSrcweir "### no context given on createChildElement() => " 678cdf0e10cSrcweir "ignoring element \"%s\" ...", aQName.getStr() ); 679cdf0e10cSrcweir #endif 680cdf0e10cSrcweir } 681cdf0e10cSrcweir } 682cdf0e10cSrcweir } 683cdf0e10cSrcweir 684cdf0e10cSrcweir //______________________________________________________________________________ 685cdf0e10cSrcweir void DocumentHandlerImpl::endElement( 686cdf0e10cSrcweir OUString const & rQElementName ) 687cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException) 688cdf0e10cSrcweir { 689cdf0e10cSrcweir Reference< xml::input::XElement > xCurrentElement; 690cdf0e10cSrcweir { 691cdf0e10cSrcweir MGuard aGuard( m_pMutex ); 692cdf0e10cSrcweir if (m_nSkipElements) 693cdf0e10cSrcweir { 694cdf0e10cSrcweir --m_nSkipElements; 695cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 696cdf0e10cSrcweir OString aQName( 697cdf0e10cSrcweir OUStringToOString( rQElementName, RTL_TEXTENCODING_ASCII_US ) ); 698cdf0e10cSrcweir OSL_TRACE( "### received endElement() for \"%s\".", aQName.getStr() ); 699cdf0e10cSrcweir #endif 700cdf0e10cSrcweir static_cast<void>(rQElementName); 701cdf0e10cSrcweir return; 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir // popping context 705cdf0e10cSrcweir OSL_ASSERT( ! m_elements.empty() ); 706cdf0e10cSrcweir ElementEntry * pEntry = m_elements.back(); 707cdf0e10cSrcweir xCurrentElement = pEntry->m_xElement; 708cdf0e10cSrcweir 709cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 710cdf0e10cSrcweir sal_Int32 nUid; 711cdf0e10cSrcweir OUString aLocalName; 712cdf0e10cSrcweir getElementName( rQElementName, &nUid, &aLocalName ); 713cdf0e10cSrcweir OSL_ASSERT( xCurrentElement->getLocalName() == aLocalName ); 714cdf0e10cSrcweir OSL_ASSERT( xCurrentElement->getUid() == nUid ); 715cdf0e10cSrcweir #endif 716cdf0e10cSrcweir 717cdf0e10cSrcweir // pop prefixes 718cdf0e10cSrcweir for ( sal_Int32 nPos = pEntry->m_prefixes.size(); nPos--; ) 719cdf0e10cSrcweir { 720cdf0e10cSrcweir popPrefix( pEntry->m_prefixes[ nPos ] ); 721cdf0e10cSrcweir } 722cdf0e10cSrcweir m_elements.pop_back(); 723cdf0e10cSrcweir delete pEntry; 724cdf0e10cSrcweir } 725cdf0e10cSrcweir xCurrentElement->endElement(); 726cdf0e10cSrcweir } 727cdf0e10cSrcweir 728cdf0e10cSrcweir //______________________________________________________________________________ 729cdf0e10cSrcweir void DocumentHandlerImpl::characters( OUString const & rChars ) 730cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir Reference< xml::input::XElement > xCurrentElement( getCurrentElement() ); 733cdf0e10cSrcweir if (xCurrentElement.is()) 734cdf0e10cSrcweir xCurrentElement->characters( rChars ); 735cdf0e10cSrcweir } 736cdf0e10cSrcweir 737cdf0e10cSrcweir //______________________________________________________________________________ 738cdf0e10cSrcweir void DocumentHandlerImpl::ignorableWhitespace( 739cdf0e10cSrcweir OUString const & rWhitespaces ) 740cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir Reference< xml::input::XElement > xCurrentElement( getCurrentElement() ); 743cdf0e10cSrcweir if (xCurrentElement.is()) 744cdf0e10cSrcweir xCurrentElement->ignorableWhitespace( rWhitespaces ); 745cdf0e10cSrcweir } 746cdf0e10cSrcweir 747cdf0e10cSrcweir //______________________________________________________________________________ 748cdf0e10cSrcweir void DocumentHandlerImpl::processingInstruction( 749cdf0e10cSrcweir OUString const & rTarget, OUString const & rData ) 750cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException) 751cdf0e10cSrcweir { 752cdf0e10cSrcweir Reference< xml::input::XElement > xCurrentElement( getCurrentElement() ); 753cdf0e10cSrcweir if (xCurrentElement.is()) 754cdf0e10cSrcweir xCurrentElement->processingInstruction( rTarget, rData ); 755cdf0e10cSrcweir else 756cdf0e10cSrcweir m_xRoot->processingInstruction( rTarget, rData ); 757cdf0e10cSrcweir } 758cdf0e10cSrcweir 759cdf0e10cSrcweir //______________________________________________________________________________ 760cdf0e10cSrcweir void DocumentHandlerImpl::setDocumentLocator( 761cdf0e10cSrcweir Reference< xml::sax::XLocator > const & xLocator ) 762cdf0e10cSrcweir throw (xml::sax::SAXException, RuntimeException) 763cdf0e10cSrcweir { 764cdf0e10cSrcweir m_xRoot->setDocumentLocator( xLocator ); 765cdf0e10cSrcweir } 766cdf0e10cSrcweir 767cdf0e10cSrcweir //############################################################################## 768cdf0e10cSrcweir 769cdf0e10cSrcweir // XAttributes 770cdf0e10cSrcweir 771cdf0e10cSrcweir //______________________________________________________________________________ 772cdf0e10cSrcweir sal_Int32 ExtendedAttributes::getIndexByQName( OUString const & rQName ) 773cdf0e10cSrcweir throw (RuntimeException) 774cdf0e10cSrcweir { 775cdf0e10cSrcweir for ( sal_Int32 nPos = m_nAttributes; nPos--; ) 776cdf0e10cSrcweir { 777cdf0e10cSrcweir if (m_pQNames[ nPos ].equals( rQName )) 778cdf0e10cSrcweir { 779cdf0e10cSrcweir return nPos; 780cdf0e10cSrcweir } 781cdf0e10cSrcweir } 782cdf0e10cSrcweir return -1; 783cdf0e10cSrcweir } 784cdf0e10cSrcweir 785cdf0e10cSrcweir //______________________________________________________________________________ 786cdf0e10cSrcweir sal_Int32 ExtendedAttributes::getLength() 787cdf0e10cSrcweir throw (RuntimeException) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir return m_nAttributes; 790cdf0e10cSrcweir } 791cdf0e10cSrcweir 792cdf0e10cSrcweir //______________________________________________________________________________ 793cdf0e10cSrcweir OUString ExtendedAttributes::getLocalNameByIndex( sal_Int32 nIndex ) 794cdf0e10cSrcweir throw (RuntimeException) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir if (nIndex < m_nAttributes) 797cdf0e10cSrcweir return m_pLocalNames[ nIndex ]; 798cdf0e10cSrcweir else 799cdf0e10cSrcweir return OUString(); 800cdf0e10cSrcweir } 801cdf0e10cSrcweir 802cdf0e10cSrcweir //______________________________________________________________________________ 803cdf0e10cSrcweir OUString ExtendedAttributes::getQNameByIndex( sal_Int32 nIndex ) 804cdf0e10cSrcweir throw (RuntimeException) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir if (nIndex < m_nAttributes) 807cdf0e10cSrcweir return m_pQNames[ nIndex ]; 808cdf0e10cSrcweir else 809cdf0e10cSrcweir return OUString(); 810cdf0e10cSrcweir } 811cdf0e10cSrcweir 812cdf0e10cSrcweir //______________________________________________________________________________ 813cdf0e10cSrcweir OUString ExtendedAttributes::getTypeByIndex( sal_Int32 nIndex ) 814cdf0e10cSrcweir throw (RuntimeException) 815cdf0e10cSrcweir { 816cdf0e10cSrcweir static_cast<void>(nIndex); 817cdf0e10cSrcweir OSL_ASSERT( nIndex < m_nAttributes ); 818cdf0e10cSrcweir return OUString(); // unsupported 819cdf0e10cSrcweir } 820cdf0e10cSrcweir 821cdf0e10cSrcweir //______________________________________________________________________________ 822cdf0e10cSrcweir OUString ExtendedAttributes::getValueByIndex( sal_Int32 nIndex ) 823cdf0e10cSrcweir throw (RuntimeException) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir if (nIndex < m_nAttributes) 826cdf0e10cSrcweir return m_pValues[ nIndex ]; 827cdf0e10cSrcweir else 828cdf0e10cSrcweir return OUString(); 829cdf0e10cSrcweir } 830cdf0e10cSrcweir 831cdf0e10cSrcweir //______________________________________________________________________________ 832cdf0e10cSrcweir sal_Int32 ExtendedAttributes::getIndexByUidName( 833cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName ) 834cdf0e10cSrcweir throw (RuntimeException) 835cdf0e10cSrcweir { 836cdf0e10cSrcweir for ( sal_Int32 nPos = m_nAttributes; nPos--; ) 837cdf0e10cSrcweir { 838cdf0e10cSrcweir if (m_pUids[ nPos ] == nUid && m_pLocalNames[ nPos ] == rLocalName) 839cdf0e10cSrcweir { 840cdf0e10cSrcweir return nPos; 841cdf0e10cSrcweir } 842cdf0e10cSrcweir } 843cdf0e10cSrcweir return -1; 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir //______________________________________________________________________________ 847cdf0e10cSrcweir sal_Int32 ExtendedAttributes::getUidByIndex( sal_Int32 nIndex ) 848cdf0e10cSrcweir throw (RuntimeException) 849cdf0e10cSrcweir { 850cdf0e10cSrcweir if (nIndex < m_nAttributes) 851cdf0e10cSrcweir return m_pUids[ nIndex ]; 852cdf0e10cSrcweir else 853cdf0e10cSrcweir return -1; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir 856cdf0e10cSrcweir //______________________________________________________________________________ 857cdf0e10cSrcweir OUString ExtendedAttributes::getValueByUidName( 858cdf0e10cSrcweir sal_Int32 nUid, OUString const & rLocalName ) 859cdf0e10cSrcweir throw (RuntimeException) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir for ( sal_Int32 nPos = m_nAttributes; nPos--; ) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir if (m_pUids[ nPos ] == nUid && m_pLocalNames[ nPos ] == rLocalName) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir return m_pValues[ nPos ]; 866cdf0e10cSrcweir } 867cdf0e10cSrcweir } 868cdf0e10cSrcweir return OUString(); 869cdf0e10cSrcweir } 870cdf0e10cSrcweir 871cdf0e10cSrcweir 872cdf0e10cSrcweir //############################################################################## 873cdf0e10cSrcweir 874cdf0e10cSrcweir 875cdf0e10cSrcweir //============================================================================== 876cdf0e10cSrcweir Reference< xml::sax::XDocumentHandler > SAL_CALL createDocumentHandler( 877cdf0e10cSrcweir Reference< xml::input::XRoot > const & xRoot, 878cdf0e10cSrcweir bool bSingleThreadedUse ) 879cdf0e10cSrcweir SAL_THROW( () ) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir OSL_ASSERT( xRoot.is() ); 882cdf0e10cSrcweir if (xRoot.is()) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir return static_cast< xml::sax::XDocumentHandler * >( 885cdf0e10cSrcweir new DocumentHandlerImpl( xRoot, bSingleThreadedUse ) ); 886cdf0e10cSrcweir } 887cdf0e10cSrcweir return Reference< xml::sax::XDocumentHandler >(); 888cdf0e10cSrcweir } 889cdf0e10cSrcweir 890cdf0e10cSrcweir //------------------------------------------------------------------------------ 891cdf0e10cSrcweir Reference< XInterface > SAL_CALL create_DocumentHandlerImpl( 892cdf0e10cSrcweir Reference< XComponentContext > const & ) 893cdf0e10cSrcweir SAL_THROW( (Exception) ) 894cdf0e10cSrcweir { 895cdf0e10cSrcweir return static_cast< ::cppu::OWeakObject * >( 896cdf0e10cSrcweir new DocumentHandlerImpl( 897cdf0e10cSrcweir Reference< xml::input::XRoot >(), false /* mt use */ ) ); 898cdf0e10cSrcweir } 899cdf0e10cSrcweir 900cdf0e10cSrcweir } 901