Package com.github.dandelion.datatables.core.export

Examples of com.github.dandelion.datatables.core.export.ExportConf$Builder


    if (parent.isFirstIteration()) {

      String format = type.toLowerCase().trim();
     
      // Export URL build
      ExportConf conf = null;
     
      if (parent.getTable().getTableConfiguration().getExportConfiguration().get(format) != null) {
        conf = parent.getTable().getTableConfiguration().getExportConfiguration().get(format);
      }
      else{
        conf = new ExportConf(format);
        parent.getTable().getTableConfiguration().getExportConfiguration().put(format, conf);
      }
     
      // Default mode (export using filter)
      StringBuilder exportUrl = null;
      if(StringUtils.isBlank(url)){
        exportUrl = UrlUtils.getCurrentUri(request);
        UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "f");
        conf.setHasCustomUrl(false);
      }
      // Custom mode (export using controller)
      else{
        exportUrl = new StringBuilder(url.trim());
        UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "c");
        conf.setHasCustomUrl(true);
      }

      if (StringUtils.isNotBlank(fileName)) {
        conf.setFileName(fileName.trim());
        UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_NAME, this.fileName);
      }

      if (StringUtils.isNotBlank(fileExtension)) {
        conf.setFileExtension(fileExtension);
        UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_EXTENSION, this.fileExtension);
      }

      if (StringUtils.isNotBlank(label)) {
        conf.setLabel(StringUtils.escape(this.escapeXml, this.label.trim()));
      }
      if (StringUtils.isNotBlank(cssClass)) {
        conf.setCssClass(new StringBuilder(cssClass.trim()));
      }
      if (StringUtils.isNotBlank(cssStyle)) {
        conf.setCssStyle(new StringBuilder(cssStyle.trim()));
      }

      if (StringUtils.isNotBlank(method)) {
        HttpMethod httpMethod = null;
        try {
          httpMethod = HttpMethod.valueOf(this.method.toUpperCase().trim());
        } catch (IllegalArgumentException e) {
          StringBuilder sb = new StringBuilder();
          sb.append("'");
          sb.append(this.method);
          sb.append("' is not a valid HTTP method. Possible values are: ");
          sb.append(EnumUtils.printPossibleValuesOf(HttpMethod.class));
          throw new JspException(sb.toString());
        }

        conf.setMethod(httpMethod);
      }

      if (StringUtils.isNotBlank(orientation)) {
        Orientation orientationEnum = null;
        try {
          orientationEnum = Orientation.valueOf(this.orientation.toUpperCase().trim());
        } catch (IllegalArgumentException e) {
          StringBuilder sb = new StringBuilder();
          sb.append("'");
          sb.append(this.orientation);
          sb.append("' is not a valid orientation. Possible values are: ");
          sb.append(EnumUtils.printPossibleValuesOf(Orientation.class));
          throw new JspException(sb.toString());
        }

        conf.setOrientation(orientationEnum);
        UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ORIENTATION, orientation);
      }

      if (StringUtils.isNotBlank(mimeType)) {
        conf.setMimeType(mimeType.trim());
        UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_MIME_TYPE, mimeType.trim());
      }

      if (includeHeader != null) {
        conf.setIncludeHeader(includeHeader);
        UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_HEADER, includeHeader);
      }

      if (autoSize != null) {
        conf.setAutoSize(autoSize);
        UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_AUTOSIZE, autoSize);
      }
     
      // Finalizes the export URL
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ID, parent.getTable().getId());
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_FORMAT, format);
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_IN_PROGRESS, "y");
      UrlUtils.addParameter(exportUrl, WebConstants.DANDELION_ASSET_FILTER_STATE, false);
      conf.setUrl(UrlUtils.getProcessedUrl(exportUrl, request, response));
     
      logger.debug("Export configuration for the type {} has been updated", format);
    }

    return EVAL_PAGE;
