use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.
the class SaveDocument method redo.
@Override
public void redo() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
try {
ParsedDocument pd = new ParsedDocument(getAdditionalDataStream(), mFilename, mMimeType, System.currentTimeMillis(), mAuthor, mDescription, mDescEnabled);
mbox.createDocument(getOperationContext(), getFolderId(), pd, type, getFlags());
} catch (MailServiceException e) {
if (e.getCode() == MailServiceException.ALREADY_EXISTS) {
mLog.info("Document " + getMessageId() + " is already in mailbox " + mbox.getId());
return;
} else {
throw e;
}
}
}
use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.
the class NativeFormatter method saveDocument.
private void saveDocument(Blob blob, UserServletContext context, String contentType, Folder folder, String filename, InputStream is) throws IOException, ServiceException, UserServletException {
Mailbox mbox = folder.getMailbox();
MailItem item = null;
String creator = context.getAuthAccount() == null ? null : context.getAuthAccount().getName();
ParsedDocument pd = null;
try {
if (contentType == null) {
contentType = MimeDetect.getMimeDetect().detect(filename);
if (contentType == null)
contentType = MimeConstants.CT_APPLICATION_OCTET_STREAM;
}
pd = new ParsedDocument(blob, filename, contentType, System.currentTimeMillis(), creator, context.req.getHeader("X-Zimbra-Description"), true);
item = mbox.getItemByPath(context.opContext, filename, folder.getId());
// XXX: should we just overwrite here instead?
if (!(item instanceof Document))
throw new UserServletException(HttpServletResponse.SC_BAD_REQUEST, "cannot overwrite existing object at that path");
// scan upload for viruses
StringBuffer info = new StringBuffer();
UploadScanner.Result result = UploadScanner.acceptStream(is, info);
if (result == UploadScanner.REJECT)
throw MailServiceException.UPLOAD_REJECTED(filename, info.toString());
if (result == UploadScanner.ERROR)
throw MailServiceException.SCAN_ERROR(filename);
item = mbox.addDocumentRevision(context.opContext, item.getId(), pd);
} catch (NoSuchItemException nsie) {
item = mbox.createDocument(context.opContext, folder.getId(), pd, MailItem.Type.DOCUMENT, 0);
}
sendZimbraHeaders(context, context.resp, item);
}
use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.
the class Document method generateIndexData.
@Override
public List<IndexDocument> generateIndexData() throws TemporaryIndexingException {
try {
MailboxBlob mblob = getBlob();
if (mblob == null) {
ZimbraLog.index.warn("Unable to fetch blob for Document id=%d,ver=%d,vol=%s", mId, mVersion, getLocator());
throw new MailItem.TemporaryIndexingException();
}
ParsedDocument pd = null;
pd = new ParsedDocument(mblob.getLocalBlob(), getName(), getContentType(), getChangeDate(), getCreator(), getDescription(), isDescriptionEnabled());
if (pd.hasTemporaryAnalysisFailure()) {
throw new MailItem.TemporaryIndexingException();
}
IndexDocument doc = pd.getDocument();
if (doc != null) {
List<IndexDocument> toRet = new ArrayList<IndexDocument>(1);
toRet.add(doc);
return toRet;
} else {
return new ArrayList<IndexDocument>(0);
}
} catch (IOException e) {
ZimbraLog.index.warn("Error generating index data for Wiki Document " + getId() + ". Item will not be indexed", e);
return new ArrayList<IndexDocument>(0);
} catch (ServiceException e) {
ZimbraLog.index.warn("Error generating index data for Wiki Document " + getId() + ". Item will not be indexed", e);
return new ArrayList<IndexDocument>(0);
}
}
use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.
the class Document method create.
static Document create(int id, String uuid, Folder folder, String filename, String type, ParsedDocument pd, CustomMetadata custom, int flags, MailItem parent) throws ServiceException {
assert (id != Mailbox.ID_AUTO_INCREMENT);
Mailbox mbox = folder.getMailbox();
UnderlyingData data = prepareCreate(Type.DOCUMENT, id, uuid, folder, filename, type, pd, null, custom, flags);
if (parent != null) {
data.parentId = parent.mId;
}
data.contentChanged(mbox);
ZimbraLog.mailop.info("Adding Document %s: id=%d, folderId=%d, folderName=%s", filename, data.id, folder.getId(), folder.getName());
new DbMailItem(mbox).create(data);
Document doc = new Document(mbox, data);
doc.finishCreation(parent);
pd.setVersion(doc.getVersion());
return doc;
}
use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.
the class DumpsterTest method createDocument.
private MailItem createDocument(String name, String content) throws Exception {
InputStream in = new ByteArrayInputStream(content.getBytes());
ParsedDocument pd = new ParsedDocument(in, name, "text/plain", System.currentTimeMillis(), null, null);
return mbox.createDocument(null, folder.getId(), pd, MailItem.Type.DOCUMENT, 0);
}
Aggregations