summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-03-29 18:25:41 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-03-29 18:25:41 +0000
commit511c9ee4ae9a30b616016d242bf7f476e45339b8 (patch)
treeb1a917bfe00a36f80e9fbbff727cd86d0afccebb /sca-java-2.x/trunk
parentb2c79131670c993537ecb55f7628190c85a959b8 (diff)
Enhanving dojo javascript extension to support dojox js framework
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1086668 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/web-javascript-dojo/build-dojo.xml2
-rw-r--r--sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java24
-rw-r--r--sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoWidgetJavascriptProvider.java51
3 files changed, 50 insertions, 27 deletions
diff --git a/sca-java-2.x/trunk/modules/web-javascript-dojo/build-dojo.xml b/sca-java-2.x/trunk/modules/web-javascript-dojo/build-dojo.xml
index 85bdaa4c42..bcfa3c134d 100644
--- a/sca-java-2.x/trunk/modules/web-javascript-dojo/build-dojo.xml
+++ b/sca-java-2.x/trunk/modules/web-javascript-dojo/build-dojo.xml
@@ -50,7 +50,7 @@
<include name="dojo-${dojo.version}/dojo/**"/>
<exclude name="dojo-${dojo.version}/dojo/tests/**"/>
<exclude name="dojo-${dojo.version}/dijit/**"/>
- <exclude name="dojo-${dojo.version}/dojox/**"/>
+ <include name="dojo-${dojo.version}/dojox/**"/>
<exclude name="dojo-${dojo.version}/util/**"/>
</patternset>
</unzip>
diff --git a/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java b/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java
index eacf4a6224..268fbafa36 100644
--- a/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java
+++ b/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoResourceServlet.java
@@ -6,15 +6,15 @@
* to you 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.
+ * under the License.
*/
package org.apache.tuscany.sca.web.javascript.dojo;
@@ -50,8 +50,12 @@ public class DojoResourceServlet extends HttpServlet {
String contextRoot = URLDecoder.decode(HTTPUtils.getContextRoot(request), HTTPConstants.CHARACTER_ENCODING_UTF8);
String path = URLDecoder.decode(request.getRequestURI(), HTTPConstants.CHARACTER_ENCODING_UTF8);
- if( path.startsWith(contextRoot + "/dojo") ) {
- if( ! path.contains("tuscany/AtomService.js")) {
+ System.out.println("contextRoot " + contextRoot);
+ System.out.println("path " + path);
+
+ if( path.startsWith(contextRoot + "/dojo")||
+ path.startsWith(contextRoot + "/dojox")) {
+ if( ! path.contains("tuscany/")) {
//this is a workaround where we need to have dojo files in its own folder
//to avoid clean target to clean other non dojo resources
path = path.substring(contextRoot.length());
@@ -62,7 +66,7 @@ public class DojoResourceServlet extends HttpServlet {
} else if( path.startsWith("/")) {
path = path.substring(1);
}
-
+
if(response.getContentType() == null || response.getContentType().length() == 0){
// Calculate content-type based on extension
String contentType = HTTPContentTypeMapper.getContentType(path);
@@ -70,9 +74,9 @@ public class DojoResourceServlet extends HttpServlet {
response.setContentType(contentType);
}
}
-
+
response.setCharacterEncoding(HTTPConstants.CHARACTER_ENCODING_UTF8);
-
+
// Write the response from the service implementation to the response
// output stream
InputStream is = this.getClass().getClassLoader().getResourceAsStream(path);
@@ -80,7 +84,7 @@ public class DojoResourceServlet extends HttpServlet {
is = this.getClass().getResourceAsStream(path);
}
if(is != null) {
- OutputStream os = response.getOutputStream();
+ OutputStream os = response.getOutputStream();
byte[] buffer = new byte[2048];
for (;;) {
int n = is.read(buffer);
@@ -89,7 +93,7 @@ public class DojoResourceServlet extends HttpServlet {
os.write(buffer, 0, n);
}
os.flush();
- os.close();
+ os.close();
}
}
}
diff --git a/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoWidgetJavascriptProvider.java b/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoWidgetJavascriptProvider.java
index e69c2488ec..8b8eb2b61e 100644
--- a/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoWidgetJavascriptProvider.java
+++ b/sca-java-2.x/trunk/modules/web-javascript-dojo/src/main/java/org/apache/tuscany/sca/web/javascript/dojo/DojoWidgetJavascriptProvider.java
@@ -6,15 +6,15 @@
* to you 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.
+ * under the License.
*/
package org.apache.tuscany.sca.web.javascript.dojo;
@@ -32,55 +32,71 @@ import org.apache.tuscany.sca.implementation.widget.javascript.WidgetImplementat
public class DojoWidgetJavascriptProvider implements WidgetImplementationJavascriptProvider {
private final static Logger logger = Logger.getLogger(DojoWidgetJavascriptProvider.class.getName());
-
+
private static final String dojoBaseUri = URI.create("/dojo").toString();
private static final String dojoUri = URI.create("/dojo/*").toString();
+ private static final String dojoxBaseUri = URI.create("/dojox").toString();
+ private static final String dojoxUri = URI.create("/dojox/*").toString();
+
private static final String tuscanyBaseUri = URI.create("/tuscany").toString();
private static final String tuscanyUri = URI.create("/tuscany/*").toString();
-
+
private static int counter = 0;
-
+
private ServletHost servletHost;
public DojoWidgetJavascriptProvider(ExtensionPointRegistry registry) {
this.servletHost = ServletHostHelper.getServletHost(registry);
}
-
+
public void start() {
-
+
if (servletHost == null) {
throw new IllegalStateException("Can't find ServletHost reference !");
}
Servlet servlet = null;
-
+
servlet = servletHost.getServletMapping(dojoBaseUri);
if(servlet == null) {
try {
- DojoResourceServlet baseResourceServlet = new DojoResourceServlet();
+ DojoResourceServlet baseResourceServlet = new DojoResourceServlet();
servletHost.addServletMapping(dojoBaseUri, baseResourceServlet);
- DojoResourceServlet resourceServlet = new DojoResourceServlet();
+ DojoResourceServlet resourceServlet = new DojoResourceServlet();
servletHost.addServletMapping(dojoUri, resourceServlet);
} catch (ServletMappingException me ) {
logger.warning("Dojo already registered at :" + dojoBaseUri);
}
}
+ servlet = servletHost.getServletMapping(dojoxBaseUri);
+ if(servlet == null) {
+ try {
+ DojoResourceServlet baseResourceServlet = new DojoResourceServlet();
+ servletHost.addServletMapping(dojoxBaseUri, baseResourceServlet);
+
+ DojoResourceServlet resourceServlet = new DojoResourceServlet();
+ servletHost.addServletMapping(dojoxUri, resourceServlet);
+ } catch (ServletMappingException me ) {
+ logger.warning("Dojox already registered at :" + dojoxBaseUri);
+ }
+ }
+
servlet = servletHost.getServletMapping(tuscanyBaseUri);
if(servlet == null) {
try {
- DojoResourceServlet baseResourceServlet = new DojoResourceServlet();
+ DojoResourceServlet baseResourceServlet = new DojoResourceServlet();
servletHost.addServletMapping(tuscanyBaseUri, baseResourceServlet);
- DojoResourceServlet resourceServlet = new DojoResourceServlet();
+ DojoResourceServlet resourceServlet = new DojoResourceServlet();
servletHost.addServletMapping(tuscanyUri, resourceServlet);
} catch (ServletMappingException me ) {
logger.warning("Tuscany dojo extensions already registered at :" + tuscanyBaseUri);
}
}
-
+
counter += 1;
logger.info("Registered Dojo and Tuscany Dojo extensions (counter=" + counter + ")");
}
@@ -90,16 +106,19 @@ public class DojoWidgetJavascriptProvider implements WidgetImplementationJavascr
counter = counter -= 1;
logger.info("Unregistering Dojo and Tuscany Dojo extensions (counter=" + counter + ")");
}
-
+
Servlet servlet = servletHost.getServletMapping(dojoBaseUri);
if(servlet != null && counter == 0) {
servletHost.removeServletMapping(dojoBaseUri);
servletHost.removeServletMapping(dojoUri);
+ servletHost.removeServletMapping(dojoxBaseUri);
+ servletHost.removeServletMapping(dojoxUri);
+
servletHost.removeServletMapping(tuscanyBaseUri);
servletHost.removeServletMapping(tuscanyUri);
}
-
+
servletHost = null;
}