View Full Code Here


    processor.process(entry, tableConfiguration);
   
    assertThat(tableConfiguration.isExportable()).isEqualTo(true);
    assertThat(tableConfiguration.getExportConfiguration()).hasSize(1);
   
    ExportConf csvExportConf = tableConfiguration.getExportConfiguration().get("csv");
    assertThat(csvExportConf.getFormat()).isEqualTo("csv");
    assertThat(csvExportConf.getFileName()).isEqualTo("export-csv-" + new SimpleDateFormat("yyyymmDD").format(new GregorianCalendar().getTime()));
    assertThat(csvExportConf.getMimeType()).isEqualTo("text/csv");
    assertThat(csvExportConf.getLabel()).isEqualTo("CSV");
    assertThat(csvExportConf.getIncludeHeader()).isTrue();
    assertThat(csvExportConf.getUrl()).isEqualTo("?dtt=f&dtf=csv&dti=fakeId&dtp=y&" + WebConstants.DANDELION_ASSET_FILTER_STATE + "=false");
    assertThat(csvExportConf.getMethod()).isEqualTo(HttpMethod.GET);
    assertThat(csvExportConf.getAutoSize()).isTrue();
    assertThat(csvExportConf.getExportClass()).isEqualTo(ExportConf.DEFAULT_CSV_CLASS);
    assertThat(csvExportConf.getFileExtension()).isEqualTo("csv");
    assertThat(csvExportConf.getOrientation()).isNull();
   
    entry = new MapEntry<ConfigToken<?>, Object>(TableConfig.EXPORT_ENABLED_FORMATS, "csv  ");
    processor.process(entry, tableConfiguration);
   
    assertThat(tableConfiguration.isExportable()).isEqualTo(true);
    assertThat(tableConfiguration.getExportConfiguration()).hasSize(1);
   
    assertThat(csvExportConf.getFormat()).isEqualTo("csv");
    assertThat(csvExportConf.getFileName()).isEqualTo("export-csv-" + new SimpleDateFormat("yyyymmDD").format(new GregorianCalendar().getTime()));
    assertThat(csvExportConf.getMimeType()).isEqualTo("text/csv");
    assertThat(csvExportConf.getLabel()).isEqualTo("CSV");
    assertThat(csvExportConf.getIncludeHeader()).isTrue();
    assertThat(csvExportConf.getUrl()).isEqualTo("?dtt=f&dtf=csv&dti=fakeId&dtp=y&" + WebConstants.DANDELION_ASSET_FILTER_STATE + "=false");
    assertThat(csvExportConf.getMethod()).isEqualTo(HttpMethod.GET);
    assertThat(csvExportConf.getAutoSize()).isTrue();
    assertThat(csvExportConf.getExportClass()).isEqualTo(ExportConf.DEFAULT_CSV_CLASS);
    assertThat(csvExportConf.getFileExtension()).isEqualTo("csv");
  }
View Full Code Here

    processor.process(entry, tableConfiguration);
   
    assertThat(tableConfiguration.isExportable()).isEqualTo(true);
    assertThat(tableConfiguration.getExportConfiguration()).hasSize(2);
   
    ExportConf csvExportConf = tableConfiguration.getExportConfiguration().get("csv");
    assertThat(csvExportConf.getFormat()).isEqualTo("csv");
    assertThat(csvExportConf.getFileName()).isEqualTo("export-csv-" + new SimpleDateFormat("yyyymmDD").format(new GregorianCalendar().getTime()));
    assertThat(csvExportConf.getMimeType()).isEqualTo("text/csv");
    assertThat(csvExportConf.getLabel()).isEqualTo("CSV");
    assertThat(csvExportConf.getIncludeHeader()).isTrue();
    assertThat(csvExportConf.getUrl()).isEqualTo("?dtt=f&dtf=csv&dti=fakeId&dtp=y&" + WebConstants.DANDELION_ASSET_FILTER_STATE + "=false");
    assertThat(csvExportConf.getMethod()).isEqualTo(HttpMethod.GET);
    assertThat(csvExportConf.getAutoSize()).isTrue();
    assertThat(csvExportConf.getExportClass()).isEqualTo(ExportConf.DEFAULT_CSV_CLASS);
    assertThat(csvExportConf.getFileExtension()).isEqualTo("csv");
    assertThat(csvExportConf.getOrientation()).isNull();
   
    ExportConf pdfExportConf = tableConfiguration.getExportConfiguration().get("pdf");
    assertThat(pdfExportConf.getFormat()).isEqualTo("pdf");
    assertThat(pdfExportConf.getFileName()).isEqualTo("export-pdf-" + new SimpleDateFormat("yyyymmDD").format(new GregorianCalendar().getTime()));
    assertThat(pdfExportConf.getMimeType()).isEqualTo("application/pdf");
    assertThat(pdfExportConf.getLabel()).isEqualTo("PDF");
    assertThat(pdfExportConf.getIncludeHeader()).isTrue();
    assertThat(pdfExportConf.getUrl()).isEqualTo("?dtt=f&dtf=pdf&dti=fakeId&dtp=y&" + WebConstants.DANDELION_ASSET_FILTER_STATE + "=false");
    assertThat(pdfExportConf.getMethod()).isEqualTo(HttpMethod.GET);
    assertThat(pdfExportConf.getAutoSize()).isTrue();
    assertThat(pdfExportConf.getExportClass()).isEqualTo(ExportConf.DEFAULT_PDF_CLASS);
    assertThat(pdfExportConf.getFileExtension()).isEqualTo("pdf");
    assertThat(pdfExportConf.getOrientation()).isEqualTo(Orientation.LANDSCAPE);
  }
