Coverage Report - org.mule.example.geomail.components.ReceivedHeader
 
Classes in this File Line Coverage Branch Coverage Complexity
ReceivedHeader
0%
0/43
0%
0/26
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.example.geomail.components;
 8  
 
 9  
 import java.util.regex.Matcher;
 10  
 import java.util.regex.Pattern;
 11  
 
 12  
 /**
 13  
  * TODO
 14  
  */
 15  0
 public class ReceivedHeader
 16  
 {
 17  
     private String id;
 18  
     private String from;
 19  
     private String by;
 20  
     private String via;
 21  
     private String with;
 22  
     private String _for;
 23  
     private String timestamp;
 24  
 
 25  
     public static ReceivedHeader getInstance(String receivedHeader)
 26  
     {
 27  0
         String fromPattern = "(?:from (.*?))?";
 28  0
         String byPattern = "(?:by (.*?))?";
 29  0
         String viaPattern = "(?:via (.*?))?";
 30  0
         String withPattern = "(?:with (.*?))?";
 31  0
         String idPattern = "(?:id (.*?))?";
 32  0
         String forPattern = "(?:for (.*?))?";
 33  0
         String timePattern = ";(.*)";
 34  
 
 35  0
         String pattern = fromPattern + byPattern + viaPattern + withPattern + idPattern + forPattern
 36  
                          + timePattern;
 37  
 
 38  0
         Matcher matcher = Pattern.compile(pattern, Pattern.DOTALL).matcher(receivedHeader);
 39  
 
 40  0
         ReceivedHeader result = null;
 41  0
         if (matcher.find())
 42  
         {
 43  0
             result = new ReceivedHeader();
 44  0
             result.setFrom(matcher.group(1));
 45  0
             result.setBy(matcher.group(2));
 46  0
             result.setVia(matcher.group(3));
 47  0
             result.setWith(matcher.group(4));
 48  0
             result.setId(matcher.group(5));
 49  0
             result.setFor(matcher.group(6));
 50  0
             result.setTimestamp(matcher.group(7));
 51  
         }
 52  
 
 53  0
         return result;
 54  
     }
 55  
 
 56  
     public String getId()
 57  
     {
 58  0
         return id;
 59  
     }
 60  
 
 61  
     private void setId(String id)
 62  
     {
 63  0
         this.id = (id != null ? id.trim() : null);
 64  0
     }
 65  
 
 66  
     public String getFrom()
 67  
     {
 68  0
         return from;
 69  
     }
 70  
 
 71  
     private void setFrom(String from)
 72  
     {
 73  0
         this.from = (from != null ? from.trim() : null);
 74  0
     }
 75  
 
 76  
     public String getBy()
 77  
     {
 78  0
         return by;
 79  
     }
 80  
 
 81  
     private void setBy(String by)
 82  
     {
 83  0
         this.by = (by != null ? by.trim() : null);
 84  0
     }
 85  
 
 86  
     public String getVia()
 87  
     {
 88  0
         return via;
 89  
     }
 90  
 
 91  
     private void setVia(String via)
 92  
     {
 93  0
         this.via = (via != null ? via.trim() : null);
 94  0
     }
 95  
 
 96  
     public String getWith()
 97  
     {
 98  0
         return with;
 99  
     }
 100  
 
 101  
     private void setWith(String with)
 102  
     {
 103  0
         this.with = (with != null ? with.trim() : null);
 104  0
     }
 105  
 
 106  
     public String getFor()
 107  
     {
 108  0
         return _for;
 109  
     }
 110  
 
 111  
     public void setFor(String _for)
 112  
     {
 113  0
         this._for = (_for != null ? _for.trim() : null);
 114  0
     }
 115  
 
 116  
     public String getTimestamp()
 117  
     {
 118  0
         return timestamp;
 119  
     }
 120  
 
 121  
     private void setTimestamp(String timestamp)
 122  
     {
 123  0
         this.timestamp = timestamp.trim();
 124  0
     }
 125  
 
 126  
     @Override
 127  
     public String toString()
 128  
     {
 129  0
         return "Received {\n  " + (getId() != null ? "id: " + getId() + "\n  " : "")
 130  
                + (getFrom() != null ? "from: " + getFrom() + "\n  " : "")
 131  
                + (getBy() != null ? "by: " + getBy() + "\n  " : "")
 132  
                + (getVia() != null ? "via: " + getVia() + "\n  " : "")
 133  
                + (getWith() != null ? "with: " + getWith() + "\n  " : "")
 134  
                + (getFor() != null ? "for: " + getFor() + "\n  " : "") + "date-time: " + getTimestamp()
 135  
                + "\n  " + "}";
 136  
     }
 137  
 }