Search in sources :

Example 1 with XWikiAttachmentStoreInterface

use of com.xpn.xwiki.store.XWikiAttachmentStoreInterface in project xwiki-platform by xwiki.

the class XWikiAttachment method loadAttachmentContent.

public void loadAttachmentContent(XWikiContext xcontext) throws XWikiException {
    if (this.content == null) {
        WikiReference currentWiki = xcontext.getWikiReference();
        try {
            // Make sure we work on the attachment's wiki
            WikiReference attachmentWiki = getReference().getDocumentReference().getWikiReference();
            if (attachmentWiki != null) {
                xcontext.setWikiReference(attachmentWiki);
            }
            try {
                XWikiAttachmentStoreInterface store = getAttachmentContentStore(xcontext);
                store.loadAttachmentContent(this, xcontext, true);
            } catch (ComponentLookupException e) {
                throw new XWikiException("Failed to find store for attachment [" + getReference() + "]", e);
            }
        } finally {
            if (currentWiki != null) {
                xcontext.setWikiReference(currentWiki);
            }
        }
    }
}
Also used : XWikiAttachmentStoreInterface(com.xpn.xwiki.store.XWikiAttachmentStoreInterface) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) WikiReference(org.xwiki.model.reference.WikiReference) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with XWikiAttachmentStoreInterface

use of com.xpn.xwiki.store.XWikiAttachmentStoreInterface in project xwiki-platform by xwiki.

the class XWikiDocument method saveAttachmentContent.

/**
 * @deprecated should not be used, save the document instead
 */
@Deprecated
public void saveAttachmentContent(XWikiAttachment attachment, boolean updateParent, boolean transaction, XWikiContext context) throws XWikiException {
    String currentWiki = context.getWikiId();
    try {
        // get the translated content
        if (getDatabase() != null) {
            context.setWikiId(getDatabase());
        }
        // Save the attachment
        XWikiAttachmentStoreInterface store = resolveXWikiAttachmentStoreInterface(attachment.getContentStore(), context);
        store.saveAttachmentContent(attachment, false, context, transaction);
        // We need to make sure there is a version upgrade
        setMetaDataDirty(true);
        // Save the document
        if (updateParent) {
            context.getWiki().saveDocument(this, context);
        }
    } catch (OutOfMemoryError e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE, "Out Of Memory Exception");
    } finally {
        if (currentWiki != null) {
            context.setWikiId(currentWiki);
        }
    }
}
Also used : XWikiAttachmentStoreInterface(com.xpn.xwiki.store.XWikiAttachmentStoreInterface) ToString(org.suigeneris.jrcs.util.ToString) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)2 XWikiAttachmentStoreInterface (com.xpn.xwiki.store.XWikiAttachmentStoreInterface)2 ToString (org.suigeneris.jrcs.util.ToString)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 WikiReference (org.xwiki.model.reference.WikiReference)1