View Full Code Here

    processor.process(entry, tableConfiguration);
   
    assertThat(tableConfiguration.isExportable()).isEqualTo(true);
    assertThat(tableConfiguration.getExportConfiguration()).hasSize(2);
   
    ExportConf csvExportConf = tableConfiguration.getExportConfiguration().get("csv");
    assertThat(csvExportConf.getFormat()).isEqualTo("csv");
    assertThat(csvExportConf.getFileName()).isEqualTo("export-csv-" + new SimpleDateFormat("yyyymmDD").format(new GregorianCalendar().getTime()));
    assertThat(csvExportConf.getMimeType()).isEqualTo("text/csv");
    assertThat(csvExportConf.getLabel()).isEqualTo("CSV");
    assertThat(csvExportConf.getIncludeHeader()).isTrue();
    assertThat(csvExportConf.getUrl()).isEqualTo("?dtt=f&dtf=csv&dti=fakeId&dtp=y&" + WebConstants.DANDELION_ASSET_FILTER_STATE + "=false");
    assertThat(csvExportConf.getMethod()).isEqualTo(HttpMethod.GET);
    assertThat(csvExportConf.getAutoSize()).isTrue();
    assertThat(csvExportConf.getExportClass()).isEqualTo(ExportConf.DEFAULT_CSV_CLASS);
    assertThat(csvExportConf.getFileExtension()).isEqualTo("csv");
    assertThat(csvExportConf.getOrientation()).isNull();
   
    ExportConf pdfExportConf = tableConfiguration.getExportConfiguration().get("pdf");
    assertThat(pdfExportConf.getFormat()).isEqualTo("pdf");
    assertThat(pdfExportConf.getFileName()).isEqualTo("export-pdf-" + new SimpleDateFormat("yyyymmDD").format(new GregorianCalendar().getTime()));
    assertThat(pdfExportConf.getMimeType()).isEqualTo("application/pdf");
    assertThat(pdfExportConf.getLabel()).isEqualTo("PDF");
    assertThat(pdfExportConf.getIncludeHeader()).isTrue();
    assertThat(pdfExportConf.getUrl()).isEqualTo("?dtt=f&dtf=pdf&dti=fakeId&dtp=y&" + WebConstants.DANDELION_ASSET_FILTER_STATE + "=false");
    assertThat(pdfExportConf.getMethod()).isEqualTo(HttpMethod.GET);
    assertThat(pdfExportConf.getAutoSize()).isTrue();
    assertThat(pdfExportConf.getExportClass()).isEqualTo(ExportConf.DEFAULT_PDF_CLASS);
    assertThat(pdfExportConf.getFileExtension()).isEqualTo("pdf");
    assertThat(pdfExportConf.getOrientation()).isEqualTo(Orientation.LANDSCAPE);
  }
View Full Code Here

    processor.process(entry, tableConfiguration);
   
    assertThat(tableConfiguration.isExportable()).isEqualTo(true);
    assertThat(tableConfiguration.getExportConfiguration()).hasSize(1);
   
    ExportConf myFormatExportConf = tableConfiguration.getExportConfiguration().get("myformat");
    assertThat(myFormatExportConf.getFormat()).isEqualTo("myformat");
    assertThat(myFormatExportConf.getFileName()).isEqualTo("export-myformat-" + new SimpleDateFormat("yyyymmDD").format(new GregorianCalendar().getTime()));
    assertThat(myFormatExportConf.getMimeType()).isNull();
    assertThat(myFormatExportConf.getLabel()).isEqualTo("MYFORMAT");
    assertThat(myFormatExportConf.getIncludeHeader()).isTrue();
    assertThat(myFormatExportConf.getUrl()).isEqualTo("?dtt=f&dtf=myformat&dti=fakeId&dtp=y&" + WebConstants.DANDELION_ASSET_FILTER_STATE + "=false");
    assertThat(myFormatExportConf.getMethod()).isEqualTo(HttpMethod.GET);
    assertThat(myFormatExportConf.getAutoSize()).isTrue();
    assertThat(myFormatExportConf.getExportClass()).isNull();
    assertThat(myFormatExportConf.getFileExtension()).isEqualTo("myformat");
    assertThat(myFormatExportConf.getOrientation()).isNull();
  }
