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.");
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations