本文整理汇总了Java中org.thymeleaf.context.IWebContext类的典型用法代码示例。如果您正苦于以下问题:Java IWebContext类的具体用法?Java IWebContext怎么用?Java IWebContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IWebContext类属于org.thymeleaf.context包,在下文中一共展示了IWebContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBundleUrl
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
/**
* Adds the context path to the bundleUrl. We don't use the Thymeleaf "@" syntax or any other mechanism to
* encode this URL as the resolvers could have a conflict.
*
* For example, resolving a bundle named "style.css" that has a file also named "style.css" creates problems as
* the TF or version resolvers both want to version this file.
*
* @param arguments
* @param bundleName
* @return
*/
protected String getBundleUrl(Arguments arguments, String bundleName) {
String bundleUrl = bundleName;
if (!StringUtils.startsWith(bundleUrl, "/")) {
bundleUrl = "/" + bundleUrl;
}
IWebContext context = (IWebContext) arguments.getContext();
HttpServletRequest request = context.getHttpServletRequest();
String contextPath = request.getContextPath();
if (StringUtils.isNotEmpty(contextPath)) {
bundleUrl = contextPath + bundleUrl;
}
return bundleUrl;
}
示例2: adaptHeader
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
@Override
protected void adaptHeader(HtmlTable table) {
Node tableNode = (Node) ((IWebContext) arguments.getContext()).getHttpServletRequest().getAttribute(
DataTablesDialect.INTERNAL_NODE_TABLE);
Element thead = DomUtils.findElement((Element) tableNode, "thead");
Element tr = new Element("tr");
for (HtmlColumn column : table.getLastHeaderRow().getColumns()) {
Element th = new Element("th");
th.addChild(new Text(column.getContent().toString()));
tr.addChild(th);
}
if (thead != null) {
thead.addChild(tr);
}
else {
thead = new Element("thead");
thead.addChild(tr);
((Element) tableNode).addChild(thead);
}
}
示例3: adaptFooter
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
@Override
protected void adaptFooter(HtmlTable table) {
Element tfoot = new Element("tfoot");
Node tableNode = (Node) ((IWebContext) arguments.getContext()).getHttpServletRequest().getAttribute(
DataTablesDialect.INTERNAL_NODE_TABLE);
for (HtmlColumn column : table.getLastHeaderRow().getColumns()) {
Element th = new Element("th");
th.addChild(new Text(column.getContent().toString()));
tfoot.addChild(th);
}
((Element) tableNode).addChild(tfoot);
}
示例4: processAttribute
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) {
HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest();
Map<Option<?>, Object> stagingOptions = (Map<Option<?>, Object>) request
.getAttribute(DataTablesDialect.INTERNAL_BEAN_TABLE_STAGING_OPTIONS);
// Make the actual attribute processing
doProcessAttribute(arguments, element, attributeName, stagingOptions);
// Housekeeping
element.removeAttribute(attributeName);
return ProcessorResult.ok();
}
示例5: setupExport
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
/**
* Sets up the export properties, before the filter intercepts the response.
*
* @param arguments
* The Thymeleaf arguments.
* @param htmlTable
* The {@link HtmlTable} to export.
*/
private void setupExport(Arguments arguments, HtmlTable htmlTable) {
HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest();
HttpServletResponse response = ((IWebContext) arguments.getContext()).getHttpServletResponse();
String currentExportType = ExportUtils.getCurrentExportType(request);
htmlTable.getTableConfiguration().setExporting(true);
htmlTable.getTableConfiguration().setCurrentExportFormat(currentExportType);
// Call the export delegate
ExportDelegate exportDelegate = new ExportDelegate(htmlTable, request);
exportDelegate.prepareExport();
response.reset();
}
示例6: processView
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
@Override public void processView(final ViewEngineContext context) throws ViewEngineException {
try {
final IWebContext ctx = ctxFactory.create(context);
engine.process(context.getView(), ctx, context.getResponse().getWriter());
} catch (IOException e) {
throw new ViewEngineException(e);
}
}
示例7: createHtmlContentFromTemplate
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
private String createHtmlContentFromTemplate(final User user, final Locale locale, final HttpServletRequest request,
final HttpServletResponse response) {
Map<String, Object> variables = new HashMap<>();
variables.put("user", user);
variables.put("baseUrl", request.getScheme() + "://" + // "http" + "://
request.getServerName() + // "myhost"
":" + request.getServerPort());
IWebContext context = new SpringWebContext(request, response, servletContext,
locale, variables, applicationContext);
return templateEngine.process("activationEmail", context);
}
示例8: createHtmlContentFromTemplate
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
private String createHtmlContentFromTemplate(final User user, final Locale locale, final HttpServletRequest request,
final HttpServletResponse response) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("user", user);
variables.put("baseUrl", request.getScheme() + "://" + // "http" + "://
request.getServerName() + // "myhost"
":" + request.getServerPort());
IWebContext context = new SpringWebContext(request, response, servletContext,
locale, variables, applicationContext);
return templateEngine.process(MailService.EMAIL_ACTIVATION_PREFIX + MailService.TEMPLATE_SUFFIX, context);
}
示例9: createHtmlContentFromTemplate
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
private String createHtmlContentFromTemplate(final User user, final Locale locale, final HttpServletRequest request,
final HttpServletResponse response) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("user", user);
variables.put("baseUrl", request.getScheme() + "://" + // "http" + "://
request.getServerName() + // "myhost"
":" + request.getServerPort());
IWebContext context = new SpringWebContext(request, response, servletContext,
locale, variables, applicationContext);
return templateEngine.process("activationEmail", context);
}
示例10: buildObject
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
@Override
public Object buildObject(IExpressionContext context, String expressionObjectName) {
if (JawrDialect.PREFIX.equals(expressionObjectName)) {
if (context instanceof IWebContext) {
return new Jawr((IWebContext) context);
}
}
return null;
}
示例11: processElement
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
@Override
protected ProcessorResult processElement(Arguments arguments, Element element) {
HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest();
HttpServletResponse response = ((IWebContext) arguments.getContext()).getHttpServletResponse();
HtmlTable htmlTable = (HtmlTable) RequestUtils.getFromRequest(DataTablesDialect.INTERNAL_BEAN_TABLE, request);
ProcessorResult processorResult = doProcessElement(arguments, element, request, response, htmlTable);
return processorResult;
}
示例12: processAttribute
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) {
HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest();
// A Map<ConfType, Object> is associated with each table id
Map<String, Map<ConfType, Object>> configs = (Map<String, Map<ConfType, Object>>) RequestUtils.getFromRequest(
DataTablesDialect.INTERNAL_BEAN_CONFIGS, request);
String tableId = AttributeUtils.parseStringAttribute(arguments, element, attributeName);
if (configs != null && configs.containsKey(tableId)) {
throw new DandelionException("A div with id '" + tableId + "' is already present in the current template.");
}
else {
configs = new HashMap<String, Map<ConfType, Object>>();
}
configs.put(tableId, new HashMap<ConfType, Object>());
RequestUtils.storeInRequest(DataTablesDialect.INTERNAL_BEAN_CONFIGS, configs, request);
// The node is stored to be easily accessed later during the processing
RequestUtils.storeInRequest(DataTablesDialect.INTERNAL_NODE_CONFIG, element, request);
return ProcessorResult.ok();
}
示例13: findPage
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
public static Page<?> findPage(final ITemplateContext context) {
// 1. Get Page object from local variables (defined with sd:page-object)
// 2. Search Page using ${page} expression
// 3. Search Page object as request attribute
final Object pageFromLocalVariable = context.getVariable(Keys.PAGE_VARIABLE_KEY);
if (isPageInstance(pageFromLocalVariable)) {
return (Page<?>) pageFromLocalVariable;
}
// Check if not null and Page instance available with ${page} expression
final IEngineConfiguration configuration = context.getConfiguration();
final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
final IStandardExpression expression = parser.parseExpression(context, Keys.PAGE_EXPRESSION);
final Object page = expression.execute(context);
if (isPageInstance(page)) {
return (Page<?>) page;
}
// Search for Page object, and only one instance, as request attribute
if (context instanceof IWebContext) {
HttpServletRequest request = ((IWebContext) context).getRequest();
Enumeration<String> attrNames = request.getAttributeNames();
Page<?> pageOnRequest = null;
while (attrNames.hasMoreElements()) {
String attrName = (String) attrNames.nextElement();
Object attr = request.getAttribute(attrName);
if (isPageInstance(attr)) {
if (pageOnRequest != null) {
throw new InvalidObjectParameterException("More than one Page object found on request!");
}
pageOnRequest = (Page<?>) attr;
}
}
if (pageOnRequest != null) {
return pageOnRequest;
}
}
throw new InvalidObjectParameterException("Invalid or not present Page object found on request!");
}
示例14: buildBaseUrl
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
private static String buildBaseUrl(final ITemplateContext context, Collection<String> excludeParams) {
// URL defined with pagination-url tag
final String url = (String) context.getVariable(Keys.PAGINATION_URL_KEY);
if (url == null && context instanceof IWebContext) {
// Creates url from actual request URI and parameters
final StringBuilder builder = new StringBuilder();
final IWebContext webContext = (IWebContext) context;
final HttpServletRequest request = webContext.getRequest();
// URL base path from request
builder.append(request.getRequestURI());
Map<String, String[]> params = request.getParameterMap();
Set<Entry<String, String[]>> entries = params.entrySet();
boolean firstParam = true;
for (Entry<String, String[]> param : entries) {
// Append params not excluded to basePath
String name = param.getKey();
if (!excludeParams.contains(name)) {
if (firstParam) {
builder.append(Q_MARK);
firstParam = false;
} else {
builder.append(AND);
}
// Iterate over all values to create multiple values per
// parameter
String[] values = param.getValue();
Collection<String> paramValues = Arrays.asList(values);
Iterator<String> it = paramValues.iterator();
while (it.hasNext()) {
String value = it.next();
builder.append(name).append(EQ).append(value);
if (it.hasNext()) {
builder.append(AND);
}
}
}
}
// Escape to HTML content
return HtmlEscape.escapeHtml4Xml(builder.toString());
}
return url == null ? EMPTY : url;
}
示例15: execute
import org.thymeleaf.context.IWebContext; //导入依赖的package包/类
public void execute() {
IWebContext context = (IWebContext) arguments.getContext();
context.getRequestAttributes().put(CONNECTION_ATTR_NAME, createJdbcTemplate());
}