1 36 package org.columba.ristretto.composer; 37 38 import java.io.InputStream ; 39 import java.util.Hashtable ; 40 41 import org.columba.ristretto.composer.mimepartrenderers.DefaultMimePartRenderer; 42 import org.columba.ristretto.composer.mimepartrenderers.MultipartRenderer; 43 import org.columba.ristretto.composer.mimepartrenderers.TextpartRenderer; 44 import org.columba.ristretto.message.MimePart; 45 import org.columba.ristretto.message.MimeTree; 46 import org.columba.ristretto.message.MimeType; 47 48 58 59 public class MimeTreeRenderer { 60 61 private Hashtable rendererMap; 62 63 private static MimeTreeRenderer myInstance; 64 65 private MimePartRenderer defaultRenderer; 66 67 private MimeTreeRenderer() { 68 defaultRenderer = new DefaultMimePartRenderer(); 69 rendererMap = new Hashtable (); 70 addMimePartRenderer( new MultipartRenderer() ); 71 addMimePartRenderer( new TextpartRenderer() ); 72 73 } 74 75 81 public void addMimePartRenderer( MimePartRenderer renderer ) { 82 rendererMap.put(renderer.getRegisterString(), renderer); 83 } 84 85 90 public static MimeTreeRenderer getInstance() { 91 92 if( myInstance == null ) 93 myInstance = new MimeTreeRenderer(); 94 95 return myInstance; 96 } 97 98 106 public InputStream renderMimeTree( MimeTree tree ) throws Exception { 107 return renderMimePart( tree.getRootMimeNode() ); 108 } 109 110 118 public InputStream renderMimePart( MimePart part ) throws Exception { 119 MimePartRenderer renderer = getRenderer( part.getHeader().getMimeType() ); 120 121 return renderer.render(part); 122 } 123 124 private MimePartRenderer getRenderer( MimeType type ) { 125 126 if (type == null) 128 return defaultRenderer; 129 130 MimePartRenderer renderer; 131 132 134 renderer = 135 (MimePartRenderer) rendererMap.get( 136 type.toString()); 137 if (renderer != null) { 138 return renderer; 139 } 140 141 143 renderer = (MimePartRenderer) rendererMap.get(type.getType()); 144 if (renderer != null) { 145 return renderer; 146 } 147 148 return defaultRenderer; 150 151 } 152 153 } 154 | Popular Tags |