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