Search in sources :

Example 91 with XWikiException

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

the class XWikiHibernateVersioningStore method loadXWikiDocArchive.

@Override
public void loadXWikiDocArchive(XWikiDocumentArchive archivedoc, boolean bTransaction, XWikiContext context) throws XWikiException {
    try {
        List<XWikiRCSNodeInfo> nodes = loadAllRCSNodeInfo(context, archivedoc.getId(), bTransaction);
        archivedoc.setNodes(nodes);
    } catch (Exception e) {
        Object[] args = { Long.valueOf(archivedoc.getId()) };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading archive {0}", e, args);
    }
}
Also used : XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiException(com.xpn.xwiki.XWikiException) HibernateException(org.hibernate.HibernateException) XWikiException(com.xpn.xwiki.XWikiException)

Example 92 with XWikiException

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

the class XWikiHibernateVersioningStore method loadXWikiDoc.

@Override
public XWikiDocument loadXWikiDoc(XWikiDocument basedoc, String sversion, XWikiContext inputxcontext) throws XWikiException {
    XWikiContext context = getExecutionXContext(inputxcontext, true);
    try {
        XWikiDocumentArchive archive = getXWikiDocumentArchive(basedoc, context);
        Version version = new Version(sversion);
        XWikiDocument doc = archive.loadDocument(version, context);
        if (doc == null) {
            Object[] args = { basedoc.getDocumentReferenceWithLocale(), version.toString() };
            throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_UNEXISTANT_VERSION, "Version {1} does not exist while reading document {0}", null, args);
        }
        // Make sure the document has the same name
        // as the new document (in case there was a name change
        // FIXME: is this really needed ?
        doc.setDocumentReference(basedoc.getDocumentReference());
        doc.setStore(basedoc.getStore());
        return doc;
    } finally {
        restoreExecutionXContext();
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiDocumentArchive(com.xpn.xwiki.doc.XWikiDocumentArchive) Version(org.suigeneris.jrcs.rcs.Version) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 93 with XWikiException

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

the class XWikiHibernateVersioningStore method updateXWikiDocArchive.

@Override
public void updateXWikiDocArchive(XWikiDocument doc, boolean bTransaction, XWikiContext inputxcontext) throws XWikiException {
    XWikiContext context = getExecutionXContext(inputxcontext, true);
    try {
        XWikiDocumentArchive archiveDoc = getXWikiDocumentArchive(doc, context);
        archiveDoc.updateArchive(doc, doc.getAuthor(), doc.getDate(), doc.getComment(), doc.getRCSVersion(), context);
        doc.setRCSVersion(archiveDoc.getLatestVersion());
        saveXWikiDocArchive(archiveDoc, bTransaction, context);
    } catch (Exception e) {
        Object[] args = { doc.getFullName() };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_OBJECT, "Exception while updating archive {0}", e, args);
    } finally {
        restoreExecutionXContext();
    }
}
Also used : XWikiDocumentArchive(com.xpn.xwiki.doc.XWikiDocumentArchive) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) HibernateException(org.hibernate.HibernateException) XWikiException(com.xpn.xwiki.XWikiException)

Example 94 with XWikiException

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

the class XWikiScriptContextInitializer method initialize.

