Search in sources :

Example 6 with XWikiException

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);
    }
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) EventStreamException(org.xwiki.eventstream.EventStreamException) XWikiException(com.xpn.xwiki.XWikiException)

Example 7 with XWikiException

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();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 8 with XWikiException

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);
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 9 with XWikiException

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);
    }
}
Also used : InstanceId(org.xwiki.instance.InstanceId) HibernateException(org.hibernate.HibernateException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiHibernateBaseStore(com.xpn.xwiki.store.XWikiHibernateBaseStore) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Example 10 with XWikiException

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;
}
Also used : MessagingException(javax.mail.MessagingException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

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