You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/04/28 22:27:47 UTC

svn commit: r1741509 - in /webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments: MIMEMessage.java Util.java

Author: veithen
Date: Thu Apr 28 20:27:47 2016
New Revision: 1741509

URL: http://svn.apache.org/viewvc?rev=1741509&view=rev
Log:
Eliminate duplicate code.

Added:
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Util.java   (with props)
Modified:
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1741509&r1=1741508&r2=1741509&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Thu Apr 28 20:27:47 2016
@@ -169,22 +169,10 @@ class MIMEMessage {
             if (attachmentsMap.isEmpty()) {
                 getNextPartDataHandler();
             }
-            rootContentID = firstPartId;
+            return firstPartId;
         } else {
-            rootContentID = rootContentID.trim();
-
-            if ((rootContentID.indexOf("<") > -1)
-                    & (rootContentID.indexOf(">") > -1)) {
-                rootContentID = rootContentID.substring(1, (rootContentID
-                        .length() - 1));
-            }
-        }
-        // Strips off the "cid:" part from content-id
-        if (rootContentID.length() > 4
-                && "cid:".equalsIgnoreCase(rootContentID.substring(0, 4))) {
-            rootContentID = rootContentID.substring(4);
+            return Util.normalizeContentID(rootContentID);
         }
-        return rootContentID;
     }
     
     String getRootPartContentType() {
@@ -287,12 +275,7 @@ class MIMEMessage {
                 throw new OMException(
                         "Part content ID cannot be blank for non root MIME parts");
             }
-            if ((partContentID.indexOf("<") > -1)
-                    & (partContentID.indexOf(">") > -1)) {
-                partContentID = partContentID.substring(1, (partContentID
-                        .length() - 1));
-
-            }
+            partContentID = Util.normalizeContentID(partContentID);
             if (attachmentsMap.isEmpty()) {
                 firstPartId = partContentID;
             }

Added: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Util.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Util.java?rev=1741509&view=auto
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Util.java (added)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Util.java Thu Apr 28 20:27:47 2016
@@ -0,0 +1,37 @@
+/*
+ * 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.axiom.attachments;
+
+final class Util {
+    private Util() {}
+
+    static String normalizeContentID(String contentID) {
+        contentID = contentID.trim();
+        if (contentID.length() >= 2 && contentID.charAt(0) == '<'
+                && contentID.charAt(contentID.length()-1) == '>') {
+            contentID = contentID.substring(1, contentID.length()-1);
+        }
+        // There is some evidence that some broken MIME implementations add
+        // a "cid:" prefix to the Content-ID; remove it if necessary.
+        if (contentID.length() > 4 && contentID.startsWith("cid:")) {
+            contentID = contentID.substring(4);
+        }
+        return contentID;
+    }
+}

Propchange: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Util.java
------------------------------------------------------------------------------
    svn:eol-style = native