Author: hannes
Date: 2008-12-18 16:28:36 +0100 (Thu, 18 Dec 2008)
New Revision: 9447
Modified:
apps/gobi/trunk/code/Global/Config.js
apps/gobi/trunk/code/Global/Startup.js
apps/gobi/trunk/extensions/search/Global/Config.js
apps/gobi/trunk/extensions/search/README.txt
apps/gobi/trunk/extensions/search/Search/Search.js
Log:
Implement onstart and onstop handlers in order to allow the search extension to start up the first time around.
Details at http://dev.helma.org/trac/helma/changeset/9447
Modified: apps/gobi/trunk/code/Global/Config.js
===================================================================
--- apps/gobi/trunk/code/Global/Config.js 2008-12-18 14:58:33 UTC (rev 9446)
+++ apps/gobi/trunk/code/Global/Config.js 2008-12-18 15:28:36 UTC (rev 9447)
@@ -1,7 +1,9 @@
// global registry for services and extensions
var gobi = {
pages: [],
- services: []
+ services: [],
+ onstart: [],
+ onstop: []
};
// root page for configuration
@@ -41,3 +43,4 @@
type: "Updates"
});
+
Modified: apps/gobi/trunk/code/Global/Startup.js
===================================================================
--- apps/gobi/trunk/code/Global/Startup.js 2008-12-18 14:58:33 UTC (rev 9446)
+++ apps/gobi/trunk/code/Global/Startup.js 2008-12-18 15:28:36 UTC (rev 9447)
@@ -20,16 +20,16 @@
/**
- * Application onStart script. this is called when the application is started.
- * It reads a file called gobi.conf in the application directory and uses
+ * Application onStart script. this is called when the application is started.
+ * It reads a file called gobi.conf in the application directory and uses
* it to build up a new site structure in case it doesn't exist already.
* It also registers a number of user-visible page prototypes in app.data.registry.
*
- * There are two kind of pages that can be created by gobi.conf: ordinary pages
- * that just sit there, and services, which are pages that serve a specific
- * purpose within the site.
- *
- * This script *should* try not to mess with sites that have been booted and
+ * There are two kind of pages that can be created by gobi.conf: ordinary pages
+ * that just sit there, and services, which are pages that serve a specific
+ * purpose within the site.
+ *
+ * This script *should* try not to mess with sites that have been booted and
* customized by their owner. I'm not sure how good we are at this.
*/
function onStart() {
@@ -55,8 +55,30 @@
if (!root.name) {
root.name = "Home";
}
+
+ // invoke gobi onstart handlers
+ for (var i = 0; i < gobi.onstart.length; i++) {
+ try {
+ gobi.onstart[i].apply();
+ } catch (x) {
+ app.logger.error("Error in onstart handler: " + x);
+ }
+ }
}
+/**
+ * onStop handler: call all registered onstop functions.
+ */
+function onStop() {
+ for (var i = 0; i < gobi.onstop.length; i++) {
+ try {
+ gobi.onstop[i].apply();
+ } catch (x) {
+ app.logger.error("Error in onstop handler: " + x);
+ }
+ }
+}
+
function registerPage(base, conf) {
app.log("Registering page " + conf.path);
if (!conf.path) {
@@ -64,11 +86,11 @@
"path=" + conf.path);
return null;
}
-
+
var page = base.getPage(conf.path, true, conf.type);
-
+
applyPageConfig(page, conf);
-
+
return page;
}
@@ -77,7 +99,7 @@
if (conf.properties) {
for (var i in conf.properties) {
page[i] = conf.properties[i];
- }
+ }
}
}
@@ -93,7 +115,7 @@
var srvLinkName = "system:service:" + conf.name;
var links = root.getLinks(srvLinkName, "out");
var page = links.length > 0 ? links[0].target : null;
-
+
if (!page) {
try {
page = registerPage(base, conf);
@@ -105,7 +127,7 @@
} else {
applyPageConfig(page, conf);
}
-
+
return page;
}
Modified: apps/gobi/trunk/extensions/search/Global/Config.js
===================================================================
--- apps/gobi/trunk/extensions/search/Global/Config.js 2008-12-18 14:58:33 UTC (rev 9446)
+++ apps/gobi/trunk/extensions/search/Global/Config.js 2008-12-18 15:28:36 UTC (rev 9447)
@@ -5,3 +5,22 @@
path: "search",
type: "Search"
});
+
+/**
+ * Called when the Search service is initialized
+ */
+gobi.onstart.push(function() {
+ if (!app.data.index) {
+ // initialize lucene search index
+ var baseDir;
+ if (app.properties["index.dir"] != null) {
+ baseDir = new helma.File(app.properties["index.dir"]);
+ } else {
+ baseDir = new helma.File(app.getServerDir(), "index");
+ }
+ app.data.index = new jala.IndexManager(app.name,
+ baseDir, app.properties["index.analyzer"]);
+ app.data.index.start();
+ }
+ return;
+});
Modified: apps/gobi/trunk/extensions/search/README.txt
===================================================================
--- apps/gobi/trunk/extensions/search/README.txt 2008-12-18 14:58:33 UTC (rev 9446)
+++ apps/gobi/trunk/extensions/search/README.txt 2008-12-18 15:28:36 UTC (rev 9447)
@@ -17,9 +17,9 @@
Place the line above at the beginning of the list of repositories and change
the number according to its position.
-NOTICE: You'll need to RESTART GOBI TWICE: the first time the service will be
-created, the second time the index will be initialized. You might watch the
-event log to see if everything went fine.
+NOTICE: You will have to rebuild the index in order to make the extension
+find already existing pages. To do this, open the /search page in your
+browser and click the "rebuild" tab.
###################
## CONFIGURATION ##
Modified: apps/gobi/trunk/extensions/search/Search/Search.js
===================================================================
--- apps/gobi/trunk/extensions/search/Search/Search.js 2008-12-18 14:58:33 UTC (rev 9446)
+++ apps/gobi/trunk/extensions/search/Search/Search.js 2008-12-18 15:28:36 UTC (rev 9447)
@@ -22,26 +22,6 @@
//
//
-
-/**
- * Called when the Search service is initialized
- */
-function onInit() {
- if (!app.data.index) {
- // initialize lucene search index
- var baseDir;
- if (app.properties["index.dir"] != null) {
- baseDir = new helma.File(app.properties["index.dir"]);
- } else {
- baseDir = new helma.File(app.getServerDir(), "index");
- }
- app.data.index = new jala.IndexManager(app.name,
- baseDir, app.properties["index.analyzer"]);
- app.data.index.start();
- }
- return;
-}
-
/** @ignore */
this._actions = new LookupList([
//actions displayed in control bar
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.