1 36 package org.columba.ristretto.message; 37 38 import java.util.List ; 39 import java.util.Vector ; 40 41 42 48 public class MimePart { 49 50 private List childs; 51 private MimePart parent; 52 protected MimeHeader header; 53 protected int size; 54 55 58 public MimePart() { 59 this( new MimeHeader() ); 60 } 61 62 67 public MimePart(MimeHeader header ) { 68 this.header = header; 69 childs = new Vector (); 70 } 71 72 76 public Integer [] getAddress() { 77 List result = new Vector (); 78 79 if (parent == null) 80 result.add(new Integer (0)); 81 else { 82 MimePart nextParent = parent; 83 MimePart nextChild = this; 84 85 while (nextParent != null) { 86 result.add(0, new Integer ( nextParent.getNumber(nextChild) )); 87 88 nextChild = nextParent; 89 nextParent = nextParent.getParent(); 90 } 91 } 92 93 Integer [] returnValue = new Integer [result.size()]; 94 95 for( int i=0; i<result.size(); i++ ) 96 returnValue[i] = (Integer ) result.get(i); 97 98 return returnValue; 99 } 100 101 105 public MimePart getParent() { 106 return parent; 107 } 108 109 113 public void setParent(MimePart parent) { 114 this.parent = parent; 115 } 116 117 120 public int countChilds() { 121 return childs.size(); 122 } 123 124 128 public MimePart getChild(int nr) { 129 return (MimePart) childs.get(nr); 130 } 131 132 137 public void addChild(MimePart child) { 138 if( child == null ) return; 139 childs.add(child); 140 child.setParent(this); 141 } 142 143 149 public int count() { 150 if (header.getMimeType().getSubtype().equals("alternative")) 152 return 1; 153 154 if (countChilds() == 0) 155 return 1; 156 157 int result = 0; 158 159 for (int i = 0; i < countChilds(); i++) { 160 result += getChild(i).count(); 161 } 162 163 return result; 164 } 165 166 170 public int getNumber(MimePart child) { 171 return childs.indexOf(child); 172 } 173 174 177 public List getChilds() { 178 return childs; 179 } 180 181 184 public MimeHeader getHeader() { 185 return header; 186 } 187 188 192 public void setHeader(MimeHeader h) { 193 header = h; 194 } 195 196 201 public void setSize(int size) { 202 this.size = size; 203 } 204 205 208 public int getSize() { 209 return size; 210 } 211 212 } 213 | Popular Tags |