From 151eaaac68607589770bb79f464c5780898707b7 Mon Sep 17 00:00:00 2001 From: projsaha Date: Sun, 8 Jun 2014 17:21:06 +0530 Subject: [PATCH] Non-osgi sample of jaggr, jaggr-web --- .../WebContent/META-INF/MANIFEST.MF | 3 + .../WebContent/WEB-INF/aggrConfig.js | 53 +++ .../WEB-INF/classes/jaggrWeb/colors.less | 17 + .../classes/jaggrWeb/js/LazyContentPane.js | 73 ++++ .../WEB-INF/classes/jaggrWeb/js/bootstrap.js | 33 ++ .../WEB-INF/classes/jaggrWeb/js/css.js | 142 ++++++++ .../classes/jaggrWeb/js/loaderConfig.js | 95 +++++ .../WEB-INF/classes/jaggrWeb/sample.less | 21 ++ ...ulebuilder.css.CSSModuleBuilder.properties | 16 + ...ebuilder.i18n.I18nModuleBuilder.properties | 16 + ...ascript.JavaScriptModuleBuilder.properties | 16 + ...ebuilder.less.LessModuleBuilder.properties | 16 + ...ebuilder.text.TextModuleBuilder.properties | 16 + ...source.ClassPathResourceFactory.properties | 16 + ...pl.resource.FileResourceFactory.properties | 16 + ...mpl.resource.JarResourceFactory.properties | 16 + ...mpl.transport.DojoHttpTransport.properties | 17 + jaggr-sample-web/WebContent/WEB-INF/web.xml | 45 +++ jaggr-sample-web/WebContent/test.html | 90 +++++ jaggr-sample-web/WebContent/test1.html | 91 +++++ jaggr-web/src/META-INF/MANIFEST.MF | 3 + ...bm.jaggr.core.modulebuilder.IModuleBuilder | 19 + ...m.ibm.jaggr.core.resource.IResourceFactory | 19 + ...om.ibm.jaggr.core.transport.IHttpTransport | 15 + .../ibm/jaggr/web/PlatformServicesImpl.java | 125 +++++++ .../ibm/jaggr/web/ServiceReferenceWeb.java | 36 ++ .../ibm/jaggr/web/ServiceRegistrationWeb.java | 36 ++ .../ibm/jaggr/web/impl/AggregatorImpl.java | 325 ++++++++++++++++++ .../ibm/jaggr/web/impl/config/ConfigImpl.java | 135 ++++++++ .../web/impl/transport/DojoHttpTransport.java | 27 ++ 30 files changed, 1548 insertions(+) create mode 100644 jaggr-sample-web/WebContent/META-INF/MANIFEST.MF create mode 100644 jaggr-sample-web/WebContent/WEB-INF/aggrConfig.js create mode 100644 jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/colors.less create mode 100644 jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/LazyContentPane.js create mode 100644 jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/bootstrap.js create mode 100644 jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/css.js create mode 100644 jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/loaderConfig.js create mode 100644 jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/sample.less create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.i18n.I18nModuleBuilder.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.javascript.JavaScriptModuleBuilder.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.less.LessModuleBuilder.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.text.TextModuleBuilder.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.ClassPathResourceFactory.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.FileResourceFactory.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.JarResourceFactory.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.web.impl.transport.DojoHttpTransport.properties create mode 100644 jaggr-sample-web/WebContent/WEB-INF/web.xml create mode 100644 jaggr-sample-web/WebContent/test.html create mode 100644 jaggr-sample-web/WebContent/test1.html create mode 100644 jaggr-web/src/META-INF/MANIFEST.MF create mode 100644 jaggr-web/src/META-INF/services/com.ibm.jaggr.core.modulebuilder.IModuleBuilder create mode 100644 jaggr-web/src/META-INF/services/com.ibm.jaggr.core.resource.IResourceFactory create mode 100644 jaggr-web/src/META-INF/services/com.ibm.jaggr.core.transport.IHttpTransport create mode 100644 jaggr-web/src/com/ibm/jaggr/web/PlatformServicesImpl.java create mode 100644 jaggr-web/src/com/ibm/jaggr/web/ServiceReferenceWeb.java create mode 100644 jaggr-web/src/com/ibm/jaggr/web/ServiceRegistrationWeb.java create mode 100644 jaggr-web/src/com/ibm/jaggr/web/impl/AggregatorImpl.java create mode 100644 jaggr-web/src/com/ibm/jaggr/web/impl/config/ConfigImpl.java create mode 100644 jaggr-web/src/com/ibm/jaggr/web/impl/transport/DojoHttpTransport.java diff --git a/jaggr-sample-web/WebContent/META-INF/MANIFEST.MF b/jaggr-sample-web/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 00000000..5e949512 --- /dev/null +++ b/jaggr-sample-web/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/jaggr-sample-web/WebContent/WEB-INF/aggrConfig.js b/jaggr-sample-web/WebContent/WEB-INF/aggrConfig.js new file mode 100644 index 00000000..ca304df0 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/aggrConfig.js @@ -0,0 +1,53 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// This file is AMD Aggregator config for the Aggregator sample application +{ + baseUrl:'jaggrWeb', + + packages: [ + { + name: 'dojo', + location: 'classPath:///WebContent/source_1.8.0-20120830-IBM_dojo/dojo' + }, + { + name: 'dijit', + location: 'classPath:///WebContent/source_1.8.0-20120830-IBM_dojo/dijit' + }, + { + name: 'dojox', + location: 'classPath:///WebContent/source_1.8.0-20120830-IBM_dojo/dojox' + } + + ], + paths: { + }, + + textPluginDelegators: ["js/css"], + + deps: ["js/bootstrap"], + + depsIncludeBaseUrl: true, // include baseUrl in scan for dependencies + + inlinedImageSizeThreshold: 0, // max image size to inline in CSS + + lazyDetection: false, + + //notice: 'embed.txt', + + cacheBust: '${project.version}' // This is a maven variable, replaced at build time (see pom file for filtered resources). + // You have other options for variable replacement in this file such as "scoped-variables" (see wiki for more info) +} diff --git a/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/colors.less b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/colors.less new file mode 100644 index 00000000..8435af69 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/colors.less @@ -0,0 +1,17 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@back: lightblue; \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/LazyContentPane.js b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/LazyContentPane.js new file mode 100644 index 00000000..fa4a5292 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/LazyContentPane.js @@ -0,0 +1,73 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +define([ + "dojo/_base/lang", // lang + "dojo/_base/declare", // declare + "dijit/layout/ContentPane" // parent +], function(lang, declare, ContentPane){ + +// module: +// js/LazyContentPane +// summary: +// A demo container that sets its contents based on its title. + + + return declare("dijit.layout.LazyContentPane", [ContentPane], { + onShow: function() { + if (this.get('content') == '') { + this.set('content', this.onDownloadStart()); + + var title = this.get('title'); + if (title == 'Calendar') { + require(['dijit/Calendar'], lang.hitch(this, function(calendar) { + this.set('content', new calendar({})); + })); + } else if (title == 'Color Palette') { + require(['dijit/ColorPalette'], lang.hitch(this, function(colorPallete) { + this.set('content', '
'); + new colorPallete({}, this.containerNode.firstChild); + })); + } else if (title == 'Editor') { + require(['dijit/Editor'], lang.hitch(this, function(editor) { + this.set('content', '
'); + new editor({ + plugins: ["bold","italic","|","cut","copy","paste","|","insertUnorderedList"] + }, this.containerNode.firstChild); + })); + } else if (title == 'Chart') { + // Chained requires for gfx are internal to the gfx module. + require([ + 'dojox/charting/Chart2D', + 'dojox/charting/themes/Wetland', + 'dojox/charting/axis2d/Default', + 'dojox/charting/plot2d/Default' + ], lang.hitch(this, function(chart, wetland) { + this.set('content', '
'); + var c = new chart(this.containerNode.firstChild); + c.addPlot("default", {type: "StackedAreas", tension:3}) + .addAxis("x", {fixLower: "major", fixUpper: "major"}) + .addAxis("y", {vertical: true, fixLower: "major", fixUpper: "major", min: 0}) + .setTheme(wetland) + .addSeries("Series A", [1, 2, 0.5, 1.5, 1, 2.8, 0.4]) + .addSeries("Series B", [2.6, 1.8, 2, 1, 1.4, 0.7, 2]) + .addSeries("Series C", [6.3, 1.8, 3, 0.5, 4.4, 2.7, 2]) + .render(); + })); + } + } + } + }); +}); diff --git a/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/bootstrap.js b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/bootstrap.js new file mode 100644 index 00000000..0186f00c --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/bootstrap.js @@ -0,0 +1,33 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +define(["dojo/ready", + "dojo/parser", + "dijit/layout/TabContainer", + "js/LazyContentPane", + "js/css!dijit/themes/claro/claro.css", + "js/css!dijit/themes/claro/claro.css", + "js/css!sample.less", + "dojo/has!dojo-combo-api?combo/dojo/featureMap", + + /* + * preload selector lite implementation which is used by dojo/query and + * supports modern browsers. If the emulation library is required, it + * will be required by the loader. + */ + "dojo/selector/lite" +], function() { + return {}; +}); diff --git a/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/css.js b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/css.js new file mode 100644 index 00000000..c9311ff4 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/css.js @@ -0,0 +1,142 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +define([ + "dojo/_base/window", + "dojo/_base/html", + "dojo/dom-construct", + "dojo/has", + "dojo/text" +], function(dwindow, dhtml, domConstruct, has){ + /* + * module: + * css + * summary: + * This plugin handles AMD module requests for CSS files. Required modules are + * loaded by delegating to the dojo/text plugin and then inserting the CSS into + * a style sheet element that is appended to the HEAD element in the DOM, and + * the style element is returned as the value of the module. + * + * URLs for url(...) and @import statements in the CSS are fixed up to make them + * relative to the requested module's path. + * + * This plugin guarantees that style elements will be inserted into the DOM in + * the same order that the associated CSS modules are requested, except when a + * previously requested module is requested again. In other words, if + * stylesA.css is required before stylesB.css, then the styles for stylesA.css + * will be inserted into the DOM ahead of the styles for stylesB.css. This + * behavior ensures proper cascading of styles based on order of request. + */ + var + cache = {}, // Cache of style sheets that have been added to DOM + loading = [], // Ordered list of required modules that are loading. + waiting = {}, // List of modules that have loaded but are waiting on + // previously required modules before the style-sheet + // can be added to the DOM. + tokenId = 1, // Unique token identifier for a request + + head = dwindow.doc.getElementsByTagName("head")[0], + toAbsMid= has("dojo-loader") ? + function(id, require){ + var result = require.toAbsMid(id + "/x"); + return result.substring(0, result.length-2); + } : + function(id, require){ + return require.toUrl(id); + }, + + fixUrlsInCssFile = function(/*String*/filePath, /*String*/content){ + var rewriteUrl = function(url) { + // remove surrounding quotes and normalize slashes + url = url.replace(/[\'\"]/g,"").replace(/\\/g, "/").replace(/^\s\s*/, "").replace(/\s*\s$/, ""); + // only fix relative URLs. + if (url.charAt(0) != '/' && !/^[a-zA-Z]:\/\//.test(url)) { + url = filePath.slice(0, filePath.lastIndexOf("/") + 1) + url; + //Collapse .. and . + var parts = url.split("/"); + for(var i = parts.length - 1; i > 0; i--){ + if(parts[i] == "."){ + parts.splice(i, 1); + }else if(parts[i] == ".."){ + if(i != 0 && parts[i - 1] != ".."){ + parts.splice(i - 1, 2); + } + } + } + url = require.toUrl(parts.join("/")); // Apply dojo's cache bust (if any) + } + return url; + }; + content = content.replace(/url\s*\(([^#\n\);]+)\)/gi, function(match, url){ + return "url(\"" + rewriteUrl(url) + "\")"; + }); + content = content.replace(/@import\s+(url\()?([^\s;]+)(\))?/gi, function(match, prefix, url) { + return (prefix == "url(" ? match : ("@import \"" + rewriteUrl(url) + "\"")); + }); + return content; + }; + + return { + load: function(/*String*/id, /*Function*/parentRequire, /*Function*/load){ + var parts = id.split("!"), + url = parentRequire.toUrl(parts[0]), + absMid= toAbsMid(parts[0], parentRequire), + requestToken = "tok" + (tokenId++); // A unique id for this request + + // Add this module's token to the ordered list of modules currently loading. + loading.push(requestToken); + + parentRequire(["dojo/text!" + absMid], function(cssText){ + // Process modules in fifo order + if (requestToken === loading[0]) { + // this module is at the head of the list, so process it + loading.shift(); // remove from queue + delete waiting[requestToken]; // remove from waiting list, if there + } else { + // Other modules need to be processed before this one, so add to the + // waiting list and return without processing the module + waiting[requestToken] = {fn:arguments.callee, args:arguments}; + return; + } + // see if this module is already in the cache + var style = cache[absMid]; + if (!style) { + // create a new style element for this module and add it to the DOM + style = domConstruct.create("style", {}, head); + style.type = "text/css"; + dhtml.setAttr(style, "mid", absMid); + if (cssText && dojo.isString(cssText) && cssText.length) { + cssText = fixUrlsInCssFile(url, cssText); + if(style.styleSheet){ + style.styleSheet.cssText = cssText; + }else{ + style.appendChild(dwindow.doc.createTextNode(cssText)); + } + } + // Put in cache + cache[absMid] = style; + } + load(style); + + // Now that we're done processing this module, see if a waiting module + // is at the head of the queue and process it if there is. + if (loading.length && loading[0] in waiting) { + var o = waiting[loading[0]]; + o.fn.apply(this, o.args); + } + }); + } + }; +}); diff --git a/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/loaderConfig.js b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/loaderConfig.js new file mode 100644 index 00000000..00e688ca --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/js/loaderConfig.js @@ -0,0 +1,95 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +(function() { + var href = location.href, + isDebugLoader = /[&?]debugLoader=1/.test(href); + + // make sure we use the global require object + this.require = { + baseUrl: '/test', + packages: [ + { + name: 'dojo', + location: '../jaggr-dojo/dojo', + lib: '.' + }, + { + name: 'dijit', + location: '../jaggr-dojo/dijit', + lib: '.' + }, + { + name: 'dojox', + location: '../jaggr-dojo/dojox', + lib: '.' + } + ], + + paths: { + js: "res/js" + }, + + has: { + "dojo-error-api" : isDebugLoader, + "dojo-trace-api" : isDebugLoader, + "host-browser" : 1 + }, + + // Enable the desired loader tracing options + trace: { + "loader-inject":isDebugLoader, + "loader-inject-combo": isDebugLoader, + "loader-inject-combo-reject": isDebugLoader, + "loader-define":isDebugLoader, + "loader-exec-module":isDebugLoader, + //"loader-run-factory":isDebugLoader, + //"loader-finish-exec":isDebugLoader, + "loader-define-module":isDebugLoader + }, + + // This option only has meaning if has.dojo-timeout-api is enabled + waitSeconds: 10, + + combo: { + contextPath: "/jaggr-webSample/jaggr", + expandRequire: true, + // This is a maven variable, replaced at build time (see pom file for filtered resources). + cacheBust: '${project.version}' + }, + + deps: [ + "dojo/ready", + "dojo/parser", + "js/bootstrap" + ], + + callback: function(ready, parser) { + ready(function() { + parser.parse(); + }); + } + }; + + // get combo propery overrides from URL + for (var s in {optimize:0,expandRequire:0,showFilenames:0,noCache:0}) { + var regex = new RegExp("[&?]"+s+"=([^&]*)","i"); + var result = regex.exec(href) || []; + if (result.length > 1) { + require.combo[s] = result[1]; + } + } + +})(); diff --git a/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/sample.less b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/sample.less new file mode 100644 index 00000000..ee2f4123 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/classes/jaggrWeb/sample.less @@ -0,0 +1,21 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@import "colors.less"; + +body { + background: @back; +} diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder.properties new file mode 100644 index 00000000..7a693052 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder.properties @@ -0,0 +1,16 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.web.impl.modulebuilder.css.CSSModuleBuilder +extension=css \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.i18n.I18nModuleBuilder.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.i18n.I18nModuleBuilder.properties new file mode 100644 index 00000000..63fc333d --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.i18n.I18nModuleBuilder.properties @@ -0,0 +1,16 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.core.impl.modulebuilder.i18n.I18nModuleBuilder +extension=js \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.javascript.JavaScriptModuleBuilder.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.javascript.JavaScriptModuleBuilder.properties new file mode 100644 index 00000000..6eea4b49 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.javascript.JavaScriptModuleBuilder.properties @@ -0,0 +1,16 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.core.impl.modulebuilder.javascript.JavaScriptModuleBuilder +extension=js \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.less.LessModuleBuilder.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.less.LessModuleBuilder.properties new file mode 100644 index 00000000..33123867 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.less.LessModuleBuilder.properties @@ -0,0 +1,16 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.core.impl.modulebuilder.less.LessModuleBuilder +extension=less \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.text.TextModuleBuilder.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.text.TextModuleBuilder.properties new file mode 100644 index 00000000..8deed96c --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.modulebuilder.text.TextModuleBuilder.properties @@ -0,0 +1,16 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.core.impl.modulebuilder.text.TextModuleBuilder +extension=* \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.ClassPathResourceFactory.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.ClassPathResourceFactory.properties new file mode 100644 index 00000000..8d5faf44 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.ClassPathResourceFactory.properties @@ -0,0 +1,16 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.core.impl.resource.ClassPathResourceFactory +scheme=classPath \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.FileResourceFactory.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.FileResourceFactory.properties new file mode 100644 index 00000000..b058110d --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.FileResourceFactory.properties @@ -0,0 +1,16 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.core.impl.resource.FileResourceFactory +scheme=file \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.JarResourceFactory.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.JarResourceFactory.properties new file mode 100644 index 00000000..be5ca649 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.core.impl.resource.JarResourceFactory.properties @@ -0,0 +1,16 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.core.impl.resource.JarResourceFactory +scheme=jar \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.web.impl.transport.DojoHttpTransport.properties b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.web.impl.transport.DojoHttpTransport.properties new file mode 100644 index 00000000..f0bc84d1 --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/extensionPointsConf/com.ibm.jaggr.web.impl.transport.DojoHttpTransport.properties @@ -0,0 +1,17 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class=com.ibm.jaggr.web.impl.transport.DojoHttpTransport +path=combo +resourcesUri=classPath:///jaggrCore/js/ \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/WEB-INF/web.xml b/jaggr-sample-web/WebContent/WEB-INF/web.xml new file mode 100644 index 00000000..1c22555e --- /dev/null +++ b/jaggr-sample-web/WebContent/WEB-INF/web.xml @@ -0,0 +1,45 @@ + + + + jaggr-webSample + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + + The jaggr servlet handles requests to aggregate JS modules + JAGGR Servlet + JaggrServlet + com.ibm.jaggr.web.impl.AggregatorImpl + + alias + /jaggr-webSample/jaggr + + + config + aggrConfig.js + + + + JaggrServlet + /jaggr/* + + \ No newline at end of file diff --git a/jaggr-sample-web/WebContent/test.html b/jaggr-sample-web/WebContent/test.html new file mode 100644 index 00000000..5a81129b --- /dev/null +++ b/jaggr-sample-web/WebContent/test.html @@ -0,0 +1,90 @@ + + + + +Test + + + + + + +
+
+
+
+
+
+ + diff --git a/jaggr-sample-web/WebContent/test1.html b/jaggr-sample-web/WebContent/test1.html new file mode 100644 index 00000000..13290dcb --- /dev/null +++ b/jaggr-sample-web/WebContent/test1.html @@ -0,0 +1,91 @@ + + + + +Test + + + + + + +
+
+
+
+
+
+ + diff --git a/jaggr-web/src/META-INF/MANIFEST.MF b/jaggr-web/src/META-INF/MANIFEST.MF new file mode 100644 index 00000000..5e949512 --- /dev/null +++ b/jaggr-web/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.modulebuilder.IModuleBuilder b/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.modulebuilder.IModuleBuilder new file mode 100644 index 00000000..6b44bde3 --- /dev/null +++ b/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.modulebuilder.IModuleBuilder @@ -0,0 +1,19 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +com.ibm.jaggr.core.impl.modulebuilder.i18n.I18nModuleBuilder +com.ibm.jaggr.core.impl.modulebuilder.javascript.JavaScriptModuleBuilder +com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder +com.ibm.jaggr.core.impl.modulebuilder.text.TextModuleBuilder +com.ibm.jaggr.core.impl.modulebuilder.less.LessModuleBuilder \ No newline at end of file diff --git a/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.resource.IResourceFactory b/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.resource.IResourceFactory new file mode 100644 index 00000000..f8f9ccad --- /dev/null +++ b/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.resource.IResourceFactory @@ -0,0 +1,19 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +com.ibm.jaggr.core.impl.resource.FileResourceFactory +com.ibm.jaggr.core.impl.resource.ClassPathResourceFactory +com.ibm.jaggr.core.impl.resource.JarResourceFactory + + diff --git a/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.transport.IHttpTransport b/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.transport.IHttpTransport new file mode 100644 index 00000000..5f44ced1 --- /dev/null +++ b/jaggr-web/src/META-INF/services/com.ibm.jaggr.core.transport.IHttpTransport @@ -0,0 +1,15 @@ +# (C) Copyright 2012, IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +com.ibm.jaggr.web.impl.transport.DojoHttpTransport diff --git a/jaggr-web/src/com/ibm/jaggr/web/PlatformServicesImpl.java b/jaggr-web/src/com/ibm/jaggr/web/PlatformServicesImpl.java new file mode 100644 index 00000000..8a9344cd --- /dev/null +++ b/jaggr-web/src/com/ibm/jaggr/web/PlatformServicesImpl.java @@ -0,0 +1,125 @@ +/* + * © Copyright IBM Corp. 2013 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.ibm.jaggr.web; + +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Dictionary; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import com.ibm.jaggr.core.IPlatformServices; +import com.ibm.jaggr.core.IServiceReference; +import com.ibm.jaggr.core.IServiceRegistration; + +public class PlatformServicesImpl implements IPlatformServices { + + private Map serviceReferenceMap; + + public PlatformServicesImpl() { + serviceReferenceMap = new HashMap(); + } + + @Override + public IServiceRegistration registerService(String clazz, Object service, Dictionary properties) { + StringBuilder sb = new StringBuilder(); + String uniqueKey = sb.append(clazz).append("_") //$NON-NLS-1$ + .append(service.getClass().getName()).toString(); + if (!serviceReferenceMap.containsKey(uniqueKey)) { + Object[] serviceDetails = new Object[3]; + serviceDetails[0] = clazz; + serviceDetails[1] = service; + serviceDetails[2] = properties; + serviceReferenceMap.put(uniqueKey, serviceDetails); + } + IServiceRegistration serviceRegistation = new ServiceRegistrationWeb(uniqueKey, this); + + return serviceRegistation; + } + + + public void unRegisterService(Object serviceRegistration) { + if (serviceReferenceMap.containsKey((String) serviceRegistration)) { + serviceReferenceMap.remove((String) serviceRegistration); + return; + } + } + + @Override + public IServiceReference[] getServiceReferences(String clazz, String filter) { + return getServiceReferences(clazz); + } + + public IServiceReference[] getServiceReferences(String clazz) { + ArrayList serviceReferences = new ArrayList(); + Set srs = serviceReferenceMap.keySet(); + for(String sr : srs){ + int index = ((String) sr).indexOf("_"); //$NON-NLS-1$ + String clz = ((String) sr).substring(0, index); + if(clz.equalsIgnoreCase(clazz)){ + serviceReferences.add(new ServiceReferenceWeb(sr)); + } + } + IServiceReference[] serviceRefs = new IServiceReference[serviceReferences.size()]; + for(int i = 0; i < serviceReferences.size(); i++){ + serviceRefs[i] = serviceReferences.get(i); + } + return serviceRefs; + } + + @Override + public Object getService(IServiceReference serviceReference) { + Object[] serviceDetails = null; + serviceDetails = (Object[])(serviceReferenceMap.get((String)serviceReference.getPlatformObject())); + return serviceDetails[1]; + } + + @Override + public synchronized boolean ungetService(IServiceReference serviceReference) { + boolean status = false; + if(serviceReferenceMap.containsKey((String)serviceReference.getPlatformObject())){ + serviceReferenceMap.remove((String)serviceReference.getPlatformObject()); + status = true; + return status; + } + return status; + } + + @Override + public URL getResource(String resourceName) { + return null; + } + + @Override + public Dictionary getHeaders() { + return null; + } + + @Override + public boolean isShuttingdown() { + return true; + } + + @Override + public URI getAppContextURI() throws URISyntaxException { + return null; + } + +} diff --git a/jaggr-web/src/com/ibm/jaggr/web/ServiceReferenceWeb.java b/jaggr-web/src/com/ibm/jaggr/web/ServiceReferenceWeb.java new file mode 100644 index 00000000..c2289e76 --- /dev/null +++ b/jaggr-web/src/com/ibm/jaggr/web/ServiceReferenceWeb.java @@ -0,0 +1,36 @@ +/* + * © Copyright IBM Corp. 2013 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.ibm.jaggr.web; + +import com.ibm.jaggr.core.IServiceReference; + +public class ServiceReferenceWeb implements IServiceReference { + + String serviceReference = null; + + + public ServiceReferenceWeb(String serviceRef){ + serviceReference = serviceRef; + } + + @Override + public Object getPlatformObject(){ + return serviceReference; + + } + +} diff --git a/jaggr-web/src/com/ibm/jaggr/web/ServiceRegistrationWeb.java b/jaggr-web/src/com/ibm/jaggr/web/ServiceRegistrationWeb.java new file mode 100644 index 00000000..b19b97fa --- /dev/null +++ b/jaggr-web/src/com/ibm/jaggr/web/ServiceRegistrationWeb.java @@ -0,0 +1,36 @@ +/* + * © Copyright IBM Corp. 2013 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.ibm.jaggr.web; + +import com.ibm.jaggr.core.IServiceRegistration; + +public class ServiceRegistrationWeb implements IServiceRegistration { + + String ServiceRegistration = null; + PlatformServicesImpl platformServices = null; + + public ServiceRegistrationWeb(String serviceRegistrationWeb, PlatformServicesImpl platformServicesWeb){ + ServiceRegistration = serviceRegistrationWeb; + platformServices = platformServicesWeb; + } + + @Override + public void unregister() { + platformServices.unRegisterService(ServiceRegistration); + } + +} diff --git a/jaggr-web/src/com/ibm/jaggr/web/impl/AggregatorImpl.java b/jaggr-web/src/com/ibm/jaggr/web/impl/AggregatorImpl.java new file mode 100644 index 00000000..fbc14e0e --- /dev/null +++ b/jaggr-web/src/com/ibm/jaggr/web/impl/AggregatorImpl.java @@ -0,0 +1,325 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ibm.jaggr.web.impl; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import java.util.ServiceLoader; +import java.util.regex.Matcher; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + +import org.eclipse.core.runtime.CoreException; + +import com.ibm.jaggr.core.InitParams; +import com.ibm.jaggr.core.InitParams.InitParam; +import com.ibm.jaggr.core.NotFoundException; +import com.ibm.jaggr.core.config.IConfig; +import com.ibm.jaggr.core.deps.IDependencies; +import com.ibm.jaggr.core.executors.IExecutors; +import com.ibm.jaggr.core.impl.AggregatorExtension; +import com.ibm.jaggr.core.impl.OverrideFoldersTreeWalker; +import com.ibm.jaggr.core.impl.deps.DependenciesImpl; +import com.ibm.jaggr.core.impl.executors.ExecutorsImpl; +import com.ibm.jaggr.core.impl.options.OptionsImpl; +import com.ibm.jaggr.core.modulebuilder.IModuleBuilder; +import com.ibm.jaggr.core.options.IOptions; +import com.ibm.jaggr.core.resource.IResourceFactory; +import com.ibm.jaggr.core.transport.IHttpTransport; +import com.ibm.jaggr.web.PlatformServicesImpl; +import com.ibm.jaggr.web.impl.config.ConfigImpl; + +/** + * Implementation for IAggregator and HttpServlet interfaces. + * + * Note that despite the fact that HttpServlet (which this class extends) + * implements Serializable, attempts to serialize instances of this class will + * fail due to the fact that not all instance data is serializable. The + * assumption is that because instances of this class are created by the OSGi + * Framework, and the framework itself does not support serialization, then no + * attempts will be made to serialize instances of this class. + */ +@SuppressWarnings("serial") +public class AggregatorImpl extends com.ibm.jaggr.core.impl.AbstractAggregatorImpl { + + protected static final String RESOURCE_FACTORY = "com.ibm.jaggr.resourcefactory"; //$NON-NLS-1$ + protected static final String DEFAULT_RESOURCEFACTORIES = "com.ibm.jaggr.core.default.resourcefactories"; //$NON-NLS-1$ + protected static final String MODULE_BUILDER = "com.ibm.jaggr.modulebuilder"; //$NON-NLS-1$ + protected static final String DEFAULT_MODULEBUILDERS = "com.ibm.jaggr.core.default.modulebuilders"; //$NON-NLS-1$ + protected static final String HTTP_TRANSPORT = "com.ibm.jaggr.httptransport"; //$NON-NLS-1$ + protected static final String DEFAULT_HTTPTRANSPORT = "com.ibm.jaggr.core.dojo.httptransport"; //$NON-NLS-1$ + + protected ServletContext servletContext = null; + protected ExecutorsImpl ex = null; + protected OptionsImpl op = null; + private File workdir = null; + + @Override + public File getWorkingDirectory() { + return workdir; + } + + public void setInitializationData() { + + try { + + servletContext = getServletContext(); + name = getAggregatorName(); + initParams = getInitParamsFromServletConfig(); + op = new OptionsImpl(true, this); + ex = new ExecutorsImpl(op); + workdir = initWorkingDirectory(); + initExtensions(); + IConfig config = newConfig(); + + // Check last-modified times of resources in the overrides folders. + // These resources + // are considered to be dynamic in a production environment and we + // want to + // detect new/changed resources in these folders on startup so that + // we can clear + // caches, etc. + OverrideFoldersTreeWalker walker = new OverrideFoldersTreeWalker( + this, config); + walker.walkTree(); + deps = newDependencies(walker.getLastModifiedJS()); + cacheMgr = newCacheManager(walker.getLastModified()); + this.config = config; + // Notify listeners + notifyConfigListeners(1); + + // bundleContext.addBundleListener(this); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Returns the name for this aggregator + *

