Пример #1
0
func (f *fileManagerLib) Access(name string) (lib tr.ToplevelTreeElementIf, err error) {
	var ok bool
	lib, ok = f.libraryMap[name]
	if ok {
		return
	}
	lib = behaviour.LibraryNew(name, f.context)
	var filedir string
	for _, filedir := range backend.XmlSearchPaths() {
		err = lib.ReadFile(fmt.Sprintf("%s/%s", filedir, name))
		if err == nil {
			break
		}
	}
	if err != nil {
		err = fmt.Errorf("fileManagerLib.Access: library file %s not found", name)
		return
	}
	lib.SetPathPrefix(filedir)
	f.libraryMap[name] = lib.(bh.LibraryIf)
	var newId string
	newId, err = f.context.FTS().AddToplevel(lib.(bh.LibraryIf))
	if err != nil {
		err = fmt.Errorf("fileManagerLib.Access: %s", err)
		return
	}
	f.context.FTV().SelectId(newId)
	if err != nil {
		err = fmt.Errorf("fileManagerLib.Access: %s", err)
		return
	}
	log.Printf("fileManagerLib.Access: library %s successfully loaded\n", name)
	return
}
Пример #2
0
func (f *fileManagerLib) New() (lib tr.ToplevelTreeElementIf, err error) {
	filename := f.NewFilename()
	lib = behaviour.LibraryNew(filename, f.context)
	f.libraryMap[filename] = lib.(bh.LibraryIf)
	var newId string
	newId, err = f.context.FTS().AddToplevel(lib.(bh.LibraryIf))
	if err != nil {
		err = fmt.Errorf("fileManagerLib.New: %s.\n", err)
		return
	}
	f.context.FTV().SelectId(newId)
	return
}