8 #include "TomboURI.h"
\r
9 #include "Repository.h"
\r
10 #include "Property.h"
\r
12 #include "AutoPtr.h"
\r
14 #include "RepositoryImpl.h"
\r
16 // At this time, Repository is only proxy to RepositoryImpl.
\r
17 // This class will choose repository implementations in future.
\r
19 /////////////////////////////////////////
\r
20 // Global definition
\r
21 /////////////////////////////////////////
\r
23 Repository g_Repository;
\r
25 /////////////////////////////////////////
\r
26 // Repository ctor & dtor, initializer
\r
27 /////////////////////////////////////////
\r
29 Repository::Repository() : pDefaultImpl(NULL)
\r
33 Repository::~Repository()
\r
37 BOOL Repository::Init()
\r
39 if (!vSubRepository.Init(10, 10)) return FALSE;
\r
40 return ClearSubRepository();
\r
43 BOOL Repository::ClearSubRepository()
\r
45 for (DWORD i = 0; i < vSubRepository.NumItems(); i++) {
\r
46 RepositoryImpl *p = *vSubRepository.GetUnit(i);
\r
49 vSubRepository.Clear(FALSE);
\r
51 pDefaultImpl = NULL;
\r
55 BOOL Repository::AddSubRepository(RepositoryImpl *pImpl)
\r
57 if (!vSubRepository.Add(&pImpl)) return FALSE;
\r
59 pDefaultImpl = *vSubRepository.GetUnit(0);
\r
63 BOOL Repository::GetAttachURI(const TomboURI *pBase, TomboURI *pAttached)
\r
65 if (pBase->IsLeaf()) {
\r
66 if (!pBase->GetParent(pAttached)) return FALSE;
\r
68 if (!pAttached->Init(pBase->GetFullURI())) return FALSE;
\r
73 RepositoryImpl *Repository::GetAssocSubRepository(const TomboURI *pURI)
\r
75 DWORD n = vSubRepository.NumItems();
\r
76 for (DWORD i = 0; i < n; i++) {
\r
77 RepositoryImpl *pImpl = *vSubRepository.GetUnit(i);
\r
78 if (_tcsncmp(pImpl->GetRootURI()->GetFullURI() + 8, pURI->GetFullURI() + 8, pImpl->GetRepNameLen() + 1) == 0) {
\r
85 /////////////////////////////////////////
\r
86 // delegated methods
\r
87 /////////////////////////////////////////
\r
89 BOOL Repository::Update(const TomboURI *pCurrentURI,
\r
91 TomboURI *pNewURI, TString *pNewHeadLine)
\r
93 // pNewURI is in same sub repository
\r
94 RepositoryImpl *pImpl = GetAssocSubRepository(pCurrentURI);
\r
95 if (pImpl == NULL) return FALSE;
\r
96 return pImpl->Update(pCurrentURI, pData, pNewURI, pNewHeadLine);
\r
99 BOOL Repository::GetHeadLine(const TomboURI *pURI, TString *pHeadLine)
\r
101 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
102 if (pImpl == NULL) return FALSE;
\r
103 return pImpl->GetHeadLine(pURI, pHeadLine);
\r
106 BOOL Repository::GetOption(const TomboURI *pURI, URIOption *pOption)
\r
108 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
109 if (pImpl == NULL) return FALSE;
\r
110 return pImpl->GetOption(pURI, pOption);
\r
113 BOOL Repository::SetOption(const TomboURI *pCurrentURI, URIOption *pOption)
\r
115 RepositoryImpl *pImpl = GetAssocSubRepository(pCurrentURI);
\r
116 if (pImpl == NULL) return FALSE;
\r
117 return pImpl->SetOption(pCurrentURI, pOption);
\r
120 BOOL Repository::IsEncrypted(const TomboURI *pURI)
\r
122 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
123 if (pImpl == NULL) return FALSE;
\r
124 return pImpl->IsEncrypted(pURI);
\r
127 BOOL Repository::Delete(const TomboURI *pURI, URIOption *pOption)
\r
129 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
130 if (pImpl == NULL) return FALSE;
\r
131 return pImpl->Delete(pURI, pOption);
\r
134 BOOL Repository::Copy(const TomboURI *pCopyFrom, const TomboURI *pCopyTo, URIOption *pOption)
\r
136 // XXXX over subrepository is not supported yet.
\r
137 RepositoryImpl *pImpl = GetAssocSubRepository(pCopyFrom);
\r
138 if (pImpl == NULL) return FALSE;
\r
139 return pImpl->Copy(pCopyFrom, pCopyTo, pOption);
\r
142 BOOL Repository::Move(const TomboURI *pMoveFrom, const TomboURI *pMoveTo, URIOption *pOption)
\r
144 // XXXX over subrepository is not supported yet.
\r
145 RepositoryImpl *pImpl = GetAssocSubRepository(pMoveFrom);
\r
146 if (pImpl == NULL) return FALSE;
\r
147 return pImpl->Move(pMoveFrom, pMoveTo, pOption);
\r
150 BOOL Repository::GetPhysicalPath(const TomboURI *pURI, TString *pFullPath)
\r
152 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
153 if (pImpl == NULL) return FALSE;
\r
154 return pImpl->GetPhysicalPath(pURI, pFullPath);
\r
157 BOOL Repository::ChangeHeadLine(const TomboURI *pURI, LPCTSTR pReqNewHeadLine, URIOption *pOption)
\r
159 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
160 if (pImpl == NULL) return FALSE;
\r
161 return pImpl->ChangeHeadLine(pURI, pReqNewHeadLine, pOption);
\r
165 URIList *Repository::GetChild(const TomboURI *pFolder, BOOL bSkipEncrypt, BOOL bLooseDecrypt, BOOL *pLoose)
\r
167 RepositoryImpl *pImpl = GetAssocSubRepository(pFolder);
\r
168 if (pImpl == NULL) return FALSE;
\r
169 return pImpl->GetChild(pFolder, bSkipEncrypt, bLooseDecrypt, pLoose);
\r
172 BOOL Repository::RequestAllocateURI(const TomboURI *pBaseURI, LPCTSTR pText, TString *pHeadLine, TomboURI *pURI, const TomboURI *pTemplateURI)
\r
174 RepositoryImpl *pImpl = GetAssocSubRepository(pBaseURI);
\r
175 if (pImpl == NULL) return FALSE;
\r
176 return pImpl->RequestAllocateURI(pBaseURI, pText, pHeadLine, pURI, pTemplateURI);
\r
179 BOOL Repository::GetAttribute(const TomboURI *pURI, NoteAttribute *pAttribute)
\r
181 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
182 if (pImpl == NULL) return FALSE;
\r
183 return pImpl->GetAttribute(pURI, pAttribute);
\r
186 BOOL Repository::GetNoteAttribute(const TomboURI *pURI, UINT64 *pLastUpdate, UINT64 *pCreateDate, UINT64 *pFileSize)
\r
188 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
189 if (pImpl == NULL) return FALSE;
\r
190 return pImpl->GetNoteAttribute(pURI, pLastUpdate, pCreateDate, pFileSize);
\r
193 BOOL Repository::SetAttribute(const TomboURI *pURI, const NoteAttribute *pAttribute)
\r
195 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
196 if (pImpl == NULL) return FALSE;
\r
197 return pImpl->SetAttribute(pURI, pAttribute);
\r
200 LPTSTR Repository::GetNoteData(const TomboURI *pURI)
\r
202 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
203 if (pImpl == NULL) return FALSE;
\r
204 return pImpl->GetNoteData(pURI);
\r
207 LPBYTE Repository::GetNoteDataNative(const TomboURI *pURI, LPDWORD pSize)
\r
209 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
210 if (pImpl == NULL) return FALSE;
\r
211 return pImpl->GetNoteDataNative(pURI, pSize);
\r
214 BOOL Repository::ExecuteAssoc(const TomboURI *pURI, ExeAppType nType)
\r
216 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
217 if (pImpl == NULL) return FALSE;
\r
218 return pImpl->ExecuteAssoc(pURI, nType);
\r
221 BOOL Repository::MakeFolder(const TomboURI *pParent, LPCTSTR pFolderName)
\r
223 RepositoryImpl *pImpl = GetAssocSubRepository(pParent);
\r
224 if (pImpl == NULL) return FALSE;
\r
225 return pImpl->MakeFolder(pParent, pFolderName);
\r
228 BOOL Repository::GetFileName(const TomboURI *pURI, TString *pName)
\r
230 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
\r
231 if (pImpl == NULL) return FALSE;
\r
232 return pURI->GetBaseName(pName);
\r
235 /////////////////////////////////////////
\r
236 // sub repository IF
\r
237 /////////////////////////////////////////
\r
239 DWORD Repository::GetNumOfSubRepository()
\r
241 return vSubRepository.NumItems();
\r
244 DWORD Repository::GetSubRepositoryType(DWORD nIndex)
\r
246 RepositoryImpl *pImpl = *vSubRepository.GetUnit(nIndex);
\r
247 if (pImpl == NULL) return NULL;
\r
249 return pImpl->GetRepositoryType();
\r
252 LPCTSTR Repository::GetSubRepositoryName(DWORD nIndex)
\r
254 RepositoryImpl *pImpl = *vSubRepository.GetUnit(nIndex);
\r
255 if (pImpl == NULL) return NULL;
\r
257 return pImpl->GetDisplayName();
\r
260 const TomboURI *Repository::GetSubRepositoryRootURI(DWORD nIndex)
\r
262 RepositoryImpl *pImpl = *vSubRepository.GetUnit(nIndex);
\r
263 if (pImpl == NULL) return NULL;
\r
264 return pImpl->GetRootURI();
\r
267 LPTSTR Repository::GetSubRepoXMLSaveString(DWORD nIndex)
\r
269 RepositoryImpl *pImpl = *vSubRepository.GetUnit(nIndex);
\r
270 if (pImpl == NULL) return NULL;
\r
271 return pImpl->GetXMLSaveString();
\r
274 // factory methods for RepositoryImpl
\r
275 RepositoryImpl *Repository::CreateSubRepo(LPCWSTR pName, const WCHAR **atts)
\r
277 if (wcscmp(pName, L"localfile") == 0) {
\r
279 LPTSTR pDispName = NULL;
\r
280 LPTSTR pRepName = NULL;
\r
281 LPTSTR pTopDir = NULL;
\r
282 BOOL bKeepTitle = FALSE;
\r
283 BOOL bKeepCaret = FALSE;
\r
284 BOOL bSafeFileName = FALSE;
\r
286 while (atts[i] != L'\0') {
\r
287 if (wcscmp(atts[i], L"name") == 0) {
\r
288 pRepName = ConvWCharToTChar(atts[i + 1]);
\r
289 } else if (wcscmp(atts[i], L"dispname") == 0) {
\r
290 pDispName = ConvWCharToTChar(atts[i + 1]);
\r
291 } else if (wcscmp(atts[i], L"path") == 0) {
\r
292 pTopDir = ConvWCharToTChar(atts[i + 1]);
\r
293 } else if (wcscmp(atts[i], L"keeptitle") == 0) {
\r
294 bKeepTitle = (wcscmp(atts[i + 1], L"1") == 0);
\r
295 } else if (wcscmp(atts[i], L"keepcaret") == 0) {
\r
296 bKeepCaret = (wcscmp(atts[i + 1], L"1") == 0);
\r
297 } else if (wcscmp(atts[i], L"safefilename") == 0) {
\r
298 bSafeFileName = (wcscmp(atts[i + 1], L"1") == 0);
\r
302 ArrayAutoPointer<TCHAR> ap1(pDispName), ap2(pRepName), ap3(pTopDir);
\r
304 if (pRepName == NULL || pDispName == NULL || pTopDir == NULL) {
\r
305 SetLastError(ERROR_INVALID_PARAMETER);
\r
309 LocalFileRepository *pImpl = new LocalFileRepository();
\r
310 if (pImpl == NULL) {
\r
311 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
\r
314 if (!pImpl->Init(pRepName, pDispName, pTopDir, bKeepTitle, bKeepCaret, bSafeFileName)) {
\r
319 } else if (wcscmp(pName, L"vfolder") == 0) {
\r
320 LPTSTR pDispName = NULL;
\r
321 LPTSTR pRepName = NULL;
\r
323 while (atts[i] != L'\0') {
\r
324 if (wcscmp(atts[i], L"name") == 0) {
\r
325 pRepName = ConvWCharToTChar(atts[i + 1]);
\r
326 } else if (wcscmp(atts[i], L"dispname") == 0) {
\r
327 pDispName = ConvWCharToTChar(atts[i + 1]);
\r
331 ArrayAutoPointer<TCHAR> ap1(pDispName), ap2(pRepName);
\r
333 VFolderRepository *pImpl = new VFolderRepository();
\r
334 if (pImpl == NULL) {
\r
335 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
\r
338 if (!pImpl->Init(pRepName, pDispName)) {
\r