Search in sources :

Example 16 with XWikiException

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

the class ParseGroovyFromString method initCache.

private void initCache(int iClassCapacity, XWikiContext context) throws XWikiException {
    try {
        CacheConfiguration configuration = new LRUCacheConfiguration("xwiki.groovy.class", iClassCapacity);
        this.classCache = this.cacheManager.createNewLocalCache(configuration);
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to initilize caches", e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration) XWikiException(com.xpn.xwiki.XWikiException) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration)

Example 17 with XWikiException

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

the class CreateActionRequestHandler method isTemplateProviderAllowedToCreateInCurrentSpace.

/**
 * Verifies if the creation inside the specified spaceReference is allowed by the current template provider. If the
 * creation is not allowed, an exception will be set on the context.
 *
 * @return {@code true} if the creation is allowed, {@code false} otherwise
 */
public boolean isTemplateProviderAllowedToCreateInCurrentSpace() {
    // - Set an error on the context, to be read by the create.vm
    if (templateProvider != null) {
        // Check if the creation restrictions are enforced.
        boolean creationRestrictionsEnforced = templateProvider.getIntValue(TP_CREATION_RESTRICTIONS_ARE_SUGGESTIONS_PROPERTY, 0) == 0;
        // Check using the template provider's creation restrictions, only when they are enforced.
        if (creationRestrictionsEnforced && !isTemplateProviderAllowedInSpace(templateProvider, spaceReference, TP_CREATION_RESTRICTIONS_PROPERTY)) {
            // put an exception on the context, for create.vm to know to display an error
            Object[] args = { templateProvider.getStringValue(TEMPLATE), spaceReference, name };
            XWikiException exception = new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_TEMPLATE_NOT_AVAILABLE, "Template {0} cannot be used in space {1} when creating page {2}", null, args);
            ScriptContext scontext = getCurrentScriptContext();
            scontext.setAttribute(EXCEPTION, exception, ScriptContext.ENGINE_SCOPE);
            scontext.setAttribute("createAllowedSpaces", getTemplateProviderRestrictions(templateProvider, TP_CREATION_RESTRICTIONS_PROPERTY), ScriptContext.ENGINE_SCOPE);
            return false;
        }
    }
    // For all other cases, creation is allowed.
    return true;
}
Also used : ScriptContext(javax.script.ScriptContext) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiException(com.xpn.xwiki.XWikiException)

Example 18 with XWikiException

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

the class CreateActionRequestHandler method isDocumentAlreadyExisting.

/**
 * @param newDocument the new document to check if it already exists
 * @return true if the document already exists (i.e. is not usable) and set an exception in the velocity context;
 *         false otherwise.
 */
public boolean isDocumentAlreadyExisting(XWikiDocument newDocument) {
    // re-requests the page and space, else create the document and redirect to edit
    if (!isEmptyDocument(newDocument)) {
        ScriptContext scontext = getCurrentScriptContext();
        // Expose to the template reference of the document that already exist so that it can propose to view or
        // edit it.
        scontext.setAttribute("existingDocumentReference", newDocument.getDocumentReference(), ScriptContext.ENGINE_SCOPE);
        // Throw an exception.
        Object[] args = { newDocument.getDocumentReference() };
        XWikiException documentAlreadyExists = new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY, "Cannot create document {0} because it already has content", null, args);
        scontext.setAttribute(EXCEPTION, documentAlreadyExists, ScriptContext.ENGINE_SCOPE);
        return true;
    }
    return false;
}
Also used : ScriptContext(javax.script.ScriptContext) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiException(com.xpn.xwiki.XWikiException)

Example 19 with XWikiException

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

the class DeleteAction method deleteFromRecycleBin.

private void deleteFromRecycleBin(long index, XWikiContext context) throws XWikiException {
    XWiki xwiki = context.getWiki();
    XWikiResponse response = context.getResponse();
    XWikiDocument doc = context.getDoc();
    XWikiDeletedDocument dd = xwiki.getRecycleBinStore().getDeletedDocument(index, context, true);
    // don't try to delete it and instead redirect to the view page.
    if (dd != null) {
        DeletedDocument ddapi = new DeletedDocument(dd, context);
        if (!ddapi.canDelete()) {
            throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, "You are not allowed to delete a document from the trash " + "immediately after it has been deleted from the wiki");
        }
        if (!dd.getFullName().equals(doc.getFullName())) {
            throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION, "The specified trash entry does not match the current document");
        }
        xwiki.getRecycleBinStore().deleteFromRecycleBin(index, context, true);
    }
    sendRedirect(response, Utils.getRedirect("view", context));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) DeletedDocument(com.xpn.xwiki.api.DeletedDocument) XWiki(com.xpn.xwiki.XWiki) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) XWikiException(com.xpn.xwiki.XWikiException)

Example 20 with XWikiException

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

the class DeleteAction method startDeleteJob.

private Job startDeleteJob(EntityReference entityReference, XWikiContext context) throws XWikiException {
    RefactoringScriptService refactoring = (RefactoringScriptService) Utils.getComponent(ScriptService.class, "refactoring");
    EntityRequest deleteRequest = refactoring.createDeleteRequest(Arrays.asList(entityReference));
    deleteRequest.setInteractive(isAsync(context.getRequest()));
    try {
        JobExecutor jobExecutor = Utils.getComponent(JobExecutor.class);
        return jobExecutor.execute(RefactoringJobs.DELETE, deleteRequest);
    } catch (JobException e) {
        throw new XWikiException(String.format("Failed to schedule the delete job for [%s]", entityReference), e);
    }
}
Also used : RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) ScriptService(org.xwiki.script.service.ScriptService) JobException(org.xwiki.job.JobException) EntityRequest(org.xwiki.refactoring.job.EntityRequest) JobExecutor(org.xwiki.job.JobExecutor) RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) 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