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