public static HtmlTable getTable(Arguments arguments) { return (HtmlTable) ((IWebContext) arguments.getContext()).getHttpServletRequest() .getAttribute("htmlTable"); }
public static HtmlTable getTable(Arguments arguments){ return (HtmlTable)((IWebContext) arguments.getContext()).getHttpServletRequest().getAttribute("htmlTable"); }
@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(); }
@Override protected void doProcessAttribute(Arguments arguments, Element element, String attributeName, Map<Option<?>, Object> stagingOptions) { HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest(); String attrValue = AttributeUtils.parseStringAttribute(arguments, element, attributeName); RequestUtils.storeInRequest(DataTablesDialect.INTERNAL_CONF_GROUP, attrValue, request); } }
@Override public InputStream getResourceAsStream(TemplateProcessingParameters templateProcessingParameters, String resourceName) { IContext context = templateProcessingParameters.getContext(); if (!(context instanceof IWebContext)) { throw new TemplateProcessingException("Resource resolution by ServletContext with " + this.getClass().getName() + " can only be performed " + "when context implements " + IWebContext.class.getName() + " [current context: " + context.getClass().getName() + "]"); } HttpServletRequest request = ((IWebContext) context).getHttpServletRequest(); Context dandelionContext = (Context) request.getAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE); // Get the asset content thanks to the cache key String cacheKey = AssetUtils.extractCacheKeyFromRequest(request); String contents = dandelionContext.getAssetStorage().get(cacheKey).getContents(); // Wrap the contents with prototype-only comment blocks StringBuilder adaptedContents = new StringBuilder(BLOCK_WRAP_START); adaptedContents.append(BLOCK_WRAP_CDATA_START); adaptedContents.append(contents); adaptedContents.append(BLOCK_WRAP_CDATA_END); adaptedContents.append(BLOCK_WRAP_END); String configuredEncoding = dandelionContext.getConfiguration().getEncoding(); InputStream is = null; try { is = new ByteArrayInputStream(adaptedContents.toString().getBytes(configuredEncoding)); } catch (UnsupportedEncodingException e) { throw new DandelionException("Unable to encode the Javascript asset using the '" + configuredEncoding + "', which doesn't seem to be supported", e); } return is; }
@Override public InputStream getResourceAsStream(TemplateProcessingParameters templateProcessingParameters, String resourceName) { IContext context = templateProcessingParameters.getContext(); if (!(context instanceof IWebContext)) { throw new TemplateProcessingException("Resource resolution by ServletContext with " + this.getClass().getName() + " can only be performed " + "when context implements " + IWebContext.class.getName() + " [current context: " + context.getClass().getName() + "]"); } HttpServletRequest request = ((IWebContext) context).getHttpServletRequest(); Context dandelionContext = (Context) request.getAttribute(WebConstants.DANDELION_CONTEXT_ATTRIBUTE); // Get the asset content thanks to the cache key String cacheKey = AssetUtils.extractCacheKeyFromRequest(request); String contents = dandelionContext.getAssetStorage().get(cacheKey).getContents(); // Wrap the contents with prototype-only comment blocks StringBuilder adaptedContents = new StringBuilder(BLOCK_WRAP_START); adaptedContents.append(BLOCK_WRAP_CDATA_START); adaptedContents.append(contents); adaptedContents.append(BLOCK_WRAP_CDATA_END); adaptedContents.append(BLOCK_WRAP_END); String configuredEncoding = dandelionContext.getConfiguration().getEncoding(); InputStream is = null; try { is = new ByteArrayInputStream(adaptedContents.toString().getBytes(configuredEncoding)); } catch (UnsupportedEncodingException e) { throw new DandelionException("Unable to encode the Javascript asset using the '" + configuredEncoding + "', which doesn't seem to be supported", e); } return is; }
@Override protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) { logger.debug("{} attribute found", attributeName); // Get the request HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest(); // Get HtmlTable POJO from the HttpServletRequest HtmlTable htmlTable = Utils.getTable(arguments); // Get attribute value String attrValue = element.getAttributeValue(attributeName); logger.debug("Extracted value : {}", attrValue); // HtmlTable update if (htmlTable != null && StringUtils.isNotBlank(attrValue)) { htmlTable.setLabels(Utils.getBaseUrl(request) + attrValue); } return nonLenientOK(element, attributeName); } }
HTTP_SERVLET_REQUEST_VARIABLE_NAME, webContext.getHttpServletRequest()); variables.put( HTTP_SESSION_VARIABLE_NAME, webContext.getHttpSession());
protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) { HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest();
@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; }
HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest();
@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); } }
final HttpServletRequest request = webContext.getHttpServletRequest(); final HttpServletResponse response = webContext.getHttpServletResponse(); final ServletContext servletContext = webContext.getServletContext();
logger.debug("{} element found with id {}", element.getNormalizedName(), tableId); HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest(); ((IWebContext) arguments.getContext()).getHttpServletRequest().setAttribute( "htmlTable", htmlTable); ((IWebContext) arguments.getContext()).getHttpServletRequest().setAttribute( "tableNode", element);
final HttpServletRequest request = webContext.getHttpServletRequest(); final HttpServletResponse response = webContext.getHttpServletResponse(); final ServletContext servletContext = webContext.getServletContext();
/** * TODO * * @param element */ private void generateFooter(Element element, Arguments arguments) { Element tfoot = new Element("tfoot"); Node tableNode = (Node)((IWebContext) arguments.getContext()).getHttpServletRequest().getAttribute("tableNode"); for(HtmlColumn column : htmlTable.getLastHeaderRow().getColumns()){ Element th = new Element("th"); th.addChild(new Text(column.getContent())); tfoot.addChild(th); } ((Element) tableNode).addChild(tfoot); } }
logger.debug("Setting export up ..."); HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest(); HttpServletResponse response = ((IWebContext) arguments.getContext()) .getHttpServletResponse();
/** * 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(); }
@Override protected ProcessorResult processElement(Arguments arguments, Element element) { // Get the HTTP request HttpServletRequest request = ((IWebContext) arguments.getContext()).getHttpServletRequest(); // HtmlTable htmlTable = (HtmlTable) // arguments.getLocalVariable("htmlTable"); HtmlTable htmlTable = Utils.getTable(arguments); this.htmlTable = htmlTable; if (this.htmlTable != null) { // The table is being exported if (RequestHelper.isTableBeingExported(request, this.htmlTable)) { setupExport(arguments); } // The table must be generated and displayed else { setupHtmlGeneration(arguments, element, request); } } // The "finalizing div" can now be removed element.getParent().removeChild(element); return ProcessorResult.OK; }
@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); } }