in axiom-api/src/main/java/org/apache/axiom/mime/MultipartBody.java [243:308]
PartImpl getNextPart() {
if (currentPart != null) {
currentPart.fetch();
}
if (parser.getState() == EntityState.T_END_MULTIPART) {
currentPart = null;
} else {
String partContentID = null;
boolean isRootPart;
try {
checkParserState(parser.next(), EntityState.T_START_HEADER);
List<Header> headers = new ArrayList<Header>();
while (parser.next() == EntityState.T_FIELD) {
Field field = parser.getField();
String name = field.getName();
String value = field.getBody();
if (log.isDebugEnabled()){
log.debug("addHeader: (" + name + ") value=(" + value +")");
}
headers.add(new Header(name, value));
if (partContentID == null && name.equalsIgnoreCase("Content-ID")) {
partContentID = normalizeContentID(value);
}
}
checkParserState(parser.next(), EntityState.T_BODY);
if (rootPartContentID == null) {
isRootPart = firstPart == null;
} else {
isRootPart = rootPartContentID.equals(partContentID);
}
PartImpl part = new PartImpl(this, isRootPart ? MemoryBlob.FACTORY : attachmentBlobFactory, partContentID, headers, parser);
if (currentPart == null) {
firstPart = part;
} else {
currentPart.setNextPart(part);
}
currentPart = part;
} catch (IOException ex) {
throw new MIMEException(ex);
} catch (MimeException ex) {
throw new MIMEException(ex);
}
partCount++;
if (partContentID != null) {
if (partMap.containsKey(partContentID)) {
throw new MIMEException(
"Two MIME parts with the same Content-ID not allowed.");
}
partMap.put(partContentID, currentPart);
}
if (isRootPart) {
rootPart = currentPart;
}
if (partCreationListener != null) {
partCreationListener.partCreated(currentPart);
}
}
return currentPart;
}