You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by sz...@apache.org on 2011/07/07 09:38:27 UTC

svn commit: r1143692 [9/10] - in /incubator/stanbol/trunk/commons/web/webvie: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/stanbol/ src/main/java/org/apache/stanbol/enhancer/ src/main/java/org/a...

Added: incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie.js
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie.js?rev=1143692&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie.js (added)
+++ incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie.js Thu Jul  7 07:38:24 2011
@@ -0,0 +1,1283 @@
+//     VIE - Vienna IKS Editables
+//     (c) 2011 Henri Bergius, IKS Consortium
+//     VIE may be freely distributed under the MIT license.
+//     For all details and documentation:
+//     http://wiki.iks-project.eu/index.php/VIE
+
+(function() {
+    //  [VIE](http://wiki.iks-project.eu/index.php/VIE) enables you to make
+    //  [RDFa](http://en.wikipedia.org/wiki/RDFa) -annotated content on your
+    //  web pages editable.
+    //
+    //  For example, if your page contains the following mark-up:
+    //
+    //     <p xmlns:dc="http://purl.org/dc/elements/1.1/"
+    //        about="http://www.example.com/books/wikinomics">
+    //       In his latest book
+    //       <cite property="dc:title">Wikinomics</cite>,
+    //       <span property="dc:creator">Don Tapscott</span>
+    //       explains deep changes in technology,
+    //       demographics and business.
+    //       The book is due to be published in
+    //       <span property="dc:date" content="2006-10-01">October 2006</span>.
+    //     </p>
+    //
+    // Then with VIE you can get a proper Backbone Model object for 
+    // that. First scan your page for RDFa entities:
+    //
+    //     VIE.RDFaEntities.getInstances();
+    //
+    // And then just access the entity by subject:
+    //
+    //     var myBook = VIE.EntityManager.getBySubject('<http://www.example.com/books/wikinomics>');
+    //     alert(myBook.get('dc:title')); // "Wikinomics"
+    //
+    // Properties of the entity may also be modified, and these changes
+    // will also happen on the page itself:
+    //
+    //     myBook.set({'dc:title':'Wikinomics, Second Edition'});
+    //
+    // You can also access the entities via the `VIE.EntityManager.entities` Backbone Collection.
+    //
+    // Initial setup
+    // -------------
+    //
+    // The VIE library is fully contained inside a `VIE` namespace. The 
+    // namespace is available in both CommonJS and the browser.
+    var VIE;
+    if (typeof exports !== 'undefined') {
+        VIE = exports;
+    } else {
+        VIE = this.VIE = {};
+    }
+
+    // ### Handle dependencies
+    //
+    // VIE tries to load its dependencies automatically. 
+    // Please note that this autoloading functionality only works on the server.
+    // On browser Backbone needs to be included manually.
+
+    // Require [underscore.js](http://documentcloud.github.com/underscore/) 
+    // using CommonJS require if it isn't yet loaded.
+    //
+    // On node.js underscore.js can be installed via:
+    //
+    //     npm install underscore
+    var _ = this._;
+    if (!_ && (typeof require !== 'undefined')) { _ = require('underscore')._; }
+    if (!_) {
+        throw 'VIE requires underscore.js to be available';
+    }
+
+    // Require [Backbone.js](http://documentcloud.github.com/backbone/) 
+    // using CommonJS require if it isn't yet loaded.
+    //
+    // On node.js Backbone.js can be installed via:
+    //
+    //     npm install backbone
+    var Backbone = this.Backbone;
+    if (!Backbone && (typeof require !== 'undefined')) { Backbone = require('backbone'); }
+    if (!Backbone) {
+        throw 'VIE requires Backbone.js to be available';
+    }
+
+    // Require [jQuery](http://jquery.com/) using CommonJS require if it 
+    // isn't yet loaded.
+    //
+    // On node.js jQuery can be installed via:
+    //
+    //     npm install jquery
+    var jQuery = this.jQuery;
+    if (!jQuery && (typeof require !== 'undefined')) { jQuery = require('jquery'); }
+    if (!jQuery) {
+        throw 'VIE requires jQuery to be available';
+    }
+
+    // VIE.EntityManager
+    // -------------
+    //
+    // VIE.EntityManager keeps track of all RDFa entities loaded via VIE. This
+    // means that entities matched by a common subject can be treated as singletons.
+    //
+    // It is possible to access all loaded entities via the 
+    // `VIE.EntityManager.entities` Backbone Collection.
+    VIE.EntityManager = {
+        entities: null,
+        
+        initializeCollection: function() {
+            if (VIE.EntityManager.entities === null) {
+                VIE.EntityManager.entities = new VIE.RDFEntityCollection();
+            }
+        },
+
+        // ### VIE.EntityManager.getBySubject
+        //
+        // It is possible to get an entity that has been loaded from the page
+        // via the `getBySubject` method. If the entity cannot be found this method
+        // will return `null`.
+        //
+        // The entities accessed this way are singletons, so multiple calls to same
+        // subject will all return the same `VIE.RDFEntity` instance.
+        //
+        // Subjects may be either wrapped in `<` and `>` or not.
+        //
+        // Example:
+        //
+        //     var myBook = VIE.EntityManager.getBySubject('<http://www.example.com/books/wikinomics>');
+        getBySubject: function(subject) {
+            VIE.EntityManager.initializeCollection();
+            if (typeof subject === 'string' &&
+                VIE.RDFa._isReference(subject)) {
+                subject = VIE.RDFa._fromReference(subject);
+            }
+            
+            if (typeof subject === 'object')
+            {
+                return VIE.EntityManager.entities.detect(function(item) { 
+                    if (item.id === subject) {
+                        return true;
+                    }
+                    return false;
+                });
+            }
+
+            return VIE.EntityManager.entities.get(subject);
+        },
+
+        // ### VIE.EntityManager.getByType
+        // 
+        // Get list of RDF Entities matching the given type.
+        getByType: function(type) {
+            VIE.EntityManager.initializeCollection();
+            if (VIE.RDFa._isReference(type)) {
+                type = VIE.RDFa._fromReference(type);
+            }
+        
+            return VIE.EntityManager.entities.select(function(entity) {
+                if (entity.type === type) {
+                    return true;
+                }
+                return false;
+            });
+        },
+        
+        // ### VIE.EntityManager.getPredicate
+        //
+        // Get requested predicate from all loaded entities.
+        getPredicate: function(predicate) {
+            var predicates = [];
+            _.forEach(VIE.EntityManager.entities.pluck('dcterms:hasPart'), function(property) {
+                if (property) {
+                    predicates.push(property);
+                }
+            });
+            return predicates;
+        },
+
+        // ### VIE.EntityManager.getByJSONLD
+        //
+        // Another way to get or load entities is by passing EntityManager a valid
+        // JSON-LD object.
+        //
+        // This can be either called with a JavaScript object representing JSON-LD,
+        // or with a JSON-LD string.
+        //
+        // Example:
+        //
+        //     var json = '{"@": "<http://www.example.com/books/wikinomics>","dc:title": "Wikinomics","dc:creator": "Don Tapscott","dc:date": "2006-10-01"}';
+        //     var objectInstance = VIE.EntityManager.getByJSONLD(json);
+        getByJSONLD: function(jsonld, options) {
+            VIE.EntityManager.initializeCollection();
+            var entityInstance;
+            var properties;
+
+            if (typeof jsonld !== 'object') {
+                try {
+                    jsonld = jQuery.parseJSON(jsonld);
+                } catch (e) {
+                    return null;
+                }
+            }
+
+            // The entities accessed this way are singletons, so multiple calls 
+            // to same subject (`@` in JSON-LD) will all return the same   
+            // `VIE.RDFEntity` instance.
+            if (typeof jsonld['@'] !== 'undefined') {
+                entityInstance = VIE.EntityManager.getBySubject(jsonld['@']);
+            }
+            
+            if (entityInstance) {
+                properties = VIE.EntityManager._JSONtoProperties(jsonld, entityInstance.attributes, entityInstance.id);
+                entityInstance.set(properties, options);
+                
+                if (!entityInstance.type &&
+                    typeof jsonld.a !== 'undefined') {
+                    entityInstance.type = VIE.RDFa._fromReference(jsonld.a);
+                }
+                
+                return entityInstance;
+            }
+
+            properties = VIE.EntityManager._JSONtoProperties(jsonld, {}, VIE.EntityManager._normalizeSubject(jsonld['@']));
+            entityInstance = new VIE.RDFEntity(properties);
+
+            // Namespace prefixes are handled by the `#` property of JSON-LD.
+            // We map this to the `namespaces` property of our `VIE.RDFEntity` 
+            // instance.
+            if (typeof jsonld['#'] !== 'undefined') {
+                entityInstance.namespaces = jsonld['#'];
+            }
+
+            // Types are handled by the `a` property of JSON-LD. We map this
+            // to the `type` property of our `VIE.RDFEntity` instance.
+            if (typeof jsonld.a !== 'undefined') {
+                entityInstance.type = VIE.RDFa._fromReference(jsonld.a);
+            }
+            
+            // Normalize the subject, handling both proper JSON-LD and JSON-LD
+            // anonymous entities extracted from RDFa
+            entityInstance.id = VIE.EntityManager._normalizeSubject(jsonld['@']);
+            
+            VIE.EntityManager.registerModel(entityInstance);
+            return entityInstance;
+        },
+
+        // ### VIE.EntityManager.getByRDFJSON
+        //
+        // Another way to get or load entities is by passing EntityManager a valid
+        // RDF/JSON object.
+        //
+        // This can be either called with a JavaScript object representing JSON-LD,
+        // or with a JSON-LD string.
+        //
+        // Example:
+        //
+        //     var rdfjson = '{"<http://www.example.com/books/wikinomics>": {"dc:title": "Wikinomics","dc:creator": "Don Tapscott","dc:date": "2006-10-01"}}';
+        //     var objectInstance = VIE.EntityManager.getByRDFJSON(rdfjson);
+        getByRDFJSON: function(rdfjson, options){
+            VIE.EntityManager.initializeCollection();
+            var entityInstance;
+            var simpleProperties = {}, res = [];
+
+            if (typeof rdfjson !== 'object') {
+                try {
+                    rdfjson = jQuery.parseJSON(rdfjson);
+                } catch (e) {
+                    return null;
+                }
+            }
+            
+            _.each(rdfjson, function(properties, entityUri){
+                
+                // Simplify rdfjson
+                _(properties).each(function(propertyValues, key){
+                    curie = key;
+                    _(VIE.RDFa.Namespaces).each(function(uri, prefix) {
+                        curie = curie.replace(uri, prefix + ":");
+                    });
+                    if(key === curie){
+                        key = '<' + key + '>';
+                    } else {
+                        key = curie;
+                    }
+                    
+                    simpleProperties[key] = _(propertyValues).map(function(value){
+                        return value.value;
+                    });
+                    
+                    simpleProperties[key] = _(simpleProperties[key]).uniq();
+                    if(simpleProperties[key].length == 1)
+                        simpleProperties[key] = simpleProperties[key][0];
+                });
+                
+                entityInstance = VIE.EntityManager.getBySubject(entityUri);
+                
+                if (entityInstance) {
+                    entityInstance.set(simpleProperties, options);
+                    
+                    return entityInstance;
+                }
+                entityInstance = new VIE.RDFEntity(simpleProperties);
+                entityInstance.id = entityUri;
+                
+                res.push(entityInstance);
+                
+                VIE.EntityManager.registerModel(entityInstance);
+                return entityInstance;
+            })
+            return res;
+        },
+        
+        // All new entities must be added to the `entities` collection.
+        registerModel: function(model) {
+            model.id = VIE.EntityManager._normalizeSubject(model.id);
+            if (VIE.EntityManager.entities.indexOf(model) === -1) {
+                VIE.EntityManager.entities.add(model);
+            }
+        },
+        
+        _normalizeSubject: function(subject) {
+            // Subjects are handled by the `@` property of JSON-LD. We map this
+            // to the `id` property of our `VIE.RDFEntity` instance.
+            if (typeof subject === 'string') {
+                if (VIE.RDFa._isReference(subject)) {
+                    subject = VIE.RDFa._fromReference(subject);
+                }
+                return subject;
+            }
+            
+            // When handling anonymous entities coming from RDFa, we keep their
+            // containing element as the ID so they can be matched
+            if (typeof subject === 'object') {
+                return subject;
+            }
+            
+            return undefined;
+        },
+
+        // Create a list of Models for referenced properties
+        _referencesToModels: function(value) {
+            if (!_.isArray(value)) {
+                value = [value];
+            }
+            
+            var models = [];
+            _.forEach(value, function(subject) {
+                models.push(VIE.EntityManager.getByJSONLD({
+                    '@': subject
+                }));
+            });
+            return models;
+        },
+
+        // Helper for cleaning up JSON-LD so that it can be used as properties
+        // of a Backbone Model.
+        _JSONtoProperties: function(jsonld, instanceProperties, instanceId) {
+            var properties;
+            var references;
+            var property;
+
+            properties = jQuery.extend({}, jsonld);
+            
+            delete properties['@'];
+            delete properties.a;
+            delete properties['#'];
+            
+            _.each(properties, function(propertyValue, property) {
+                if (VIE.RDFa._isReference(propertyValue) ||
+                    typeof propertyValue === 'object') {
+                    references = VIE.EntityManager._referencesToModels(propertyValue);
+                    if (instanceProperties[property] instanceof VIE.RDFEntityCollection) {
+                        // Object already has this reference collection, keep it
+                        // and add new references
+                        jQuery.each(references, function() {
+                            if (instanceProperties[property].indexOf(this) === -1) {
+                                instanceProperties[property].add(this);
+                            }
+                        });
+
+                        properties[property] = instanceProperties[property];
+                    }
+                    else {
+                        properties[property] = new VIE.RDFEntityCollection(references);
+                        if (instanceId) {
+                            properties[property].subject = VIE.EntityManager._normalizeSubject(instanceId);
+                            properties[property].predicate = property;
+                        }
+                    }
+                }
+            });
+
+            return properties;
+        },
+        
+        // Helper for removing existing information about loaded entities.
+        cleanup: function() {
+            VIE.EntityManager.entities = new VIE.RDFEntityCollection();
+        }
+    };
+
+    // VIE.RDFEntity
+    // -------------
+    //
+    // VIE.RDFEntity defines a common [Backbone Model](http://documentcloud.github.com/backbone/#Model) 
+    // for RDF entities handled in VIE.
+    //
+    // Attributes that are references to other entities are exposed as
+    // `VIE.RDFEntityCollection` objects containing those entities.
+    VIE.RDFEntity = Backbone.Model.extend({
+        namespaces: {},
+        type: '',
+        
+        // Get the subject of a RDF entity. For persistent entities full URL 
+        // subjects will be returned wrapped in `<` and `>`. 
+        // For non-persistent entities an anonymous `_:bnodeX` will be returned,
+        // with `X` matching the local `cid` number of the entity instance.
+        //
+        // CURIEs will be returned as-is.
+        getSubject: function() {
+            if (typeof this.id === 'string') {
+                if (this.id.substr(0, 7) === 'http://') {
+                    return VIE.RDFa._toReference(this.id);
+                }
+                return this.id;
+            }
+            return this.cid.replace('c', '_:bnode');
+        },
+
+        // VIE's entities have a method for generating [JSON-LD](http://json-ld.org/)
+        // representations of themselves. JSON-LD is a lightweight format for handling
+        // Linked Data (RDF) information.
+        //
+        // Using the book example from above, we could call:
+        //
+        //     myBook.toJSONLD();
+        //
+        // And we would get a JSON object looking like the following:
+        //
+        //     {
+        //         '@': '<http://www.example.com/books/wikinomics>',
+        //         'dc:title': 'Wikinomics',
+        //         'dc:creator': 'Don Tapscott',
+        //         'dc:date': '2006-10-01' 
+        //     }
+        //
+        // Calling `JSON.stringify()` for this object would produce:
+        //
+        //
+        //     {
+        //         "@": "<http://www.example.com/books/wikinomics>",
+        //         "dc:title": "Wikinomics",
+        //         "dc:creator": "Don Tapscott",
+        //         "dc:date": "2006-10-01"
+        //     }
+        toJSONLD: function() {
+            var instance = this;
+            var instanceLD = {};
+            var property;
+
+            _.each(instance.attributes, function(attributeValue, property) {
+                attributeValue = instance.get(property);
+                if (attributeValue instanceof VIE.RDFEntityCollection) {
+                    instanceLD[property] = attributeValue.map(function(referenceInstance) {
+                        return referenceInstance.getSubject();
+                    });
+                } else {
+                    instanceLD[property] = attributeValue;
+                }
+            });
+            
+            instanceLD['@'] = instance.getSubject();
+
+            if (instance.namespaces.length > 0) {
+                instanceLD['#'] = instance.namespaces;
+            }
+
+            if (instance.type) {
+                instanceLD.a = VIE.RDFa._toReference(instance.type);
+            }
+            
+            return instanceLD;
+        }
+    });
+
+    // VIE.RDFEntityCollection
+    // -----------------------
+    //
+    // VIE.RDFEntityCollection defines a common [Backbone Collection](http://documentcloud.github.com/backbone/#Collection) 
+    // for references to RDF entities handled in VIE.
+    VIE.RDFEntityCollection = Backbone.Collection.extend({
+        model: VIE.RDFEntity,
+        initialize: function() {
+            this.bind('add', this.registerItem);
+        },
+        registerItem: function(entityInstance, collection) {
+            if (collection === VIE.EntityManager.entities) {
+                return;
+            }
+
+            _.each(entityInstance.attributes, function(propertyValue, property) {
+                if(property == 'id') return true;
+                if (VIE.RDFa._isReference(propertyValue)) {
+                    var references = VIE.EntityManager._referencesToModels(propertyValue);
+                    entityInstance.attributes[property] = new VIE.RDFEntityCollection(references);
+                }
+            });
+
+            VIE.EntityManager.registerModel(entityInstance);
+        }
+    });
+    
+    // VIE.RDFaEntities
+    // -------------
+    //
+    // VIE.RDFaEntities provide mapping between RDFa on a page and Backbone Views.
+    // When you load RDFa entities from a page, new `VIE.RDFEntity` objects will
+    // be instantiated for them, and the DOM element the RDFa comes from will
+    // be registered as a `VIE.RDFaView` instance.
+    //
+    // If you're working with RDFa -annotated content and want to access it as
+    // Backbone Models, then VIE.RDFaEntities is the main access point.
+    VIE.RDFaEntities = {
+        // RDFaEntities manages a list of Views so that every view instance will be
+        // a singleton.
+        Views: [],
+        CollectionViews: [],
+
+        // ### VIE.RDFaEntities.getInstance
+        //
+        // The `getInstance` method can be used for retrieving a single Backbone
+        // Model for a given RDFa -annotated DOM element. It accepts 
+        // [jQuery selectors](http://api.jquery.com/category/selectors/)
+        // and returns a `VIE.RDFEntity` instance matching the content. If no valid
+        // RDFa entities can be found from the element, then it returns `null`.
+        //
+        // Example:
+        //
+        //     var myBook = VIE.RDFaEntities.getInstance('p[about]');
+        //     alert(myBook.get('dc:title')); // "Wikinomics"
+        getInstance: function(element) {
+            element = jQuery(element);
+            var entityInstance;
+            var jsonld;
+
+            jsonld = VIE.RDFa.readEntity(element);
+            if (!jsonld) {
+                return null;
+            }
+
+            entityInstance = VIE.EntityManager.getByJSONLD(jsonld);
+
+            VIE.RDFaEntities._registerView(entityInstance, element);
+
+            return entityInstance;
+        },
+        
+        _getViewInstance: function(element, collection) {
+            var viewInstance;
+            var viewArray = VIE.RDFaEntities.Views;
+            element = jQuery(element);
+            
+            if (collection) {
+                viewArray = VIE.RDFaEntities.CollectionViews;
+            }
+            
+            jQuery.each(viewArray, function() {
+                if (this.el.get(0) === element.get(0)) {
+                    viewInstance = this;
+                    return false;
+                }
+            });
+            
+            return viewInstance;
+        },
+        
+        // Helper for registering views for a collection
+        _registerCollectionView: function(collectionInstance, element) {
+            var viewInstance;
+            var template;
+            element = jQuery(element);
+            
+            // Check whether we already have a View instantiated for the DOM element
+            viewInstance = VIE.RDFaEntities._getViewInstance(element, true);
+            if (viewInstance) {
+                return viewInstance;
+            }
+
+            template = element.children(':first-child');
+
+            viewInstance = new VIE.RDFaCollectionView({
+                collection: collectionInstance,
+                model: collectionInstance.model, 
+                el: element,
+                elementTemplate: template,
+                tagName: element.get(0).nodeName
+            });
+            VIE.RDFaEntities.CollectionViews.push(viewInstance);
+
+            return viewInstance;
+        },
+        
+        // Helper for registering views for an entity
+        _registerView: function(entityInstance, element, refreshCollections) {
+            var viewInstance;
+            element = jQuery(element);
+            
+            // Check whether we already have a View instantiated for the DOM element
+            viewInstance = VIE.RDFaEntities._getViewInstance(element);
+            if (viewInstance) {
+                return viewInstance;
+            }
+
+            viewInstance = new VIE.RDFaView({
+                model: entityInstance, 
+                el: element,
+                tagName: element.get(0).nodeName
+            });
+            VIE.RDFaEntities.Views.push(viewInstance);
+
+            // Find collection elements, and create collection views for them
+            _.each(entityInstance.attributes, function(attributeValue, property) {
+                attributeValue = entityInstance.get(property);
+                if (attributeValue instanceof VIE.RDFEntityCollection) {
+                    jQuery.each(VIE.RDFa._getElementByPredicate(property, element), function() {
+                        VIE.RDFaEntities._registerCollectionView(attributeValue, this);
+                        if (refreshCollections) {
+                            attributeValue.trigger('refresh', attributeValue);
+                        }
+                    });
+                }
+            });
+            
+            return viewInstance;
+        },
+
+        // ### VIE.RDFaEntities.getInstances
+        //
+        // Get a list of Backbone Model instances for all RDFa-marked content in 
+        // an element. The method accepts [jQuery selectors](http://api.jquery.com/category/selectors/)
+        // as argument. If no selector is given, then the whole HTML document will
+        // be searched.
+        //
+        // Example:
+        //
+        //     var allInstances = VIE.RDFaEntities.getInstances();
+        //     alert(allInstances[0].get('dc:title')); // "Wikinomics"
+        getInstances: function(element) {
+            var entities = [];
+            var entity;
+
+            if (typeof element === 'undefined') {
+                element = jQuery(document);
+            }
+
+            jQuery(VIE.RDFa.subjectSelector, element).add(jQuery(element).filter(VIE.RDFa.subjectSelector)).each(function() {
+                entity = VIE.RDFaEntities.getInstance(this);
+                if (entity) {
+                    entities.push(entity);
+                }
+            });
+
+            return entities;
+        },
+        
+        // Helper for removing existing references to Views loaded for RDFa entities.
+        cleanup: function() {
+            VIE.RDFaEntities.Views = [];
+        }
+    };
+    
+    // VIE.RDFaView
+    // -------------
+    //
+    // VIE.RDFaView defines a common [Backbone View](http://documentcloud.github.com/backbone/#View) 
+    // for all RDFa -annotated elements on a page that have been loaded as
+    // `VIE.RDFEntity` objects.
+    //
+    // In normal operation, the RDFaView objects are automatically handled by
+    // `VIE.RDFaEntities`.
+    VIE.RDFaView = Backbone.View.extend({
+
+        // We ensure view gets updated when properties of the Entity change.
+        initialize: function() {
+            _.bindAll(this, 'render');
+            this.model.bind('change', this.render);
+        },
+
+        // Rendering a view means writing the properties of the Entity back to
+        // the element containing our RDFa annotations.
+        render: function() {
+            VIE.RDFa.writeEntity(this.el, this.model.toJSONLD());
+            return this;
+        }
+    });
+    
+    // VIE.RDFaCollectionView
+    // ----------------------
+    //
+    // VIE.RDFaCollectionView defines a common Backbone View for Collection properties
+    VIE.RDFaCollectionView = Backbone.View.extend({
+    
+        elementTemplate: null,
+
+        // Ensure the collection view gets updated when items get added or removed
+        initialize: function() {
+            this.elementTemplate = this.options.elementTemplate;
+            _.bindAll(this, 'addItem', 'removeItem', 'refreshItems');
+            this.collection.bind('add', this.addItem);
+            this.collection.bind('remove', this.removeItem);
+            this.collection.bind('refresh', this.refreshItems);
+        },
+        
+        // When a collection is refreshed, we empty the collection list and
+        // add each child separately
+        refreshItems: function(collectionInstance) {
+            var collectionView = this;
+            jQuery(this.el).empty();
+            collectionInstance.forEach(function(itemInstance) {
+                collectionView.addItem(itemInstance, collectionInstance);
+            });
+        },
+
+        // When adding new items we create a new element of the child type
+        // and append it to the list.
+        addItem: function(itemInstance, collection) {
+            if (collection !== this.collection) {
+                return;
+            }
+            if (!this.elementTemplate ||
+                this.elementTemplate.length === 0) {
+                return;
+            }
+            var itemView = VIE.RDFaEntities._registerView(itemInstance, VIE.RDFa._cloneElement(this.elementTemplate), true);
+            var itemViewElement = itemView.render().el;
+            if (itemInstance.id &&
+                typeof itemInstance.id === 'string') {
+                VIE.RDFa.setSubject(itemViewElement, itemInstance.id);
+            } else {
+                itemInstance.id = itemViewElement.get(0);
+            }
+                    
+            // Figure out where to place the element based on its order
+            var itemOrder = this.collection.indexOf(itemInstance);
+            var childElements = jQuery(this.el).children();
+            if (childElements.length === 0 ||
+                itemOrder > childElements.length - 1)
+            {
+                jQuery(this.el).append(itemViewElement);
+            } else {
+                jQuery(this.el).children().each(function(index, element) {
+                    if (index >= itemOrder) {
+                        jQuery(element).before(itemViewElement);
+                        return false;
+                    }
+                });
+            }
+
+            this.trigger('add', itemView);
+            itemViewElement.show();
+            
+            // If the new instance doesn't yet have an identifier, bind it to
+            // the HTML representation of itself. This safeguards from duplicates.
+            if (!itemInstance.id) {
+                itemInstance.id = VIE.RDFa.getSubject(itemViewElement);
+            }
+            
+            // Ensure we catch all inferred predicates. We add these via JSONLD
+            // so the references get properly Collectionized.
+            jQuery(itemViewElement).parent('[rev]').each(function() {
+                var properties = {
+                    '@': itemInstance.id
+                };
+                var predicate = jQuery(this).attr('rev');
+                properties[predicate] = VIE.RDFa.getSubject(this);
+                VIE.EntityManager.getByJSONLD(properties);
+            });
+        },
+
+        // When removing items from Collection we remove their views from the DOM.
+        removeItem: function(itemInstance) {
+            // Try to find it from DOM
+            jQuery(VIE.RDFa.subjectSelector, this.el).filter(function() {
+                if (VIE.RDFa.getSubject(this) === VIE.RDFa._toReference(itemInstance.id)) {
+                    return true;
+                }
+            }).each(function() {
+                jQuery(this).remove();
+            });
+            return;
+        }
+    });
+
+    // VIE.RDFa
+    // --------
+    //
+    // RDFa reading and writing utilities. VIE.RDFa acts as a mapping tool between
+    // [JSON-LD](http://json-ld.org/) -encoded RDF triples and RDFa -annotated content
+    // on a page.
+    VIE.RDFa = {
+        Namespaces: {},
+
+        // By default we look for RDF subjects based on elements that have a
+        // `about`, `typeof` or `src` attribute. In addition, the full HTML page
+        // is regarded as a valid subject.
+        //
+        // For more specialized scenarios this can be overridden:
+        //
+        //     VIE.RDFa.subjectSelector = '[about]';
+        subjectSelector: '[about],[typeof],[src],html',
+        
+        // By default we look for RDF predicates based on elements that have a
+        // `property` or `rel` attribute.
+        //
+        // For more specialized scenarios this can be overridden:
+        //
+        //     VIE.RDFa.predicateSelector = '[property]';
+        predicateSelector: '[property],[rel]',
+
+        // ### VIE.RDFa.getSubject
+        //
+        // Get the RDF subject for an element. The method accepts 
+        // [jQuery selectors](http://api.jquery.com/category/selectors/) as
+        // arguments. If no argument is given, then the _base URL_ of the
+        // page is used.
+        //
+        // Returns the subject as a string if one can be found, and if the
+        // given element has no valid subjects returns `undefined`.
+        //
+        // Example:
+        //
+        //     var subject = VIE.RDFa.getSubject('p[about]');
+        //     alert(subject); // <http://www.example.com/books/wikinomics>
+        getSubject: function(element) {
+            if (typeof document !== 'undefined') {
+                if (element === document) {
+                    return document.baseURI;
+                }
+            }
+            var subject;
+            jQuery(element).closest(VIE.RDFa.subjectSelector).each(function() {
+                if (jQuery(this).attr('about')) {
+                    subject = jQuery(this).attr('about');
+                    return true;
+                }
+                if (jQuery(this).attr('src')) {
+                    subject = jQuery(this).attr('src');
+                    return true;
+                }
+                if (jQuery(this).attr('typeof')) {
+                    subject = this;
+                    return true;
+                }
+
+                // We also handle baseURL outside browser context by manually
+                // looking for the `<base>` element inside HTML head.
+                if (jQuery(this).get(0).nodeName === 'HTML') {
+                    jQuery(this).find('base').each(function() {
+                        subject = jQuery(this).attr('href');
+                    });
+                }
+            });
+            
+            if (!subject) {
+                return undefined;
+            }
+            
+            if (typeof subject === 'object') {
+                return subject;
+            }
+
+            return VIE.RDFa._toReference(subject);
+        },
+        
+        // Set subject for an element
+        setSubject: function(element, subject) {
+            if (jQuery(element).attr('src')) {
+                return jQuery(element).attr('src', subject);
+            }
+            jQuery(element).attr('about', subject);
+        },
+        
+        // Get predicate for an element
+        getPredicate: function(element) {
+            var propertyName;
+
+            element = jQuery(element);
+            
+            propertyName = element.attr('property');
+            if (!propertyName) {
+                propertyName = element.attr('rel');
+            }
+            return propertyName;
+        },
+
+        // ### VIE.RDFa.readEntity
+        //
+        // Get a JSON-LD object for an RDFa-marked entity in 
+        // an element. The method accepts [jQuery selectors](http://api.jquery.com/category/selectors/)
+        // as argument. If the element contains no RDFa entities, the this method
+        // returns `null`.
+        //
+        // Example:
+        //
+        //     var jsonld = VIE.RDFa.readEntity('p[about]');
+        //
+        // Would return a JSON-LD object looking like the following:
+        //
+        //     {
+        //         '@': '<http://www.example.com/books/wikinomics>',
+        //         'dc:title': 'Wikinomics',
+        //         'dc:creator': 'Don Tapscott',
+        //         'dc:date': '2006-10-01' 
+        //     }
+        readEntity: function(element) {
+            var entity;
+            var subject;
+            var namespaces = {};
+            var namespace;
+            var type;
+            var propertyName;
+
+            subject = VIE.RDFa.getSubject(element);
+
+            entity = VIE.RDFa._getElementProperties(subject, element, false);
+            if (jQuery.isEmptyObject(entity)) {
+                return null;
+            }
+
+            // We also try to resolve namespaces used in the RDFa entity. If they
+            // can be found, we will write them to the `#` property of the object.
+            for (propertyName in entity) {
+                if (entity.hasOwnProperty(propertyName)) {
+                    var propertyParts = propertyName.split(':');
+                    if (propertyParts.length === 2) {
+                        namespace = VIE.RDFa._resolveNamespace(propertyParts[0], element);
+                        if (namespace) {
+                            namespaces[propertyParts[0]] = namespace;
+                        }
+                    }
+                }
+            }
+            if (!jQuery.isEmptyObject(namespaces)) {
+                entity['#'] = namespaces;
+            }
+
+            // If the RDF type is defined, that will be set to the [`a` property](http://json-ld.org/spec/latest/#specifying-the-type)
+            // of the JSON-LD object.
+            type = VIE.RDFa._getElementValue(element, 'typeof');
+            if (type) {
+                entity.a = VIE.RDFa._toReference(type);
+            }
+
+            entity['@'] = subject;
+
+            return entity;
+        },
+
+        // ### VIE.RDFa.readEntities
+        //
+        // Get a list of JSON-LD objects for RDFa-marked entities in 
+        // an element. The method accepts [jQuery selectors](http://api.jquery.com/category/selectors/)
+        // as argument.  If no selector is given, then the whole HTML document will
+        // be searched.
+        //
+        // Example:
+        //
+        //     var jsonldEntities = VIE.RDFa.readEntities();
+        //     JSON.stringify(jsonldEntities[0]);
+        //
+        // Would produce something like:
+        //
+        //     {
+        //         "@": "<http://www.example.com/books/wikinomics>",
+        //         "dc:title": "Wikinomics",
+        //         "dc:creator": "Don Tapscott",
+        //         "dc:date": "2006-10-01"
+        //     }
+        readEntities: function(element) {
+            var entities = [];
+            var entity;
+
+            if (typeof element === 'undefined') {
+                element = jQuery(document);
+            }
+
+            jQuery(VIE.RDFa.subjectSelector, element).add(jQuery(element).filter(VIE.RDFa.subjectSelector)).each(function() {
+                entity = VIE.RDFa.readEntity(this);
+                if (entity) {
+                    entities.push(entity);
+                }
+            });
+
+            return entities;
+        },
+
+        // ### VIE.RDFa.writeEntity
+        //
+        // Write the contents of a JSON-LD object into the given DOM element. This
+        // method accepts [jQuery selectors](http://api.jquery.com/category/selectors/)
+        // as arguments.
+        //
+        // Only properties matching RDFa-annotated predicates found found from
+        // the selected DOM element will be written.
+        writeEntity: function(element, jsonld) {
+            VIE.RDFa.findPredicateElements(VIE.RDFa.getSubject(element), element, true).each(function() {
+                var propertyElement = jQuery(this);
+                var propertyName = propertyElement.attr('property');
+
+                if (typeof jsonld[propertyName] === 'undefined') {
+                    jsonld[propertyName] = propertyName;
+                }
+
+                // Before writing to DOM we check that the value has actually changed.
+                if (VIE.RDFa._readPropertyValue(propertyName, propertyElement) !== jsonld[propertyName]) {
+                    VIE.RDFa._writePropertyValue(propertyElement, jsonld[propertyName]);
+                }
+            });
+            return this;
+        },
+        
+        // ### VIE.RDFa.findPredicateElements
+        //
+        // Find RDFa-annotated predicates for a given subject inside the DOM. This
+        // method accepts [jQuery selectors](http://api.jquery.com/category/selectors/)
+        // as arguments.
+        //
+        // The method returns a list of matching DOM elements.
+        //
+        // Only predicates matching the given subject will be returned.
+        // You can also tell whether to allow nested predicates to be returned, 
+        // which is useful for example when instantiating WYSIWYG editors for 
+        // editable properties, as most editors do not like getting nested.
+        findPredicateElements: function(subject, element, allowNestedPredicates) {
+            if (typeof subject === 'string' &&
+                !VIE.RDFa._isReference(subject)) {
+                subject = VIE.RDFa._toReference(subject);
+            }
+            return jQuery(element).find(VIE.RDFa.predicateSelector).add(jQuery(element).filter(VIE.RDFa.predicateSelector)).filter(function() {
+                if (VIE.RDFa.getSubject(this) !== subject) {
+                    return false;
+                }
+                if (!allowNestedPredicates) {
+                    if (!jQuery(this).parents('[property]').length) {
+                        return true;
+                    }
+                    return false;
+                }
+
+                return true;
+            });
+        },
+
+        // Figure out if a given value is a wrapped reference
+        _isReference: function(value) {
+            var matcher = new RegExp("^\\<([^\\>]*)\\>$");
+            if (matcher.exec(value)) {
+                return true;
+            }
+            return false;
+        },
+
+        // In JSON-LD all references are surrounded by `<` and `>`. Convert a regular
+        // textual value to this format.
+        _toReference: function(value) {
+            return '<' + value + '>';
+        },
+        
+        // In JSON-LD all references are surrounded by `<` and `>`. Convert reference
+        // to a regular textual value.
+        _fromReference: function(reference) {
+            if (_.isArray(reference)) {
+                return _.map(reference, function(ref) {
+                    return VIE.RDFa._fromReference(ref);
+                });
+            }
+            return reference.substring(1, reference.length - 1);
+        },
+
+        // Get value of a DOM element defining a RDFa predicate.
+        _readPropertyValue: function(propertyName, element) {
+
+            // The `content` attribute can be used for providing machine-readable
+            // values for elements where the HTML presentation differs from the
+            // actual value.
+            var content = element.attr('content');
+            if (content !== undefined) {
+                return content;
+            }
+            
+            // The `resource` attribute can be used to link a predicate to another
+            // RDF resource.
+            var resource = element.attr('resource');
+            if (resource) {
+                return VIE.RDFa._toReference(resource);
+            }
+            
+            // `href` attribute also links to another RDF resource.
+            var href = element.attr('href');
+            if (href &&
+                element.attr('rel') === propertyName) {
+                return VIE.RDFa._toReference(href);
+            }
+
+            // If the predicate is a relation, we look for identified child objects
+            // and provide their identifiers as the values. To protect from scope
+            // creep, we only support direct descentants of the element where the
+            // `rel` attribute was set.
+            if (element.attr('rel')) {
+                var value = [];
+                jQuery(element).children(VIE.RDFa.subjectSelector).each(function() {
+                    value.push(VIE.RDFa.getSubject(this));
+                });
+                return value;
+            }
+
+            // If none of the checks above matched we return the HTML contents of
+            // the element as the literal value.
+            return element.html();
+        },
+
+        // Write a value to a DOM element defining a RDFa predicate.
+        _writePropertyValue: function(element, value) {
+
+            // For now we don't deal with multivalued properties when writing
+            // contents.
+            if (value instanceof Array ||
+                element.attr('rel')) {
+                return true;
+            }
+   
+            // The `content` attribute can be used for providing machine-readable
+            // values for elements where the HTML presentation differs from the
+            // actual value.
+            var content = element.attr('content');
+            if (content) {
+                element.attr('content', value);
+                return;
+            }
+            
+            // The `resource` attribute can be used to link a predicate to another
+            // RDF resource.
+            var resource = element.attr('resource');
+            if (resource) {
+                element.attr('resource', value);
+            }
+
+            // Property has inline value. Change the HTML contents of the property
+            // element to match the new value.
+            element.html(value);
+        },
+
+        // Namespace resolution, find namespace declarations from inside
+        // a DOM element.
+        _resolveNamespace: function(prefix, element) {
+            if (typeof VIE.RDFa.Namespaces[prefix] !== 'undefined') {
+                return VIE.RDFa.Namespaces[prefix];
+            }
+            
+            jQuery('[xmlns\\:' + prefix + ']').each(function() {
+                VIE.RDFa.Namespaces[prefix] = jQuery(this).attr('xmlns:' + prefix);
+            });
+
+            return VIE.RDFa.Namespaces[prefix];
+        },
+
+        // Get the value of an attribute from the element or from one of its children
+        _getElementValue: function(element, propertyName) {
+            element = jQuery(element);
+            if (typeof element.attr(propertyName) !== 'undefined')
+            {
+                return element.attr(propertyName);
+            }
+            return element.children('[' + propertyName + ']').attr(propertyName);
+        },
+        
+        // Get elements matching a given subject and predicate
+        _getElementByPredicate: function(predicate, element) {
+            var subject = VIE.RDFa.getSubject(element);
+            return jQuery(element).find(VIE.RDFa.predicateSelector).add(jQuery(element).filter(VIE.RDFa.predicateSelector)).filter(function() {
+                if (VIE.RDFa.getPredicate(this) !== predicate) {
+                    return false;
+                }
+
+                if (VIE.RDFa.getSubject(this) !== subject) {
+                    return false;
+                }
+ 
+                return true;
+            });
+        },
+
+        // Get JSON-LD properties from a DOM element.
+        _getElementProperties: function(subject, element, emptyValues) {
+            var containerProperties = {};
+
+            VIE.RDFa.findPredicateElements(subject, element, true).each(function() {
+                var propertyName;
+                var propertyValue;
+                var objectProperty = jQuery(this);
+                propertyName = VIE.RDFa.getPredicate(this); 
+                
+                propertyValue = VIE.RDFa._readPropertyValue(propertyName, objectProperty);
+                if (propertyValue === null &&
+                    !emptyValues) {
+                    return;
+                }
+
+                if (typeof containerProperties[propertyName] !== 'undefined') {
+                    if (containerProperties[propertyName] instanceof Array) {
+                        if (emptyValues) {
+                            return;
+                        }
+                        containerProperties[propertyName].push(propertyValue);
+                        return;
+                    }
+                    // Multivalued properties, are converted to an Array
+                    var previousValue = containerProperties[propertyName];
+                    containerProperties[propertyName] = [];
+
+                    if (emptyValues) {
+                        return;
+                    }
+
+                    containerProperties[propertyName].push(previousValue);
+                    containerProperties[propertyName].push(propertyValue);
+                    return;
+                }
+
+                if (emptyValues) {
+                    containerProperties[propertyName] = '';
+                    return;
+                }
+
+                containerProperties[propertyName] = propertyValue;
+            });
+
+            if (jQuery(element).get(0).tagName !== 'HTML') {
+                jQuery(element).parent('[rev]').each(function() {
+                    containerProperties[jQuery(this).attr('rev')] = VIE.RDFa.getSubject(this); 
+                });
+            }
+
+            return containerProperties;
+        },
+        
+        // Create an anonymized clone of an element
+        _cloneElement: function(element) {
+            element = jQuery(element).clone(false);
+
+            if (typeof element.attr('about') !== 'undefined')
+            {
+                // Direct match with container
+                element.attr('about', '');
+            }
+            element.find('[about]').attr('about', '');
+            var subject = VIE.RDFa.getSubject(element);
+            VIE.RDFa.findPredicateElements(subject, element, false).each(function() {
+                VIE.RDFa._writePropertyValue(jQuery(this), '');
+            });
+
+            return element;
+        },
+        
+        // Helper for removing existing namespaces information.
+        cleanup: function() {
+            VIE.RDFa.Namespaces = {};
+        }
+    };
+
+    // VIE.cleanup()
+    // -------------
+    //
+    // By default VIE keeps track of all RDF entities, RDFa views and namespaces
+    // handled. If you want to clear all of these (for example in unit tests),
+    // then call:
+    //
+    //     VIE.cleanup();
+    VIE.cleanup = function() {
+        VIE.EntityManager.cleanup();
+        VIE.RDFaEntities.cleanup();
+        VIE.RDFa.cleanup();
+    };
+
+}).call(this);

