james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r564673 - /james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java
Date Fri, 10 Aug 2007 16:50:20 GMT
Author: rdonkin
Date: Fri Aug 10 09:50:18 2007
New Revision: 564673

URL: http://svn.apache.org/viewvc?view=rev&rev=564673
Log:
Store field name and value data. https://issues.apache.org/jira/browse/MIME4J-25. Contributed
by Jochen Wiedmann.

Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java?view=diff&rev=564673&r1=564672&r2=564673
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MimeTokenStream.java Fri Aug
10 09:50:18 2007
@@ -75,7 +75,7 @@
  * @version $Id: MimeStreamParser.java,v 1.8 2005/02/11 10:12:02 ntherning Exp $
  */
 public class MimeTokenStream {
-    private static final Log log = LogFactory.getLog(MimeStreamParser.class);
+    private static final Log log = LogFactory.getLog(MimeTokenStream.class);
 
     /**
      * This token indicates, that the MIME stream has been completely
@@ -194,7 +194,7 @@
         private int lineNumber, startLineNumber;
         private final int endState;
         
-        String field;
+        String field, fieldName, fieldValue;
 
         Entity(Cursor cursor, BodyDescriptor parent, int startState, int endState) {
             this.parent = parent;
@@ -342,7 +342,7 @@
                     boolean valid = false;
                     if (index != -1 && fieldChars.get(field.charAt(0))) {
                         valid = true;
-                        String fieldName = field.substring(0, index).trim();
+                        fieldName = field.substring(0, index).trim();
                         for (int i = 0; i < fieldName.length(); i++) {
                             if (!fieldChars.get(fieldName.charAt(i))) {
                                 valid = false;
@@ -350,7 +350,8 @@
                             }
                         }
                         if (valid) {
-                            body.addField(fieldName, field.substring(index + 1));
+                            fieldValue = field.substring(index + 1);
+                            body.addField(fieldName, fieldValue);
                             startLineNumber = lineNumber;
                             pos += 2;
                             lineNumber++;
@@ -466,6 +467,36 @@
         switch (getState()) {
             case T_FIELD:
                 return ((Entity) currentStateMachine).field;
+            default:
+                throw new IllegalStateException("Expected state to be T_FIELD.");
+        }
+    }
+
+    /**
+     * This method is valid, if {@link #getState()} returns {@link #T_FIELD}.
+     * @return String with the fields name.
+     * @throws IllegalStateException {@link #getState()} returns another
+     *   value than {@link #T_FIELD}.
+     */
+    public String getFieldName() {
+        switch (getState()) {
+            case T_FIELD:
+                return ((Entity) currentStateMachine).fieldName;
+            default:
+                throw new IllegalStateException("Expected state to be T_FIELD.");
+        }
+    }
+
+    /**
+     * This method is valid, if {@link #getState()} returns {@link #T_FIELD}.
+     * @return String with the fields value.
+     * @throws IllegalStateException {@link #getState()} returns another
+     *   value than {@link #T_FIELD}.
+     */
+    public String getFieldValue() {
+        switch (getState()) {
+            case T_FIELD:
+                return ((Entity) currentStateMachine).fieldValue;
             default:
                 throw new IllegalStateException("Expected state to be T_FIELD.");
         }



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


Mime
View raw message