use of com.xpn.xwiki.web.XWikiURLFactory in project xwiki-platform by xwiki.
the class XWikiMockitoTest method getURLWithDotsAndBackslashInSpaceName.
@Test
public void getURLWithDotsAndBackslashInSpaceName() throws Exception {
XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
context.setURLFactory(urlFactory);
DocumentReference reference = new DocumentReference("wiki", Arrays.asList("space.withdot.and\\and:"), "page");
this.xwiki.getURL(reference, "view", null, null, context);
verify(urlFactory).createURL("space\\.withdot\\.and\\\\and\\:", "page", "view", null, null, "wiki", context);
}
use of com.xpn.xwiki.web.XWikiURLFactory in project xwiki-platform by xwiki.
the class XWikiMockitoTest method getURLWithLocale.
@Test
public void getURLWithLocale() throws Exception {
XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
context.setURLFactory(urlFactory);
DocumentReference reference = new DocumentReference("wiki", "Space", "Page", Locale.FRENCH);
this.xwiki.getURL(reference, "view", null, null, context);
verify(urlFactory).createURL("Space", "Page", "view", "language=fr", null, "wiki", context);
this.xwiki.getURL(reference, "view", "language=ro", null, context);
verify(urlFactory).createURL("Space", "Page", "view", "language=ro&language=fr", null, "wiki", context);
}
use of com.xpn.xwiki.web.XWikiURLFactory in project xwiki-platform by xwiki.
the class XWikiMockitoTest method getEntityURLWithDefaultAction.
@Test
public void getEntityURLWithDefaultAction() throws Exception {
DocumentReference documentReference = new DocumentReference("tennis", Arrays.asList("Path", "To"), "Success");
AttachmentReference attachmentReference = new AttachmentReference("image.png", documentReference);
XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
context.setURLFactory(urlFactory);
this.xwiki.getURL(documentReference, this.context);
verify(urlFactory).createURL("Path.To", "Success", "view", null, null, "tennis", this.context);
this.xwiki.getURL(attachmentReference, this.context);
verify(urlFactory).createAttachmentURL("image.png", "Path.To", "Success", "download", null, "tennis", this.context);
}
use of com.xpn.xwiki.web.XWikiURLFactory in project xwiki-platform by xwiki.
the class AbstractAnnotationRESTResource method renderDocumentWithAnnotations.
/**
* Helper function to get the rendered content of the document with annotations. All setup of context for rendering
* content similar to the rendering on standard view will be done in this function. <br>
* FIXME: find out if this whole context setup code has to be here or in the annotations service
*
* @param docName the name of the document to render
* @param language the language in which to render the document
* @param action the context action to render the document for
* @param annotations the annotations to render on the document
* @return the HTML rendered content of the document
* @throws XWikiException if anything wrong happens while setting up the context for rendering
* @throws AnnotationServiceException if anything goes wrong during the rendering of the annotations
*/
private String renderDocumentWithAnnotations(String docName, String language, String action, Collection<Annotation> annotations) throws XWikiException, AnnotationServiceException {
String isInRenderingEngineKey = "isInRenderingEngine";
XWikiContext context = this.xcontextProvider.get();
Object isInRenderingEngine = context.get(isInRenderingEngineKey);
// set the context url factory to the servlet url factory so that all links get correctly generated as if we
// were view-ing the page
XWikiURLFactory oldFactory = context.getURLFactory();
int oldMode = context.getMode();
String result = null;
try {
context.setMode(XWikiContext.MODE_SERVLET);
XWikiURLFactory urlf = context.getWiki().getURLFactoryService().createURLFactory(context.getMode(), context);
context.setURLFactory(urlf);
// setup documents on the context, and velocity context, and message tool for i18n and all
setUpDocuments(docName, language);
// set the current action on the context
context.setAction(action);
context.put(isInRenderingEngineKey, true);
// render the content in xhtml syntax, with the passed list of annotations
result = annotationService.getAnnotatedRenderedContent(docName, null, "xhtml/1.0", annotations);
} finally {
if (isInRenderingEngine != null) {
context.put(isInRenderingEngineKey, isInRenderingEngine);
} else {
context.remove(isInRenderingEngineKey);
}
context.setURLFactory(oldFactory);
context.setMode(oldMode);
}
return result;
}
use of com.xpn.xwiki.web.XWikiURLFactory in project xwiki-platform by xwiki.
the class DefaultMailTemplateManager method evaluate.
@Override
public String evaluate(DocumentReference templateReference, String property, Map<String, Object> velocityVariables, Object localeValue) throws MessagingException {
Locale locale = getLocale(localeValue);
// Note: Make sure to use the class reference relative to the template's wiki and not the current wiki.
DocumentReference mailClassReference = this.resolver.resolve(MAIL_CLASS, templateReference.getWikiReference());
VelocityContext velocityContext = createVelocityContext(velocityVariables);
String templateFullName = this.serializer.serialize(templateReference);
int objectNumber = getObjectMailNumber(templateReference, mailClassReference, locale);
String content = this.documentBridge.getProperty(templateReference, mailClassReference, objectNumber, property).toString();
// Save the current URL Factory since we'll replace it with a URL factory that generates external URLs (ie
// full URLs).
XWikiContext xcontext = this.xwikiContextProvider.get();
XWikiURLFactory originalURLFactory = xcontext.getURLFactory();
Locale originalLocale = xcontext.getLocale();
try {
// Generate full URLs (instead of relative URLs)
xcontext.setURLFactory(new ExternalServletURLFactory(xcontext));
// Set the current locale to be the passed locale so that the template content is evaluated in that
// language (in case there are translations used).
xcontext.setLocale(locale);
return velocityEvaluator.evaluateVelocity(content, templateFullName, velocityContext);
} catch (XWikiException e) {
throw new MessagingException(String.format("Failed to evaluate property [%s] for Document [%s] and locale [%s]", property, templateReference, localeValue), e);
} finally {
xcontext.setURLFactory(originalURLFactory);
xcontext.setLocale(originalLocale);
}
}
Aggregations