Transports are selected on a cascading basis determined by browser * capability and other checks. The order of preference is: *
See each transport's commentary/documentation for details.
* @return {Object}
* @member gadgets.rpc
*/
function getTransport() {
return typeof window.postMessage === 'function' ? OpenAjax.gadgets.rpctx.wpm :
typeof window.postMessage === 'object' ? OpenAjax.gadgets.rpctx.wpm :
window.ActiveXObject ? OpenAjax.gadgets.rpctx.nix :
navigator.userAgent.indexOf('WebKit') > 0 ? OpenAjax.gadgets.rpctx.rmr :
navigator.product === 'Gecko' ? OpenAjax.gadgets.rpctx.frameElement :
OpenAjax.gadgets.rpctx.ifpc;
}
/**
* Function passed to, and called by, a transport indicating it's ready to
* send and receive messages.
*/
function transportReady(receiverId, readySuccess) {
var tx = transport;
if (!readySuccess) {
tx = fallbackTransport;
}
receiverTx[receiverId] = tx;
// If there are any early-queued messages, send them now directly through
// the needed transport.
var earlyQueue = earlyRpcQueue[receiverId] || [];
for (var i = 0; i < earlyQueue.length; ++i) {
var rpc = earlyQueue[i];
// There was no auth/rpc token set before, so set it now.
rpc.t = getAuthToken(receiverId);
tx.call(receiverId, rpc.f, rpc);
}
// Clear the queue so it won't be sent again.
earlyRpcQueue[receiverId] = [];
}
// Track when this main page is closed or navigated to a different location
// ("unload" event).
// NOTE: The use of the "unload" handler here and for the relay iframe
// prevents the use of the in-memory page cache in modern browsers.
// See: https://developer.mozilla.org/en/using_firefox_1.5_caching
// See: http://webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/
var mainPageUnloading = false,
hookedUnload = false;
function hookMainPageUnload() {
if ( hookedUnload ) {
return;
}
function onunload() {
mainPageUnloading = true;
}
OpenAjax.gadgets.util.attachBrowserEvent(window, 'unload', onunload, false);
hookedUnload = true;
}
function relayOnload(targetId, sourceId, token, data, relayWindow) {
// Validate auth token.
if (!authToken[sourceId] || authToken[sourceId] !== token) {
OpenAjax.gadgets.error("Invalid auth token. " + authToken[sourceId] + " vs " + token);
securityCallback(sourceId, FORGED_MSG);
}
relayWindow.onunload = function() {
if (setup[sourceId] && !mainPageUnloading) {
securityCallback(sourceId, FRAME_PHISH);
OpenAjax.gadgets.rpc.removeReceiver(sourceId);
}
};
hookMainPageUnload();
data = OpenAjax.gadgets.json.parse(decodeURIComponent(data));
transport.relayOnload(sourceId, data);
}
/**
* Helper function to process an RPC request
* @param {Object} rpc RPC request object
* @private
*/
function process(rpc) {
//
// RPC object contents:
// s: Service Name
// f: From
// c: The callback ID or 0 if none.
// a: The arguments for this RPC call.
// t: The authentication token.
//
if (rpc && typeof rpc.s === 'string' && typeof rpc.f === 'string' &&
rpc.a instanceof Array) {
// Validate auth token.
if (authToken[rpc.f]) {
// We don't do type coercion here because all entries in the authToken
// object are strings, as are all url params. See setupReceiver(...).
if (authToken[rpc.f] !== rpc.t) {
OpenAjax.gadgets.error("Invalid auth token. " + authToken[rpc.f] + " vs " + rpc.t);
securityCallback(rpc.f, FORGED_MSG);
}
}
if (rpc.s === ACK) {
// Acknowledgement API, used to indicate a receiver is ready.
window.setTimeout(function() { transportReady(rpc.f, true); }, 0);
return;
}
// If there is a callback for this service, attach a callback function
// to the rpc context object for asynchronous rpc services.
//
// Synchronous rpc request handlers should simply ignore it and return a
// value as usual.
// Asynchronous rpc request handlers, on the other hand, should pass its
// result to this callback function and not return a value on exit.
//
// For example, the following rpc handler passes the first parameter back
// to its rpc client with a one-second delay.
//
// function asyncRpcHandler(param) {
// var me = this;
// setTimeout(function() {
// me.callback(param);
// }, 1000);
// }
if (rpc.c) {
rpc.callback = function(result) {
OpenAjax.gadgets.rpc.call(rpc.f, CALLBACK_NAME, null, rpc.c, result);
};
}
// Call the requested RPC service.
var result = (services[rpc.s] ||
services[DEFAULT_NAME]).apply(rpc, rpc.a);
// If the rpc request handler returns a value, immediately pass it back
// to the callback. Otherwise, do nothing, assuming that the rpc handler
// will make an asynchronous call later.
if (rpc.c && typeof result !== 'undefined') {
OpenAjax.gadgets.rpc.call(rpc.f, CALLBACK_NAME, null, rpc.c, result);
}
}
}
/**
* Helper method returning a canonicalized protocol://host[:port] for
* a given input URL, provided as a string. Used to compute convenient
* relay URLs and to determine whether a call is coming from the same
* domain as its receiver (bypassing the try/catch capability detection
* flow, thereby obviating Firebug and other tools reporting an exception).
*
* @param {string} url Base URL to canonicalize.
* @memberOf gadgets.rpc
*/
function getOrigin(url) {
if (!url) {
return "";
}
url = url.toLowerCase();
if (url.indexOf("//") == 0) {
url = window.location.protocol + url;
}
if (url.indexOf("://") == -1) {
// Assumed to be schemaless. Default to current protocol.
url = window.location.protocol + "//" + url;
}
// At this point we guarantee that "://" is in the URL and defines
// current protocol. Skip past this to search for host:port.
var host = url.substring(url.indexOf("://") + 3);
// Find the first slash char, delimiting the host:port.
var slashPos = host.indexOf("/");
if (slashPos != -1) {
host = host.substring(0, slashPos);
}
var protocol = url.substring(0, url.indexOf("://"));
// Use port only if it's not default for the protocol.
var portStr = "";
var portPos = host.indexOf(":");
if (portPos != -1) {
var port = host.substring(portPos + 1);
host = host.substring(0, portPos);
if ((protocol === "http" && port !== "80") ||
(protocol === "https" && port !== "443")) {
portStr = ":" + port;
}
}
// Return This method replaces setRelayUrl(...) and setAuthToken(...)
*
* Simplified instructions - highly recommended:
* All parent/child communication initializes automatically from here.
* Naturally, both sides need to include the library.
* Detailed container/parent instructions:
* [Optional]. Strictly speaking, you may omit rpctoken and parent. This
* practice earns little but is occasionally useful for testing.
* If you omit parent, you MUST pass your container URL as the 2nd
* parameter to this method.
* Detailed gadget/child IFRAME instructions:
*
*
*
*
*
*
*
*
*
* @member gadgets.rpc
* @param {string} targetId
* @param {string=} opt_receiverurl
* @param {string=} opt_authtoken
* @param {boolean=} opt_forcesecure
*/
function setupReceiver(targetId, opt_receiverurl, opt_authtoken, opt_forcesecure) {
if (targetId === '..') {
// Gadget/IFRAME to container.
var rpctoken = opt_authtoken || params.rpctoken || params.ifpctok || "";
if (window['__isgadget'] === true) {
setupContainerGadgetContext(rpctoken, opt_forcesecure);
} else {
setupContainerGenericIframe(rpctoken, opt_receiverurl, opt_forcesecure);
}
} else {
// Container to child.
setupChildIframe(targetId, opt_receiverurl, opt_authtoken, opt_forcesecure);
}
}
return /** @scope gadgets.rpc */ {
config: function(config) {
if (typeof config.securityCallback === 'function') {
securityCallback = config.securityCallback;
}
},
/**
* Registers an RPC service.
* @param {string} serviceName Service name to register.
* @param {function(Object,Object)} handler Service handler.
*
* @member gadgets.rpc
*/
register: function(serviceName, handler) {
if (serviceName === CALLBACK_NAME || serviceName === ACK) {
throw new Error("Cannot overwrite callback/ack service");
}
if (serviceName === DEFAULT_NAME) {
throw new Error("Cannot overwrite default service:"
+ " use registerDefault");
}
services[serviceName] = handler;
},
/**
* Unregisters an RPC service.
* @param {string} serviceName Service name to unregister.
*
* @member gadgets.rpc
*/
unregister: function(serviceName) {
if (serviceName === CALLBACK_NAME || serviceName === ACK) {
throw new Error("Cannot delete callback/ack service");
}
if (serviceName === DEFAULT_NAME) {
throw new Error("Cannot delete default service:"
+ " use unregisterDefault");
}
delete services[serviceName];
},
/**
* Registers a default service handler to processes all unknown
* RPC calls which raise an exception by default.
* @param {function(Object,Object)} handler Service handler.
*
* @member gadgets.rpc
*/
registerDefault: function(handler) {
services[DEFAULT_NAME] = handler;
},
/**
* Unregisters the default service handler. Future unknown RPC
* calls will fail silently.
*
* @member gadgets.rpc
*/
unregisterDefault: function() {
delete services[DEFAULT_NAME];
},
/**
* Forces all subsequent calls to be made by a transport
* method that allows the caller to verify the message receiver
* (by way of the parent parameter, through getRelayUrl(...)).
* At present this means IFPC or WPM.
* @member gadgets.rpc
*/
forceParentVerifiable: function() {
if (!transport.isParentVerifiable()) {
transport = OpenAjax.gadgets.rpctx.ifpc;
}
},
/**
* Calls an RPC service.
* @param {string} targetId Module Id of the RPC service provider.
* Empty if calling the parent container.
* @param {string} serviceName Service name to call.
* @param {function()|null} callback Callback function (if any) to process
* the return value of the RPC request.
* @param {*} var_args Parameters for the RPC request.
*
* @member gadgets.rpc
*/
call: function(targetId, serviceName, callback, var_args) {
targetId = targetId || '..';
// Default to the container calling.
var from = '..';
if (targetId === '..') {
from = rpcId;
}
++callId;
if (callback) {
callbacks[callId] = callback;
}
var rpc = {
s: serviceName,
f: from,
c: callback ? callId : 0,
a: Array.prototype.slice.call(arguments, 3),
t: authToken[targetId],
l: useLegacyProtocol[targetId]
};
if (targetId !== '..' && !document.getElementById(targetId)) {
// The target has been removed from the DOM. Don't even try.
OpenAjax.gadgets.log("WARNING: attempted send to nonexistent frame: " + targetId);
return;
}
// If target is on the same domain, call method directly
if (callSameDomain(targetId, rpc)) {
return;
}
// Attempt to make call via a cross-domain transport.
// Retrieve the transport for the given target - if one
// target is misconfigured, it won't affect the others.
var channel = receiverTx[targetId];
if (!channel) {
// Not set up yet. Enqueue the rpc for such time as it is.
if (!earlyRpcQueue[targetId]) {
earlyRpcQueue[targetId] = [ rpc ];
} else {
earlyRpcQueue[targetId].push(rpc);
}
return;
}
// If we are told to use the legacy format, then we must
// default to IFPC.
if (useLegacyProtocol[targetId]) {
channel = OpenAjax.gadgets.rpctx.ifpc;
}
if (channel.call(targetId, from, rpc) === false) {
// Fall back to IFPC. This behavior may be removed as IFPC is as well.
receiverTx[targetId] = fallbackTransport;
transport.call(targetId, from, rpc);
}
},
/**
* Gets the relay URL of a target frame.
* @param {string} targetId Name of the target frame.
* @return {string|undefined} Relay URL of the target frame.
*
* @member gadgets.rpc
*/
getRelayUrl: function(targetId) {
var url = relayUrl[targetId];
// Some RPC methods (wpm, for one) are unhappy with schemeless URLs.
if (url && url.substring(0,1) === '/') {
if (url.substring(1,2) === '/') { // starts with '//'
url = document.location.protocol + url;
} else { // relative URL, starts with '/'
url = document.location.protocol + '//' + document.location.host + url;
}
}
return url;
},
setRelayUrl: setRelayUrl,
setAuthToken: setAuthToken,
setupReceiver: setupReceiver,
getAuthToken: getAuthToken,
// Note: Does not delete iframe
removeReceiver: function(receiverId) {
delete relayUrl[receiverId];
delete useLegacyProtocol[receiverId];
delete authToken[receiverId];
delete setup[receiverId];
delete sameDomain[receiverId];
delete receiverTx[receiverId];
},
/**
* Gets the RPC relay mechanism.
* @return {string} RPC relay mechanism. See above for
* a list of supported types.
*
* @member gadgets.rpc
*/
getRelayChannel: function() {
return transport.getCode();
},
/**
* Receives and processes an RPC request. (Not to be used directly.)
* Only used by IFPC.
* @param {Array.
* Please note that the status of the action is transported only with
* callbacks, even if you use synchronous mode. If you need to check the status,
* you must use callback functions.
* @param {Object} callback the callback funtion in the format of Function(Object resource, int statusCode, Object[] params)
.
* Must not be null
* Callbackparameters
* resource
- resource object or id string
* of the related resource.
* May be null
in case the action does not relate
* to a particular resource. In case multiple resources are involved in the
* action, the DeferredOperation interface may be used to obtain the resource
* objects or string id
s of those resources.
* statusCode
- the overall HTTP status
* code of the action (the highest status code of the involved operations).
* params
- the parameters
* passed into the callback
* @param {Object[]} parameters optional array of parameters to be
* passed on to the callback function. May be null
* @return {com.ibm.mashups.enabler.Deferred} the deferred object
*/
setFinishedCallback: function(callback, parameters) {
},
/**
* Executes the deferred action and invokes the callback functions set
* with the deferred object.
* @param {Boolean} sync indicates if the deferred action is executed
* synchronously or asynchronously. Optional, defaults to true.
* @return {Object} resource if called asynchronously, the return value is
* undefined
, otherwise a resource object or id string of the
* related resource is returned.
In order to obtain information on
* the resource as well as on the status code of the operation, you
* must use the callback functions of the deferred object.
*/
start: function(sync) {
return {};
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.DeferredImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.DeferredImpl"] = true;
dojo.provide("com.ibm.mm.enabler.DeferredImpl");
// base
dojo.declare("com.ibm.mm.enabler.DeferredImpl", [com.ibm.mashups.enabler.Deferred], {
_chainedDeferred: null,
_sync: false,
_previous: null,
// If you mixin the DeferredImpl into your class, you may use a different
// set of parameters for the constructor, but then you do not have access
// to the parameters 'context', 'startfn', as well as 'params' and thus,
// you need to overwrite the start function, which accesses those parameters.
// If you want to use the start function defined in DeferredImpl, you need
// to make sure, the parameters 'context', 'startfn', as well as 'params'
// are set in the constructor of DeferredImpl.
constructor: function(context, startfn, params){
// context for start function
this.context = context;
// start function
this.startfn = startfn;
// parameters to pass to start function
this.params = params;
},
// deprecated
addErrorCallback: function(callback, parameters){
dojo.deprecated("com.ibm.mashups.enabler.Deferred.addErrorCallback()", "use com.ibm.mashups.enabler.Deferred.setFinishedCallback() instead");
this.errorCallback = callback;
this.errorCallbackParameters = parameters;
},
// deprecated
addFinishedCallback: function(callback, parameters){
dojo.deprecated("com.ibm.mashups.enabler.Deferred.addFinishedCallback()", "use com.ibm.mashups.enabler.Deferred.setFinishedCallback() instead");
this.finishedCallback = callback;
this.finishedCallbackParameters = parameters;
// forward compatibility
//this.setFinishedCallback(callback, parameters);
},
setFinishedCallback: function(callback, parameters){
this.finishedCallback2 = callback;
this.finishedCallbackParameters2 = parameters;
return this;
},
start: function(sync, previous){
this._sync = (sync || typeof(sync) == 'undefined');
var ret = null;
if (dojo.isFunction(this.startfn)) {
ret = dojo.hitch(this.context || null, this.startfn)(this, this._sync, this.params, previous || null);
}
return ret;
},
getFinishedCallback: function(){
return this.finishedCallback2;
},
getFinishedCallbackParameters: function(){
return this.finishedCallbackParameters2;
},
setChainedDeferred: function(deferred){
this._chainedDeferred = deferred;
},
getChainedDeferred: function(){
return this._chainedDeferred;
},
getPrevious: function(){
return this._previous;
},
_setPreviousDeferred: function(deferred, result, status){
this._previous = {
deferred: deferred,
result: result,
status: status
};
},
removeChainedDeferred: function(){
this._chainedDeferred = null;
},
/**
* call this at the end of whatever you are doing
*
* @param {Object} result
* @param {Object} status
*/
finish: function(result, status){
try {
if (dojo.isFunction(this.getFinishedCallback())) {
// call callback
dojo.partial(this.getFinishedCallback())(result, status, this.getFinishedCallbackParameters());
}
else {
if (dojo.isFunction(this.finishedCallback) && ("" + status).indexOf('2') === 0) {
// backwards compatibility
dojo.partial(this.finishedCallback)(result, this.finishedCallbackParameters);
}
else {
if (dojo.isFunction(this.errorCallback) && status >= 400) {
dojo.partial(this.errorCallback)(result, this.errorCallbackParameters);
}
}
}
}
catch (e) {
}
if (this._chainedDeferred) {
this._chainedDeferred._setPreviousDeferred(this, result, status);
this._chainedDeferred.start(this._sync);
}
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Deferred"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Deferred"] = true;
dojo.provide( "com.ibm.mashups.enabler.Deferred");
dojo.require( "com.ibm.mm.enabler.DeferredImpl" );
}
if(!dojo._hasResource["com.ibm.mashups.enabler.context.LocalizedContext_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.context.LocalizedContext_API"] = true;
dojo.provide("com.ibm.mashups.enabler.context.LocalizedContext_API");
dojo.provide("com.ibm.mashups.enabler.context.LocalizedContext");
/**
* LocalizedContext to get the preferred locale, the default locale, as well as
* titles and descriptions of localized resources within this localized context.
*
* @ibm-api
* @ibm-module Base2
*/
dojo.declare("com.ibm.mashups.enabler.context.LocalizedContext", null, {
/**
* Returns the preferred locale of this LocalizedContext.
* @ibm-api
* @type {String}
* @return the preferred locale
*/
getPreferredLocale : function() {
},
/**
* Returns the default locale of this LocalizedContext.
* @ibm-api
* @type {String}
* @return the default locale
*/
getDefaultLocale : function() {
},
/**
* Returns the locale of the localized resource, which matches best the locale set with
* the browser.
* @ibm-api
* @param {com.ibm.mashups.enabler.Localized} localized resource implementing the Localized interface; must not be null
* @type {String}
* @return the preferred locale. Returns null
if no locale is available.
*/
getLocale : function(localized) {
},
/**
* Returns the display locale set with the browser matching the specified locale.
* @ibm-api
* @param {String} locale; mandatory, must not be null
* @type {String}
* @return the display locale. Returns null
if no display locale is available.
*/
getDisplayLocale : function(locale) {
},
/**
* Returns the title of the localized resource in the locale, which matches best the locale
* set with the browser.
* @ibm-api
* @param {com.ibm.mashups.enabler.Localized} localized resource implementing the Localized interface; must not be null
* @type {String}
* @return the title string in the preferred locale. Returns null
if no locale is available.
*/
getTitle : function(localized) {
},
/**
* Returns the description of the localized resource in the locale, which matches best the
* locale set with the browser.
* @ibm-api
* @param {com.ibm.mashups.enabler.Localized} localized resource implementing the Localized interface; must not be null
* @type {String}
* @return the description string in the preferred locale. Returns null
if no locale is available.
*/
getDescription : function(localized) {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.xml.XPath_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.xml.XPath_API"] = true;
dojo.provide("com.ibm.mashups.enabler.xml.XPath_API");
dojo.provide("com.ibm.mashups.enabler.xml.XPath");
/**
* Interface provides functions to select nodes by evaluating XPATH expression
*
* @ibm-api
* @ibm-module Base2
*/
dojo.declare("com.ibm.mashups.enabler.xml.XPath", null, {
/**
* This interface returns a list of XMLNodes upon XPATH evaluation.
* @param {String} xpathExpr the xpath expression (i.e. /atom:content). Must not be NULL.
* @param {XMLDocument} doc the XML document. Must not be NULL.
* @param {JSON} namespaces the namespaces used as part of the xpath expression. The json must be of the format {"prefix": "URL", ... }; must not be NULL.
* Example: { "atom" : "http://www.w3.org/2005/Atom", "app" : "http://www.w3.org/2007/app" };
*
* @return {XMLNodeList} select nodes from XML document with xpath; may be null
.
*/
evaluateXPath : function(xpathExpr, doc, namespaces) {
},
/**
* This interface returns a single Entry upon XPATH evaluation or null if the entry is not present.
*
* @param {String} xpathExpr the xpath expression (i.e. /atom:content). Must not be NULL.
* @param {XMLDocument} doc the XML document. Must not be NULL.
* @param {JSON} namespaces the namespaces used as part of the xpath expression. The json must be of the format {"prefix": "URL", ... }; must not be NULL.
* Example: { "atom" : "http://www.w3.org/2005/Atom", "app" : "http://www.w3.org/2007/app" };
*
* @return {Object}
*/
evaluateEntry: function(xpathExpr, doc, namespaces) {
},
/**
* This interface returns a boolean upon XPATH evaluation. Returns false if the result is not valid (e.g. node does not exist, etc.).
*
* @param {String} xpathExpr the xpath expression (i.e. /atom:content). Must not be NULL.
* @param {XMLDocument} doc the XML document. Must not be NULL.
* @param {JSON} namespaces the namespaces used as part of the xpath expression. The json must be of the format {"prefix": "URL", ... }; must not be NULL.
* Example: { "atom" : "http://www.w3.org/2005/Atom", "app" : "http://www.w3.org/2007/app" };
*
* @return {Boolean}
*/
evaluateBoolean: function(xpathExpr, doc, namespaces) {
},
/**
* This interface returns a String upon XPATH evaluation. Returns an empty String if the result is not valid (e.g. node does not exist, etc.).
* If you want to check for existence of an attribute/element use either evaluateBoolean (which returns false if the element is not present) or evaluateEntry (which returns null if the element is not present).
*
* @param {String} xpathExpr the xpath expression (i.e. /atom:content). Must not be NULL.
* @param {XMLDocument} doc the XML document. Must not be NULL.
* @param {JSON} namespaces the namespaces used as part of the xpath expression. The json must be of the format {"prefix": "URL", ... }; must not be NULL.
* Example: { "atom" : "http://www.w3.org/2005/Atom", "app" : "http://www.w3.org/2007/app" };
*
* @return {String}
*/
evaluateString: function(xpathExpr, doc, namespaces) {
},
/**
* This interface returns a Number upon XPATH evaluation. Returns zero (0) if the result is not valid (e.g. node does not exist, etc.).
* If you want to check for existence of an attribute/element use either evaluateBoolean (which returns false if the element is not present) or evaluateEntry (which returns null if the element is not present).
*
* @param {String} xpathExpr the xpath expression (i.e. /atom:content). Must not be NULL.
* @param {XMLDocument} doc the XML document. Must not be NULL.
* @param {JSON} namespaces the namespaces used as part of the xpath expression. The json must be of the format {"prefix": "URL", ... }; must not be NULL.
* Example: { "atom" : "http://www.w3.org/2005/Atom", "app" : "http://www.w3.org/2007/app" };
*
* @return {Number}
*/
evaluateNumber: function(xpathExpr, doc, namespaces) {
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.utils.Dom"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.utils.Dom"] = true;
dojo.provide("com.ibm.mm.enabler.utils.Dom");
com.ibm.mm.enabler.utils.Dom = {
getAttributeWithNS: function(element, attName, localAttName, nsUri) {
if (!element) {
return null;
}
if (!attName) {
return null;
}
if (!localAttName) {
return null;
}
if (!nsUri) {
return null;
}
var value = null;
if (dojo.isIE) {
// IE with no namepsace
value = element.getAttribute(attName);
if (value === null || value == "") {
// IE with namepsace
var attributes = element.attributes;
for (var i = attributes.length; i > 0; i--) {
if (attributes[i - 1].baseName == localAttName && attributes[i - 1].namespaceURI == nsUri) {
value = attributes[i - 1].value;
break;
}
}
}
}
else {
// Safari & Firefox
value = element.getAttributeNS(nsUri, localAttName);
}
return value;
},
setAttributeWithNS: function(dom, element, attName, localAttName, nsUri, value) {
if (!dojo.isObject(element)) {
throw new Error("element must be a DOMNode");
}
if (dojo.isIE) {
var attr = dom.createNode(2, attName, nsUri);
// set value
if (value === null || value === undefined) {
value = "";
}
attr.nodeValue = value;
// attach to element
element.setAttributeNode(attr);
}
else {
element.setAttributeNS(nsUri, attName, value);
}
},
textContent: function(node, text) {
if (!node) {
return "";
}
if (arguments.length > 1) {
var doc = node.ownerDocument;
var aNode = doc.createTextNode(text || ""); // IE8 createTextNode fails when text == null
com.ibm.mm.enabler.utils.Dom.replaceChildren(node, aNode);
return;
}
else {
var tc = dojox.xml.parser.textContent(node);
if (tc) {
return tc;
}
return dojo.map(node.childNodes || [], function(node) {
return (node.nodeType > 0 && node.nodeType < 4) ? node.nodeValue : "";
}).join("");
}
},
createElement: function(dom, name, ns) {
var newElem;
if (dojo.isIE) {
if (ns) {
newElem = dom.createNode(1, name, ns);
}
else {
newElem = dom.createElement(name);
}
}
else {
newElem = dom.createElementNS(ns, name);
}
return newElem;
},
destroyNode: function(node) {
//avoid pseudo leaks since our webpage are open for long long time!
var garbageBin = dojo.byId('IELeakGarbageBin');
if (!garbageBin) {
garbageBin = dojo.create("div",{
id: "IELeakGarbageBin",
style: {display: "none"}
}, dojo.body());
}
// move the element to the garbage bin
dojo.place(node,garbageBin);
dojo.attr(garbageBin,'innerHTML','');
if (node.nodeType != 3) { // ingore TEXT_NODE
if (dojo.isIE) {
dojo.attr(node,'outerHTML',''); //prevent ugly IE mem leak
}
}
},
createDocument: function(/*string?*/str, /*string?*/ mimetype) {
return dojox.xml.parser.parse(str, mimetype);
},
replaceChildren: function(/*Element*/node, /*Node || array*/ newChildren) {
return dojox.xml.parser.replaceChildren(node, newChildren);
},
innerXML: function(node) {
return node ? dojox.xml.parser.innerXML(node) : null;
},
removeChildren: function(node) {
return dojox.xml.parser.removeChildren(node);
},
copyChildren: function(/*Element*/srcNode, /*Element*/ destNode, /*boolean?*/ trim) {
var clonedNode = srcNode.cloneNode(true);
return this.moveChildren(clonedNode, destNode, trim); // number
},
moveChildren: function(srcNode, destNode, trim) {
var count = 0;
if (trim) {
while (srcNode.hasChildNodes() &&
srcNode.firstChild.nodeType == 3) {
srcNode.removeChild(srcNode.firstChild);
}
while (srcNode.hasChildNodes() &&
srcNode.lastChild.nodeType == 3) {
srcNode.removeChild(srcNode.lastChild);
}
}
while (srcNode.hasChildNodes()) {
destNode.appendChild(srcNode.firstChild);
count++;
}
return count; // number
},
/**
* Get's the local name of the node passed in as parameter
*
* @param {Node} node the node of which to get the local name
* @return {String} the local name of the node or null if the node doesn't have a local name
*/
getLocalName: function(node) {
if (!node) {
return null;
}
switch (node.nodeType) {
case 3:
return "#text";
case 1:
return node.localName || com.ibm.mm.enabler.utils.Dom.removeNodeNS(node.nodeName);
}
return null;
},
/**
* Get's the namespace prefix from the given nodename or null if there is no NS Prefix.
*
* @param {String} nodeName The name of the node
* @return {String} the namespace prefix of the node name or null if there is none.
*/
getNodeNSPrefix: function(nodeName) {
var tN = '' + nodeName;
var hasColon = tN.indexOf(':');
return (hasColon != -1) ? tN.substring(0, hasColon) : null;
},
/**
* Removes the namespace from a node name.
* This is a copy of com.ibm.mashups.widget.dijit.url.util.Dom.removeNodeNs and should
* replace this method in case, this one here becomes public.
*
* @private
* @param {String} nodeName the node name with or without namespace
* @return {String} the node name without namespace
* @see com.ibm.mashups.widget.dijit.url.util.Dom#removeNodeNs(String)
*/
removeNodeNS: function(nodeName) {
var tN = '' + nodeName;
var hasColon = tN.indexOf(':');
return (hasColon != -1) ? tN.substring(1 + hasColon) : nodeName;
},
/**
* Looks up the namespace for the specified prefix
* @param {Node} node the node for which to lookup the namespace
* @param {String} prefix the prefix to lookup the namespace for.
* @return {String} the namespace for the specified prefix or null if the namespace for the prefix wasn't found.
*/
lookupNamespaceURI: function(node, prefix) {
// If we are not on IE, we have native support for this
if (!dojo.isIE) {
return node.lookupNamespaceURI(prefix);
}
// seems we are on IE, so let's do some magic here
var lastNode = node;
// while node != null and node isn't a document
while (lastNode && lastNode.nodeType != 9) {
var attrValue = lastNode.getAttribute("xmlns:" + prefix);
if (attrValue) {
return attrValue;
}
lastNode = lastNode.parentNode;
}
return null;
}
};
}
if(!dojo._hasResource["com.ibm.mm.enabler.xml.xpath._Generic"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.xml.xpath._Generic"] = true;
dojo.provide("com.ibm.mm.enabler.xml.xpath._Generic");
// generic impl
dojo.declare("com.ibm.mm.enabler.xml.xpath._Generic", null, {
constructor: function(){
},
_evaluateXPath: function(/*String*/xpathExpr, /*DOMDocument*/ doc, /*Object{prefix:ns,prefix2:ns2,...}*/ namespaces){
if (dojo.isSafari) {
return this._safariEvaluateXPath(xpathExpr, doc, namespaces);
} else if (dojo.isIE) {
return this._ieEvaluateXPath(xpathExpr, doc, namespaces);
} else {
return this._geckoEvaluateXPath(xpathExpr, doc, namespaces);
}
},
_transformNode: function(result, resType){
if (typeof XPathResult != "undefined" && result instanceof XPathResult) {
return this._xpathResultValue(result, resType);
} else {
if (resType == com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE) {
return result;
} else if (resType == com.ibm.mm.enabler.xml.xpath._Generic.NUMBER_TYPE) {
return parseFloat(com.ibm.mm.enabler.utils.Dom.textContent(result));
} else if (resType == com.ibm.mm.enabler.xml.xpath._Generic.STRING_TYPE) {
return com.ibm.mm.enabler.utils.Dom.textContent(result);
} else if (resType == com.ibm.mm.enabler.xml.xpath._Generic.BOOLEAN_TYPE) {
return !!result;
}
}
return null;
},
_xpathResultValue: function(node, resType){
if (resType == com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE) {
return node;
} else if (resType == com.ibm.mm.enabler.xml.xpath._Generic.NUMBER_TYPE) {
return node.numberValue;
} else if (resType == com.ibm.mm.enabler.xml.xpath._Generic.STRING_TYPE) {
return node.stringValue;
} else if (resType == com.ibm.mm.enabler.xml.xpath._Generic.BOOLEAN_TYPE) {
return node.booleanValue;
}
return null;
},
_evaluateXPathSingle: function(xpathExpr, doc, namespaces, resType){
resType = resType || com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE;
var result;
if (dojo.isSafari) {
result = this._safariEvaluateXPathRaw(xpathExpr, doc, namespaces, resType);
if (XPathResult && result instanceof XPathResult) {
if (resType == com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE) {
return result.iterateNext();
}
return this._transformNode(result, resType);
} else if (result) {
return this._transformNode(result[0], resType);
}
} else if (dojo.isIE) {
result = this._ieEvaluateXPathRawSingle(xpathExpr, doc, namespaces);
if (result || result === null) {
return this._transformNode(result, resType);
}
} else {
result = this._geckoEvaluateXPathRaw(xpathExpr, doc, namespaces, resType);
if (result && resType == com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE) {
return result.iterateNext();
} else {
return this._transformNode(result, resType);
}
}
return result || null;
},
_geckoEvaluateXPath: function(/*String*/xpathExpr, /*DOMDocument*/ doc, /*Object{prefix:ns,prefix2:ns2,...}*/ namespaces){
var result = this._geckoEvaluateXPathRaw(xpathExpr, doc, namespaces, com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE);
var resultSet = [];
if (result) {
var thisResult;
while ((thisResult = result.iterateNext())) {
resultSet.push(thisResult);
}
}
return resultSet;
},
_geckoEvaluateXPathRaw: function(xpathExpr, doc, namespaces, type){
var xmlDocument = doc;
if (doc.nodeType != 9) {
xmlDocument = doc.ownerDocument;
}
return xmlDocument.evaluate(xpathExpr, doc, function(prefix){
return namespaces[prefix] ? namespaces[prefix].toString() : null;
}, type, null);
},
_ieEvaluateXPath: function(/*String*/xpathExpr, /*DOMDocument*/ doc, /*Object{prefix:ns,prefix2:ns2,...}*/ namespaces){
var result = this._ieEvaluateXPathRaw(xpathExpr, doc, namespaces);
return result || [];
},
_setIeNamespaces: function(doc, namespaces) {
if (namespaces) {
var ns = [];
var item;
for (var prop in namespaces) { // JSLINT-IGNORE: Filtering for prototype properties must not be done here, as namespaces often use dojo.delegate to save memory - dojo.delegate uses the prototype functionality for doing so - we use dojo.isFunction() which should suffice.
// ATTENTION: DON'T ADD .hasOwnProperty() CHECK HERE!
item = namespaces[prop];
if (prop != "xml") { // we cannot use !dojo.isFunction(item) as it costs too much performance
// There is no automatic namespace recognition, this is a workaround
ns.push("xmlns:", prop, "='", item, "' ");
}
}
if(dojo.isIE !=11){
var sDoc = doc.ownerDocument || doc;
sDoc.setProperty("SelectionNamespaces", ns.join(""));
sDoc.setProperty("SelectionLanguage", "XPath");
}
}
},
_ieEvaluateXPathRaw: function(xpathExpr, doc, namespaces){
this._setIeNamespaces(doc, namespaces);
return doc.selectNodes(xpathExpr);
},
_ieEvaluateXPathRawSingle: function(xpathExpr, doc, namespaces){
this._setIeNamespaces(doc, namespaces);
return doc.selectSingleNode(xpathExpr);
},
_safariEvaluateXPath: function(/*String*/xpathExpr, /*DOMDocument*/ doc, /*Object{prefix:ns,prefix2:ns2,...}*/ namespaces){
var result = this._safariEvaluateXPathRaw(xpathExpr, doc, namespaces, com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE);
if (XPathResult && result instanceof XPathResult) {
var resultSet = [];
var thisResult;
while ((thisResult = result.iterateNext())) {
resultSet.push(thisResult);
}
return resultSet;
}
return result || [];
},
_safariEvaluateXPathRaw: function(xpathExpr, doc, namespaces, type){
if (typeof XPathResult != "undefined") {
//use build in xpath support for Safari 3.0
return document.evaluate(xpathExpr, doc, function(prefix){
return namespaces[prefix] ? namespaces[prefix].toString() : null;
}, type, null);
} else if (doc.selectNodes) {
//use javeline Safari2 xpath support
return doc.selectNodes(xpathExpr);
}
}
});
com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE = 0;
com.ibm.mm.enabler.xml.xpath._Generic.NUMBER_TYPE = 1;
com.ibm.mm.enabler.xml.xpath._Generic.STRING_TYPE = 2;
com.ibm.mm.enabler.xml.xpath._Generic.BOOLEAN_TYPE = 3;
}
if(!dojo._hasResource["com.ibm.mm.enabler.xml.XPathImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.xml.XPathImpl"] = true;
dojo.provide("com.ibm.mm.enabler.xml.XPathImpl");
dojo.declare("com.ibm.mm.enabler.xml.XPathImpl", [com.ibm.mashups.enabler.xml.XPath, com.ibm.mm.enabler.xml.xpath._Generic], {
modelMessages: null,
constructor: function() {
this.modelMessages = dojo.i18n.getLocalization("com.ibm.mm.enabler", "modelMessages");
},
ANY_TYPE: com.ibm.mm.enabler.xml.xpath._Generic.ANY_TYPE,
NUMBER_TYPE: com.ibm.mm.enabler.xml.xpath._Generic.NUMBER_TYPE,
STRING_TYPE: com.ibm.mm.enabler.xml.xpath._Generic.STRING_TYPE,
BOOLEAN_TYPE: com.ibm.mm.enabler.xml.xpath._Generic.BOOLEAN_TYPE,
evaluateXPath: function(xpathExpr, doc, namespaces) {
if(!dojo.isString(xpathExpr) || xpathExpr.length === 0) {
throw new Error(this.modelMessages.E_INVALID_XPATH_EXPR_0);
}
if(!doc) {
throw new Error(this.modelMessages.E_INVALID_DOCUMENT_0);
}
var ret = this._evaluateXPath(xpathExpr, doc, namespaces);
return ret;
},
evaluateSingle: function(xpathExpr, doc, namespaces, type) {
if(!dojo.isString(xpathExpr) || xpathExpr.length === 0) {
throw new Error(this.modelMessages.E_INVALID_XPATH_EXPR_0);
}
if(!doc) {
throw new Error(this.modelMessages.E_INVALID_DOCUMENT_0);
}
return this._evaluateXPathSingle(xpathExpr, doc, namespaces, type);
},
evaluateEntry: function(xpathExpr, doc, namespaces) {
return this.evaluateSingle(xpathExpr, doc, namespaces, com.ibm.mashups.enabler.xml.XPath.ANY_TYPE);
},
evaluateBoolean: function(xpathExpr, doc, namespaces) {
return this.evaluateSingle(xpathExpr, doc, namespaces, com.ibm.mashups.enabler.xml.XPath.BOOLEAN_TYPE);
},
evaluateString: function(xpathExpr, doc, namespaces) {
return this.evaluateSingle(xpathExpr, doc, namespaces, com.ibm.mashups.enabler.xml.XPath.STRING_TYPE);
},
evaluateNumber: function(xpathExpr, doc, namespaces) {
return this.evaluateSingle(xpathExpr, doc, namespaces, com.ibm.mashups.enabler.xml.XPath.NUMBER_TYPE);
},
/**
* evaluates the specified xpath, but creates xml elements, which are not part
* of the document; please note that attributes are not supported
*
* @param {Object} xPath
* @param {Object} node
* @param {Object} namespaces
*/
createXPath: function(xPath, node, namespaces) {
// split off first part of xpath
var xPathParts = xPath.split("/");
// handle head
var qName = xPathParts[0];
// extract name and name space
var qNameParts = qName.split(":");
var name, namespace;
if (qNameParts.length > 1) {
namespace = qNameParts[0];
name = qNameParts[1];
}
else {
name = qNameParts[0];
}
// search for first part of xpath (what about case insensitive search for attributes, especially "_" vs "-" in locales?)
var names = com.ibm.mashups.enabler.xml.XPath.evaluateXPath((namespace ? namespace + ":" : "") + name, node, namespaces);
var result;
if (names && names.length > 0) {
// use existing xml element
result = names[0];
}
else {
// what about attributes?
// create xml element
result = com.ibm.mm.enabler.utils.Dom.createElement(node.ownerDocument, (namespace ? namespace + ":" : "") + name, namespace ? namespaces[namespace] : null);
node.appendChild(result);
}
// handle remaining parts of xpath
if (xPathParts.length > 1) {
// recursive call with remaining xpath part
result = com.ibm.mashups.enabler.xml.XPath.createXPath(xPath.substr(xPath.indexOf("/") + 1), result, namespaces);
}
return result;
}
});
// create the singleton
com.ibm.mashups.enabler.xml.XPath = new com.ibm.mm.enabler.xml.XPathImpl();
// backwards compatibility - still needed?
// TODO remove this in next enabler version
com.ibm.mm.enabler.xml.xpath.evaluateXPath = function(xpathExpr, doc, namespaces) {
dojo.deprecated("com.ibm.mm.enabler.xml.xpath.evaluateXPath", "The method com.ibm.mm.enabler.xml.xpath.evaluateXPath is deprecated, please use com.ibm.mashups.enabler.xml.XPath.evaluateXPath instead");
return com.ibm.mm.enabler.xml.xpath._Generic.evaluateXPath.apply(null, arguments);
};
}
if(!dojo._hasResource["com.ibm.mashups.enabler.xml.XPath"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.xml.XPath"] = true;
dojo.provide("com.ibm.mashups.enabler.xml.XPath");
}
if(!dojo._hasResource["com.ibm.mm.enabler.utils.LocaleHelper"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.utils.LocaleHelper"] = true;
dojo.provide("com.ibm.mm.enabler.utils.LocaleHelper");
com.ibm.mm.enabler.utils.LocaleHelper = {
getLocale:function(/*com.ibm.mashups.enabler.Localized*/localized,aLocale,defaultLocale){
if (typeof localized == "undefined" || localized === null) {
return null;
}
var localeArr = localized.getLocales();
if (typeof localeArr == "undefined" || localeArr === null || !dojo.isArray(localeArr)) {
return null;
}
if (localeArr.length === 0) {
return null;
}
var returnLocale = null;
if (localeArr.length === 1) {
returnLocale = localeArr[0];
}
var arr = {};
for (var i in localeArr) {
if (Object.prototype.hasOwnProperty.call(localeArr,i)) {
var temp = localeArr[i];
arr[temp] = temp;
}
}
var tempArr;
if (returnLocale === null) {
if (typeof aLocale != "undefined" && aLocale !== null) {
returnLocale = this.findMatchLocale(arr, aLocale);
if (returnLocale === null) {
tempArr = aLocale.split(/-|_/);
if (tempArr.length == 2) {
var iLocale = tempArr[0];
if (typeof arr[iLocale] != "undefined" && arr[iLocale] !== null) {
returnLocale = iLocale;
}
}
}
}
}
if (returnLocale === null) {
//get browser locale
var browserLocale = (dojo.isIE ? navigator.userLanguage : navigator.language).toLowerCase();
if (typeof ibmConfig != "undefined" && ibmConfig && typeof(ibmConfig.locale) != "undefined" && ibmConfig.locale) {
browserLocale = ibmConfig.locale;
}
if (browserLocale !== null) {
//browserLocale = browserLocale.replace(/-/,"_");
returnLocale = this.findMatchLocale(arr, browserLocale);
if (returnLocale === null) {
tempArr = browserLocale.split(/-|_/);
if (tempArr.length == 2) {
var tempLocale = tempArr[0];
if (typeof arr[tempLocale] != "undefined" && arr[tempLocale] !== null) {
returnLocale = tempLocale;
}
}
}
}
}
if (returnLocale === null) {
if (defaultLocale) {
returnLocale = defaultLocale;
}
}
if (returnLocale === null) {
if (arr.en) {
returnLocale = "en";
}
}
if (returnLocale === null) {
returnLocale = localeArr[0];
}
return returnLocale;
},
findMatchLocale:function(arr,locale){
var returnLocale = null;
if (arr[locale]) {
returnLocale = locale;
}
var serverLocale = this.toServerLocale(locale);
if (returnLocale === null && arr[serverLocale]) {
returnLocale = serverLocale;
}
var serverLocaleLowercase = serverLocale.toLowerCase();
if (returnLocale === null && arr[serverLocaleLowercase]) {
returnLocale = serverLocaleLowercase;
}
return returnLocale;
},
/**
* match a locale against an array of locales
*
* TODO: also allow preferred to be an array
*
* @param {String} preferred
* @param {Array} available
*/
matchLocale: function(preferred, available) {
return com.ibm.mm.enabler.utils.LocaleHelper._matchLocale(
com.ibm.mm.enabler.utils.LocaleHelper._getLocaleObj(preferred),
com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale(available));
},
/**
* match a normalized locale against an array of normalized locales
*
* FIXME: we need to add handling of multiple possible locales matching against multiple available ones,
* keeping in mind the order the user defined and also handling for exceptions
* (e.g. pt-br must not fall back to pt, sh traditional must fall back to simplified, etc.)
*
* @param {Object} locale an locale object
* @param {Array} locales an Array of normalized locale strings
*/
_matchLocale: function(locale, locales, stop) {
// console.debug("match locale:",locale,"against",locales);
var _origLocale = locale;
var match = null;
var found = dojo.some(locales, function(item) {
if (item == com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale(locale.toString())) {
match = item;
return true;
}
});
if (found && match) {
return match;
}
if (locale.variant) {
// try without variant
locale.variant = null;
return com.ibm.mm.enabler.utils.LocaleHelper._matchLocale(locale, locales);
}
if (locale.country) {
// try without country
locale.country = null;
return com.ibm.mm.enabler.utils.LocaleHelper._matchLocale(locale, locales);
}
if (!stop) {
// TODO: make list of aliases [he,iw], to automate this for other fallbacks.
locale = _origLocale;
switch (locale.language) {
case 'he':
// special handling for hebrew (he and iw (old) are equal)
locale.language = "iw";
break;
case 'iw':
// special handling for hebrew (he and iw (old) are equal)
locale.language = "he";
break;
}
return com.ibm.mm.enabler.utils.LocaleHelper._matchLocale(locale, locales, true);
}
return null;
},
/**
* (DE_dE_VariAnt -> de_DE)
* removes the variant part to sustain backwards compatibility - please use com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale
* whitespaces are trimmed at the beginning and end
*
* @deprecated
*
* @param {Object} locale
*/
toServerLocale:function(locale) {
if (!locale) {
return null;
}
if (locale.indexOf("-") < 0) {
return locale;
}
locale = locale.replace(/-/, "_");
var tempArr = locale.split('_');
var lang = tempArr[0];
var country = tempArr[1].toUpperCase();
var returnLocale = lang + "_" + country;
return returnLocale;
},
/**
* returns a locale object with normalized parts
*
* (DE_dE_VariAnt -> {language: 'de', country: 'DE', variant: 'VariAnt'})
* whitespaces are trimmed at the beginning and end
*
* @param {String|Array} locale
*
*/
_getLocaleObj: function(locale) {
if (dojo.isArray(locale)) {
return dojo.map(locale, function(item) {
return com.ibm.mm.enabler.utils.LocaleHelper._getLocaleObj(item);
});
}
else if (dojo.isString(locale) && dojo.string.trim(locale).length > 0) {
var localeObj = {
language: null,
country: null,
variant: null,
toString: function() {
return (this.language ? this.language + (this.country ? "_" + this.country + (this.variant ? "_" + this.variant : "") : "") : "");
},
isValid: function() {
return !!this.language;
}
};
var parts = dojo.string.trim(locale).replace(/-/g, "_").split('_');
switch (parts.length) {
case 3:
// we have got a variant
localeObj.variant = parts[2]; // JSLINT-IGNORE: NO BREAK HERE
// ATTN: no break here
case 2:
// we have got a country
localeObj.country = parts[1].toUpperCase(); // JSLINT-IGNORE: NO BREAK HERE
// ATTN: no break here
case 1:
// and we have got a language
localeObj.language = parts[0].toLowerCase();
break;
}
return localeObj;
}
else {
return null;
}
},
/**
* normalizes a locale or an array of locales
*
* (DE_dE_VariAnt -> de-DE_VariAnt)
* whitespaces are trimmed at the beginning and end
* @param {String|Array} locale
*/
normalizeLocale: function(locale) {
if (dojo.isArray(locale)) {
return dojo.map(locale, function(item) {
return com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale(item);
});
}
else if (locale && dojo.isString(locale)) {
return locale.replace(/_/g, "-").toLowerCase();
}
else {
return null;
}
}
};
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.NameSpaceFactory"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.NameSpaceFactory"] = true;
dojo.provide("com.ibm.mm.enabler.model.NameSpaceFactory");
dojo.declare( "com.ibm.mm.enabler.model.NameSpaceFactoryImpl", null,
{
constructor:function () {
// name space prefixes
this.NS_APP = "app";
this.NS_ATOM = "atom";
this.NS_THR = "thr";
this.NS_UM = "um";
this.NS_XHTML = "xhtml";
this.NS_XML = "xml";
this.NS_XSI = "xsi";
this.NS_OPENSEARCH = "opensearch";
this.NS_CM = "cm";
this.NS_CA = "ca";
this.NS_AC = "ac";
this.NS_EVENT_DATATYPES = "event-datatypes";
this.NS_XMLNS = "xmlns";
this.NS_XSD = "xsd";
this.NS_JS = "js";
// name space URIs
this.namespaces = {};
this.namespaces[this.NS_APP] = "http://www.w3.org/2007/app";
this.namespaces[this.NS_ATOM] = "http://www.w3.org/2005/Atom";
this.namespaces[this.NS_THR] = "http://purl.org/syndication/thread/1.0";
this.namespaces[this.NS_UM] = "http://www.ibm.com/xmlns/prod/websphere/um.xsd";
this.namespaces[this.NS_XHTML] = "http://www.w3.org/1999/xhtml";
this.namespaces[this.NS_XML] = "http://www.w3.org/XML/1998/namespace";
this.namespaces[this.NS_XSI] = "http://www.w3.org/2001/XMLSchema-instance";
this.namespaces[this.NS_XMLNS] = "http://www.w3.org/2000/xmlns/";
this.namespaces[this.NS_OPENSEARCH] = "http://a9.com/-/spec/opensearch/1.1/";
this.namespaces[this.NS_CM] = "http://www.ibm.com/xmlns/prod/composite-applications/v1.0";
this.namespaces[this.NS_CA] = "http://www.ibm.com/xmlns/prod/composite-applications/v1.0";
this.namespaces[this.NS_AC] = "http://www.ibm.com/xmlns/prod/lotus/access-control/v1.0";
this.namespaces[this.NS_EVENT_DATATYPES] = "http://www.ibm.com/xmlns/prod/lotus/mashups/event-datatypes";
this.namespaces[this.NS_XSD] = "http://www.w3.org/2001/XMLSchema";
this.namespaces[this.NS_JS] = "text/javascript";
},
/**
* Returns an object with a property for each element in the
* passed in array and the corresponding name space uri as value
* @param {Array} prefixes
*/
getNameSpaces: function(prefixes) {
var result = {};
var len = prefixes.length;
for (var i=0; i
*
* Defaults to API_ENFORCEMENT_MODE_WARN
API_ENFORCEMENT_MODE_ERROR
API_ENFORCEMENT_MODE_WARN
.
* @type String
* @private
*/
API_ENFORCEMENT_MODE: "com.ibm.mashups.enabler.enforcement",
/**
* Warnings will be prompted in the console denoting usage errors of the enabler api.
* @type String
* @private
*/
API_ENFORCEMENT_MODE_WARN: "warning",
/**
* Errors will be thrown denoting usage errors of the enabler api, note that
* this potentially breaks the driver if the api is used incorrectly.
* @type String
* @private
*/
API_ENFORCEMENT_MODE_ERROR: "error",
/**
* With this option the location (a URL) of the widget which will be displayed for non previewable content can be defined.
* If empty (thats the default) the widget delivered with the enabler will be used.
*
* @since 3.0
* @type String
*/
NON_PREVIEWABLE_WIDGET_LOCATION: "com.ibm.mashups.enabler.layout.widget.NonPreviewableContentWidget.location",
/**
* Size limit of page descriptions, implied from persistence
* @since 3.0
* @type String
*/
LIMIT_PAGE_DESCRIPTION: "com.ibm.mashups.persistence.page.description.limit",
/**
* Defines whether personalize is allowed or not for users. Defaults to true.
* @since 3.0
* @type Boolean
*/
WIDGET_PERSONALIZE_ENABLED: "com.ibm.mashups.widget.attributes.personalize.enabled",
/**
* Defines maximum page number when creating page base on page from hub. Defaults to 50.
* @since 3.0
* @type String
*/
SPACEMANAGER_PAGE_QUERYCOUNT : "com.ibm.mashups.spacemanager.page.queryCount",
/**
* Defines the search keyword when pages in hub are queried. Keep it empty will return all pages.
* @since 3.0
* @type String
*/
SPACEMANAGER_PAGE_QUERYKEYWORD : "com.ibm.mashups.spacemanager.page.queryKeyword",
/**
* Defines maximum space number when creating space base on space from hub. Defaults to 50.
* @since 3.0
* @type String
*/
SPACEMANAGER_SPACE_QUERYCOUNT : "com.ibm.mashups.spacemanager.spacetemplate.queryCount",
/**
* Defines the search keyword when spaces in hub are queried. Keep it empty will return all spaces.
* @since 3.0
* @type String
*/
SPACEMANAGER_SPACE_QUERYKEYWORD : "com.ibm.mashups.spacemanager.spacetemplate.queryKeyword",
/**
* Defines the search keyword when spaces in hub are queried. Keep it empty will return all spaces.
* @since 3.0
* @type String
*/
LOCALAPPS_REGEX : "com.ibm.mashups.multipart.localapps.regex",
/**
* Defines the format (as a regular expression) of the server side object IDs.
* @since 3.0
* @type String
*/
SERVER_OBJECT_ID_FORMAT: "com.ibm.mashups.server.oid.format",
/**
* Defines whether to use queued widget rendering. Default to true.
* @since 3.0.0.1
* @type Boolean
*/
QUEUE_RENDERING: "com.ibm.mashups.queueRendering"
});
com.ibm.mashups.enabler.services.ConfigConstants = new com.ibm.mashups.enabler.services.ConfigConstants();
}
if(!dojo._hasResource["com.ibm.mashups.enabler.services.ConfigObject_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.services.ConfigObject_API"] = true;
dojo.provide("com.ibm.mashups.enabler.services.ConfigObject_API");
dojo.provide("com.ibm.mashups.enabler.services.ConfigObject");
/**
* The Config Object allows to access config variables as defined by the system.
* for a specific config provider.
* @ibm-spi
* @ibm-module Base2
*/
dojo.declare("com.ibm.mashups.enabler.services.ConfigObject", null, {
/**
* This method returns the value of the config variable as defined by the system
* @param {String} name the name of the config variable
* @return {String} the value of the config variable. Maybe be NULL.
*/
getValue: function(name) {
return null;
},
/**
* This method returns the value of the config variable as defined by the system in a async way
* @param {String} name the name of the config variable
* @return {com.ibm.mashups.enabler.Deferred} a deferred object used to start this operation. The return value
* when executed through the deferred object is the value of the config variable. Maybe be NULL
*/
getValueDeferred: function(name) {
return null;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.services.ConfigObjectDefaultImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.services.ConfigObjectDefaultImpl"] = true;
dojo.provide("com.ibm.mm.enabler.services.ConfigObjectDefaultImpl");
dojo.declare("com.ibm.mm.enabler.services.ConfigObjectDefaultImpl", [com.ibm.mashups.enabler.services.ConfigObject], {
constructor: function(provider, configService) {
this.provider = provider;
this.configService = configService;
this.ns = {};
this.ns.app = "http://www.w3.org/2007/app";
this.ns.atom = "http://www.w3.org/2005/Atom";
},
/**
* @deprecated
*/
getPreferenceValue: function( /*string*/name) {
if (this.provider == "all") {
return this.configService.getValue(name);
}
else {
return this._getValue(this.provider, name);
}
return null;
},
getValue: function( /*string*/name) {
if (this.provider == "all") {
return this.configService.getValue(name, internal);
}
else {
return this._getValue(this.provider, name);
}
return null;
},
_getValue: function(/*string*/provider, /*string*/ name) {
return null;
},
getValueDeferred: function(/*string*/name){
if (this.provider == "all") {
return new com.ibm.mm.enabler.DeferredImpl(this, function(deferred, sync, name) {
var callBack = deferred.getFinishedCallback();
var retValue = this.configService.getValue(name, internal);
if (retValue && callBack ) {
callBack(retValue, com.ibm.mm.enabler.model.HttpStatusCodes.HTTP_OK, deferred.getFinishedCallbackParameters());
}
return retValue;
});
}
else {
return this._getValueDeferred(this.provider, name);
}
},
_getValueDeferred: function(/*string*/provider, /*string*/ name) {
return null;
}
});
// IMPORTANT
// ibmConfig.enablerLayerModules is a comma separated string of all supported modules at runtime
// This section dynamically loads the Extended representation when the variable enablerLayerModules contains the given module
if ((ibmConfig.enablerLayerModules) && (dojo.indexOf(ibmConfig.enablerLayerModules, "Base")>=0)) {
dojo["require"]("com.ibm.mm.enabler.services.ConfigObjectExtendedImpl"); // JSLINT-IGNORE: This needs to be done to allow modularization and to support the minimal layer
}
}
if(!dojo._hasResource["com.ibm.mashups.enabler.services.ConfigObject"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.services.ConfigObject"] = true;
dojo.provide("com.ibm.mashups.enabler.services.ConfigObject");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.services.ConfigService_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.services.ConfigService_API"] = true;
dojo.provide("com.ibm.mashups.enabler.services.ConfigService_API");
dojo.provide("com.ibm.mashups.enabler.services.ConfigService");
/**
* The Config Service allows to access config variables as defined by the system.
* The service can be retrieved using the following code:
* var configService = com.ibm.mashups.services.ServiceManager.getService(
* com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME);
* @ibm-spi
* @ibm-module Base2
*/
dojo.declare("com.ibm.mashups.enabler.services.ConfigService", null, {
/**
* The service name to be used to fetch the service from the ServiceManager
* @type String
*/
SERVICE_NAME: "configService",
/**
* This method returns the value of the config variable as defined by the system
* @param {String} name the name of the config variable
* @return {String} the value of the config variable. Maybe be NULL.
*/
getValue: function(name) {
return null;
},
/**
* This method returns the value of the config object for a config provider
* @param {String} name the name of the config provider
* @return {com.ibm.mashups.enabler.services.ConfigObject} the config provider. Maybe be NULL.
*/
getConfigObject: function(name) {
return null;
},
/**
* This method returns the Config Provider names. Each Config Provider will
* have a corresponding ConfigObject.
* @return {String[]} the config provider names. Never NULL.
*/
getConfigProviderNames: function() {
return null;
}
});
// make sure we can reference this globally
com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME = "configService";
}
if(!dojo._hasResource["com.ibm.mashups.services.ServiceManager_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.services.ServiceManager_API"] = true;
dojo.provide("com.ibm.mashups.services.ServiceManager_API");
dojo.provide("com.ibm.mashups.services.ServiceManager");
/**
* This interface manages services that are provided to the system, i.e. to iWidgets and other components.
* It provides capability to access Services in Lotus Mashups.
* By default EventService and ConfigService are provided.
* Page components are able to use event services by using following api:
* var eventService = com.ibm.mashups.services.ServiceManager.getService(
* com.ibm.mashups.iwidget.services.EventService.SERVICE_NAME);
*
* Configuration of services:
* This section describes how each service is configured and how additional services can be added.
*
* Through the ConfigService.properties one can define an additional property named "additionalServices"
* defining additional services besides EventService and ConfigService.
* Each entry should have the following format.
* "name": service name.
* "path": url that point to the service js file.
* "baseClass": the class that implements the service. one instance of this class will be generated.
*
* Example:
* additionalServices = [
* { "name":"SecurityService",
* "path":"/mum/js/com/ibm/enabler/iw/securityservices.js",
* "baseClass":"com.ibm.mm.iwidget.services.SecurityService"}
* ]
*
* @ibm-spi
* @ibm-module Base2
*/
dojo.declare("com.ibm.mashups.services.ServiceManager",null,
{
/**
* @private
*/
constructor:function(){
},
/**
This interface allow page components to get the required service.
@param{String} serviceName required service name that's used to uniquely identify a service .
@type Object
@returns{Object} an instance of required service. NULL if configured incorrectly.
*/
getService:function(serviceName) {
}
}
);
}
if(!dojo._hasResource["com.ibm.mashups.services.ServiceManager"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.services.ServiceManager"] = true;
dojo.provide("com.ibm.mashups.services.ServiceManager");
}
if(!dojo._hasResource["com.ibm.mm.services.ServiceManagerImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.services.ServiceManagerImpl"] = true;
dojo.provide("com.ibm.mm.services.ServiceManagerImpl");
dojo.declare("com.ibm.mm.services.ServiceManagerImpl", com.ibm.mashups.services.ServiceManager, {
constructor: function() {
this._serviceEntries = {};
//allow overwritten if ibmConfig.loadServices is set
ibmConfig = ibmConfig || {};
ibmConfig.additionalServices = ibmConfig.additionalServices || null;
if (ibmConfig.additionalServices) {
var entries = dojo.fromJson(ibmConfig.additionalServices);
for (var i in entries) {
if (Object.prototype.hasOwnProperty.call(entries,i)) {
var anEntry = entries[i];
this._serviceEntries[anEntry.name] = anEntry;
}
}
}
},
getService: function(serviceName) {
var serviceEntry = this._serviceEntries[serviceName];
serviceEntry = serviceEntry || null;
if (serviceEntry !== null) {
var serviceHandler = serviceEntry.serviceHandler;
serviceHandler = serviceHandler || null;
if (serviceHandler === null) {
// assume js is already loaded, create service object
serviceHandler = this._createService(serviceEntry);
serviceHandler = serviceHandler || null;
if (serviceHandler === null) {
this._loadScript(serviceEntry);
// serviceHandler = this._createService(serviceEntry);
}
else {
this._serviceEntries[serviceName].serviceHandler = serviceHandler;
}
}
}
return this._serviceEntries[serviceName].serviceHandler;
},
//if serviceHandler is String, then it's baseClass
//if it's object, then it's the service handler instance
setService: function(serviceName, serviceHandler) {
serviceHandler = serviceHandler || null;
if (serviceHandler === null) {
return null;
}
//create new service or overwrite an existing service
var serviceEntry = this._serviceEntries[serviceName];
serviceEntry = serviceEntry || null;
if (serviceEntry !== null) {
delete this._serviceEntries[serviceName];
}
if (!this._serviceEntries[serviceName]) {
this._serviceEntries[serviceName] = {};
}
if (dojo.isString(serviceHandler)) {
this._serviceEntries[serviceName].baseClass = serviceHandler;
}
else {
this._serviceEntries[serviceName].serviceHandler = serviceHandler;
}
},
_loadScript: function(serviceEntry) {
var me = this;
dojo.xhrGet({
url: serviceEntry.path,
handleAs: "text",
sync: true,
load: function(result) {
dojo.eval(result); // JSLINT-IGNORE: We have to evaluate the services JavaScript in this case
var serviceHandler = me._createService(serviceEntry);
if (typeof serviceHandler != "undefined" && serviceHandler !== null) {
var serviceName = serviceEntry.name;
serviceEntry.serviceHandler = serviceHandler;
}
},
error: function(data, ioArgs) {
}
});
},
_createService: function(serviceEntry) {
var service = null;
try {
service = new (dojo.getObject(serviceEntry.baseClass))();
}
catch (err) {
}
return service;
}
});
com.ibm.mashups.services.ServiceManager = new com.ibm.mm.services.ServiceManagerImpl();
}
if(!dojo._hasResource["com.ibm.mm.enabler.services.AbstractConfigServiceImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.services.AbstractConfigServiceImpl"] = true;
dojo.provide("com.ibm.mm.enabler.services.AbstractConfigServiceImpl");
dojo.declare("com.ibm.mm.enabler.services.AbstractConfigServiceImpl", com.ibm.mashups.enabler.services.ConfigService, {
constructor: function(){
},
/**
* @deprecated
*/
getPreferenceValue: function( /*string*/name){
return this.getValue(name);
},
getValue: function( /*string*/name, internal){
var value = ibmConfig[name];
return value;
},
getConfigObject: function(/*string*/configProvider){
return null;
},
getConfigProviderNames: function(){
return null;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.services.ConfigServiceDefaultImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.services.ConfigServiceDefaultImpl"] = true;
dojo.provide("com.ibm.mm.enabler.services.ConfigServiceDefaultImpl");
// inject this service into the ServiceManager at the end. Therefore we have to require the implementation
//
//
//
dojo.declare("com.ibm.mm.enabler.services.ConfigServiceDefaultImpl", [com.ibm.mm.enabler.services.AbstractConfigServiceImpl], {
constructor: function() {
},
_getConfigObject: function(/*string*/configProvider) {
if (!ibmConfig["CO_" + configProvider]) {
var co = new com.ibm.mm.enabler.services.ConfigObjectDefaultImpl(configProvider, this);
ibmConfig["CO_" + configProvider] = co;
}
return ibmConfig["CO_" + configProvider];
},
_getConfigProviderNames: function() {
var ret = [];
ret.push("all");
return ret;
},
getValue: function(name) {
var ret = this.inherited(arguments, [name, true]);
return ret;
},
getConfigObject: function(name) {
var ret = this._getConfigObject(name);
return ret;
},
getConfigProviderNames: function() {
var ret = this._getConfigProviderNames();
return ret;
}
});
com.ibm.mashups.services.ServiceManager.setService("configService", "com.ibm.mm.enabler.services.ConfigServiceDefaultImpl");
// IMPORTANT
// ibmConfig.enablerLayerModules is a comma separated string of all supported modules at runtime
// This section dynamically loads the Extended representation when the variable enablerLayerModules contains the given module
if ((ibmConfig.enablerLayerModules) && (dojo.indexOf(ibmConfig.enablerLayerModules, "Base")>=0)) {
dojo["require"]("com.ibm.mm.enabler.services.ConfigServiceExtendedImpl"); // JSLINT-IGNORE: This needs to be done to allow modularization and to support the minimal layer
}
}
if(!dojo._hasResource["com.ibm.mashups.enabler.services.ConfigService"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.services.ConfigService"] = true;
dojo.provide("com.ibm.mashups.enabler.services.ConfigService");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.utils.EndpointHelper_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.utils.EndpointHelper_API"] = true;
dojo.provide("com.ibm.mashups.enabler.utils.EndpointHelper_API");
dojo.provide("com.ibm.mashups.enabler.utils.EndpointHelper");
/**
* Helper utility for endpoint encoded urls.
*
* @ibm-module Base2
* TODO: Change/Remove
*/
dojo.declare("com.ibm.mashups.enabler.utils.EndpointHelper", null, {
/**
* This method resolves endpoint://{endpointid}/relativeurl
*
* @param {String} url the url to resolve for endpoints
* @return {String} the url with endpoints resolved
*/
resolve: function(url) {
return null;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.EndpointUtils"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.EndpointUtils"] = true;
dojo.provide("com.ibm.mm.enabler.EndpointUtils");
dojo.declare("com.ibm.mm.enabler.EndpointUtilsDefaultImpl", null, {
constructor: function(){
},
checkForEndpoints: function(/*String*/url){
return null;
}
});
com.ibm.mm.enabler.EndpointUtils = new com.ibm.mm.enabler.EndpointUtilsDefaultImpl();
// IMPORTANT
// ibmConfig.enablerLayerModules is a comma separated string of all supported modules at runtime
// This section dynamically loads the Extended representation when the variable enablerLayerModules contains the given module
if ((ibmConfig.enablerLayerModules) && (dojo.indexOf(ibmConfig.enablerLayerModules, "iWidget")>=0)) {
dojo["require"]("com.ibm.mm.enabler.EndpointUtilsExtendedImpl"); // JSLINT-IGNORE: This needs to be done to allow modularization and to support the minimal layer
}
}
if(!dojo._hasResource["com.ibm.mm.enabler.utils.EndpointHelperImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.utils.EndpointHelperImpl"] = true;
dojo.provide("com.ibm.mm.enabler.utils.EndpointHelperImpl");
dojo.declare("com.ibm.mm.enabler.utils.EndpointHelperImpl", null,
{
resolve: function(url) {
if (!url) {
return url;
}
var url2 = com.ibm.mm.enabler.EndpointUtils.checkForEndpoints(url);
if (url2) {
return url2;
}
return url;
}
}
);
com.ibm.mashups.enabler.utils.EndpointHelper = new com.ibm.mm.enabler.utils.EndpointHelperImpl();
}
if(!dojo._hasResource["com.ibm.mashups.enabler.utils.EndpointHelper"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.utils.EndpointHelper"] = true;
dojo.provide("com.ibm.mashups.enabler.utils.EndpointHelper");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.utils.URLHelper_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.utils.URLHelper_API"] = true;
dojo.provide("com.ibm.mashups.enabler.utils.URLHelper_API");
dojo.provide("com.ibm.mashups.enabler.utils.URLHelper");
/**
* Helper utility for encoding urls.
*
* @ibm-module Base2
*/
dojo.declare("com.ibm.mashups.enabler.utils.URLHelper", null, {
/**
* This method rewrites a url and takes care for instance to proxify the given url
*
* @ibm-api
*
* @param {String} url the url to rewrite
* @return {String} the encoded url
*/
rewriteURL: function(targetUrl){
return null;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.utils.Misc"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.utils.Misc"] = true;
dojo.provide("com.ibm.mm.enabler.utils.Misc");
com.ibm.mm.enabler.utils.Misc = {
/**
* Example usage:
*
*
*
* var myObj = {a: 1, b: "bla", c: function(){}};
*
* com.ibm.mm.enabler.utils.Misc.forIn(myObj,function(item,idx,arr) {
* console.debug(arguments);
* });
* // prints:
* // [1, "a", Object { a=1, more...}]
* // ["bla", "b", Object { a=1, more...}]
* // [function(), "c", Object { a=1, more...}]
*
*
* var myScope = {
* count: 0,
* f: function(item,idx,arr) {
* this.count++;
* }
* }
* com.ibm.mm.enabler.utils.Misc.forIn(myObj,'f',myScope);
*
* console.debug(myScope.count); // prints: 3
* @param {Object} obj The object to iterate over
* @param {Function|String} func The function to call on each object with three parameters: value, key, object
* @param {Object} scope Optional, the scope to call the function on.
*/
forIn: function(obj, func, scope) {
if(!obj || typeof obj != "object") {
return;
}
scope = scope || null;
var item;
for(var idx in obj) {
if(Object.prototype.hasOwnProperty.call(obj,idx)) {
item = obj[idx];
dojo.hitch(scope,func)(item,idx,obj);
}
}
},
encodePath: function(path, decoded) {
if (path.length === 0) {
return path;
}
var parts = path.split("/");
for (var i=0; inull
* @type void
*/
setStrategy : function(strategy) {
},
/**
* Returns the array of strategies which are in use
* @return {com.ibm.mashups.enabler.strategy.Strategy[]} array of strategies in use, null
if no
* strategies are in use
*/
getStrategies : function() {
},
/**
* Returns the specified strategy
* @param {strategy} strategy class name or array index of strategy
* @return {com.ibm.mashups.enabler.strategy.Strategy} strategy in use, null
if no
* strategy with the specified type is in use
* @ibm-spi
*/
getStrategy : function(strategy) {
},
/**
* Adds a strategy to the strategies array
* @param {com.ibm.mashups.enabler.strategy.Strategy} strategy strategy to add; must not be null
* @return {int} index where the strategy was added in the strategies array
*/
addStrategy : function(strategy) {
},
/**
* Removes the specified strategy
* @param {strategy} strategy class name or array index of the strategy; must not be
* null
* @type void
*/
removeStrategy : function(strategy) {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.Model"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.Model"] = true;
dojo.provide("com.ibm.mashups.enabler.model.Model");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.strategy.NoCacheStrategy"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.strategy.NoCacheStrategy"] = true;
dojo.provide("com.ibm.mashups.enabler.strategy.NoCacheStrategy");
/**
* Interface to control, if caching is used for obtaining model artifacts
*
* @since 3.0
*
* @ibm-spi
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.strategy.NoCacheStrategy", com.ibm.mashups.enabler.strategy.Strategy, {
/**
* @private
*/
_apply: function(restRequest) {
// this is the spec way, but nobody cares. Try it yourself: http://www.mnot.net/javascript/xmlhttprequest/cache.html
restRequest.setHeader("Pragma", "no-cache");
restRequest.setHeader("Cache-Control", "no-cache");
// This works on all major browsers even though it is not the spec way
restRequest.setHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
// the only other solution is to use the existing parameter solution (pragma=no-cache) or something like dojo with a random parameter
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.ModelImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.ModelImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.ModelImpl");
dojo.declare("com.ibm.mm.enabler.model.ModelImpl", com.ibm.mashups.enabler.model.Model, {
/**
* @private
*/
// FIXME: use _strategies
strategy: null,
constructor: function() {
// messages
this.modelMessages = dojo.i18n.getLocalization("com.ibm.mm.enabler", "modelMessages");
},
setStrategy: function(strategy) {
if (strategy === null || typeof strategy == 'undefined') {
this.strategy = null;
}
else if (com.ibm.mm.enabler.utils.Misc.isInstanceOf(strategy, Array)) {
if (strategy.length > 0) {
this.strategy = [];
dojo.forEach(strategy, function(item, idx, arr) {
this.strategy.push(item);
this._preprocessStrategy(item);
}, this);
}
}
else {
this.strategy = [strategy];
this._preprocessStrategy(strategy);
}
},
getStrategies: function() {
// FIXME: expose copy of array
return this.strategy || [];
},
addStrategy: function(strategy) {
if (strategy === null || typeof strategy == 'undefined') {
throw new Error(this.modelMessages.E_PARAM_ISNULL_0);
}
if (null === this.strategy) {
// null strategy array
this.strategy = [];
}
// do preprocessing of strategies
this._preprocessStrategy(strategy);
// potentially replace existing strategy of same type
for (var i = 0, l = this.strategy.length; i < l; i++) {
// only dojo objects have declaredClass
if (this.strategy[i].declaredClass) {
if (strategy instanceof (dojo.getObject(this.strategy[i].declaredClass))) {
this.strategy[i] = strategy;
return i;
}
}
}
return (this.strategy.push(strategy) - 1);
},
removeStrategy: function(s) {
if (s === null || typeof s == 'undefined') {
throw new Error(this.modelMessages.E_PARAM_ISNULL_0);
}
if (!this.strategy) {
return;
}
else if (dojo.isString(s)) {
s = this._getIndexOfStrategyByType(s);
}
if (!isNaN(s) && (s < this.strategy.length) && (s >= 0)) {
this.strategy.splice(s, 1 + s);
}
},
getStrategy: function(s) {
if (!this.strategy) {
return null;
}
else if (dojo.isString(s)) {
return this._findStrategyByType(s);
}
else {
if (!isNaN(s) && (s < this.strategy.length) && (s >= 0)) {
return this.strategy[s];
}
else {
return null;
}
}
},
_findStrategyByType: function(type) {
var i = this._getIndexOfStrategyByType(type);
return i >= 0 ? this.strategy[i] : null;
},
_getIndexOfStrategyByType: function(type) {
if (this.strategy) {
for (var i = 0, l = this.strategy.length; i < l; i++) {
// only dojo objects have declaredClass
if (this.strategy[i].declaredClass) {
if (type == this.strategy[i].declaredClass) {
return i;
}
}
}
}
return -1;
},
_preprocessStrategy: function(s) {
if (com.ibm.mm.enabler.utils.Misc.isInstanceOf(s, com.ibm.mashups.enabler.strategy.NoCacheStrategy)) {
if (dojo.isFunction(this.invalidate)) {
this.invalidate();
}
}
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.services.ModelRestServiceRequest"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.services.ModelRestServiceRequest"] = true;
dojo.provide("com.ibm.mm.enabler.services.ModelRestServiceRequest");
/*
* This is injected on the fly and not fetched through an API. Therefore we need
* to define the @ibm-module so that the build process is picking it up
* @ibm-module Base
*
* This value defines the order in which the packages should be printed out into
* the dojo profile. Default is 100. Any number that is smaller causes this
* class to be written out before any other with a higher number
* @ibm-dojo-profile-level 50
*/
dojo.declare("com.ibm.mm.enabler.services.ModelRestServiceRequest", null, {
REQUEST_METHOD_POST: "POST",
REQUEST_METHOD_PUT: "PUT",
REQUEST_METHOD_DELETE: "DELETE",
POST_ACTION_HEADER: "X-Method-Override",
MODIFICATION_COOKIE: "modified.id",
constructor: function( /* HttpUrl */feedlocation, /* HTMLFormElement? */ formNode, /* Function? */ formFilter, /* boolean? */ textOnly, /* boolean? */ sync) {
if (com.ibm.mm.enabler.services.ModelRestServiceRequestStatic.getXRequestDigest()) {
feedlocation.setParameter("digest", com.ibm.mm.enabler.services.ModelRestServiceRequestStatic.getXRequestDigest());
}
this._feedURI = feedlocation.toProxifiedString();
this._textOnly = textOnly;
if (textOnly) {
this._handleAs = "text";
} else {
this._handleAs = "xml";
}
this._sync = sync;
this._formNode = formNode;
this._formFilter = formFilter;
this._config = com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME);
this._headers = {};
this.logoutVerificationForRaw = false;
// Make sure this isn't undefined.
if (!this._sync) {
this._sync = false;
}
},
setHandleAs: function(handleAs) {
if (handleAs == "atom") {
this._handleAs = "xml";
} else {
this._handleAs = handleAs;
}
},
setHeader: function(name, value) {
this._headers[name] = value;
},
enableLogoutVerificationForRawRetrieval: function() {
this.logoutVerificationForRaw = true;
},
// summary: Sends a request to one of the Portal REST Services and handles
// the response.
// description: Create a new instance of this object for every REST service
// request that is
// sent. The URL is passed in to the constructor. If a form node and form
// filter is
// passed into the constructor, the REST service request is handled as a
// form submit.
// The request can also be executed synchronously if TRUE is passed into the
// constructor.
// In general, only the model implementations should send these requests.
create: function( /* ibm.atom.Feed */feed, /* Function */ callbackfn, /* Object? */ addtlCallbackFnArguments) {
// summary: Creates an entry in a feed.
// description: Creates an entry in a feed. This operation is not
// implemented in this
// class. It should be overridden by subclasses and properly implemented
// if
// the REST service supports the create operation.
// feed: the ATOM feed object
// entry: the ATOM entry to create
// callbackfn: the function to call when the operation is complete
this._updateCookie();
var me = this;
var args = {
url: this._feedURI,
headers: {
// "If-Modified-Since": "Thu, 1 Jan 1970 00:00:00 GMT",
"Content-Type": "application/atom+xml; charset=utf-8"
}, // temporary to force the browser to ignore cached requests
load: function(response, ioArgs) {
var xhr = ioArgs.xhr;
var data = response;
var xrd = xhr.getResponseHeader("X-Request-Digest");
if (xrd !== null) {
com.ibm.mm.enabler.services.ModelRestServiceRequestStatic.setXRequestDigest(xrd);
}
var contentType = xhr.getResponseHeader("Content-Type");
if (typeof contentType != "undefined" && contentType !== null && contentType.indexOf("text/html") >= 0) {
me._doLogin();
return;
}
if (dojo.isIE) {
data = dojox.xml.parser.parse(xhr.responseText);
}
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_LOAD, data, xhr, addtlCallbackFnArguments);
},
error: function(response, ioArgs) {
var xhr = ioArgs.xhr;
var status = xhr.status;
// Check whether we are having an authorization problem
if (status == 401) {
me._doLogin();
return;
}
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_ERROR, null, xhr, addtlCallbackFnArguments);
},
sync: this._sync,
postData: feed.toString(),
handleAs: this._handleAs
};
dojo.rawXhrPost(args);
},
read: function( /* Function? */callbackfn, /* Object? */ addtlCallbackFnArguments) {
// summary: Read the ATOM feed provided by the REST service.
// description: If textOnly is set to true, the ATOM feed is returned as
// text and
// passed in as a single argument to the specified callback function.
// Otherwise, the ATOM feed is parsed into an {@link ibm.atom.Feed}
// object
// and passed into the callback function along with the original XML
// Document
// Object Model object.
// callbackfn: the function to call when the operation is complete (only
// valid if
// sync is false)
// addtlCallbackFnArguments: any arguments to pass through to the
// callback function
if (this._textOnly) {
this._retrieveRawFeed(callbackfn, addtlCallbackFnArguments);
}
else {
this._retrieve(callbackfn, addtlCallbackFnArguments);
}
},
update: function( /* ibm.atom.Feed */feed, /* Function */ callbackfn, /* Object? */ addtlCallbackFnArguments) {
// summary: Updates an entry in a feed.
// description: Updates an entry in a feed. This operation is not
// implemented in this
// class. It should be overridden by subclasses and properly implemented
// if the
// REST service supports the update operation.
// feed: the ATOM feed object
// entry: the ATOM entry to create
// callbackfn: the function to call when the operation is complete
this._updateCookie();
var me = this;
var args = {
url: this._feedURI,
load: function(response, ioArgs) {
var xhr = ioArgs.xhr;
var xrd = xhr.getResponseHeader("X-Request-Digest");
if (xrd !== null) {
com.ibm.mm.enabler.services.ModelRestServiceRequestStatic.setXRequestDigest(xrd);
}
var contentType = xhr.getResponseHeader("Content-Type");
if (typeof contentType != "undefined" && contentType !== null && contentType.indexOf("text/html") >= 0) {
me._doLogin();
return;
}
// this seems to be fixed with dojo 1.4.1 ... WTF ? Seems or IS ???
// if (dojo.isIE < 7) {
// data = dojox.xml.parser.parse(xhr.responseText,"application/xml");
// }
dojo.partial(callbackfn)(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_LOAD, response, xhr, addtlCallbackFnArguments);
},
error: function(response, ioArgs) {
var xhr = ioArgs.xhr;
var status = xhr.status;
// Check whether we are having an authorization problem
if (status == 401) {
me._doLogin();
return;
}
dojo.partial(callbackfn)(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_ERROR, null, xhr, addtlCallbackFnArguments);
},
sync: this._sync,
handleAs: this._handleAs
};
var requestHeaders = {
// "If-Modified-Since": "Thu, 1 Jan 1970 00:00:00 GMT",
"Content-Type": "application/atom+xml; charset=utf-8"
};
var mpHandler = com.ibm.mashups.enabler.io.XHRMultipartFactory.create();
var inTrans = mpHandler.isTransaction();
// we verify for sync here as well because we know that the transactions
// gets aborted by the multipart processing and hence we can do the PUT
// right away
if (com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME).getValue(com.ibm.mashups.enabler.services.ConfigConstants.TUNNEL_MODE) === true && (!inTrans || this._sync)) {
requestHeaders[this.POST_ACTION_HEADER] = this.REQUEST_METHOD_PUT;
args.headers = requestHeaders;
args.postData = feed;
dojo.rawXhrPost(args);
}
else {
args.putData = feed;
args.headers = requestHeaders;
dojo.rawXhrPut(args);
}
},
remove: function(/* Function */callbackfn, /* Object? */ addtlCallbackFnArguments) {
// summary: Removes an entry from a feed.
// description: Removes an entry from a feed. This operation is not
// implemented in this
// class. It should be overridden by subclasses and properly implemented
// if the
// REST service supports the remove operation.
// feed: the ATOM feed object
// entry: the ATOM entry to create
// callbackfn: the function to call when the operation is complete
this._updateCookie();
var me = this;
var args = {
url: this._feedURI,
load: function(response, ioArgs) {
var type = com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_LOAD;
var data = response;
var xhr = ioArgs.xhr;
var xrd = xhr.getResponseHeader("X-Request-Digest");
if (xrd !== null) {
com.ibm.mm.enabler.services.ModelRestServiceRequestStatic.setXRequestDigest(xrd);
}
var contentType = xhr.getResponseHeader("Content-Type");
if (typeof contentType != "undefined" && contentType !== null && contentType.indexOf("text/html") >= 0) {
me._doLogin();
return;
}
if (dojo.isIE) {
data = dojox.xml.parser.parse(xhr.responseText);
}
callbackfn(type, data, xhr, addtlCallbackFnArguments);
},
error: function(response, ioArgs) {
var xhr = ioArgs.xhr;
var status = xhr.status;
// Check whether we are having an authorization problem
if (status == 401) {
me._doLogin();
return;
}
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_ERROR, null, xhr, addtlCallbackFnArguments);
},
sync: this._sync,
handleAs: this._handleAs
};
var requestHeaders = {
// "If-Modified-Since": "Thu, 1 Jan 1970 00:00:00 GMT",
"Content-Type": "application/atom+xml"
};
if (com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME).getValue(com.ibm.mashups.enabler.services.ConfigConstants.TUNNEL_MODE) === true) {
requestHeaders[this.POST_ACTION_HEADER] = this.REQUEST_METHOD_DELETE;
args.headers = requestHeaders;
dojo.rawXhrPost(args);
}
else {
args.headers = requestHeaders;
dojo.xhrDelete(args);
}
},
_retrieveRawFeed: function(callbackfn, callbackargs) {
var me = this;
dojo.xhrGet({
url: this._feedURI,
headers: this._headers,
load: function(data, ioArgs) {
var xhr = ioArgs.xhr;
var xrd = xhr.getResponseHeader("X-Request-Digest");
if (xrd !== null) {
com.ibm.mm.enabler.services.ModelRestServiceRequestStatic.setXRequestDigest(xrd);
}
if (me.logoutVerificationForRaw) {
// in this case we assume that a X-Request-Digest is always returned from the resolver
// if it is not coming back it had to be due to a login challange
if (!xrd) {
me._doLogin();
return;
}
}
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_LOAD, data, ioArgs.xhr, callbackargs);
},
error: function(data, ioArgs) {
var xhr = ioArgs.xhr;
var status = xhr.status;
// Check whether we are having an authorization problem
if (status == 401) {
me._doLogin();
return;
}
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_ERROR, data, ioArgs.xhr, callbackargs);
},
sync: this._sync,
handleAs: this._handleAs
});
},
_retrieve: function(callbackfn, callbackargs, formNode, formFilter) {
var content = {};
// temp my ass
var mt = "xml"; // temp
if (dojo.isIE) {
// content = { "com.ibm.wps.web2.contenttype": "text/xml" };
mt = "text"; // temp
}
var me = this;
var args = {
url: this._feedURI,
content: content,
headers: this._headers,
load: function(response, ioArgs) {
var data = response;
var xhr = ioArgs.xhr;
var xrd = xhr.getResponseHeader("X-Request-Digest");
if (xrd !== null) {
com.ibm.mm.enabler.services.ModelRestServiceRequestStatic.setXRequestDigest(xrd);
}
var contentType = xhr.getResponseHeader("Content-Type");
// If the HTML content is returned, this is probably another
// re-direction so we need to
// force a full-page refresh.
if (typeof contentType != "undefined" && contentType !== null && contentType.indexOf("text/html") >= 0) {
me._doLogin();
return;
}
if (dojo.isIE) {
var doc = com.ibm.mm.enabler.utils.Dom.createDocument(data);
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_LOAD, doc, xhr, callbackargs);
}
else {
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_LOAD, data, xhr, callbackargs);
}
},
error: function(response, ioArgs) {
var data = response;
var xhr = ioArgs.xhr;
var status = xhr.status;
// Check whether we are having an authorization problem
if (status == 401) {
me._doLogin();
return;
}
if (dojo.isIE) {
var doc = null;
try {
if (data) {
doc = com.ibm.mm.enabler.utils.Dom.createDocument(data);
}
}
catch (e) {
}
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_ERROR, doc, xhr, callbackargs);
}
else {
callbackfn(com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_ERROR, data, xhr, callbackargs);
}
},
sync: this._sync,
handleAs: mt
};
var method = "Get";
if (this._formNode) {
args.form = this._formNode;
method = "Post";
}
if (this._formFilter) {
args.formFilter = this._formFilter;
}
dojo["xhr" + method](args);
},
_updateCookie: function() {
var dt = new Date();
var properties = {};
properties.path = this._config.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTEXT_ROOT);
dojo.cookie(this.MODIFICATION_COOKIE, dt.getTime(), properties);
},
_doLogin: function() {
// lazy load, to support dojo layer build
dojo["require"]("com.ibm.mashups.enabler.model.state.NavigationStateModelFactory"); // JSLINT-IGNORE:
// This
// needs
// to
// be
// done
// to
// allow
// modularization
// and
// not
// break
// the
// layer
// build
dojo["require"]("com.ibm.mashups.enabler.model.state.UrlGeneratorFactory"); // JSLINT-IGNORE:
// This
// needs
// to
// be
// done
// to
// allow
// modularization
// and
// not
// break
// the
// layer
// build
var pid = null;
var url = document.location.href;
// get full page refresh redirect url
var cb = function(url) {
if (url) {
top.location.href = url;
}
};
var navStateModel = com.ibm.mashups.enabler.model.state.NavigationStateModelFactory.getNavigationStateModel();
com.ibm.mashups.enabler.model.state.UrlGeneratorFactory.getURLGenerator().getUrl(navStateModel, cb, {
nohash: "true"
});
},
toString: function() {
return this._feedURI;
}
});
com.ibm.mm.enabler.services.ModelRestServiceRequestStatic = {
xRequestDigest : null,
getXRequestDigest: function() {
if ((null === this.xRequestDigest) && (ibmConfig["com.ibm.resolver.digest"])) {
this.xRequestDigest = ibmConfig["com.ibm.resolver.digest"];
}
return this.xRequestDigest;
},
setXRequestDigest: function(digest) {
this.xRequestDigest = digest;
},
invalidateXRequestDigest: function() {
// update digest
var dt = new Date();
var digest = dt.getTime();
this.setXRequestDigest(digest);
// update cookie
var properties = {};
var cs = com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME);
properties.path = cs.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTEXT_ROOT);
dojo.cookie("modified.id", digest, properties);
}
};
// constants
com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_LOAD = "load";
com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_ERROR = "error";
dojo.declare("com.ibm.mm.enabler.services.XHRModelHeaderExtensionImpl", null, {
constructor: function() {
this.originalDojoXHR = dojo.xhr;
dojo.xhr = dojo.hitch(this, function(/* String */method, /* dojo.__XhrArgs */ args, /* Boolean */ hasBody) {
if (!args.headers) {
args.headers = {};
}
args.headers["X-IBM-XHR"] = "true";
var ret = this.originalDojoXHR(method, args, hasBody);
return ret;
});
}
});
com.ibm.mm.enabler.services.XHRModelHeaderExtension = new com.ibm.mm.enabler.services.XHRModelHeaderExtensionImpl();
}
if(!dojo._hasResource["com.ibm.mm.enabler.endpoints.XHREndpointExtensionImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.endpoints.XHREndpointExtensionImpl"] = true;
dojo.provide("com.ibm.mm.enabler.endpoints.XHREndpointExtensionImpl");
dojo.declare("com.ibm.mm.enabler.endpoints.XHREndpointExtensionImpl", null, {
constructor: function(){
this.originalDojoXHR = dojo.xhr;
dojo.xhr = dojo.hitch(this, function(/* String */ method, /* dojo.__XhrArgs */ args, /* Boolean */ hasBody) {
var url = args.url;
var url2 = com.ibm.mm.enabler.EndpointUtils.checkForEndpoints(url);
url2 = url2 || null;
if (url2 !== null) {
args.url = url2;
}
var ret = this.originalDojoXHR(method, args, hasBody);
return ret;
});
}
});
com.ibm.mm.enabler.endpoints.XHREndpointExtension = new com.ibm.mm.enabler.endpoints.XHREndpointExtensionImpl();
}
if(!dojo._hasResource["com.ibm.mm.enabler.services.ConfigServiceExtendedImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.services.ConfigServiceExtendedImpl"] = true;
dojo.provide("com.ibm.mm.enabler.services.ConfigServiceExtendedImpl");
/*
* This is injected on the fly and not fetched through an API. Therefore we need to define the @ibm-module so that the build process is picking it up
* @ibm-module Base
*
* This value defines the order in which the packages should be printed out into the dojo profile. Default is 100.
* Any number that is smaller causes this class to be written out before any other with a higher number
* @ibm-dojo-profile-level 40
*/
// inject this service into the ServiceManager at the end. Therefore we have to require the implementation
dojo.declare("com.ibm.mm.enabler.services.ConfigServiceExtendedImpl", [com.ibm.mm.enabler.services.ConfigServiceDefaultImpl], {
constructor: function() {
},
_getConfigObject: function(/*string*/configProvider) {
if (!ibmConfig["CO_" + configProvider]) {
var co = new com.ibm.mm.enabler.services.ConfigObjectExtendedImpl(configProvider, this);
ibmConfig["CO_" + configProvider] = co;
}
return ibmConfig["CO_" + configProvider];
},
_getConfigProviderNames: function() {
// lazy load, to support dojo layer build
dojo["require"]("com.ibm.mashups.enabler.model.url.ModelUrlFactory"); // JSLINT-IGNORE: This needs to be done to allow modularization and not break the layer build
var ret = [];
ret.push("all");
var myUrl = com.ibm.mashups.enabler.model.url.ModelUrlFactory.createModelURL(com.ibm.mashups.enabler.model.url.ModelUrlFactory.CONFIG_URL, this);
myUrl.setSchemeSpecificPart("/*");
myUrl.setParameter("rep", "compact");
var serviceReq = new com.ibm.mm.enabler.services.ModelRestServiceRequest(myUrl, null, null, false, true);
var me = this;
serviceReq.read(function(type, data, xhr, args) {
var configXmls = com.ibm.mashups.enabler.xml.XPath.evaluateXPath("//atom:entry/atom:id", data, me.ns);
if (configXmls && configXmls.length > 0) {
for (var i = 0, l = configXmls.length; i < l; i++) {
var configXml = com.ibm.mm.enabler.utils.Dom.textContent(configXmls[i]);
var lastSlash = configXml.indexOf("/", 9);
configXml = configXml.substring(8, lastSlash).trim();
for (var config in ibmConfig) {
if (ibmConfig[config] === configXml) {
configXml = config.substring(15);
}
}
ret.push(configXml);
}
}
});
return ret;
}
});
com.ibm.mashups.services.ServiceManager.setService("configService", "com.ibm.mm.enabler.services.ConfigServiceExtendedImpl");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.ServiceDocumentModel_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.ServiceDocumentModel_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.ServiceDocumentModel_API");
dojo.provide("com.ibm.mashups.enabler.model.ServiceDocumentModel");
/**
* An singleton that represents the Service Document
*
* @ibm-spi
* @ibm-module Base
*
* This value defines the order in which the packages should be printed out into the dojo profile. Default is 100.
* Any number that is smaller causes this class to be written out before any other with a higher number
* @ibm-dojo-profile-level 50
*/
dojo.declare("com.ibm.mashups.enabler.model.ServiceDocumentModel", null,
{
/**
* Constant representing the navigation service
* @type {String}
*/
SERVICE_NAVIGATION: "navigation",
/**
* Constant representing the space navigation service
* @type {String}
*/
SERVICE_SPACE_NAVIGATION: "space-navigation",
/**
* Constant representing the shared navigation service
* @type {String}
*/
SERVICE_SHARED_NAVIGATION: "shared-navigation",
/**
* Constant representing the content service
* @type {String}
*/
SERVICE_CONTENT: "content",
/**
* Constant representing the catalog service
* @type {String}
*/
SERVICE_CATALOG: "catalog",
/**
* Constant representing the resource service
* @type {String}
*/
SERVICE_RESOURCE: "resource",
/**
* Constant representing the widget service
* @type {String}
*/
SERVICE_WIDGET: "widget",
/**
* Constant representing the theme service
* @type {String}
*/
SERVICE_THEME: "theme",
/**
* Constant representing the user service
* @type {String}
*/
SERVICE_USER: "user",
/**
* Constant representing generic model services
* @type {String}
*/
SERVICE_MODEL: "model",
/**
* Constant representing multipart services
* @type {String}
*/
SERVICE_MULTIPART: "multipart",
/**
* Constant representing the huffman encoding of multipart services
* @type {String}
*/
SERVICE_HUFFMAN: "huffman",
/**
* Constant representing the sitemap encoding of multipart services
* @type {String}
*/
SERVICE_SITEMAP: "sitemap",
/**
* Constant representing the commit handler sitemap encoding of multipart services
* @type {String}
*/
SERVICE_SITEMAP_COMMITHANDLER: "commit-handler",
/**
* Constant representing the composite application service
* @type {String}
*/
SERVICE_COMPOSITE: "composite-applications",
/**
* Constant representing the space service
* @type {String}
*/
SERVICE_SPACE: "application",
/**
* Constant representing the space favorites service
* @type {String}
*/
SERVICE_SPACE_FAVORITE: "application-favorite",
/**
* Constant representing the template service
* @type {String}
*/
SERVICE_TEMPLATE: "template",
/**
* Constant representing the config service
* @type {String}
*/
SERVICE_CONFIG: "config",
/**
* Constant representing the webdav filestore
* @type {String}
*/
SERVICE_FILESTORE: "filestore",
/**
* Constant representing generic webdav services
* @type {String}
*/
SERVICE_WEBDAV: "webdav",
/**
* Invalidates the Service Document Model in order for it to be re-initialized again.
*
* @type void
*/
invalidate: function() {
},
/**
* Returns a two-dimensional array of IDs representing services which are attached to a specific endpoint namespace.
* The IDs in the second dimension are required to lookup the service data.
* Example: [["webdav"],["filestore"]]
* Only the combination of both IDs make the service unique and must be used to lookup the service data
*
* @Returns {String[][]} A two-dimensional array with the second dimension being a list of IDs which represent the service.
*/
getModelCollections: function() {
},
/**
* Returns a two-dimensional array of IDs representing services which are attached to mashups specifically.
* The IDs in the second dimension are required to lookup the service data.
* Example: [["webdav"],["filestore"]]
* Only the combination of both IDs make the service unique and must be used to lookup the service data
*
* @return {String[][]} A two-dimensional array with the second dimension being a list of IDs which represent the service.
*/
getMashupsCollections: function() {
},
/**
* Returns a JSON object for a given collection link in the service document. Not all elements are mandatory.
* JSON format
* { id: "the id array",
* url :"the url",
* template :"the template",
* idprefix: "id|oid",
* namespaces : { "base" : "base-url", "model" : "model-url", "ext" : "ext-url", "creation-context" : "creation-context-url" },
* accept: "accept MIME type",
* version: "major.minor"
* }
* @param {String[]} idArray The ID Array to lookup the service for.
* @type Object
* @return {Object} Returns a JSON object for a given collection link in the service document
*/
getCollectionData: function(idArray) {
}
}
);
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.ServiceDocumentModel"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.ServiceDocumentModel"] = true;
dojo.provide("com.ibm.mm.enabler.model.ServiceDocumentModel");
dojo.declare("com.ibm.mm.enabler.model.ServiceDocumentModelImpl", com.ibm.mashups.enabler.model.ServiceDocumentModel,
{
SERVICE_NAVIGATION: "navigation",
SERVICE_SPACE_NAVIGATION: "space-navigation",
SERVICE_SHARED_NAVIGATION: "shared-navigation",
SERVICE_CONTENT: "content",
SERVICE_CATALOG: "catalog",
SERVICE_RESOURCE: "resource",
SERVICE_WIDGET: "widget",
SERVICE_THEME: "theme",
SERVICE_USER: "user",
SERVICE_MODEL: "model",
SERVICE_MULTIPART: "multipart",
SERVICE_HUFFMAN: "huffman",
SERVICE_SITEMAP: "sitemap",
SERVICE_SITEMAP_COMMITHANDLER: "commit-handler",
SERVICE_COMPOSITE: "composite-applications",
SERVICE_SPACE: "application",
SERVICE_SPACE_FAVORITE: "application-favorite",
SERVICE_TEMPLATE: "template",
SERVICE_CONFIG: "config",
SERVICE_FILESTORE: "filestore",
SERVICE_WEBDAV: "webdav",
constructor: function () {
this.prefix = "service";
this.ns = { "atom" : "http://www.w3.org/2005/Atom",
"app" : "http://www.w3.org/2007/app",
"service" : "http://www.ibm.com/xmlns/prod/sw/model/service/1.0"};
this.xmlData = null;
this.xmlDataAsString = null;
this.max_version = null;
this.cache = [];
},
getInstance: function() {
var instance = com.ibm.mm.enabler.model.ServiceDocumentModelImpl._instance;
return instance ? instance : (com.ibm.mm.enabler.model.ServiceDocumentModelImpl._instance = new com.ibm.mm.enabler.model.ServiceDocumentModelImpl());
},
invalidate: function() {
this.xmlData = null;
this.max_version = null;
},
_loadAhead: function() {
// lazy load, to support dojo layer build
dojo["require"]("com.ibm.mashups.enabler.model.url.ModelUrlFactory"); // JSLINT-IGNORE: This needs to be done to allow modularization and not break the layer build
if (ibmConfig.servicedocument) {
if (this.xmlDataAsString != ibmConfig.servicedocument) {
this.xmlData = null;
}
}
if (this.xmlData) {
return;
}
if (ibmConfig.servicedocument) {
this.xmlData = dojox.xml.parser.parse( ibmConfig.servicedocument );
this.xmlDataAsString = ibmConfig.servicedocument;
} else {
var myUrl;
if (ibmConfig.serviceDocumentUrl) {
myUrl = new com.ibm.mm.enabler.utils.HttpUrl(ibmConfig.serviceDocumentUrl);
} else {
myUrl = com.ibm.mashups.enabler.model.url.ModelUrlFactory.createModelURL("service", null);
myUrl.setNodes([{
value: "collection",
isID: false
}]);
}
var serviceReq = new com.ibm.mm.enabler.services.ModelRestServiceRequest(myUrl, null, null, false, true);
serviceReq.read(
dojo.hitch(this,
function (type, data, xhr, args) {
if (type == com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_LOAD) {
this.xmlData = data;
} else if (type == com.ibm.mm.enabler.services.ModelRestServiceRequest.XHR_STATUS_ERROR) {
// TODO
}
}
)
);
}
this._fillCache();
},
_fillCache: function() {
this.max_version = null;
if (ibmConfig.servicedocument_version_max) {
this.max_version = parseInt(ibmConfig.servicedocument_version_max.replace(/\./g, ""),10);
}
var matches = [];
var i, l, found;
var expr = "//app:collection";
var nodes = com.ibm.mashups.enabler.xml.XPath.evaluateXPath(expr, this.xmlData, this.ns);
for (i=0, l = nodes.length; i
* @return {DeferredOperation} a deferred object used to start this operation.
* The return value when executed through the deferred object is null
*/
commit: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.DefaultLocalized"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.DefaultLocalized"] = true;
dojo.provide("com.ibm.mashups.enabler.DefaultLocalized");
/**
* Read-Only interface providing methods to obtain default title, description,
* and locale
* @ibm-spi
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.DefaultLocalized", null, {
/**
* Returns the default locale.
*
* @return {String} the default locale; may be null
.
*/
getDefaultLocale: function(){
},
/**
* Returns the default title.
* @return {String} the default title of this node; may be null
.
*/
getDefaultTitle: function(){
},
/**
* Returns the default description of this object.
* @return {String} the default description; may be null
.
*/
getDefaultDescription: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Iterator"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Iterator"] = true;
dojo.provide("com.ibm.mashups.enabler.Iterator");
/**
* Extended iterator interface, which allows iterating over elements
* in a sequentiell order. It allows to set the starting point of the
* iteration and exposes the number of elements in the iteration.
*
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.Iterator", null, {
/**
* Returns true if the iteration has more elements.
* @return {Boolean} true if the iterator has more elements,
* otherwise false.
*/
hasNext: function(){
},
/**
* Returns the next element in the iteration. Calling this method
* repeatedly until the hasNext() method returns false will return
* each element in the underlying collection exactly once.
* The cursor position is increased by one. if no element is available
* at the specified position, null
is returned and the
* position is not changed
*
* @returns {Object} the next element in the iteration
*/
next: function(){
},
/**
* Returns the number of elements in this iterator.
*
* @return {com.ibm.mashups.enabler.Deferred} a deferred object used to start this operation. The
* return value when executed through the deferred object
* is the number of elements in this iterator
*/
size: function(){
},
/**
* Sets the zero-based position of the cursor, i.e the last
* element is addressed through size()-1.
* A position which is out of the bounds of the current iteration
* is ignored and in this case the position is set to the nearest
* possible value within valid bounds.
*
* @param {int} position position of the cursor. Defaults to zero
* @type void
*/
setCursorPosition: function(position){
},
/**
* Returns the zero-based position of the cursor, i.e. zero for the first element
*
* @return {int} the position of the cursor
*/
getCursorPosition: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.DeferredIterator_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.DeferredIterator_API"] = true;
dojo.provide("com.ibm.mashups.enabler.DeferredIterator_API");
dojo.provide("com.ibm.mashups.enabler.DeferredIterator");
/**
* The DeferredIterator can be used to iterate over a list of objects
* in an asynchronous fashion. The callback handler is called as
* soon as the next object has been loaded.
* The start method is only used for the asynchronous aspect of
* the deferred iterator. For the synchronous aspect the methods
* such as hasNext() can be called directly.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.DeferredIterator", [com.ibm.mashups.enabler.Deferred, com.ibm.mashups.enabler.Iterator], {
/**
* Sets the handler of the deferred action. It is called when the
* next object in the list has been loaded and is ready to be processed.
* @param {Object} callback the callback funtion in the format of Function(object nextElement, Object[] params)
. Must not be null
* Callbackparameters
* nextElement
- the next
* object in the list
* params
- the parameters
* passed into the addForEachCallback
* @param {Object[]} parameters optional array of parameters to be
* passed on to the callback function
* @return {com.ibm.mashups.enabler.DeferredIterator} the deferred object
*/
setForEachCallback: function(callback, parameters){
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.DeferredIteratorImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.DeferredIteratorImpl"] = true;
dojo.provide("com.ibm.mm.enabler.DeferredIteratorImpl");
// iterator
dojo.declare("com.ibm.mm.enabler.DeferredIteratorImpl", [com.ibm.mashups.enabler.DeferredIterator, com.ibm.mm.enabler.DeferredImpl], {
setForEachCallback: function(callback, parameters){
this.foreachCallback = callback;
this.foreachCallbackParameters = parameters;
return this;
},
/**
* there's a typo in this one, keeping it around for backwards compat
*
* @param {Object} callback
* @param {Object} parameters
*/
setForeachCallback: function(callback, parameters){
return this.setForEachCallback(callback, parameters);
},
getForeachCallback: function(){
return this.foreachCallback;
},
getForeachCallbackParameters: function(){
return this.foreachCallbackParameters;
},
nextFinish: function(entry) {
if(dojo.isFunction(this.getForeachCallback())) {
// call callback
dojo.partial(this.getForeachCallback())(entry, this.getForeachCallbackParameters());
}
},
start: function(sync){
while (this.hasNext(this, sync)) {
this.next(this, sync);
}
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.DeferredIterator"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.DeferredIterator"] = true;
dojo.provide("com.ibm.mashups.enabler.DeferredIterator");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.DeferredOperation_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.DeferredOperation_API"] = true;
dojo.provide("com.ibm.mashups.enabler.DeferredOperation_API");
dojo.provide("com.ibm.mashups.enabler.DeferredOperation");
/**
* In addition to the Deferred interface, which allows to trigger callbacks after the
* entire action has finished, the DeferredOperation interface allows to trigger a
* callback for each involved operation.
* @ibm-api
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.DeferredOperation", [com.ibm.mashups.enabler.Deferred], {
/**
* Mode of operation: retrieving a resource
* @type String
*/
OPERATION_GET: "GET",
/**
* Mode of operation: creating a resource
* @type String
*/
OPERATION_CREATE: "CREATE",
/**
* Mode of operation: modifying a resource
* @type String
*/
OPERATION_MODIFY: "MODIFY",
/**
* Mode of operation: deleting a resource
* @type String
*/
OPERATION_DELETE: "DELETE",
/**
* Sets the handler of the deferred action. The handler is called for each
* operation the action involves.
* @param {Object} callback the callback funtion in the format of Function(Object node, string mode, int statusCode, Object[] params)
. Must not be null
* Callbackparameters
* node
- resource object or string id of the
* related resource, depending on the operation. For example, when a resource is created, the
* resource itself is returned. In case of a delete operation, the id is returned
* instead.
* mode
- the mode of the operation.
* May be one of OPERATION_GET
, OPERATION_CREATE
,
* OPERATION_MODIFY
, or OPERATION_DELETE
.
* statusCode
- the overall HTTP status code
* of the operation.
* params
- the parameters
* passed into the callback
* @param {Object[]} parameters optional array of parameters to be
* passed on to the callback function. May be null
* @return {com.ibm.mashups.enabler.DeferredOperation} the deferred object
*/
setOperationCallback: function(callback, parameters) {
}
});
com.ibm.mashups.enabler.DeferredOperation.OPERATION_GET = "GET";
com.ibm.mashups.enabler.DeferredOperation.OPERATION_CREATE = "CREATE";
com.ibm.mashups.enabler.DeferredOperation.OPERATION_MODIFY = "MODIFY";
com.ibm.mashups.enabler.DeferredOperation.OPERATION_DELETE = "DELETE";
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.HttpStatusCodes"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.HttpStatusCodes"] = true;
dojo.provide("com.ibm.mm.enabler.model.HttpStatusCodes");
dojo.provide("com.ibm.mm.enabler.model.HttpStatusCodesImpl");
dojo.declare("com.ibm.mm.enabler.model.HttpStatusCodesImpl", null, {
HTTP_CONTINUE: "100",
HTTP_SWITCHING_PROTOCOLS: "101",
HTTP_OK: "200",
HTTP_CREATED: "201",
HTTP_BAD_REQUEST: "400",
HTTP_NOT_FOUND: "404",
HTTP_REQUEST_TIMEOUT: "408",
HTTP_INTERNAL_SERVER_ERROR: "500",
HTTP_SERVICE_UNAVAILABLE: "503"
});
com.ibm.mm.enabler.model.HttpStatusCodes = new com.ibm.mm.enabler.model.HttpStatusCodesImpl();
}
if(!dojo._hasResource["com.ibm.mm.enabler.DeferredOperationImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.DeferredOperationImpl"] = true;
dojo.provide("com.ibm.mm.enabler.DeferredOperationImpl");
// operation
dojo.declare("com.ibm.mm.enabler.DeferredOperationImpl", [com.ibm.mashups.enabler.DeferredOperation, com.ibm.mm.enabler.DeferredImpl], {
operationCallback: null,
operationCallbackParameters: null,
setOperationCallback: function(callback, parameters){
this.operationCallback = callback;
this.operationCallbackParameters = parameters;
return this;
},
getOperationCallback: function(){
return this.operationCallback;
},
getOperationCallbackParameters: function(){
return this.operationCallbackParameters;
},
finishOperation: function(result, operation, status) {
if(dojo.isFunction(this.getOperationCallback())) {
// call callback
if(dojo.isOpera && status === 0) {
status = com.ibm.mm.enabler.model.HttpStatusCodes.HTTP_NOT_FOUND;
}
dojo.partial(this.getOperationCallback())(result, operation, status, this.getOperationCallbackParameters());
}
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.DeferredOperation"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.DeferredOperation"] = true;
dojo.provide("com.ibm.mashups.enabler.DeferredOperation");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.DirtyFlagProvider_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.DirtyFlagProvider_API"] = true;
dojo.provide("com.ibm.mashups.enabler.DirtyFlagProvider_API");
dojo.provide("com.ibm.mashups.enabler.DirtyFlagProvider");
/**
* Base interface that allows to track whether a node or model has been modified (i.e. became dirty).
*
* @since 3.0.0.1
* @ibm-spi
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.DirtyFlagProvider", null, {
/**
* Tests whether the instance is dirty. Instances that have been modified, or newly created return true.
*
* @return {Boolean} true if the instance is dirty, otherwise false.
*/
isDirty: function() {},
/**
* Marks this instance as dirty.
*/
setDirty: function() {},
/**
* Marks this instance as not dirty, i.e. clean.
*/
setClean: function() {},
/**
* Adds a callback handler to be called when the instance changes its state.
*
* @param {Object} ctx The context in which to run the callback handler
* Must not be null
* @param {Object} callback the callback funtion in the format of Function(Object[] passed in with addDirtyCallback)
.
* Must not be null
* @param {Object[]} parameters optional array of parameters to be
* passed on to the callback function. May be null
* @param {Boolean} alwaysFire Specifies whether to only fire when clean->dirty (set flag to false) or also fire when dirty->dirty (set flag to true)
*/
addDirtyCallback: function(ctx, callback, parameters, alwaysFire) {
},
/**
* Removes a callback handler previously added
*
* @param {Object} callback the callback funtion to be removed.
* Must not be null
*/
removeDirtyCallback: function(fn){
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.DirtyFlagProviderImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.DirtyFlagProviderImpl"] = true;
dojo.provide("com.ibm.mm.enabler.DirtyFlagProviderImpl");
dojo.declare("com.ibm.mm.enabler.DirtyFlagProviderImpl", com.ibm.mashups.enabler.DirtyFlagProvider, {
_dirty: false,
setDirty: function() {
this._setDirty();
},
_setDirty: function() {
var wasFalse = this._dirty === false;
this._dirty = true;
if (this._dirtyCallbacks) {
dojo.forEach(this._dirtyCallbacks, function(cb) {
if ((wasFalse || cb.alwaysFire) && dojo.isFunction(cb.fn)) {
dojo.hitch(cb.ctx || null, cb.fn)(cb.args);
}
}, this);
}
},
setClean: function() {
this._setClean();
},
_setClean: function() {
this._dirty = false;
},
isDirty: function() {
return this._dirty;
},
_isDirty: function() {
return this._dirty;
},
addDirtyCallback: function(ctx, fn, args, alwaysFire) {
this._addDirtyCallback(ctx, fn, args, alwaysFire);
},
/**
* ctx = context
* fn = function to call
* args = arguments to that function
* alwaysFire (boolean) = whether to only fire when clean->dirty (set flag to false) or also fire when dirty->dirty (set flag to true)
*/
_addDirtyCallback: function(ctx, fn, args, alwaysFire) {
if (!this._dirtyCallbacks) {
this._dirtyCallbacks = [];
}
this._dirtyCallbacks.push({
ctx: ctx,
fn: fn,
args: args,
alwaysFire: !!alwaysFire
});
},
removeDirtyCallback: function(fn) {
this._removeDirtyCallback(fn);
},
_removeDirtyCallback: function(fn) {
if (this._dirtyCallbacks) {
for (var i = this._dirtyCallbacks.length; i > 0; i--) {
if (fn === this._dirtyCallbacks[i - 1].fn) {
this._dirtyCallbacks.splice(i - 1, 1);
break;
}
}
}
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.DirtyFlagProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.DirtyFlagProvider"] = true;
dojo.provide("com.ibm.mashups.enabler.DirtyFlagProvider");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Discardable_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Discardable_API"] = true;
dojo.provide("com.ibm.mashups.enabler.Discardable_API");
dojo.provide("com.ibm.mashups.enabler.Discardable");
/**
* Discardable interface, which allows to discard artifacts or the whole
* model.
*
* @since 2.4
*
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.Discardable", null, {
/**
* Discards the specified node, or the whole model if no node is specified.
* @parameter {Object} node node to discard, must not be null
; optional
* @type void
*/
discard : function(node) {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Discardable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Discardable"] = true;
dojo.provide("com.ibm.mashups.enabler.Discardable");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Identifiable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Identifiable"] = true;
dojo.provide("com.ibm.mashups.enabler.Identifiable");
/**
* Interface for any resource in the system that can be identified
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.Identifiable", null, {
/**
* Returns the ID of the resource that implements the Identifiable
interface.
* @return {String} the identifier; never null
*/
getID: function(){
},
/**
* Returns the unique name of the resource that implements the Identifiable
interface.
* @return {String} the unique name; never null
* @private
*/
getUniqueName: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Invalidatable_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Invalidatable_API"] = true;
dojo.provide("com.ibm.mashups.enabler.Invalidatable_API");
dojo.provide("com.ibm.mashups.enabler.Invalidatable");
/**
* Invalidatable interface, which allows to invalidate artifacts or the whole
* model.
*
* @since 2.4
*
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.Invalidatable", null, {
/**
* Invalidates the specified node, or the whole model if no node is specified.
*
* @param {Object} node node to invalidate, must not be null
; optional
* @type void
*/
invalidate : function(node) {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Invalidatable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Invalidatable"] = true;
dojo.provide("com.ibm.mashups.enabler.Invalidatable");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Locator"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Locator"] = true;
dojo.provide( "com.ibm.mashups.enabler.Locator");
/**
* This interface defines search methods that allow locating resources in a model.
* A resource is identified by its ID (mandatory). This interface is the base for all locators;
* other locators allow a more specific search in the context they are offered in,
* e.g. a search for a node with certain properties in a model.
* A Locator
is usually obtained using the getLocator()
method .
*
* var treeModel model = ...;
* var locator = model.getLocator();
* var node = locator.find(...);
*
* This locator returns an {@code Object} which is part of some model.
* What exact kind of object is returned depends on the locator.
* Please refer to individual JavaScriptDoc for the locator used.
* The result object can be expected to be an element of the model
* the locator is used on unless specified otherwise.
* @ibm-api
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.Locator", null, {
/**
* Returns an element of a model with the given ID.
* @param {com.ibm.mashups.enabler.Identifiable} id identifiable or string id of the object to find;
* must not be null
.
* @return {com.ibm.mashups.enabler.Deferred} a deferred object used to start this operation.
* The return value when executed through the deferred object is
* the element with the given ID or null
if the element cannot be found.
*/
find: function (id) {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.ListModel"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.ListModel"] = true;
dojo.provide("com.ibm.mashups.enabler.ListModel");
/**
* A read-only model representing a list. Acting as a base class for all concrete list models.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.ListModel", [com.ibm.mashups.enabler.model.Model, com.ibm.mashups.enabler.Locator], {
/**
* Returns an iterator over elements of the list.
*
* @return {com.ibm.mashups.enabler.DeferredIterator} a deferred iterator
*/
iterator: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.ListModelController"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.ListModelController"] = true;
dojo.provide("com.ibm.mashups.enabler.ListModelController");
/**
* A modifiable model representing a list. Acting as a base class for all concrete list models.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.ListModelController", com.ibm.mashups.enabler.ListModel, {
/**
* Creates a new model object. The created node can be inserted
* into the model using an appropriate insert
method defined
* on a subinterface of this interface. The node will not appear in the model
* unless it is inserted.
* @param {JSON} context array of predefined information
* used for the creation of the node. May be null
. Accepted
* names are defined in the appropriate subinterfaces
* @type Object
* @return the created node
*/
create: function(context){
},
/**
* Confirms whether creating the node is possible.
* @param {JSON} context array of predefined information
* used for the creation of the node. May be null
. Accepted
* names are defined in the appropriate subinterfaces
* @return {Boolean} true if the node can be created, otherwise false.
*/
confirmCreate: function(context){
},
/**
* Inserts the specified node into the list model at the specified
* position; the node must be created with the create method of the
* concrete ListModel
*
* @param {Object} node node or node uri (without any scope) to
* insert into the list model. Must not be
* null
* @param {Object} nextNode node object or node uri (without any scope) of
* the successor node before which the node
* is to be inserted;
* if null
is specified, the
* node is appended at the end of the existing nodes
* @type void
*/
insert: function(node, nextNode){
},
/**
* Confirms whether inserting the node is possible.
* @param {Object} node node or node uri (without any scope) to
* insert into the list model. Must not be
* null
* @param {Object} nextNode node object or node uri (without any scope) of
* the successor node before which the node
* is to be inserted;
* if null
is specified, the
* node is appended at the end of the existing nodes
* @return {Boolean} true if the node can be inserted, otherwise false.
*/
confirmInsert: function(node, nextNode){
},
/**
* Removes the specified node from the list model
*
* @param{Object} node node object or node uri (without any scope).
* Must not be null
* @type void
*/
remove: function(node){
},
/**
* Confirms whether removing the node is possible.
* @param{Object} node node object or node uri (without any scope).
* Must not be null
* @return {Boolean} true if the node can be removed, otherwise false.
*/
confirmRemove: function(node){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Localized_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Localized_API"] = true;
dojo.provide("com.ibm.mashups.enabler.Localized_API");
dojo.provide("com.ibm.mashups.enabler.Localized");
/**
* Read-Only interface providing methods to obtain title and description of a
* resource. Please note that title or description are only returned if they
* are available in the requested locale. No fallback for locales is performed.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.Localized", null, {
/**
* Returns an array containing the locales that are supported by this
* object. The presence of a locale in this list does not mean that a title
* and description is available, but rather that either one or both
* are available in that locale.
*
* Note: Modifying the array does not change the supported locales.
* @return {String[]} a list of locales defined for this object, returns an
* empty array if no locales are supported. Can never be null
.
*/
getLocales: function(){
},
/**
* Returns the title of this object in the given locale.
* @param {String} locale the locale for which to retrieve the title,
* must not be null
.
* @return {String} the title of this node in the given locale. If a title is not
* available in the given locale, this method will return null
.
* It is up to the invoker of the method to implement an appropriate fallback mechanism.
*/
getTitle: function(locale){
},
/**
* Returns the titles of this object in a map (key: locale, value: title).
*
* @param {String} locale (optional) the locale for which to retrieve the titles, can be null
. If locale is null/omitted, all are returned.
* @return {Object} the titles of this node in a locale<->title map. If a locale was given, the result will be a map containing only those locales with country specific matches (e.g. if you give a locale "pt", you might also get brazilian portugese ("pt-BR") - if you give a locale "zh-TW", you won't get "zh"). If there are no titles (matching the given locale), an empty object will be returned.
*
* @since 3.0
*/
getTitles: function(){
},
/**
* Returns the description of this object in the given locale.
* @param {String} locale the locale for which to retrieve the
* description, must not be null
.
* @return {String} the description of this node in the given locale. If a
* description is not available in the given locale, this method
* will return null
. It is up to the invoker of the
* method to implement an appropriate fallback mechanism.
*/
getDescription: function(locale){
},
/**
* Returns the descriptions of this object in a map (key: locale, value: description).
*
* @param {String} locale (optional) the locale for which to retrieve the descriptions, can be null
. If locale is null/omitted, all are returned.
* @return {Object} the descriptions of this node in a locale<->description map. If a locale was given, the result will be a map containing only those locales with country specific matches (e.g. if you give a locale "pt", you might also get brazilian portugese ("pt-BR") - if you give a locale "zh-TW", you won't get "zh"). If there are no descriptions (matching the given locale), an empty object will be returned.
*
* @since 3.0
*/
getDescriptions: function(locale){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.ModifiableLocalized"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.ModifiableLocalized"] = true;
dojo.provide("com.ibm.mashups.enabler.ModifiableLocalized");
/**
* Modifiable interface providing methods to set title and description of a
* resource.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.ModifiableLocalized", com.ibm.mashups.enabler.Localized, {
/**
* Sets the title for the given locale.
* @param {String} title title to set; must not be null
* @param {String} locale locale to set the title for; must not be null
* @return {String} the former title; if none existed, null
is returned
*/
setTitle: function(title, locale){
},
/**
* Confirms whether setting the title for the given locale is possible.
* @param {String} title title to set; must not be null
* @param {String} locale locale to set the title for; must not be null
* @return {Boolean} true if the value can be set, otherwise false.
*/
confirmSetTitle: function(title, locale){
},
/**
* Removes the title for the given locale.
* @param {String} locale locale of the title to remove; must not be null
* @type void
*/
removeTitle: function(locale){
},
/**
* Indicates if the title for the specified locale may be removed.
* @param {String} locale locale for which to indicate if the title may be removed; must not be null
* @return {Boolean} true
if the title can be removed, otherwise false
.
*/
confirmRemoveTitle: function(locale){
},
/**
* Removes all titles.
* @type void
*/
removeTitles: function(){
},
/**
* Indicates if the titles for all locales may be removed.
* @return {Boolean} true
if all titles can be removed, otherwise
* false
.
*/
confirmRemoveTitles: function(){
},
/**
* Sets the description for the given locale.
* @param {String} desc description to set; must not be null
* @param {String} locale locale to set the description for; must not be null
* @return {String} the former description; if none existed, null
is returned
*/
setDescription: function(desc, locale){
},
/**
* Confirms whether setting the description for the given locale is possible.
* @param {String} desc description to set; must not be null
* @param {String} locale locale to set the description for; must not be null
* @return {Boolean} true if the value can be set, otherwise false.
*/
confirmSetDescription: function(desc, locale){
},
/**
* Removes the description for the given locale.
* @param {String} locale locale of the description to remove; must not be null
* @type void
*/
removeDescription: function(locale){
},
/**
* Indicates if the description for the specified locale may be removed.
* @param {String} locale locale for which to indicate if the description may be removed; must not be null
* @return {Boolean} true
if the description can be removed, otherwise false
.
*/
confirmRemoveDescription: function(locale){
},
/**
* Removes all description.
* @type void
*/
removeDescriptions: function(){
},
/**
* Indicates if the description for all locales may be removed.
* @return {Boolean} true
if all descriptions can be removed, otherwise
* false
.
*/
confirmRemoveDescriptions: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Localized"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Localized"] = true;
dojo.provide("com.ibm.mashups.enabler.Localized");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Representation_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Representation_API"] = true;
dojo.provide("com.ibm.mashups.enabler.Representation_API");
dojo.provide("com.ibm.mashups.enabler.Representation");
/**
* An interface that allows retrieving a URL and mime type representing the resource.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.Representation", com.ibm.mashups.enabler.Identifiable, {
/**
* Returns the mimetype of the representation.
* @return {String} the identifier; never null
*/
getID: function(){
},
/**
* Returns a full or absolute URL pointing to the resource in another representation.
* @return {String} the URL pointing to the other representation; never null
*/
getURL: function(){
},
/**
* Returns the mimetype of the content to which the URL is pointing to.
* @return {String} the mimetype; never null
*/
getMimeType: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.RepresentationImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.RepresentationImpl"] = true;
dojo.provide( "com.ibm.mm.enabler.RepresentationImpl");
// representation
dojo.declare( "com.ibm.mm.enabler.RepresentationImpl", com.ibm.mashups.enabler.Representation,
{
constructor:function (url, type) {
this.url = url;
this.type = type;
},
getID: function() {
return this.type;
},
getURL: function() {
return this.url;
},
getMimeType: function() {
return this.type;
}
}
);
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Representation"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Representation"] = true;
dojo.provide("com.ibm.mashups.enabler.Representation");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.RepresentationProvider_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.RepresentationProvider_API"] = true;
dojo.provide("com.ibm.mashups.enabler.RepresentationProvider_API");
dojo.provide("com.ibm.mashups.enabler.RepresentationProvider");
/**
* An interface that allows to retrieve information about different representations of the resource.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.RepresentationProvider", null, {
/**
* Returns a ListModel containing information about the alternate representations available. The model contains Representation
objects .
* @see com.ibm.mashups.enabler.Representation
* @return {com.ibm.mashups.enabler.ListModel} ListModel containing alternate representations of the resource; never null
*/
getAlternateModel: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.RepresentationModelImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.RepresentationModelImpl"] = true;
dojo.provide("com.ibm.mm.enabler.RepresentationModelImpl");
// alternate representation list model
dojo.declare("com.ibm.mm.enabler.RepresentationModelImpl", [com.ibm.mashups.enabler.ListModel, com.ibm.mm.enabler.DeferredIteratorImpl], {
constructor: function(nodes) {
this.loadedNodes = {};
this.entries = [];
this.cursor = 0;
this.size = null;
this.start = null;
this.num = null;
this.strategy = null;
// now fill in loadedNodes and entries
if (nodes && nodes.length > 0) {
this.size = nodes.length;
for (var i = 0; i < nodes.length; i++) {
var link = nodes[i];
var url = link.getAttribute("href");
var mimetype = link.getAttribute("type");
// create a new representation node
var uri = mimetype;
var node = new com.ibm.mm.enabler.RepresentationImpl(url, mimetype);
// setup the internal objects
this.entries[i] = uri;
this.loadedNodes[uri] = node;
}
}
},
find: function(uri) {
return new com.ibm.mm.enabler.DeferredImpl(this, this._find, uri);
},
_find: function(deferred, sync, uri) {
return this._load(uri, deferred, sync);
},
start: function(sync) {
while (this._hasNext(this, sync)) {
if (this._next(this, sync)) {
continue;
}
else {
break;
}
}
},
hasNext: function() {
return this._hasNext(null, true);
},
_hasNext: function(deferred, sync) {
if (this.start === null || this.cursor < this.start || (this.cursor >= (this.start + this.num) && (this.size > this.cursor))) {
this._loadAhead(deferred, sync);
}
return (this.size > this.cursor);
},
next: function() {
return this._next(null, true);
},
_next: function(deferred, sync) {
return this._hasNext(deferred, sync) ? this.loadedNodes[this.entries[this.cursor++]] : null;
},
size: function() {
return this.size;
},
setCursorPosition: function(position) {
this.cursor = position;
},
getCursorPosition: function() {
return this.cursor;
},
setStrategy: function(strategy) {
if (com.ibm.mm.enabler.utils.Misc.isInstanceOf(strategy, Array)) {
// evaluate the first strategy only
this.strategy = strategy[0];
}
else {
// backwards compatibility
this.strategy = strategy;
}
},
_load: function(uri, deferred, sync) {
if (uri in this.loadedNodes) {
// fetch node from cache
if(deferred) { deferred.finish(this.loadedNodes[uri], com.ibm.mm.enabler.model.HttpStatusCodes.HTTP_OK); }
}
return this.loadedNodes[uri];
},
_loadAhead: function(deferred, sync) {
// noop
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.RepresentationProviderImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.RepresentationProviderImpl"] = true;
dojo.provide("com.ibm.mm.enabler.RepresentationProviderImpl");
// representation provider
dojo.declare("com.ibm.mm.enabler.RepresentationProviderImpl", com.ibm.mashups.enabler.RepresentationProvider, {
constructor: function() {
// service document and initialization
this.serviceJson = com.ibm.mm.enabler.model.ServiceDocumentModel.getCollectionData(com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_NAVIGATION);
var nsf = com.ibm.mm.enabler.model.NameSpaceFactory;
this.r_ns = dojo.delegate(this.serviceJson.namespaces, nsf.getNameSpaces([nsf.NS_ATOM, nsf.NS_XML]));
this.XPATH = "atom:link";
},
getAlternateModel: function() {
var validLinks = [];
var md = com.ibm.mashups.enabler.xml.XPath.evaluateXPath(this.XPATH, this.xmlData, this.r_ns);
if (md && md.length > 0) {
for (var i = 0, l = md.length; i < l; i++) {
var link = md[i];
var rel = link.getAttribute("rel");
var extrel = com.ibm.mm.enabler.utils.Dom.getAttributeWithNS(link, "ext:rel", "rel", this.r_ns.ext);
if (extrel == "") {
extrel = null;
}
if (((!rel) || (rel == 'alternate')) && (!extrel)) {
validLinks[validLinks.length] = link;
}
}
}
var model = new com.ibm.mm.enabler.RepresentationModelImpl(validLinks);
return model;
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.RepresentationProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.RepresentationProvider"] = true;
dojo.provide("com.ibm.mashups.enabler.RepresentationProvider");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.ResourceLocator"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.ResourceLocator"] = true;
dojo.provide("com.ibm.mashups.enabler.ResourceLocator");
/**
* Interface for finding resources within a model.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.ResourceLocator", com.ibm.mashups.enabler.Locator, {
/**
* Returns the URL of the resource to be located, or null
if the resource cannot be found.
* @param {Object} node A node of the model this locator is implemented on. Must not be null
.
* @param {String} name The name of the resource to be located within the given model. The name can also contain a directory path relative to the model. Must not be null
.
* @return {String} The URL that can be used to fetch the resource, or null
if the resource cannot be found.
* @deprecated Use findResourceURL instead.
*/
findResourceUrl: function(node, name){
},
/**
* Returns the URL of the resource to be located, or null
if the resource cannot be found.
* @param {Object} node A node of the model this locator is implemented on. Must not be null
.
* @param {String} name The name of the resource to be located within the given model. The name can also contain a directory path relative to the model. Must not be null
.
* @return {String} The URL that can be used to fetch the resource, or null
if the resource cannot be found.
*/
findResourceURL: function(node, name){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.SubmittableForm_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.SubmittableForm_API"] = true;
dojo.provide("com.ibm.mashups.enabler.SubmittableForm_API");
dojo.provide("com.ibm.mashups.enabler.SubmittableForm");
/**
* An interface representing a submittable form. Submittable forms can be used
* to import resources of models, which implement the SubmittableFormProvider
* interface, for example spaces or templates. The provider of submittable forms
* automatically set the necessary URL parameters, such as enctype, action and method.
* To submit a submittable form, you invoke the submit()-method, which in turn
* imports the resource using an appropriate xhr request.
* Example:
*
* var form = spaceModel.getSubmittableImportForm(spaceId);
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.SubmittableForm", com.ibm.mashups.enabler.Identifiable, {
/**
* Returns the URL this form is submitted to. Used to fill in the action attribute in the form.
* @return {String} the URL this form is submitted to; never
* form.submit().start();
* null
*/
getURL: function(){
},
/**
* Returns the HTTP method used to submit this form. Used to fill in the method attribute in the form.
* @return {String} the method; never null
*/
getMethod: function(){
},
/**
* Submits the form
* @return {com.ibm.mashups.enabler.Deferred} a deferred object used to start this operation.
*/
submit: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.SubmittableFormImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.SubmittableFormImpl"] = true;
dojo.provide("com.ibm.mm.enabler.SubmittableFormImpl");
dojo.declare("com.ibm.mm.enabler.SubmittableFormImpl", com.ibm.mashups.enabler.SubmittableForm, {
constructor: function(url, method, formId){
this.url = url;
this.method = method;
this.formId = formId;
},
/**
* Returns the URL this form is submitted to. Used to fill in the action attribute in the form.
* @return {String} the URL this form is submitted to; never null
*/
getURL: function(){
return this.url;
},
/**
* Returns the HTTP method used to submit this form. Used to fill in the method attribute in the form.
* @return {String} the method; never null
*/
getMethod: function(){
return this.method;
},
/**
* Submits the form
* @return {com.ibm.mashups.enabler.Deferred} a deferred object used to start this operation.
*/
submit: function(){
return new com.ibm.mm.enabler.DeferredImpl(this, this._submit);
},
/**
* Submits the form
* @return {com.ibm.mashups.enabler.Deferred} a deferred object used to start this operation.
*/
_submit: function(deferred){
dojo.io.iframe.send({
url: this.url,
method: this.method,
handleAs: "text",
// For IE issue
form: document.getElementsByName(this.formId)[0],
load: function(data, ioArgs){
if(deferred) { deferred.finish(data, com.ibm.mm.enabler.model.HttpStatusCodes.HTTP_CREATED); }
},
error: function(data, ioArgs){
if(deferred) { deferred.finish(data, com.ibm.mm.enabler.model.HttpStatusCodes.HTTP_NOT_FOUND); }
}
});
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.SubmittableForm"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.SubmittableForm"] = true;
dojo.provide("com.ibm.mashups.enabler.SubmittableForm");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.SubmittableFormProvider_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.SubmittableFormProvider_API"] = true;
dojo.provide("com.ibm.mashups.enabler.SubmittableFormProvider_API");
dojo.provide("com.ibm.mashups.enabler.SubmittableFormProvider");
/**
* An interface that allows to retieve submittable form
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.SubmittableFormProvider", null, {
/**
* Returns a SubmittableForm object associated with the given id.
* @param {String} id the id of the html form this object is associated with
* @return {com.ibm.mashups.enabler.SubmittableForm} SubmittableForm object, maybe null
*/
getSubmittableForm: function(id){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.url.ModelUrl_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.url.ModelUrl_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.url.ModelUrl_API");
dojo.provide("com.ibm.mashups.enabler.model.url.ModelUrl");
/**
* Interface representing a model URL. This class should be used by the specific model
* API's in order to generate a valid model URL. The low level classes like ModelRestServiceRequest
* expect a request to be made with an implementation of the interface. It also allows an easy way
* to handle URIs. e.g.
* <scheme>:<primaryNode>@<secondaryNode>
scheme-specific part = <primaryNode>@<secondaryNode>
*
* @ibm-spi
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.model.url.ModelUrl", null, {
/**
* @private
*/
constructor: function () {
},
/**
* Sets the nodes of the scheme-specific part.
* @param {JSONArray} nodes an array containing the nodes of the scheme-specific part in a JSON notation way.
* The ordering of the array elements specifies the position of the node, meaning
* the array element 0 will become node 1 and so on and so forth.
* valid JSON attributes are:
*
*
* example for "nodes":
*
* [ {
* @type {void}
*/
setNodes: function(nodes) {
},
/**
* Sets the scheme-specific part of the unerlying URI.
* @param {String} value the value for the scheme-specifc part. (Must not be
* value: "100",
* isID: false,
* subModel: "member"
* } ]
* null
)
* @type {void}
*/
setSchemeSpecificPart: function (value) {
},
/**
* Returns the scheme-specific part of the underlying URI.
* @type {String}
* @return the scheme-specific part. If a scheme-specific part was set through setSchemeSpecificPart
* the raw value will be returned. If the SSP was set by using setNodes
,
* the converted part will be returned. If neither a node nor the raw SSP was set,
* this method returns null
.
*/
getSchemeSpecificPart: function() {
return null;
},
/**
* Adds the value of the specified parameter.
* @param {String} name the name of the parameter; must not be null
.
* @param {String} value the value of the parameter. Valid is only a single String. (Must not be null
)
* @type {void}
*/
addParameter: function (name, value) {
},
/**
* Sets the value(s) of the specified parameter.
* @param {String} name the name of the parameter; must not be null
.
* @param {String} value the value of the parameter. Valid are either a single String or a String array. (Must not be null
)
* @type {void}
*/
setParameter: function (name, value) {
},
/**
* Returns the value(s) of the specified parameter.
* @param {String} name the name of the parameter; must not be null
.
* @type {String}
* @return the value(s) of the specified parameter or null
if the specified parameter wasn't found. In case the parameter has one value
* the return type is String. For multiple values a String array is returned.
*/
getParameter: function (name) {
return null;
},
/**
* Returns the parameters as an object. Note: this must be used read-only
* @type {JSON}
* @return an object containing all parameters in the format { <name>: [<value>, <value>, ... ], ... }
*/
getParameters: function() {
return null;
},
/**
* Returns the absolute URL of this object.
* @type {String}
* @return the absolute URL of this object. e.g. http://myhost/contenthandler?uri=acme:id:myid
* or /contenthandler?uri=acme:id:myid
*/
getAbsoluteURL: function () {
return null;
},
/**
* The same as getAbsoluteURL
with the difference that this URL is (if needed) converted to a proxified URL
* @type {String}
* @return the proxified absolute URL. e.g. http://acme.com/proxy/http/myhost/contenthandler?uri=acme:id:myid
*/
getProxifiedAbsoluteURL: function () {
return null;
},
/**
* Returns the model URI of this object. If the complete link is e.g. /mum/contenthandler?uri=acme:id:myid
,
* this method will return acme:id:myid
.
* @type {String}
* @return the URI portion of this Model URL.
*/
getModelURI: function () {
return null;
}
}
);
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.url.ModelUrl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.url.ModelUrl"] = true;
dojo.provide("com.ibm.mashups.enabler.model.url.ModelUrl");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.url.ModelUrlFactory_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.url.ModelUrlFactory_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.url.ModelUrlFactory_API");
dojo.provide("com.ibm.mashups.enabler.model.url.ModelUrlFactory");
/**
* Interface for a ModelUrl Factory that allows to generate ModelUrl's a comfortable way.
* This class should not be instantiated directly, but should be used through it's defined singleton
* (com.ibm.mashups.enabler.model.url.ModelUrlFactory
).
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.url.ModelUrlFactory", null,
{
/**
* Constant for creation of a navigation URL
* @type {String}
*/
NAVIGATION_URL: "nav",
/**
* Constant for creation of a layout URL
* @type {String}
*/
LAYOUT_URL: "layout",
/**
* Constant for creation of a shared navigation URL
* @type {String}
*/
SHARED_NAVIGATION_URL: "sharednav",
/**
* Constant for creation of a fragment URL
* @type {String}
*/
FRAGMENT_URL: "fragment",
/**
* Constant for creation of a fragment-media URL
* @type {String}
*/
FRAGMENT_MEDIA_URL: "fragment-media",
/**
* Constant for creation of a user URL
* @type {String}
*/
USER_URL: "user",
/**
* Constant for creation of a theme URL
* @type {String}
*/
THEME_URL: "theme",
/**
* Constant for creation of a theme-media URL
* @type {String}
*/
THEME_MEDIA_URL: "theme-media",
/**
* Constant for creation of a catalog URL
* @type {String}
*/
CATALOG_URL: "cat",
/**
* Constant for creation of a config URL
* @type {String}
*/
CONFIG_URL: "config",
/**
* Constant for creation of a space URL
* @type {String}
*/
SPACE_URL: "space",
/**
* Constant for creation of a space-favorite URL
* @type {String}
*/
SPACE_FAVORITE_URL: "space-favorite",
/**
* Constant for creation of a ac URL
* @type {String}
*/
AC_URL: "ac",
/**
* Constant for creation of a ac URL
* @type {String}
*/
AI_URL: "ai",
/**
* Constant for creation of a template URL
* @type {String}
*/
TEMPLATE_URL: "template",
/**
* Constant for widget model
* @type {String}
*/
WIDGET_URL: "widget",
/**
* Constant for event model
* @type {String}
*/
EVENT_URL: "event",
/**
* Constant for member sub model
* @type {String}
*/
SUBMODEL_MEMBER: "member",
/**
* Constant for role sub model
* @type {String}
*/
SUBMODEL_ROLE: "role",
/**
* Constant for allowed-access sub model
* @type {String}
*/
SUBMODEL_ACCESS: "access",
/**
* Constant for resource sub model
* @type {String}
*/
SUBMODEL_RESOURCE: "resource",
RESOURCE_URL: "resource-service",
/**
* @private
**/
constructor:function () {
},
/**
* Create a ModelUrl based on the specified urlType. Afterwards parameters and scheme
* specific parts can be changed.
* Sample:
* var myURL = com.ibm.mashups.enabler.model.url.ModelUrlFactory.createModelURL(com.ibm.mashups.enabler.model.url.ModelUrlFactory.NAVIGATION_URL, this);
* @param {String} urlType the type of ModelUrl that should be created. You should use the URL constants that are defined in this interface. (Must not be null
)
* @param {com.ibm.mashups.enabler.model.Model} model the model used to create this ModelUrl object for. (Might be null
)
* @type {com.ibm.mashups.enabler.model.url.ModelUrl}
* @return the created ModelUrl
. Returns null
if the specified urlType is not known.
* @deprecated Use createModelURL instead.
*/
createModelUrl: function (urlType, model) {
return new com.ibm.mashups.enabler.model.url.ModelUrl(urlType, model);
},
/**
* Create a ModelUrl based on the specified urlType. Afterwards parameters and scheme
* specific parts can be changed.
* Sample:
* var myURL = com.ibm.mashups.enabler.model.url.ModelUrlFactory.createModelURL(com.ibm.mashups.enabler.model.url.ModelUrlFactory.NAVIGATION_URL, this);
* @param {String} urlType the type of ModelUrl that should be created. You should use the URL constants that are defined in this interface. (Must not be null
)
* @param {com.ibm.mashups.enabler.model.Model} model the model used to create this ModelUrl object for. (Might be null
)
* @type {com.ibm.mashups.enabler.model.url.ModelUrl}
* @return the created ModelUrl
. Returns null
if the specified urlType is not known.
*/
createModelURL: function (urlType, model) {
return new com.ibm.mashups.enabler.model.url.ModelUrl(urlType, model);
},
/**
* Create a ModelUrl based on the specified URL. Afterwards parameters and scheme specific parts can be changed.
* @param {String} url the URL that should be used to create a ModelUrl
. (Must not be null
)
* @param {com.ibm.mashups.enabler.model.Model} model the model used to create this ModelUrl object for. (Might be null
)
* @type {com.ibm.mashups.enabler.model.url.ModelUrl}
* @return the created ModelUrl
(Must not be null
).
* @deprecated Use getModelURL instead.
*/
getModelUrl: function (url, model) {
return new com.ibm.mashups.enabler.model.url.ModelUrl(url, model);
},
/**
* Create a ModelUrl based on the specified URL. Afterwards parameters and scheme specific parts can be changed.
* @param {String} url the URL that should be used to create a ModelUrl
. (Must not be null
)
* @param {com.ibm.mashups.enabler.model.Model} model the model used to create this ModelUrl object for. (Might be null
)
* @type {com.ibm.mashups.enabler.model.url.ModelUrl}
* @return the created ModelUrl
(Must not be null
).
*/
getModelURL: function (url, model) {
return new com.ibm.mashups.enabler.model.url.ModelUrl(url, model);
}
}
);
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.url.BaseModelUrl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.url.BaseModelUrl"] = true;
dojo.provide("com.ibm.mm.enabler.model.url.BaseModelUrl");
dojo.declare("com.ibm.mm.enabler.model.url.BaseModelUrl", [com.ibm.mashups.enabler.model.url.ModelUrl], {
modelSchema: null,
schemeSpecific: null,
isMediaUrl: false,
httpUrl: null,
VALUE: "value",
IS_ID: "isID",
SUBMODEL: "submodel",
constructor: function() {
this.nodes = [];
this.prefix = null;
this.subModelSchemeMap = {};
this.subModelSchemeMap[com.ibm.mashups.enabler.model.url.ModelUrlFactory.SUBMODEL_RESOURCE] = "resource";
this.subModelSchemeMap[com.ibm.mashups.enabler.model.url.ModelUrlFactory.SUBMODEL_ROLE] = "role";
this.subModelSchemeMap[com.ibm.mashups.enabler.model.url.ModelUrlFactory.SUBMODEL_MEMBER] = "member";
this.subModelSchemeMap[com.ibm.mashups.enabler.model.url.ModelUrlFactory.SUBMODEL_ACCESS] = "access";
},
_loadPrefix: function() {
if (!this.prefix) {
// service document and initialization
this.serviceJson = com.ibm.mm.enabler.model.ServiceDocumentModel.getCollectionData(com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_NAVIGATION);
this.prefix = this.serviceJson.idprefix;
}
},
setPrimaryNode: function(value, isID, subModel) {
var primary = {};
primary.value = value;
primary.isID = (isID === false) ? isID : true;
primary.subModel = subModel;
this.nodes[0] = primary;
this._updateURI();
},
setSecondaryNode: function(value, isID, subModel) {
var secondary = {};
secondary.value = value;
secondary.isID = (isID === false) ? isID : true;
secondary.subModel = subModel;
this.nodes[1] = secondary;
this._updateURI();
},
setNodes: function(nodes) {
this.nodes = nodes;
for (var i = 0; i < nodes.length; i++) {
nodes[i].isID = (nodes[i].isID === false) ? nodes[i].isID : true;
}
this._updateURI();
},
setSchemeSpecificPart: function(value) {
this.nodes = [];
this.schemeSpecific = value;
this._updateURI();
},
getSchemeSpecificPart: function() {
if (this.schemeSpecific) {
return this.schemeSpecific;
}
var tempSSP = "";
if (this.isMediaUrl) {
tempSSP = "/";
}
if (!this.nodes) {
return tempSSP;
}
var i, node;
if (this.isMediaUrl) {
for (i = 0; i < this.nodes.length; i++) {
node = this.nodes[i];
// the prefix MUST only be loaded if the prefix is needed, since the
// loading method uses this function as well which would causea infinite loop
if (node.isID && !this.prefix) {
this._loadPrefix();
}
if (i > 0) {
if (i < this.nodes.length - 1) {
tempSSP += "@";
}
else {
tempSSP += "/";
}
}
tempSSP += node.value;
}
}
else {
for (i = 0; i < this.nodes.length; i++) {
node = this.nodes[i];
// the prefix MUST only be loaded if the prefix is needed, since the
// loading method uses this function as well which would causea infinite loop
if (node.isID && !this.prefix) {
this._loadPrefix();
}
if (tempSSP != "") {
tempSSP += "@";
}
if (node.subModel) {
tempSSP += this.subModelSchemeMap[node.subModel] + ":";
}
if (node.isID) {
tempSSP += this.prefix + ":";
}
tempSSP += node.value;
}
}
return tempSSP;
},
_updateURI: function() {
var uri = this.modelSchema + ":" + this.getSchemeSpecificPart();
this.httpUrl.setParameter("uri", uri);
},
addParameter: function(name, value) {
this.httpUrl.addParameter(name, value);
},
setParameter: function(name, value) {
this.httpUrl.setParameter(name, value);
},
getParameter: function(name) {
return this.httpUrl.getParameter(name);
},
getParameters: function() {
return this.httpUrl.getParameters();
},
getAbsoluteURL: function() {
return this.httpUrl.toString();
},
getProxifiedAbsoluteURL: function() {
return this.httpUrl.toProxifiedString();
},
getModelURI: function() {
return this.httpUrl.getParameter("uri");
},
toProxifiedString: function() {
// TBD: REMOVE AFTER FULL SWITCH
return this.httpUrl.toProxifiedString();
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.url.SchemeBasedModelUrlImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.url.SchemeBasedModelUrlImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.url.SchemeBasedModelUrlImpl");
dojo.declare("com.ibm.mm.enabler.model.url.SchemeBasedModelUrlImpl", [com.ibm.mm.enabler.model.url.BaseModelUrl], {
constructor: function(modelSchema, model) {
this.modelSchema = modelSchema;
this.model = model;
var configService = com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME);
var url = "";
// add the contextroot
url += configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTEXT_ROOT);
// add the public contenthandler url
var anonymousUser = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.ANONYMOUS_USER);
var contenthandlerPath;
if (anonymousUser) {
contenthandlerPath = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTENTHANDLER_PUBLIC);
}
else {
contenthandlerPath = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTENTHANDLER_PRIVATE);
}
url += contenthandlerPath;
this.httpUrl = new com.ibm.mm.enabler.utils.HttpUrl(url);
this.httpUrl.setParameter("uri", this.modelSchema); // first initialization
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.url.SchemeBasedModelMediaUrlImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.url.SchemeBasedModelMediaUrlImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.url.SchemeBasedModelMediaUrlImpl");
dojo.declare("com.ibm.mm.enabler.model.url.SchemeBasedModelMediaUrlImpl", [com.ibm.mm.enabler.model.url.SchemeBasedModelUrlImpl], {
constructor: function(modelSchema, model) {
this.isMediaUrl = true;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.url.ThemeResourceUrlImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.url.ThemeResourceUrlImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.url.ThemeResourceUrlImpl");
dojo.declare("com.ibm.mm.enabler.model.url.ThemeResourceUrlImpl", [com.ibm.mm.enabler.model.url.BaseModelUrl],
{
constructor: function (modelSchema, model) {
this.modelSchema = modelSchema;
this.model = model;
this.httpUrl = new com.ibm.mm.enabler.utils.HttpUrl("/");
this.httpUrl.setParameter("uri", this.modelSchema); // first initialization
},
_updateURI: function() {
// at this point we know it must be a theme or skin resource we try to fetch
var resource, url;
if (this.nodes.length==2) { // theme
var themeId = this.nodes[0].value;
resource = this.nodes[1].value;
var themeNode = this.model.find(themeId).start();
url = themeNode._getBaseUrl();
this.httpUrl = new com.ibm.mm.enabler.utils.HttpUrl(url+resource);
}
else if (this.nodes.length==3) { // skin
var skinId = this.nodes[0].value;
//var themeId = this.nodes[1].value;
resource = this.nodes[2].value;
var skinNode = this.model.find(skinId).start();
url = skinNode._getBaseUrl();
this.httpUrl = new com.ibm.mm.enabler.utils.HttpUrl(url+resource);
}
else {
this.httpUrl = new com.ibm.mm.enabler.utils.HttpUrl("/");
}
}
}
);
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl");
dojo.declare("com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl", [com.ibm.mm.enabler.model.url.BaseModelUrl], {
constructor: function(url, model) {
if (!com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl.CONTEXT_ROOT) {
com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl.CONTEXT_ROOT = com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME).getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTEXT_ROOT);
com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl.PRIVATE_HANDLER = com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl.CONTEXT_ROOT +
com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME).getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTENTHANDLER_PRIVATE);
com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl.PUBLIC_HANDLER = com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl.CONTEXT_ROOT +
com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME).getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTENTHANDLER_PUBLIC);
}
if (url.indexOf("?") === 0) {
// add the public contenthandler url
var anonymousUser = com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME).getValue(com.ibm.mashups.enabler.services.ConfigConstants.ANONYMOUS_USER);
var contenthandlerPath;
if (anonymousUser) {
contenthandlerPath = com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl.PUBLIC_HANDLER;
}
else {
contenthandlerPath = com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl.PRIVATE_HANDLER;
}
var newURL = "";
// add contenthandlerPath
newURL += contenthandlerPath;
url = newURL + url;
}
this.httpUrl = new com.ibm.mm.enabler.utils.HttpUrl(url);
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.url.ModelUrlFactoryImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.url.ModelUrlFactoryImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.url.ModelUrlFactoryImpl");
dojo.declare("com.ibm.mm.enabler.model.url.ModelUrlFactoryImpl", [com.ibm.mashups.enabler.model.url.ModelUrlFactory], {
WEBDAV_URL: "webdav",
/**
* @private
**/
constructor: function() {
this.schemeMap = {};
this.schemeMap[this.NAVIGATION_URL] = "nm";
this.schemeMap[this.SHARED_NAVIGATION_URL] = "snm";
this.schemeMap[this.FRAGMENT_URL] = "fragment";
this.schemeMap[this.FRAGMENT_MEDIA_URL] = "fragment-media";
this.schemeMap[this.USER_URL] = "um";
this.schemeMap[this.THEME_URL] = "theme";
this.schemeMap[this.THEME_MEDIA_URL] = "theme-media";
this.schemeMap[this.CATALOG_URL] = "catalog";
this.schemeMap[this.CONFIG_URL] = "config";
this.schemeMap[this.SPACE_URL] = "space";
this.schemeMap[this.SPACE_FAVORITE_URL] = "space-favorite";
this.schemeMap[this.AC_URL] = "ac";
this.schemeMap[this.AI_URL] = "ai";
this.schemeMap[this.TEMPLATE_URL] = "template";
this.schemeMap[this.LAYOUT_URL] = "lm";
// internal, not exposed
this.schemeMap.service = "service";
this.schemeMap[this.WEBDAV_URL] = "dav:mmdav";
this.schemeMap[this.WIDGET_URL] = "wm";
this.schemeMap[this.EVENT_URL] = "ce";
this.schemeMap[this.RESOURCE_URL] = "resource-service";
},
// @deprecated
createModelUrl: function(urlType, model) {
return this.createModelURL(urlType, model);
},
createModelURL: function(urlType, model) {
var modelSchema = com.ibm.mashups.enabler.model.url.ModelUrlFactory.schemeMap[urlType];
if (!modelSchema) {
return null;
}
var urlImpl;
if (urlType == this.THEME_MEDIA_URL) {
urlImpl = new com.ibm.mm.enabler.model.url.ThemeResourceUrlImpl(modelSchema, model);
}
else if (urlType == this.FRAGMENT_MEDIA_URL) {
urlImpl = new com.ibm.mm.enabler.model.url.SchemeBasedModelMediaUrlImpl(modelSchema, model);
}
else {
urlImpl = new com.ibm.mm.enabler.model.url.SchemeBasedModelUrlImpl(modelSchema, model);
}
return urlImpl;
},
// @deprecated
getModelUrl: function(url, model) {
return this.getModelURL(url, model);
},
getModelURL: function(url, model) {
return new com.ibm.mm.enabler.model.url.StringBasedModelUrlImpl(url, model);
}
});
// legacy
com.ibm.mm.enabler.model.UrlFactory = new com.ibm.mm.enabler.model.url.ModelUrlFactoryImpl();
// define public factory
com.ibm.mashups.enabler.model.url.ModelUrlFactory = com.ibm.mm.enabler.model.UrlFactory;
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.url.ModelUrlFactory"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.url.ModelUrlFactory"] = true;
dojo.provide("com.ibm.mashups.enabler.model.url.ModelUrlFactory");
}
if(!dojo._hasResource["com.ibm.mm.enabler.SubmittableFormProviderImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.SubmittableFormProviderImpl"] = true;
dojo.provide("com.ibm.mm.enabler.SubmittableFormProviderImpl");
// submittable form provider
dojo.declare("com.ibm.mm.enabler.SubmittableFormProviderImpl", com.ibm.mashups.enabler.SubmittableFormProvider, {
constructor: function(){
},
/**
* Returns a SubmittableForm object associated with the given id.
* @param {String} id the id of the html form this object is associated with
* @return {SubmittableForm} SubmittableForm object, maybe null
*/
getSubmittableForm: function(id){
var model = null;
var url;
if (id == "spaceForm") {
url = new com.ibm.mashups.enabler.model.url.ModelUrlFactory.createModelURL(com.ibm.mashups.enabler.model.url.ModelUrlFactory.SPACE_URL, null);
url.setNodes([{
value: "collection",
isID: false
}]);
url.setParameter("mode", "import");
url.setParameter("mime-type", "text/html");
url = url.toProxifiedString();
/*"/mum/mycontenthandler?uri=space:collection&mode=import"*/
model = new com.ibm.mm.enabler.SubmittableFormImpl(url, "post", id);
}
else
if (id == "pageForm") {
var serviceJson = com.ibm.mm.enabler.model.ServiceDocumentModel.getCollectionData(com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_RESOURCE);
url = new com.ibm.mashups.enabler.model.url.ModelUrlFactory.getModelURL(serviceJson.url, this);
url.setParameter("mode", "import");
url.setParameter("mime-type", "text/html");
// post the spaceId to server.
if (arguments[1]) {
url.setParameter("spaceId", arguments[1]);
}
url = url.toProxifiedString();
/*"/mum/mycontenthandler?uri=resource:collection&mode=import"*/
model = new com.ibm.mm.enabler.SubmittableFormImpl(url, "post", id);
}
else
if (id == "spacePageForm") {
url = new com.ibm.mashups.enabler.model.url.ModelUrlFactory.createModelURL(com.ibm.mashups.enabler.model.url.ModelUrlFactory.SPACE_URL, null);
url.setNodes([{
value: "collection",
isID: false
}]);
url.setParameter("mode", "import");
url.setParameter("mime-type", "text/html");
// When we import page .data file came from old BSpace data, we should use the import space rest api, and post spaceId to server.
if (arguments[1]) {
url.setParameter("spaceId", arguments[1]);
}
// The form id is come from the arguments[2]
var postForm = null;
if (arguments[2]) {
postForm = arguments[2];
}
url = url.toProxifiedString();
/*"/mum/mycontenthandler?uri=space:collection&mode=import"*/
model = new com.ibm.mm.enabler.SubmittableFormImpl(url, "post", postForm);
}
return model;
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.SubmittableFormProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.SubmittableFormProvider"] = true;
dojo.provide("com.ibm.mashups.enabler.SubmittableFormProvider");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.TimeStamped_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.TimeStamped_API"] = true;
dojo.provide("com.ibm.mashups.enabler.TimeStamped_API");
dojo.provide("com.ibm.mashups.enabler.TimeStamped");
/**
* Model interface for specific date access properties: This is information such as the
* creation date or the last modification date of a resource.
* @ibm-api
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.TimeStamped", null, {
/**
* Returns the creation date of the resource.
* @return {Date} the creation date, never null
.
*/
getCreated: function () {
},
/**
* Returns the modification date of the resource.
* @return {Date} the modification date, never null
.
*/
getLastModified: function () {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.TimeStamped"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.TimeStamped"] = true;
dojo.provide( "com.ibm.mashups.enabler.TimeStamped" );
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Transformable_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Transformable_API"] = true;
dojo.provide("com.ibm.mashups.enabler.Transformable_API");
dojo.provide("com.ibm.mashups.enabler.Transformable");
/**
* Interface for resources in the system that can be transformed
* @ibm-spi
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.Transformable", null, {
/**
* Returns the xml representation of the resource. It may be modified,
* e.g. with an xsl transformation.
* WARNING: Please note that you must change the xml representation
* of the resource in a compatible way only, since the Enabler API
* operates on this representation. Otherwise the Enabler API may
* function incorrectly or break.
* @return {Object} the xml representation; never null
*/
getXml: function() {
},
/**
* Sets the specified xml of the resource.
* WARNING: Please note that you must set a valid xml representation
* of the resource, since the Enabler API operates on this representation.
* Otherwise the Enabler API may function incorrectly or break.
* @param {Object} xml the xml representation to set for the resource
*/
setXml: function(xml) {
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.TransformableImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.TransformableImpl"] = true;
dojo.provide("com.ibm.mm.enabler.TransformableImpl");
// transformable
dojo.declare("com.ibm.mm.enabler.TransformableImpl", [com.ibm.mashups.enabler.Transformable, com.ibm.mm.enabler.DirtyFlagProviderImpl], {
constructor: function() {
},
getXml: function() {
return this.xmlData;
},
setXml: function(xml, keepClean) {
this.xmlData = xml;
if (this._resetCachedRawID) {
// if this also implements the IdentifiableXml aspect we need to clean out any cached raw id at this point
this._resetCachedRawID();
}
if (!keepClean) {
this._setDirty();
}
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.Transformable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.Transformable"] = true;
dojo.provide("com.ibm.mashups.enabler.Transformable");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.TreeModel"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.TreeModel"] = true;
dojo.provide("com.ibm.mashups.enabler.TreeModel");
/**
* This interface provides a generic tree model acting as a base class
* for all concrete tree models
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.TreeModel", [com.ibm.mashups.enabler.model.Model, com.ibm.mashups.enabler.Locator], {
/**
* Returns the root node of the model; may return null
* if the concrete tree model supports for empty models
*
* @type Deferred
* @return a deferred object used to start this operation. The
* return value when executed through the deferred object
* is the root object of the tree model
*/
getRoot: function(){
},
/**
* Returns whether or not the given node has children. Please pay
* attention to the documentation of the return value; it is not
* guaranteed that children are present if the method returns
* true
- the iterator might be empty.
*
* @param {Object} node node object or node uri (without any scope)
* for which to check if it has children. Must
* not be null
.
* @return {Boolean} true if the specified node has children, false otherwise
*/
hasChildren: function(node){
},
/**
* Returns an iterator over the child elements for the given node.
*
* @param {Object} node node object or node uri (without any scope)
* for which to return its children. Must not
* be null
.
* @return {com.ibm.mashups.enabler.DeferredIterator} deferred iterator for the children of the given node.
* Never null
*/
getChildren: function(node){
},
/**
* Returns the parent of a given node.
* @param {Object} node node object or node uri (without any scope)
* for which to return its parent. Must not
* be null
.
* @return {com.ibm.mashups.enabler.Deferred} a deferred object used to start this operation. The
* return value when executed through the deferred object
* is the parent of the given node, or null
* if the node has no parent
*/
getParent: function(node){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.TreeModelController"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.TreeModelController"] = true;
dojo.provide("com.ibm.mashups.enabler.TreeModelController");
/**
* This modifiable interface provides a generic tree model acting as a base class
* for all concrete tree models
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.TreeModelController", com.ibm.mashups.enabler.TreeModel, {
/**
* creates a new model object. The created node can be inserted
* into the model using an appropriate insert
method defined
* on a subinterface of this interface. The node will not appear in the model
* unless it is inserted.
* @param {JSON} context array of predefined information
* used for the creation of the node. May be null
. Accepted
* names are defined in the appropriate subinterfaces
* @type Object
* @return the created node
*/
create: function(context){
},
/**
* Confirms whether creating the node is possible.
* @param {JSON} context array of predefined information
* used for the creation of the node. May be null
. Accepted
* names are defined in the appropriate subinterfaces
* @return {Boolean} true if the node can be created, otherwise false.
*/
confirmCreate: function(context){
},
/**
* Inserts a node into the tree model at the specified location;
* the node must either be created with the create method of the
* concrete tree model before, or must exist in the tree model;
* in this case the existing node is moved to the specified location
*
* @param {Object} node node to insert or move. Must not be
* null
.
* @param {Object} parentNode node object or node uri (without any
* scope) of the parent node. The given
* node is inserted/moved underneath the
* parent node; must not be null
.
* @param {Object} nextNode node object or node uri (without any
* scope) of the successor node before
* which the node is to be inserted;
* if null
is specified,
* the node is appended at the end of
* the existing nodes
* @type void
*/
insert: function(node, parentNode, nextNode){
},
/**
* Confirms whether inserting the node is possible.
* @param {Object} node node to insert or move. Must not be
* null
.
* @param {Object} parentNode node object or node uri (without any
* scope) of the parent node. The given
* node is inserted/moved underneath the
* parent node; must not be null
.
* @param {Object} nextNode node object or node uri (without any
* scope) of the successor node before
* which the node is to be inserted;
* if null
is specified,
* the node is appended at the end of
* the existing nodes
* @return {Boolean} true if the node can be inserted, otherwise false.
*/
confirmInsert: function(node, parentNode, nextNode){
},
/**
* Deletes a node from the model. All its children are deleted as well.
*
* @param {Object} node node object or node uri (without any scope)
* to delete from the model. Must not be null
.
* @type void
*/
remove: function(node){
},
/**
* Confirms whether removing the node is possible.
* @param{Object} node node object or node uri (without any scope).
* Must not be null
* @return {Boolean} true if the node can be removed, otherwise false.
*/
confirmRemove: function(node){
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.io.DynamicResolver_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.io.DynamicResolver_API"] = true;
dojo.provide("com.ibm.mashups.enabler.io.DynamicResolver_API");
dojo.provide("com.ibm.mashups.enabler.io.DynamicResolver");
/**
* This provides a system plugin point where extensions can be registered
* to provide immediate resolution of IO requests for data that can be
* retrieved from the client. It allows circumvention of remote requests
* to serve data that is already available in the system. It also allows
* an completely extensible URL naming system such that URLs passed to
* IO requests can take on formats besides typical ones such as http or https.
* Extension formats and schemes can be handled by custom plugins to allow
* an arbitrary mapping of resources on the client to URLs that can be serviced
* through normal IO requests.
* The service can be retrieved using the following code:
* var dynamicResolver = com.ibm.mashups.services.ServiceManager.getService(
* com.ibm.mashups.enabler.io.DynamicResolver.SERVICE_NAME);
* @ibm-spi
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.io.DynamicResolver", null, {
/**
* The service name to be used to fetch the service from the ServiceManager
* @type String
*/
SERVICE_NAME: "dynamicResolver",
/**
* Registers a plugin for immediate request resolution.
* @param {String} id the id of the plugin
* @param {Function} matcher the function that returns a validation result
* to verify if the plugin can resolve the current request. Function format:
* Function(String url)
.
* This function must return a "truthy" value to indicate that it can resolve
* this request, or a "falsy" value if it cannot. Whatever this function returns
* will be passed into the plugin's resolver function as the second argument.
* @param {Function} resolver the function that resolves the current request
* and passes the response data back to the caller. Function format:
* Function(String url, Anything validationResult)
.
* This function must return the data for the response.
* @param {Boolean} first optional argument to specify if this plugin should
* take precedence over all existing plugins if set to true. If it is false
* the plugin will take lowest precedence of existing plugins. Default is false.
* @type void
*/
register: function(/*String*/ id, /*Function*/matcher, /*Function*/resolver, /*Boolean?*/first) {
},
/**
* Unregisters a plugin by its registered id.
* @param {String} id the id of the plugin to unregister
* @type void
*/
unregister: function(/*String*/id) {
}
});
com.ibm.mashups.enabler.io.DynamicResolver.SERVICE_NAME = "dynamicResolver";
}
if(!dojo._hasResource["com.ibm.mm.enabler.io.XHRWrapper"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.io.XHRWrapper"] = true;
dojo.provide("com.ibm.mm.enabler.io.XHRWrapper");
dojo.declare("com.ibm.mm.enabler.io.XHRWrapper", null, {
constructor: function(ioArgs, partString, statusCode, contentType, partHeaders) {
this.ioArgs = ioArgs;
this.xhr = ioArgs.xhr;
this.readyState = ioArgs.xhr.readyState;
this.responseText = partString;
this.responseXML = ioArgs.xhr.responseXML;
this.status = statusCode;
this.statusText = ioArgs.xhr.statusText;
this.contentType = contentType;
this.partHeaders = partHeaders;
},
getAllResponseHeaders: function() {
return this.xhr.getAllResponseHeaders();
},
getInterface: function() {
return this.xhr.getInterface();
},
getResponseHeader: function(header) {
var headerString = header + '';
if (this.partHeaders[headerString]) {
return this.partHeaders[headerString];
} else if (headerString.toLowerCase() == "content-type") {
return (this.contentType);
}
return this.xhr.getResponseHeader(header);
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.io.DynamicResolver"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.io.DynamicResolver"] = true;
dojo.provide("com.ibm.mm.enabler.io.DynamicResolver");
dojo.declare("com.ibm.mm.enabler.io.DynamicResolver", com.ibm.mashups.enabler.io.DynamicResolver, {
constructor: function(){
this._plugins = []; // each plugin has format -> [id,matchFn,resolveFn]
// Wrap dojo.xhr; if a resolver is found, use it, otherwise delegate to unwrapped dojo.xhr
var me = this, origXhr = dojo.xhr;
dojo.xhr = function(){
var fn = me.getResolver.apply(me, arguments) || origXhr;
return fn.apply(this, arguments);
};
},
_buildDfdFn: function(fname, obj, ioArgs){
var func = obj[fname];
return func ? function(val){
return func.call(obj, val, ioArgs);
}
: null;
},
resolve: function(/*Function*/resolver, /*Object*/ validationResult, /* String */ method, /* dojo.__XhrArgs */ args, /* Boolean */ hasBody){
// called in scope of original xhr call, not in DynamicResolver instance scope
var data = null, isErr = false, dfd = new dojo.Deferred(), ioArgs = { // dojo.__IoCallbackArgs
args: args,
url: com.ibm.mm.enabler.EndpointUtils.checkForEndpoints(args.url) || args.url, // check for endpoint URLs
handleAs: args.handleAs || "text",
xhr: { // need this stubbed out for XHRWrapper
readyState: 4,
responseXML: null,
statusText: ""
}
};
dfd.addCallback(this._buildDfdFn("load", args, ioArgs)).addErrback(this._buildDfdFn("error", args, ioArgs)).addBoth(this._buildDfdFn("handle", args, ioArgs));
ioArgs.xhr = new com.ibm.mm.enabler.io.XHRWrapper(ioArgs, "", 200, "text", {});
try {
data = resolver(ioArgs.url, validationResult); // use potentially endpoint-resolved URL
ioArgs.xhr.status = 200;
if (data) {
ioArgs.xhr.responseText = data;
if (args.handleAs === "xml" && typeof data === "string") {
// create document object from text string
ioArgs.xhr.responseXML = com.ibm.mm.enabler.utils.Dom.createDocument(data);
}
}
}
catch (err) {
ioArgs.xhr.status = 500;
data = err;
ioArgs.xhr.responseText = err.toString();
isErr = true;
}
dfd[isErr ? "errback" : "callback"](data);
return dfd; // dojo.Deferred
},
_embedValidation: function(fn, vResult){
var me = this;
return function(method, args, hasBody){
return me.resolve(fn, vResult, method, args, hasBody);
};
},
getResolver: function(/* String */method, /* dojo.__XhrArgs */ args, /* Boolean */ hasBody){
if (method && method.toLowerCase() == "get") {
for (var i = 0; i < this._plugins.length; i++) {
var plg = this._plugins[i];
var ret = plg[1](args.url);
if (ret) {
// escape closure around the unnecessaries
return this._embedValidation(plg[2], ret);
}
}
}
return null;
},
register: function(/*String*/id, /*Function*/ plgMatcher, /*Function*/ plgResolver, /*Boolean?*/ first){
this._plugins[first ? "unshift" : "push"]([id, plgMatcher, plgResolver]);
},
unregister: function(/*String*/id){
for (var i = 0; i < this._plugins.length; i++) {
if (id === this._plugins[i][0]) {
this._plugins.splice(i, 1);
return;
}
}
}
});
com.ibm.mashups.services.ServiceManager.setService(com.ibm.mashups.enabler.io.DynamicResolver.SERVICE_NAME, "com.ibm.mm.enabler.io.DynamicResolver");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.io.DynamicResolver"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.io.DynamicResolver"] = true;
dojo.provide("com.ibm.mashups.enabler.io.DynamicResolver");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.io.XHRMultipart_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.io.XHRMultipart_API"] = true;
dojo.provide("com.ibm.mashups.enabler.io.XHRMultipart_API");
dojo.provide("com.ibm.mashups.enabler.io.XHRMultipart");
/**
* Provides Dojo XHR support. Requests are batched together via a transaction
* concept - Dojo XHR requests which are made between the start and end
* transaction calls will be batched. This would include any Dojo API's which would
* use Dojo XHR. If the com.ibm.mashups.multipart.correlatehosts
* Configuration Service property is set to true, multipart requests will be
* split by hostname.
* @ibm-api
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.io.XHRMultipart", null, {
/**
* @private
*/
constructor: function() {
},
/**
* Begins a multipart transaction. If the com.ibm.mashups.multipart.enabled
* property is set to false, this method simply returns.
* @type void
*/
startTransaction: function() {
},
/**
* Ends a multipart transaction and submits the multipart request to
* the server. If the com.ibm.mashups.multipart.enabled
* property is set to false, this method simply returns.
* @return {DeferredOperation} a deferred object used to start this operation.
* The return value when executed through the deferred object is null
*/
endTransactionDeferred: function() {
},
/**
* Ends a multipart transaction and submits the multipart request to
* the server. If the com.ibm.mashups.multipart.enabled
* property is set to false, this method simply returns.
* @param {Object} callback the callback funtion in the format of
Function(Object[] params)
. May be null
* Callbackparameters
* params
- the parameters
* passed into the callback
* @param {Object[]} parameters optional array of parameters to be
* passed on to the callback function. May be null
* @type void
* @deprecated Use endTransactionDeferred instead.
*/
endTransaction: function(callback, parameters) {
},
/**
* Suspends a mulitpart transaction, allowing normal XHR requests
* to be made. If the com.ibm.mashups.multipart.enabled
* property is set to false, this method simply returns.
* @type void
*/
suspendTransaction: function() {
},
/**
* Resumes a mulitpart transaction. If the com.ibm.mashups.multipart.enabled
* property is set to false, this method simply returns.
* @type void
*/
resumeTransaction: function() {
},
/**
* Returns if there is an active multipart transaction
* @return {Boolean} true
if there is an active multipart
* transaction, false
otherwise
*/
isTransaction: function() {
return false;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.ServiceDocConsumer"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.ServiceDocConsumer"] = true;
dojo.provide("com.ibm.mm.enabler.ServiceDocConsumer");
dojo.declare("com.ibm.mm.enabler.ServiceDocConsumer",null,{
_noop: function(){},
_initServiceDoc: function() {
this._initServiceDoc = this._noop; // turns this init into a noop for this object
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.encode.huffman.ZEncoder"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.encode.huffman.ZEncoder"] = true;
dojo.provide("com.ibm.mm.enabler.encode.huffman.ZEncoder");
dojo.declare("com.ibm.mm.enabler.encode.huffman.ZEncoder", null, {
HEX_CHARS: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"],
UNSAFE_CHARS: "$&+,/:;=?@ <>#%{}|\\^~[]`\"Z",
constructor: function() {
},
isUnsafeChar: function(testChar) {
if (this.UNSAFE_CHARS.indexOf(testChar) > -1 || testChar.charCodeAt(0) <= 32 || testChar.charCodeAt(0) >= 123) {
return true;
}
return false;
},
zEncode: function(value) {
var retVal = "";
for (var i = 0; i < value.length; ++i) {
var currentChar = value.charAt(i);
if (!this.isUnsafeChar(currentChar)) {
retVal += currentChar;
continue;
}
retVal += this.zEncodeChar(currentChar);
}
return retVal;
},
zEncodeChar: function(plainChar) {
var magicChar = "Z";
return magicChar + this.byteToHex(plainChar.charCodeAt(0));
},
byteToHex: function(byteValue) {
var upper = Math.floor(byteValue / 16);
var lower = byteValue % 16;
return this.HEX_CHARS[upper] + this.HEX_CHARS[lower];
},
zDecode: function(value) {
var retVal = "";
var magicChar = "Z";
if (value.indexOf(magicChar) != -1) {
for (var i = 0, l = value.length; i < l; i++) {
var charX = value.charAt(i);
if (charX == magicChar) {
var hex = "0x" + value.substr(i + 1, 2);
i = i + 2;
try {
var charCode = parseInt(hex,16);
retVal = retVal.concat(String.fromCharCode(charCode));
}
catch (e) {
continue;
}
}
else {
retVal = retVal.concat(value.substr(i, 1)); //concat character
}
}
}
else {
retVal = value;
}
return retVal;
}
});
com.ibm.mm.enabler.encode.huffman.ZEncoder = new com.ibm.mm.enabler.encode.huffman.ZEncoder();
}
if(!dojo._hasResource["com.ibm.mm.enabler.encode.huffman.HuffmanURL"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.encode.huffman.HuffmanURL"] = true;
dojo.provide("com.ibm.mm.enabler.encode.huffman.HuffmanURL");
dojo.declare("com.ibm.mm.enabler.encode.huffman.HuffmanURL", null, {
// alphabet used for base64 encoding, this is NOT the default base64 alphabet but an alphabet that only contains URL safe characters
URL_ALPHABET: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_!",
constructor: function() {
},
/** Encodes the huffman codes of the tokens in the alphabet into a stream
* @param the target stream
* @param the map between token and prefix
* @param the array of tokens to encode
*/
_encodeTokens: function(stream, nodes, tokens) {
// iterate over all tokens
var len = tokens.length;
for (var i = 0; i < len; ++i) {
// add the code for the token
this._addBits(stream, nodes[tokens[i]].prefix);
}
// return the stream
return this._encodeStream(stream);
},
/** Encodes the dwords in the stream into a base64 encoded string
*
* @param stream stream to encode
* @return a string of the base64 encoded dwords
*/
_encodeStream: function(stream) {
// number of bytes to encode
var len = stream.dwords.length * 4;
// push the last dword
if (stream.bits > 0) {
// add the last dword
stream.dwords.push(stream.dword);
// update the length
len += ((stream.bits + 0x07) >> 0x03);
stream.bits = 0;
}
// compute the number of bytes and encode
return this._encodeBase64(stream.dwords, 0, len);
},
/* Initializes the stream object
* @param stream the stream to be initialized
* @return the actual stream
*/
_initStream: function(stream) {
// reset the masks and the current dword
stream.dword = 0;
stream.mask = 1;
stream.bits = 0;
// start with an empty array of encoded dwords
stream.dwords = [];
// the stream
return stream;
},
/* Encode an array of 0/1 values that are stored in the data array into a sequence of 32 bit values stored
* in the stream.
*
* @param stream target stream that contains a dword array
* @param data the data array of 0/1 values to be encoded
*/
_addBits: function(stream, data) {
// cache the data in local variables and save it back to the stream object at the end
var mask = stream.mask, dword = stream.dword, bits = stream.bits;
// add all bits sequentially
var len = data.length, off = 0;
while (len > 0) {
// check how many bits we can add in a batch
var copy = Math.min(len, 0x20 - bits);
for (var i = 0; i < copy; ++i) {
// add the bit
if (data[off + i] == 1) {
dword |= mask;
}
mask <<= 1;
}
// update
bits += copy;
len -= copy;
off += copy;
// check for an overflow
if (bits == 0x20) {
// add the new word
stream.dwords.push(dword);
bits = 0;
mask = 1;
dword = 0;
}
}
// update the object
stream.mask = mask;
stream.bits = bits;
stream.dword = dword;
},
/* Adds a single bit (0/1) to the the stream
* @param stream target stream that contains a dword array
* @param bit to be encoded, must be 1 or 0
*/
_addBit: function(stream, bit) {
// add to the dword
if (bit == 1) {
stream.dword |= stream.mask;
}
stream.mask <<= 1;
stream.bits++;
// check for the max mask
if (stream.bits == 0x20) {
// add the dword to the list
stream.dwords.push(stream.dword);
stream.dword = 0;
stream.mask = 1;
stream.bits = 0;
}
},
/** encodes the data into base64 format, the data is packed in 32bit integer values in little endian notation.
* Offset and length refer to the actual bytes, not the dwords. */
_encodeBase64: function(data, off, len) {
// cache the alphabet
var ab = this.URL_ALPHABET;
// starting dword and offset of the byte inside the dword
var srcIdx = off >> 0x02;
var shift = off & 0x03;
// the current dword and a place holder for the next (wrapping) dword
var value = data[srcIdx++], newValue;
// the four 6-bit numbers that we decode from three consequtive bytes
var c1, c2, c3, c4;
// the resulting base64 encoding
var result = "";
// iterate over the range of bytes in three-byte tuples
for (var i = len; i > 0; i -= 3) {
/** get the next three bytes. We use direct bit operations based on the packing.
*/
switch (shift) {
case 0:
// all bytes are available inside the dword
c1 = ((value >> 0x02) & 0x3f);
c2 = ((value << 0x04) & 0x30) | ((value >> 0x0c) & 0x0f);
c3 = ((value >> 0x06) & 0x3c) | ((value >> 0x16) & 0x03);
c4 = ((value >> 0x10) & 0x3f);
// next shift
shift = 3;
break;
case 1:
// all bytes are available inside the dword
c1 = ((value >> 0x0a) & 0x3f);
c2 = ((value >> 0x04) & 0x30) | ((value >> 0x14) & 0x0f);
c3 = ((value >> 0x0e) & 0x3c) | ((value >> 0x1e) & 0x03);
c4 = ((value >> 0x18) & 0x3f);
// next shift
shift = 0;
value = data[srcIdx++];
break;
case 2:
// wrap around to the next dword
newValue = data[srcIdx++];
c1 = ((value >> 0x12) & 0x3f);
c2 = ((value >> 0x0c) & 0x30) | ((value >> 0x1c) & 0x0f);
c3 = ((value >> 0x16) & 0x3c) | ((newValue >> 0x06) & 0x03);
c4 = (newValue & 0x3f);
// next shift
value = newValue;
shift = 1;
break;
case 3:
// wrap around to the next dword
newValue = data[srcIdx++];
c1 = ((value >> 0x1A) & 0x3f);
c2 = ((value >> 0x14) & 0x30) | ((newValue >> 0x04) & 0x0f);
c3 = ((newValue << 0x02) & 0x3c) | ((newValue >> 0x0e) & 0x03);
c4 = ((newValue >> 0x08) & 0x3f);
// next shift
value = newValue;
shift = 2;
break;
}
// padding
switch (i) {
case 1:
c3 = 0x40;
c4 = 0x40;
break;
case 2:
c4 = 0x40;
break;
}
// construct the 4-character tuple
result += ab.charAt(c1);
result += ab.charAt(c2);
result += ab.charAt(c3);
result += ab.charAt(c4);
}
// return the result of the encoding process
return result;
},
//decode encoded string
//conver 4 byte into 3
//return an array of charcode
//first item in the array should be the right most in bit stream...
_decodeBase64: function(encodedStr) {
var ab = this.URL_ALPHABET;
var len = encodedStr.length / 4;
var i = 0;
var array = []; //each array item contains 3 char
for (var j = 0; j < len; j++) {
var padding = 0;
indexC1 = ab.indexOf(encodedStr.charAt(i++));
indexC2 = ab.indexOf(encodedStr.charAt(i++));
indexC3 = ab.indexOf(encodedStr.charAt(i++));
if (indexC3 == 64) {
padding++;
}
indexC4 = ab.indexOf(encodedStr.charAt(i++));
if (indexC4 == 64) {
padding++;
}
c1 = (indexC1 << 2) | (indexC2 >> 4); //this is the last byte (from right)
c2 = ((indexC2 & 15) << 4) | (indexC3 >> 2); //this is the middle byte
c3 = ((indexC3 & 3) << 6) | indexC4; //this is the byte on the left
array.push(c1);
switch (padding) {
case 0:
array.push(c2);
array.push(c3);
break;
case 1:
array.push(c2);
break;
case 2:
break;
}
}
return array;
},
/** Callback used by the sort method to compare nodes by frequency
*/
_frequencyCompare: function(n1, n2) {
return n1.frequency - n2.frequency;
},
/** Initializes the encoding and the prefixes of the huffman tree. The
* method writes the tree structure as a bit sequence into the stream and
* initializes the node prefixes with the huffman code.
*
* @param stream the stream that contains the tree structure and the sequence of the node names
* @param node the current node in the tree to encode
* @param prefix the huffman prefix of the parent node, an array that contains 0/1 bits
*/
_initTree: function(stream, node, prefix) {
// iterate into the children
if (node.left && node.right) {
// add to the stream
this._addBit(stream, 1);
// recurse the left and right branch
this._initTree(stream, node.left, prefix.concat(0));
this._initTree(stream, node.right, prefix.concat(1));
}
else {
// add to the stream
this._addBit(stream, 0);
// this is our huffman code!
node.prefix = prefix;
// add this node
stream.tokens.push(node.name);
}
// ok
return stream;
},
_dumpTokens: function(tree, nodes) {
},
/** Constructs the huffman tree from the token sequence
*
* @param array of tokens
* @return the URL that encodes the tokens
*/
_buildTree: function(tokens) {
// build a list of token frequencies
var nodes = {};
// iterate and fill the node map
var len = tokens.length;
var node, i;
for (i = len - 1; i >= 0; --i) {
// do we know the node?
var token = tokens[i];
node = nodes[token];
if (node) {
// increment the frequency of the node
node.frequency++;
}
else {
// construct the new token
node = {
frequency: 1,
name: token
};
// add the node
nodes[token] = node;
}
}
// produce a sorted list based on the frequencies
var queue = [];
for (node in nodes) {
if (Object.prototype.hasOwnProperty.call(nodes,node)) {
queue.push(nodes[node]);
}
}
queue.sort(this._frequencyCompare);
// build the huffman tree
while (queue.length > 1) {
// remove the smallest items
var left = queue.shift(), right = queue.shift();
// construct the new, combined node
queue.push({
frequency: left.frequency + right.frequency,
left: left,
right: right
});
queue.sort(this._frequencyCompare);
}
// now, we have the tree, initialize its huffman codes
var root = queue[0];
var tree = this._initTree(this._initStream({
tokens: []
}), queue.shift(), []);
this._dumpTokens(tree, nodes);
// serialize the tree into a prefix
var url = this._encodeStream(tree);
// append the tokens
len = tree.tokens.length;
for (i = 0; i < len; ++i) {
url += "/" + com.ibm.mm.enabler.encode.huffman.ZEncoder.zEncode(tree.tokens[i]);
}
// serialize the huffman codes
url += "/" + this._encodeTokens(this._initStream({}), nodes, tokens);
// return the url
return url;
},
/** Constructs the huffman tree from a data string an a regular expression that splits
* the string into tokens. The delimiters are considered part of the tokens.
* @param data the data string to split
* @param regexStrg the regular expression string, e.g. "[\/\.<>]"
*
* @return the encoded URL
*/
_buildTreeFromRegex: function(data, regexStrg) {
// compile the regex
var regex = new RegExp(regexStrg, "g");
// record the split positions
var pos = [];
var result;
while ((result = regex.exec(data))) {
pos.push(result.index);
}
// padding
if (pos[0]) {
pos.unshift(0);
}
if (pos[pos.length - 1] != data.length) {
pos.push(data.length);
}
// split
var tokens = [];
for (result = 1; result < pos.length; ++result) {
tokens.push(data.substring(pos[result - 1], pos[result]));
}
// construct the URL
return this._buildTree(tokens);
},
/** Constructs the huffman tree from the token sequence
*
* @param array of tokens
* @return the URL that encodes the tokens
*/
createRawSchemeSpecificPartFromTokens: function(tokens) {
return this._buildTree(tokens);
},
/** Constructs the huffman tree from a data string an a regular expression that splits
* the string into tokens. The delimiters are considered part of the tokens.
* @param data the data string to split
* @param regexStrg the regular expression string, e.g. "[\/\.<>]"
*
* @return the encoded URL
*/
createRawSchemeSpecificPartFromRegex: function(data, regexStrg) {
return this._buildTreeFromRegex(data, regexStrg);
},
/** Restores data from the encoded huffman tree based on the token sequence
* @param url encoded data
* @return the data string that's decoded from huffman tree
*/
getDataFromHuffmanTree: function(tree) {
return this._restoreData(tree);
},
_restoreData: function(tree) {
if (!tree) {
return null;
}
var i0 = tree.indexOf("/");
var i1 = tree.lastIndexOf("/");
if ((i0 >= 0) && (i1 >= 0)) {
var treeStream = this._decodeBase64(tree.substring(0, i0));
var encodedToken = tree.substring(i0 + 1, i1).split("/");
var codeStream = this._decodeBase64(tree.substring(i1 + 1));
//array of decoded tokens
encodedTokens = this._decodeTokens(encodedToken);
//build tree with token
var root = this._readStructure(this._convertBitToChar(treeStream), encodedTokens);
var bitArr = this._convertBitToChar(codeStream);
var retVal = "";
while (bitArr.length > 0) {
retVal = this._buildData(retVal, bitArr, root);
}
return retVal;
}
return null;
},
_buildData: function(retVal, bitArr, root) {
var found = false;
var node = null;
while (!found) {
var bit = bitArr.shift();
if (typeof bit == "undefined") {
node = null;
break;
}
node = this._getNode(bit, root);
if (node && node.token && node.token) {
found = true;
}
else if (!node) {
found = true;
}
root = node;
}
if (found && node) {
retVal = retVal.concat(node.token);
}
return retVal;
},
_getNode: function(bit, parent) {
//0 --left, 1--right
var node = null;
node = (bit == 1) ? parent.right : parent.left;
if (!node) {
return null;
}
return node;
},
_convertBitToChar: function(charCodeArr) {
var arr = [];
var mask = 0x01;
var bit = 0;
for (var i = 0; i < charCodeArr.length; i++) {
var charCode = charCodeArr[i];
for (var j = 0; j < 8; j++) {
bit = charCode & mask;
arr.push(bit);
charCode = (charCode >> 1); //remove 1 bit
}
}
return arr;
},
_readStructure: function(charArr, encodedTokens) {
var bit = charArr.shift();
var node = {};
if (bit == 1) { // internal node
node.left = this._readStructure(charArr, encodedTokens);
node.right = this._readStructure(charArr, encodedTokens);
}
else { //leaf node
var token = encodedTokens.shift();
node.token = token;
}
return node;
},
// an array of tokens try to zDecode it
_decodeTokens: function(encodedToken) {
var arr = [];
for (var i in encodedToken) {
if (Object.prototype.hasOwnProperty.call(encodedToken,i)) {
arr.push(com.ibm.mm.enabler.encode.huffman.ZEncoder.zDecode(encodedToken[i]));
}
}
return arr;
}
});
com.ibm.mm.enabler.encode.huffman.HuffmanURL = new com.ibm.mm.enabler.encode.huffman.HuffmanURL();
}
if(!dojo._hasResource["com.ibm.mm.enabler.ArrayMap"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.ArrayMap"] = true;
dojo.provide("com.ibm.mm.enabler.ArrayMap");
dojo.declare("com.ibm.mm.enabler.ArrayMap", null, {
constructor: function(){
this.entries = [];
this.keys = {};
},
values: function(){
return this.entries;
},
put: function(/*String*/key,/*object*/ value){
var index = this.keys[key];
if (typeof index != 'undefined' && index !== null) {
this.entries[index] = value;
}
else {
index = this.entries.length;
this.entries.push(value);
this.keys[key] = index;
}
},
getKey: function(index){
if (index < this.entries.length) {
for (var key in this.keys) {
if(Object.prototype.hasOwnProperty.call(this.keys,key)) {
var temp = this.keys[key];
if (temp !== null && temp == index) {
return temp;
}
}
}
}
else {
return null;
}
},
getValue: function(index){
return (index < this.entries.length) ? this.entries[index] : null;
},
get: function(key){
var index = this.keys[key];
if (typeof index != 'undefined' && index !== null) {
var value = this.entries[index];
return value;
}
return null;
},
remove: function(key){
var index = this.keys[key];
if (typeof index != 'undefined' && index !== null) {
this.entries.splice(index, 1);
this.keys[key] = null;
}
return index;
},
size: function(){
return this.entries.length;
},
keySet: function(){
var arr = [];
com.ibm.mm.enabler.utils.Misc.forIn(this.keys,function(value,key) {
arr.push(key);
});
return arr;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.io.XHRMultipartImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.io.XHRMultipartImpl"] = true;
dojo.provide("com.ibm.mm.enabler.io.XHRMultipartImpl");
dojo.declare("com.ibm.mm.enabler.io.XHRMultipartImpl", [com.ibm.mashups.enabler.io.XHRMultipart, com.ibm.mm.enabler.ServiceDocConsumer], {
DYN_RES: com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.io.DynamicResolver.SERVICE_NAME),
statics: {
semaphore: 0,
digest: null,
suspendedXhr: null
},
constructor: function() {
this.method = "POST";
this.partsArray = null;
var configService = com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME);
this.correlateHosts = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.MULTIPART_CORRELATE_HOSTS);
this.correlatedHosts = null;
this.cacheQueries = false;
var cacheQueriesConfig = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.MULTIPART_CACHE_QUERIES);
if (typeof(cacheQueriesConfig) !== "undefined" && cacheQueriesConfig !== null && cacheQueriesConfig === true) {
this.cacheQueries = true;
}
this.privateUrl = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTEXT_ROOT) +
configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTENTHANDLER_PRIVATE);
this.publicUrl = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTEXT_ROOT) +
configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.CONTENTHANDLER_PUBLIC);
this.doSiteMap = true;
this.urlMaxLength = 2000;
// unique (arbitrary) boundary
this.boundary = "{EB2F8DA2-5B2C-F66A-CDD0-A2D42143F5AC}";
this.newL = "\r\n";
this.sep = "--";
this.startB = this.newL + this.sep + this.boundary + this.newL;
this.endB = this.sep + this.boundary + this.sep + this.newL;
// used to capture the header
//this.headerRegx = /\r\n\s*([^\r]*)\s*/mg;
this.headerRegx = new RegExp(this.newL + "\s*([^\r]*)\s*", "mg");// JSLINT-IGNORE: Enabler Team decided to keep this paradigma from dojo in tact
this.headerPartsRegx = /\s*([^:]*):\s*(.+)/;
// used to find the boundary
this.boundaryRegx = /boundary\s*=\s*\"?([^\"]*)\"?/;
this.multipartParts = false;
this.replaceDigest = false;
this.digest = null;
},
_initServiceDoc: function() {
this.inherited("_initServiceDoc", arguments);
this.doMultipart = com.ibm.mashups.enabler.io.XHRMultipartFactory.isMultipartEnabled();
if(this.doMultipart) {
this.serviceMPJson = com.ibm.mm.enabler.model.ServiceDocumentModel.getCollectionData([com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_MODEL, com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_MULTIPART]);
this.serviceSMJson = com.ibm.mm.enabler.model.ServiceDocumentModel.getCollectionData([com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_MODEL, com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_HUFFMAN]);
this.serviceCHJson = com.ibm.mm.enabler.model.ServiceDocumentModel.getCollectionData([com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_MODEL, com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_SITEMAP_COMMITHANDLER]);
}
},
_partHandler: function(partArgs, responsePart, ioArgs, partHeaders) {
var work = dojo.hitch(partArgs, function() {
try {
if (com.ibm.mm.enabler.utils.Misc.isInstanceOf(responsePart, Error)) {
if (this.error) {
this.error(responsePart, ioArgs, partHeaders);
}
}
else if (ioArgs.xhr.status >= 400) {
if (this.error) {
this.error(new Error(ioArgs.xhr.status + ": " + partHeaders.URI), ioArgs, partHeaders);
}
}
else {
if (this.load) {
this.load(responsePart, ioArgs, partHeaders);
}
}
// always call the handle function if it exists
if (this.handle) {
this.handle(responsePart, ioArgs, partHeaders);
}
}
catch (err) {
// make one attempt to call the error handler
try {
if (this.error) {
this.error(responsePart, ioArgs, partHeaders);
}
}
catch (err2) {
//noop
}
}
}); // JSLINT-IGNORE: Enabler Team decided to keep this paradigma from dojo in tact
work();
},
_handleMultiPartResponse: function(parts, multipartParts, scope, response, ioArgs) {
// Getting the Content-Type header from the response, and extract
// the boundary string
var contentType = ioArgs.xhr.getResponseHeader("Content-Type");
var boundMatch = contentType.match(scope.boundaryRegx);
if (!boundMatch) {
throw new Error("No boundary specified in Content-Type response header");
}
var bound = boundMatch[1];
var stripPossibleCharSetIndex = bound.indexOf(";");
if (stripPossibleCharSetIndex!=-1) {
bound = bound.substring(0,stripPossibleCharSetIndex);
}
// build a regx from the response boundary string used to split the parts
var splitterRegx = new RegExp(scope.newL + scope.sep + bound, "mg");
var respParts = response.split(splitterRegx);
// if handleAs is xml, it comes as text so build it using the domUtilities
// iterate through the response parts, handling the callbacks for each
var mpHandler = null;
if (multipartParts) {
mpHandler = new com.ibm.mm.enabler.io.XHRMultipartImpl();
mpHandler.startTransaction();
}
var i = 1;
for (var current in parts) {
if (Object.prototype.hasOwnProperty.call(parts, current)) {
var partArgs = parts[current];
for (var x = 0, l = partArgs.length; xnull
*/
create: function(){
},
/**
* Returns if multipart is enabled on the server
* @return {Boolean} true
if multipart is
* enabled, false
otherwise
*/
isMultipartEnabled: function(){
},
/**
* Returns if application widgets should be fetched in multipart requests
* @return {Boolean} true
if application widgets should be
* fetched in multipart requests, false
otherwise
*/
isMultipartApplicationWidgets: function(){
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.io.XHRMultipartFactoryImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.io.XHRMultipartFactoryImpl"] = true;
dojo.provide("com.ibm.mm.enabler.io.XHRMultipartFactoryImpl");
// public factory
dojo.declare("com.ibm.mm.enabler.io.XHRMultipartFactoryImpl", [com.ibm.mashups.enabler.io.XHRMultipartFactory, com.ibm.mm.enabler.ServiceDocConsumer], {
constructor: function() {
this._init = false;
this.serviceMPJson = null;
this.doMultipart = false;
var configService = com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME);
var pageLoadOptAppWidgets = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.PAGE_LOAD_OPTIMIZATION_APP_WIDGETS);
this.multipartAppWidgets = false;
if (typeof(pageLoadOptAppWidgets) == "undefined" || pageLoadOptAppWidgets === null || pageLoadOptAppWidgets === true) {
this.multipartAppWidgets = true;
}
},
_initServiceDoc: function() {
this.inherited("_initServiceDoc", arguments);
// service document and initialization
if (dojo.exists("com.ibm.mm.enabler.model.ServiceDocumentModel")) {
this.serviceMPJson = com.ibm.mm.enabler.model.ServiceDocumentModel.getCollectionData([com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_MODEL, com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_MULTIPART]);
}
if(this.serviceMPJson && this.serviceMPJson.url) {
this.doMultipart = true;
}
},
create: function() {
return new com.ibm.mm.enabler.io.XHRMultipartImpl();
},
isMultipartEnabled: function() {
if(!this._init) {
this._init = true;
var configService = com.ibm.mashups.services.ServiceManager.getService(com.ibm.mashups.enabler.services.ConfigService.SERVICE_NAME);
var multipartConfig = configService.getValue(com.ibm.mashups.enabler.services.ConfigConstants.MULTIPART_ENABLED);
// disable on IE6
if (dojo.isIE != 6 && multipartConfig) {
this._initServiceDoc();
}
}
return this.doMultipart;
},
isMultipartApplicationWidgets: function() {
return this.multipartAppWidgets;
}
});
// public factory
com.ibm.mashups.enabler.io.XHRMultipartFactory = new com.ibm.mm.enabler.io.XHRMultipartFactoryImpl();
}
if(!dojo._hasResource["com.ibm.mashups.enabler.io.XHRMultipartFactory"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.io.XHRMultipartFactory"] = true;
dojo.provide("com.ibm.mashups.enabler.io.XHRMultipartFactory");
dojo.require( "com.ibm.mm.enabler.io.XHRMultipartFactoryImpl" );
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.Accessor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.Accessor"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.Accessor");
/**
* Interface representing an Accessor.
*
* @ibm-spi
* @ibm-module Base
*/
dojo.declare("com.ibm.mashups.enabler.model.state.Accessor", null, {});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.PageAccessor_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.PageAccessor_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.PageAccessor_API");
dojo.provide("com.ibm.mashups.enabler.model.state.PageAccessor");
/**
* Interface representing an PageAccessor.
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.PageAccessor", [com.ibm.mashups.enabler.model.state.Accessor] , {
/**
* Returns the of the page within a space.
* @type String
* @return {String} The page id of provided space
*/
getPageID:function() {
},
/**
* Sets the page of the space
* @param {String} pageId id of page
* @type void
*/
setPageID:function(pageId) {
},
/**
* Confirms if it's possible to set a new page id
* @param {String} pageId id of page
* @type Boolean
* @return{Boolean} return true if it's possible to set a new page id
*/
confirmSetPageID:function(pageId) {
return true;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.PageAccessorImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.PageAccessorImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.PageAccessorImpl");
dojo.declare("com.ibm.mm.enabler.model.state.PageAccessorImpl", [com.ibm.mashups.enabler.model.state.PageAccessor], {
constructor: function(navStateModel, spaceid) {
this.navStateModel = navStateModel;
if (spaceid) {
this.spaceid = spaceid;
}
},
getPageID: function() {
var state = this.navStateModel._state;
var rc = null;
if (!state) {
return null;
}
if (!this.spaceid) {
if (state.pid) {
return state.pid.value;
}
return null;
}
else {
if (state.pageselection && state.pageselection[this.spaceid]) {
return state.pageselection[this.spaceid].value;
}
return null;
}
return null;
},
setPageID: function(pageId) {
var state = this.navStateModel._state;
if (!state) {
this.navStateModel._state = {};
state = this.navStateModel._state;
}
if (!pageId) {
state.pid = null;
if (this.spaceid) {
if (state.pageselection && state.pageselection[this.spaceid]) {
state.pageselection[this.spaceid] = null;
}
}
this.navStateModel.setDirty(true, "pid");
return;
}
var lm = new Date().getTime();
state.pid = state.pid ? state.pid : {};
state.pid.value = pageId;
state.pid.params = state.pid.params ? state.pid.params : {};
state.pid.params.lm = lm;
if (this.spaceid) {
if (!state.pageselection) {
state.pageselection = {};
}
if (!state.pageselection[this.spaceid]) {
state.pageselection[this.spaceid] = {};
}
state.pageselection[this.spaceid].value = pageId;
state.pageselection[this.spaceid].params = state.pageselection[this.spaceid].params ? state.pageselection[this.spaceid].params : {};
state.pageselection[this.spaceid].params.lm = lm;
}
this.navStateModel.setDirty(true, "pid");
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.PageAccessor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.PageAccessor"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.PageAccessor");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.SpaceAccessor_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.SpaceAccessor_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.SpaceAccessor_API");
dojo.provide("com.ibm.mashups.enabler.model.state.SpaceAccessor");
/**
* Interface representing a SpaceAccessor.
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.SpaceAccessor", [com.ibm.mashups.enabler.model.state.Accessor], {
/**
* Returns the of the currently selected space.
* @type String
* @return {String} The spaceid
*/
getSpaceID:function() {
},
/**
* Sets the space
* @param {String} spaceId id of space
* @type void
*/
setSpaceID:function(spaceId) {
},
/**
* Confirms if it's possible ot set the space id
* @param {String} spaceId id of space
* @type Boolean
* @return{Boolean} return true if it's possible to set the new space id
*/
confirmSetSpaceID:function(spaceId) {
return true;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.SpaceAccessorImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.SpaceAccessorImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.SpaceAccessorImpl");
dojo.declare("com.ibm.mm.enabler.model.state.SpaceAccessorImpl", [com.ibm.mashups.enabler.model.state.SpaceAccessor], {
constructor: function(navStateModel) {
this.navStateModel = navStateModel;
},
getSpaceID: function() {
var state = this.navStateModel._state;
if (!state) {
return null;
}
if (state.sid && state.sid.value) {
return state.sid.value;
}
return null;
},
_setSpaceIDInternal: function(spaceId) {
var state = this.navStateModel._state;
if (!state) {
this.navStateModel._state = {};
state = this.navStateModel._state;
}
var lm = new Date().getTime(); //todo
if (typeof spaceId == "undefined") {
state.sid = {};
}
else {
state.sid = state.sid ? state.sid : {};
state.sid.value = spaceId;
state.sid.params = state.sid.params ? state.sid.params : {};
state.sid.params.lm = lm;
}
if (state.pid) {
state.pid = null;
}
},
setSpaceID: function(spaceId) {
this._setSpaceIDInternal(spaceId);
this.navStateModel.setDirty(true, "sid");
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.SpaceAccessor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.SpaceAccessor"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.SpaceAccessor");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.WidgetAccessor_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.WidgetAccessor_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.WidgetAccessor_API");
dojo.provide("com.ibm.mashups.enabler.model.state.WidgetAccessor");
/**
* Interface representing a WidgetAccessor. Reserved Widget Paramers:
* "cp" : the reserved paremeter for widget customized state.
* "h" : the reserved paremeter for widget height.
* "w" : the reserved paremeter for widget width.
* "st" : the reserved paremeter for widget window state.
* "md" : the reserved paremeter for widget mode.
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.WidgetAccessor", [com.ibm.mashups.enabler.model.state.Accessor], {
/**
* @private
*/
constructor:function (navStateModel, id) {
},
/**
* Returns the widget id of the Widget
* @type String
* @return {String} ID of required Widget
*/
getWidgetID:function() {
},
/**
* Returns the values of the required widget state parameter. If state has only one value, this method returns a single array with a length of 1.
*
* @since 2.4
* @param {String} key The name of the required parameter of Widget Navigation State
* "cp" is the reserved parameter for widget customized state.
* @type String
* @return {String[]} Values of required parameter
*/
getWidgetStateValues:function(key) {
},
/**
* Returns the state of the required widget state parameter
* @param {String} key The name of the required parameter of Widget Navigation State
* "cp" is the reserved parameter for widget customized state.
* @type String
* @return {String} Value of required parameter
*/
getWidgetState:function(key) {
},
/**
* Set the value of a widget state parameter
*
* @since 2.4
* @param {String} key The name of the required parameter
* @param {String[]} values The values of the required parameter
* @type WidgetAccessor
* @return{WidgetAccessor} return an handle of WidgetAccessor upon successful, null
upon failure.
*/
setWidgetState:function(key,values){
},
/**
* Confirms whether setting the values for the given widget state parameter is possible.
*
* @since 2.4
* @param {String} key The name of the required parameter
* @param {String[]} values The values of the required parameter
* @type Boolean
* @return {Boolean} true if the values can be set, otherwise false.
*/
confirmSetWidgetState:function(key,values){
return true;
},
/**
* Set the value of a widget state parameter
*
* @since 2.4
* @param {String} key The name of the required parameter
* @param {String} value The value of the required parameter
* @type WidgetAccessor
* @return{WidgetAccessor} return an handle of WidgetAccessor upon successful, null
upon failure.
*/
setWidgetState:function(key,value){ // JSLINT-IGNORE: in Java functions with the same name but different signatures are allowed - this is only used for generating JavaDoc
},
/**
* Confirms whether setting the value for the given widget state parameter is possible.
*
* @since 2.4
* @param {String} key The name of the required parameter
* @param {String} value The value of the required parameter
* @type Boolean
* @return {Boolean} true if the value can be set, otherwise false.
*/
confirmSetWidgetState:function(key,value){// JSLINT-IGNORE: in Java functions with the same name but different signatures are allowed - this is only used for generating JavaDoc
return true;
},
/**
* Remove a widget state parameter
* @param {String} key The name of the required parameter
* @type WidgetAccessor
* @return{WidgetAccessor} return an handle of WidgetAccessor upon successful, null
upon failure.
*/
removeWidgetState:function(key){
},
/**
* Confirms whether removing a widget state parameter is possible
*
* @since 2.4
* @param {String} key The name of the required parameter
* @type Boolean
* @return{Boolean} return true if the required parameter can be removed
*/
confirmRemoveWidgetState:function(key){
return true;
},
/**
* Returns the names of custimized widget state
* @type String[]
* @return {String[]} an array of customized widget state names
*/
getWidgetStateNames:function(){
},
/**
* Returns the mode of the required widget
* @type String
* @return {String} The mode of the required widget and null
if no mode is set yet.
*/
getWidgetMode:function() {
},
/**
* Set the mode of a widget
* @param {String} mode of the required widget
* @type WidgetAccessor
* @return{WidgetAccessor} return an handle of WidgetAccessor upon successful, null
upon failure.
*/
setWidgetMode:function(mode) {
},
/**
* Confirms whether it's possible or not to set the widget to a new mode
* @param {String} mode of the required widget
* @type Boolean
* @return{Boolean} return true if it's possible to set widget to the new model
*/
confirmSetWidgetMode:function(mode) {
return true;
},
/**
* Returns the window state of the required widget
* @type String
* @return {String} The window state of the required widget following states are allowed: "normal","minimize","maximize". It returns null
if no windowstate is set yet.
*/
getWindowState:function() {
},
/**
* Set the window state of a widget
* @param {String} windowState The window state of the required widget
* @type WidgetAccessor
* @return{WidgetAccessor} return an handle of WidgetAccessor upon successful, null
upon failure.
*/
setWindowState:function(windowState) {
},
/**
* Confirms whether it's possible or not to set the widget to a new window state
* @param {String} windowState The window state of the required widget
* @type Boolean
* @return{Boolean} return true if it's possible to set widget to the new window state
*/
confirmSetWindowState:function(windowState) {
return true;
},
/**
* Returns the size of the required widget
* @type Object
* @return {Object} A JSON object representing the widget width/height, for example: {w:"200",h:"400"}
*/
getSize:function() {
},
/**
* Set the size of a widget
* @param {String} width The width of the widget
* @param {String} height The height of the widget
* @type WidgetAccessor
* @return{WidgetAccessor} return an handle of WidgetAccessor upon successful, null
upon failure.
*/
setSize:function(width, height) {
},
/**
* Confirms whether it's possible or not to set the widget to the new width and height
* @param {String} width The width of the widget
* @param {String} height The height of the widget
* @type Boolean
* @return{Boolean} return true if it's possible to set widget to the new width and height
*/
confirmSetSize:function(width,height) {
return true;
},
/**
* "minimize" window state supported by enabler
* @type String
*/
MIN: "minimize",
/**
* "maximize" window state supported by enabler
* @type String
*/
MAX: "maximize",
/**
* "normal" window state supported by enabler
* @type String
*/
NORMAL: "normal"
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.WidgetAccessorImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.WidgetAccessorImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.WidgetAccessorImpl");
dojo.declare("com.ibm.mm.enabler.model.state.WidgetAccessorImpl", [com.ibm.mashups.enabler.model.state.WidgetAccessor], {
constructor: function(navStateModel, id){
this.navStateModel = navStateModel;
this.wid = id;
this.uniqueWid = this._getUniqueWid();
this.widgetNavStateNode = navStateModel._find(this.WIDGET_PREFIX + this.navStateModel.DELIMITER + this.uniqueWid);
if (this.wid != this.uniqueWid && !this.widgetNavStateNode) {
this.widgetNavStateNodeFallback = navStateModel._find(this.WIDGET_PREFIX + this.navStateModel.DELIMITER + this.wid);
}
},
WIDGET_PREFIX: "wparams",
WIDTH: "w",
HEIGHT: "h",
WINDOWSTATE: "st",
SYSTEMSTATE: "rp",
CUSTOMSTATE: "cp",
VALUE: "value",
PARAMS: "params",
MODE: "md",
RP: {
w: "w",
h: "h",
st: "st",
md: "md"
},
VIEW: "view",
getWidgetID: function(){
return this.wid;
},
_getUniqueWid: function(){
return this.navStateModel._getUniqueWid(this.wid);
},
getWidgetStateSet: function(){
var value = null;
if (!this.widgetNavStateNode && !this.widgetNavStateNodeFallback) {
return null;
}
var widgetNavStateNode = this.widgetNavStateNode;
if (!widgetNavStateNode) {
widgetNavStateNode = this.widgetNavStateNodeFallback;
}
var data = widgetNavStateNode.getRef();
if (data && data[this.VALUE]) {
if (data[this.VALUE][this.CUSTOMSTATE]) {
value = data[this.VALUE][this.CUSTOMSTATE];
}
}
if (value && !dojo.isString(value)) {
value = dojo.toJson(value);
}
return value; //always return string as defined by the spec
},
_createWidgetNavStateNode: function(){
var aNode = this.navStateModel.create({
key: this.uniqueWid
});
var parentNode = this.navStateModel._find(this.WIDGET_PREFIX);
if (!parentNode) {
var temp = this.navStateModel.create({
key: this.WIDGET_PREFIX
});
this.navStateModel.insert(temp, this.navStateModel._getRoot());
parentNode = this.navStateModel._find(this.WIDGET_PREFIX);
}
this.navStateModel.insert(aNode, parentNode);
aNode = this.navStateModel._find(this.WIDGET_PREFIX + this.navStateModel.DELIMITER + this.uniqueWid);
return aNode;
},
setWidgetStateSet: function(object){
//it should be a simple String,save as an object internally
var value = null;
//need to support both string or object
//save as object for portal CSA2 support
if (dojo.isString(object)) {
try {
object = dojo.fromJson(object);
} catch (e) {
// just use the string
}
}
if (!this.widgetNavStateNode) {
//create this.widgetNavStateNode
this.widgetNavStateNode = this._createWidgetNavStateNode();
}
var data = this.widgetNavStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime(); //todo
if (data && data[this.VALUE]) {
if (data[this.VALUE][this.CUSTOMSTATE]) {
value = dojo.clone(data[this.VALUE][this.CUSTOMSTATE]);
}
}
data[this.VALUE] = data[this.VALUE] ? data[this.VALUE] : {};
var obj = object;
if (value && !dojo.isString(value) && !dojo.isString(object)) {
obj = dojo.mixin(value, object); //mixin behaviour
}
data[this.VALUE][this.CUSTOMSTATE] = obj;
this.navStateModel.setDirty(true);
return this;
},
_getWidgetSystemState: function(key){
var value = null;
if (!this.widgetNavStateNode && !this.widgetNavStateNodeFallback) {
return null;
}
var widgetNavStateNode = this.widgetNavStateNode;
if (!widgetNavStateNode) {
widgetNavStateNode = this.widgetNavStateNodeFallback;
}
var data = widgetNavStateNode.getRef();
if (data && data[this.VALUE]) {
if (data[this.VALUE][this.SYSTEMSTATE]) {
data = data[this.VALUE][this.SYSTEMSTATE];
if (data && data[key]) {
value = data[key];
}
}
}
return value;
},
_setWidgetSystemState: function(key, value){
//overwrite behaviour
if (!this.widgetNavStateNode) {
this.widgetNavStateNode = this._createWidgetNavStateNode();
}
var data = this.widgetNavStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime(); //todo
var keyRef = null;
data[this.VALUE] = data[this.VALUE] ? data[this.VALUE] : {};
data[this.VALUE][this.SYSTEMSTATE] = data[this.VALUE][this.SYSTEMSTATE] ? data[this.VALUE][this.SYSTEMSTATE] : {};
keyRef = data[this.VALUE][this.SYSTEMSTATE];
keyRef[key] = value;
this.navStateModel.setDirty(true);
return this;
},
getWidgetState: function(key){
var rc = this._getWidgetStateValue(key) || null;
if (!rc) {
return null;
}
if (!dojo.isString(rc)) {
rc = dojo.toJson(rc);
}
return rc;
},
_getWidgetStateValue: function(key){
if (!key) {
return null;
}
if (key && key == "cp") {
return this.getWidgetStateSet();
}
if (this.RP[key]) {
return this._getWidgetSystemState(key);
}
var value = null;
if (!this.widgetNavStateNode && !this.widgetNavStateNodeFallback) {
return null;
}
var widgetNavStateNode = this.widgetNavStateNode;
if (!widgetNavStateNode) {
widgetNavStateNode = this.widgetNavStateNodeFallback;
}
var data = widgetNavStateNode.getRef();
if (data && data[this.VALUE]) {
if (data[this.VALUE][this.CUSTOMSTATE]) {
data = data[this.VALUE][this.CUSTOMSTATE];
if (dojo.isString(data)) {
return null;
}
if (data && data[key]) {
value = data[key];
}
}
}
return value;
},
getWidgetStateValues: function(key){
// TODO implement
var rc = this._getWidgetStateValue(key) || null;
if (!rc) {
return null;
}
if (dojo.isString(rc)) {
var arr = [];
arr.push(rc);
return arr;
}
return rc;
},
getWidgetStateNames: function(){
var names = [];
if (!this.widgetNavStateNode && !this.widgetNavStateNodeFallback) {
return null;
}
var widgetNavStateNode = this.widgetNavStateNode;
if (!widgetNavStateNode) {
widgetNavStateNode = this.widgetNavStateNodeFallback;
}
var data = widgetNavStateNode.getRef();
if (data && data[this.VALUE]) {
if (data[this.VALUE][this.CUSTOMSTATE]) {
data = data[this.VALUE][this.CUSTOMSTATE];
if (dojo.isString(data)) {
return null;
}
if (data) {
for (var i in data) {
if (Object.prototype.hasOwnProperty.call(data, i)) {
if (data[i]) { //if it's not deleted
names.push(i);
}
}
}
}
}
}
if (names.length === 0) {
return null;
}
return names;
},
setWidgetState: function(key, value){
if (!key || !value) {
return null;
}
if (key && key == "cp") {
return this.setWidgetStateSet(value);
}
var isValidValue = false;
if (dojo.isArray(value) && value.length >= 1) {
if (dojo.isString(value[0])) {
isValidValue = true;
}
}
if (!isValidValue) {
if (dojo.isString(value)) {
isValidValue = true;
}
}
if (!isValidValue) {
return null;
}
if (this.RP[key]) {
return this._setWidgetSystemState(key, value);
}
//overwrite behaviour
if (key && key == "cp") {
return this.setWidgetStateSet(value);
}
if (!this.widgetNavStateNode) {
this.widgetNavStateNode = this._createWidgetNavStateNode();
}
var data = this.widgetNavStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime(); //todo
var keyRef = null;
data[this.VALUE] = data[this.VALUE] ? data[this.VALUE] : {};
data[this.VALUE][this.CUSTOMSTATE] = data[this.VALUE][this.CUSTOMSTATE] ? data[this.VALUE][this.CUSTOMSTATE] : {};
keyRef = data[this.VALUE][this.CUSTOMSTATE];
keyRef[key] = value;
this.navStateModel.setDirty(true);
return this;
},
removeWidgetState: function(key){
if (!key) {
return false;
}
if (this.RP[key]) {
return this._removeWidgetSystemState(key);
}
if (!this.widgetNavStateNode) {
return false;
}
var data = this.widgetNavStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime(); //todo
if (key && key == "cp") {
if (data && data[this.VALUE] && data[this.VALUE][this.CUSTOMSTATE]) {
data[this.VALUE][this.CUSTOMSTATE] = null;
this.navStateModel.setDirty(true);
return true;
}
return false;
}
if (data && data[this.VALUE] && data[this.VALUE][this.CUSTOMSTATE]) {
var keyRef = data[this.VALUE][this.CUSTOMSTATE];
if (keyRef && keyRef[key]) {
keyRef[key] = null;
this.navStateModel.setDirty(true);
return true;
}
}
return false;
},
_removeWidgetSystemState: function(key){
if (!key) {
return false;
}
if (!this.widgetNavStateNode) {
return false;
}
var data = this.widgetNavStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime(); //todo
if (data && data[this.VALUE] && data[this.VALUE][this.SYSTEMSTATE]) {
var keyRef = data[this.VALUE][this.SYSTEMSTATE];
if (keyRef && keyRef[key]) {
keyRef[key] = null;
this.navStateModel.setDirty(true);
return true;
}
}
return false;
},
getWindowState: function(){
rc = this._getWidgetSystemState(this.WINDOWSTATE);
//rc = rc ? rc : this.NORMAL;
return rc;
},
setWindowState: function(windowState){
if (windowState && (windowState == this.MIN || windowState == this.MAX || windowState == this.NORMAL)) {
this._setWidgetSystemState(this.WINDOWSTATE, windowState);
}
},
getWidgetMode: function(){
var rc = this._getWidgetSystemState(this.MODE);
//rc = rc ? rc : this.VIEW;
return rc;
},
setWidgetMode: function(aMode){
if (aMode) {
this._setWidgetSystemState(this.MODE, aMode);
return this;
}
return null;
},
getSize: function(){
var size = {};
var height = this._getWidgetSystemState(this.HEIGHT);
var width = this._getWidgetSystemState(this.WIDTH);
if (height) {
size[this.HEIGHT] = height;
}
if (width) {
size[this.WIDTH] = width;
}
if (!size[this.HEIGHT] && !size[this.WIDTH]) {
return null;
}
return size;
},
setSize: function(width, height){
if (width) {
this._setWidgetSystemState(this.WIDTH, width);
}
if (height) {
this._setWidgetSystemState(this.HEIGHT, height);
}
return this;
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.WidgetAccessor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.WidgetAccessor"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.WidgetAccessor");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.PageModeAccessor_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.PageModeAccessor_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.PageModeAccessor_API");
dojo.provide("com.ibm.mashups.enabler.model.state.PageModeAccessor");
/**
* Interface representing an PageModeAccessor.
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.PageModeAccessor", [com.ibm.mashups.enabler.model.state.Accessor] , {
/**
* VIEW mode of page, can be used as com.ibm.mashups.enabler.model.state.PageModeAccessor.VIEW with "view" as the actual value
* @type String
*/
VIEW:"view",
/**
* EDIT mode of page, can be used as com.ibm.mashups.enabler.model.state.PageModeAccessor.EDIT with "edit" as the actual value
* @type String
*/
EDIT:"edit",
/**
* Returns the of the page mode of current page.
* @type String
* @return {String} The page mode of current page
*/
getPageMode:function() {
},
/**
* Sets the page mode of the page
* @param {String} pageMode The mode of the page
* @type void
*/
setPageMode:function(pageMode) {
},
/**
* Confirms if it's possible to set a new page mode
* @param {String} pageMode The mode of the page
* @type Boolean
* @return{Boolean} return true if it's possible to set a new page mode
*/
confirmSetPageMode:function(pageMode) {
return true;
}
});
com.ibm.mashups.enabler.model.state.PageModeAccessor.VIEW = "view";
com.ibm.mashups.enabler.model.state.PageModeAccessor.EDIT = "edit";
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.PageModeAccessorImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.PageModeAccessorImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.PageModeAccessorImpl");
dojo.declare("com.ibm.mm.enabler.model.state.PageModeAccessorImpl", [com.ibm.mashups.enabler.model.state.PageModeAccessor], {
constructor: function(navStateModel) {
// it supports 3 modes: "view","edit","unload" -- unload is internal at this moment and used to indicate a page is being unloaded
this.navStateModel = navStateModel;
},
getPageMode: function() {
var pageMode = this.navStateModel._getPageMode();
if (!pageMode) {
return null;
}
return pageMode;
},
setPageMode: function(mode) {
if (mode) {
this.navStateModel._setPageMode(mode);
}
return;
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.PageModeAccessor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.PageModeAccessor"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.PageModeAccessor");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor_API");
dojo.provide("com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor");
/**
* Interface representing a ShareableParameterSetAccessor.
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor", [com.ibm.mashups.enabler.model.state.Accessor], {
/**
* Returns the id of ShareableParamterSet
* @type String
* @return {String} name of ShareableParameterSet
*/
getId:function() {
},
/**
* Returns the scope of ShareableParamterSet or null, if this accessor represents the global scope.
* @type String
* @return {String} name of the scope
*/
getScope:function() {
},
/**
* Returns an array of all Shareable Parameter names within this Shareable Parameter Set
* @type String[]
* @return {String[]} array of all the ShareableParameterSet
*/
getAllNames:function() {
},
/**
* Set the value of a required item. It will replace the old value. If the value is a serialized version of complex data type, it's recommended for the widget to get the original
* value, update the complex object and serialize again before calling this api.
* @param {String} itemName The name of the required parameter
* @param {String} value The value of the required parameter
* @type Boolean
* @return {Boolean} return true if item is updated or created successfully.
*/
setItemValue:function(itemName,value){
},
/**
* Confirm if it's possible to set the value of a required item. It will replace the old value. If the value is a serialized version of complex data type, it's recommended for the widget to get the original
* value, update the complex object and serialize again before calling this api.
* @param {String} itemName The name of the required parameter
* @param {String} value The value of the required parameter
* @type Boolean
* @return {Boolean} return true if it's possible to set the value
*/
confirmSetItemValue:function(itemName,value){
return true;
},
/**
* Remove the required item
* @param {String} itemName The name of the required parameter that needs to be removed
* @type Boolean
* @return {Boolean} return true if item is removed successfully.
*/
removeItem:function(itemName){
},
/**
* confirm if it's possible to remove the required item
* @param {String} itemName The name of the required parameter that needs to be removed
* @type Boolean
* @return {Boolean} return true if it's possible to remove item
*/
confirmRemoveItem:function(itemName){
return true;
},
/**
* Returns the value of required item name
* @param {String} itemName the name of the required parameter
* @type String
* @return {String} value of the required item
*/
getItemValue:function(itemName) {
},
/**
* Register listener so listener will be notified when an item set is updated
* @param {Function} listener which is a js function that's already scoped properly.
* @return{String} listener id
*/
registerListener:function(listener) {
},
/**
* Remove the listener given a listener id
* @param {String} listenerId id of the listener that will be removed.
* @type Boolean
* @return {Boolean} return true if listener is removed successfully
*/
removeListener:function(listenerId) {
},
/**
* Confirm if it's possible to remove the listener given a listener id
* @param {String} listenerId id of the listener that will be removed.
* @type Boolean
* @return {Boolean} return true if it's possible to remove Listener
*/
confirmRemoveListener:function(listenerId) {
return true;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.ShareableParameterSetAccessorImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.ShareableParameterSetAccessorImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.ShareableParameterSetAccessorImpl");
dojo.declare("com.ibm.mm.enabler.model.state.ShareableParameterSetAccessorImpl", [com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor], {
/**
* @private
*/
DELETE_TOKEN: "DELETE_TOKEN",
TYPE_NEW: "newItem",
TYPE_UPDATE: "changedValue",
TYPE_REMOVE: "removedItem",
constructor: function(navStateModel, name, scope) {
/*{
value:{//type: newItem/changedValue/removedItem
page:{value:"3",params:{_isDirty:true,_type:"changedValue",_oldVal:"4"}},
tablesize:{value:"10"}
}
params:{lm:{},_listener:{}}
}
*/
if (!scope) {
this.scope = com.ibm.mm.enabler.model.state.ShareableParameterSetAccessorImpl.GLOBAL_SCOPE;
} else {
this.scope = scope;
}
this.name = name;
this.navStateModel = navStateModel;
this.navStateNode = navStateModel._find("sparams" + this.navStateModel.DELIMITER + name + this.navStateModel.DELIMITER + this.scope);
},
_createNavStateNode: function() {
var temp;
var parentNode = this.navStateModel._find("sparams");
if (!parentNode) {
temp = this.navStateModel.create({
key: "sparams"
});
this.navStateModel.insert(temp, this.navStateModel._getRoot());
parentNode = this.navStateModel._find("sparams");
}
var nameNode = this.navStateModel._find(this.name);
if (!nameNode) {
temp = this.navStateModel.create({
key: this.name
});
this.navStateModel.insert(temp, parentNode);
nameNode = this.navStateModel._find("sparams" + this.navStateModel.DELIMITER + this.name);
}
var scopeNode = this.navStateModel.create({
key: this.scope
});
this.navStateModel.insert(scopeNode, nameNode);
scopeNode = this.navStateModel._find("sparams" + this.navStateModel.DELIMITER + this.name + this.navStateModel.DELIMITER + this.scope);
return scopeNode;
},
getId: function() {
return this.name;
},
getScope: function() {
return this.scope;
},
getAllNames: function() {
if (!this.navStateNode) {
return null;
}
var arr = [];
var data = this.navStateNode.getRef();
if (data && data[this.navStateModel.VALUE]) {
for (var i in data[this.navStateModel.VALUE]) {
if (data[this.navStateModel.VALUE].hasOwnProperty(i)) {
var value = data[this.navStateModel.VALUE][i][this.navStateModel.VALUE];
if (value && value != this.DELETE_TOKEN) {
arr.push(i);
}
}
}
}
return arr;
},
setItemValue: function(itemName, value) {
if (!this.navStateNode) {
//create this.widgetNavStateNode
this.navStateNode = this._createNavStateNode();
}
var data = this.navStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime(); //mark lm of itemset
data.value = data.value ? data.value : {};
var change = {};
if (!data.value[itemName]) {
//new item
data.value[itemName] = {};
data.value[itemName].value = value;
data.value[itemName].params = data.value[itemName].params ? data.value[itemName].params : {};
data.value[itemName].params._isDirty = true;
change.alias = itemName;
change.type = this.TYPE_NEW;
change.newVal = value;
data.value[itemName].params._change = change;
} else if (data.value[itemName]) {
var oldValue = dojo.clone(data.value[itemName].value);
data.value[itemName].value = value;
data.value[itemName].params = data.value[itemName].params ? data.value[itemName].params : {};
var isDirty = data.value[itemName].params._isDirty;
if (isDirty) {
//check various condition
change = data.value[itemName].params._change;
if (change.type == this.TYPE_NEW) {
change.newVal = value;
} else if (change.type == this.TYPE_UPDATE) {
change.newVal = value;
} else if (change.type == this.TYPE_REMOVE) {
if (change.oldVal) {
change.type = this.TYPE_UPDATE;
} else {
change.type = this.TYPE_NEW;
}
change.newVal = value;
}
} else {
change.type = this.TYPE_UPDATE;
change.oldVal = oldValue;
change.newVal = value;
change.alias = itemName;
data.value[itemName].params._change = change;
}
data.value[itemName].params._isDirty = true;
}
this.navStateModel.setDirty(true);
return true;
},
removeItem: function(itemName) {
if (!this.navStateNode) {
return false;
}
var data = this.navStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime(); //mark lm of itemset
if (data && data[this.navStateModel.VALUE]) {
if (data[this.navStateModel.VALUE][itemName]) {
var anItem = data[this.navStateModel.VALUE][itemName];
var oldValue = dojo.clone(anItem.value);
anItem.value = this.DELETE_TOKEN;
anItem.params = anItem.params ? anItem.params : {};
var isDirty = anItem.params._isDirty;
var change = {};
if (isDirty) {
change = anItem.params._change;
if (change.type == this.TYPE_NEW) {
//completely remove this item
//data[this.navStateModel.VALUE][itemName];
delete data[this.navStateModel.VALUE][itemName];
} else if (change.type == this.TYPE_UPDATE) {
change.type = this.TYPE_REMOVE;
change.newVal = null;
delete change.oldVal;
} //don't do anything if it's remove
} else {
change.type = this.TYPE_REMOVE;
change.alias = itemName;
change.oldVal = oldValue;
anItem.params._change = change;
anItem.params._isDirty = true;
}
this.navStateModel.setDirty(true);
} else {
return false; //if item not found
}
}
return true;
},
getItemValue: function(itemName) {
if (!this.navStateNode) {
return null;
}
var data = this.navStateNode.getRef();
if (data && data[this.navStateModel.VALUE]) {
if (data[this.navStateModel.VALUE][itemName]) {
var anItemNode = data[this.navStateModel.VALUE][itemName];
var value = anItemNode[this.navStateModel.VALUE];
if (value && value != this.DELETE_TOKEN) {
return value;
}
}
}
return null;
},
registerListener: function(listener) {
if (!this.navStateNode) {
//create this.widgetNavStateNode
this.navStateNode = this._createNavStateNode();
}
var data = this.navStateNode.getRef();
var params = data[this.navStateModel.PARAMS];
if (!params) {
data[this.navStateModel.PARAMS] = {};
params = data[this.navStateModel.PARAMS];
}
if (!params._listeners) {
params._listeners = {};
}
var listenerId = this.navStateModel._generateListenerId();
params._listeners[listenerId] = listener; //save the function pointer here
return listenerId;
},
removeListener: function(listenerId) {
if (!this.navStateNode) {
return null;
}
var data = this.navStateNode.getRef();
var params = data[this.navStateModel.PARAMS];
if (params && params._listeners) {
var listeners = params._listeners;
if (listeners[listenerId]) {
listeners[listenerId] = null;
delete listeners[listenerId];
return true;
}
}
return false;
//listener not found
},
_setItems: function(changedItems) {
// add data to navigationstate
for (var i in changedItems) {
if (changedItems[i] && changedItems[i] == this.DELETE_TOKEN) {
this.removeItem(i);
} else if (changedItems[i]) {
this.setItemValue(i, changedItems[i]);
}
}
}
});
com.ibm.mm.enabler.model.state.ShareableParameterSetAccessorImpl.GLOBAL_SCOPE = "global";
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.LayoutContainerAccessor_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.LayoutContainerAccessor_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.LayoutContainerAccessor_API");
dojo.provide("com.ibm.mashups.enabler.model.state.LayoutContainerAccessor");
/**
* Interface representing a LayoutContainerAccessor. Reserved layout container paramers:
* "w" : the reserved parameter for layout container width.
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.LayoutContainerAccessor", [com.ibm.mashups.enabler.model.state.Accessor], {
/**
* @private
*/
constructor:function (navStateModel, componentId, pageId) {
},
/**
* Returns the id of the layout container
* @type String
* @return {String} ID of required layout container
*/
getID:function() {
},
/**
* Returns the size of the required layout container
* @type Object
* @return {Object} A JSON object representing the layout container width, for example: {w:"70%"}
*/
getSize:function() {
},
/**
* Set the size of a layout container
* @param {String} width The width of the layout container
* @type LayoutContainerAccessor
* @return{LayoutContainerAccessor} return an handle of LayoutContainerAccessor upon successful, null
upon failure.
*/
setSize:function(width) {
},
/**
* Confirms whether it's possible or not to set the layout container to the new width and height
* @param {String} width The width of the layout container
* @type Boolean
* @return{Boolean} return true if it's possible to set layout container to the new width and height
*/
confirmSetSize:function(width) {
return true;
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.LayoutContainerAccessorImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.LayoutContainerAccessorImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.LayoutContainerAccessorImpl");
dojo.declare("com.ibm.mm.enabler.model.state.LayoutContainerAccessorImpl", [com.ibm.mashups.enabler.model.state.LayoutContainerAccessor], {
constructor: function(navStateModel, containerId, pageId){
this.navStateModel = navStateModel;
this.cid = containerId;
this.pid = pageId;
var delim = this.navStateModel.DELIMITER;
var path = this.LAYOUT_PREFIX;
path += delim + this.pid;
this.layoutNavStateNode = navStateModel._find(path);
if (this.layoutNavStateNode) {
path += delim + this.VALUE + delim + this.cid;
this.layoutContainerNavStateNode = navStateModel._find(path);
}
else {
this.layoutContainerNavStateNode = null;
}
},
LAYOUT_PREFIX: "lcparams",
WIDTH: "w",
SYSTEMSTATE: "rp",
VALUE: "value",
PARAMS: "params",
MODE: "md",
RP: {
w: "w"
},
getID: function(){
return this.cid;
},
_getLayoutContainerSystemState: function(key){
var value = null;
if (!this.layoutContainerNavStateNode) {
return null;
}
var data = this.layoutContainerNavStateNode.getRef();
if (data && data[this.VALUE]) {
if (data[this.VALUE][this.SYSTEMSTATE]) {
data = data[this.VALUE][this.SYSTEMSTATE];
if (data && data[key]) {
value = data[key];
}
}
}
return value;
},
_setLayoutContainerSystemState: function(key, value){
var data;
//overwrite behavior
if (!this.layoutContainerNavStateNode) {
this.layoutContainerNavStateNode = this._createLayoutContainerNavStateNode();
}
data = this.layoutNavStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime();
data = this.layoutContainerNavStateNode.getRef();
var keyRef = null;
data[this.VALUE] = data[this.VALUE] ? data[this.VALUE] : {};
data[this.VALUE][this.SYSTEMSTATE] = data[this.VALUE][this.SYSTEMSTATE] ? data[this.VALUE][this.SYSTEMSTATE] : {};
keyRef = data[this.VALUE][this.SYSTEMSTATE];
keyRef[key] = value;
this.navStateModel.setDirty(true);
return this;
},
_createLayoutNavStateNode: function(){
var aNode = this.navStateModel.create({
key: this.pid
});
var parentNode = this.navStateModel._find(this.LAYOUT_PREFIX);
if (!parentNode) {
var temp = this.navStateModel.create({
key: this.LAYOUT_PREFIX
});
this.navStateModel.insert(temp, this.navStateModel._getRoot());
parentNode = this.navStateModel._find(this.LAYOUT_PREFIX);
}
this.navStateModel.insert(aNode, parentNode);
aNode = this.navStateModel._find(this.LAYOUT_PREFIX + this.navStateModel.DELIMITER + this.pid);
return aNode;
},
_createLayoutContainerNavStateNode: function(){
//overwrite behaviour
if (!this.layoutNavStateNode) {
this.layoutNavStateNode = this._createLayoutNavStateNode();
}
var data = this.layoutNavStateNode.getRef();
data[this.VALUE] = data[this.VALUE] ? data[this.VALUE] : {};
var delim = this.navStateModel.DELIMITER;
var path = this.LAYOUT_PREFIX + delim + this.pid + delim + this.VALUE;
var aNode = this.navStateModel.create({
key: this.cid
});
var parentNode = this.navStateModel._find(path);
this.navStateModel.insert(aNode, parentNode);
aNode = this.navStateModel._find(path + delim + this.cid);
return aNode;
},
getSize: function(){
var size = {};
var width = this._getLayoutContainerSystemState(this.WIDTH);
if (width) {
size[this.WIDTH] = width;
return size;
}
else {
return null;
}
return size;
},
setSize: function(width){
if (width) {
this._setLayoutContainerSystemState(this.WIDTH, width);
}
return this;
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.LayoutContainerAccessor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.LayoutContainerAccessor"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.LayoutContainerAccessor");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.LayoutAccessor_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.LayoutAccessor_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.LayoutAccessor_API");
dojo.provide("com.ibm.mashups.enabler.model.state.LayoutAccessor");
/**
* Interface representing a LayoutAccessor. Reserved layout container parameters:
* "templateURL" : the reserved parameter for layout template URL.
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.LayoutAccessor", [com.ibm.mashups.enabler.model.state.Accessor], {
/**
* @private
*/
constructor:function (navStateModel, pageId) {
},
/**
* Returns the layout template URL (can be used to determine if the state layout is inconsistent with the page instance layout)
* @type String
* @return {String} A url to the layout's template. Uses dav: endpoint notation, e.g. "dav:filestore/layout-tempates/2ColumnEqual"
*/
getTemplateURL:function() {
},
/**
* Sets the layout template URL
* @param {String} url The layout templateURL. Uses dav: endpoint notation, e.g. "dav:filestore/layout-tempates/2ColumnEqual"
* @type LayoutAccessor
* @return{com.ibm.mashups.enabler.model.state.LayoutAccessor} returns a LayoutAccessor upon success, null
upon failure.
*/
setTemplateURL:function(url) {
},
/**
* Returns the layout container accessor for the specified layout container id in this layout. (Note: Possibly non-intinutively Layout contains LayoutContainers.)
* @param {String} containerId The layout container id for the desired layout container.
* @type LayoutContainerAccessor
* @return {com.ibm.mashups.enabler.model.state.LayoutContainerAccessor} Returns the specified LayoutContainerAccessor upon success, null
upon failure.
*/
getContainerAccessor:function(containerId) {
},
/**
* Removes all layout containers and the template URL (can be used to remove obsolete layout's i.e. when the state layout is not the same as the page instance layout)
* @param {Array} pageWidgets Set of widgets on page that if in model should have their size removed. Optional parameter.
* @type LayoutContainerAccessor
* @return{com.ibm.mashups.enabler.model.state.LayoutAccessor} Returns a LayoutAccessor upon success, null
upon failure.
*/
removeAll:function(pageWidgets) {
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.LayoutAccessorImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.LayoutAccessorImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.LayoutAccessorImpl");
dojo.declare("com.ibm.mm.enabler.model.state.LayoutAccessorImpl", [com.ibm.mashups.enabler.model.state.LayoutAccessor], {
constructor: function(navStateModel, pageId){
this.navStateModel = navStateModel;
this.pid = pageId;
this.path = this.LAYOUT_PREFIX + this.navStateModel.DELIMITER + this.pid;
this.layoutNavStateNode = null;
},
LAYOUT_PREFIX: "lcparams",
WIDGET_PREFIX: "wparams",
VALUE: "value",
TEMPLATE_URL: "templateURL",
SYSTEMSTATE: "rp",
WIDTH: "w",
HEIGHT: "h",
_getLayoutState: function(key){
var value = null;
// we need to check if the layoutNavsState node exists for each call because
// layout containers can create this node too.
if (!this.layoutNavStateNode) {
this.layoutNavStateNode = this.navStateModel._find(this.path);
if (!this.layoutNavStateNode)
return null;
}
var data = this.layoutNavStateNode.getRef();
if (data && data[key])
value = data[key];
return value;
},
_setLayoutState: function(key, value){
var data;
//overwrite behavior
if (!this.layoutNavStateNode) {
this.layoutNavStateNode = this.navStateModel._find(this.path);
if (!this.layoutNavStateNode)
this.layoutNavStateNode = this._createLayoutNavStateNode();
}
data = this.layoutNavStateNode.getRef();
data.params = data.params ? data.params : {};
data.params.lm = new Date().getTime();
data[key] = value;
this.navStateModel.setDirty(true);
return this;
},
_createLayoutNavStateNode: function(){
var aNode = this.navStateModel.create({
key: this.pid
});
var parentNode = this.navStateModel._find(this.LAYOUT_PREFIX);
if (!parentNode) {
var temp = this.navStateModel.create({
key: this.LAYOUT_PREFIX
});
this.navStateModel.insert(temp, this.navStateModel._getRoot());
parentNode = this.navStateModel._find(this.LAYOUT_PREFIX);
}
this.navStateModel.insert(aNode, parentNode);
aNode = this.navStateModel._find(this.path);
return aNode;
},
getTemplateURL: function(){
return this._getLayoutState(this.TEMPLATE_URL);
},
setTemplateURL: function(url){
return this._setLayoutState(this.TEMPLATE_URL, url);
},
removeAll: function(pageWidgets) {
var delim = this.navStateModel.DELIMITER;
if (pageWidgets && this.navStateModel._find(this.WIDGET_PREFIX)) {
var i;
var systemState;
for (i = 0; i < pageWidgets.length; i++) {
systemState = this.navStateModel._find(this.WIDGET_PREFIX + delim + pageWidgets[i] + delim + this.VALUE + delim + this.SYSTEMSTATE);
if (systemState) {
systemState = systemState.getRef();
delete systemState[this.WIDTH];
delete systemState[this.HEIGHT];
this.navStateModel.setDirty(true);
}
}
}
if (this.layoutNavStateNode) {
this.navStateModel.remove(this.layoutNavStateNode);
this.navStateModel.setDirty(true);
delete this.layoutNavStateNode;
}
return this;
},
getContainerAccessor: function(containerId) {
return new com.ibm.mm.enabler.model.state.LayoutContainerAccessorImpl(this.navStateModel, containerId, this.pid);
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.LayoutAccessor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.LayoutAccessor"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.LayoutAccessor");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.AccessorFactory_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.AccessorFactory_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.AccessorFactory_API");
dojo.provide("com.ibm.mashups.enabler.model.state.AccessorFactory");
/**
* Interface representing an AccessorFactory. Accessor API should be used to read/write information from NavigationStateModel.
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.AccessorFactory", null, {
/**
* Returns the Accessor to access Page selection in each Space
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navStateModel NavigationStateModel to get Space/Page Selection
* @param {String} spaceId spaceId to getPage Selection
* @type com.ibm.mashups.enabler.model.state.PageAccessor
* @return {com.ibm.mashups.enabler.model.state.PageAccessor} The PageAccessor of NavigationStateModel
*/
getPageAccessor:function(navStateModel,spaceId) {
// look for node in model and instatiate the Page Accessor with Node
},
/**
* Returns the Accessor to access Space selection
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navStateModel NavigationStateModel to get Space Selection
* @type com.ibm.mashups.enabler.model.state.SpaceAccessor
* @return {com.ibm.mashups.enabler.model.state.SpaceAccessor} The SpaceAccessor of NavigationStateModel
*/
getSpaceAccessor:function(navStateModel) {
},
/**
* Returns the Widget Accessor to access Widget state information
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navStateModel to Widget Navigation State
* @param {String} widgetId to Widget Navigation State
* @type com.ibm.mashups.enabler.model.state.WidgetAccessor
* @return {com.ibm.mashups.enabler.model.state.WidgetAccessor} The WidgetAccessor of NavigationStateModel
*/
getWidgetAccessor:function(navStateModel, widgetId) {
},
/**
* Returns the Accessor to access Page mode of current page
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navStateModel NavigationStateModel to get Space/Page Selection
* @type com.ibm.mashups.enabler.model.state.PageModeAccessor
* @return {com.ibm.mashups.enabler.model.state.PageModeAccessor} The PageModeAccessor of NavigationStateModel
*/
getPageModeAccessor:function(navStateModel) {
// look for node in model and instatiate the Page Accessor with Node
},
/**
* Returns the Accessor to access the sharable parameters
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navStateModel NavigationStateModel to get ShareableParameterSet
* @param {String} id id of ShareableParameterSet
* @param {String} scope optional scope for the sharable item set. If not provided or null, the global scope is returned.
* @type com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor
* @return {com.ibm.mashups.enabler.model.state.ShareableParameterSetAccessor} The ShareableParameterSetAccessor of NavigationStateModel
*/
getShareableParameterSetAccessor:function(navStateModel,id,scope) {
// look for node in model and instatiate the Page Accessor with Node
},
/**
* Returns the Layout Accessor to access page layout state information
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navStateModel to Layout Navigation State
* @param {String} pageId of the page containing the Layout Container
* @type com.ibm.mashups.enabler.model.state.LayoutAccessor
* @return {com.ibm.mashups.enabler.model.state.LayoutAccessor} The LayoutAccessor of NavigationStateModel for the specified page
*/
getLayoutAccessor:function(navStateModel, pageId){
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.AccessorFactoryImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.AccessorFactoryImpl"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.AccessorFactoryImpl");
dojo.declare("com.ibm.mm.enabler.model.state.AccessorFactoryImpl", [com.ibm.mashups.enabler.model.state.AccessorFactory], {
constructor: function() {
},
getPageAccessor: function(navStateModel, spaceId) {
return new com.ibm.mm.enabler.model.state.PageAccessorImpl(navStateModel, spaceId);
},
getPageModeAccessor: function(navStateModel) {
return new com.ibm.mm.enabler.model.state.PageModeAccessorImpl(navStateModel);
},
getSpaceAccessor: function(navStateModel) {
return new com.ibm.mm.enabler.model.state.SpaceAccessorImpl(navStateModel);
},
getWidgetAccessor: function(navStateModel, widgetId) {
return new com.ibm.mm.enabler.model.state.WidgetAccessorImpl(navStateModel, widgetId);
},
getShareableParameterSetAccessor: function(navStateModel, name, scope) {
return new com.ibm.mm.enabler.model.state.ShareableParameterSetAccessorImpl(navStateModel, name, scope);
},
getLayoutAccessor:function(navStateModel, pageId){
return new com.ibm.mm.enabler.model.state.LayoutAccessorImpl(navStateModel, pageId);
}
});
com.ibm.mashups.enabler.model.state.AccessorFactory = new com.ibm.mm.enabler.model.state.AccessorFactoryImpl();
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.AccessorFactory"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.AccessorFactory"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.AccessorFactory");
}
if(!dojo._hasResource["com.ibm.mashups.enabler.model.state.NavigationStateModel_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.model.state.NavigationStateModel_API"] = true;
dojo.provide("com.ibm.mashups.enabler.model.state.NavigationStateModel_API");
dojo.provide("com.ibm.mashups.enabler.model.state.NavigationStateModel");
/**
* Interface for a Navigation state model.
* Navigation State API does not garantee that any modifications issued on the API have any further impact on the
* user experience of any widgets or components on the page. Widgets or components may choose to listen to changes on the Navigation
* State Model and react properly upon those changes. However any user experience change cuased by those components are not part of
* the contract of this API and therefore these UI behaviour may change going forward
*
* AccessorFactory API should be used to read/write navigation state within NavigationStateModel.
* var navStateModel=com.ibm.mashups.enabler.model.state.NavigationStateModelFactory.getNavigationStateModel();
* var widgetAccessor = com.ibm.mashups.enabler.model.state.AccessorFactory.getWidgetAccessor(navStateModel);
* widgetAccessor.setSize("200","300");
* var deferred = navStateModel.commit();
* deferred.setFinishedCallback(cb);
* deferred.start();
*
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.NavigationStateModel", null, {
/**
* The name of the event to handle to get NavState update notifications.
* @type String
*/
ONNAVSTATEUPDATED:"com.ibm.mashups.enabler.model.state.onNavStateUpdated",
/**
* This method starts a global transaction for a NavigationStateModel object
* @type void
*/
startTransaction: function () {
return;
},
/**
* This method commits all changes done withing a global transaction for a NavigationStateModel object
* @type void
*/
commitTransaction: function () {
return;
},
/**
* This method discards all changes done within a transaction for a NavigationStateModel object and restores the original NavigationStateModel object.
* @type void
*/
discardTransaction: function () {
return;
},
/**
* This method starts a global transaction for a NavigationStateModel object
* @return {boolean} Returns true if a transaction has been started, false otherwise.
*/
isTransaction: function () {
return false;
},
/**
* Commits the modifications applied to this model and all dependent models.
* @param {Object} additionalParams Optional JSON object to control various aspects while commiting
* addToHistory
(Boolean) - true
if the state should be added to the browser history, false
otherwise
* allowRedirect
(Boolean) - true
if the page should be refreshed after the commit, false
otherwise. Note, this parameter is ignored if the commit is synchronous
* @return {DeferredOperation} a deferred object used to start this operation.
* The return value when executed through the deferred object is null
*/
commit: function (additionalParams) {
return new com.ibm.mashups.enabler.Deferred();
},
/**
* Discards the modifications applied to this model.
* @type void
*/
discard: function () {
return;
},
/**
* Dispose this model completely all the navigation state will be destroyed.
* @type void
*/
dispose: function () {
return;
}
});
}
if(!dojo._hasResource["com.ibm.mashups.enabler.services.IdentificationService_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.enabler.services.IdentificationService_API"] = true;
dojo.provide("com.ibm.mashups.enabler.services.IdentificationService_API");
dojo.provide("com.ibm.mashups.enabler.services.IdentificationService");
/**
* Interface to work with client side ids.
* @ibm-spi
* @ibm-module Base
* @since 3.0
*/
dojo.declare("com.ibm.mashups.enabler.services.IdentificationService", null, {
/**
* Returns a new client side ID.
* @return {String} client side id; never null
.
*/
createClientID: function() {
},
/**
* This method attaches a client side id to make it know to the service
* @param {Object} clientID client side id as string or Identifiable object
* @return {void}
* @since 3.0.0.1
*/
attachClientID: function(clientID) {
},
/**
* Releases an earlier through getClientID loaded client id.
* @param {String} id the id to release
* @return {void}
*/
releaseClientID: function(id) {
},
/**
* Checks whether the specified id is a client id of this IdentificationService
* @param {String} id the id to check for client id
* @return {boolean} true if the specified id is a client id false otherwise.
*/
isClientID: function(id) {
},
/**
* Checks whether the specified id is a server id generated by the underling server implementation
* @param {String} id the id to check for server id
* @return {boolean} true if the specified id is a server id false otherwise.
*/
isServerID: function(id) {
},
/**
* Checks whether the specified id is neither an client id nor an server id but is specified outside the mashup framework.
*
* @param {String} id the id to check for alien id
* @return {boolean} true if the specified id is a alien id false otherwise.
*/
isAlienID: function(id) {
},
/**
* This method attaches a server side id to an existing client side id.
* @param {Object} clientID client side id as string or Identifiable object
* @param {Object} serverID server side id as string or Identifiable object
* @return {void}
*/
attachServerID: function(clientID, serverID) {
},
/**
* Returns the attached server side id for any given client side id. Returns the
* specified id, if it cannot be resolved.
* @param {String} id the id to resolve
* @return {String} id the resolved id
*/
resolveID: function(id) {
},
/**
* Returns the attached server side id for any given client side id. Returns the
* specified id, if it cannot be resolved.
* @param {String} id the id to resolve
* @return {com.ibm.mashups.enabler.Identifiable} id the resolved id
*/
resolveIdentifiable: function(id) {
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.utils.Utils"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.utils.Utils"] = true;
/*WARNING: don't include this class in any iWidget2 modules,it should be exclusively used by Model related api*/
dojo.provide("com.ibm.mm.enabler.utils.Utils");
dojo.declare("com.ibm.mm.enabler.utils.UtilsImpl", null, {
constructor: function() {
// we do a lazy init
this.serviceJson = null;
},
_lazyInit: function() {
if (this.serviceJson) {
return;
}
this.xmlDom = com.ibm.mm.enabler.utils.Dom.createDocument();
// service document and initialization
this.serviceJson = com.ibm.mm.enabler.model.ServiceDocumentModel.getCollectionData(com.ibm.mm.enabler.model.ServiceDocumentModel.SERVICE_NAVIGATION);
this.prefix = this.serviceJson.idprefix;
var nsf = com.ibm.mm.enabler.model.NameSpaceFactory;
this.ns = dojo.delegate(this.serviceJson.namespaces, nsf.getNameSpaces([nsf.NS_ATOM]));
},
createNode: function(name, ns) {
this._lazyInit();
return com.ibm.mm.enabler.utils.Dom.createElement(this.xmlDom, name, ns);
},
createLinkNode: function(href, rel, ns) {
var linkNode = this.createNode("atom:link", ns);
linkNode.setAttribute("href", href);
linkNode.setAttribute("rel", rel);
return linkNode;
},
createExtLinkNode: function(href, rel, extrel) {
this._lazyInit();
var nsf = com.ibm.mm.enabler.model.NameSpaceFactory;
var linkNode = this.createNode("atom:link", this.ns[nsf.NS_ATOM]);
linkNode.setAttribute("href", href);
if (rel) {
linkNode.setAttribute("rel", rel);
}
com.ibm.mm.enabler.utils.Dom.setAttributeWithNS(this.xmlDom, linkNode, "ext:rel", "rel", this.ns.ext, extrel);
return linkNode;
},
getIdFromExtUri: function(prefix, node) {
this._lazyInit();
var id = null;
var uri = com.ibm.mm.enabler.utils.Dom.getAttributeWithNS(node, "ext:uri", "uri", this.ns.ext);
// remove model scope from id
if (uri) {
// check for associative id
var aPos = uri.indexOf("@");
if (aPos != -1) {
uri = uri.slice(0, aPos);
}
id = uri;
// remove model scope from id
var idPos = id.lastIndexOf(":");
if (idPos != -1) {
id = id.slice(idPos + 1);
}
idPos = id.toUpperCase().lastIndexOf("%3A");
if (idPos != -1) {
id = id.slice(idPos + 3);
}
idPos = id.lastIndexOf("/");
if (idPos != -1) {
id = id.slice(idPos + 1);
}
}
return id;
},
getHrefFromIdentifiable: function(identifiable) {
return (identifiable && (typeof identifiable._getParameters == "function")) ? identifiable._getParameters().href : null;
},
getIdFromIdentifiable: function(identifiable) {
if(com.ibm.mm.enabler.utils.Misc.isInstanceOf(identifiable, com.ibm.mashups.enabler.Identifiable)) {
return identifiable.getID();
} else if(dojo.isString(identifiable)) {
return dojo.string.trim(identifiable);
} else {
return identifiable;
}
},
setAttributeWithNS: function(element, attName, nsUri, value) {
this._lazyInit();
com.ibm.mm.enabler.utils.Dom.setAttributeWithNS(this.xmlDom, element, attName, null, nsUri, value);
},
createFeed: function(id, title, entry, namespaces) {
var ns = "";
for (var prefix in namespaces) {
if (Object.prototype.hasOwnProperty.call(namespaces,prefix)) {
ns += "xmlns:" + prefix + "=\"" + namespaces[prefix] + "\" ";
}
}
var time = new Date();
var feed = '\n' +
'
* Paramters are predefined.
*
* {
*
* sid:{
* value: <sid>,
* params:{}
* },
* pid:{
* value: <pid>,
* params:{}
* },
* pageselection:{
* <spaceid>:{
* value: <pageid>,
* params:{lm:<timestamp>}
* },
* <spaceid>:{
* value: <pageid>,
* params:{lm:<timestamp>}
* }
* },
* wparams:{
* <wid>:{
* value: {
* rp:{w:<"200">,h:<"300">,st:<"NORMAL">},
* cp:{<page:"3">}
* },
* params:{lm:<timestamp>}
* },
* <wid>:{
* value: {
* rp:{w:<"300">,h:<"400">,st:<"MAX">},
* cp:{<page:"4">}
* },
* params:{lm:<timestamp>}
* }
* },
* lcparams:{
* <pid>:{
* templateURL: "<dav:filestore/layout-templates/2ColumnEqual>",{
* value: {
* <lcid>:{
* value: {
* rp:{w:<"70%">}
* }
* },
* <lcid>:{
* value: {
* rp:{w:<"30%">}
* }
* }
* },
* params:{lm:<timestamp>}
* },
* <pid>:{
* templateURL: "<dav:filestore/layout-templates/3ColumnEqual>",{
* value: {
* <lcid>:{
* value: {
* rp:{w:<"30%">}
* }
* },
* <lcid>:{
* value: {
* rp:{w:<"30%">}
* }
* },
* <lcid>:{
* value: {
* rp:{w:<"40%">}
* }
* }
* },
* params:{lm:<timestamp>}
* }
* },
* sparams:{
* <id>:{
* global: {
* params:{lm:<timestamp>},
* value: {
* <name>:{
* value: <value>,
* params:{lm:<timestamp>}
* },
* <name>:{
* value: <value>,
* params:{lm:<timestamp>}
* }
* },
* <scope-id>: {
* params:{lm:<timestamp>},
* value: {
* <name>:{
* value: <value>,
* params:{lm:<timestamp>}
* },
* <name>:{
* value: <value>,
* params:{lm:<timestamp>}
* }
* }
* }
* }
*
* Navigation State parameters will be written to url or persistence store upon configuration.
* Here's the default configuration:
*
*
*
* Following is the list of parameters that are configurable:
*
*
*
* Upon page loading or page refresh, navigationstatemodel is initialized with navigation state data from url or
* persistence. "decode" will be used to load data from url and "preprocess" will be used to load data from persistence.
* Upon commit on NavigationStateModel updates, navigation state data will be sent to url or sent to persistence.
* "postprocess" will send the updates to persistence and "encode" will generate the new url fragment based on latest navigation state.
*
*
* @ibm-spi
* @ibm-module Base
*/
dojo.declare( "com.ibm.mashups.enabler.model.state.NavigationStateProcessor", null, {
/**
* Encodes the specified widget instance id.
* @param {String} wid widget instance id; different page may have same widget instance id.
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navigationStateModel
* @type String
* @return {String} unique id, representing a widget instance on a page
*/
encodeWidgetIdentifier: function(wid, navigationStateModel){
},
/**
* Decodes a unique widget instance id.
* @param {String} wid unique widget instance id.
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navigationStateModel
* @type String
* @return {String} widget instance id
*/
decodeWidgetIdentifier: function(wid, navigationStateModel){
},
/**
* Decode the url and store the state into a JSON Object. JSON object should be
* pass into Callback. If no callback is defined, navigation state is returned.
* callback:function(state){};
* @param {String} url url string
* @param {Function} callback callback function
* @type Object
* @return {Object} navigation state object
*/
decode:function(url,callback){
},
/**
* Encode state object and generate fragment. Fragment should be passed into callback function.
* callback(fragment);
* If no callback is defined, url fragment is returned.
* @param {Object} state JSON object representing Mashup state
* @param {Function} callback callback function which takes the following parameters:
* additionalParams
(JSON) - if the additionalParams
was passed in to the encode
* function, then it must be passed back into the callback function
* responseParams
(JSON) - Optional If additionalParams.allowRedirect
is true and this is an asynchronous commit,
* then the implementation of this function may pass responseParams.doRedirect
set to true to refresh the page after the commit is completed
* @param {Object} oldState JSON object representing Mashup state before it gets updated
* @param {Object} additionalParams Optional JSON object to control various aspects of encoding or the registered callback
* @param {com.ibm.mashups.enabler.model.state.NavigationStateModel} navigationStateModel
* @type String
* @return {String} the url fragment that contains navigation state
*/
encode:function(state,callback,oldState, additionalParams, navigationStateModel){
},
/**
* @deprecated Use generateURL instead.
*
* @param {Object} state
* @param {Function} callback
* @param {JSON} params
* @type String
*/
generateUrl:function(state,callback,params){
},
/**
* Encode state object and generate full url. URL should be absolute URL. URL should be passed into callback function.
* If no callback, full url is returned.
* callback:function(url){};
* Sample parameter: {nohash:"true"}
* if "nohash" is set to true,the returned url will not contain state in hash.
* By default Lotus Mashups only supports url that contains navigation state in hash.
* Extensions can be added to support additional parameter by using extension registry.
*
* @param {Object} state JSON object representing Mashup state
* @param {Function} callback callback function
* @param {JSON} params additional parameter in json format
* @type String
* @return {String} full url that contains navigation state
*/
generateURL:function(state,callback,params){
},
/**
* Preprocess could be used to filter the original state. For example,
* pulling more state information that's cached in cookie.
* The final state should be passed into callback.
* callback:function(state){};
* If no callback, state object will be returned.
* @param {Object} state JSON object representing Mashup state
* @param {Function} callback callback function
* @type Object
* @return {Object} object contains navigation state
*/
preprocess:function(state,callback){
},
/**
* Dispose the any navigation state that's persisted. Callback is executed when dispose action is done.
* callback:function(){};
* @param {Function} callback callback function
* @type void
*/
dispose:function(callback){
},
/**
* Postprocess could be used to filter the original state before url is generated.
* For example,some state information should be persisted into cookie.
* The final state should be passed into callback.
* callback:function(state){};
* If no callback, state object will be returned.
* @param {Object} state JSON object representing Mashup state
* @param {Function} callback callback function
* @param {Object} oldState JSON object representing Mashup state before it gets updated
* @param {Object} additionalParams Optional JSON object to control various aspects of encoding or the registered callback.
* @type Object
* @return {Object} object contains navigation state
*/
postprocess:function(state,callback,oldState, additionalParams){
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.model.state.CookieManager"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.model.state.CookieManager"] = true;
dojo.provide("com.ibm.mm.enabler.model.state.CookieManager");
dojo.declare("com.ibm.mm.enabler.model.state.CookieManager", null, {
//cookie limit is 4096byte(at least for IE)
//cookie is persisted per user, cookiename uid+"_state"
//need to split if we run into problems
/* {sid:{value: function(ievent)
@type String
*/
handlingFn:/*String*/ "",
/**
it returns a user-oriented description (markup allowed) of the event in the requested locale. If no locale is supplied, the default locale of the iWidget is used (with "en" being the default iWidget locale). The description is likely to be displayed when a user is wiring event flow between iWidgets.
@param{String} locale required locale. Can be NULL. If no locale is supplied, the default locale of the iWidget is used (with "en" being the default iWidget locale).
@type String
@returns{String} Return the description of a given locale,if no locale is provided, then the default locale of the iWidget is used.
@deprecated please use getAttribute("description",locale) instead
@since Deprecated since Version 2.0
*/
getDescription: function(/*String*/locale) {
return null;
},
/**
This provides the default language of all the localized attributes within this event description.
@type String
*/
lang:/*String*/ "",
/**
This indicates if an event is a handled event or not. Default value is false.
@type Boolean
*/
isHandled: false,
/**
This indicates if an event is a published event or not. Default value is false.
@type Boolean
*/
isPublished: false,
/**
This method returns the asking value of an attribute of the event description. Each event description should have title and description . Normally title and description should be globalized, default locale should be specified by using the iso language code, if missing, the value for the default locale will be en.
@param{String} attributeName name of attribute. Can Not be NULL.
@param{String} locale required locale. Can be NULL. If no locale is supplied, the default locale of the iWidget is used (with "en" being the default iWidget locale).
@type String
@returns{String} Return the value of the required attribute,if locale is provided, it returns locale specific value.
*/
getAttribute: function(/*String*/attributeName,/*String*/ locale) {
return null;
},
/**
The method set the value for a given event description attribute.It returns a handle of this eventdescription, return null upon failure. If the locale parameter is absent, then the given attribute won't be locale specific.
@param{String} attributeName name of attribute. Can Not be NULL.
@param{String} attributeValue value of attribute. Can Not be NULL.
@param{String} locale optional, locale. Can be NULL.
@type com.ibm.mashups.iwidget.IEventDescription
@returns{com.ibm.mashups.iwidget.IEventDescription} return a handle of this eventdescription, return null upon failure..
*/
setAttribute: function(/*String*/attributeName, /* String*/ attributeValue, /*String*/ locale) {
}
});
}
if(!dojo._hasResource["com.ibm.mm.iwidget.IEventDescriptionImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.iwidget.IEventDescriptionImpl"] = true;
dojo.provide("com.ibm.mm.iwidget.IEventDescriptionImpl");
dojo.declare("com.ibm.mm.iwidget.IEventDescriptionImpl", com.ibm.mashups.iwidget.IEventDescription, {
constructor: function(/*String*/name,/*function*/ handlingFn,/*String*/ type,/*String*/ description,/*String[]*/ aliases, defaultLang,/*[]*/ descriptions) {
if (dojo.isString(name)) {
/*backward compatibility, some widget are still trying to create iEventDescription by using this constuctor as is!*/
var obj = {};
obj.name = name;
handlingFn = handlingFn || null;
if (handlingFn) {
obj.handlingFn = handlingFn;
obj.isHandled = true;
obj.isPublished = false; //backward compatibility either isPublished or isHandled
}
else {
obj.isPublished = true;
}
type = type || null;
if (type) {
obj.type = type;
}
defaultLang = defaultLang || null;
if (defaultLang) {
obj.lang = defaultLang;
}
else {
obj.lang = "en";
}
//how to set isPublished? or set it later
obj.attributes = {};
obj.localizedAttributes = {};
aliases = aliases || null;
if (aliases) {
obj.attributes.aliases = aliases;
}
descriptions = descriptions || null;
if (descriptions) {
obj.localizedAttributes = descriptions;
}
//backward compatibility
if (description) {
if (!obj.localizedAttributes[obj.lang]) {
obj.localizedAttributes[obj.lang] = {};
}
obj.localizedAttributes[obj.lang].description = description;
}
this._internalJsonObj = obj;
}
else {
this._internalJsonObj = name;
}
this.initPredefinedFields(this._internalJsonObj);
},
initPredefinedFields: function(obj) {
//initialize fields
this.name = obj.name;
this.type = obj.type;
this.lang = obj.lang;
this.handlingFn = obj.handlingFn;
this.isHandled = obj.isHandled;
this.isPublished = obj.isPublished;
// if (this.handlingFn) {
// this.isHandled = true;
// }
// else {
// this.isHandled = false;
// }
// // set isPublished to true only when both isHandled and isPublished is not defined
// // this is required for backward compatiblity reason
// if ((obj.isPublished && obj.isPublished == "true") || obj.isPublished) {
// this.isPublished = true;
// }
},
getDescription: function(locale) {
return this._getLocalizedAttribute("description", locale);
},
getTitle: function(locale) {
return this._getLocalizedAttribute("title", locale);
},
_getLocalizedAttribute: function(attributeName, locale) {
var attValue = null, altAttValue = null;
var lc = com.ibm.mashups.enabler.context.Factory.getLocalizedContext(locale, this.lang);
var finalLocale = lc.getLocale(this);
if (this.localemapping && this.localemapping[finalLocale]) {
finalLocale = this.localemapping[finalLocale];
}
if (this._internalJsonObj.localizedAttributes) {
altAttValue = this._internalJsonObj.localizedAttributes[finalLocale];
if (altAttValue) {
attValue = altAttValue[attributeName];
}
}
if (!attValue) {
attValue = this[attributeName];
}
if (typeof attValue == "undefined") {
attValue = null;
}
return attValue;
},
setOnRemoveWire: function(/*String*/handler) {
if (typeof handler == "undefined" || handler === null) {
handler = "onRemoveWire";
}
//this.onRemoveWire = handler;
if (typeof this._internalJsonObj.attributes == "undefined") {
this._internalJsonObj.attributes = {};
}
this._internalJsonObj.attributes.onRemoveWire = handler;
return this;
},
getOnRemoveWire: function() {
//can remove?
if (typeof this._internalJsonObj.attributes != "undefined" && this._internalJsonObj.attributes.onRemoveWire) {
return this._internalJsonObj.attributes.onRemoveWire;
}
return null;
},
setOnNewWire: function(/*String*/handler) {
if (typeof handler == "undefined" || handler === null) {
handler = "onNewWire";
}
//this.onNewWire = handler;
if (typeof this._internalJsonObj.attributes == "undefined") {
this._internalJsonObj.attributes = {};
}
this._internalJsonObj.attributes.onNewWire = handler;
return this;
},
getOnNewWire: function() {
if (typeof this._internalJsonObj.attributes != "undefined" && this._internalJsonObj.attributes.onNewWire) {
return this._internalJsonObj.attributes.onNewWire;
}
return null;
},
getLocales: function() {
var locales = [];
var mapping = {};
if (this._internalJsonObj.localizedAttributes) {
for (var i in this._internalJsonObj.localizedAttributes) {
if (Object.prototype.hasOwnProperty.call(this._internalJsonObj.localizedAttributes,i)) {
locales.push(i);
var normalizedLocale = com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale(i);
if (normalizedLocale != i) {
mapping[normalizedLocale] = i;
}
}
}
}
this.localemapping = mapping;
return locales;
},
toString: function() {
//return null or unserialized string, dojo will throw exception if it's not a valid Json obj
var temp = this.toJson();
return dojo.toJson(temp);
},
_getInternalJsonObj: function() {
return this._internalJsonObj;
},
toJson: function() {
var internalJson = {};
for (var i in this._internalJsonObj) {
if (Object.prototype.hasOwnProperty.call(this._internalJsonObj,i)) {
if (i == "handlingFn") { //it could be functionpointer
if (dojo.isFunction(this._internalJsonObj[i])) {
internalJson[i] = "HANDLEFN";
continue;
}
}
internalJson[i] = dojo.clone(this._internalJsonObj[i]);
}
}
return internalJson;
},
clone: function() {
var temp = dojo.toJson(this._internalJsonObj);
if (temp) {
return new com.ibm.mm.iwidget.IEventDescriptionImpl(dojo.fromJson(temp));
}
else {
return null;
}
},
getAttribute: function(attName, locale) {
if (!attName) {
return null;
}
if (!locale) {
if (this._internalJsonObj.attributes && typeof this._internalJsonObj.attributes[attName] != "undefined") {
return this._internalJsonObj.attributes[attName];
}
//get value for default locale
if (this._internalJsonObj.localizedAttributes && this._internalJsonObj.localizedAttributes[this.lang]) {
var attValue = this._internalJsonObj.localizedAttributes[this.lang][attName];
if (attValue) {
return attValue;
}
}
return null; //if no such attributes or localized attributes
}
else {
return this._getLocalizedAttribute(attName, locale);
}
},
setAttribute: function(attName, attValue, locale) {
//todo; if no locale defined and attributes is predefined such as "title","description", set the value on default locale
//return a handle of this eventdescription, return null upon failure.
if (!attName) {
return null;
}
if (typeof attValue == "undefined") {
return null; // allow value to be null
}
if (!locale) {
if (typeof this._internalJsonObj.attributes == "undefined") {
this._internalJsonObj.attributes = {};
}
this._internalJsonObj.attributes[attName] = attValue;
if (attValue === null) {
delete this._internalJsonObj.attributes[attName];
}
return this;
}
if (!this._internalJsonObj.localizedAttributes[locale]) {
this._internalJsonObj.localizedAttributes[locale] = {};
}
this._internalJsonObj.localizedAttributes[locale][attName] = attValue;
if (attValue === null) {
delete this._internalJsonObj.localizedAttributes[locale][attName];
}
return this;
},
copyRuntimeProperties: function(eventDesc2Copy) {
if ((!this.handlingFn) && (eventDesc2Copy.handlingFn)) {
this.handlingFn = eventDesc2Copy.handlingFn;
}
if ((!this._internalJsonObj.handlingFn) && (eventDesc2Copy._internalJsonObj.handlingFn)) {
this._internalJsonObj.handlingFn = eventDesc2Copy._internalJsonObj.handlingFn;
}
if (typeof this._internalJsonObj.attributes == "undefined") {
this._internalJsonObj.attributes = {};
}
for (name in eventDesc2Copy._internalJsonObj.attributes) {
if (!this._internalJsonObj.attributes[name]) {
this._internalJsonObj.attributes[name] = eventDesc2Copy._internalJsonObj.attributes[name];
}
}
}
});
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.IEventDescription"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.IEventDescription"] = true;
dojo.provide("com.ibm.mashups.iwidget.IEventDescription");
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.EventProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.EventProvider"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.EventProvider");
/**
* Interface defines functions to access handled or published event descriptions.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.EventProvider", null, {
/**
* @private
*/
constructor: function() {
},
/**
This method returns an array of event description. Only published event of this widget will be returned.
@type {com.ibm.mashups.iwidget.IEventDescription}
@returns{com.ibm.mashups.iwidget.IEventDescription[] } array of event description
*/
getWidgetPublishedEvents: function() {
},
/**
This method returns an array of event description. Only handled event of this widget will be returned.
@type {com.ibm.mashups.iwidget.IEventDescription[]}
@returns{com.ibm.mashups.iwidget.IEventDescription[] } array of event description
*/
getWidgetHandledEvents: function() {
},
/**
This method returns the required event.
@param {String}name name of required public event
@type {com.ibm.mashups.iwidget.IEventDescription}
@returns{com.ibm.mashups.iwidget.IEventDescription } an event description it returns NULL if event can't be found.
*/
getPublicEvent: function(name) {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.Properties_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.Properties_API"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.Properties_API");
dojo.provide("com.ibm.mashups.iwidget.widget.Properties");
/**
* Interface defines functions to iterates , updates and persist Properties.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.Properties", null, {
/**
* @private
*/
constructor: function() {
},
/**
* This method returns the value of the required item
* @param{String} itemName name of the item.Must never be NULL.
* @param{String} locale the locale of the value to fetch. if locale isn't defined, the
* DEFAULT_LOCALE
will be used
* @return{String} return the value of required item
*/
getItemValue: function(/*String*/itemName, locale) {
},
/**
* This method returns an array of Strings,providing the name of each item.
* @return{String[]} return an array of items names and return NULL if the set contains no item
*/
getAllNames: function() {
return null;
},
/**
* This methods returns the locales for the item specified by itemName
* @param{String} itemName the name of the item for which do get the locales.
* @return{String[]} return an array of locales valid for the specified itemName, returns an empty array if no localized item values are available.
*/
getItemLocales: function(itemName) {
},
/**
* This method allows the caller to check whether a specific item is readOnly or not.
* @param{String} itemName the item name of the item to check readOnly
* @return{Boolean} true
if the item exists and is read only, false
otherwise.
*/
isReadOnly: function(itemName) {
}
});
}
if(!dojo._hasResource["com.ibm.mm.iwidget.widget.PropertiesImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.iwidget.widget.PropertiesImpl"] = true;
dojo.provide("com.ibm.mm.iwidget.widget.PropertiesImpl");
dojo.declare("com.ibm.mm.iwidget.widget.PropertiesImpl", com.ibm.mashups.iwidget.widget.Properties, {
DELETE_TOKEN: "com.ibm.mm.iwidget.widget.DELETE_TOKEN",
TYPE_NEW: "newItem",
TYPE_UPDATE: "updatedValue",
TYPE_REMOVE: "removedItem",
/**
* @param items {ItemSet JSON} the items this Properties class is based on
* @param defaultProps {Properties} The default properties object
**/
constructor: function(items, defaultProps) {
this._defaultProperties = defaultProps;
// create the new object
this._items = {};
if (items) {
this._items = items;
}
this._localizedItems = {};
// define the default locale of this properties set
this.DEFAULT_LOCALE = ibmConfig[com.ibm.mashups.enabler.services.ConfigConstants.DEFAULT_LOCALE];
if (!this.DEFAULT_LOCALE) {
this.DEFAULT_LOCALE = "en";
}
},
/**
* Internal method which can be used by ENABLER components for determining the default locale of an Properties Element
*/
_getItemDefaultLocale: function(itemName) {
var defLocale = null;
if (this._items[itemName]) {
if (this._items[itemName].defaultLocale) {
defLocale = this._items[itemName].defaultLocale;
}
}
if (!defLocale) {
defLocale = null;
}
return defLocale;
},
getLocalizedItemValue:function(itemName,locale){
//internal function, used by private ItemSet
//no fallback to default locale
if (!itemName || !locale) {
return;
}
if (!(itemName in this._items) && !this._defaultProperties) {
return null;
}
var item = this._items[itemName];
var value = null;
if (!item.values) {
return null;
}
var matchLocales = [];
for (var i in item.values) {
if (Object.prototype.hasOwnProperty.call(item.values,i)) {
matchLocales.push(i);
}
}
var normalizedLocale;
// check if we have a value for the specified locale
normalizedLocale = com.ibm.mm.enabler.utils.LocaleHelper.matchLocale(locale, matchLocales);
for (var i in item.values) {
if (normalizedLocale == com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale(i)) {
value = item.values[i];
break;
}
}
if (value == this.DELETE_TOKEN) {
return null;
}
return value;
},
getItemValue: function(itemName, locale) {
// if we don't have an item and don't have default properties, we can exit right away
if (!(itemName in this._items) && !this._defaultProperties) {
return null;
}
// if we don't have the item we can delegate to default props (which we checked earlier)
if (!(itemName in this._items)) {
return this._defaultProperties.getItemValue(itemName, locale);
}
// seems we have an item, so let's do the magic
var item = this._items[itemName];
var value = null;
if ((typeof locale == "undefined" || locale === null) && typeof item.value != "undefined" && item.value !== null) {
if (item.value == this.DELETE_TOKEN) {
return null;
}
return item.value;
}
if (!item.values) {
return null;
}
var matchLocales = [];
for (var i in item.values) {
if (Object.prototype.hasOwnProperty.call(item.values,i)) {
matchLocales.push(i);
}
}
var normalizedLocale;
// check if we have a value for the specified locale
if (locale) {
normalizedLocale = com.ibm.mm.enabler.utils.LocaleHelper.matchLocale(locale, matchLocales);
for (var i in item.values) {
if (normalizedLocale == com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale(i)) {
value = item.values[i];
break;
}
}
}
// test the default locale of the item
if (item.defaultLocale && value === null) {
normalizedLocale = com.ibm.mm.enabler.utils.LocaleHelper.matchLocale(item.defaultLocale, matchLocales);
for (var i in item.values) {
if (normalizedLocale == com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale(i)) {
value = item.values[i];
break;
}
}
}
// test the default of the sytem
if (this.DEFAULT_LOCALE && value === null) {
normalizedLocale = com.ibm.mm.enabler.utils.LocaleHelper.matchLocale(this.DEFAULT_LOCALE, matchLocales);
for (var i in item.values) {
if (normalizedLocale == com.ibm.mm.enabler.utils.LocaleHelper.normalizeLocale(i)) {
value = item.values[i];
break;
}
}
}
// otherwise the first locale wins
if (value === null) {
for (var lang in item.values) {
if (Object.prototype.hasOwnProperty.call(item.values,lang)) {
value = item.values[lang];
break;
}
}
}
if (value == this.DELETE_TOKEN) {
return null;
}
return value;
},
getItemLocales: function(itemName) {
var locales = [];
if (itemName in this._items && this._items[itemName].values) {
for (var locale in this._items[itemName].values) {
if (Object.prototype.hasOwnProperty.call(this._items[itemName].values,locale)) {
locales.push(locale);
}
}
}
/*if (itemName in this._items && this._items[itemName].value) {
locales.push("");
}*/
if (locales.length === 0) {
return null;
}
return locales;
},
getAllNames: function() {
//return empty array if there's no item
var defaultNames = [];
if (this._defaultProperties) {
defaultNames = this._defaultProperties.getAllNames();
}
var mergedItems = {};
for (var i = 0; i < defaultNames.length; i++) {
mergedItems[defaultNames[i]] = null;
}
for (var itemName in this._items) {
if (this._items[itemName] && this._items[itemName]._change && this._items[itemName]._change.changeType == this.TYPE_REMOVE) {
if (itemName in mergedItems) {
delete mergedItems[itemName];
}
}
else {
mergedItems[itemName] = null;
}
}
var names = [];
for (var itemName2 in mergedItems) {
if (Object.prototype.hasOwnProperty.call(mergedItems,itemName2)) {
names.push(itemName2);
}
}
return names;
},
isReadOnly: function(itemName) {
var item = this._items[itemName];
return (this._defaultProperties && this_defaultProperties.isReadOnly(itemName)) ||
(item && item.readOnly);
}
});
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.Properties"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.Properties"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.Properties");
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.PropertiesProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.PropertiesProvider"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.PropertiesProvider");
/**
* Read-Only interface defines functions to access properties that's defined with iWidget.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.PropertiesProvider", null, {
/**
* @private
*/
constructor: function() {
},
/**
This method returns an object that contains iDescriptor items as defined by iWidget spec. It contains default title and icon
@type com.ibm.mashups.iwidget.widget.Properties
@returns{com.ibm.mashups.iwidget.widget.Properties } object that contains iWidget iDescriptor items information
*/
getIDescriptorItems: function() {
},
/**
This method returns an object that contains attributes as defined by iWidget spec.
@type com.ibm.mashups.iwidget.widget.Properties
@returns{com.ibm.mashups.iwidget.widget.Properties } object that contains iWidget iDescriptor items information
*/
getAttributes: function() {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetDefinition_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetDefinition_API"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.IWidgetDefinition_API");
dojo.provide("com.ibm.mashups.iwidget.widget.IWidgetDefinition");
/**
* Interface defines functions to access all the data object in widget definition. PropertiesProvider is not implemented.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.IWidgetDefinition",[com.ibm.mashups.iwidget.widget.EventProvider,com.ibm.mashups.iwidget.widget.PropertiesProvider],{
/**
* @private
*/
constructor:function(){
},
/**
This method returns an array of supported modes such as "view" and "edit".
@returns{String[] } array of supported modes this iWidget supports.
*/
getSupportedModes:function(){
},
/**
This method returns a JSON based spec compliant object that represents all the data that's defined in widget xml.
Rule to follow:
1. Element -- "iw:iwidget" is considered to be root Element and a root object is created from here.
2. Any attribute of this element will be a field in the root object. '_' will be added as prefix to field names.
":" within any namespaced attribute will be replaced with "_".
<iw:iwidget id="map" xml:base="/root/test/" allowInstanceContent="false"......>
{ _id:"map",_xml_base:"/root/test/",_allowInstanceContent:"false"......}
3. All repreatable elements, element name (append with "s") is used as a field name and an object is created to contain all the repeatable elements.
Within that object, value of "id" attribute is used as field name for an individual element if id attribute is available.
{
resources:{
"myId":{_id:"myId",_src:"my.js"},
"myOtherId":{_id:"myOtherId",_src:"my2.js"}
}
}
4. For "iw:content" elements, "contents" is used as the key in the parent object and an object is created to contain all the content elements.
For each "content" element, "mode" attribute is used as the key and CDATA section is saved as the value.
{
contents:{
"view": {
"_mode": "view",
"value": "mycontent"
}
}
}
5. For "iw:alt" elements,"alts" is used as the key in parent object and an object is created to contain all the alt elements.
For each "alt" element, "lang" attribute is used as the key and all the attributes are saved per attributes convention.
eventDescname:{
_id:"eventDescnname",
_payloadType:"payloadType",
alts:{
"en":{_lang:'en',_description:"description",_descriptionURI:"descriptionURI"},
"zh":{_lang:'zh',_description:"description",_descriptionURI:"descriptionURI"}
}
}
An example of simple iWidget and the return result.
<iw:iwidget id="stock" xmlns:iw="http://www.ibm.com/xmlns/prod/iWidget" iScope="stock" allowInstanceContent="true" supportedModes="view edit " mode="view" lang="en">
<iw:itemSet id="attributes" private="true" onItemSetChanged="changeItemSet">
<iw:item id="broker" readOnly="false" value="Etrade" />
<iw:item id="company" value="IBM" />
</iw:itemSet>
<iw:event id="sendStockData" eventDescName="sendStockDataDesc" published="true" onNewWire="sendData" />
<iw:eventDescription id="sendStockDataDesc" payloadType="stockData" title="Send stock data" lang="en" >
<iw:alt title="Send stock data" lang="en" />
</iw:eventDescription>
<iw:resource src="stock.js" id="stock" />
<iw:content mode="view">
<![CDATA[
mycontent
]]>
</iw:content>
</iw:iwidget>
Example of returnin json object.
{ _id:"map",_allowInstanceContent:"true",_iScope:"stock",_supportedModes:"view edit",_mode:"view",_lang:"en",
@returns{object} a JSON based, spec compliant object that represents all the data that's defined in widget.xml
*/
toSpecObject:function(){
}
});
}
if(!dojo._hasResource["com.ibm.mm.iwidget.widget.IWidgetDefinitionDefaultImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.iwidget.widget.IWidgetDefinitionDefaultImpl"] = true;
dojo.provide("com.ibm.mm.iwidget.widget.IWidgetDefinitionDefaultImpl");
//no support on EventProvider,
//todo toSpecObject should just return the json object
dojo.declare("com.ibm.mm.iwidget.widget.IWidgetDefinitionDefaultImpl", com.ibm.mashups.iwidget.widget.IWidgetDefinition, {
namespaces: {
"iw": "http://www.ibm.com/xmlns/prod/iWidget"
},
reservedAttributes: {
iScope: "iScope",
supportedModes: "supportedModes",
id: "id",
allowInstanceContent: "allowInstanceContent",
lang: "language",
"xml_lang":"_xml_lang",
"xmlns_iw": "_xmlns_iw",
supportedWindowStates: "supportedWindowStates",
"xml_base": "_xml_base",
sandbox:"sandbox"
},
constructor: function(/*/object*/widgetDef, xmlStr, specObject) {
this.widgetDef = widgetDef; //xmlStr is now widgetDef.xmlStr, xmlData is rarely used so only load when it's called in toSpec function.
if (xmlStr) {
this.xmlStr = xmlStr;
}
if (specObject) {
this.specObject = specObject;
this._specObjectToWidgetDef();
}
},
getXmlBase: function() {
if (this.widgetDef.xmlBase) {
return this.widgetDef.xmlBase;
}
return null;
},
getAllowInstanceContent: function() {
return this.widgetDef.allowInstanceContent;
},
getResources: function() {
if (!this.resources) {
this.resources = [];
}
return this.resources;
},
getIScope: function() {
return this.widgetDef.iScope;
},
getWidgetEvents: function() {
return this.widgetDef.widgetEvents;
},
getMarkupByMode: function(mode) {
if (this.widgetDef.markup) {
if (!mode) {
mode = "view";
}
var temp = this.widgetDef.markup[mode];
return temp;
}
else {
return null;
}
},
setMarkupByMode: function(mode, elem) {
if (this.widgetDef.markup) {
if (!mode) {
mode = "view";
}
this.widgetDef.markup[mode] = elem; //simple replacement
return this;
}
return null;
},
_getManagedItemSetListener: function(itemsetname) {
if (!itemsetname) {
return null;
}
if (itemsetname != iwConstants.ATTRIBUTES && itemsetname != iwConstants.IDESCRIPTOR) {
return null;
}
if (this.widgetDef.itemSetsArr) {
var defAttrItemSet = this.widgetDef.itemSetsArr[itemsetname];
if (defAttrItemSet && defAttrItemSet.onItemSetChanged) {
return defAttrItemSet.onItemSetChanged;
}
}
return null;
},
_getManagedItemSetItems: function(itemsetname, simpleAttributes) {
var properties = {};
if (this.widgetDef.itemSetsArr) {
var defAttrItemSet = this.widgetDef.itemSetsArr[itemsetname];
if (defAttrItemSet) {
for (var itemName in defAttrItemSet.items) {
if (Object.prototype.hasOwnProperty.call(defAttrItemSet.items, itemName)) {
properties[itemName] = defAttrItemSet.items[itemName]; // the new internal json itemset notation is compatible with the SPI
}
}
}
}
// determine the default locale for fallback
/*var lang = ibmConfig[com.ibm.mashups.enabler.services.ConfigConstants.DEFAULT_LOCALE];
if (!lang)
lang = "en";*/
simpleAttributes = simpleAttributes || null;
if (simpleAttributes) {
for (var attName in simpleAttributes) {
if (Object.prototype.hasOwnProperty.call(simpleAttributes,attName)) {
var value = simpleAttributes[attName];
if (typeof value != "undefined" && value !== null) {
var property = {};
//property.defaultLocale = lang;
property.readOnly = false;
//property.values = {};
//property.values[lang] = value;
property.value = value;
property.id = attName;
properties[attName] = property;
}
}
}
}
return new com.ibm.mm.iwidget.widget.PropertiesImpl(properties);
},
/**
* PropertiesProvider Impl
*/
getAttributes: function() {
if (!this.attributeProperties) {
this.attributeProperties = this._getManagedItemSetItems(iwConstants.ATTRIBUTES, this.widgetDef.simpleAttributes);
}
return this.attributeProperties;
},
/**
* PropertiesProvider Impl
*/
getIDescriptorItems: function() {
if (!this.idescriptorProperties) {
this.idescriptorProperties = this._getManagedItemSetItems(iwConstants.IDESCRIPTOR, this.widgetDef.iDescriptor);
}
return this.idescriptorProperties;
},
getAllItemSetNames: function() {
var names = [];
if (!this.widgetDef.itemSetsArr) {
return names;
}
for (var itemName in this.widgetDef.itemSetsArr) {
if (Object.prototype.hasOwnProperty.call(this.widgetDef.itemSetsArr,itemName)) {
var itemSetWrapper = this.widgetDef.itemSetsArr[itemName];
if (typeof(itemSetWrapper) != "undefined" && itemName != iwConstants.ATTRIBUTES && itemName != iwConstants.IDESCRIPTOR) {
names.push(itemSetWrapper.id);
}
}
}
return names;
},
getItemSet: function(/*String*/name) {
if (name == "attributes") {
return this.getAttributes();
}
var itemSetWrapper = this.widgetDef.itemSetsArr[name] || null;
if (!itemSetWrapper) {
return null;
}
return itemSetWrapper;
},
getWidgetId: function() {
return this.widgetDef.id;
},
getWidgetName: function() {
return this.widgetDef.id;
},
getPayloadDefs: function() {
return null;
},
getPayloadDef: function(name) {
return null;
},
getPayloadDefNames: function() {
var arr = [];
return arr;
},
getSupportedModes: function() {
var temp = this.widgetDef.supportedModes;
if (!temp) {
return null;
}
var arr = temp.split(" ");
return arr;
},
getSupportedWindowStates: function() {
var temp = this.widgetDef.supportedWindowStates;
if (!temp) {
return null;
}
var arr = temp.split(" ");
return arr;
},
getDefaultLanguage: function() {
return this.widgetDef.lang;
},
getMarkup: function() {
return this.widgetDef.markup;
},
_specObjectToWidgetDef: function() {
this.widgetDef = {};
if (null === this.specObject) {
return;
}
// id
var temp = this.specObject._id;
if (!temp) {
temp = this.specObject._name;
}
this.widgetDef.id = null;
this.widgetDef.name = null;
if (temp){
this.widgetDef.id = temp;
this.widgetDef.name = temp;
}
// allowInstanceContent
this.widgetDef.allowInstanceContent = false;
temp = this.specObject._allowInstanceContent;
if (temp && temp == "true") {
this.widgetDef.allowInstanceContent = true;
}
// iScope
temp = this.specObject._iScope;
this.widgetDef.iScope = null;
if (temp) {
this.widgetDef.iScope = temp;
}
// supportedModes
temp = this.specObject._supportedModes;
if (!temp) {
temp = "view";
}
this.widgetDef.supportedModes = temp;
// supportedWindowStates
temp = this.specObject._supportedWindowStates;
if (!temp) {
temp = "normal";
}
this.widgetDef.supportedWindowStates = temp;
// lang
temp = this.specObject._lang;
if (!temp) {
temp = this.specObject._xml_lang;
}
if (!temp){
temp = "en";
}
this.widgetDef.lang = temp;
// xml:base
temp = this.specObject._xml_base;
if (temp){
this.widgetDef.xmlBase = temp;
}
// iDescriptor
var iDescriptorItems = iwConstants.iDescriptorItems;
var iDescriptor = {};
for (var i in iDescriptorItems) {
if (Object.prototype.hasOwnProperty.call(iDescriptorItems,i)) {
var name = iDescriptorItems[i];
var value = this.specObject['_' + name];
if (typeof value == "undefined") {
value = null;
}
iDescriptor[name] = value;
}
}
this.widgetDef.iDescriptor = iDescriptor;
// simple attributes and widget events
var simpleAttributes = {};
var widgetEvents = {};
for (var j in this.specObject) {
if (Object.prototype.hasOwnProperty.call(this.specObject,j)) {
// only root level attributes
if (0 !== j.indexOf('_')) {
continue;
}
var attr = j;
attr = attr.substr(1);
if (attr.indexOf("on") !== 0 && !iwConstants.iDescriptorItems[attr] && !this.reservedAttributes[attr]) {
simpleAttributes[attr] = this.specObject[j];
}
else if (attr.indexOf("on") === 0) {
widgetEvents[attr] = this.specObject[j];
}
}
}
this.widgetDef.simpleAttributes = simpleAttributes;
this.widgetDef.widgetEvents = widgetEvents;
// markup
this.widgetDef.markup = this._extractMarkupFromSpecObject();
// itemSets
var itemSets = this._extractItemSetsFromSpecObject(this.widgetDef);
if (null !== itemSets) {
this.widgetDef.itemSetsArr = itemSets;
}
// public events
this.widgetDef.publicEvents = this._extractEventsFromSpecObject();
// resources
this.widgetDef.resources = this._extractResourcesFromSpecObject();
// payload defs
// this.widgetDef.payloadDefs = this._extractPayloadDefsFromSpecObject();
// event descriptions
this.widgetDef.eventDescriptions = this._extractEventDescFromSpecObject();
},
// never used
// _extractEventsFromSpecObject: function() {
// // widget events
// var widgetEvents = {};
// for (var i in this.specObject) {
// var handler = this.specObject[i];
// if (typeof handler != "undefined" && handler != null) {
// widgetEvents[event.name] = handler;
// }
// }
// return widgetEvents;
// },
_extractMarkupFromSpecObject: function() {
var contents = this.specObject.contents;
var widgetDefContents = {};
for (var mode in contents) {
if (Object.prototype.hasOwnProperty.call(contents,mode)) {
if (contents[mode]) {
widgetDefContents[mode] = {};
if (contents[mode]._uri) {
widgetDefContents[mode].uri = contents[mode]._uri;
}
if (contents[mode].value) {
widgetDefContents[mode].content = contents[mode].value;
}
}
}
}
return widgetDefContents;
},
_extractItemSetsFromSpecObject: function(widgetDef) {
var itemSets = this.specObject.itemSets;
if (itemSets) {
var itemSetsArr = {};
var shareableItemSetsArr = {};
for (var i in itemSets) {
if (Object.prototype.hasOwnProperty.call(itemSets,i)) {
var itemSet = itemSets[i];
var id = i;
var onItemSetChanged = itemSet._onItemSetChanged;
var temp = itemSet._private;
var isPrivate = true;
if (temp && temp == "false") {
isPrivate = false;
}
var alias = itemSet._alias?itemSet._alias:null;
var descriptionRef = itemSet._description;
var itemSetWrapper = {
id: id,
onItemSetChanged: onItemSetChanged,
isPrivate: isPrivate
};
if (alias){
itemSetWrapper.alias = alias;
}
itemSetWrapper.items = {};
var items = itemSet.items; // WARNING: this assumes that an itemset only contains items !
for (var j in items) {
if (Object.prototype.hasOwnProperty.call(items,j)) {
var item = items[j];
var readOnly = false;
var readOnlyAtt = item._readOnly;
if (readOnlyAtt && readOnlyAtt == "true") {
readOnly = true;
}
var id2 = item._id;
var alias2 = item._alias?item._alias:null;
var value = item._value;
var lang = item._lang;
if (!lang){
lang = item._xml_lang;
}
var anItem = {};
anItem.id = id2;
if (alias2){
anItem.alias = alias2;
}
anItem.readOnly = readOnly;
if (lang) {
anItem.defaultLocale = lang;
}
//value could be ""
if (typeof value != "undefined" && value !== null && !lang) {
anItem.value = value;
}
if (typeof value != "undefined" && value !== null && lang){
anItem.values = {};
anItem.values[lang]=value;
}
var values = item.alts;
for (var v in values) {
if (Object.prototype.hasOwnProperty.call(values,v)) {
var valueNode = values[v];
var locale = v;
var localeValue = valueNode._value;
if (!anItem.values) {
anItem.values = {};
}
anItem.values[locale] = localeValue;
// if default value for default locale is defined in alts, remove default value here so no duplicates
if (lang && locale == lang && anItem.value){
delete anItem.value;
}
}
}
itemSetWrapper.items[id2] = anItem;
}
}
if (isPrivate === true) {
itemSetsArr[id] = itemSetWrapper;
}
else {
shareableItemSetsArr[id] = itemSetWrapper;
}
}
}
widgetDef.shareableItemSetsArr = shareableItemSetsArr;
return itemSetsArr;
}
return null;
},
_extractEventsFromSpecObject: function() {
var events = this.specObject.events;
var eventsArray = {};
if (events && events.length !== 0) {
for (var j in events) {
if (Object.prototype.hasOwnProperty.call(events,j)) {
var event = events[j];
//todo. handler attributes
var iEvent = {};
for (var i in event) {
if (Object.prototype.hasOwnProperty.call(event,i)) {
var name = i;
if (0 === i.indexOf('_')) {
name = name.substr(1);
}
var value = event[i];
if (name == "eventDescName") {
name = "description"; //backward compatibility
}
if (name == "handled") {
name = "isHandled"; //align with js representation
}
if (name == "published") {
name = "isPublished"; //align with js representation
}
if (value) {
iEvent[name] = value;
}
}
}
eventsArray[iEvent.id] = iEvent;
}
}
}
return eventsArray;
},
_extractResourcesFromSpecObject: function() {
var resources = [];
var nodes = this.specObject.resources;
var j = 0;
if (nodes && nodes.length !== 0) {
for (var i in nodes) {
if (Object.prototype.hasOwnProperty.call(nodes,i)) {
var node = nodes[i];
var resource = {};
var id = node._id;
if (!id) {
id = node._globalid;
}
resource[iwConstants.RESOURCE.id] = id?id:null;
var src = node._src;
if (!src) {
src = node._uri;
}
resource[iwConstants.RESOURCE.src] = src;
resource[iwConstants.RESOURCE.version] = node._version?node._version:null;
resource[iwConstants.RESOURCE.callback] = node._callback?node._callback:null;
resource[iwConstants.RESOURCE.mimeType] = node._mimeType?node._mimeType:null;
resource[iwConstants.RESOURCE.blockInit] = node._blockInit?node._blockInit:null;
resource[iwConstants.RESOURCE.globalid] = node._globalid?node._globalid:null;
resource[iwConstants.RESOURCE.skipLoad] = node._skipLoad?node._skipLoad:null;
resources[j] = resource;
j++;
}
}
}
return resources;
},
_extractPayloadDefsFromSpecObject: function() {
var payloadDefsArr = {};
var payloadDefs = this.specObject.payloadDefs;
for (var i in payloadDefs) {
if (Object.prototype.hasOwnProperty.call(payloadDefs,i)) {
var aNode = payloadDef[i];
// MDG to do fix!
// var payloadDef = com.ibm.mm.iwidget.Utils.getPayloadDef(aNode);
//payloadDefsArr[i]=payloadDef;
}
}
},
//todo!
_extractEventDescFromSpecObject: function() {
var eventDescriptions = {};
var eventDescs = this.specObject.eventDescriptions;
if (eventDescs && eventDescs.length !== 0) {
for (var i in eventDescs) {
if (Object.prototype.hasOwnProperty.call(eventDescs,i)) {
var node = eventDescs[i];
var eventDescription = {};
var id = i;
eventDescription.id = id;
eventDescription.payloadType = node._payloadType;
eventDescription.description = node._description;
eventDescription.title = node._title;
eventDescription.descriptionURI = node._descriptionURI?node._descriptionURI:null;
//eventDescription.aliases = node._aliases?node._aliases:null;
var lang = node._lang;
if (!lang ){
lang = node._xml_lang;
}
if (lang) {
eventDescription.lang = lang;
}
var children = node.alts;
for (var j in children) {
if (Object.prototype.hasOwnProperty.call(children,j)) {
var aNode = children[j];
var temp = {};
temp.description = aNode._description;
temp.title = aNode._title;
temp.descriptionURI = aNode._descriptionURI?aNode_descriptionURI:null;
if (!eventDescription.descriptions){
eventDescription.descriptions = {};
}
eventDescription.descriptions[j] = temp;
}
}
eventDescriptions[id] = eventDescription;
}
}
}
return eventDescriptions;
},
toSpecObject: function() {
if (this.specObject) {
return this.specObject;
}
var outputJSON = {};
return outputJSON;
}
});
com.ibm.mm.iwidget.widget.IWidgetDefinitionImpl = com.ibm.mm.iwidget.widget.IWidgetDefinitionDefaultImpl;
// IMPORTANT
// ibmConfig.enablerLayerModules is a comma separated string of all supported modules at runtime
// This section dynamically loads the Extended representation when the variable enablerLayerModules contains the given module
if ((ibmConfig.enablerLayerModules) && (dojo.indexOf(ibmConfig.enablerLayerModules, "iWidget") >= 0)) {
dojo["require"]("com.ibm.mm.iwidget.widget.IWidgetDefinitionExtendedImpl"); // JSLINT-IGNORE: This needs to be done to allow modularization and to support the minimal layer
}
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetDefinition"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetDefinition"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.IWidgetDefinition");
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.ModifiableProperties_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.ModifiableProperties_API"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.ModifiableProperties_API");
dojo.provide("com.ibm.mashups.iwidget.widget.ModifiableProperties");
/**
* Modifiable interface defines functions to iterates , updates and persist Properties.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.ModifiableProperties", [com.ibm.mashups.iwidget.widget.Properties], {
/**
* @private
*/
constructor: function() {
},
/**
* This method creates or overwrites the value of the required item
* @param{String}itemName name of the item. Must never be NULL.
* @param{String} itemValue value of the item. Must never be NULL.
* @param{Boolean} readOnly whether the item value is read only (on this level).
* @param{String} locale the locale in which the item value is
* @return{com.ibm.mashups.iwidget.widget.Properties} return an handle of InstanceProperties upon successful, NULL upon failure.
*/
setItemValue: function(itemName, itemValue, readOnly, locale) {
},
/**
* Removes the named item from the set.
* @param{String} itemName name of the item that should be removed.Must never be NULL.
* @return{com.ibm.mashups.iwidget.widget.Properties} return an handle of InstanceProperties upon successful, NULL upon failure..
*/
removeItem: function(itemName) {
//summary:This method sets an value of an iDescriptor item
},
/**
* Removes the specified item value with the given locale.
* @param{String} itemName the name of the item for which to remove the value.
* @param{String} locale the locale of the value to remove. Must never be NULL
* @return{void}
*/
removeItemValue: function(itemName, locale) {
}
});
}
if(!dojo._hasResource["com.ibm.mm.iwidget.widget.ModifiablePropertiesImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.iwidget.widget.ModifiablePropertiesImpl"] = true;
dojo.provide("com.ibm.mm.iwidget.widget.ModifiablePropertiesImpl");
dojo.declare("com.ibm.mm.iwidget.widget.ModifiablePropertiesImpl", [com.ibm.mashups.iwidget.widget.ModifiableProperties, com.ibm.mm.iwidget.widget.PropertiesImpl], {
constructor: function(items, defaultProps) {
this._dirty = false;
},
_buildChange: function(item, itemName, oldVal, newVal, isRemove) {
var isDirty = item._dirty;
if (!isDirty) {
item._dirty = true;
}
var change = item._change ? item._change : {};
change.id = itemName;
if (isRemove) {
//if it's remove action
if (isDirty && change.changeType && change.changeType == this.TYPE_NEW) {
item._dirty = false;
delete item._change;
return;
}
else if (isDirty) {
change.changeType = this.TYPE_REMOVE;
return;
}
item._change.changeType = this.TYPE_REMOVE;
item._change.oldVal = oldVal;
return;
}
if (isDirty && change.changeType) {
if (change.changeType == this.TYPE_NEW) {
change.newVal = newVal;
}
else {
change.changeType = this.TYPE_UPDATE;
change.newVal = newVal;
}
}
else {
if (oldVal) {
change.oldVal = oldVal;
}
if (newVal) {
change.newVal = newVal;
}
if (oldVal) {
change.changeType = this.TYPE_UPDATE;
}
else {
change.changeType = this.TYPE_NEW;
}
}
item._change = change;
return;
},
setItemValue: function(itemName, itemValue, readOnly, locale) {
if (!itemName || !itemValue) {
return null;
}
if (itemName in this._items) {
if (this._defaultProperties && this._defaultProperties.isReadOnly(itemName)) {
return null;
}
}
var oldValue = {};
var newValue = {};
var isReadOnly;
if (!locale || (locale && locale == "")) { //that means this is a nonlocalized item
if (itemName in this._items) {
oldValue = {};
newValue = {};
if (this._items[itemName].values) {
oldValue = dojo.clone(this._items[itemName].values);
if (this._items[itemName].value) {
oldValue[""] = this._items[itemName].value;
}
newValue = dojo.clone(this._items[itemName].values);
newValue[""] = itemValue;
}
else {
if (this._items[itemName].value) {
oldValue[""] = this._items[itemName].value;
}
newValue[""] = itemValue;
}
this._items[itemName].value = itemValue;
this._buildChange(this._items[itemName], itemName, oldValue, newValue);
}
else {
var anItem = {};
anItem.id = itemName;
//anItem.name = itemName;
anItem.value = itemValue;
isReadOnly = !!readOnly;
anItem.readOnly = isReadOnly;
this._items[itemName] = anItem;
newValue = {};
newValue[""] = itemValue;
this._items[itemName] = this._items[itemName] ? this._items[itemName] : {};
this._buildChange(this._items[itemName], itemName, null, newValue);
}
if (this._items[itemName]._dirty) {
this._dirty = true;
}
return this;
}
var normalizedLocale = locale.replace(/-/g, "_"); // normalize the locale
if (itemName in this._items) {
oldValue = {};
newValue = {};
//this is update
if (this._items[itemName].values) {
oldValue = dojo.clone(this._items[itemName].values);
}
this._items[itemName].values[normalizedLocale] = itemValue;
newValue = dojo.clone(this._items[itemName].values);
if (this._items[itemName].value) {
oldValue[""] = this._items[itemName].value;
newValue[""] = this._items[itemName].value;
}
this._items[itemName].readOnly = readOnly;
this._buildChange(this._items[itemName], itemName, oldValue, itemValue);
if (this._items[itemName]._dirty) {
this._dirty = true;
}
return this;
}
//if it's a new item
var item = {};
item.values = {};
item.values[normalizedLocale] = itemValue;
item.id = itemName;
isReadOnly = !!readOnly;
item.readOnly = isReadOnly;
this._items[itemName] = item;
newValue = dojo.clone(item.values);
this._buildChange(this._items[itemName], itemName, null, newValue);
if (this._items[itemName]._dirty) {
this._dirty = true;
}
return this;
},
removeItem: function(itemName) {
//remove all the values of the Item
// check if this item is read-only on the parent level
if (this._defaultProperties && this._defaultProperties.isReadOnly(itemName)) {
throw "The specified item [" + itemName + "] is readOnly!";
}
var change = {};
var deleted = false;
if (itemName in this._items) {
//delete this._items[itemName]; //this._items only keeps track of any change
if (this._items[itemName]._dirty) {
this._items[itemName].value = this.DELETE_TOKEN;
this._items[itemName].values = this.DELETE_TOKEN;
change = this._items[itemName]._change ? this._items[itemName]._change : {};
if (change.changeType == this.TYPE_NEW) {
delete this._items[itemName];
return this;
}
else {
change.changeType = this.TYPE_REMOVE; //keep old value
}
}
else {
var oldValue = {};
if (this._items[itemName].values) {
oldValue = dojo.clone(this._items[itemName].values);
}
if (this._items[itemName].value) {
oldValue[""] = this._items[itemName].value;
}
this._items[itemName].value = this.DELETE_TOKEN;
this._items[itemName].values = this.DELETE_TOKEN;
change = {};
change.changeType = this.TYPE_REMOVE;
change.itemName = itemName;
change.oldVal = oldValue;
this._items[itemName]._change = change;
this._items[itemName]._dirty = true;
}
deleted = true;
}
if (deleted) {
this._dirty = true;
return this;
}
else {
return null;
}
},
removeItemValue: function(itemName, locale) {
if (!locale) {
//remove nonlocalized value
locale = "";
}
// check if this item is read-only on the parent level
if (this._defaultProperties && this._defaultProperties.isReadOnly(itemName)) {
throw "The specified item [" + itemName + "] is readOnly!";
}
var normalizedLocale = locale.replace(/-/g, "_"); // normalize the locale
var deleted = false;
var change = {};
if (itemName in this._items) {
if (this._items[itemName]._dirty) {
change = this._items[itemName]._change ? this._items[itemName]._change : {};
if (change.changeType == this.TYPE_REMOVE) {
return null; //item is already removed
}
else if (change.changeType == this.TYPE_NEW) { //don't change type
if (normalizedLocale == "" && this._items[itemName].value && this._items[itemName].value != this.DELETE_TOKEN) {
delete this._items[itemName].value;
if (this._items[itemName]._change.newVal[""]) {
delete this._items[itemName]._change.newVal[""];
}
deleted = true;
}
if (normalizedLocale != "") {
if (this._items[itemName].values[normalizedLocale]) {
delete this._items[itemName].values[normalizedLocale];
if (this._items[itemName]._change.newVal[normalizedLocale]) {
delete this._items[itemName]._change.newVal[normalizedLocale];
}
deleted = true;
}
}
if (this._isEmpty(this._items[itemName]._change.newVal)) {
delete this._items[itemName]._dirty;
delete this._items[itemName]._change;
}
}
else { //update
if (normalizedLocale == "" && this._items[itemName].value && this._items[itemName].value != this.DELETE_TOKEN) {
delete this._items[itemName].value;
if (this._items[itemName]._change.newVal[""]) {
delete this._items[itemName]._change.newVal[""];
}
deleted = true;
}
if (this._items[itemName].values[normalizedLocale]) {
delete this._items[itemName].values[normalizedLocale];
if (this._items[itemName]._change.newVal[normalizedLocale]) {
delete this._items[itemName]._change.newVal[normalizedLocale];
}
deleted = true;
}
}
}
else {
var oldValue = {};
var newValue = {};
if (normalizedLocale == "" && this._items[itemName].value) {
change = {};
change.id = itemName;
oldValue = {};
newValue = {};
if (this._items[itemName].values) {
change.changeType = this.TYPE_UPDATE;
oldValue = dojo.clone(this._items[itemName].values);
oldValue[""] = this._items[itemName][""];
change.oldVal = oldValue;
change.newVal = dojo.clone(this._items[itemName].values);
delete this._items[itemName].value;
}
else {
change.changeType = this.TYPE_REMOVE;
oldValue[""] = this._items[itemName][""];
change.oldVal = oldValue;
delete this._items[itemName].value;
}
this._items[itemName]._change = change;
this._items[itemName]._dirty = true;
deleted = true;
}
if (normalizedLocale in this._items[itemName].values) {
change = {};
change.id = itemName;
oldValue = {};
newValue = {};
if (this._items[itemName].value) {
change.changeType = this.TYPE_UPDATE;
oldValue = dojo.clone(this._items[itemName].values);
oldValue[""] = this._items[itemName][""];
change.oldVal = oldValue;
change.newVal = dojo.clone(this._items[itemName].values);
change.newVal[""] = this._items[itemName].value;
delete change.newVal[normalizedLocale];
delete this._items[itemName].value;
}
else {
oldValue = dojo.clone(this._items[itemName].values);
delete this._items[itemName].values[normalizedLocale];
if (this._isEmpty(this._items[itemName].values)) {
change.changeType = this.TYPE_REMOVE;
}
else {
change.changeType = this.TYPE_UPDATE;
change.newVal = dojo.clone(this._items[itemName].values);
}
change.oldVal = oldValue;
}
this._items[itemName]._change = change;
this._items[itemName]._dirty = true;
deleted = true;
}
}
}
if (deleted) {
this._dirty = true;
return this;
}
else {
return null;
}
},
_isDirty: function() {
return this._dirty;
},
_setDirty: function(value) {
this._dirty = value;
},
_isItemDirty: function(itemName) {
if (!itemName) {
return false;
}
var isDirty = false;
if (this._items[itemName]) {
isDirty = this._items[itemName]._dirty;
}
return isDirty;
},
_setItemDirty: function(itemName, value) {
if (!itemName) {
return;
}
if (this._items[itemName]) {
this._items[itemName]._dirty = value;
if (typeof value != "undefined" && !value) {
delete this._items[itemName]._dirty;
delete this._items[itemName]._change;
}
if (this._items[itemName].values && this._items[itemName].values == this.DELETE_TOKEN) {
delete this._items[itemName].values;
}
if (this._items[itemName].value && this._items[itemName].value == this.DELETE_TOKEN) {
delete this._items[itemName].value;
}
if (!this._items[itemName].value && !this._items[itemName].values) {
delete this._items[itemName];
}
}
},
_getInternalItemValue: function(itemName) {
if (this._items[itemName]) {
return this._items[itemName];
}
return null;
},
_isEmpty: function(obj) {
return com.ibm.mm.enabler.utils.Misc.isEmpty(obj);
},
_getRequiredValue: function(obj, locale) {
if (!obj) {
return null;
}
if (dojo.isString(obj)) {
return obj;
}
if (locale) {
if (obj[locale]) {
return obj[locale];
}
else {
return null;
}
}
var singleValue = null;
var j = 0;
for (var i in obj) {
if (Object.prototype.hasOwnProperty.call(obj,i)) {
if (i == "") {
singleValue = obj[i];
}
j++;
}
}
if (singleValue && j == 1) {
return singleValue;
}
return obj;
},
_updateProperties:function(updatedProperties){
//used by sandboxed mode... updates is sent from wrapper to stub
//merge the updates, latest one overwrites the old one
var updatedItems = dojo.mixin(this._items,updatedProperties);
this._items = updatedItems;
this._dirty = true;
},
toJson:function(){
return this._items;
}
});
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.ModifiableProperties"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.ModifiableProperties"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.ModifiableProperties");
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.ModifiablePropertiesProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.ModifiablePropertiesProvider"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.ModifiablePropertiesProvider");
/**
* Modifiable interface defines functions to access properties that's defined with iWidget.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.ModifiablePropertiesProvider", null, {
/**
* @private
*/
constructor: function() {
},
/**
This method returns an object that contains iDescriptor items as defined by iWidget spec. It contains default title and icon
@type com.ibm.mashups.iwidget.widget.ModifiableProperties
@returns{com.ibm.mashups.iwidget.widget.ModifiableProperties } object that contains iWidget iDescriptor items information
*/
getIDescriptorItems: function() {
},
/**
This method returns an object that contains attributes as defined by iWidget spec.
@type com.ibm.mashups.iwidget.widget.ModifiableProperties
@returns{com.ibm.mashups.iwidget.widget.ModifiableProperties } object that contains iWidget iDescriptor items information
*/
getAttributes: function() {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.ModifiableWireProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.ModifiableWireProvider"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.ModifiableWireProvider");
/**
* Interface defines functions to access handled or published event descriptions.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.ModifiableWireProvider", com.ibm.mashups.iwidget.widget.WireProvider, {
/**
* @private
*/
constructor: function(id) {
},
/**
* @param {String}sourceWidgetId id of the widget that will publish the event
* @param {String}sourceEventName name of the event source widget will publish
* @param {String}targetEventName name of the event the receiving widget and this event will handle the event published by source widget
* @type void
*/
addWire: function(sourceWidgetId, sourceEventName, targetEventName) {
},
/**
* @param {String}sourceWidgetId id of the widget that will publish the event
* @param {String}sourceEventName name of the event source widget will publish
* @param {String}targetEventName name of the event the receiving widget and this event will handle the event published by source widget
* @type void
*/
removeWire: function(sourceWidgetId, sourceEventName, targetEventName) {
}
});
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetInstance_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetInstance_API"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.IWidgetInstance_API");
dojo.provide("com.ibm.mashups.iwidget.widget.IWidgetInstance");
/**
* Interface defines functions to access all the instance level descriptive data.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.IWidgetInstance", [com.ibm.mashups.iwidget.widget.ModifiablePropertiesProvider, com.ibm.mashups.iwidget.widget.ModifiableWireProvider], {
/**
* @private
*/
constructor: function() {
}
});
}
if(!dojo._hasResource["com.ibm.mm.iwidget.Utils"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.iwidget.Utils"] = true;
dojo.provide("com.ibm.mm.iwidget.Utils");
dojo.declare("com.ibm.mm.iwidget.UtilsDefaultImpl", null, {
constructor: function() {
},
widgetClassRE: new RegExp("(mm:|mm_|iw-)iWidget"),
findElementByAttribute: function(/*String*/att,/*String*/ value,/*DOMElement*/ root,/*[]*/ element, hasMultiple){
var aRoot = root;
if (!root.childNodes) {
return false;
}
if (att == "class") {
dojo.query("." + value, root).forEach(function(ele){
element.push(ele);
});
return element.length !== 0;
}
else if (att == "query") {
dojo.query(value, root).forEach(function(ele){
element.push(ele);
});
return element.length !== 0;
}
//other attributes
if (root.getElementsByTagName) {
var nodes = root.getElementsByTagName("*");
for (var i = 0, l = nodes.length; i < l; i++) {
var aNode = nodes[i];
if (aNode && aNode.getAttribute) {
var childValue = aNode.getAttribute(att);
if (childValue == value) {
element.push(aNode);
if (!hasMultiple) {
return true;
}
}
}
}
}
// made this order change for 20459. The above code should fix 20459 for dojo test. If it fails 20403 and 20330, the following code will catch it
// This is to avoid using the hacking code
// made the change for 20403 and 20330 since IE7 returns wrong value with code in the other attributes section above
if (att == "id") {
dojo.query("#" + value, root).forEach(function(ele){
element.push(ele);
});
return element.length !== 0;
}
return false;
},
getClass: function(/*object*/node){
var childValue = node.getAttribute("class");
childValue = childValue ? childValue : node.getAttribute("className");
return childValue;
},
checkParentElement: function(/*Node*/selfNode, /*RegExp*/ classToFind){
if (selfNode) {
var dadNode = selfNode.parentNode;
if (dadNode) {
if (dadNode.className) {
if (dadNode.className.match(classToFind)) {
return dadNode.id;
}
}
return this.checkParentElement(dadNode, classToFind);
}
}
return null;
},
getWidgetParent: function(/*Domnode*/node, /*RegExp*/ classToFind){
if (dojo.isString(node)) {
node = dojo.byId(node);
}
if (!classToFind) {
classToFind = this.widgetClassRE;
}
return this.checkParentElement(node, classToFind);
},
getParents: function(/*widget*/widget,/*array*/ arr){
var parent = widget.getParent();
if (parent) {
arr.push(parent);
this.getParents(parent, arr);
}
return;
},
/**
* This utility method takes an id from the markup and returns
* an unprefixed id to pass into an enabler model (like Widget,
* Wire or Event.) IE7 doesn't support ids that start with a
* number so the server may encode the ids with a prefix,
* like 'id_' to make an id valid.
*
* If the markup id starts with the prefix from
* ibmConfig["com.ibm.mashups.iWidget.idPrefix"] this method
* will remove the prefix.
*
* If the id does not start with the prefix no action will be
* taken.
*
* @param {String} id from the markup
* @return {String} the unprefixed id to pass to the enabler
* models
*/
getModelID: function(/*string*/id){
var ret = id;
var prefix = ibmConfig[com.ibm.mashups.enabler.services.ConfigConstants.ID_PREFIX];
if (prefix && dojo.isString(ret)) {
var indx = ret.indexOf(prefix);
if (indx === 0) {
ret = ret.substring(prefix.length);
}
}
return ret;
},
/**
* This utility method takes an id from an enabler (like Widget,
* Wire or Event) and returns a prefixed markup id. IE7 doesn't
* support ids that start with a number so the server may encode
* the ids with a prefix, like 'id_' to make an id valid.
*
* If the model id starts with a number this method will take
* prefix from ibmConfig["com.ibm.mashups.iWidget.idPrefix"]
* and prepend it to the id passed in.
*
*
* @param {String} id retrieved from an enabler model
* @return {String} the prefixed id to match the markup returned
* from the server
*/
getMarkupID: function(/*string*/id) {
var ret = id;
var prefix = ibmConfig[com.ibm.mashups.enabler.services.ConfigConstants.ID_PREFIX];
if (prefix && dojo.isString(ret)) {
ret = prefix + ret;
}
return ret;
},
stripHashPrefix: function(str) {
if (dojo.isString(str)) {
var pos = str.indexOf('#');
if (pos !== -1) { // not enough to just strip first character, because IE prepends the URL.
return str.substr(1 + pos);
}
}
return str;
},
/**
* This method is internal only, it is mainly used for classes that use the "Model" type of instances
*/
_getWidgetTitle: function(widgetId) {
return null;
}
});
// IMPORTANT
// ibmConfig.enablerLayerModules is a comma separated string of all supported modules at runtime
// This section dynamically loads the Extended representation when the variable enablerLayerModules contains the given module
if ((ibmConfig.enablerLayerModules) && (dojo.indexOf(ibmConfig.enablerLayerModules, "iWidget") >= 0)) {
dojo["require"]("com.ibm.mm.iwidget.UtilsExtended"); // JSLINT-IGNORE: This needs to be done to allow modularization and to support the minimal layer
} else {
com.ibm.mm.iwidget.Utils = new com.ibm.mm.iwidget.UtilsDefaultImpl();
}
}
if(!dojo._hasResource["com.ibm.mm.iwidget.widget.IWidgetInstanceDefaultImpl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.iwidget.widget.IWidgetInstanceDefaultImpl"] = true;
dojo.provide("com.ibm.mm.iwidget.widget.IWidgetInstanceDefaultImpl");
dojo.declare("com.ibm.mm.iwidget.widget.IWidgetInstanceDefaultImpl", com.ibm.mashups.iwidget.widget.IWidgetInstance, {
constructor: function(wrapper, /*RootElement*/widgetSpan,/*String*/ id){
this.wrapper = wrapper;
this.rootElement = widgetSpan;
this.id = id;
this.ns = widgetSpan.className.substr(0, 3);
var nodes = [];
var className = this.ns + "Definition";
com.ibm.mm.iwidget.Utils.findElementByAttribute("query", "> ."+className, this.rootElement, nodes, false);
if (nodes && nodes.length > 0) {
var node = nodes[0];
var url = node.getAttribute("href");
if (typeof(url) != "undefined" && url !== null) {
this.widgetXMLUrl = url;
}
}
},
_destroy: function(){
// #17713 one leak for widgetWrapper.rootElement (iw-iWidget DIV)
if (this.rootElement) {
this.rootElement = null;
}
},
getDefaultViewContent: function(){
if (this.defaultViewContent) {
return this.defaultViewContent;
}
var className = this.ns + "Content";
var node = null;
var nodeList = dojo.query("> ." + className+"."+iwConstants.mode_view, this.rootElement);
if (nodeList) {
node = nodeList[0];
}
if (!node) {
nodeList = dojo.query("> ." + className, this.rootElement);
if (nodeList) {
node = nodeList[0];
}
}
if (node) {
this.defaultViewContent = node.innerHTML;
return this.defaultViewContent;
}
else {
return null;
}
},
getWidgetEvents: function(){
//simple events including all the predefined events and onSth. event
if (this.widgetEvents) {
return this.widgetEvents;
}
var widgetEvents = {};
var attributes = this.rootElement.attributes;
for (var i = 0; i < attributes.length; i++) {
var attribute = attributes[i];
if (attribute.name !== null && attribute.name.indexOf("on") === 0) {
var handler = this.rootElement.getAttribute(attribute.name);
if (typeof handler != "undefined" && handler !== null) {
widgetEvents[attribute.name] = handler;
}
}
}
this.widgetEvents = widgetEvents;
return this.widgetEvents;
},
_addWire: function(wire){
},
_removeWire: function(id){
},
addWire: function(sourceWidget, sourceEvent, targetEvent){
},
removeWire: function(sourceWidget, sourceEvent, targetEvent){
},
_getPublicEvents: function(){
return null;
},
getWires: function(){
return [];
},
getWireModel: function(){
return null;
},
/**
* ModifiablePropertiesProvider Impl
*/
getAttributes: function(){
if (!this.attributeProperties) {
//return all the attributes as JSON data
var attributes = this.getItemSets()[iwConstants.ATTRIBUTES];
var properties = {};
if (attributes) {
for (var itemName in attributes) {
if (Object.prototype.hasOwnProperty.call(attributes, itemName)) {
properties[itemName] = attributes[itemName]; // we are compatible with the new internal itemset format
}
}
}
this.attributeProperties = new com.ibm.mm.iwidget.widget.ModifiablePropertiesImpl(properties);
}
return this.attributeProperties;
},
/**
* ModifiablePropertiesProvider Impl
*/
getIDescriptorItems: function(){
if (!this.idescriptorProperties) {
//return all the attributes as JSON data
var iDescriptor = this.getItemSets()[iwConstants.IDESCRIPTOR];
var properties = {};
if (iDescriptor) {
for (var itemName in iDescriptor) {
if (Object.prototype.hasOwnProperty.call(iDescriptor, itemName)) {
properties[itemName] = iDescriptor[itemName]; // we are compatible with the new internal itemset format
// (this is working here, because on instance level we got the idescriptor from markup, not def)
}
}
}
this.idescriptorProperties = new com.ibm.mm.iwidget.widget.ModifiablePropertiesImpl(properties);
}
return this.idescriptorProperties;
},
_getItemSets: function(){
if (this.itemSets) {
return this.itemSets;
}
this.loadItemSets();
return this.itemSets;
},
getItemSets: function(){
//returns a list of itemsets: each itemset is like following
// { itemname1:object,itemname2;object}
//
return this._getItemSets();
},
getItemSet: function(itemSetName){
//returns json object as indicated in _loadItem
//{ itemName1:{},itemName2:{}}
if (!itemSetName) {
return null;
}
var itemSets = this._getItemSets();
if (itemSets && itemSets[itemSetName]) {
return itemSets[itemSetName];
}
},
loadItemSets: function(){
//this.itemSets = this._loadItemSets(this.rootElement, this.ns);
this.itemSets = this._loadItemSetsOptimized(this.rootElement, this.ns);
},
_loadItemSetsOptimized: function(rootElement, ns){
var itemSets = {};
if (rootElement.childNodes.length) {
dojo.query('> .'+ns+com.ibm.mm.iwidget.Constants.CSSCLASS_INSTANCE.iwItemSet+' > .'+ns+com.ibm.mm.iwidget.Constants.CSSCLASS_INSTANCE.iwItem, rootElement).forEach(function(item){
var setName = dojo.attr(item.parentNode, 'title');
if (setName) {
if (!itemSets[setName]) {
itemSets[setName] = {};
}
var anItem = this._loadItemOptimized(item, ns);
itemSets[setName][anItem.id] = anItem;
}
}, this);
}
return itemSets;
},
_loadItemOptimized: function(elem, ns){
var css = com.ibm.mm.iwidget.Constants.CSSCLASS_INSTANCE;
var item = {
id: com.ibm.mm.iwidget.Utils.stripHashPrefix(dojo.attr(elem, 'href')),
readOnly: dojo.hasClass(elem, ns + css.iwReadOnly)
};
var lang = dojo.attr(elem, 'lang');
if (lang) {
item.defaultLocale = lang;
}
var value;
var children = dojo.query('> .' + ns + css.iwValue, elem);
if (children.length) {
item.values = {};
children.forEach(function(valElem){
var locale = dojo.attr(valElem, 'lang') || lang;
item.values[locale] = com.ibm.mm.enabler.utils.Dom.textContent(valElem);
});
}
else {
value = com.ibm.mm.enabler.utils.Dom.textContent(elem);
if (dojo.isString(value)) {
item.value = dojo.string.trim(value);
}
}
return item;
},
// invalidate itemsets
_invalidateItemSets: function(name){
if (!name) {
// invalidate all itemset
this.itemSets = {};
}
else {
// invalidate a single itemsets
this.itemSets[name] = {};
}
},
_getInstanceMarkup: function(){
var node = dojo.clone(this.rootElement);
//remove content div if it's available
dojo.query("> ." + this.ns + "Content", node).forEach(function(contentNode){
com.ibm.mm.enabler.utils.Dom.destroyNode(contentNode);
});
dojo.query("> ." + this.ns + "loading", node).forEach(function(contentNode){
com.ibm.mm.enabler.utils.Dom.destroyNode(contentNode);
});
var tempEl = document.createElement("div");
tempEl.appendChild(node);
var html = tempEl.innerHTML;
return html;
}
});
com.ibm.mm.iwidget.widget.IWidgetInstanceImpl = com.ibm.mm.iwidget.widget.IWidgetInstanceDefaultImpl;
// IMPORTANT
// ibmConfig.enablerLayerModules is a comma separated string of all supported modules at runtime
// This section dynamically loads the Extended representation when the variable enablerLayerModules contains the given module
if ((ibmConfig.enablerLayerModules) && (dojo.indexOf(ibmConfig.enablerLayerModules, "iWidget") >= 0)) {
dojo["require"]("com.ibm.mm.iwidget.widget.IWidgetInstanceExtendedImpl"); // JSLINT-IGNORE: This needs to be done to allow modularization and to support the minimal layer
}
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetInstance"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetInstance"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.IWidgetInstance");
}
if(!dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetWrapper_API"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mashups.iwidget.widget.IWidgetWrapper_API"] = true;
dojo.provide("com.ibm.mashups.iwidget.widget.IWidgetWrapper_API");
dojo.provide("com.ibm.mashups.iwidget.widget.IWidgetWrapper");
/**
* IWidgetWrapper interface represents a runtime instance of an iWidget on the page. Information provided by the IWidgetWrapper is an aggregation of definition level data and instance level data.
* To get desriptive data that's specific to instance level and definition level. It should use Provider api that's implemented by IWidgetDefinition or IWidgetIstance.
* @ibm-spi
* @ibm-module iWidget2
*/
dojo.declare("com.ibm.mashups.iwidget.widget.IWidgetWrapper", [com.ibm.mashups.iwidget.widget.WireProvider, com.ibm.mashups.iwidget.widget.EventProvider], {
/**
* @private
*/
constructor: function() {
},
/**
This method returns iWidgetDefinition of this runtime instance.
itemSets:{
"attributes":{ _id:"attributes", _private:"true",_onItemSetChanged:"changedItemSet",
items:{
"broker":{ _id:"broker",_readOnly:"false", _value:"Etrade"},
"company":{ _id:"company",_value;"IBM"}
}
}
},
events:{
"sendStockData":{ _id:"sendStockData", _eventDescName:"sendStockDataDesc", _published:"true",_onNewWire:"sendData"}
},
eventDescriptions:{
"sendStockDataDesc":{ _id:"sendStockDataDesc", _payloadType:"stockData",_title:"Send stock data",_lang:"en",
alts:{
"en":{ _lang:"en",_title:"Send stock data"}
}
}
},
resources:{
"stock":{ _id:"stock", _src:"stock.js"}
},
contents:{
"view": {
"_mode": "view",
"value": "mycontent"
}
}
}
var deferred = widgetWrapper.getIWidgetDefinition();
deferred.setFinishedCallback(callback,parameters);
deferred.start(true);
here are the callback parameters that will be passed into callback function:
resource
- IWidgetDefinition object
statusCode
- the overall HTTP status,code of the action (the highest status code of the involved operations).
params
- the parameters passed into the callback
@type com.ibm.mashups.enabler.Deferred
@returns{com.ibm.mashups.enabler.Deferred} a deferred object used to start this operation.
@see com.ibm.mashups.iwidget.widget.IWidgetDefinition
*/
getIWidgetDefinition: function() {
},
/**
Sets the iWidgetDefinition for this runtime instance
@param{com.ibm.mashups.iwidget.widget.IWidgetDefinition} widgetDefinition IWidgetDefinition to use for this runtime instance. Must not be null.
@type{void}
@return{void}
*/
setIWidgetDefinition: function(widgetDefinition) {
},
/**
This method returns iWidgetInstance which contains all the descriptive data for this iWidget instance
@type com.ibm.mashups.iwidget.widget.IWidgetInstance
@returns{com.ibm.mashups.iwidget.widget.IWidgetInstance } iWidgetInstance object
*/
getIWidgetInstance: function() {
},
/**
* This method returns the a clone of the content of the widget as it is inside of the DOM.
It removes automatically
* any markup that was added to the DOM using microformats (given that the microformat implements the unProcess handler).
* This method does not remove any additional DOM changes that where done by the widget itself and applies the unProcess only
* to the subnodes of the actual widget node.
* If your widget needs to take special action to it's DOM nodes before the getMarkup is processing it, you can define the method
* _onGetMarkup
in your widgets JavaScript file. This method, as part of the iScope, will always be called before the actual
* markup is processed.
* The synchrounus mode of returned Deferred is not supported.
* @type com.ibm.mashups.enabler.Deferred
* @returns {com.ibm.mashups.enabler.Deferred} a deferred object used to fetch the actual markup.
*/
getMarkup: function() {
},
/**
This method returns true if an iwidget instance is already loaded on the page dom.
@type Boolean
@returns{Boolean } true if widget is already completely rendered on the page.
*/
isLoaded: function() {
},
/**
* This method returns true if an iwidget instance is standalone on the page.
* @type Boolean
* @returns{Boolean} true if widget is standalone on the page.
*/
isStandalone: function() {
},
/**
This method displays the widgets on the page if widget has not been displayed yet.
@type void
*/
doRender: function() {
}
});
}
if(!dojo._hasResource["com.ibm.mm.enabler.aggregation.javascript.Filter"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["com.ibm.mm.enabler.aggregation.javascript.Filter"] = true;
dojo.provide("com.ibm.mm.enabler.aggregation.javascript.Filter");
function com_ibm_enabler_aggregation_javascript_globalEvalNonIE( /*String*/javascript) {
// summary: Evaluates a string of javascript in the global scope.
// description: Calling eval.call( self, ... ); from within a JS object apparently makes "this" point to the object from which the
// eval call was made even though the scope is set using the "call" function. Therefore we need to have this function
// available in the global scope and not as a member variable on a JS object.
eval.call(self, javascript);
}
dojo.declare("com.ibm.mm.enabler.aggregation.javascript.Filter", null, {
// summary: Base interface for a filter. Each implementation must implement
// the doFilter function.
// description: Passes the given event through to give the implementation of
// this filter a chance to alter or handle the event in some way.
constructor: function() {
},
doFilter: function( script) {
// summary: Filter the given event.
// description: Allows this filter to handle or alter the event. If this function
// returns true, processing is stopped and the event is considered "handled".
// script: the script block (string or HTMLElement)
//dojo.unimplemented( "com.ibm.mm.enabler.aggregation.JavascriptFilter.doFilter" );
},
evalGlobal: function( javascript) {
// summary: Evaluates the given javascript in the global context.
// javascript: a string of javascript to evaluate.
if (window.execScript) { // JSLINT-IGNORE: We have to use eval here
window.execScript(this._stripHTMLComments(javascript), "JavaScript"); // JSLINT-IGNORE: We have to use eval here
}
else {
//Using eval.call( window, javascript ) was apparently not really eval'ing
//in the global scope since 'this' was still referring to the Filter object
//and not the window object as it should have (or I think it should have)...
com_ibm_enabler_aggregation_javascript_globalEvalNonIE(javascript);
}
},
_stripHTMLComments: function(str) {
// summary: Strip all HTML comments from a script block.
// description: Although HTML comments are allowed in a script block by the browser
// IE throws up whenever you try and eval a javascript string in the global context
// that has HTML comments in the string.
var resultStr = str;
resultStr = resultStr.replace(/)]+-->/g, '');
return resultStr;
},
prepareDocumentWrite: function(buffer) {
// summary: Prepares support for document.write() and document.writeln
// description: Overrides the original document.write() and document.writeln()
// functions with functions writing to the buffer
var me = this;
document.write = function() { // JSLINT-IGNORE: We have to use eval here
me._documentWrite(buffer, document.write.arguments); // JSLINT-IGNORE: We have to use eval here
};
document.writeln = function(str) { // JSLINT-IGNORE: We have to use eval here
me._documentWrite(buffer, document.writeln.arguments); // JSLINT-IGNORE: We have to use eval here
};
},
_documentWrite: function(buffer, args) {
// summary: Internal document.write() function writing to the given buffer
// description: Just appends the given String arguments to our buffer
for (var i = 0, l = args.length; i < l; i++) {
buffer.content += args[i];
}
},
applyDocumentWrite: function( script, buffer) {
// summary: Injects the markup in the given buffer into the DOM
// description: Looks up the script element in the original DOM
// and injects the markup before that element
var cont = buffer.content || null;
if (cont !== null && cont.length > 0) {
var i = 0;
if (dojo.isIE) {
// Attention: IE needs the
tag available, otherwise