use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class FeedPluginApi method getDefaultFeedImage.
/**
* Creates a new instance of the default feed image. The default image file name is taken from the <i>logo</i> skin
* preference. If this preference is missing, <i>logo.png</i> is used instead.
*
* @return a new feed image
*/
public SyndImage getDefaultFeedImage() {
// Currently, getSkinFile method returns relative (internal) URLs. I couldn't find a way to
// get the external URL for a skin file. Is this something forbidden? I've noticed that we
// actually compute the full URL but we strip it with urlFactory.getURL(url, context). So
// what do you think of overloading the getSkinFile method by adding a absoluteURL flag?
XWiki xwiki = getXWikiContext().getWiki();
String fileName = xwiki.getSkinPreference("logo", "logo.png", getXWikiContext());
String url = xwiki.getSkinFile(fileName, getXWikiContext());
String port = "";
XWikiRequest request = getXWikiContext().getRequest();
if (("http".equals(request.getScheme()) && request.getServerPort() != 80) || ("https".equals(request.getScheme()) && request.getServerPort() != 443)) {
port = ":" + request.getServerPort();
}
String link = request.getScheme() + "://" + request.getServerName() + port;
url = link + url;
return getFeedImage(url, link, "XWiki Logo", "XWiki Logo");
}
use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class LevelsClass method getList.
@Override
public List<String> getList(XWikiContext context) {
List<String> list;
try {
list = context.getWiki().getRightService().listAllLevels(context);
} catch (XWikiException e) {
// TODO add log exception
list = new ArrayList<String>();
}
XWikiRequest req = context.getRequest();
if (("editrights".equals(req.get("xpage")) || "rights".equals(req.get("editor"))) && (!"1".equals(req.get("global")))) {
list.remove("admin");
list.remove("programming");
list.remove("delete");
list.remove("register");
}
return list;
}
use of com.xpn.xwiki.web.XWikiRequest in project celements-blog by celements.
the class NewsletterReceivers method sendArticleByMail.
public List<String[]> sendArticleByMail(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
String articleName = request.get("sendarticle");
String from = request.get("from");
String replyTo = request.get("reply_to");
String subject = request.get("subject");
String testSend = request.get("testSend");
boolean isTest = false;
if ((testSend != null) && testSend.equals("1")) {
isTest = true;
}
XWiki wiki = context.getWiki();
List<String[]> result = new ArrayList<>();
int successfullySent = 0;
LOGGER.debug("articleName = " + articleName);
LOGGER.debug("article exists = " + wiki.exists(articleName, context));
if ((articleName != null) && (!"".equals(articleName.trim())) && (wiki.exists(articleName, context))) {
XWikiDocument doc = wiki.getDocument(articleName, context);
String baseURL = doc.getExternalURL("view", context);
List<String[]> allUserMailPairs = null;
LOGGER.debug("is test send: " + isTest);
if (isTest) {
String user = context.getUser();
XWikiDocument userDoc = context.getWiki().getDocument(user, context);
BaseObject userObj = userDoc.getObject("XWiki.XWikiUsers");
if (userObj != null) {
String email = userObj.getStringValue("email");
if (email.trim().length() > 0) {
allUserMailPairs = new ArrayList<>();
String[] userFields = getUserAdminLanguage(user, getWebUtilsService().getDefaultLanguage());
allUserMailPairs.add((String[]) ArrayUtils.addAll(new String[] { user, email }, userFields));
}
}
} else {
allUserMailPairs = getNewsletterReceiversList();
}
String origUser = context.getUser();
String origLanguage = context.getLanguage();
VelocityContext vcontext = (VelocityContext) context.get("vcontext");
Object origAdminLanguage = vcontext.get("admin_language");
Object origMsgTool = vcontext.get("msg");
Object origAdminMsgTool = vcontext.get("adminMsg");
for (String[] userMailPair : allUserMailPairs) {
String[] sendResult = sendNewsletterToOneReceiver(from, replyTo, subject, doc, baseURL, userMailPair, context);
if ("0".equals(sendResult[1])) {
successfullySent++;
}
result.add(sendResult);
}
context.setUser(origUser);
context.setLanguage(origLanguage);
vcontext.put("language", origLanguage);
vcontext.put("admin_language", origAdminLanguage);
vcontext.put("msg", origMsgTool);
vcontext.put("adminMsg", origAdminMsgTool);
setNewsletterSentObject(doc, from, replyTo, subject, successfullySent, isTest, context);
}
return result;
}
use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class XWikiContextCopierTest method setup.
@Before
public void setup() throws Exception {
Utils.setComponentManager(mocker);
originalResponse = new XWikiServletResponseStub();
original = new XWikiContext();
// Set some values
original.setWikiId("wiki");
DocumentReference userReference = new DocumentReference("wiki", "Space", "Page");
EntityReferenceSerializer<String> serializer = mocker.registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
when(serializer.serialize(userReference)).thenReturn("wiki:Space.Page");
mocker.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
original.setUserReference(userReference);
// Set the mock request
this.originalRequest = mock(XWikiRequest.class);
original.setRequest(this.originalRequest);
Copier<XWikiRequest> requestCopier = mocker.getInstance(new DefaultParameterizedType(null, Copier.class, XWikiRequest.class));
when(requestCopier.copy(this.originalRequest)).thenReturn(this.originalRequest);
// Set the stubbed response
original.setResponse(originalResponse);
// XWiki mock
XWiki xwiki = mock(XWiki.class);
original.setWiki(xwiki);
// Store mock
// Simulate the existence of a hibernate session in context
original.put(HIBSESSION, "opened session");
store = mock(XWikiStoreInterface.class);
// clean up will remove the session in the given context
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
XWikiContext context = (XWikiContext) invocation.getArguments()[0];
context.put(HIBSESSION, null);
return null;
}
}).when(store).cleanUp(any(XWikiContext.class));
when(xwiki.getStore()).thenReturn(store);
// URL factory mock
XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
XWikiURLFactoryService urlFactoryService = mock(XWikiURLFactoryService.class);
when(urlFactoryService.createURLFactory(anyInt(), any(XWikiContext.class))).thenReturn(urlFactory);
when(xwiki.getURLFactoryService()).thenReturn(urlFactoryService);
}
use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class XWikiRequestCopierTest method copyRequest.
@Test
public void copyRequest() throws Exception {
XWikiRequest copy = this.mocker.getComponentUnderTest().copy(this.originalRequest);
assertNotSame(this.originalRequest, copy);
// Check that each value on the cloned request are equal.
assertEquals(this.originalRequest.getHeader("x-forwarded-host"), copy.getHeader("x-forwarded-host"));
assertEquals(this.originalRequest.getContextPath(), copy.getContextPath());
assertEquals(this.originalRequest.getScheme(), copy.getScheme());
assertEquals(this.originalRequest.getAttributeNames(), copy.getAttributeNames());
assertEquals(this.originalRequest.getAttribute("attribute"), copy.getAttribute("attribute"));
assertEquals(this.originalRequest.getServerName(), copy.getServerName());
assertEquals(this.originalRequest.getRequestURL(), copy.getRequestURL());
}
Aggregations