Added: incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/dbpedia.js
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/dbpedia.js?rev=1143692&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/dbpedia.js (added)
+++ incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/dbpedia.js Thu Jul  7 07:38:24 2011
@@ -0,0 +1,99 @@
+// File:   dbpedia.js
+// Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
+//
+
+//The dbpedia connector needs to be initialized like this:
+//VIE2.getConnector('dbpedia').options({
+//    "proxy_url" : "../utils/proxy/proxy.php"
+//});
+new VIE2.Connector('dbpedia', {
+    namespaces: {
+        'owl'    : "http://www.w3.org/2002/07/owl#",
+        'yago'   : "http://dbpedia.org/class/yago/",
+        'dbonto' : 'http://dbpedia.org/ontology/'
+    }
+});
+
+VIE2.connectors['dbpedia'].query = function (uri, props, callback) {    
+    if (uri instanceof jQuery.rdf.resource &&
+            uri.type === 'uri') {
+        this.query(uri.toString(), props, callback);
+        return;
+    }
+    if (!jQuery.isArray(props)) {
+        return this.query(uri, [props], callback);
+        return;
+    }
+    if ((typeof uri != 'string')) {
+        VIE2.log ("warn", "VIE2.Connector('" + this.id + "')", "Query does not support the given URI!");
+        callback.call(this, {});
+        return;
+    }
+    var uri = uri.replace(/^</, '').replace(/>$/, '');
+    if (!uri.match(/^http\:\/\/dbpedia.org\/.*/)) {
+        VIE2.log ("warn", "VIE2.Connector('" + this.id + "')", "Query does not support the given URI!");
+        callback.call(this, {});
+        return;
+    }
+    
+    var url = uri.replace('resource', 'data') + ".jrdf";
+    var c = function (conn, u, ps) {
+        return function (data) {
+            //initialize the returning object
+            var ret = {};
+            
+            if (data && data.status === 200) {
+                try {
+                    var json = jQuery.parseJSON(data.responseText);
+                    if (json) {
+                        var rdfc = jQuery.rdf().load(json);
+                        jQuery.each(VIE2.namespaces, function(k, v) {
+                            rdfc.prefix(k, v);
+                        });
+                        
+                        for (var i=0; i < ps.length; i++) {
+                            var prop = props[i].toString();
+                            ret[prop] = [];
+                            
+                            rdfc
+                            .where(jQuery.rdf.pattern('<' + u + '>', prop, '?object', { namespaces: VIE2.namespaces}))
+                            .each(function () {
+                                ret[prop].push(this.object);
+                            });
+                        }
+                    }
+                } catch (e) {
+                    VIE2.log ("warn", "VIE2.Connector('dbpedia')", "Could not query for uri '" + uri + "' because of the following parsing error: '" + e.message + "'!");
+                }
+            }
+            callback.call(conn, ret);
+        };
+    }(this, uri, props);
+    
+    this.queryDBPedia(url, c);
+};
+
+VIE2.connectors['dbpedia'].queryDBPedia = function (url, callback) {
+    var proxy = this.options().proxy_url;
+    
+    if (proxy) {
+        jQuery.ajax({
+            async: true,
+            complete : callback,
+            type: "POST",
+            url: proxy,
+            data: {
+                proxy_url: url, 
+                content: "",
+                verb: "GET"
+            }
+        });
+    } else {
+        data = jQuery.ajax({
+            async: true,
+            complete : callback,
+            type: "GET",
+            'url': url
+        });
+    }
+};
\ No newline at end of file

