Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

SchemaChild.cpp

Go to the documentation of this file.
00001 //
00002 // SchemaChild.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Schema.h"
00026 #include "SchemaChild.h"
00027 #include "XML.h"
00028 
00029 #ifdef _DEBUG
00030 #undef THIS_FILE
00031 static char THIS_FILE[]=__FILE__;
00032 #define new DEBUG_NEW
00033 #endif
00034 
00035 
00037 // CSchemaChild construction
00038 
00039 CSchemaChild::CSchemaChild(CSchema* pSchema)
00040 {
00041         m_pSchema       = pSchema;
00042         m_nType         = CSchema::stFile;
00043 }
00044 
00045 CSchemaChild::~CSchemaChild()
00046 {
00047         Clear();
00048 }
00049 
00051 // CSchemaChild load
00052 
00053 BOOL CSchemaChild::Load(CXMLElement* pXML)
00054 {
00055         m_sURI = pXML->GetAttributeValue( _T("location") );
00056         if ( m_sURI.IsEmpty() ) return FALSE;
00057 
00058         CString strType = pXML->GetAttributeValue( _T("type") );
00059 
00060         if ( strType == _T("folder") )
00061                 m_nType = CSchema::stFolder;
00062         else if ( strType == _T("file") )
00063                 m_nType = CSchema::stFile;
00064         else
00065                 return FALSE;
00066 
00067         for ( POSITION pos = pXML->GetElementIterator() ; pos ; )
00068         {
00069                 CXMLElement* pElement = pXML->GetNextElement( pos );
00070 
00071                 if (    pElement->IsNamed( _T("identity") ) ||
00072                                 pElement->IsNamed( _T("shared") ) )
00073                 {
00074                         CSchemaChildMap* pMap = new CSchemaChildMap();
00075 
00076                         if ( pMap->Load( pElement ) )
00077                         {
00078                                 m_pMap.AddTail( pMap );
00079                         }
00080                         else
00081                         {
00082                                 delete pMap;
00083                                 return FALSE;
00084                         }
00085                 }
00086         }
00087 
00088         return TRUE;
00089 }
00090 
00092 // CSchemaChild clear
00093 
00094 void CSchemaChild::Clear()
00095 {
00096         for ( POSITION pos = m_pMap.GetHeadPosition() ; pos ; )
00097         {
00098                 delete (CSchemaChildMap*)m_pMap.GetNext( pos );
00099         }
00100         m_pMap.RemoveAll();
00101 }
00102 
00104 // CSchemaChild member copy
00105 
00106 BOOL CSchemaChild::MemberCopy(CXMLElement* pLocal, CXMLElement* pRemote, BOOL bToRemote, BOOL bAggressive)
00107 {
00108         if ( ! pLocal || ! pRemote ) return FALSE;
00109 
00110         BOOL bChanged = FALSE;
00111 
00112         for ( POSITION pos = m_pMap.GetHeadPosition() ; pos ; )
00113         {
00114                 CSchemaChildMap* pMap           = (CSchemaChildMap*)m_pMap.GetNext( pos );
00115                 CXMLAttribute* pAttribute1      = NULL;
00116                 CXMLAttribute* pAttribute2      = NULL;
00117 
00118                 if ( bToRemote )
00119                 {
00120                         pAttribute1 = pLocal->GetAttribute( pMap->m_sLocal );
00121                         pAttribute2 = pRemote->GetAttribute( pMap->m_sRemote );
00122                 }
00123                 else
00124                 {
00125                         pAttribute1 = pRemote->GetAttribute( pMap->m_sRemote );
00126                         pAttribute2 = pLocal->GetAttribute( pMap->m_sLocal );
00127                 }
00128 
00129                 if ( pAttribute1 && ( ! pAttribute2 || bAggressive ) )
00130                 {
00131                         CString strValue( pAttribute1->GetValue() );
00132 
00133                         if ( pMap->m_bIdentity ) CXMLNode::UniformString( strValue );
00134 
00135                         if ( bToRemote )
00136                                 pRemote->AddAttribute( pMap->m_sRemote, strValue );
00137                         else
00138                                 pLocal->AddAttribute( pMap->m_sLocal, strValue );
00139 
00140                         bChanged = TRUE;
00141                 }
00142         }
00143 
00144         return bChanged;
00145 }
00146 
00148 // CSchemaChildMap construction
00149 
00150 CSchemaChildMap::CSchemaChildMap()
00151 {
00152 }
00153 
00154 CSchemaChildMap::~CSchemaChildMap()
00155 {
00156 }
00157 
00159 // CSchemaChildMap operation
00160 
00161 BOOL CSchemaChildMap::Load(CXMLElement* pXML)
00162 {
00163         if ( pXML->IsNamed( _T("identity") ) )
00164                 m_bIdentity = TRUE;
00165         else if ( pXML->IsNamed( _T("shared") ) )
00166                 m_bIdentity = FALSE;
00167         else
00168                 return FALSE;
00169 
00170         m_sLocal        = pXML->GetAttributeValue( _T("local") );
00171         m_sRemote       = pXML->GetAttributeValue( _T("remote") );
00172 
00173         if ( m_sLocal.IsEmpty() || m_sRemote.IsEmpty() ) return FALSE;
00174 
00175         return TRUE;
00176 }

Generated on Thu Dec 15 10:39:48 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2