+ * This method is called during aggregator intialization. Subclasses may + * override this method to initialize the aggregator using a different name. + * Use the public {@link AggregatorImpl#getName()} method to get the name of + * an initialized aggregator. + * + * @param configElem + * The configuration element. + * @return The aggregator name + */ + + public String getAggregatorName() { + // trim leading and trailing '/' + String alias = getInitParameter("alias");//$NON-NLS-1$ + while (alias.charAt(0) == '/') + alias = alias.substring(1); + while (alias.charAt(alias.length() - 1) == '/') + alias = alias.substring(0, alias.length() - 1); + return alias; + } + + /** + * Returns the init params for this aggregator + *

+ * This method is called during aggregator intialization. Subclasses may + * override this method to initialize the aggregator using different init + * params. Use the public {@link AggregatorImpl#getInitParams()} method to + * get the init params for an initialized aggregator. + * + * @param configElem + * The configuration element. + * @return The init params + */ + + public InitParams getInitParamsFromServletConfig() { + + List initParams = new LinkedList(); + Enumeration strs = getInitParameterNames(); + while (strs.hasMoreElements()) { + String name = strs.nextElement(); + String value = getInitParameter(name); + if (!(name.equals("alias"))) { //$NON-NLS-1$ + initParams.add(new InitParam(name, value)); + } + } + return new InitParams(initParams); + } + + /** + * Loads and initializes the resource factory, module builder and http + * transport extensions specified in the configuration element for this + * aggregator + * + * @param configElem + * The configuration element + * @throws CoreException + * @throws NotFoundException + */ + protected void initExtensions() throws NotFoundException { + /* + * Init the resource factory extensions + */ + initResourceFactoryExtension(); + initModuleBuilderExtension(); + initHttpTransportExtension(); + + ExtensionRegistrar reg = new ExtensionRegistrar(); + callExtensionInitializers(getExtensions(null), reg); + reg.closeRegistration(); + } + + @Override + public IOptions getOptions() { + return op; + } + + @Override + public IExecutors getExecutors() { + return ex; + } + + + public ServletContext getAggregatorServletContext(){ + return servletContext; + } + + @Override + protected IDependencies newDependencies(long stamp) { + return new DependenciesImpl(this, stamp); + } + + @Override + public IDependencies getDependencies() { + return (IDependencies) deps; + } + + @Override + public String substituteProps(String str, + SubstitutionTransformer transformer) { + if (str == null) { + return null; + } + StringBuffer buf = new StringBuffer(); + Matcher matcher = pattern.matcher(str); + while (matcher.find()) { + String propName = matcher.group(1); + String propValue = null; + propValue = System.getProperty(propName); + if (propValue != null) { + if (transformer != null) { + propValue = transformer.transform(propName, propValue); + } + matcher.appendReplacement(buf, propValue.replace("\\", "\\\\") //$NON-NLS-1$ //$NON-NLS-2$ + .replace("$", "\\$") //$NON-NLS-1$ //$NON-NLS-2$ + ); + } else { + matcher.appendReplacement(buf, "\\${" + propName + "}"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + matcher.appendTail(buf); + return buf.toString(); + } + + /** + * Returns the working directory for this aggregator. + *

+ * This method is called during aggregator intialization. Subclasses may + * override this method to initialize the aggregator using a different + * working directory. Use the public {@link #getWorkingDirectory()} method + * to get the working directory from an initialized aggregator. + * + * @param configElem + * The configuration element. Not used by this class but provided + * for use by subclasses. + * @return The {@code File} object for the working directory + * @throws FileNotFoundException + */ + protected File initWorkingDirectory() { + File tmpDir = (File) getServletContext().getAttribute( + "javax.servlet.context.tempdir"); //$NON-NLS-1$ + System.out.println("cache dir " + tmpDir); //$NON-NLS-1$ + return tmpDir; + + + } + + public void initResourceFactoryExtension() throws NotFoundException { + ServiceLoader resourceFactoryLoader = ServiceLoader.load(IResourceFactory.class); + for (IResourceFactory resourceFactory : resourceFactoryLoader) { + Properties props = getExtensionPointProperties(resourceFactory); + registerExtension(new AggregatorExtension(resourceFactory, + props, "com.ibm.jaggr.service.resourcefactory", //$NON-NLS-1$ + DEFAULT_RESOURCEFACTORIES), null); + } + } + + public void initModuleBuilderExtension() throws NotFoundException { + ServiceLoader moduleBuilderLoader = ServiceLoader.load(IModuleBuilder.class); + for (IModuleBuilder moduleBuilder : moduleBuilderLoader) { + Properties props = getExtensionPointProperties(moduleBuilder); + registerExtension(new AggregatorExtension(moduleBuilder, + props, "com.ibm.jaggr.service.modulebuilder", //$NON-NLS-1$ + DEFAULT_MODULEBUILDERS), null); + } + } + + + + + public void initHttpTransportExtension() throws NotFoundException { + ServiceLoader httpTransportLoader = ServiceLoader.load(IHttpTransport.class); + for (IHttpTransport httpTransport : httpTransportLoader) { + Properties props = getExtensionPointProperties(httpTransport); + registerExtension(new AggregatorExtension(httpTransport, + props, "com.ibm.jaggr.service.httptransport", //$NON-NLS-1$ + DEFAULT_HTTPTRANSPORT), null); + } + + } + + public Properties getExtensionPointProperties(Object object){ + Properties prop = new Properties(); + try { + URL propUrl = this.getAggregatorServletContext().getResource("/WEB-INF/extensionPointsConf/" + object.getClass().getName() + ".properties"); //$NON-NLS-1$ //$NON-NLS-2$ + prop.load(propUrl.openStream()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return prop; + + } + + @Override + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + platformServices = new PlatformServicesImpl(); + setInitializationData(); + } + + protected IConfig newConfig() throws IOException { + return new ConfigImpl(this); + } + +} diff --git a/jaggr-web/src/com/ibm/jaggr/web/impl/config/ConfigImpl.java b/jaggr-web/src/com/ibm/jaggr/web/impl/config/ConfigImpl.java new file mode 100644 index 00000000..29918c7a --- /dev/null +++ b/jaggr-web/src/com/ibm/jaggr/web/impl/config/ConfigImpl.java @@ -0,0 +1,135 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ibm.jaggr.web.impl.config; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; +import java.util.Collection; +import java.util.Enumeration; + +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Scriptable; + +import com.ibm.jaggr.core.IAggregator; +import com.ibm.jaggr.core.InitParams; + +public class ConfigImpl extends com.ibm.jaggr.core.impl.config.ConfigImpl { + + protected Scriptable defaultConfig; + protected Scriptable overrideConfig; + + public ConfigImpl(IAggregator aggregator) throws IOException { + super(aggregator); + } + + /** + * Initializes and returns the URI to the server-side config JavaScript + * + * @return The config URI + * @throws URISyntaxException + * @throws FileNotFoundException + * @throws + */ + + @Override + protected URI loadConfigUri() throws URISyntaxException, + FileNotFoundException { + URI configUri = null; + URL configUrl = null; + Collection configNames = getAggregator().getInitParams() + .getValues(InitParams.CONFIG_INITPARAM); + if (configNames.size() != 1) { + throw new IllegalArgumentException(InitParams.CONFIG_INITPARAM); + } + String configName = configNames.iterator().next(); + + try { + configUrl = ((com.ibm.jaggr.web.impl.AggregatorImpl) this.getAggregator()) + .getAggregatorServletContext().getResource( + "/WEB-INF/" + configName); //$NON-NLS-1$ + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + configUri = new URI(configUrl.toString()); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return configUri; + + } + + protected void loadConfig() throws IOException, URISyntaxException { + this.setConfigUri(loadConfigUri()); + // Try to convert to an IResource in case the URI specifies + // an IResource supported scheme like 'namedbundleresource'. + URI uri; + try { + uri = this.getAggregator().newResource(this.getConfigUri()) + .getURI(); + } catch (UnsupportedOperationException e) { + // Not fatal. Just use the configUri as is + uri = this.getConfigUri(); + } + URLConnection connection = uri.toURL().openConnection(); + this.setLastModified(connection.getLastModified()); + + overrideConfig = loadConfig(connection.getInputStream()); + this.setRawConfig(overrideConfig); + } + + protected Location loadBaseURI(Scriptable cfg) throws URISyntaxException { + Object baseObj = cfg.get(BASEURL_CONFIGPARAM, cfg); + Location result; + if (baseObj == Scriptable.NOT_FOUND) { + result = new Location(getConfigUri().resolve(".")); //$NON-NLS-1$ + } else { + Location loc = loadBaseLocation(baseObj, true); + Location configLoc = new Location(getConfigUri(), + loc.getOverride() != null ? getConfigUri() : null); + result = configLoc.resolve(loc); + } + return result; + } + + private Location loadBaseLocation(Object baseObj, boolean b) { + + String str = Context.toString(baseObj); + Location result = null; + + try { + ClassLoader classLoader = Thread.currentThread() + .getContextClassLoader(); + Enumeration resources = classLoader.getResources(str); + while (resources.hasMoreElements()) { + URL resource = resources.nextElement(); + String resourceUrl = resource.toString(); + result = new Location(new URI(resourceUrl)); + } + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/jaggr-web/src/com/ibm/jaggr/web/impl/transport/DojoHttpTransport.java b/jaggr-web/src/com/ibm/jaggr/web/impl/transport/DojoHttpTransport.java new file mode 100644 index 00000000..e827dd31 --- /dev/null +++ b/jaggr-web/src/com/ibm/jaggr/web/impl/transport/DojoHttpTransport.java @@ -0,0 +1,27 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ibm.jaggr.web.impl.transport; + +import com.ibm.jaggr.core.transport.IHttpTransport; + +public class DojoHttpTransport extends + com.ibm.jaggr.core.impl.transport.DojoHttpTransport implements IHttpTransport { + + protected String getLoaderExtensionPath(){ + return getComboUri().getPath() + "loaderExt.js"; //$NON-NLS-1$ + } +}