Added: incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/opencalais.js
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/opencalais.js?rev=1143692&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/opencalais.js (added)
+++ incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/opencalais.js Thu Jul  7 07:38:24 2011
@@ -0,0 +1,149 @@
+new VIE2.Connector('opencalais', {
+    namespaces: {
+        c:  "http://s.opencalais.com/1/pred/",
+        cr: "http://s.opencalais.com/1/type/er/",
+        cm: "http://s.opencalais.com/1/type/em/e/",
+        cl: "http://s.opencalais.com/1/type/lid/",
+        cs: "http://s.opencalais.com/1/type/sys/",
+        cc: "http://s.opencalais.com/1/type/cat/",
+        foaf : "http://xmlns.com/foaf/0.1/"
+    }
+});
+
+VIE2.connectors['opencalais'].analyze = function (object, options) {
+    var rdf = jQuery.rdf();
+    
+    var rules = this.createReasoningRules();
+    
+    if (object === undefined) {
+        VIE2.log ("warn", "VIE2.Connector('" + this.id + "')", "Given object is undefined!");
+        if (options && options.error) {
+            options.error("Given object is undefined!");
+        }
+    } else if (typeof object === 'object') {
+        var self = this; 
+        //opencalais can in fact deal with embedded HTML
+        var text = self.extractText(object);
+        //the AJAX callback function
+        var callback = function (rdfc) {
+            //adding all new found triples to the main rdfQuery object
+            rdfc.databank.triples().each(function () {
+                rdf.add(this);
+            });
+            //let's see if there are children to be enhanced.
+            VIE2.log("info", "VIE2.Connector(" + self.id + ")", "Start reasoning '" + (rdf.databank.triples().length) + "'");
+            rdf.reason(rules);    
+            VIE2.log("info", "VIE2.Connector(" + self.id + ")", "End   reasoning '" + (rdf.databank.triples().length) + "'");
+            if (options && options.success) {
+                options.success.call(self, rdf);
+            } else {
+                VIE2.log("warn", "VIE2.Connector(" + self.id + ")", "No success callback given. How do you think this should gonna work?'");
+            }
+        };
+        this.enhance(text, callback);
+    } else {
+        VIE2.log("error", "VIE2.Connector(" + this.id + ")", "Expected element of type 'object', found: '" + (typeof object) + "'");
+        if (options && options.error) {
+            options.error.call(this, "Expected element of type 'object', found: '" + (typeof object) + "'");
+        }
+    }
+};
+
+VIE2.connectors['opencalais'].createReasoningRules = function () {
+    var rules = jQuery.rdf.ruleset();
+    
+    jQuery.each(this._options.namespaces, function (k, v) {
+        rules.prefix(k, v);
+    })
+    
+    rules.add(['?subject a cm:Person',
+               '?subject c:name ?name',
+               '?subject c:commonname ?commonname'], 
+              ['?subject foaf:name ?name',
+               '?subject foaf:name ?commonname'
+              ]);
+              
+   return rules;
+}
+
+VIE2.connectors['opencalais'].extractText = function (obj) {
+    if (obj.get(0) && 
+            obj.get(0).tagName && 
+            (obj.get(0).tagName == 'TEXTAREA' ||
+            obj.get(0).tagName == 'INPUT' && obj.attr('type', 'text'))) {
+        return obj.get(0).val();
+    }
+    else {
+        return obj
+            .html()    //get the html of element
+            .replace(/\s+/g, ' ') //collapse multiple whitespaces
+            .replace(/\0\b\n\r\f\t/g, '').trim(); // remove non-letter symbols
+    }
+};
+
+VIE2.connectors['opencalais'].enhance = function (text, callback) {
+    if (text.length === 0) {
+        VIE2.log("warn", "VIE2.Connector(" + this.id + ")", "Empty text.");
+        callback(jQuery.rdf());
+    }
+    else {
+        var c = function(data) {
+            if (data) {
+                try {
+                    
+                    var rdf = jQuery.rdf().load(data, {});
+                    callback(rdf);
+                } 
+                catch (e) {
+                    VIE2.log("error", "VIE2.Connector(" + this.id + ")", "Could not connect to opencalais enhancer.");
+                    VIE2.log("error", "VIE2.Connector(" + this.id + ")", data);
+                    callback(jQuery.rdf());
+                }
+            }
+        };
+        this.queryOpencalais(this.prepareOpencalaisData(text), c);
+    }
+};
+
+VIE2.connectors['opencalais'].prepareOpencalaisData = function (text) {
+    return {
+        licenseID: this._options.opencalais_api_key,
+        calculareRelevanceScore: "true",
+        enableMetadataType: "GenericRelations,SocialTags",
+        contentType: "text/html",
+        content: text
+        // for more options check http://developer.opencalais.com/docs/suggest/
+    };
+};
+
+VIE2.connectors['opencalais'].queryOpencalais = function (data, callback) {
+
+    var proxy = this._options.proxy_url;
+    var opencalais_url = this._options.opencalais_url;
+
+    if (proxy) {
+        jQuery.ajax({
+            async: true,
+            success: callback,
+            error: callback,
+            type: "POST",
+            url: proxy,
+            data: {
+                proxy_url: opencalais_url, 
+                content: data,
+                verb: "POST",
+                format: "text/xml"//application/x-www-form-urlencoded"
+            }
+        });
+    } else {
+        jQuery.ajax({
+            async: true,
+            success: callback,
+            error: callback,
+            type: "POST",
+            url: opencalais_url,
+            data: data,
+            dataType: "text/xml"
+        });
+    }
+};
\ No newline at end of file

