You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2008/04/17 02:50:52 UTC

svn commit: r648909 - /jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java

Author: sebb
Date: Wed Apr 16 17:50:51 2008
New Revision: 648909

URL: http://svn.apache.org/viewvc?rev=648909&view=rev
Log:
Start collecting common HTTP/HTML conversion utilities

Added:
    jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java   (with props)

Added: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java?rev=648909&view=auto
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java (added)
+++ jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java Wed Apr 16 17:50:51 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.jmeter.protocol.http.util;
+
+import org.apache.jorphan.util.JOrphanUtils;
+
+/**
+ * General purpose conversion utilities related to HTTP/HTML
+ */
+public class ConversionUtils {
+
+    private static final String CHARSET_EQ = "charset="; // $NON-NLS-1$
+    private static final int CHARSET_EQ_LEN = CHARSET_EQ.length();
+
+    /**
+     * Extract the encoding (charset) from the Content-Type,
+     * e.g. "text/html; charset=utf-8".
+     * 
+     * @param contentType
+     * @return the charset encoding
+     */
+    public static String getEncodingFromContentType(String contentType){
+        String charSet = null;
+        if (contentType != null) {
+            int charSetStartPos = contentType.toLowerCase().indexOf(CHARSET_EQ);
+            if (charSetStartPos > 0) {
+                charSet = contentType.substring(charSetStartPos + CHARSET_EQ_LEN);
+                if (charSet != null) {
+                    // Remove quotes from charset name
+                    charSet = JOrphanUtils.replaceAllChars(charSet, '"', "");
+                    charSet = charSet.trim();
+                    if (charSet.length() > 0) {
+                        return charSet;
+                    }
+                    return null;
+                }
+            }
+        }
+        return charSet;
+    }
+}

Propchange: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org