Search in sources :

Example 1 with XWikiRequest

use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.

the class FOPXSLFORenderer method extendConfiguration.

private void extendConfiguration(DefaultConfiguration writableConfiguration) {
    // Add XWiki fonts folder to the configuration.
    try {
        String fontsPath = this.environment.getResource(FONTS_PATH).getPath();
        XWikiContext xcontext = this.xcontextProvider.get();
        if (xcontext != null) {
            XWikiRequest request = xcontext.getRequest();
            if (request != null && request.getSession() != null) {
                fontsPath = request.getSession().getServletContext().getRealPath(FONTS_PATH);
            }
        }
        // <renderers>
        DefaultConfiguration renderersConfiguration = (DefaultConfiguration) writableConfiguration.getChild(RENDERERS, false);
        if (renderersConfiguration == null) {
            renderersConfiguration = new DefaultConfiguration(RENDERERS);
            writableConfiguration.addChild(renderersConfiguration);
        }
        // Ensure we have support for PDF rendering.
        // <renderer mime="application/pdf">
        DefaultConfiguration pdfRenderer = null;
        for (Configuration renderer : renderersConfiguration.getChildren()) {
            if (MIME_TYPE_PDF.equals(renderer.getAttribute(MIME))) {
                pdfRenderer = (DefaultConfiguration) renderer;
            }
        }
        if (pdfRenderer == null) {
            pdfRenderer = new DefaultConfiguration("renderer");
            pdfRenderer.setAttribute(MIME, MIME_TYPE_PDF);
            renderersConfiguration.addChild(pdfRenderer);
        }
        // <fonts>
        DefaultConfiguration fontsConfiguration = (DefaultConfiguration) pdfRenderer.getChild(FONTS, false);
        if (fontsConfiguration == null) {
            fontsConfiguration = new DefaultConfiguration(FONTS);
            pdfRenderer.addChild(fontsConfiguration);
        }
        // <directory>fontdirectory</directory>
        DefaultConfiguration directoryConfiguration = new DefaultConfiguration("directory");
        directoryConfiguration.setValue(fontsPath);
        fontsConfiguration.addChild(directoryConfiguration);
    } catch (Exception e) {
        this.logger.warn("Starting with 1.5, XWiki uses the WEB-INF/fonts/ directory as the font directory, " + "and it should contain the FreeFont (http://savannah.gnu.org/projects/freefont/) fonts. " + "FOP cannot access this directory. If this is an upgrade from a previous version, " + "make sure you also copy the WEB-INF/fonts directory from the new distribution package.");
    }
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) DefaultConfiguration(org.apache.avalon.framework.configuration.DefaultConfiguration) Configuration(org.apache.avalon.framework.configuration.Configuration) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultConfiguration(org.apache.avalon.framework.configuration.DefaultConfiguration) InitializationException(org.xwiki.component.phase.InitializationException) ConfigurationException(org.apache.avalon.framework.configuration.ConfigurationException)

Example 2 with XWikiRequest

use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.

the class XWiki method validateUser.

public int validateUser(boolean withConfirmEmail, XWikiContext context) throws XWikiException {
    try {
        XWikiRequest request = context.getRequest();
        // Get the user document
        String username = convertUsername(request.getParameter("xwikiname"), context);
        if (username.indexOf('.') == -1) {
            username = "XWiki." + username;
        }
        XWikiDocument userDocument = getDocument(username, context);
        // Get the stored validation key
        BaseObject userObject = userDocument.getObject("XWiki.XWikiUsers", 0);
        String storedKey = userObject.getStringValue("validkey");
        // Get the validation key from the URL
        String validationKey = request.getParameter("validkey");
        PropertyInterface validationKeyClass = getClass("XWiki.XWikiUsers", context).get("validkey");
        if (validationKeyClass instanceof PasswordClass) {
            validationKey = ((PasswordClass) validationKeyClass).getEquivalentPassword(storedKey, validationKey);
        }
        // Compare the two keys
        if ((!storedKey.equals("") && (storedKey.equals(validationKey)))) {
            userObject.setIntValue("active", 1);
            saveDocument(userDocument, context);
            if (withConfirmEmail) {
                String email = userObject.getStringValue("email");
                String password = userObject.getStringValue("password");
                sendValidationEmail(username, password, email, request.getParameter("validkey"), "confirmation_email_content", context);
            }
            return 0;
        } else {
            return -1;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_VALIDATE_USER, "Exception while validating user", e, null);
    }
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) PropertyInterface(com.xpn.xwiki.objects.PropertyInterface) PasswordClass(com.xpn.xwiki.objects.classes.PasswordClass) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 3 with XWikiRequest

use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.

the class StatsUtil method isVisitObjectValid.

/**
 * Indicate of the provided visit object has to be recreated.
 *
 * @param visitObject the visit object to validate.
 * @param context the XWiki context.
 * @return false if the visit object has to be recreated, true otherwise.
 * @since 1.4M1
 */