Added: incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/rdfa.js
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/rdfa.js?rev=1143692&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/rdfa.js (added)
+++ incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/rdfa.js Thu Jul  7 07:38:24 2011
@@ -0,0 +1,65 @@
+// File:   rdfa.js
+// Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
+//
+
+new VIE2.Connector('rdfa');
+
+VIE2.connectors['rdfa'].analyze = function (object, options) {
+    var rdf = jQuery.rdf({namespaces: VIE2.namespaces});
+    
+    if (object === undefined) {
+        VIE2.log ("warn", "VIE2.Connector('" + this.id + "')#analyze()", "Given object is undefined!");
+        callback(rdf);
+    } else if (typeof object === 'object') {
+        var self = this;
+        //does only work on objects that have the 'typeof' attribute set!
+        if (object.attr('typeof')) {
+            //use rdfQuery to analyze the object
+            //RDF.add() is broken -> workaround!
+            jQuery(object).rdf().databank.triples().each(function () {
+                rdf.add(this);
+            });
+            
+            if (options && options.success) {
+                options.success.call(self, rdf);
+            } else {
+                VIE2.log("warn", "VIE2.Connector(" + self.id + ")", "No success callback given. How do you think this should gonna work?'");
+            }
+            
+        } else {
+            VIE2.log("info", "VIE2.Connector(" + this.id + ")#analyze()", "Object has no 'typeof' attribute! Trying to find children.");
+            
+            object.find('[typeof]').each(function(i, e) {
+                var rdfa = jQuery(e).rdf();
+                
+                //RDF.add() is broken -> workaround!
+                jQuery.each(rdfa.databank.triples(), function () {
+                    rdf.add(this);
+                });
+            });
+            if (options && options.success) {
+                options.success.call(self, rdf);
+            } else {
+                VIE2.log("warn", "VIE2.Connector(" + self.id + ")", "No success callback given. How do you think this should gonna work?'");
+            }
+        }
+    } else {
+        VIE2.log("error", "VIE2.Connector(" + this.id + ")#analyze()", "Expected object, found: '" + (typeof object) + "'");
+        if (options && options.error) {
+            options.error.call(this, "Expected element of type 'object', found: '" + (typeof object) + "'");
+        }
+    }
+};
+
+
+VIE2.connectors['rdfa'].serialize = function (triple, options) {
+    VIE2.log("info", "VIE2.Connector(" + this.id + ")#serialize()", "Start annotation of object with triple.");
+    if (options.elem) {
+        jQuery(options.elem).rdfa(triple, VIE2.namespaces);
+    } else {
+        VIE2.log("error", "VIE2.Connector(" + this.id + ")#serialize()", "No element specified! Please use 'options.elem' to do that!");
+    }    
+};
+
+//$('#main > p > a').rdfa('<> dc:date "2008-10-19"^^xsd:date .');
+//$('#main > p > a').removeRdfa({ property: "dc:creator" });

