Permalink
Browse files

Webclient: plugin namespace convention (#275).

IMPORTANT for plugin developers:
For proper namespacing there is the convention to use the plugin's URI when registering via dm4c.add_plugin():

    dm4c.add_plugin("de.deepamehta.topicmaps", function() {
        ...
    })

Technically this string is arbitrary. It's just the identifier by which you can access the plugin later on, usually to call its public API methods:

    dm4c.get_plugin("de.deepamehta.topicmaps").get_topicmap()

However, the string must be globally unique, so it is most natural to use the plugin's URI. Actually the plugin URI is the plugin bundle's symbolic name, which is calculated from the plugin project's group ID and artifact ID.

See ticket 275.

Furthermore in Webclient: exceptions that occur while loading and executing a script via dm4c.load_script() are rethrown to let them appear in the browser's error console.
  • Loading branch information...
1 parent b30004d commit 082a4651368309fb0bb3aca30ef8067f5bc7d87e @jri committed Jun 28, 2012
@@ -1,4 +1,4 @@
-dm4c.add_plugin("accesscontrol_plugin", function() {
+dm4c.add_plugin("de.deepamehta.accesscontrol", function() {
var DEFAULT_USER = "admin"
var DEFAULT_PASSWORD = ""
@@ -1,4 +1,4 @@
-dm4c.add_plugin("facets_plugin", function() {
+dm4c.add_plugin("de.deepamehta.facets", function() {
// ------------------------------------------------------------------------------------------------------ Public API
@@ -1,4 +1,4 @@
-dm4c.add_plugin("filemanager_plugin", function() {
+dm4c.add_plugin("de.deepamehta.filemanager", function() {
// === Webclient Listeners ===
@@ -7,7 +7,7 @@ dm4c.add_plugin("filemanager_plugin", function() {
type_menu.add_item({
label: "New File Browser",
handler: function() {
- dm4c.get_plugin("files_plugin").create_folder_topic({path: "/"}, true, true)
+ dm4c.get_plugin("de.deepamehta.files").create_folder_topic({path: "/"}, true, true)
}
})
})
@@ -19,10 +19,10 @@ dm4c.add_plugin("filemanager_plugin", function() {
//
var dir_count = files.get_directory_count()
for (var i = 0; i < dir_count; i++) {
- dm4c.get_plugin("files_plugin").create_file_topics(files.get_directory(i), i == 0)
+ dm4c.get_plugin("de.deepamehta.files").create_file_topics(files.get_directory(i), i == 0)
}
for (var i = 0; i < files.get_file_count(); i++) {
- dm4c.get_plugin("files_plugin").create_file_topic(files.get_file(i), !dir_count && i == 0)
+ dm4c.get_plugin("de.deepamehta.files").create_file_topic(files.get_file(i), !dir_count && i == 0)
}
//
dm4c.canvas.stop_grid_positioning()
@@ -1,4 +1,4 @@
-dm4c.add_plugin("files_plugin", function() {
+dm4c.add_plugin("de.deepamehta.files", function() {
dm4c.load_field_renderer("/de.deepamehta.files/script/field_renderers/file_content_renderer.js")
dm4c.load_field_renderer("/de.deepamehta.files/script/field_renderers/folder_content_renderer.js")
@@ -1,4 +1,4 @@
-dm4c.add_plugin("help_plugin", function() {
+dm4c.add_plugin("de.deepamehta.help", function() {
dm4c.load_stylesheet("/de.deepamehta.help/style/help.css")
@@ -1,4 +1,4 @@
-dm4c.add_plugin("iconpicker_plugin", function() {
+dm4c.add_plugin("de.deepamehta.iconpicker", function() {
dm4c.load_field_renderer("/de.deepamehta.iconpicker/script/field_renderers/icon_field_renderer.js")
dm4c.load_stylesheet("/de.deepamehta.iconpicker/style/iconpicker.css")
@@ -1,4 +1,4 @@
-dm4c.add_plugin("proxy_plugin", function() {
+dm4c.add_plugin("de.deepamehta.proxy", function() {
// === REST Client Extension ===
@@ -1,4 +1,4 @@
-dm4c.add_plugin("topicmaps_plugin", function() {
+dm4c.add_plugin("de.deepamehta.topicmaps", function() {
var LOG_TOPICMAPS = false
var self = this
@@ -1,4 +1,4 @@
-dm4c.add_plugin("typeeditor_plugin", function() {
+dm4c.add_plugin("de.deepamehta.typeeditor", function() {
dm4c.load_page_renderer("/de.deepamehta.typeeditor/script/page_renderers/topictype_renderer.js")
dm4c.load_stylesheet("/de.deepamehta.typeeditor/style/typeeditor.css")
@@ -1,7 +1,7 @@
/**
* Provides the "By Type" search mode.
*/
-dm4c.add_plugin("typesearch_plugin", function() {
+dm4c.add_plugin("de.deepamehta.typesearch", function() {
var type_menu
@@ -1,4 +1,4 @@
-dm4c.add_plugin("webbrowser_plugin", function() {
+dm4c.add_plugin("de.deepamehta.webbrowser", function() {
dm4c.load_page_renderer("/de.deepamehta.webbrowser/script/page_renderers/webpage_renderer.js")
@@ -1,4 +1,4 @@
-dm4c.add_plugin("ckeditor_plugin", function() {
+dm4c.add_plugin("de.deepamehta.webclient.ckeditor", function() {
// === Webclient Listeners ===
@@ -1,7 +1,7 @@
/**
* Provides the standard commands ("Create", "Edit", "Delete", "Hide", "Associate").
*/
-dm4c.add_plugin("default_plugin", function() {
+dm4c.add_plugin("de.deepamehta.webclient.default", function() {
var type_menu
@@ -1,7 +1,7 @@
/**
* Provides the "By Text" search mode.
*/
-dm4c.add_plugin("fulltext_plugin", function() {
+dm4c.add_plugin("de.deepamehta.webclient.fulltext", function() {
var SEARCH_FIELD_WIDTH = 20 // in chars
var search_field
@@ -71,18 +71,27 @@ function PluginManager(config) {
}
this.add_plugin = function(plugin_uri, plugin_func) {
- // instantiate
+ // 1) instantiate
if (dm4c.LOG_PLUGIN_LOADING) dm4c.log(".......... instantiating \"" + plugin_uri + "\"")
- var plugin = {}
- plugin_func.call(plugin)
- plugins[plugin_uri] = plugin
- // all plugins complete?
+ // error check
+ if (plugins[plugin_uri]) {
+ throw "PluginManagerError: plugin URI clash with \"" + plugin_uri + "\""
+ }
+ //
+ plugins[plugin_uri] = create_plugin()
+ // 2) all plugins complete?
plugins_complete++
if (plugins_complete == plugin_sources.length) {
if (dm4c.LOG_PLUGIN_LOADING) dm4c.log("PLUGINS COMPLETE!")
all_plugins_loaded()
}
+ function create_plugin() {
+ var plugin = {}
+ plugin_func.call(plugin)
+ return plugin
+ }
+
function all_plugins_loaded() {
load_page_renderers()
load_field_renderers()
@@ -93,7 +102,13 @@ function PluginManager(config) {
}
this.get_plugin = function(plugin_uri) {
- return plugins[plugin_uri]
+ var plugin = plugins[plugin_uri]
+ // error check
+ if (!plugin) {
+ throw "PluginManagerError: plugin \"" + plugin_uri + "\" not found"
+ }
+ //
+ return plugin
}
this.get_page_renderer = function(topic_or_association_or_classname) {
@@ -658,8 +658,11 @@ function Webclient() {
$.ajax({
url: script_url,
dataType: "script",
+ async: callback != undefined,
success: callback,
- async: callback != undefined
+ error: function(jq_xhr, text_status, error_thrown) {
+ throw text_status + ": " + error_thrown
+ }
})
}
@@ -1,4 +1,4 @@
-dm4c.add_plugin("workspaces_plugin", function() {
+dm4c.add_plugin("de.deepamehta.workspaces", function() {
dm4c.load_stylesheet("/de.deepamehta.workspaces/style/workspaces.css")

0 comments on commit 082a465

Please sign in to comment.