private static boolean isVisitObjectValid(VisitStats visitObject, XWikiContext context) {
    boolean valid = true;
    XWikiRequest request = context.getRequest();
    HttpSession session = request.getSession(true);
    Cookie cookie = (Cookie) context.get(CONTPROP_STATS_COOKIE);
    Date nowDate = new Date();
    if (visitObject != null) {
        // If the cookie is not the same
        if (!visitObject.getCookie().equals(cookie.getValue())) {
            // then there is something wrong here
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Found visit with cookie " + visitObject.getCookie() + " in session " + session.getId() + " for request with cookie " + cookie.getValue());
            }
            valid = false;
        } else if ((nowDate.getTime() - visitObject.getEndDate().getTime()) > 30 * 60 * 1000) {
            // If session is longer than 30 minutes we should invalidate it
            // and create a new one
            valid = false;
        } else if (!context.getUser().equals(visitObject.getName())) {
            // If the user is not the same, we should invalidate the session
            // and create a new one
            valid = false;
        }
    }
    return valid;
}
Also used : Cookie(javax.servlet.http.Cookie) XWikiRequest(com.xpn.xwiki.web.XWikiRequest) HttpSession(javax.servlet.http.HttpSession) Date(java.util.Date)

Example 4 with XWikiRequest

use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.

the class ChartingAction method render.

@Override
public String render(XWikiContext context) throws XWikiException {
    XWikiRequest request = context.getRequest();
    String path = request.getRequestURI();
    String filename = Util.decodeURI(path.substring(path.lastIndexOf("/") + 1), context);
    try {
        ((ChartingPluginApi) context.getWiki().getPluginApi("charting", context)).outputFile(filename, context);
    } catch (IOException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION, "Exception while sending response", e);
    }
    return null;
}
Also used : ChartingPluginApi(com.xpn.xwiki.plugin.charts.ChartingPluginApi) XWikiRequest(com.xpn.xwiki.web.XWikiRequest) IOException(java.io.IOException) XWikiException(com.xpn.xwiki.XWikiException)

Example 5 with XWikiRequest

use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.

the class FeedPluginApi method getBlogFeed.

/**
 * Instantiates the default article feed.
 *
 * @param query the HQL query used for retrieving the articles
 * @param count the maximum number of articles to retrieve
 * @param start the start index
 * @param blogPostClassName The name of the Blog Class the data are retrieved from. If null the Default Blog
 *            Application is used.
 * @param metadata feed meta data (includes the author, description, copyright, encoding, url, title)
 * @return a new feed
 * @see #getArticleFeed(String, int, int, Map)
 */
public SyndFeed getBlogFeed(String query, int count, int start, String blogPostClassName, Map<String, Object> metadata) {
    if (query == null) {
        XWikiRequest request = getXWikiContext().getRequest();
        String category = request.getParameter("category");
        if (category == null || category.equals("")) {
            query = ", BaseObject as obj where obj.name=doc.fullName and obj.className='" + BLOG_POST_CLASS_NAME + "' and obj.name<>'" + BLOG_POST_TEMPLATE_NAME + "' order by doc.creationDate desc";
        } else {
            query = ", BaseObject as obj, DBStringListProperty as prop join prop.list list where obj.name=doc.fullName and obj.className='" + BLOG_POST_CLASS_NAME + "' and obj.name<>'" + BLOG_POST_TEMPLATE_NAME + "' and obj.id=prop.id.id and prop.id.name='category' and list = '" + category + "' order by doc.creationDate desc";
        }
    }
    Map<String, Object> params = Collections.emptyMap();
    Map<String, Object> blogMappings = null;
    if (blogPostClassName == null) {
        blogMappings = BLOG_FIELDS_MAPPING;
    } else {
        blogMappings = new HashMap<String, Object>();
        blogMappings.put(SyndEntryDocumentSource.FIELD_TITLE, blogPostClassName + "_title");
        blogMappings.put(SyndEntryDocumentSource.FIELD_DESCRIPTION, blogPostClassName + "_content");
        blogMappings.put(SyndEntryDocumentSource.FIELD_CATEGORIES, blogPostClassName + "_category");
        blogMappings.put(SyndEntryDocumentSource.FIELD_PUBLISHED_DATE, blogPostClassName + "_publishDate");
        blogMappings.put(SyndEntryDocumentSource.CONTENT_LENGTH, Integer.valueOf(400));
    }
    SyndFeed blogFeed = getFeed(query, count, start, getSyndEntrySource(SyndEntryDocumentSource.class.getName(), blogMappings), params, fillBlogFeedMetadata(metadata));
    if (blogFeed != null) {
        blogFeed.setImage(getDefaultFeedImage());
    }
    return blogFeed;
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

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