Added: incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/semantictweet.js
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/semantictweet.js?rev=1143692&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/semantictweet.js (added)
+++ incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/semantictweet.js Thu Jul  7 07:38:24 2011
@@ -0,0 +1,96 @@
+// File:   semantictweet.js
+// Author: Rene Kapusta
+//
+
+//The semantictweet connector needs to be initialized like this:
+//VIE2.getConnector('semantictweet').options({
+//    "proxy_url" : "../utils/proxy/proxy.php"
+//});
+new VIE2.Connector('semantictweet');
+
+VIE2.connectors['semantictweet'].query = function (uri, props, callback) {
+    if (uri instanceof jQuery.rdf.resource &&
+            uri.type === 'uri') {
+        this.query(uri.toString(), props, callback);
+        return;
+    }
+    if (!jQuery.isArray(props)) {
+        return this.query(uri, [props], callback);
+        return;
+    }
+    if ((typeof uri != 'string')) {
+        VIE2.log ("warn", "VIE2.Connector('" + this.id + "')", "Query does not support the given URI!");
+        callback.call(this, {});
+        return;
+    }
+    var uri = uri.replace(/^</, '').replace(/>$/, '');
+    
+    if (!uri.match(/^http\:\/\/semantictweet.com\/.*/)) {
+        VIE2.log ("warn", "VIE2.Connector('" + this.id + "')", "Query does not support the given URI!");
+        callback.call(this, {});
+        return;
+    }
+    
+    //var url = uri.replace('resource', 'data') + ".jrdf";
+    var url = uri;
+    var c = function (conn, u, ps) {
+        return function (data) {
+            //initialize the returning object
+            var ret = {};
+            
+            if (data && data.status === 200) {
+                try {
+                    //var json = jQuery.parseJSON(data.responseText);
+                    var rdf_xml = data.responseText;
+                    if (rdf_xml) {
+                        var rdfc = jQuery.rdf().load(rdf_xml);
+                        jQuery.each(VIE2.namespaces, function(k, v) {
+                            rdfc.prefix(k, v);
+                        });
+                        
+                        for (var i=0; i < ps.length; i++) {
+                            var prop = props[i].toString();
+                            ret[prop] = [];
+                            
+                            rdfc
+                            .where(jQuery.rdf.pattern('<' + u + '>', prop, '?object', { namespaces: VIE2.namespaces}))
+                            .each(function () {
+                                ret[prop].push(this.object);
+                            });
+                        }
+                    }
+                } catch (e) {
+                    VIE2.log ("warn", "VIE2.Connector('semantictweet')", "Could not query for uri '" + uri + "' because of the following parsing error: '" + e.message + "'!");
+                }
+            }
+            callback.call(this, ret);
+        };
+    }(this, uri, props);
+    
+    this.querySemantictweet(url, c);
+};
+
+VIE2.connectors['semantictweet'].querySemantictweet = function (url, callback) {
+    var proxy = this.options().proxy_url;
+    
+    if (proxy) {
+        jQuery.ajax({
+            async: true,
+            complete : callback,
+            type: "POST",
+            url: proxy,
+            data: {
+                proxy_url: url, 
+                content: "",
+                verb: "GET"
+            }
+        });
+    } else {
+        data = jQuery.ajax({
+            async: true,
+            complete : callback,
+            type: "GET",
+            'url': url
+        });
+    }
+};
\ No newline at end of file

Added: incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/stanbol.js
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/stanbol.js?rev=1143692&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/stanbol.js (added)
+++ incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/stanbol.js Thu Jul  7 07:38:24 2011
@@ -0,0 +1,333 @@
+// File:   stanbol.js
+// Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
+//
+
+// Ontology structure:
+//type == http://fise.iks-project.eu/ontology/TextAnnotation
+// => fise:start
+// => fise:end
+// => fise:selected-text
+// => fise:selection-context
+//type == http://fise.iks-project.eu/ontology/EntityAnnotation
+// => fise:entity-reference
+// => entity-label
+// => fise:entity-type
+//type == http://fise.iks-project.eu/ontology/Enhancement    
+// => fise:confidence <float>
+// => dc:type
+
+
+// The stanbol connector needs to be initialized like this:
+//$.VIE2.getConnector('stanbol').options({
+//    "proxy_url" : "../utils/proxy/proxy.php",
+//    "enhancer_url" : "http://stanbol.iksfordrupal.net:9000/engines/",
+//    "entityhub_url" : "http://stanbol.iksfordrupal.net:9000/entityhub/"
+//});
+
+new VIE2.Connector('stanbol', {
+    namespaces: {
+        semdesk : "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#",
+        owl : "http://www.w3.org/2002/07/owl#",
+        gml : "http://www.opengis.net/gml/_",
+        geonames : "http://www.geonames.org/ontology#",
+        fise : "http://fise.iks-project.eu/ontology/",
+        rick: "http://www.iks-project.eu/ontology/rick/model/"
+    }
+});
+
+VIE2.connectors['stanbol'].analyze = function (object, options) {
+    var rdf = jQuery.rdf();
+    
+    //rules to add backwards-relations to the triples
+    //this makes querying for entities a lot easier!
+    var rules = jQuery.rdf.ruleset()
+    .prefix('fise', 'http://fise.iks-project.eu/ontology/')
+    .prefix('dc', 'http://purl.org/dc/terms/')
+    .add(['?subject a <http://fise.iks-project.eu/ontology/EntityAnnotation>',
+          '?subject fise:entity-type ?type',
+          '?subject fise:confidence ?confidence',
+          '?subject fise:entity-reference ?entity',
+          '?subject dc:relation ?relation',
+          '?relation a <http://fise.iks-project.eu/ontology/TextAnnotation>',
+          '?relation fise:selected-text ?selected-text',
+          '?relation fise:selection-context ?selection-context',
+          '?relation fise:start ?start',
+          '?relation fise:end ?end'],
+          ['?entity a ?type',
+           '?entity fise:hasTextAnnotation ?relation',
+           '?entity fise:hasEntityAnnotation ?subject']);
+    
+    if (object === undefined) {
+        VIE2.log ("warn", "VIE2.Connector('" + this.id + "')", "Given object is undefined!");
+        if (options && options.error) {
+            options.error("Given object is undefined!");
+        }
+    } else if (typeof object === 'object') {
+        var self = this; 
+        //stanbol cannot deal with embedded HTML, so we remove that.
+        //--> hack!
+        var text = self.extractText(object);
+        //the AJAX callback function
+        var callback = function (rdfc) {
+            //adding all new found triples to the main rdfQuery object
+            rdfc.databank.triples().each(function () {
+                rdf.add(this);
+            });
+            //let's see if there are children to be enhanced.
+            VIE2.log("info", "VIE2.Connector(" + self.id + ")", "Start reasoning '" + (rdf.databank.triples().length) + "'");
+            //rdf.reason(rules);    
+            VIE2.log("info", "VIE2.Connector(" + self.id + ")", "End   reasoning '" + (rdf.databank.triples().length) + "'");
+            if (options && options.success) {
+                options.success.call(self, rdf);
+            } else {
+                VIE2.log("warn", "VIE2.Connector(" + self.id + ")", "No success callback given. How do you think this should gonna work?'");
+            }
+        };
+        this.enhance(text, callback);
+    } else {
+        VIE2.log("error", "VIE2.Connector(" + this.id + ")", "Expected element of type 'object', found: '" + (typeof object) + "'");
+        if (options && options.error) {
+            options.error.call(this, "Expected element of type 'object', found: '" + (typeof object) + "'");
+        }
+    }
+};
+
+VIE2.connectors['stanbol'].extractText = function (obj) {
+    if (obj.get(0) && 
+            obj.get(0).tagName && 
+            (obj.get(0).tagName == 'TEXTAREA' ||
+            obj.get(0).tagName == 'INPUT' && obj.attr('type', 'text'))) {
+        return obj.get(0).val();
+    }
+    else {
+        return obj
+            .text()    //get the text of element
+            .replace(/\s+/g, ' ') //collapse multiple whitespaces
+            .replace(/\0\b\n\r\f\t/g, '').trim(); // remove non-letter symbols
+    }
+};
+
+VIE2.connectors['stanbol'].enhance = function (text, callback) {
+    if (text.length === 0) {
+        VIE2.log("warn", "VIE2.Connector(" + this.id + ")", "Empty text.");
+        callback(jQuery.rdf());
+    }
+    else {
+        var that = this;
+        var c = function(data) {
+            if (data) {
+                if(typeof data == "string")
+                    data = JSON.parse(data);
+                var rdf;
+                try {
+                    rdf = jQuery.rdf().load(data, {});
+                } 
+                catch (e) {
+                    VIE2.log("error", "VIE2.Connector(" + that.id + ")", e);
+                    VIE2.log("error", "VIE2.Connector(" + that.id + ")", data);
+                    rdf = jQuery.rdf();
+                }
+                setTimeout(function(){
+                    callback(rdf)
+                }, 1);
+            }
+        };
+        this.queryEnhancer(text, c);
+    }
+};
+
+VIE2.connectors['stanbol'].queryEnhancer = function (text, callback) {
+
+    var proxy = this._options.proxy_url;
+    var enhancer_url = this._options.enhancer_url;
+    
+    if (!this._options.enhancer_url) {
+        VIE2.log("warn", "VIE2.connectors(" + this.id + ")", "No URL found for enhancer hub!");
+        throw "VIE2.connector.stanbol.enhancer_url is empty";
+        return;
+    }
+
+    if (proxy) {
+        jQuery.ajax({
+            async: true,
+            success: callback,
+            error: callback,
+            type: "POST",
+            url: proxy,
+            data: {
+                proxy_url: enhancer_url, 
+                content: text,
+                verb: "POST",
+                format: "application/rdf+json"
+            }
+        });
+    } else {
+        jQuery.ajax({
+            async: true,
+            success: callback,
+            error: callback,
+            type: "POST",
+            url: enhancer_url,
+            data: text,
+            dataType: "application/rdf+json",
+            contentType: "text/plain",
+            accepts: {"application/rdf+json": "application/rdf+json"}
+        });
+    }
+};
+
+
+//////////////////////
+
+VIE2.connectors['stanbol'].query = function (uri, props, callback) {
+    if (uri instanceof jQuery.rdf.resource &&
+            uri.type === 'uri') {
+        this.query(uri.toString().replace(/^</, '').replace(/>$/, ''), props, callback);
+        return;
+    }
+    if (!jQuery.isArray(props)) {
+        this.query(uri, [props], callback);
+        return;
+    }
+    if ((typeof uri !== 'string') || uri.match(/^<urn:.*/) || uri.match(/^_:.*/)) {
+        VIE2.log ("warn", "VIE2.Connector(" + this.id + ")", "Query does not support the given URI '" + uri + "'!");
+        callback.call(this, {});
+        return;
+    }
+    var uri = uri.replace(/^</, '').replace(/>$/, '');
+    //initialize the returning object
+    var ret = {};
+    var that = this;
+    
+    var c = function (data) {
+        if (data && data.status === 200) {
+            try {
+                var json = jQuery.parseJSON(data.responseText);
+                var rdfc = jQuery.rdf().load(json);
+
+                jQuery.each(VIE2.namespaces, function(k, v) {
+                    rdfc.prefix(k, v);
+                });
+                
+                for (var i=0; i < props.length; i++) {
+                    var prop = props[i].toString();
+                    ret[prop] = [];
+                    
+                    rdfc
+                    .where(jQuery.rdf.pattern('<' + uri + '>', prop, '?object', { namespaces: VIE2.namespaces}))
+                    .each(function () {
+                        ret[prop].push(this.object);
+                    });
+                }
+            } catch (e) {
+                VIE2.log ("warn", "VIE2.Connector(" + that.id + ")", "Could not query for uri '" + uri + "' because of the following parsing error: '" + e.message + "'!");
+            }
+            callback.call(that, ret);
+        } else {
+            //we need to send back something in order to clear the queue.
+            callback.call(that, {});
+        }
+    };
+    
+    this.queryEntityHub(uri, c);
+};
+
+VIE2.connectors['stanbol'].queryEntityHub = function (uri, callback) {
+    var proxy = this._options.proxy_url;
+    
+    if (!this._options.entityhub_url) {
+        VIE2.log("warn", "VIE2.connectors(" + this.id + ")", "No URL found for entity hub!");
+        throw "VIE2.connector.stanbol.entityhub_url is empty";
+        return;
+    }
+    
+    var entityhub_url = this._options.entityhub_url.replace(/\/$/, '');
+    
+    if (proxy) {
+        jQuery.ajax({
+            async: true,
+            type: "POST",
+            success: callback,
+            error: callback,
+            url: proxy,
+            dataType: "application/rdf+json",
+            data: {
+                proxy_url: entityhub_url + "/sites/entity?id=" + escape(uri), 
+                content: '',
+                verb: "GET",
+                format: "application/rdf+json"
+            }
+        });
+    } else {
+        jQuery.ajax({
+            async: true,
+            success: callback,
+            error: callback,
+            type: "GET",
+            url: entityhub_url + "/sites/entity?id=" + escape(uri),
+            data: '',
+            dataType: "application/rdf+json"
+        });
+    }
+};
+
+VIE2.connectors['stanbol'].findEntity = function (term, callback, limit, offset) {
+    // curl -X POST -d "name=Bishofsh&limit=10&offset=0" http://localhost:8080/entityhub/sites/find
+    var proxy = this._options.proxy_url;
+    
+    if (offset == null) {
+        offset = 0;
+    }
+    
+    if (limit == null) {
+        limit = 10;
+    }
+    
+    if (!this._options.entityhub_url) {
+        VIE2.log("warn", "VIE2.connectors(" + this.id + ")", "No URL found for entity hub!");
+        throw "VIE2.connector.stanbol.entityhub_url is empty";
+        return;
+    }
+    
+    var entityhub_url = this._options.entityhub_url.replace(/\/$/, '');
+    
+    function findResultTransform(findResponse){
+        console.info(findResponse);
+        return findResponse.results;
+    }
+    
+    if (proxy) {
+        // TODO test with proxy
+        jQuery.ajax({
+            async: true,
+            type: "POST",
+            success: callback,
+            error: callback,
+            url: proxy,
+            dataType: "application/rdf+json",
+            data: {
+                proxy_url: entityhub_url + "/sites/find", 
+                content: "name=" + term + "&limit=" + offset + "&limit=" + offset,
+                verb: "POST",
+                format: "application/rdf+json"
+            }
+        });
+    } else {
+        jQuery.ajax({
+            async: true,
+            success: function(response){
+                callback(findResultTransform(response))
+            },
+            error: callback,
+            type: "POST",
+            url: entityhub_url + "/sites/find",
+            data: "name=" + term + "&limit=" + offset + "&limit=" + offset,
+            dataType: "application/rdf+json"
+        });
+    }
+    
+};
+jQuery.ajaxSetup({
+    converters: {"text application/rdf+json": function(s){return JSON.parse(s);}}
+});
+

Added: incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/zemanta.js
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/zemanta.js?rev=1143692&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/zemanta.js (added)
+++ incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/connector/zemanta.js Thu Jul  7 07:38:24 2011
@@ -0,0 +1,130 @@
+new VIE2.Connector('zemanta', {
+    namespaces: {
+        z: "http://s.zemanta.com/ns#"
+    }
+});
+
+VIE2.connectors['zemanta'].analyze = function (object, options) {
+    var rdf = jQuery.rdf();
+    
+    var rules = jQuery.rdf.ruleset()
+    .prefix('z', 'http://s.zemanta.com/ns#')
+    .add([], []);
+    
+    if (object === undefined) {
+        VIE2.log ("warn", "VIE2.Connector('" + this.id + "')", "Given object is undefined!");
+        if (options && options.error) {
+            options.error("Given object is undefined!");
+        }
+    } else if (typeof object === 'object') {
+        var self = this; 
+        //zemanta cannot deal with embedded HTML, so we remove that.
+        //--> hack!
+        var text = self.extractText(object);
+        //the AJAX callback function
+        var callback = function (rdfc) {
+            //adding all new found triples to the main rdfQuery object
+            rdfc.databank.triples().each(function () {
+                rdf.add(this);
+            });
+            //let's see if there are children to be enhanced.
+            VIE2.log("info", "VIE2.Connector(" + self.id + ")", "Start reasoning '" + (rdf.databank.triples().length) + "'");
+            rdf.reason(rules);    
+            VIE2.log("info", "VIE2.Connector(" + self.id + ")", "End   reasoning '" + (rdf.databank.triples().length) + "'");
+            if (options && options.success) {
+                options.success.call(self, rdf);
+            } else {
+                VIE2.log("warn", "VIE2.Connector(" + self.id + ")", "No success callback given. How do you think this should gonna work?'");
+            }
+        };
+        this.enhance(text, callback);
+    } else {
+        VIE2.log("error", "VIE2.Connector(" + this.id + ")", "Expected element of type 'object', found: '" + (typeof object) + "'");
+        if (options && options.error) {
+            options.error.call(this, "Expected element of type 'object', found: '" + (typeof object) + "'");
+        }
+    }
+};
+
+VIE2.connectors['zemanta'].extractText = function (obj) {
+    if (obj.get(0) && 
+            obj.get(0).tagName && 
+            (obj.get(0).tagName == 'TEXTAREA' ||
+            obj.get(0).tagName == 'INPUT' && obj.attr('type', 'text'))) {
+        return obj.get(0).val();
+    }
+    else {
+        return obj
+            .text()    //get the text of element
+            .replace(/\s+/g, ' ') //collapse multiple whitespaces
+            .replace(/\0\b\n\r\f\t/g, '').trim(); // remove non-letter symbols
+    }
+};
+
+VIE2.connectors['zemanta'].enhance = function (text, callback) {
+    if (text.length === 0) {
+        VIE2.log("warn", "VIE2.Connector(" + this.id + ")", "Empty text.");
+        callback(jQuery.rdf());
+    }
+    else {
+        var c = function(data) {
+            if (data && data.status === 200) {
+                try {
+                    var responseData = data.responseText
+                    .replace(/<z:signature>.*?<\/z:signature>/, '');
+                    var rdf = jQuery.rdf().load(responseData, {});
+                    callback(rdf);
+                } 
+                catch (e) {
+                    VIE2.log("error", "VIE2.Connector(" + this.id + ")", "Could not connect to zemanta enhancer.");
+                    VIE2.log("error", "VIE2.Connector(" + this.id + ")", data);
+                    callback(jQuery.rdf());
+                }
+            }
+        };
+        this.queryZemanta(this.prepareZemantaData(text), c);
+    }
+};
+
+VIE2.connectors['zemanta'].prepareZemantaData = function (text) {
+    return {
+        method: 'zemanta.suggest_markup',
+        format: 'rdfxml',
+        api_key: this._options.zemanta_api_key,
+        text: text,
+        return_rdf_links: 1
+        // for more options check http://developer.zemanta.com/docs/suggest/
+    };
+};
+
+VIE2.connectors['zemanta'].queryZemanta = function (data, callback) {
+
+    var proxy = this._options.proxy_url;
+    var zemanta_url = this._options.zemanta_url;
+
+    if (proxy) {
+        jQuery.ajax({
+            async: true,
+            success: callback,
+            error: callback,
+            type: "POST",
+            url: proxy,
+            data: {
+                proxy_url: zemanta_url, 
+                content: data,
+                verb: "POST",
+                format: "application/rdf+json"
+            }
+        });
+    } else {
+        jQuery.ajax({
+            async: true,
+            success: callback,
+            error: callback,
+            type: "POST",
+            url: zemanta_url,
+            data: data,
+            dataType: "application/rdf+json"
+        });
+    }
+};
\ No newline at end of file

