| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <sal/config.h> |
| 21 |
|
| 22 |
#include <comphelper/attributelist.hxx> |
| 23 |
#include "MutableAttrList.hxx" |
| 24 |
|
| 25 |
|
| 26 |
using namespace ::com::sun::star::uno; |
| 27 |
using namespace ::com::sun::star::lang; |
| 28 |
using namespace ::com::sun::star::util; |
| 29 |
|
| 30 |
comphelper::AttributeList* XMLMutableAttributeList::GetMutableAttrList() |
| 31 |
{ |
| 32 |
if( !m_pMutableAttrList ) |
| 33 |
{ |
| 34 |
m_pMutableAttrList = new comphelper::AttributeList( m_xAttrList ); |
| 35 |
m_xAttrList = m_pMutableAttrList; |
| 36 |
} |
| 37 |
|
| 38 |
return m_pMutableAttrList.get(); |
| 39 |
} |
| 40 |
|
| 41 |
XMLMutableAttributeList::XMLMutableAttributeList() : |
| 42 |
m_pMutableAttrList( new comphelper::AttributeList ) |
| 43 |
{ |
| 44 |
m_xAttrList = m_pMutableAttrList; |
| 45 |
} |
| 46 |
|
| 47 |
XMLMutableAttributeList::XMLMutableAttributeList( const Reference< |
| 48 |
XAttributeList> & rAttrList, bool bClone ) : |
| 49 |
m_xAttrList( rAttrList.is() ? rAttrList : new comphelper::AttributeList ) |
| 50 |
{ |
| 51 |
if( bClone ) |
| 52 |
GetMutableAttrList(); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
XMLMutableAttributeList::~XMLMutableAttributeList() |
| 57 |
{ |
| 58 |
m_xAttrList = nullptr; |
| 59 |
} |
| 60 |
|
| 61 |
sal_Int16 SAL_CALL XMLMutableAttributeList::getLength() |
| 62 |
{ |
| 63 |
return m_xAttrList->getLength(); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i) |
| 68 |
{ |
| 69 |
return m_xAttrList->getNameByIndex( i ); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i) |
| 74 |
{ |
| 75 |
return m_xAttrList->getTypeByIndex( i ); |
| 76 |
} |
| 77 |
|
| 78 |
OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i) |
| 79 |
{ |
| 80 |
return m_xAttrList->getValueByIndex( i ); |
| 81 |
} |
| 82 |
|
| 83 |
OUString SAL_CALL XMLMutableAttributeList::getTypeByName( |
| 84 |
const OUString& rName ) |
| 85 |
{ |
| 86 |
return m_xAttrList->getTypeByName( rName ); |
| 87 |
} |
| 88 |
|
| 89 |
OUString SAL_CALL XMLMutableAttributeList::getValueByName( |
| 90 |
const OUString& rName) |
| 91 |
{ |
| 92 |
return m_xAttrList->getValueByName( rName ); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
Reference< XCloneable > XMLMutableAttributeList::createClone() |
| 97 |
{ |
| 98 |
// A cloned list will be a read only list! |
| 99 |
Reference< XCloneable > r = new comphelper::AttributeList( m_xAttrList ); |
| 100 |
return r; |
| 101 |
} |
| 102 |
|
| 103 |
void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i, |
| 104 |
const OUString& rValue ) |
| 105 |
{ |
| 106 |
GetMutableAttrList()->SetValueByIndex( i, rValue ); |
| 107 |
} |
| 108 |
|
| 109 |
void XMLMutableAttributeList::AddAttribute( const OUString &rName , |
| 110 |
const OUString &rValue ) |
| 111 |
{ |
| 112 |
GetMutableAttrList()->AddAttribute( rName, rValue ); |
| 113 |
} |
| 114 |
|
| 115 |
void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i ) |
| 116 |
{ |
| 117 |
GetMutableAttrList()->RemoveAttributeByIndex( i ); |
| 118 |
} |
| 119 |
|
| 120 |
void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i, |
| 121 |
const OUString& rNewName ) |
| 122 |
{ |
| 123 |
GetMutableAttrList()->RenameAttributeByIndex( i, rNewName ); |
| 124 |
} |
| 125 |
|
| 126 |
void XMLMutableAttributeList::AppendAttributeList( |
| 127 |
const Reference< css::xml::sax::XAttributeList >& r ) |
| 128 |
{ |
| 129 |
GetMutableAttrList()->AppendAttributeList( r ); |
| 130 |
} |
| 131 |
|
| 132 |
sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const |
| 133 |
{ |
| 134 |
sal_Int16 nIndex = -1; |
| 135 |
if( m_pMutableAttrList ) |
| 136 |
{ |
| 137 |
nIndex = m_pMutableAttrList->GetIndexByName( rName ); |
| 138 |
} |
| 139 |
else |
| 140 |
{ |
| 141 |
sal_Int16 nCount = m_xAttrList->getLength(); |
| 142 |
for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i ) |
| 143 |
{ |
| 144 |
if( m_xAttrList->getNameByIndex(i) == rName ) |
| 145 |
nIndex = i; |
| 146 |
} |
| 147 |
} |
| 148 |
return nIndex; |
| 149 |
} |
| 150 |
|
| 151 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |