Search in sources :

Example 71 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class XWikiPageNotification method notify.

@Override
public void notify(XWikiNotificationRule rule, XWikiDocument doc, String action, XWikiContext context) {
    try {
        String notifpages = context.getWiki().getXWikiPreference("notification_pages", context);
        if ((notifpages != null) && (!notifpages.equals(""))) {
            String[] notifpages2 = StringUtils.split(notifpages, " ,");
            for (int i = 0; i < notifpages2.length; i++) {
                notifyPage(notifpages2[i], rule, doc, action, context);
            }
        }
        String xnotif = (context.getRequest() != null) ? context.getRequest().getParameter("xnotification") : null;
        if ((xnotif != null) && (!xnotif.equals(""))) {
            notifyPage(xnotif, rule, doc, action, context);
        }
    } catch (Throwable e) {
        XWikiException e2 = new XWikiException(XWikiException.MODULE_XWIKI_NOTIFICATION, XWikiException.ERROR_XWIKI_NOTIFICATION, "Error executing notifications", e);
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error(e2.getFullMessage());
        }
    }
}
Also used : XWikiException(com.xpn.xwiki.XWikiException)

Example 72 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class XWikiCacheServiceStub method newCache.

@Override
public XWikiCache newCache(String cacheName, int capacity) throws XWikiException {
    CacheConfiguration configuration = new CacheConfiguration();
    configuration.setConfigurationId(cacheName);
    LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
    lru.setMaxEntries(capacity);
    configuration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
    try {
        return new XWikiCacheStub(this.cacheFactory.newCache(configuration));
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to create new cache", e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) LRUEvictionConfiguration(org.xwiki.cache.eviction.LRUEvictionConfiguration) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) XWikiException(com.xpn.xwiki.XWikiException)

Example 73 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class Document method saveWithProgrammingRights.

public void saveWithProgrammingRights(String comment, boolean minorEdit) throws XWikiException {
    if (hasProgrammingRights()) {
        // The rights check above is generic, but the current method is a save operation, thus it should not be
        // performed if the document's wiki is in read only mode.
        XWikiContext context = getXWikiContext();
        String currentWikiId = context.getWikiId();
        try {
            // Make sure we check the current document's wiki and not the current context's wiki.
            context.setWikiId(getWiki());
            if (!context.getWiki().isReadOnly()) {
                saveDocument(comment, minorEdit);
            } else {
                java.lang.Object[] args = { getDefaultEntityReferenceSerializer().serialize(getDocumentReference()), getWiki() };
                throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, "Access denied in edit mode on document [{0}]. The wiki [{1}] is in read only mode.", null, args);
            }
        } finally {
            // Restore the context wiki.
            context.setWikiId(currentWikiId);
        }
    } else {
        java.lang.Object[] args = { this.getFullName() };
        throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, "Access denied with no programming rights document {0}", null, args);
    }
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiException(com.xpn.xwiki.XWikiException)

Example 74 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class XWikiHibernateAttachmentStore method deleteXWikiAttachment.

@Override
public void deleteXWikiAttachment(XWikiAttachment attachment, boolean parentUpdate, XWikiContext inputxcontext, boolean bTransaction) throws XWikiException {
    XWikiContext context = getExecutionXContext(inputxcontext, true);
    String currentWiki = context.getWikiId();
    try {
        // Switch context wiki to attachment wiki
        String attachmentWiki = (attachment.getReference() == null) ? null : attachment.getReference().getDocumentReference().getWikiReference().getName();
        if (attachmentWiki != null) {
            context.setWikiId(attachmentWiki);
        }
        if (bTransaction) {
            checkHibernate(context);
            bTransaction = beginTransaction(context);
        }
        Session session = getSession(context);
        // Delete the three attachment entries
        try {
            session.delete(new XWikiAttachmentContent(attachment));
        } catch (Exception e) {
            this.logger.warn("Error deleting attachment content [{}] of document [{}]", attachment.getFilename(), attachment.getDoc().getDocumentReference());
        }
        AttachmentVersioningStore store = resolveAttachmentVersioningStore(attachment, context);
        store.deleteArchive(attachment, context, false);
        try {
            session.delete(attachment);
        } catch (Exception e) {
            this.logger.warn("Error deleting attachment meta data [{}] of document [{}]", attachment.getFilename(), attachment.getDoc().getDocumentReference());
        }
        try {
            if (parentUpdate) {
                List<XWikiAttachment> list = attachment.getDoc().getAttachmentList();
                for (int i = 0; i < list.size(); i++) {
                    XWikiAttachment attach = list.get(i);
                    if (attachment.getFilename().equals(attach.getFilename())) {
                        list.remove(i);
                        break;
                    }
                }
                context.getWiki().getStore().saveXWikiDoc(attachment.getDoc(), context, false);
            }
        } catch (Exception e) {
            this.logger.warn("Error updating document when deleting attachment [{}] of document [{}]", attachment.getFilename(), attachment.getDoc().getDocumentReference());
        }
        if (bTransaction) {
            endTransaction(context, true);
        }
    } catch (Exception e) {
        Object[] args = { attachment.getReference() };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETING_ATTACHMENT, "Exception while deleting attachment {0}", e, args);
    } finally {
        try {
            if (bTransaction) {
                endTransaction(context, false);
            }
        } catch (Exception e) {
        }
        // Restore context wiki
        context.setWikiId(currentWiki);
        restoreExecutionXContext();
    }
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) XWikiAttachmentContent(com.xpn.xwiki.doc.XWikiAttachmentContent) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Example 75 with XWikiException

use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.

the class XWikiHibernateAttachmentStore method saveAttachmentsContent.

@Override
public void saveAttachmentsContent(List<XWikiAttachment> attachments, XWikiDocument doc, boolean bParentUpdate, XWikiContext inputxcontext, boolean bTransaction) throws XWikiException {
    if (attachments == null) {
        return;
    }
    XWikiContext context = getExecutionXContext(inputxcontext, true);
    try {
        if (bTransaction) {
            checkHibernate(context);
            bTransaction = beginTransaction(context);
        }
        Iterator<XWikiAttachment> it = attachments.iterator();
        while (it.hasNext()) {
            XWikiAttachment att = it.next();
            saveAttachmentContent(att, false, context, false);
        }
        if (bParentUpdate) {
            context.getWiki().getStore().saveXWikiDoc(doc, context, false);
        }
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving attachments", e);
    } finally {
        try {
            if (bTransaction) {
                endTransaction(context, false);
            }
        } catch (Exception e) {
        }
        restoreExecutionXContext();
    }
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)442 XWikiContext (com.xpn.xwiki.XWikiContext)156 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)147 DocumentReference (org.xwiki.model.reference.DocumentReference)98 BaseObject (com.xpn.xwiki.objects.BaseObject)88 IOException (java.io.IOException)57 QueryException (org.xwiki.query.QueryException)57 ArrayList (java.util.ArrayList)56 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)51 XWiki (com.xpn.xwiki.XWiki)48 XWikiRestException (org.xwiki.rest.XWikiRestException)44 Session (org.hibernate.Session)42 Document (com.xpn.xwiki.api.Document)38 InitializationException (org.xwiki.component.phase.InitializationException)36 WebApplicationException (javax.ws.rs.WebApplicationException)32 SQLException (java.sql.SQLException)31 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)30 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)29 UnexpectedException (org.xwiki.store.UnexpectedException)29 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)25