Added: incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/mapping/organization.js
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/mapping/organization.js?rev=1143692&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/mapping/organization.js (added)
+++ incubator/stanbol/trunk/commons/web/webvie/src/main/resources/org/apache/stanbol/enhancer/webvie/static/lib/vie2/mapping/organization.js Thu Jul  7 07:38:24 2011
@@ -0,0 +1,18 @@
+// File:   organization.js
+// Author: <a href="mailto:sebastian.germesin@dfki.de">Sebastian Germesin</a>
+//
+
+new VIE2.Mapping(
+    'organization',  //the id of the mapping
+    ['dbpedia:Organisation', 'google:Organization'],  //a list of all types that fall into this category
+    ['rdfs:label', 'dbprop:companyName', 'foaf:page', 'foaf:depiction', 'google:flickr'], //a list of default properties
+    { //optional options
+        namespaces: { //the used namespaces, these can be given here, or placed directly into the HTML document's xmlns attribute.
+            'google': 'http://rdf.data-vocabulary.org/#',
+            'rdfs'  : 'http://www.w3.org/2000/01/rdf-schema#',
+            'dbprop': 'http://dbpedia.org/property/',
+            'foaf'  : 'http://xmlns.com/foaf/0.1/',
+            'dbonto' : 'http://dbpedia.org/ontology/'
+        }
+    }
+);
\ No newline at end of file