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);
}
}
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;
}
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;
}
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));
}
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);
}
}
Aggregations