@Override
public void initialize(ScriptContext scriptContext) {
    XWikiContext xcontext = this.xcontextProvider.get();
    if (scriptContext.getAttribute("util") == null) {
        // Put the Util API in the Script context.
        scriptContext.setAttribute("util", new com.xpn.xwiki.api.Util(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE);
        // We put the com.xpn.xwiki.api.XWiki object into the context and not the com.xpn.xwiki.XWiki one which is
        // for internal use only. In this manner we control what the user can access.
        scriptContext.setAttribute("xwiki", new XWiki(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute("request", xcontext.getRequest(), ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute("response", xcontext.getResponse(), ScriptContext.ENGINE_SCOPE);
        // We put the com.xpn.xwiki.api.Context object into the context and not the com.xpn.xwiki.XWikiContext one
        // which is for internal use only. In this manner we control what the user can access.
        // We use "xcontext" because "context" is a reserved binding in JSR-223 specifications
        scriptContext.setAttribute("xcontext", new Context(xcontext), ScriptContext.ENGINE_SCOPE);
    }
    // Current document
    Document docAPI = null;
    XWikiDocument doc = xcontext.getDoc();
    if (doc != null) {
        docAPI = setDocument(scriptContext, "doc", doc, xcontext);
        XWikiDocument tdoc = (XWikiDocument) xcontext.get("tdoc");
        if (tdoc == null) {
            try {
                tdoc = doc.getTranslatedDocument(xcontext);
            } catch (XWikiException e) {
                this.logger.warn("Failed to retrieve the translated document for [{}]. " + "Continue using the default translation.", doc.getDocumentReference(), e);
                tdoc = doc;
            }
        }
        Document tdocAPI = setDocument(scriptContext, "tdoc", tdoc, xcontext);
        XWikiDocument cdoc = (XWikiDocument) xcontext.get("cdoc");
        if (cdoc == null) {
            Document cdocAPI = tdocAPI;
            if (cdocAPI == null) {
                cdocAPI = docAPI;
            }
            scriptContext.setAttribute("cdoc", cdocAPI, ScriptContext.ENGINE_SCOPE);
        } else {
            setDocument(scriptContext, "cdoc", cdoc, xcontext);
        }
    }
    // Current secure document
    XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc");
    if (sdoc == null) {
        scriptContext.setAttribute("sdoc", docAPI, ScriptContext.ENGINE_SCOPE);
    } else {
        setDocument(scriptContext, "sdoc", sdoc, xcontext);
    }
    // Miscellaneous
    scriptContext.setAttribute("locale", xcontext.getLocale(), ScriptContext.ENGINE_SCOPE);
}
Also used : Context(com.xpn.xwiki.api.Context) ScriptContext(javax.script.ScriptContext) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.api.XWiki) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiException(com.xpn.xwiki.XWikiException)

Example 95 with XWikiException

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

the class DisplayScriptService method content.

/**
 * Displays the content of the given document.
 *
 * @param document the document whose content is displayed
 * @param parameters the display parameters
 * @return the result of rendering the content of the given document using the provided parameters
 */
public String content(Document document, Map<String, Object> parameters) {
    XWikiContext context = getXWikiContext();
    String content = null;
    try {
        content = document.getTranslatedContent();
    } catch (XWikiException e) {
        this.logger.warn("Failed to get the translated content of document [{}].", document.getPrefixedFullName(), e);
        return null;
    }
    String renderedContent = this.renderingCache.getRenderedContent(document.getDocumentReference(), content, context);
    if (renderedContent == null) {
        Map<String, Object> actualParameters = new HashMap<String, Object>(parameters);
        DocumentDisplayerParameters displayerParameters = (DocumentDisplayerParameters) parameters.get(DISPLAYER_PARAMETERS_KEY);
        if (displayerParameters == null) {
            displayerParameters = new DocumentDisplayerParameters();
            // Default content display parameters.
            displayerParameters.setExecutionContextIsolated(true);
            displayerParameters.setContentTranslated(true);
        } else if (displayerParameters.isTitleDisplayed()) {
            // Clone because we have to enforce content display.
            displayerParameters = displayerParameters.clone();
        }
        // Ensure the content is displayed.
        displayerParameters.setTitleDisplayed(false);
        Syntax outputSyntax = getOutputSyntax(parameters);
        displayerParameters.setTargetSyntax(outputSyntax);
        actualParameters.put(DISPLAYER_PARAMETERS_KEY, displayerParameters);
        renderedContent = document(document, actualParameters, outputSyntax);
        if (renderedContent != null) {
            this.renderingCache.setRenderedContent(document.getDocumentReference(), content, renderedContent, context);
        }
    }
    return renderedContent;
}
Also used : DocumentDisplayerParameters(org.xwiki.display.internal.DocumentDisplayerParameters) HashMap(java.util.HashMap) XWikiContext(com.xpn.xwiki.XWikiContext) Syntax(org.xwiki.rendering.syntax.Syntax) 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