summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/common-http/src/main
diff options
context:
space:
mode:
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);
+ }
+}