BOOL CAlbumFolder::MetaToFiles(BOOL bAggressive) { if ( m_pSchema == NULL || m_pXML == NULL ) return FALSE; for ( POSITION pos = GetFileIterator() ; pos ; ) { CLibraryFile* pFile = GetNextFile( pos ); CSchema* pSchema = pFile->m_pSchema; if ( pSchema == NULL ) continue; if ( CSchemaChild* pChild = m_pSchema->GetContained( pSchema->m_sURI ) ) { CXMLElement* pXML = pFile->m_pMetadata->Clone(); if ( pChild->MemberCopy( m_pXML, pXML, TRUE, bAggressive ) ) { CXMLElement* pRoot = pSchema->Instantiate( TRUE ); pRoot->AddElement( pXML ); pFile->SetMetadata( pRoot ); delete pRoot; } else { delete pXML; } } } return TRUE; }
HRESULT __stdcall CSchemaParser::startPrefixMapping( const wchar_t *wszPrefix, int cchPrefix, const wchar_t *wszUri, int cchUri) { CSchema * pCurr = GetSchema(); if (pCurr != NULL) { return pCurr->SetNamespaceUri(wszPrefix, cchPrefix, wszUri, cchUri); } return E_FAIL; }
ATTR_METHOD_IMPL(CSchemaParser, OnTargetNamespace) { TRACE_PARSE_ENTRY(); CSchema * pCurr = GetSchema(); if (pCurr != NULL) { return pCurr->SetTargetNamespace(wszValue, cchValue); } EmitError(IDS_SDL_INTERNAL); return E_FAIL; }
void CSchemaParser::EmitNamedElementError(const char *szElem) { int nLine = 0; int nCol = 0; GetLocator()->getLineNumber(&nLine); GetLocator()->getColumnNumber(&nCol); CSchema *pCurr = GetSchema(); if (pCurr != NULL) { EmitFileError(IDS_SDL_SCHEMALEVEL_NAME, (LPCWSTR) pCurr->GetParentDocument()->GetDocumentUri(), nLine, nCol, 0, szElem); } EmitError(IDS_SDL_INTERNAL); }
int CSchemaCache::Load() { WIN32_FIND_DATA pFind; CString strPath; HANDLE hSearch; int nCount; Clear(); strPath.Format( _T("%s\\Schemas\\*.xsd"), (LPCTSTR)Settings.General.Path ); hSearch = FindFirstFile( strPath, &pFind ); if ( hSearch == INVALID_HANDLE_VALUE ) return 0; nCount = 0; do { strPath.Format( _T("%s\\Schemas\\%s"), (LPCTSTR)Settings.General.Path, pFind.cFileName ); CSchema* pSchema = new CSchema(); if ( pSchema->Load( strPath ) ) { CString strURI( pSchema->m_sURI ); CharLower( strURI.GetBuffer() ); strURI.ReleaseBuffer(); m_pURIs.SetAt( strURI, pSchema ); CString strName( pSchema->m_sSingular ); CharLower( strName.GetBuffer() ); strName.ReleaseBuffer(); m_pNames.SetAt( strName, pSchema ); } else { delete pSchema; } } while ( FindNextFile( hSearch, &pFind ) ); FindClose( hSearch ); return nCount; }
TAG_METHOD_IMPL(CSchemaParser, OnElement) { TRACE_PARSE_ENTRY(); CSchema * pCurr = GetSchema(); if (pCurr != NULL) { CAutoPtr<CElement> spElem; spElem.Attach( new CElement ); if (spElem != NULL) { SetXSDElementInfo(spElem, pCurr, GetLocator()); spElem->SetParentSchema(pCurr); CAutoPtr<CElementParser> p( new CElementParser(GetReader(), this, GetLevel(), spElem) ); if (p != NULL) { if (g_ParserList.AddHead(p) != NULL) { if (SUCCEEDED(p.Detach()->GetAttributes(pAttributes))) { if (spElem->GetName().GetLength() != 0) { if (pCurr->AddElement(spElem) != NULL) { spElem.Detach(); return S_OK; } } EmitNamedElementError("element"); } } } } } EmitErrorHr(E_OUTOFMEMORY); return E_FAIL; }
CXSDElement * CElement::GetType() { CXSDElement *pRet = NULL; if (m_type.GetName().GetLength()) { CSchema *pSchema = GetParentSchema(); if (pSchema != NULL) { CStringW strUri; if (SUCCEEDED(/*pSchema->*/GetNamespaceUri(m_type.GetPrefix(), strUri))) { pRet = pSchema->GetNamedItem(strUri, m_type.GetName()); } } } // // TODO: appropriate errors // return pRet; }
BOOL CFileMetadataPage::OnInitDialog() { CFilePropertiesPage::OnInitDialog(); CLibraryList* pFiles = GetList(); CRect rcClient, rcCombo; CString strText; GetClientRect( &rcClient ); m_wndSchemas.GetWindowRect( &rcCombo ); ScreenToClient( &rcCombo ); rcCombo.top = rcCombo.bottom + 8; rcCombo.bottom = rcClient.bottom - 8; m_wndData.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, rcCombo, this, IDC_METADATA ); LoadString ( strText, IDS_SEARCH_NO_METADATA ); m_wndSchemas.m_sNoSchemaText = strText; BOOL bCollection = FALSE; CSchema* pSchema = NULL; { CQuickLock oLock( Library.m_pSection ); for ( POSITION pos = pFiles->GetIterator() ; pos ; ) { if ( CLibraryFile* pFile = pFiles->GetNextFile( pos ) ) { CSchema* pThisSchema = pFile->m_pSchema; if ( pThisSchema != NULL && pThisSchema->m_nType == CSchema::stFolder ) bCollection = TRUE; if ( pSchema == NULL ) { pSchema = pThisSchema; } else if ( pSchema != pThisSchema ) { pSchema = NULL; break; } } } } m_wndSchemas.Load( pSchema != NULL ? pSchema->m_sURI : _T(""), bCollection ? -1 : 0 ); OnSelChangeSchemas(); if ( pSchema != NULL ) { CXMLElement* pContainer = pSchema->Instantiate( TRUE ); CXMLElement* pXML = pContainer->AddElement( pSchema->m_sSingular ); { CQuickLock oLock( Library.m_pSection ); for ( POSITION pos1 = pFiles->GetIterator() ; pos1 ; ) { if ( CLibraryFile* pFile = pFiles->GetNextFile( pos1 ) ) { if ( pFile->m_pMetadata != NULL && pSchema->Equals( pFile->m_pSchema ) ) { for ( POSITION pos2 = pSchema->GetMemberIterator() ; pos2 ; ) { CSchemaMember* pMember = pSchema->GetNextMember( pos2 ); CString strOld = pMember->GetValueFrom( pXML, _T("(~ns~)") ); CString strNew = pMember->GetValueFrom( pFile->m_pMetadata /* , _T("(~ns~)") */ ); if ( strNew != _T("(~ns~)") && strOld != _T("(~mt~)") ) { if ( strOld == _T("(~ns~)") ) { pXML->AddAttribute( pMember->m_sName, strNew ); } else if ( strOld != strNew ) { pXML->AddAttribute( pMember->m_sName, _T("(~mt~)") ); } } } } } } } m_wndData.UpdateData( pXML, FALSE ); delete pContainer; } return TRUE; }
void CLibraryDetailView::Update() { GET_LIST(); CSchema* pSchema = SchemaCache.Get( Settings.Library.FilterURI ); DWORD nCookie = GetFolderCookie(); if ( Settings.Library.ShowVirtual ) pSchema = NULL; if ( m_nStyle == LVS_REPORT ) { CLibraryTreeItem* pTree = GetFolderSelection(); if ( pTree != NULL && pTree->m_pVirtual != NULL && pTree->m_pSelNext == NULL && pTree->m_pVirtual->m_pSchema != NULL ) { CString strURI = pTree->m_pVirtual->m_pSchema->GetContainedURI( CSchema::stFile ); if ( strURI.GetLength() && ( m_pSchema == NULL || m_pSchema->m_sURI != strURI ) ) { if ( CSchema* pSchema = SchemaCache.Get( strURI ) ) { CPtrList pColumns; CSchemaColumnsDlg::LoadColumns( pSchema, &pColumns ); SetViewSchema( pSchema, &pColumns, TRUE, FALSE ); } } } } LDVITEM* pItem = m_pList + m_nList - 1; for ( DWORD nCount = m_nList ; nCount ; nCount--, pItem-- ) { CLibraryFile* pFile = Library.LookupFile( pItem->nIndex ); if ( pFile && pFile->m_nSelectCookie == nCookie && pFile->IsAvailable() && ( ! pSchema || pSchema->Equals( pFile->m_pSchema ) || ( ! pFile->m_pMetadata && pSchema->FilterType( pFile->m_sName ) ) ) ) { pFile->m_nListCookie = nCookie; } else { SelRemove( pItem->nIndex ); CStringArray* pSaved = pItem->pText; CopyMemory( pItem, pItem + 1, sizeof(LDVITEM) * ( m_nList - nCount ) ); pItem[ m_nList - nCount ].pText = pSaved; m_nList--; } } for ( POSITION pos = LibraryMaps.GetFileIterator() ; pos ; ) { CLibraryFile* pFile = LibraryMaps.GetNextFile( pos ); if ( pFile->m_nSelectCookie == nCookie && pFile->m_nListCookie != nCookie && pFile->IsAvailable() && ( ! pSchema || pSchema->Equals( pFile->m_pSchema ) || ( ! pFile->m_pMetadata && pSchema->FilterType( pFile->m_sName ) ) ) ) { if ( m_nList == m_nBuffer ) // MUST EQUAL { m_nBuffer += 64; LDVITEM* pList = new LDVITEM[ m_nBuffer ]; if ( m_nList ) CopyMemory( pList, m_pList, m_nList * sizeof(LDVITEM) ); if ( m_pList ) delete [] m_pList; ZeroMemory( pList + m_nList, ( m_nBuffer - m_nList ) * sizeof(LDVITEM) ); m_pList = pList; } m_pList[ m_nList ].nIndex = pFile->m_nIndex; m_pList[ m_nList ].nState &= ~LDVI_SELECTED; m_nList++; pFile->m_nListCookie = nCookie; } } m_nListCookie++; SortItems(); }
int CSchemaCache::Load() { #ifdef _DEBUG __int64 nStartTotal = GetMicroCount(); #endif Clear(); CString strPath; strPath.Format( _T("%s\\Schemas\\*.xsd"), (LPCTSTR)Settings.General.Path ); WIN32_FIND_DATA pFind = {}; HANDLE hSearch = FindFirstFile( strPath, &pFind ); if ( hSearch == INVALID_HANDLE_VALUE ) return 0; int nCount = 0; do { #ifdef _DEBUG __int64 nStart = GetMicroCount(); #endif strPath.Format( _T("%s\\Schemas\\%s"), (LPCTSTR)Settings.General.Path, pFind.cFileName ); CSchema* pSchema = new CSchema(); if ( pSchema && pSchema->Load( strPath ) ) { CString strURI( pSchema->GetURI() ); strURI.MakeLower(); m_pURIs.SetAt( strURI, pSchema ); CString strName( pSchema->m_sSingular ); strName.MakeLower(); m_pNames.SetAt( strName, pSchema ); for ( POSITION pos = pSchema->GetFilterIterator(); pos; ) { CString sType; BOOL bResult; pSchema->GetNextFilter( pos, sType, bResult ); if ( bResult ) { m_pTypeFilters.SetAt( sType, pSchema ); } } ++nCount; } else { delete pSchema; pSchema = NULL; } #ifdef _DEBUG __int64 nEnd = GetMicroCount(); TRACE( _T("Schema \"%s\" load time : %I64i ms : %s\n"), strPath, ( nEnd - nStart ) / 1000, pSchema ? _T("SUCCESS") : _T("FAILED") ); #endif } while ( FindNextFile( hSearch, &pFind ) ); FindClose( hSearch ); #ifdef _DEBUG __int64 nEndTotal = GetMicroCount(); TRACE( _T("Schemas load time : %I64i ms. Found %d types.\n"), ( nEndTotal - nStartTotal ) / 1000, m_pTypeFilters.GetCount() ); #endif return nCount; }