use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class DefaultModelBridge method findDocument.
private XWikiDocument findDocument(EntityReference entityReference) throws EventStreamException {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
try {
return xwiki.getDocument(entityReference, context);
} catch (XWikiException e) {
throw new EventStreamException(String.format("Unable to retrieve the given document [%s] in the current context.", entityReference), e);
}
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class EditorWikiComponent method getDescriptor.
@Override
public EditorDescriptor getDescriptor() {
try {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument editorDocument = xcontext.getWiki().getDocument(this.getDocumentReference(), xcontext);
XWikiDocument translatedEditorDocument = editorDocument.getTranslatedDocument(xcontext);
this.descriptorBuilder.setName(translatedEditorDocument.getRenderedTitle(Syntax.PLAIN_1_0, xcontext));
this.descriptorBuilder.setDescription(translatedEditorDocument.getRenderedContent(Syntax.PLAIN_1_0, xcontext));
} catch (XWikiException e) {
this.logger.warn("Failed to read the editor name and description. Root cause: " + ExceptionUtils.getRootCauseMessage(e));
}
return this.descriptorBuilder.build();
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class EditorWikiComponent method initialize.
/**
* Initializes the editor component based on the definition provided by the specified document.
*
* @param editorReference the reference to the wiki page that defines the editor (i.e. that has a
* {@code XWiki.EditorClass} object)
* @throws WikiComponentException if the editor component fails to be initialized
*/
public void initialize(DocumentReference editorReference) throws WikiComponentException {
if (this.editorReference != null) {
throw new WikiComponentException("This editor component is already initialized.");
}
this.editorReference = editorReference;
try {
XWikiContext xcontext = this.xcontextProvider.get();
initialize(xcontext.getWiki().getDocument(editorReference, xcontext));
} catch (XWikiException e) {
throw new WikiComponentException("Failed to load the editor document.", e);
}
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class DefaultInstanceIdManager method initialize.
@Override
public void initialize() {
// Load it from the database
XWikiContext context = getXWikiContext();
XWikiHibernateBaseStore store = (XWikiHibernateBaseStore) this.hibernateStoreProvider.get();
// Try retrieving the UUID from the database
// First ensure that we're on the main wiki since we store the unique id only on the main wiki
String originalDatabase = context.getWikiId();
context.setWikiId(context.getMainXWiki());
try {
InstanceId id = store.failSafeExecuteRead(context, new XWikiHibernateBaseStore.HibernateCallback<InstanceId>() {
@Override
public InstanceId doInHibernate(Session session) throws HibernateException {
// Retrieve the version from the database
return (InstanceId) session.createCriteria(InstanceId.class).uniqueResult();
}
});
// If the database doesn't hold the UUID then compute one and save it
if (id == null) {
// Compute UUID
final InstanceId newId = new InstanceId(UUID.randomUUID().toString());
// will be retried again next time the wiki is restarted.
try {
store.executeWrite(context, new XWikiHibernateBaseStore.HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session) throws HibernateException {
session.createQuery("delete from " + InstanceId.class.getName()).executeUpdate();
session.save(newId);
return null;
}
});
} catch (XWikiException e) {
this.logger.warn("Failed to save Instance id to database. Reason: [{}]", ExceptionUtils.getRootCauseMessage(e));
}
id = newId;
}
this.instanceId = id;
} finally {
// Restore original database
context.setWikiId(originalDatabase);
}
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class DefaultMailTemplateManager method getMailObjectsCount.
private int getMailObjectsCount(DocumentReference templateReference, DocumentReference mailClassReference) throws MessagingException {
XWikiContext context = this.xwikiContextProvider.get();
int objectsCount;
try {
List<BaseObject> objects = context.getWiki().getDocument(templateReference, context).getXObjects(mailClassReference);
if (objects != null) {
objectsCount = objects.size();
} else {
objectsCount = 0;
}
} catch (XWikiException e) {
throw new MessagingException(String.format("Failed to find number of [%s] objects in Document [%s]", mailClassReference, templateReference), e);
}
return objectsCount;
}
Aggregations