View Full Code Here

        HttpServletResponse response = (HttpServletResponse) servletResponse;
        DatatablesResponseWrapper resWrapper = new DatatablesResponseWrapper(response);

        chain.doFilter(request, resWrapper);

        ExportConf exportConf = (ExportConf) request
            .getAttribute(ExportUtils.DDL_DT_REQUESTATTR_EXPORT_CONF);

        String finalFileName = exportConf.getFileName() + "." + exportConf.getFileExtension();
        response.setHeader("Content-Disposition", "attachment; filename=\"" + finalFileName + "\"");
        response.setContentType(exportConf.getMimeType());

        byte[] content = (byte[]) servletRequest.getAttribute(ExportUtils.DDL_DT_REQUESTATTR_EXPORT_CONTENT);

        response.setContentLength(content.length);
              OutputStream out = response.getOutputStream();
View Full Code Here

      }

      if (StringUtils.isNotBlank(format)) {
        logger.debug("Export format {} found", format);

        ExportConf exportConf = null;
        // The export configuration already exists for this export
        // format
        if (tableConfiguration.getExportConfiguration().containsKey(format)) {

          exportConf = tableConfiguration.getExportConfiguration().get(format);
        }
        // The export configuration must be initialized
        else {
          exportConf = new ExportConf(format);
          tableConfiguration.getExportConfiguration().put(format, exportConf);
        }

        switch (currentExportConfToken) {
        case CLASS:
          exportConf.setExportClass(stringifiedValue);
          break;
        case FILENAME:
          exportConf.setFileName(stringifiedValue);
          break;
        case LABEL:
          exportConf.setLabel(stringifiedValue);
          break;
        case MIMETYPE:
          exportConf.setMimeType(stringifiedValue);
          break;
        }
      } else {
        throw new ConfigurationProcessingException("Format " + format + " unknown");
      }
View Full Code Here

     
      // An ExportConf will be initialized for each enable export format
      for (String enabledFormat : enabledFormats) {
        enabledFormat = enabledFormat.toLowerCase().trim();

        ExportConf exportConf = null;

        // The exportConf may already exist due to the ExportTag (JSP)
        // or the DivConfTypeAttrProcessor (Thymeleaf)
        if (!tableConfiguration.getExportConfiguration().containsKey(enabledFormat)) {
         
          // Default mode (export using filter)
          StringBuilder exportUrl = UrlUtils.getCurrentUri(tableConfiguration.getRequest());
          UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "f");
          UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_FORMAT, enabledFormat);
          UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ID, tableConfiguration.getTableId());
          UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_IN_PROGRESS, "y");
          UrlUtils.addParameter(exportUrl, WebConstants.DANDELION_ASSET_FILTER_STATE, false);
         
          exportConf = new ExportConf(enabledFormat, UrlUtils.getProcessedUrl(exportUrl, tableConfiguration.getRequest(), tableConfiguration.getResponse()));
         
          tableConfiguration.getExportConfiguration().put(enabledFormat, exportConf);
        }
      }
View Full Code Here

  @Test
  public void shoud_handle_filter_export() {
   
    exportFeature = new ExportFeature();
   
    ExportConf exportConf = new ExportConf("csv");
    exportConf.setUrl("/myExportUrl");
    exportConf.setLabel("CSV");
    table.getTableConfiguration().getExportConfiguration().put("csv", exportConf);
    extensionProcessor.process(new HashSet<Extension>(Arrays.asList(exportFeature)));

    assertThat(exportFeature.getBeforeAll()).isNull();
    assertThat(AssetRequestContext.get(table.getTableConfiguration().getRequest()).getBundles(true)).isEmpty();
View Full Code Here

  @Test
  public void shoud_handle_controller_export_with_GET_and_no_extra_param() {
   
    exportFeature = new ExportFeature();
   
    ExportConf exportConf = new ExportConf("csv");
    exportConf.setHasCustomUrl(true);
    exportConf.setUrl("/myExportUrl");
    exportConf.setLabel("CSV");
    table.getTableConfiguration().getExportConfiguration().put("csv", exportConf);
    extensionProcessor.process(new HashSet<Extension>(Arrays.asList(exportFeature)));
   
    assertThat(AssetRequestContext.get(table.getTableConfiguration().getRequest()).getBundles(true)).isEmpty();
    assertThat(exportFeature.getBeforeAll().toString()).isEqualTo("function ddl_dt_launch_export_fakeId_csv(){\n   window.location=\"/myExportUrl?\" + decodeURIComponent($.param(oTable_fakeId.oApi._fnAjaxParameters(oTable_fakeId.fnSettings())).replace(/\\+/g,' '));\n}\n");
View Full Code Here

TOP

Related Classes of com.github.dandelion.datatables.core.export.ExportConf$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.