summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/common-http/src/main
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-02-20 08:38:48 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-02-20 08:38:48 +0000
commit4f7f10f97d60a5e7083f9a5b190c2818de7359a1 (patch)
tree6d166ee0e551decd8989c66e0e8dfbe5a7acbed6 /sca-java-2.x/trunk/modules/common-http/src/main
parentda556f44f1b1fe17aa80d38cef206d266c114737 (diff)
Providing utility module to share common HTTP Utilities and Constants
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@912092 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/common-http/src/main')
-rw-r--r--sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPConstants.java27
-rw-r--r--sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPContentTypeMapper.java56
2 files changed, 83 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPConstants.java b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPConstants.java
new file mode 100644
index 0000000000..34052bfea8
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPConstants.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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.
+ */
+
+package org.apache.tuscany.sca.common.http;
+
+public class HTTPConstants {
+ public static final String CHARACTER_ENCODING_UTF8 = "UTF-8";
+
+ public static final String HTML_CONTENT_TYPE = "text/html";
+ public static final String JAVASCRIPT_CONTENT_TYPE = "text/javascript";
+}
diff --git a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPContentTypeMapper.java b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPContentTypeMapper.java
new file mode 100644
index 0000000000..1ce8cd2fd1
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPContentTypeMapper.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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.
+ */
+
+package org.apache.tuscany.sca.common.http;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Utility class to provide default HTTP Content-Type header
+ * based on resource type
+ */
+public class HTTPContentTypeMapper {
+ private static Map<String, String> contentTypeTable = new HashMap<String, String>();
+
+ static {
+ contentTypeTable.put("htm", HTTPConstants.HTML_CONTENT_TYPE);
+ contentTypeTable.put("html", HTTPConstants.HTML_CONTENT_TYPE);
+ contentTypeTable.put("js", "text/javascript");
+ }
+
+ /**
+ * Provided a resource path, identify default content-type based on the resource extension
+ * @param resourcePath
+ * @return
+ */
+ public static String getContentType(String resourcePath) {
+ return contentTypeTable.get(getResourceType(resourcePath));
+ }
+
+ /**
+ * Utility function to calculate file type based on its extension
+ * Useful to map HTTP content-type based on file extension
+ * @param resource the resource/file name
+ * @return the resource type/extension
+ */
+ private static String getResourceType(String resource) {
+ return resource.substring(resource.lastIndexOf(".") + 1);
+ }
+}