Search in sources :

Example 6 with XWikiRequest

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");
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) XWiki(com.xpn.xwiki.XWiki)

Example 7 with XWikiRequest

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;
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) ArrayList(java.util.ArrayList) XWikiException(com.xpn.xwiki.XWikiException)

Example 8 with XWikiRequest

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;
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) XWiki(com.xpn.xwiki.XWiki) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 9 with XWikiRequest

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);
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) XWikiURLFactory(com.xpn.xwiki.web.XWikiURLFactory) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiURLFactoryService(com.xpn.xwiki.web.XWikiURLFactoryService) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface) XWikiServletResponseStub(com.xpn.xwiki.web.XWikiServletResponseStub) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 10 with XWikiRequest

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());
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) Test(org.junit.Test)

Aggregations

XWikiRequest (com.xpn.xwiki.web.XWikiRequest)21 XWikiContext (com.xpn.xwiki.XWikiContext)6 XWiki (com.xpn.xwiki.XWiki)4 IOException (java.io.IOException)4 Cookie (javax.servlet.http.Cookie)4 XWikiException (com.xpn.xwiki.XWikiException)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)3 BaseObject (com.xpn.xwiki.objects.BaseObject)3 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)3 Date (java.util.Date)3 Test (org.junit.Test)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 FileNotFoundException (java.io.FileNotFoundException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 NamingException (javax.naming.NamingException)2 HttpSession (javax.servlet.http.HttpSession)2 URIException (org.apache.commons.httpclient.URIException)2