use of com.xpn.xwiki.web.XWikiMessageTool in project xwiki-platform by xwiki.
the class DeprecatedScriptContextInitializer method initialize.
@Override
public void initialize(ScriptContext scriptContext) {
// Make deprecated XWiki message tool available from scripts
scriptContext.setAttribute("msg", new XWikiMessageTool(Utils.getComponent(ContextualLocalizationManager.class)), ScriptContext.ENGINE_SCOPE);
// Make the Syntax Factory component available from Script.
// TODO: We need to decide how we want to expose components in general and how to protect users from
// "dangerous" apis.
scriptContext.setAttribute("syntaxFactory", this.syntaxFactory, ScriptContext.ENGINE_SCOPE);
}
use of com.xpn.xwiki.web.XWikiMessageTool in project xwiki-platform by xwiki.
the class XWikiContext method getMessageTool.
/**
* @deprecated since 4.3M2 use {@link org.xwiki.localization.ContextualLocalizationManager} component instead
*/
@Deprecated
public XWikiMessageTool getMessageTool() {
XWikiMessageTool msg = ((XWikiMessageTool) get("msg"));
if (msg == null) {
getWiki().prepareResources(this);
msg = ((XWikiMessageTool) get("msg"));
}
return msg;
}
use of com.xpn.xwiki.web.XWikiMessageTool in project celements-blog by celements.
the class BlogPluginTest method testBatchImportReceivers_inactiveAdd.
@Test
public void testBatchImportReceivers_inactiveAdd() throws XWikiException {
Map<String, String> result = new TreeMap<>();
result.put("myname@email.com", "inactive");
result.put("myName2@email", "invalid");
result.put("myName @email.com", "invalid");
String importData = "\r\n,myName @email.com,,,myName2@email\nmyName@email.com";
String nl = "My.Newsletter";
XWikiMessageTool messageTool = createMock(XWikiMessageTool.class);
XWikiContext context = createMock(XWikiContext.class);
expect(context.getMessageTool()).andReturn(messageTool).anyTimes();
expect(context.getWiki()).andReturn(xwiki).anyTimes();
expect(context.getUser()).andReturn("XWiki.Admin").anyTimes();
expect(xwiki.search((String) anyObject(), same(context))).andReturn(null).anyTimes();
expect(xwiki.generateRandomString(eq(16))).andReturn("abc");
expect(xwiki.exists(eq("NewsletterReceivers.abc"), same(context))).andReturn(false);
XWikiDocument doc1 = createMock(XWikiDocument.class);
expect(doc1.getObject(eq("Celements2.BlogConfigClass"))).andReturn(null);
expect(doc1.getObject(eq("XWiki.ArticleClass"))).andReturn(null);
expect(context.getDoc()).andReturn(doc1);
expect(xwiki.getDocument(eq("NewsletterReceivers.abc"), same(context))).andReturn(doc1).times(2);
XWikiDocument nlDoc = createMock(XWikiDocument.class);
expect(xwiki.exists(eq(nl), same(context))).andReturn(true);
expect(xwiki.getDocument(eq(nl), same(context))).andReturn(nlDoc);
expect(nlDoc.getFullName()).andReturn(nl).anyTimes();
expect(doc1.getObject(eq("Celements.NewsletterReceiverClass"), eq("subscribed"), eq(nl), eq(false))).andReturn(null);
BaseObject obj = new BaseObject();
expect(doc1.newObject(eq("Celements.NewsletterReceiverClass"), same(context))).andReturn(obj);
expect(doc1.getObject(eq("Celements.NewsletterReceiverClass"), eq("subscribed"), eq(nl), eq(false))).andReturn(obj);
xwiki.saveDocument(same(doc1), same(context));
expectLastCall();
expect(messageTool.get(eq("cel_newsletter_subscriber_invalid"))).andReturn("invalid").times(2);
expect(messageTool.get(eq("cel_newsletter_subscriber_inactive"))).andReturn("inactive").once();
replayAll(context, doc1, messageTool, nlDoc);
assertEquals(result, plugin.batchImportReceivers(true, importData, nl, context));
verifyAll(context, doc1, messageTool, nlDoc);
}
use of com.xpn.xwiki.web.XWikiMessageTool in project celements-blog by celements.
the class BlogPluginTest method testBatchImportReceivers_Exception.
@Test
public void testBatchImportReceivers_Exception() throws XWikiException {
Map<String, String> result = new TreeMap<>();
result.put("myname@email.com", "invalid");
String importData = "\r\n,My Name <myName@email.com>,,,,";
String nl = "My.Newsletter";
XWikiMessageTool messageTool = createMock(XWikiMessageTool.class);
XWikiContext context = createMock(XWikiContext.class);
expect(context.getMessageTool()).andReturn(messageTool).anyTimes();
expect(context.getWiki()).andReturn(xwiki).anyTimes();
expect(context.getUser()).andReturn("XWiki.Admin").anyTimes();
expect(xwiki.search((String) anyObject(), same(context))).andReturn(null).anyTimes();
expect(xwiki.generateRandomString(eq(16))).andReturn("abc");
expect(xwiki.exists(eq("NewsletterReceivers.abc"), same(context))).andReturn(false);
expect(xwiki.getDocument(eq("NewsletterReceivers.abc"), same(context))).andThrow(new XWikiException());
expect(messageTool.get(eq("cel_newsletter_subscriber_invalid"))).andReturn("invalid").once();
replayAll(context, messageTool);
assertEquals(result, plugin.batchImportReceivers(false, importData, nl, context));
verifyAll(context, messageTool);
}
use of com.xpn.xwiki.web.XWikiMessageTool in project celements-blog by celements.
the class BlogPluginTest method testBatchImportReceivers_activeAdd.
@Test
public void testBatchImportReceivers_activeAdd() throws XWikiException {
Map<String, String> result = new TreeMap<>();
result.put("myname@email.com", "active");
String importData = "\r\n,My Name <myName@email.com>,,,,";
String nl = "My.Newsletter";
XWikiMessageTool messageTool = createMock(XWikiMessageTool.class);
XWikiContext context = createMock(XWikiContext.class);
expect(context.getMessageTool()).andReturn(messageTool).anyTimes();
expect(context.getWiki()).andReturn(xwiki).anyTimes();
expect(context.getUser()).andReturn("XWiki.Admin").anyTimes();
expect(xwiki.search((String) anyObject(), same(context))).andReturn(null).anyTimes();
expect(xwiki.generateRandomString(eq(16))).andReturn("abc");
expect(xwiki.exists(eq("NewsletterReceivers.abc"), same(context))).andReturn(false);
XWikiDocument doc1 = createMock(XWikiDocument.class);
expect(doc1.getObject(eq("Celements2.BlogConfigClass"))).andReturn(null);
expect(doc1.getObject(eq("XWiki.ArticleClass"))).andReturn(null);
expect(context.getDoc()).andReturn(doc1);
expect(xwiki.getDocument(eq("NewsletterReceivers.abc"), same(context))).andReturn(doc1).times(2);
XWikiDocument nlDoc = createMock(XWikiDocument.class);
expect(xwiki.exists(eq(nl), same(context))).andReturn(true);
expect(xwiki.getDocument(eq(nl), same(context))).andReturn(nlDoc);
expect(nlDoc.getFullName()).andReturn(nl).anyTimes();
expect(doc1.getObject(eq("Celements.NewsletterReceiverClass"), eq("subscribed"), eq(nl), eq(false))).andReturn(null);
BaseObject obj = new BaseObject();
expect(doc1.newObject(eq("Celements.NewsletterReceiverClass"), same(context))).andReturn(obj);
expect(doc1.getObject(eq("Celements.NewsletterReceiverClass"), eq("subscribed"), eq(nl), eq(false))).andReturn(obj);
xwiki.saveDocument(same(doc1), same(context));
expectLastCall();
expect(messageTool.get(eq("cel_newsletter_subscriber_active"))).andReturn("active").once();
replayAll(context, doc1, messageTool, nlDoc);
assertEquals(result, plugin.batchImportReceivers(false, importData, nl, context));
verifyAll(context, doc1, messageTool, nlDoc);
}
Aggregations