Module: dylan-script-internals Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND // Example: #notes://noteslong -> ref to the server // Example: #notes://noteslong/basics/dylanevo.nsf -> ref to a database define class () slot locator-host :: , required-init-keyword: host:; slot locator-database :: false-or(), init-keyword: database:; end class; define method notes-parser (string :: ) => (locator :: ) let (host, port, path) = split-url(string); make(, host: host, // Need to remove the leading / from the path database: path & as-backslash-string(copy-sequence(path, start: 1))); end method; define method as-backslash-string (string :: ) => (string :: ) let start = #f; while ((start := subsequence-position(string, "/"))) string[start] := '\\'; end; string end method; define method as-slash-string (string :: ) => (string :: ) let start = #f; while ((start := subsequence-position(string, "\\"))) string[start] := '/'; end; string end method; define method locator-as-string (type == , locator :: ) => (string :: ) locator-as-string(, locator) end method; define method locator-as-string (type == , locator :: ) => (string :: ) let database = locator-database(locator); if (database) concatenate ("notes://", locator-host(locator), "/", as-slash-string(database)); else concatenate("notes://", locator-host(locator)); end; end method; /// One, lazily-initialized session for now define variable *notes-session* = #f; define method ensure-notes-session () => (sesion :: ) if (*notes-session*) *notes-session* else OLE-initialize(); *notes-session* := make(, class-id: $session-id, interface-id: $IID-IDispatch); end; end method; define method contents (locator :: , #rest options, #key, #all-keys) => (contents) let database = locator-database(locator); ensure-notes-session(); if (database) notes-database-contents(locator); else apply(notes-directory-contents, locator, options); end; end method; define method notes-database-contents (locator :: , #key) => (contents) let raw-db = notessession/getdatabase (*notes-session*, locator-host(locator), locator-database(locator)); let db = cast-object(, raw-db); notesdatabase/isopen(db) := #t; format-out("Open?: %=\n", notesdatabase/isopen(db)); // notesdatabase/open(db, locator-host(locator), locator-database(locator)); format-out("Title: %=\n", database-title(db)); let raw-views = notesdatabase/views(db); collecting () for (raw-view in raw-views) let view = cast-object(, raw-view); collect(notesview/name(view)); Release(view); end; notesdatabase/close(db); Release(db); end; end method; define method notes-directory-contents (locator :: , #key title-pattern) => (contents) collecting () let dir = notessession/getdbdirectory(*notes-session*, locator-host(locator)); block () let dir = cast-object(, dir); for (db = notesdbdirectory/getfirstdatabase(dir, $TEMPLATE-CANDIDATE) then notesdbdirectory/getnextdatabase(dir), until: null-pointer?(db)) let db = cast-object(, db); block () let title = as(, notesdatabase/title(db)); format-out ("DB: %s : %s : %s\n", title, as(, notesdatabase/filename(db)), as(, notesdatabase/filepath(db))); if (~title-pattern | find(title-pattern, title)) collect(make(, host: locator-host(locator), database: as(, notesdatabase/filepath(db)))); end; cleanup Release(db); end block; end for; cleanup Release(dir); end block; end collecting; end method; define method database-title (db :: ) => (title :: ) as(, notesdatabase/title(db)) end method; define method database-filepath (db :: ) => (title :: ) as(, notesdatabase/filepath(db)) end method; // eof