use of org.apache.james.mime4j.MimeException in project webservices-axiom by apache.
the class MultipartBody method getNextPart.
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;
}
use of org.apache.james.mime4j.MimeException in project webservices-axiom by apache.
the class PartImpl method discard.
@Override
public void discard() {
try {
switch(state) {
case STATE_UNREAD:
EntityState parserState;
do {
parserState = parser.next();
} while (parserState != EntityState.T_START_BODYPART && parserState != EntityState.T_END_MULTIPART);
state = STATE_DISCARDED;
break;
case STATE_BUFFERED:
content.release();
}
} catch (MimeException ex) {
throw new MIMEException(ex);
} catch (IOException ex) {
throw new MIMEException(ex);
}
}
use of org.apache.james.mime4j.MimeException in project webservices-axiom by apache.
the class PartImpl method moveToNextPart.
private void moveToNextPart() {
try {
checkParserState(parser.next(), EntityState.T_END_BODYPART);
EntityState state = parser.next();
if (state == EntityState.T_EPILOGUE) {
while (parser.next() != EntityState.T_END_MULTIPART) {
// Just loop
}
} else if (state != EntityState.T_START_BODYPART && state != EntityState.T_END_MULTIPART) {
throw new IllegalStateException("Internal error: unexpected parser state " + state);
}
} catch (IOException ex) {
throw new MIMEException(ex);
} catch (MimeException ex) {
throw new MIMEException(ex);
}
parser = null;
}
use of org.apache.james.mime4j.MimeException in project Gargoyle by callakrsos.
the class MimeToHtmlAdapter method getContent.
/*
* (non-Javadoc)
*
* @see
* com.kyj.fx.voeditor.visual.framework.word.AbstractMimeAdapter#getContent(
* )
*/
@Override
public String getContent() {
StringBuilder sb = new StringBuilder();
try {
final MessageBuilder builder = new DefaultMessageBuilder();
Message message = builder.parseMessage(new ByteArrayInputStream(this.content));
Body body = ((Entity) message).getBody();
append(sb, body);
} catch (MimeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
use of org.apache.james.mime4j.MimeException in project Gargoyle by callakrsos.
the class MimeToHtmlWordAdapter method getContent.
/*
* (non-Javadoc)
*
* @see
* com.kyj.fx.voeditor.visual.framework.word.AbstractMimeAdapter#getContent(
* )
*/
@Override
public String getContent() {
StringBuilder sb = new StringBuilder();
try {
final MessageBuilder builder = new DefaultMessageBuilder();
Message message = builder.parseMessage(new ByteArrayInputStream(this.content));
Body body = ((Entity) message).getBody();
append(sb, body);
} catch (MimeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
Aggregations