KLDAP Library
ldapobject.cpp
00001 /* 00002 This file is part of libkldap. 00003 Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "ldapobject.h" 00022 #include "ldif.h" 00023 00024 #include <QtCore/QSharedData> 00025 00026 using namespace KLDAP; 00027 00028 class LdapObject::Private : public QSharedData 00029 { 00030 public: 00031 Private() 00032 { 00033 } 00034 00035 Private( const Private &other ) 00036 : QSharedData( other ) 00037 { 00038 mDn = other.mDn; 00039 mAttrs = other.mAttrs; 00040 } 00041 00042 LdapDN mDn; 00043 LdapAttrMap mAttrs; 00044 }; 00045 00046 LdapObject::LdapObject() 00047 : d( new Private ) 00048 { 00049 } 00050 00051 LdapObject::LdapObject( const QString &dn ) 00052 : d( new Private ) 00053 { 00054 d->mDn = LdapDN( dn ); 00055 } 00056 00057 LdapObject::~LdapObject() 00058 { 00059 } 00060 00061 LdapObject::LdapObject( const LdapObject &that ) 00062 : d( that.d ) 00063 { 00064 } 00065 00066 LdapObject &LdapObject::operator=( const LdapObject &that ) 00067 { 00068 if ( this != &that ) { 00069 d = that.d; 00070 } 00071 00072 return *this; 00073 } 00074 00075 void LdapObject::setDn( const LdapDN &dn ) 00076 { 00077 d->mDn = dn; 00078 } 00079 00080 void LdapObject::setDn( const QString &dn ) 00081 { 00082 d->mDn = LdapDN( dn ); 00083 } 00084 00085 void LdapObject::setAttributes( const LdapAttrMap &attrs ) 00086 { 00087 d->mAttrs = attrs; 00088 } 00089 00090 LdapDN LdapObject::dn() const 00091 { 00092 return d->mDn; 00093 } 00094 00095 const LdapAttrMap &LdapObject::attributes() const 00096 { 00097 return d->mAttrs; 00098 } 00099 00100 QString LdapObject::toString() const 00101 { 00102 QString result = QString::fromLatin1( "dn: %1\n" ).arg( d->mDn.toString() ); 00103 LdapAttrMap::ConstIterator end( d->mAttrs.constEnd() ); 00104 for ( LdapAttrMap::ConstIterator it = d->mAttrs.constBegin(); it != end; ++it ) { 00105 const QString attr = it.key(); 00106 LdapAttrValue::ConstIterator end2( (*it).constEnd() ); 00107 for ( LdapAttrValue::ConstIterator it2 = (*it).constBegin(); it2 != end2; ++it2 ) { 00108 result += QString::fromUtf8( Ldif::assembleLine( attr, *it2, 76 ) ) + '\n'; 00109 } 00110 } 00111 return result; 00112 } 00113 00114 void LdapObject::clear() 00115 { 00116 d->mDn.clear(); 00117 d->mAttrs.clear(); 00118 } 00119 00120 void LdapObject::setValues( const QString &attributeName, const LdapAttrValue &values ) 00121 { 00122 d->mAttrs[ attributeName ] = values; 00123 } 00124 00125 void LdapObject::addValue( const QString &attributeName, const QByteArray &value ) 00126 { 00127 d->mAttrs[ attributeName ].append( value ); 00128 } 00129 00130 LdapAttrValue LdapObject::values( const QString &attributeName ) const 00131 { 00132 if ( hasAttribute( attributeName ) ) { 00133 return d->mAttrs.value( attributeName ); 00134 } else { 00135 return LdapAttrValue(); 00136 } 00137 } 00138 00139 QByteArray LdapObject::value( const QString &attributeName ) const 00140 { 00141 if ( hasAttribute( attributeName ) ) { 00142 return d->mAttrs.value( attributeName ).first(); 00143 } else { 00144 return QByteArray(); 00145 } 00146 } 00147 00148 bool LdapObject::hasAttribute( const QString &attributeName ) const 00149 { 00150 return d->mAttrs.contains( attributeName ); 00151 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:18 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:18 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.