From 9757afbffc50c95d28d44bdaf300ba0b5783ba71 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 23 Dec 2005 15:55:57 +0000 Subject: [PATCH] * Implement app.getRepositories() and app.addRepository(String|Repository) --- src/helma/framework/core/ApplicationBean.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/helma/framework/core/ApplicationBean.java b/src/helma/framework/core/ApplicationBean.java index ef7ddc62..b2d863fa 100644 --- a/src/helma/framework/core/ApplicationBean.java +++ b/src/helma/framework/core/ApplicationBean.java @@ -21,6 +21,9 @@ import helma.objectmodel.db.DbSource; import helma.util.CronJob; import helma.util.SystemMap; import helma.util.WrappedMap; +import helma.framework.repository.Repository; +import helma.framework.repository.FileRepository; + import java.io.File; import java.io.Serializable; import java.util.*; @@ -115,6 +118,42 @@ public class ApplicationBean implements Serializable { } } + /** + * Returns the app's repository list. + * + * @return the an array containing this app's repositories + */ + public Object[] getRepositories() { + return app.getRepositories().toArray(); + } + + /** + * Add a repository to the app's repository list. The .zip extension + * is automatically added, if the original library path does not + * point to an existing file or directory. + * + * @param obj the repository, relative or absolute path to the library. + */ + public void addRepository(Object obj) { + Repository rep; + if (obj instanceof String) { + String path = (String) obj; + File file = new File(path).getAbsoluteFile(); + if (!file.exists()) { + file = new File(path + ".zip").getAbsoluteFile(); + } + if (!file.exists()) { + throw new RuntimeException("Repository path does not exist: " + file); + } + rep = new FileRepository(file); + } else if (obj instanceof Repository) { + rep = (Repository) obj; + } else { + throw new RuntimeException("Invalid argument to addRepository: " + obj); + } + app.addRepository(rep); + } + /** * *