/************************************************************************* * * $RCSfile: nmspmap.cxx,v $ * * $Revision: 1.1.1.1 $ * * last change: $Author: hr $ $Date: 2000-09-19 00:31:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses * * - GNU Lesser General Public License Version 2.1 * - Sun Industry Standards Source License Version 1.1 * * Sun Microsystems Inc., October, 2000 * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2000 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * * Sun Industry Standards Source License Version 1.1 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.1 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://www.openoffice.org/license.html. * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * * Copyright: 2000 by Sun Microsystems, Inc. * * All Rights Reserved. * * Contributor(s): _______________________________________ * * ************************************************************************/ #ifndef _TOOLS_DEBUG_HXX //autogen wg. DBG_ASSERT #include #endif #ifndef _RTL_USTRING_HXX_ #include #endif #ifndef _RTL_USTRBUF_HXX_ #include #endif #ifndef _XMLKYWD_HXX #include "xmlkywd.hxx" #endif #ifndef _XMLOFF_NMSPMAP_HXX #include #endif using namespace rtl; typedef OUString *OUStringPtr; SV_DECL_PTRARR_DEL( OUStringsDtor_Impl, OUStringPtr, 5, 5 ) SV_IMPL_PTRARR( OUStringsDtor_Impl, OUStringPtr ) SvXMLNamespaceMap::SvXMLNamespaceMap() : sXMLNS( OUString::createFromAscii(sXML_xmlns) ), pPrefixes( new OUStringsDtor_Impl ), pNames( new OUStringsDtor_Impl ) { } SvXMLNamespaceMap::SvXMLNamespaceMap( const SvXMLNamespaceMap& rMap ) : sXMLNS( OUString::createFromAscii(sXML_xmlns) ), pPrefixes( new OUStringsDtor_Impl ), pNames( new OUStringsDtor_Impl ) { USHORT nCount = rMap.aKeys.Count(); for( USHORT i=0; iInsert( new OUString( *(*rMap.pPrefixes)[i] ), i ); pNames->Insert( new OUString( *(*rMap.pNames)[i] ), i ); aKeys.Insert( rMap.aKeys[i], i ); } } SvXMLNamespaceMap::~SvXMLNamespaceMap() { delete pPrefixes; delete pNames; } int SvXMLNamespaceMap::operator ==( const SvXMLNamespaceMap& rCmp ) const { BOOL bRet = aKeys.Count() == rCmp.aKeys.Count(); if( bRet ) { USHORT nCount = aKeys.Count(); USHORT i; for( i=0; bRet && igetLength() || *(*pPrefixes)[i] == rPrefix ) { *(*pPrefixes)[i] = rPrefix; *(*pNames)[i] = rName; aKeys[i] = nKey; break; } } if( i == aKeys.Count() ) { pPrefixes->Insert( new OUString(rPrefix), i ); pNames->Insert( new OUString(rName), i ); aKeys.Insert( nKey, i ); } return i; } BOOL SvXMLNamespaceMap::AddAtIndex( USHORT nIdx, const OUString& rPrefix, const OUString& rName, USHORT nKey ) { if( XML_NAMESPACE_UNKNOWN==nKey ) nKey = GetKeyByName( rName ); DBG_ASSERT( XML_NAMESPACE_NONE != nKey, "SvXMLNamespaceMap::AddAtIndex: invalid namespace key" ); if( XML_NAMESPACE_NONE==nKey ) return FALSE; BOOL bAdded = TRUE; USHORT nCount = aKeys.Count(); if( nIdx >= nCount ) { USHORT i; for( i=nCount; iInsert( new OUString, i ); pNames->Insert( new OUString, i ); aKeys.Insert( XML_NAMESPACE_UNKNOWN, i ); } pPrefixes->Insert( new OUString(rPrefix), nIdx ); pNames->Insert( new OUString(rName), nIdx ); aKeys.Insert( nKey, i ); } else { if( 0 == (*pPrefixes)[nIdx]->getLength() ) { *(*pPrefixes)[nIdx] = rPrefix; *(*pNames)[nIdx] = rName; aKeys[nIdx] = nKey; } else { bAdded = *(*pPrefixes)[nIdx] == rPrefix && *(*pNames)[nIdx] == rName && aKeys[nIdx] == nKey; DBG_ASSERT( bAdded, "SvXMLNamespaceMap::AddByIndex: reuse of indices is not supported" ); } } return bAdded; } BOOL SvXMLNamespaceMap::AddAtIndex( USHORT nIdx, const sal_Char *pPrefix, const sal_Char *pName, USHORT nKey ) { OUString sPrefix( OUString::createFromAscii(pPrefix) ); OUString sName( OUString::createFromAscii(pName) ); return AddAtIndex( nIdx, sPrefix, sName, nKey ); } USHORT SvXMLNamespaceMap::GetIndexByKey( USHORT nKey ) const { USHORT nIdx = USHRT_MAX; if( XML_NAMESPACE_UNKNOWN != nKey ) { if( nKey < aKeys.Count() && aKeys[nKey] == nKey ) { nIdx = nKey; } else { for( USHORT i=0; iCount(); i++ ) { if( *(*pPrefixes)[i] == rPrefix ) { nIdx = i; break; } } return nIdx; } USHORT SvXMLNamespaceMap::GetKeyByName( const OUString& rName ) const { USHORT nKey = XML_NAMESPACE_UNKNOWN; for( USHORT i=0; igetLength() ) nIdx++; return nIdx == aKeys.Count() ? USHRT_MAX : nIdx; } USHORT SvXMLNamespaceMap::GetNextIndex( USHORT nOldIdx ) const { if( nOldIdx >= aKeys.Count() ) return USHRT_MAX; nOldIdx++; while( nOldIdx < aKeys.Count() && 0 == (*pPrefixes)[nOldIdx]->getLength() ) nOldIdx++; return nOldIdx == aKeys.Count() ? USHRT_MAX : nOldIdx; }