├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ ├── checkBuild.yml │ ├── release.yml │ ├── test-deploy.yml │ └── update-from-template.yml ├── .gitignore ├── .idea ├── checkstyle-idea.xml ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── inspectionProfiles │ └── Project_Default.xml └── saveactions_settings.xml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── config └── checkstyle │ └── checkstyle.xml ├── pom.xml └── src └── main ├── java └── xdev │ ├── BISuite.java │ ├── reports │ └── jasper │ │ ├── AbstractReportStub.java │ │ ├── AbstractVirtualTableDataSource.java │ │ ├── FieldMappingKey.java │ │ ├── JRDataSourceMapper.java │ │ ├── JRDataSourceMappingContainer.java │ │ ├── JRJTableRendererDataSource.java │ │ ├── JRMappedField.java │ │ ├── JRRewindableDataSourceMapper.java │ │ ├── JRVirtualTableDataSource.java │ │ ├── JRVirtualTableFormattedDataSource.java │ │ ├── JasperReportUtils.java │ │ ├── Parameter.java │ │ ├── Report.java │ │ ├── ReportBuilder.java │ │ ├── ReportException.java │ │ ├── ReportStub.java │ │ └── cmd │ │ └── ReportCreation.java │ └── tableexport │ ├── Export.java │ ├── JRVirtualTableDataSource.java │ ├── cmd │ ├── DataType.java │ ├── ExportCreation.java │ └── TableExportDebugger.java │ ├── config │ ├── AbstractColumn.java │ ├── Column.java │ ├── ColumnAlignment.java │ ├── ColumnBorder.java │ ├── ColumnPadding.java │ ├── ColumnStyle.java │ ├── ContentColumn.java │ ├── DefaultColumnStyle.java │ ├── DefaultPageProperties.java │ ├── EmptyColumnBorder.java │ ├── HeaderColumn.java │ ├── LineStyle.java │ ├── PageProperties.java │ ├── TemplateColumn.java │ ├── TemplateConfig.java │ └── builder │ │ ├── DefaultJTableConfigBuilder.java │ │ ├── ExportConfigBuilder.java │ │ ├── JTableViewConfigBuilder.java │ │ ├── VTConfigBuilder.java │ │ └── XdevTableConfigBuilder.java │ ├── datasource │ ├── DefaultBooleanToStringConverter.java │ ├── ValueConverter.java │ ├── XdevJTableRendererDataSource.java │ └── XdevTableDataSource.java │ ├── export │ ├── ExportException.java │ ├── ReportBuilder.java │ ├── ReportExporter.java │ └── writer │ │ ├── CSVToFileWriter.java │ │ ├── CSVToOutputStreamWriter.java │ │ ├── ExportWriter.java │ │ ├── ExportWriterException.java │ │ ├── HtmlToFileWriter.java │ │ ├── HtmlToOutputStreamWriter.java │ │ ├── PdfToFileWriter.java │ │ ├── PdfToOutputStreamWriter.java │ │ ├── PrintWriter.java │ │ ├── ReportToPreviewWriter.java │ │ ├── RtfToFileWriter.java │ │ ├── RtfToOutputStreamWriter.java │ │ ├── XMLToFileWriter.java │ │ ├── XMLToOutputStreamWriter.java │ │ ├── XlsToFileWriter.java │ │ ├── XlsToOutputStreamWriter.java │ │ ├── XlsxToFileWriter.java │ │ └── XlsxToOutputStreamWriter.java │ └── utils │ ├── DataSourceResourceBundle.java │ ├── ExportUtils.java │ ├── NullPatternConverter.java │ ├── PatternConverter.java │ └── VirtualTableColumnPatternConverter.java └── resources └── xdev ├── lic └── pj.properties └── tableexport └── utils ├── xdevdatasource.properties └── xdevdatasource_en.properties /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | # Run it at a specific time so that we don't get emails all day long 8 | time: "00:00" 9 | open-pull-requests-limit: 10 10 | ignore: 11 | - dependency-name: "*" 12 | # GitHub actions are using git tags (v1 = v1.2 = v1.2.3) which should be compatible until a major change is performed 13 | update-types: 14 | - "version-update:semver-minor" 15 | - "version-update:semver-patch" 16 | - package-ecosystem: maven 17 | directory: "/" 18 | schedule: 19 | interval: daily 20 | # Run it at a specific time so that we don't get emails all day long 21 | time: "00:00" 22 | open-pull-requests-limit: 10 23 | -------------------------------------------------------------------------------- /.github/workflows/checkBuild.yml: -------------------------------------------------------------------------------- 1 | name: Check Build 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ develop ] 7 | paths-ignore: 8 | - '**.md' 9 | pull_request: 10 | branches: [ develop ] 11 | paths-ignore: 12 | - '**.md' 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | 18 | strategy: 19 | matrix: 20 | java: [8, 11, 17, 21] 21 | java-package: [jdk] 22 | distribution: [temurin] 23 | 24 | steps: 25 | - uses: actions/checkout@v4 26 | 27 | - name: Set up JDK 28 | uses: actions/setup-java@v4 29 | with: 30 | distribution: ${{ matrix.distribution }} 31 | java-version: ${{ matrix.java }} 32 | java-package: ${{ matrix.java-package }} 33 | cache: 'maven' 34 | 35 | - name: Build with Maven 36 | run: mvn -B clean verify 37 | 38 | - name: Check for uncommited changes 39 | run: | 40 | if [[ "$(git status --porcelain)" != "" ]]; then 41 | echo ---------------------------------------- 42 | echo git status 43 | echo ---------------------------------------- 44 | git status 45 | echo ---------------------------------------- 46 | echo git diff 47 | echo ---------------------------------------- 48 | git diff 49 | echo ---------------------------------------- 50 | echo Troubleshooting 51 | echo ---------------------------------------- 52 | echo "::error::Unstaged changes detected. Locally try running: git clean -ffdx && mvn -B clean verify" 53 | exit 1 54 | fi 55 | 56 | - uses: actions/upload-artifact@v3 57 | with: 58 | name: jars-java-${{ matrix.java }} 59 | path: target/*.jar 60 | if-no-files-found: error 61 | -------------------------------------------------------------------------------- /.github/workflows/test-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Test Deployment CI 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | publish_central: # Publish the code to central 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | 12 | - name: Set up JDK OSSRH 13 | uses: actions/setup-java@v4 14 | with: # running setup-java again overwrites the settings.xml 15 | distribution: 'temurin' 16 | java-version: '8' 17 | server-id: ossrh 18 | server-username: MAVEN_CENTRAL_USERNAME 19 | server-password: MAVEN_CENTRAL_TOKEN 20 | gpg-passphrase: MAVEN_GPG_PASSPHRASE 21 | gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} 22 | 23 | - name: Publish to OSSRH 24 | run: mvn -B deploy -Possrh 25 | env: 26 | MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} 27 | MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }} 28 | MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} 29 | -------------------------------------------------------------------------------- /.github/workflows/update-from-template.yml: -------------------------------------------------------------------------------- 1 | name: Update from Template 2 | 3 | # This workflow keeps the repo up to date with changes from the template repo (REMOTE_URL) 4 | # It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into the 5 | # this repos default branch (which is checked out here) 6 | # Note that this requires a PAT (Personal Access Token) - at best from a servicing account 7 | # Also note that you should have at least once merged the template repo into the current repo manually 8 | # otherwise a "refusing to merge unrelated histories" error might occur. 9 | 10 | on: 11 | schedule: 12 | - cron: '55 2 * * 1' 13 | workflow_dispatch: 14 | 15 | env: 16 | UPDATE_BRANCH: update-from-template 17 | REMOTE_URL: https://github.com/xdev-software/xdev-swing-framework-template.git 18 | REMOTE_BRANCH: master 19 | 20 | permissions: 21 | contents: write 22 | pull-requests: write 23 | 24 | jobs: 25 | update: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - uses: actions/checkout@v4 30 | with: 31 | # Required because otherwise there are always changes detected when executing diff/rev-list 32 | fetch-depth: 0 33 | # If no PAT is used the following error occurs on a push: 34 | # refusing to allow a GitHub App to create or update workflow `.github/workflows/xxx.yml` without `workflows` permission 35 | token: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }} 36 | 37 | - name: Init Git 38 | run: | 39 | git config --global user.email "actions@github.com" 40 | git config --global user.name "GitHub Actions" 41 | 42 | - name: Main workflow 43 | id: main 44 | run: | 45 | echo "Adding remote template-repo" 46 | git remote add template ${{ env.REMOTE_URL }} 47 | 48 | echo "Fetching remote template repo" 49 | git fetch template 50 | 51 | echo "Deleting local branch that will contain the updates - if present" 52 | git branch -D ${{ env.UPDATE_BRANCH }} || true 53 | 54 | echo "Checking if the remote template repo has new commits" 55 | git rev-list ..template/${{ env.REMOTE_BRANCH }} 56 | 57 | if [ $(git rev-list --count ..template/${{ env.REMOTE_BRANCH }}) -eq 0 ]; then 58 | echo "There are no commits new commits on the template repo" 59 | 60 | echo "Deleting origin branch that contains the updates - if present" 61 | git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true 62 | 63 | echo "abort=1" >> $GITHUB_OUTPUT 64 | exit 0 65 | fi 66 | 67 | echo "Found new commits on the template repo" 68 | 69 | echo "Creating update branch" 70 | git branch ${{ env.UPDATE_BRANCH }} template/${{ env.REMOTE_BRANCH }} 71 | git branch --unset-upstream ${{ env.UPDATE_BRANCH }} 72 | 73 | echo "Pushing update branch" 74 | git push -f -u origin ${{ env.UPDATE_BRANCH }} 75 | 76 | echo "Getting current branch" 77 | current_branch=$(git branch --show-current) 78 | echo "Current branch is $current_branch" 79 | echo "current_branch=$current_branch" >> $GITHUB_OUTPUT 80 | 81 | echo "abort=0" >> $GITHUB_OUTPUT 82 | 83 | - name: pull-request 84 | if: steps.main.outputs.abort == 0 85 | env: 86 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 87 | run: | 88 | gh_pr_up() { 89 | gh pr create -H "${{ env.UPDATE_BRANCH }}" "$@" || (git checkout "${{ env.UPDATE_BRANCH }}" && gh pr edit "$@") 90 | } 91 | gh_pr_up -B "${{ steps.main.outputs.current_branch }}" \ 92 | --title "Update from template" \ 93 | --body "An automated PR to sync changes from the template into this repo" 94 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | dependency-reduced-pom.xml 9 | buildNumber.properties 10 | .mvn/timing.properties 11 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 12 | .mvn/wrapper/maven-wrapper.jar 13 | 14 | 15 | # Compiled class file 16 | *.class 17 | 18 | # Log file 19 | *.log 20 | 21 | # BlueJ files 22 | *.ctxt 23 | 24 | # Mobile Tools for Java (J2ME) 25 | .mtj.tmp/ 26 | 27 | # Package/Binary Files don't belong into a git repo 28 | *.jar 29 | *.war 30 | *.nar 31 | *.ear 32 | *.zip 33 | *.tar.gz 34 | *.rar 35 | *.dll 36 | *.exe 37 | *.bin 38 | 39 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 40 | hs_err_pid* 41 | 42 | 43 | # bin / compiled stuff 44 | target/ 45 | 46 | 47 | # JRebel 48 | **/resources/rebel.xml 49 | **/resources/rebel-remote.xml 50 | 51 | # eclispe stuff for root 52 | /.settings/ 53 | /.classpath 54 | /.project 55 | 56 | 57 | # eclispe stuff for modules 58 | /*/.metadata/ 59 | /*/.apt_generated_tests/ 60 | /*/.settings/ 61 | /*/.classpath 62 | /*/.project 63 | /*/RemoteSystemsTempFiles/ 64 | 65 | #custom 66 | .flattened-pom.xml 67 | .tern-project 68 | 69 | # == IntelliJ == 70 | *.iml 71 | *.ipr 72 | 73 | # Some files are user/installation independent and are used for configuring the IDE 74 | # See also https://stackoverflow.com/a/35279076 75 | 76 | .idea/* 77 | !.idea/saveactions_settings.xml 78 | !.idea/checkstyle-idea.xml 79 | 80 | !.idea/inspectionProfiles/ 81 | .idea/inspectionProfiles/* 82 | !.idea/inspectionProfiles/Project_Default.xml 83 | 84 | !.idea/codeStyles/ 85 | .idea/codeStyles/* 86 | !.idea/codeStyles/codeStyleConfig.xml 87 | !.idea/codeStyles/Project.xml 88 | -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10.1 5 | JavaOnlyWithTests 6 | true 7 | true 8 | 12 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 92 | 93 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/saveactions_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 6.0.1 2 | * Updated xapi to ``6.0.1`` 3 | * Updated jasperreports to ``6.18.1`` 4 | * Updated maven plugins 5 | 6 | ## 6.0.0 7 | * Ensured build compatibility with Java 8, 11 and 17 8 | * Minor code improvements, mostly for tests 9 | * Updated some maven plugins 10 | 11 | *NOTE: ``biapi-commercial`` is now a part of the [``csapi``](https://github.com/xdev-software/csapi) and open-source* 12 | 13 | ### Complete overview about the new XDEV (IDE) Framework in version 6 14 | ![XDEV-IDE-Framework-6 overview](https://user-images.githubusercontent.com/45384811/134640194-0b42a238-3c7e-402a-8b05-51419108dbbd.png) 15 | 16 | ## 5.0.3+ 17 | Before version 5.0.3, BIAPI was distributed as commercial software. 18 | 19 | To provide this framework as open-source, we split it into two parts: the open-source part you see here and the commercial part, which requires a license. 20 | If you want to use the commercial BIAPI with third-party dependencies, please contact us at info@xdev-software.de 21 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | We would absolutely love to get the community involved, and we welcome any form of contributions – comments and questions on different communication channels, issues and pull request and anything that you build and share using our components. 4 | 5 | ### Communication channels 6 | * Communication is primarily done using issues. 7 | * If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support). 8 | * As a last resort measure or on otherwise important matter you may also [contact us directly](https://xdev.software/en/about-us/contact). 9 | 10 | ### Ways to help 11 | * **Report bugs**
Create an issue or send a pull request 12 | * **Send pull requests**
If you want to contribute code, check out the development instructions below. 13 | * However when contributing new features, please first discuss the change you wish to make via issue with the owners of this repository before making a change. Otherwise your work might be rejected and your effort was pointless. 14 | 15 | We also encourage you to read the [contribution instructions by GitHub](https://docs.github.com/en/get-started/quickstart/contributing-to-projects). 16 | 17 | ## Developing 18 | 19 | ### Software Requirements 20 | You should have the following things installed: 21 | * Git 22 | * Java 8, 11 or 17 - should be as unmodified as possible (Recommended: [Eclipse Adoptium](https://adoptium.net/temurin/releases/)) 23 | * Maven 24 | 25 | ### Recommended setup 26 | * Install ``IntelliJ`` (Community Edition is sufficient) 27 | * Install the following plugins: 28 | * [Save Actions](https://plugins.jetbrains.com/plugin/22113) - Provides save actions, like running the formatter or adding ``final`` to fields 29 | * [SonarLint](https://plugins.jetbrains.com/plugin/7973-sonarlint) - CodeStyle/CodeAnalysis 30 | * [Checkstyle-IDEA](https://plugins.jetbrains.com/plugin/1065-checkstyle-idea) - CodeStyle/CodeAnalysis 31 | * Import the project 32 | * Ensure that everything is encoded in ``UTF-8`` 33 | * Ensure that the JDK/Java-Version is correct 34 | 35 | ## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/biapi/release.yml?branch=master)](https://github.com/xdev-software/biapi/actions/workflows/release.yml) 36 | 37 | Before releasing: 38 | * Consider doing a [test-deployment](https://github.com/xdev-software/biapi/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing. 39 | * Check the [changelog](CHANGELOG.md) 40 | 41 | If the ``develop`` is ready for release, create a pull request to the ``master``-Branch and merge the changes. 42 | 43 | When the release is finished do the following: 44 | * Merge the auto-generated PR (with the incremented version number) back into the ``develop`` 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Latest version](https://img.shields.io/maven-central/v/com.xdev-software/biapi)](https://mvnrepository.com/artifact/com.xdev-software/biapi) 2 | [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/biapi/checkBuild.yml?branch=develop)](https://github.com/xdev-software/biapi/actions/workflows/checkBuild.yml?query=branch%3Adevelop) 3 | [![javadoc](https://javadoc.io/badge2/com.xdev-software/biapi/javadoc.svg)](https://javadoc.io/doc/com.xdev-software/biapi) 4 | # XDEV BI Suite (BIAPI) 5 | 6 | Java Swing provides a significant set of controls for developing graphical user interfaces (GUI), for example, buttons, labels, tabs, all formular-controls, table, tree and techniques about windowing / scenes. Many standard applications can easily be created with that. If you need innovative business applications and want to delight your users, you obviously need more. 7 | 8 | The XDEV **B**usiness **I**nteligence Suite provides you ultimate power features, which extremely upgrades your application and makes it multiple times more capable and comfortable. Extend your solutions with features your users only dream about yet. Best of all - the integrations is amazingly easy! 9 | 10 | ## XDEV-IDE 11 | The [XDEV(-IDE)](https://xdev.software/en/products/swing-builder) is a visual Java development environment for fast and easy application development (RAD - Rapid Application Development). XDEV differs from other Java IDEs such as Eclipse or NetBeans, focusing on programming through a far-reaching RAD concept. The IDE's main components are a Swing GUI builder, the XDEV Application Framework and numerous drag-and-drop tools and wizards with which the functions of the framework can be integrated. 12 | 13 | The XDEV-IDE was license-free up to version 4 inclusive and is available for Windows, Linux and macOS. From version 5, the previously proprietary licensed additional modules are included in the IDE and the license of the entire product has been converted to a paid subscription model. The XDEV Application Framework, which represents the core of the RAD concept of XDEV and is part of every XDEV application, was released as open-source in 2008. 14 | 15 | ## Support 16 | If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support). 17 | 18 | ## Contributing 19 | See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project. 20 | 21 | ## Dependencies and Licenses 22 | View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/biapi/dependencies/) 23 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/biapi/security/advisories/new). 6 | -------------------------------------------------------------------------------- /src/main/java/xdev/BISuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev; 19 | 20 | import java.util.Map; 21 | 22 | /** 23 | *

A {@link Extension} implementation which initialize needed classes for BI Suite.

24 | * 25 | * @author XDEV Software 26 | * @deprecated Will no longer be maintained and removed in the future 27 | */ 28 | @Deprecated 29 | public class BISuite implements Extension 30 | { 31 | /** 32 | * Current version of the bi suite. 33 | */ 34 | public final static Version VERSION = new Version(6,0,0,0); 35 | 36 | /** 37 | * X-API version required for the current version of the bi suite. 38 | */ 39 | private final static Version REQUIRED_XAPI_VERSION = new Version(5,0,0,0); 40 | 41 | public BISuite() 42 | { 43 | 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | @Override 50 | public void init(final Map args) throws ExtensionInitializationException 51 | { 52 | // Version check 53 | if(xdev.API.VERSION.isOlderThan(REQUIRED_XAPI_VERSION)) 54 | { 55 | throw new ExtensionInitializationException("XAPI Version " 56 | + REQUIRED_XAPI_VERSION.toScreen() + " or newer is required for the " 57 | + toString() + ", current version: " + xdev.API.VERSION.toScreen()); 58 | } 59 | 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | public String getName() 67 | { 68 | return "XDEV BI Suite"; 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | public Version getVersion() 76 | { 77 | return VERSION; 78 | } 79 | 80 | /** 81 | * {@inheritDoc} 82 | */ 83 | @Override 84 | public String toString() 85 | { 86 | return getName() + " " + getVersion().toScreen(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/AbstractReportStub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import java.io.File; 21 | import java.io.FileNotFoundException; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.util.ArrayList; 25 | import java.util.HashMap; 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | import net.sf.jasperreports.engine.JRDataSource; 30 | import net.sf.jasperreports.engine.JRException; 31 | import net.sf.jasperreports.engine.JasperReport; 32 | import net.sf.jasperreports.engine.util.JRLoader; 33 | import xdev.io.IOUtils; 34 | 35 | 36 | public abstract class AbstractReportStub implements ReportStub 37 | { 38 | private JRDataSource dataSource = null; 39 | private String jasperFilePath; 40 | private List subreports = new ArrayList(); 41 | 42 | 43 | @Override 44 | public void setDataSource(JRDataSource dataSource) 45 | { 46 | this.dataSource = dataSource; 47 | } 48 | 49 | 50 | @Override 51 | public JRDataSource getDataSource() 52 | { 53 | return dataSource; 54 | } 55 | 56 | 57 | public void setJasperFilePath(String jasperFilePath) 58 | { 59 | this.jasperFilePath = jasperFilePath; 60 | } 61 | 62 | 63 | @Override 64 | public String getJasperFilePath() 65 | { 66 | return jasperFilePath; 67 | } 68 | 69 | 70 | public void addSubreport(ReportStub subreport) 71 | { 72 | subreports.add(subreport); 73 | } 74 | 75 | 76 | @Override 77 | public JasperReport getReportTemplate() throws JRException 78 | { 79 | try 80 | { 81 | // try to find report file with xdev api 82 | final InputStream inputStream = IOUtils.findResource(jasperFilePath); 83 | return (JasperReport)JRLoader.loadObject(inputStream); 84 | } 85 | catch(FileNotFoundException e) 86 | { 87 | // fallback try to find report file with jasper api 88 | return (JasperReport)JRLoader.loadObject(new File(jasperFilePath)); 89 | } 90 | catch(IOException e) 91 | { 92 | throw new JRException(e); 93 | } 94 | } 95 | 96 | 97 | @Override 98 | public Map getParameters() 99 | { 100 | Map parameters = new HashMap() 101 | { 102 | @Override 103 | public Object put(String key, Object value) 104 | { 105 | if(value != null) 106 | { 107 | return super.put(key,value); 108 | } 109 | return null; 110 | } 111 | }; 112 | 113 | for(ReportStub subreport : this.subreports) 114 | { 115 | parameters.putAll(subreport.getParameters()); 116 | } 117 | 118 | collectParameters(parameters); 119 | 120 | return parameters; 121 | } 122 | 123 | 124 | protected abstract void collectParameters(Map map); 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/AbstractVirtualTableDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | 23 | import net.sf.jasperreports.engine.JRException; 24 | import net.sf.jasperreports.engine.JRField; 25 | import net.sf.jasperreports.engine.JRRewindableDataSource; 26 | import xdev.db.DBException; 27 | import xdev.lang.NotNull; 28 | import xdev.vt.VirtualTable; 29 | import xdev.vt.XdevBlob; 30 | 31 | 32 | /** 33 | * This class provides a skeletal implementation of the 34 | * {@link JRRewindableDataSource} interface backed by a {@link VirtualTable}. 35 | *

36 | * The developer only needs to subclass this abstract class and define the 37 | * getFieldValue method. 38 | *

39 | * 40 | * @author XDEV Software 41 | * 42 | */ 43 | public abstract class AbstractVirtualTableDataSource implements JRRewindableDataSource 44 | { 45 | 46 | /** 47 | * The VirtualTable instance to be wrapped. 48 | */ 49 | protected final VirtualTable virtualTable; 50 | /** 51 | * The current row index. Initialized to -1 as first row is retrieved by the 52 | * first next() call. 53 | */ 54 | protected int currentRowIndex = -1; 55 | 56 | 57 | /** 58 | * Straight forward constructor to wrap a given (non-null) 59 | * {@link VirtualTable}. 60 | * 61 | * @param virtualTable 62 | * the {@link VirtualTable} to wrap 63 | */ 64 | public AbstractVirtualTableDataSource(@NotNull final VirtualTable virtualTable) 65 | { 66 | super(); 67 | if(virtualTable == null) 68 | { 69 | throw new IllegalArgumentException("virtualTable must not be null"); 70 | } 71 | this.virtualTable = virtualTable; 72 | } 73 | 74 | 75 | /** 76 | * Moves the internal row cursor to the next row. 77 | * 78 | * @return if the internal row cursor points to an existing row 79 | * @throws JRException 80 | * can never happen 81 | */ 82 | @Override 83 | public boolean next() throws JRException 84 | { 85 | return ++this.currentRowIndex < this.virtualTable.getRowCount(); 86 | } 87 | 88 | 89 | /** 90 | * {@inheritDoc} 91 | */ 92 | @Override 93 | public void moveFirst() throws JRException 94 | { 95 | this.currentRowIndex = -1; 96 | } 97 | 98 | 99 | /** 100 | * Retrieves a binary value for column jrField in the current 101 | * row. Lookup is done by field name (column name). 102 | * 103 | * @param jrField 104 | * the {@link JRField} instance defining (by name) the column of 105 | * the {@link VirtualTable} whose value shall be retrieved. 106 | * @return the binary value in the wrapped {@link VirtualTable} instance 107 | * from current row, column jrField 108 | * 109 | * @throws DBException 110 | * if the column (specified by jrField.getName()) 111 | * could not be found or accessed 112 | * @throws IOException 113 | * if the column (specified by jrField.getName()) 114 | * could not be found or accessed 115 | */ 116 | protected Object getBinaryFieldValue(@NotNull final JRField jrField) throws DBException, 117 | IOException 118 | { 119 | XdevBlob blob = (XdevBlob)this.virtualTable.getValueAt(this.currentRowIndex, 120 | jrField.getName()); 121 | InputStream is; 122 | if(blob != null) 123 | { 124 | is = blob.getBinaryStream(); 125 | } 126 | else 127 | { 128 | is = null; 129 | } 130 | 131 | return is; 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/FieldMappingKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | public interface FieldMappingKey 21 | { 22 | public String getName(); 23 | 24 | 25 | public Class getType(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/JRDataSourceMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import java.util.Map; 21 | 22 | import net.sf.jasperreports.engine.JRDataSource; 23 | import net.sf.jasperreports.engine.JRException; 24 | import net.sf.jasperreports.engine.JRField; 25 | import xdev.lang.NotNull; 26 | 27 | 28 | public class JRDataSourceMapper implements JRDataSource 29 | { 30 | 31 | private final JRDataSource wrappedDataSource; 32 | private final Map fieldMapping; 33 | 34 | 35 | public JRDataSourceMapper(final JRDataSource dataSource, final Map fieldMapping) 36 | { 37 | this.wrappedDataSource = dataSource; 38 | this.fieldMapping = fieldMapping; 39 | } 40 | 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | @Override 46 | public boolean next() throws JRException 47 | { 48 | return this.wrappedDataSource.next(); 49 | } 50 | 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | 56 | @Override 57 | public Object getFieldValue(@NotNull final JRField jrField) throws JRException 58 | { 59 | final String mappedName = this.fieldMapping.get(jrField.getName()); 60 | 61 | JRField field = jrField; 62 | if(mappedName != null) 63 | { 64 | field = new JRMappedField(jrField,mappedName,jrField.getPropertyExpressions()); 65 | } 66 | 67 | return this.wrappedDataSource.getFieldValue(field); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/JRDataSourceMappingContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import net.sf.jasperreports.engine.JRDataSource; 21 | 22 | /** 23 | * @author XDEV Software 24 | * 25 | */ 26 | public interface JRDataSourceMappingContainer 27 | { 28 | 29 | public void setDataSource(final JRDataSource dataSource); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/JRJTableRendererDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import java.awt.Component; 21 | 22 | import javax.swing.JLabel; 23 | import javax.swing.JTable; 24 | import javax.swing.table.TableCellRenderer; 25 | import javax.swing.table.TableColumn; 26 | 27 | import net.sf.jasperreports.engine.JRException; 28 | import net.sf.jasperreports.engine.JRField; 29 | import net.sf.jasperreports.engine.JRRewindableDataSource; 30 | import xdev.lang.NotNull; 31 | 32 | 33 | /** 34 | * 35 | * A data source implementation that allows to access the renderer output of a 36 | * {@link JTable}. 37 | * 38 | *

39 | * Waring: Works only for columns which are rendered by a 40 | * {@link TableCellRenderer} extending {@link JLabel}. 41 | *

42 | * 43 | * This data source does not consider a {@link TableCellRenderer} extending 44 | * {@link javax.swing.JCheckBox}. Use the XdevJTableRendererDataSource instead. 45 | * 46 | * @author XDEV Software 47 | * 48 | */ 49 | public class JRJTableRendererDataSource implements JRRewindableDataSource 50 | { 51 | 52 | /** 53 | * The {@link JTable} instance to be wrapped. 54 | */ 55 | protected final JTable table; 56 | /** 57 | * The current row index. Initialized to -1 as first row is retrieved by the 58 | * first next() call. 59 | */ 60 | protected int currentRowIndex = -1; 61 | 62 | 63 | /** 64 | * Straight forward constructor to wrap a given (non-null) {@link JTable}. 65 | * 66 | * @param table 67 | * the {@link JTable} to wrap 68 | */ 69 | public JRJTableRendererDataSource(@NotNull final JTable table) 70 | { 71 | 72 | if(table == null) 73 | { 74 | throw new IllegalArgumentException("table must not be null"); 75 | } 76 | this.table = table; 77 | } 78 | 79 | 80 | /** 81 | * Retrieves the value for column jrField in the current row. 82 | * Lookup is done by field name (column name). 83 | * 84 | * @param jrField 85 | * the {@link JRField} instance defining (by name) the column of 86 | * the {@link JTable} whose value shall be retrieved. 87 | * @return the value returned from the {@link TableCellRenderer} instance of 88 | * current row and column jrField 89 | * @throws JRException 90 | * if the column (specified by jrField.getName()) 91 | * could not be found or the value of the 92 | * {@link TableCellRenderer} could not be accessed 93 | */ 94 | @Override 95 | public Object getFieldValue(JRField jrField) throws JRException 96 | { 97 | int rowIndex = this.currentRowIndex; 98 | int columnIndex = this.getColumnIndex(this.table,jrField.getName()); 99 | 100 | return this.getRendererValue(this.table.getValueAt(rowIndex,columnIndex),rowIndex, 101 | columnIndex); 102 | 103 | } 104 | 105 | 106 | /** 107 | * Moves the internal row cursor to the next row. 108 | * 109 | * @return if the internal row cursor points to an existing row 110 | * @throws JRException 111 | * can never happen 112 | */ 113 | @Override 114 | public boolean next() throws JRException 115 | { 116 | return ++this.currentRowIndex < this.table.getRowCount(); 117 | } 118 | 119 | 120 | /** 121 | * {@inheritDoc} 122 | */ 123 | @Override 124 | public void moveFirst() throws JRException 125 | { 126 | this.currentRowIndex = -1; 127 | } 128 | 129 | 130 | /** 131 | * Returns the index for the given columnName. 132 | * 133 | * @param table 134 | * {@link JTable} 135 | * @param columnName 136 | * Name of the column to get the index for. 137 | * @return the index for the given columnName. 138 | */ 139 | protected int getColumnIndex(JTable table, String columnName) 140 | { 141 | return table.getColumnModel().getColumnIndex(columnName); 142 | } 143 | 144 | 145 | /** 146 | * Returns the name for the given {@link TableColumn}. 147 | * 148 | * @param column 149 | * {@link TableColumn} to get the name for 150 | * @return the name for the given {@link TableColumn}. 151 | */ 152 | protected String getTableColumnName(final TableColumn column) 153 | { 154 | return String.valueOf(column.getHeaderValue()); 155 | } 156 | 157 | 158 | /** 159 | * Returns the {@link TableCellRenderer} value for the described item. 160 | * 161 | * @param value 162 | * value to be processed by the renderer 163 | * @param row 164 | * rowIndex of the {@link TableCellRenderer} to use 165 | * @param col 166 | * columnIndex of the {@link TableCellRenderer} to use 167 | * @return the {@link TableCellRenderer} value for the described item. 168 | */ 169 | protected String getRendererValue(final Object value, final int row, final int col) 170 | { 171 | Component cpn = this.table.getCellRenderer(row,col).getTableCellRendererComponent( 172 | this.table,value,false,false,row,col); 173 | if(cpn instanceof JLabel) 174 | { 175 | return ((JLabel)cpn).getText(); 176 | } 177 | 178 | return ""; 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/JRMappedField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import net.sf.jasperreports.engine.JRField; 21 | import net.sf.jasperreports.engine.JRPropertiesHolder; 22 | import net.sf.jasperreports.engine.JRPropertiesMap; 23 | import net.sf.jasperreports.engine.JRPropertyExpression; 24 | 25 | 26 | public class JRMappedField implements JRField 27 | { 28 | 29 | private final String name; 30 | private final JRField wrappedField; 31 | private final JRPropertyExpression[] propertyExperession; 32 | 33 | 34 | public JRMappedField(final JRField jrField, final String name,final JRPropertyExpression[] propertyExperession) 35 | { 36 | this.name = name; 37 | this.wrappedField = jrField; 38 | this.propertyExperession = propertyExperession; 39 | } 40 | 41 | 42 | @Override 43 | public String getDescription() 44 | { 45 | return this.wrappedField.getDescription(); 46 | } 47 | 48 | 49 | @Override 50 | public String getName() 51 | { 52 | return this.name; 53 | } 54 | 55 | 56 | @Override 57 | public Class getValueClass() 58 | { 59 | return this.wrappedField.getValueClass(); 60 | } 61 | 62 | 63 | @Override 64 | public String getValueClassName() 65 | { 66 | return this.wrappedField.getValueClassName(); 67 | } 68 | 69 | 70 | @Override 71 | public void setDescription(final String arg0) 72 | { 73 | this.wrappedField.setDescription(arg0); 74 | } 75 | 76 | 77 | @Override 78 | public JRPropertiesHolder getParentProperties() 79 | { 80 | return this.wrappedField.getParentProperties(); 81 | } 82 | 83 | 84 | @Override 85 | public JRPropertiesMap getPropertiesMap() 86 | { 87 | return this.wrappedField.getPropertiesMap(); 88 | } 89 | 90 | 91 | @Override 92 | public boolean hasProperties() 93 | { 94 | return this.wrappedField.hasProperties(); 95 | } 96 | 97 | 98 | @Override 99 | public Object clone() 100 | { 101 | return this.wrappedField.clone(); 102 | } 103 | 104 | 105 | @Override 106 | public JRPropertyExpression[] getPropertyExpressions() 107 | { 108 | return this.propertyExperession; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/JRRewindableDataSourceMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import java.util.Map; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRRewindableDataSource; 24 | 25 | 26 | public class JRRewindableDataSourceMapper extends JRDataSourceMapper implements 27 | JRRewindableDataSource 28 | { 29 | 30 | private final JRRewindableDataSource wrappedDataSource; 31 | 32 | 33 | public JRRewindableDataSourceMapper(final JRRewindableDataSource dataSource, 34 | final Map fieldMapping) 35 | { 36 | super(dataSource,fieldMapping); 37 | this.wrappedDataSource = dataSource; 38 | } 39 | 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | @Override 45 | public void moveFirst() throws JRException 46 | { 47 | this.wrappedDataSource.moveFirst(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/JRVirtualTableDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import net.sf.jasperreports.engine.JRException; 21 | import net.sf.jasperreports.engine.JRField; 22 | import xdev.lang.NotNull; 23 | import xdev.vt.VirtualTable; 24 | import xdev.vt.VirtualTableColumn; 25 | import xdev.vt.XdevClob; 26 | 27 | 28 | /** 29 | * 30 | * {@link VirtualTable} data source implementation that allows to access the 31 | * data of a {@link VirtualTable}. 32 | * 33 | *

34 | * {@link JRVirtualTableDataSource} ignores the format settings of the 35 | * underlining {@link VirtualTable} and leaves the formating up to the report. 36 | *

37 | * 38 | *

39 | * If you want to use the format settings of the {@link VirtualTable} in your 40 | * report see {@link JRVirtualTableFormattedDataSource}. 41 | *

42 | * 43 | * @see JRVirtualTableFormattedDataSource 44 | * 45 | * @author XDEV Software 46 | * 47 | */ 48 | public class JRVirtualTableDataSource extends AbstractVirtualTableDataSource 49 | { 50 | 51 | /** 52 | * Straight forward constructor to wrap a given (non-null) 53 | * {@link VirtualTable}. 54 | * 55 | * @param virtualTable 56 | * the {@link VirtualTable} to wrap 57 | */ 58 | public JRVirtualTableDataSource(@NotNull final VirtualTable virtualTable) 59 | { 60 | super(virtualTable); 61 | } 62 | 63 | 64 | /** 65 | * Retrieves the value for column jrField in the current row. 66 | * Lookup is done by field name (column name). 67 | * 68 | * @param jrField 69 | * the {@link JRField} instance defining (by name) the column of 70 | * the {@link VirtualTable} whose value shall be retrieved. 71 | * @return the value in the wrapped {@link VirtualTable} instance from 72 | * current row, column jrField 73 | * @throws JRException 74 | * if the column (specified by jrField.getName()) 75 | * could not be found or accessed 76 | */ 77 | @Override 78 | public Object getFieldValue(@NotNull final JRField jrField) throws JRException 79 | { 80 | try 81 | { 82 | VirtualTableColumn column = this.virtualTable.getColumn(jrField.getName()); 83 | 84 | switch(column.getType()) 85 | { 86 | case BINARY: 87 | return this.getBinaryFieldValue(jrField); 88 | 89 | case LONGVARBINARY: 90 | return this.getBinaryFieldValue(jrField); 91 | 92 | case VARBINARY: 93 | return this.getBinaryFieldValue(jrField); 94 | 95 | case BLOB: 96 | return this.getBinaryFieldValue(jrField); 97 | 98 | case CLOB: 99 | return ((XdevClob)this.virtualTable.getValueAt(this.currentRowIndex, 100 | jrField.getName())).toJDBCClob(); 101 | 102 | default: 103 | return this.virtualTable.getValueAt(this.currentRowIndex,jrField.getName()); 104 | } 105 | 106 | } 107 | catch(Exception e) 108 | { 109 | throw new JRException("Unable to get value for field '" + jrField.getName(),e); 110 | } 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/JRVirtualTableFormattedDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import net.sf.jasperreports.engine.JRException; 21 | import net.sf.jasperreports.engine.JRField; 22 | import xdev.lang.NotNull; 23 | import xdev.vt.VirtualTable; 24 | import xdev.vt.VirtualTableColumn; 25 | import xdev.vt.VirtualTableException; 26 | import xdev.vt.XdevClob; 27 | 28 | 29 | /** 30 | * 31 | * {@link VirtualTable} data source implementation that allows to access the 32 | * formatted data of a {@link VirtualTable}. 33 | * 34 | *

35 | * {@link JRVirtualTableDataSource} uses the format settings of the underlining 36 | * {@link VirtualTable}. 37 | *

38 | * 39 | *

40 | * If you don't want to use the format settings of the {@link VirtualTable} in 41 | * your report see {@link JRVirtualTableFormattedDataSource}. 42 | *

43 | * 44 | * 45 | * @author XDEV Software 46 | * 47 | */ 48 | public class JRVirtualTableFormattedDataSource extends AbstractVirtualTableDataSource 49 | { 50 | 51 | /** 52 | * Straight forward constructor to wrap a given (non-null) 53 | * {@link VirtualTable}. 54 | * 55 | * @param virtualTable 56 | * the {@link VirtualTable} to wrap 57 | */ 58 | public JRVirtualTableFormattedDataSource(@NotNull final VirtualTable virtualTable) 59 | { 60 | super(virtualTable); 61 | } 62 | 63 | 64 | /** 65 | * Retrieves the formatted value for column jrField in the 66 | * current row. Lookup is done by field name (column name). 67 | * 68 | * @param jrField 69 | * the {@link JRField} instance defining (by name) the column of 70 | * the {@link VirtualTableException} whose formatted value shall 71 | * be retrieved. 72 | * @return the formatted value in the wrapped {@link VirtualTable} instance 73 | * from current row, column jrField 74 | * @throws JRException 75 | * if the column (specified by jrField.getName()) 76 | * could not be found or accessed 77 | */ 78 | @Override 79 | public Object getFieldValue(@NotNull final JRField jrField) throws JRException 80 | { 81 | try 82 | { 83 | VirtualTableColumn column = this.virtualTable.getColumn(jrField.getName()); 84 | 85 | switch(column.getType()) 86 | { 87 | case BINARY: 88 | return this.getBinaryFieldValue(jrField); 89 | 90 | case LONGVARBINARY: 91 | return this.getBinaryFieldValue(jrField); 92 | 93 | case VARBINARY: 94 | return this.getBinaryFieldValue(jrField); 95 | 96 | case BLOB: 97 | return this.getBinaryFieldValue(jrField); 98 | 99 | case CLOB: 100 | return ((XdevClob)this.virtualTable.getValueAt(this.currentRowIndex, 101 | jrField.getName())).toJDBCClob(); 102 | 103 | default: 104 | return this.virtualTable.getFormattedValueAt(this.currentRowIndex, 105 | jrField.getName()); 106 | } 107 | 108 | } 109 | catch(Exception e) 110 | { 111 | throw new JRException("Unable to get value for field '" + jrField.getName(),e); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/JasperReportUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import java.io.File; 21 | import java.io.FileNotFoundException; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.util.Map; 25 | 26 | import net.sf.jasperreports.engine.JRDataSource; 27 | import net.sf.jasperreports.engine.JRException; 28 | import net.sf.jasperreports.engine.JRRewindableDataSource; 29 | import net.sf.jasperreports.engine.JasperReport; 30 | import net.sf.jasperreports.engine.util.JRLoader; 31 | import xdev.io.IOUtils; 32 | 33 | 34 | public class JasperReportUtils 35 | { 36 | 37 | public static JasperReport loadReport(final File reportTemplate) throws JRException 38 | { 39 | JasperReport loadedReport = null; 40 | 41 | try 42 | { 43 | // try to find report file with xdev api 44 | final InputStream inputStream = IOUtils.findResource(reportTemplate.getAbsolutePath()); 45 | loadedReport = (JasperReport)JRLoader.loadObject(inputStream); 46 | } 47 | catch(FileNotFoundException e) 48 | { 49 | // fallback try to find report file with jasper api 50 | loadedReport = (JasperReport)JRLoader.loadObject(reportTemplate); 51 | } 52 | catch(IOException e) 53 | { 54 | throw new JRException(e); 55 | } 56 | 57 | return loadedReport; 58 | } 59 | 60 | 61 | public static JRDataSource createMappedDataSource(final JRDataSource dataSource, 62 | final Map fieldMapping) 63 | { 64 | if(dataSource instanceof JRRewindableDataSource) 65 | { 66 | return new JRRewindableDataSourceMapper((JRRewindableDataSource)dataSource,fieldMapping); 67 | } 68 | else 69 | { 70 | return new JRDataSourceMapper(dataSource,fieldMapping); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | 26 | /** 27 | * Marker annotation for report parameter setters 28 | * 29 | * @author XDEV Software 30 | * 31 | */ 32 | @Target(ElementType.METHOD) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | public @interface Parameter 35 | { 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/Report.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import xdev.lang.LibraryMember; 21 | import xdev.reports.jasper.cmd.ReportCreation; 22 | 23 | 24 | @LibraryMember 25 | public final class Report 26 | { 27 | /** 28 | * No instanciation. 29 | */ 30 | private Report() 31 | { 32 | } 33 | 34 | 35 | /** 36 | * Creates a report and shows it on the screen or sends it to the printer. 37 | * 38 | * @param data 39 | * The {@link ReportCreation} containing the report content 40 | */ 41 | public static void Create(ReportCreation data) throws ReportException 42 | { 43 | data.init(); 44 | data.execute(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/ReportException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | public class ReportException extends Exception 21 | { 22 | public ReportException() 23 | { 24 | super(); 25 | } 26 | 27 | 28 | public ReportException(String message, Throwable cause) 29 | { 30 | super(message,cause); 31 | } 32 | 33 | 34 | public ReportException(String message) 35 | { 36 | super(message); 37 | } 38 | 39 | 40 | public ReportException(Throwable cause) 41 | { 42 | super(cause); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/xdev/reports/jasper/ReportStub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.reports.jasper; 19 | 20 | import java.util.Map; 21 | 22 | import net.sf.jasperreports.engine.JRDataSource; 23 | import net.sf.jasperreports.engine.JRException; 24 | import net.sf.jasperreports.engine.JasperReport; 25 | 26 | 27 | public interface ReportStub 28 | { 29 | public String getJasperFilePath(); 30 | 31 | 32 | /** 33 | * 34 | * @return a COPY of the parameters 35 | */ 36 | public Map getParameters(); 37 | 38 | 39 | public void setDataSource(JRDataSource dataSource); 40 | 41 | 42 | public JRDataSource getDataSource(); 43 | 44 | 45 | public JasperReport getReportTemplate() throws JRException; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/Export.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport; 19 | import xdev.lang.LibraryMember; 20 | import xdev.tableexport.cmd.ExportCreation; 21 | import xdev.tableexport.export.ExportException; 22 | 23 | 24 | @LibraryMember 25 | public class Export 26 | { 27 | /** 28 | * No instanciation. 29 | */ 30 | private Export() 31 | { 32 | } 33 | 34 | 35 | /** 36 | * Creates a report and shows it on the screen or sends it to the printer. 37 | * 38 | * @param data 39 | * The {@link ExportCreation} containing the report content 40 | */ 41 | public static void Create(ExportCreation data) throws ExportException 42 | { 43 | data.init(); 44 | data.execute(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/JRVirtualTableDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport; 19 | 20 | import net.sf.jasperreports.engine.JRException; 21 | import net.sf.jasperreports.engine.JRField; 22 | import xdev.lang.NotNull; 23 | import xdev.reports.jasper.AbstractVirtualTableDataSource; 24 | import xdev.reports.jasper.JRVirtualTableFormattedDataSource; 25 | import xdev.vt.VirtualTable; 26 | import xdev.vt.VirtualTableColumn; 27 | import xdev.vt.XdevClob; 28 | 29 | 30 | /** 31 | * 32 | * {@link VirtualTable} data source implementation that allows to access the 33 | * data of a {@link VirtualTable}. 34 | * 35 | *

36 | * {@link JRVirtualTableDataSource} ignores the format settings of the 37 | * underlining {@link VirtualTable} and leaves the formating up to the report. 38 | *

39 | * 40 | *

41 | * If you want to use the format settings of the {@link VirtualTable} in your 42 | * report see {@link JRVirtualTableFormattedDataSource}. 43 | *

44 | * 45 | * @see JRVirtualTableFormattedDataSource 46 | * 47 | * @author XDEV Software 48 | * 49 | */ 50 | public class JRVirtualTableDataSource extends AbstractVirtualTableDataSource 51 | { 52 | 53 | /** 54 | * Straight forward constructor to wrap a given (non-null) 55 | * {@link VirtualTable}. 56 | * 57 | * @param virtualTable 58 | * the {@link VirtualTable} to wrap 59 | */ 60 | public JRVirtualTableDataSource(@NotNull final VirtualTable virtualTable) 61 | { 62 | super(virtualTable); 63 | } 64 | 65 | 66 | /** 67 | * Retrieves the value for column jrField in the current row. 68 | * Lookup is done by field name (column name). 69 | * 70 | * @param jrField 71 | * the {@link JRField} instance defining (by name) the column of 72 | * the {@link VirtualTable} whose value shall be retrieved. 73 | * @return the value in the wrapped {@link VirtualTable} instance from 74 | * current row, column jrField 75 | * @throws JRException 76 | * if the column (specified by jrField.getName()) 77 | * could not be found or accessed 78 | */ 79 | @Override 80 | public Object getFieldValue(@NotNull final JRField jrField) throws JRException 81 | { 82 | try 83 | { 84 | VirtualTableColumn column = this.virtualTable.getColumn(jrField.getName()); 85 | 86 | switch(column.getType()) 87 | { 88 | case BINARY: 89 | return "BINARY"; 90 | 91 | case LONGVARBINARY: 92 | return "LONGVARBINARY"; 93 | 94 | case VARBINARY: 95 | return "VARBINARY"; 96 | 97 | case BLOB: 98 | return "BLOB"; 99 | 100 | case CLOB: 101 | final XdevClob xClob = ((XdevClob)this.virtualTable.getValueAt(this.currentRowIndex,jrField.getName())); 102 | return xClob == null ? null : xClob.toString(); 103 | 104 | default: 105 | return this.virtualTable.getValueAt(this.currentRowIndex,jrField.getName()); 106 | } 107 | 108 | } 109 | catch(Exception e) 110 | { 111 | throw new JRException("Unable to get value for field '" + jrField.getName(),e); 112 | } 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/cmd/DataType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.cmd; 19 | import xdev.vt.XdevBlob; 20 | import xdev.vt.XdevClob; 21 | 22 | 23 | 24 | 25 | 26 | 27 | public enum DataType 28 | { 29 | 30 | /** 31 | * 8-bit integer value between 0 and 255, signed or unsigned. 32 | */ 33 | TINYINT(Byte.class), 34 | 35 | /** 36 | * Single precision floating point number that supports 7 digits of 37 | * mantissa. 38 | */ 39 | REAL(Float.class), 40 | 41 | 42 | /** 43 | * Severe fixed-precision decimal number which takes precision and scale 44 | * parameters. 45 | */ 46 | NUMERIC(Double.class), 47 | 48 | /** 49 | * Lax fixed-precision decimal number which takes precision and scale 50 | * parameters. 51 | */ 52 | DECIMAL(Double.class), 53 | 54 | 55 | /** 56 | * Fixed length character string. 57 | */ 58 | CHAR(String.class), 59 | /** 60 | * Big variable length character string with length param. 61 | */ 62 | LONGVARCHAR(String.class), 63 | 64 | /** 65 | * Hours, minutes and seconds. 66 | */ 67 | TIME(java.util.Date.class), 68 | 69 | /** 70 | * Big variable length character string. 71 | */ 72 | CLOB(XdevClob.class), 73 | 74 | 75 | 76 | /** 77 | * BLOB is not supported in table export. 78 | * The data type is exported as a string. 79 | */ 80 | BLOB(XdevBlob.class), 81 | 82 | /** 83 | * BINARY is not supported in table export. 84 | * The data type is exported as a string. 85 | */ 86 | BINARY(byte[].class), 87 | 88 | /** 89 | * VARBINARY is not supported in table export. 90 | * The data type is exported as a string. 91 | */ 92 | VARBINARY(byte[].class), 93 | 94 | /** 95 | * LONGVARBINARY is not supported in table export. 96 | * The data type is exported as a string. 97 | */ 98 | LONGVARBINARY(byte[].class), 99 | 100 | 101 | 102 | 103 | /** 104 | * 16-bit signed integer value between -32768 and 32767. 105 | */ 106 | SMALLINT(Short.class), 107 | 108 | /** 109 | * 32-bit signed integer value between -2147483648 and 2147483647. 110 | */ 111 | INTEGER(Integer.class), 112 | 113 | /** 114 | * 64-bit signed integer value between -9223372036854775808 and 115 | * 9223372036854775807. 116 | */ 117 | BIGINT(Long.class), 118 | 119 | /** 120 | * Double precision floating point number that supports 15 digits of 121 | * mantissa. 122 | */ 123 | DOUBLE(Double.class), 124 | 125 | FLOAT(Float.class), 126 | 127 | /** 128 | * 1-bit value, which is either 1 or 0, true of false. 129 | */ 130 | BOOLEAN(Boolean.class), 131 | 132 | 133 | /** 134 | * Small variable length character string with length param. 135 | */ 136 | VARCHAR(String.class), 137 | 138 | /** 139 | * Day, month and year. 140 | */ 141 | DATE(java.util.Date.class), 142 | 143 | /** 144 | * Object and Others 145 | */ 146 | OBJECT(Object.class), 147 | 148 | /** 149 | * {@link #DATE} + {@link #TIME} + Nanoseconds. 150 | */ 151 | TIMESTAMP(java.util.Date.class); 152 | 153 | private Class javaClass; 154 | 155 | 156 | /** 157 | * Instantiates a new DataType. 158 | * 159 | * @param javaClass 160 | * the java class 161 | * 162 | */ 163 | private DataType(Class javaClass) 164 | { 165 | this.javaClass = javaClass; 166 | } 167 | 168 | 169 | /** 170 | * Gets the java class for this {@link DataType}. 171 | * 172 | * @return the java class 173 | */ 174 | public Class getJavaClass() 175 | { 176 | return javaClass; 177 | } 178 | 179 | 180 | public static DataType get(Class jClass) 181 | { 182 | 183 | for(DataType type : values()) 184 | { 185 | if(type.getJavaClass() == jClass) 186 | { 187 | return type; 188 | } 189 | } 190 | return null; 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/cmd/TableExportDebugger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.cmd; 19 | 20 | import net.sf.jasperreports.engine.JRException; 21 | import net.sf.jasperreports.engine.JasperReport; 22 | import net.sf.jasperreports.engine.xml.JRXmlWriter; 23 | 24 | 25 | public interface TableExportDebugger 26 | { 27 | 28 | public boolean isDebugModeOn(); 29 | 30 | 31 | public String getFilePath(); 32 | 33 | 34 | public void exportJasperReportToJrxml(final JasperReport jReport) throws JRException; 35 | 36 | 37 | 38 | public class DefaultTableExportDebuggerImpl implements TableExportDebugger 39 | { 40 | private boolean debugMode = false; 41 | private String filePath = null; 42 | 43 | 44 | @Override 45 | public boolean isDebugModeOn() 46 | { 47 | return debugMode; 48 | } 49 | 50 | 51 | @Override 52 | public String getFilePath() 53 | { 54 | return filePath; 55 | } 56 | 57 | 58 | @Override 59 | public void exportJasperReportToJrxml(final JasperReport jReport) throws JRException 60 | { 61 | JRXmlWriter.writeReport(jReport,this.getFilePath(),"UTF-8"); 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/AbstractColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | public abstract class AbstractColumn implements Column 21 | { 22 | private String fieldName; 23 | private Class valueClass; 24 | private ColumnStyle style = DefaultColumnStyle.DEFAULT_COLUMN_STYLE.clone(); 25 | 26 | 27 | /** 28 | * {@inheritDoc} 29 | */ 30 | @Override 31 | public void setFieldName(String fieldName) 32 | { 33 | this.fieldName = fieldName; 34 | } 35 | 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public void setColumnValueClass(Class valueClass) 42 | { 43 | this.valueClass = valueClass; 44 | } 45 | 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public void setStyle(ColumnStyle style) 52 | { 53 | this.style = style; 54 | } 55 | 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public String getFieldName() 62 | { 63 | return this.fieldName; 64 | } 65 | 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @Override 71 | public Class getColumnValueClass() 72 | { 73 | return this.valueClass; 74 | } 75 | 76 | 77 | /** 78 | * {@inheritDoc} 79 | */ 80 | @Override 81 | public ColumnStyle getStyle() 82 | { 83 | return this.style; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/Column.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | /** 21 | * An representation of a data source field. Each row in a dataset consists of one or more fields with unique 22 | * names. 23 | * 24 | * @author XDEV Software(FHAE) 25 | */ 26 | public interface Column 27 | { 28 | 29 | /** 30 | * Return the style for this {@link Column}. 31 | * 32 | * @return the {@link ColumnStyle} 33 | * 34 | * @see #setStyle(ColumnStyle) 35 | */ 36 | public ColumnStyle getStyle(); 37 | 38 | 39 | public String getProperty(); 40 | 41 | 42 | /** 43 | * Return the column (field) value class. Field types cannot be primitives. 44 | * 45 | * @return the {@link Class} for this {@link Column} 46 | */ 47 | public Class getColumnValueClass(); 48 | 49 | 50 | /** 51 | * Return the field unique name of this {@code Column}. 52 | * 53 | * @return the unique name 54 | */ 55 | public String getFieldName(); 56 | 57 | 58 | /** 59 | * Sets the style for this {@link Column}. 60 | * 61 | * @see #setStyle(ColumnStyle) 62 | */ 63 | public void setStyle(ColumnStyle style); 64 | 65 | 66 | public void setProperty(String property); 67 | 68 | 69 | /** 70 | * Sets the column (field) value class. Field types cannot be primitives. 71 | */ 72 | public void setColumnValueClass(Class valueClass); 73 | 74 | 75 | public void setFieldName(String fieldName); 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/ColumnAlignment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | import net.sf.jasperreports.engine.type.HorizontalTextAlignEnum; 21 | 22 | /** 23 | * Alignment of the content. 24 | * 25 | * @author XDEV Software(FHAE) 26 | */ 27 | public enum ColumnAlignment 28 | { 29 | /** 30 | * Indicates that the content is left aligned in the column. 31 | * 32 | */ 33 | LEFT(HorizontalTextAlignEnum.LEFT), 34 | 35 | /** 36 | * Indicates that the content is centered in the column. 37 | * 38 | */ 39 | CENTER(HorizontalTextAlignEnum.CENTER), 40 | 41 | /** 42 | * Indicates that the content is right aligned in the column. 43 | * 44 | */ 45 | RIGHT(HorizontalTextAlignEnum.RIGHT); 46 | 47 | private HorizontalTextAlignEnum horizontalAlignment; 48 | 49 | 50 | private ColumnAlignment(final HorizontalTextAlignEnum horizontalAlignment) 51 | { 52 | this.horizontalAlignment = horizontalAlignment; 53 | } 54 | 55 | 56 | /** 57 | * Return the mapped {@link HorizontalTextAlignEnum}. 58 | * 59 | * @return the {@link HorizontalTextAlignEnum} 60 | */ 61 | public HorizontalTextAlignEnum getHorizontalTextAlignEnum() 62 | { 63 | return this.horizontalAlignment; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/ColumnBorder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | import java.awt.Color; 21 | 22 | 23 | /** 24 | * A class which describes the properties of an column border. 25 | * 26 | * 27 | * @author XDEV Software(FHAE) 28 | * 29 | * @see Color 30 | * @see LineStyle 31 | * @see EmptyColumnBorder 32 | */ 33 | public class ColumnBorder 34 | { 35 | 36 | private int lineWidth; 37 | private Color lineColor; 38 | private LineStyle lineStyle; 39 | 40 | 41 | /** 42 | * Creates a column border with the specified lineWidth, lineColor and 43 | * lineStyle. 44 | * 45 | * @param lineWidth 46 | * the line width of the painted border 47 | * @param lineColor 48 | * the line color of the painted border 49 | * @param lineStyle 50 | * the line style of the painted border 51 | * 52 | * @see Color 53 | * @see LineStyle 54 | */ 55 | public ColumnBorder(int lineWidth, Color lineColor, LineStyle lineStyle) 56 | { 57 | this.lineWidth = lineWidth; 58 | this.lineColor = lineColor; 59 | this.lineStyle = lineStyle; 60 | } 61 | 62 | 63 | /** 64 | * Return the line color. 65 | * 66 | * @return the {@link Color} object for the line color 67 | */ 68 | public Color getLineColor() 69 | { 70 | return this.lineColor; 71 | } 72 | 73 | 74 | /** 75 | * Sets the line color. 76 | * 77 | * @param lineColor 78 | * a {@link Color} 79 | */ 80 | public void setLineColor(Color lineColor) 81 | { 82 | this.lineColor = lineColor; 83 | } 84 | 85 | 86 | /** 87 | * Indicates the line style used for the column. 88 | * 89 | * @return a value representing one of the style constants in 90 | * {@link LineStyle} 91 | */ 92 | public LineStyle getLineStyle() 93 | { 94 | return this.lineStyle; 95 | } 96 | 97 | 98 | /** 99 | * Specifies the {@link LineStyle}. 100 | * 101 | * @param lineStyle 102 | * a value representing one of the style constants in 103 | * {@link LineStyle} 104 | */ 105 | public void setLineStyle(LineStyle lineStyle) 106 | { 107 | this.lineStyle = lineStyle; 108 | } 109 | 110 | 111 | /** 112 | * Return the line width used for the column. 113 | * 114 | * @return line width 115 | */ 116 | public int getLineWidth() 117 | { 118 | return this.lineWidth; 119 | } 120 | 121 | 122 | /** 123 | * Sets the line width. 124 | * 125 | * @param lineWidth 126 | * the line width 127 | */ 128 | public void setLineWidth(int lineWidth) 129 | { 130 | this.lineWidth = lineWidth; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/ColumnPadding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | 21 | 22 | /** 23 | * A class which describes the properties of the column padding. 24 | * 25 | * 26 | * @author XDEV Software(FHAE) 27 | * 28 | */ 29 | public class ColumnPadding 30 | { 31 | 32 | protected int leftWidth, rightWidth, topWidth, bottomWidth; 33 | 34 | 35 | /** 36 | * Creates a column padding object with the specified leftWidth, rightWidth, topWidth and 37 | * bottomWidth. 38 | * 39 | * @param leftWidth 40 | * @param rightWidth 41 | * @param topWidth 42 | * @param bottomWidth 43 | * 44 | */ 45 | public ColumnPadding(int leftWidth, int rightWidth,int topWidth,int bottomWidth) 46 | { 47 | this.leftWidth = leftWidth; 48 | this.rightWidth = rightWidth; 49 | this.topWidth = topWidth; 50 | this.bottomWidth = bottomWidth; 51 | } 52 | 53 | public int getBottomWidth() 54 | { 55 | return bottomWidth; 56 | } 57 | 58 | public int getLeftWidth() 59 | { 60 | return leftWidth; 61 | } 62 | 63 | public int getRightWidth() 64 | { 65 | return rightWidth; 66 | } 67 | 68 | public int getTopWidth() 69 | { 70 | return topWidth; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/ColumnStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | import java.awt.Color; 21 | import java.awt.Font; 22 | 23 | import xdev.lang.Copyable; 24 | 25 | 26 | /** 27 | * A interface which describes the style properties of an column. 28 | * 29 | * @see Color 30 | * @see ColumnAlignment 31 | * @see ColumnBorder 32 | * @see Font 33 | * 34 | * @author XDEV Software(FHAE) 35 | */ 36 | public interface ColumnStyle extends Copyable 37 | { 38 | /** 39 | * Return the background color for this {@link ColumnStyle}. 40 | * 41 | * @return the {@link Color} of the background 42 | * 43 | * @see #setBackground(Color) 44 | */ 45 | public abstract Color getBackground(); 46 | 47 | 48 | /** 49 | * Return the foreground color for this {@link ColumnStyle}. 50 | * 51 | * @return the {@link Color} of the foreground 52 | * 53 | * @see #setForeground(Color) 54 | */ 55 | public abstract Color getForeground(); 56 | 57 | 58 | /** 59 | * Sets the background color for this {@link ColumnStyle}. 60 | * 61 | * @param background 62 | * the {@link Color} of the background 63 | * 64 | * @see #getBackground() 65 | */ 66 | public abstract void setBackground(Color background); 67 | 68 | 69 | /** 70 | * Sets the foreground color for this {@link ColumnStyle}. 71 | * 72 | * @param foreground 73 | * the {@link Color} of the foreground 74 | * 75 | * @see #getForeground() 76 | */ 77 | public abstract void setForeground(Color foreground); 78 | 79 | 80 | /** 81 | * Return the border of this {@link ColumnStyle}. 82 | * 83 | * @return the {@link ColumnBorder} object 84 | * 85 | * @see #setColBorder(ColumnBorder) 86 | */ 87 | public abstract ColumnBorder getColBorder(); 88 | 89 | 90 | /** 91 | * Sets the border of this {@link ColumnStyle}. 92 | * 93 | * @param colBorder 94 | * a {@link ColumnBorder} object 95 | * 96 | * @see #getColBorder() 97 | */ 98 | public abstract void setColBorder(ColumnBorder colBorder); 99 | 100 | 101 | /** 102 | * Return the font of this {@link ColumnStyle}. 103 | * 104 | * @return the {@link Font} object 105 | * 106 | * @see #setFont(Font) 107 | */ 108 | public abstract Font getFont(); 109 | 110 | 111 | /** 112 | * Sets the font of this {@link ColumnStyle}. 113 | * 114 | * @param font 115 | * a {@link Font} object 116 | * 117 | * @see #getFont() 118 | */ 119 | public abstract void setFont(Font font); 120 | 121 | 122 | /** 123 | * Return the alignment of the column content along the X axis. 124 | * 125 | * @return the {@link ColumnAlignment} of this {@link ColumnStyle} 126 | */ 127 | public abstract ColumnAlignment getHorizontalAlignment(); 128 | 129 | 130 | /** 131 | * Sets the alignment of the column contents along the X axis. 132 | * 133 | * @param horizontalAlignment 134 | * One of the following constants defined in 135 | * {@link ColumnAlignment}:
136 | *
    137 | *
  • LEFT
  • 138 | *
  • CENTER (the default)
  • 139 | *
  • RIGHT
  • 140 | *
141 | */ 142 | public abstract void setHorizontalAlignment(ColumnAlignment horizontalAlignment); 143 | 144 | 145 | public abstract void setColumnPadding(ColumnPadding colPadding); 146 | 147 | 148 | public abstract ColumnPadding getColumnPadding(); 149 | 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/ContentColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | /** 21 | * Representation of a content (detail) column. 22 | * 23 | * @author XDEV Software(FHAE) 24 | */ 25 | public class ContentColumn extends AbstractColumn 26 | { 27 | private String pattern; 28 | 29 | 30 | /** 31 | * The Property is used as the column pattern. 32 | *
33 | * Sets the pattern used for this column.
34 | * The pattern will be used in a SimpleDateFormat for dates and a DecimalFormat for numeric column fields.
35 | * The pattern format must follow one of these two classes formatting rules, as specified in the JDK API docs.
36 | * 37 | * @param pattern 38 | */ 39 | @Override 40 | public void setProperty(String pattern) 41 | { 42 | this.pattern = pattern; 43 | } 44 | 45 | 46 | /** 47 | * Return the column pattern of this {@link ContentColumn}. 48 | * @return the column pattern of this {@link ContentColumn}. 49 | * 50 | * @see #setProperty(String) 51 | */ 52 | @Override 53 | public String getProperty() 54 | { 55 | return this.pattern; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/DefaultColumnStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | import java.awt.Color; 21 | import java.awt.Font; 22 | 23 | import javax.swing.UIManager; 24 | import javax.swing.plaf.FontUIResource; 25 | 26 | import xdev.lang.Copyable; 27 | 28 | 29 | /** 30 | * High level representation of the style of a column. 31 | * 32 | * 33 | * 34 | * @author XDEV Software(FHAE) 35 | * 36 | * @see #DEFAULT_COLUMN_STYLE 37 | * @see #DEFAULT_HEADER_STYLE 38 | */ 39 | public class DefaultColumnStyle implements ColumnStyle, Copyable 40 | { 41 | /** 42 | * Return a specified default {@link ColumnStyle} of a content column. This 43 | * object are initialized with the follow values: 44 | * 45 | *
    46 | *
  • name: XdevDefaultColumnStyle
  • 47 | *
  • background: {@link Color#WHITE}
  • 48 | *
  • foreground: {@link Color#BLACK}
  • 49 | *
  • font: Arial, Plain, 10
  • 50 | *
  • horizontalAlignment: {@link ColumnAlignment#LEFT}
  • 51 | *
  • colBorder: {@link EmptyColumnBorder}
  • 52 | *
53 | */ 54 | public final static DefaultColumnStyle DEFAULT_COLUMN_STYLE = new DefaultColumnStyle(); 55 | /** 56 | * Return a specified default {@link ColumnStyle} of a header column. This 57 | * object are initialized with the follow values: 58 | * 59 | *
    60 | *
  • name: XdevDefaultHeaderStyle
  • 61 | *
  • background: {@link Color#lightGray}
  • 62 | *
  • foreground: {@link Color#BLACK}
  • 63 | *
  • font: Arial, Plain, 12
  • 64 | *
  • horizontalAlignment: {@link ColumnAlignment#LEFT}
  • 65 | *
  • colBorder with this parameters: 1,Color.BLACK,LineStyle.SOLID ( 66 | * {@link ColumnBorder})
  • 67 | *
68 | */ 69 | public final static DefaultColumnStyle DEFAULT_HEADER_STYLE = new DefaultColumnStyle( 70 | getDefaultHeaderFont(), 71 | Color.lightGray, 72 | new ColumnBorder(1, 73 | Color.BLACK, 74 | LineStyle.SOLID)); 75 | 76 | private Color background = Color.WHITE; 77 | private Color foreground = Color.BLACK; 78 | private Font font = getDefaultContentFont(); 79 | private ColumnAlignment horizontalAlignment = ColumnAlignment.LEFT; 80 | private ColumnBorder colBorder = new EmptyColumnBorder(); 81 | 82 | private ColumnPadding colPadding = new ColumnPadding(1,1,1,1); 83 | 84 | 85 | /** 86 | * Create a {@link DefaultColumnStyle} instance with default values: 87 | * 88 | *
    89 | *
  • background: {@link Color#WHITE}
  • 90 | *
  • foreground: {@link Color#BLACK}
  • 91 | *
  • font: Arial, Plain, 10
  • 92 | *
  • horizontalAlignment: {@link ColumnAlignment#LEFT}
  • 93 | *
  • colBorder: {@link EmptyColumnBorder}
  • 94 | *
95 | * 96 | */ 97 | public DefaultColumnStyle() 98 | { 99 | 100 | } 101 | 102 | 103 | 104 | /** 105 | * Create a {@link DefaultColumnStyle} instance with the given parameter. 106 | * 107 | * @param font 108 | * @param background 109 | * @param colBorder 110 | */ 111 | public DefaultColumnStyle(Font font, Color background, ColumnBorder colBorder) 112 | { 113 | this.font = font; 114 | this.background = background; 115 | this.colBorder = colBorder; 116 | } 117 | 118 | 119 | /** 120 | * 121 | * @param font 122 | * @param background 123 | * @param foreground 124 | * @param alignment 125 | * @param colBorder 126 | */ 127 | public DefaultColumnStyle(Font font, Color background, Color foreground, 128 | ColumnAlignment alignment, ColumnBorder colBorder) 129 | { 130 | this.font = font; 131 | this.background = background; 132 | this.foreground = foreground; 133 | this.colBorder = colBorder; 134 | this.horizontalAlignment = alignment; 135 | } 136 | 137 | 138 | public static Font getDefaultHeaderFont() 139 | { 140 | FontUIResource fur = (FontUIResource)UIManager.get("Label.font"); 141 | final Font defaultFont = new Font(fur.getFontName(),Font.PLAIN,12); 142 | return defaultFont; 143 | } 144 | public static Font getDefaultContentFont() 145 | { 146 | FontUIResource fur = (FontUIResource)UIManager.get("Label.font"); 147 | final Font defaultFont = new Font(fur.getFontName(),Font.PLAIN,10); 148 | return defaultFont; 149 | } 150 | 151 | /** 152 | * {@inheritDoc} 153 | */ 154 | @Override 155 | public Color getBackground() 156 | { 157 | return this.background; 158 | } 159 | 160 | 161 | /** 162 | * {@inheritDoc} 163 | */ 164 | @Override 165 | public void setBackground(Color background) 166 | { 167 | this.background = background; 168 | } 169 | 170 | 171 | /** 172 | * {@inheritDoc} 173 | */ 174 | @Override 175 | public ColumnBorder getColBorder() 176 | { 177 | return this.colBorder; 178 | } 179 | 180 | 181 | /** 182 | * {@inheritDoc} 183 | */ 184 | @Override 185 | public void setColBorder(ColumnBorder colBorder) 186 | { 187 | this.colBorder = colBorder; 188 | } 189 | 190 | 191 | /** 192 | * {@inheritDoc} 193 | */ 194 | @Override 195 | public Font getFont() 196 | { 197 | return this.font; 198 | } 199 | 200 | 201 | /** 202 | * {@inheritDoc} 203 | */ 204 | @Override 205 | public void setFont(Font font) 206 | { 207 | this.font = font; 208 | } 209 | 210 | 211 | /** 212 | * {@inheritDoc} 213 | */ 214 | @Override 215 | public Color getForeground() 216 | { 217 | return this.foreground; 218 | } 219 | 220 | 221 | /** 222 | * {@inheritDoc} 223 | */ 224 | @Override 225 | public void setForeground(Color foreground) 226 | { 227 | this.foreground = foreground; 228 | } 229 | 230 | 231 | /** 232 | * {@inheritDoc} 233 | */ 234 | @Override 235 | public ColumnAlignment getHorizontalAlignment() 236 | { 237 | return this.horizontalAlignment; 238 | } 239 | 240 | 241 | /** 242 | * {@inheritDoc} 243 | */ 244 | @Override 245 | public void setHorizontalAlignment(ColumnAlignment horizontalAlignment) 246 | { 247 | this.horizontalAlignment = horizontalAlignment; 248 | } 249 | 250 | 251 | @Override 252 | public DefaultColumnStyle clone() 253 | { 254 | return new DefaultColumnStyle(getFont(),getBackground(),getForeground(), 255 | getHorizontalAlignment(),getColBorder()); 256 | } 257 | 258 | 259 | @Override 260 | public void setColumnPadding(ColumnPadding colPadding) 261 | { 262 | this.colPadding = colPadding; 263 | } 264 | 265 | 266 | @Override 267 | public ColumnPadding getColumnPadding() 268 | { 269 | return this.colPadding; 270 | } 271 | 272 | } 273 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/DefaultPageProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | public class DefaultPageProperties implements PageProperties 21 | { 22 | /** 23 | * Default height of the page. 24 | */ 25 | public static int DEFAULT_PAGE_HEIGHT = 842; 26 | /** 27 | * Default value of column spacing. 28 | */ 29 | public static int DEFAULT_SPACING = 0; 30 | /** 31 | * Default value of left margin. 32 | */ 33 | public static int DEFAULT_LEFT_MARGIN = 40; 34 | /** 35 | * Default value of right margin. 36 | */ 37 | public static int DEFAULT_RIGHT_MARGIN = 40; 38 | /** 39 | * Default value of top margin. 40 | */ 41 | public static int DEFAULT_TOP_MARGIN = 50; 42 | /** 43 | * Default value of bottom margin. 44 | */ 45 | public static int DEFAULT_BOTTOM_MARGIN = 50; 46 | 47 | private int columnSpacing; 48 | private int leftMargin; 49 | private int rightMargin; 50 | private int topMargin; 51 | private int bottomMargin; 52 | private int pageHeight; 53 | 54 | 55 | public DefaultPageProperties() 56 | { 57 | this.columnSpacing = DEFAULT_SPACING; 58 | this.leftMargin = DEFAULT_LEFT_MARGIN; 59 | this.rightMargin = DEFAULT_RIGHT_MARGIN; 60 | this.topMargin = DEFAULT_TOP_MARGIN; 61 | this.bottomMargin = DEFAULT_BOTTOM_MARGIN; 62 | this.pageHeight = DEFAULT_PAGE_HEIGHT; 63 | } 64 | 65 | 66 | /** 67 | * {@inheritDoc} 68 | */ 69 | @Override 70 | public int getBottomMargin() 71 | { 72 | return this.bottomMargin; 73 | } 74 | 75 | 76 | /** 77 | * {@inheritDoc} 78 | */ 79 | @Override 80 | public int getColumnSpacing() 81 | { 82 | return this.columnSpacing; 83 | } 84 | 85 | 86 | /** 87 | * {@inheritDoc} 88 | */ 89 | @Override 90 | public int getLeftMargin() 91 | { 92 | return this.leftMargin; 93 | } 94 | 95 | 96 | /** 97 | * {@inheritDoc} 98 | */ 99 | @Override 100 | public int getPageHeight() 101 | { 102 | return this.pageHeight; 103 | } 104 | 105 | 106 | /** 107 | * {@inheritDoc} 108 | */ 109 | @Override 110 | public int getRightMargin() 111 | { 112 | return this.rightMargin; 113 | } 114 | 115 | 116 | /** 117 | * {@inheritDoc} 118 | */ 119 | @Override 120 | public int getTopMargin() 121 | { 122 | return this.topMargin; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/EmptyColumnBorder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | import java.awt.Color; 21 | 22 | /** 23 | * A class that represent an column border with no size. 24 | * 25 | * @author XDEV Software(FHAE) 26 | */ 27 | public class EmptyColumnBorder extends ColumnBorder 28 | { 29 | /** 30 | * Create a {@link EmptyColumnBorder} object. 31 | */ 32 | public EmptyColumnBorder() 33 | { 34 | super(0,Color.WHITE,LineStyle.SOLID); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/HeaderColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | /** 21 | * Representation of a header column. 22 | * 23 | * @author XDEV Software(FHAE) 24 | */ 25 | public class HeaderColumn extends AbstractColumn 26 | { 27 | private String text; 28 | 29 | 30 | /** 31 | * The Property is used as header text. 32 | * 33 | * @return the header text 34 | */ 35 | @Override 36 | public String getProperty() 37 | { 38 | return this.text; 39 | } 40 | 41 | 42 | /** 43 | * The Property is used as header text. 44 | * 45 | * @param text 46 | */ 47 | @Override 48 | public void setProperty(String text) 49 | { 50 | this.text = text; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/LineStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | import net.sf.jasperreports.engine.type.LineStyleEnum; 20 | 21 | /** 22 | * Representation of the frame lines. 23 | * 24 | * @author XDEV Software(FHAE) 25 | */ 26 | public enum LineStyle 27 | { 28 | /** 29 | * Constant useful for specifying solid line style. 30 | */ 31 | SOLID(LineStyleEnum.SOLID), 32 | 33 | /** 34 | * Constant useful for specifying dashed line style. 35 | */ 36 | DASHED(LineStyleEnum.DASHED), 37 | 38 | /** 39 | * Constant useful for specifying dotted line style. 40 | */ 41 | DOTTED(LineStyleEnum.DOTTED), 42 | 43 | /** 44 | * Constant useful for specifying double line style. 45 | */ 46 | DOUBLE(LineStyleEnum.DOUBLE); 47 | 48 | private LineStyleEnum lineStyleEnum; 49 | 50 | private LineStyle(LineStyleEnum lineStyleEnum) 51 | { 52 | this.lineStyleEnum = lineStyleEnum; 53 | } 54 | 55 | /** 56 | * Return the mapped {@link LineStyleEnum}. 57 | * 58 | * @return the {@link LineStyleEnum} 59 | */ 60 | public LineStyleEnum getLineStyleEnum() 61 | { 62 | return this.lineStyleEnum; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/PageProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | /** 21 | * 22 | * @author XDEV Software(FHAE) 23 | */ 24 | public interface PageProperties 25 | { 26 | 27 | 28 | /** 29 | * Return page height (including margins etc.). 30 | * 31 | * @return the page height value as int 32 | */ 33 | public int getPageHeight(); 34 | 35 | 36 | /** 37 | * Return the spacing between columns. 38 | * 39 | * @return the spacing value between columns as int 40 | */ 41 | public int getColumnSpacing(); 42 | 43 | 44 | /** 45 | * Return the left margin. The working space is calculated by subtracting the margins from the page width. 46 | * 47 | * @return the left margin value as int 48 | */ 49 | public int getLeftMargin(); 50 | 51 | 52 | /** 53 | * Return the right margin. The working space is calculated by subtracting the margins from the page width. 54 | * 55 | * @return the right margin value as int 56 | */ 57 | public int getRightMargin(); 58 | 59 | 60 | /** 61 | * Return the top margin. The working space is calculated by subtracting the margins from the page height. 62 | * 63 | * @return the top margin value as int 64 | */ 65 | public int getTopMargin(); 66 | 67 | 68 | /** 69 | * Return the bottom margin. The working space is calculated by subtracting the margins from the page height. 70 | * 71 | * @return the bottom margin value as int 72 | */ 73 | public int getBottomMargin(); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/TemplateColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | /** 21 | * The class encapsulates the two column object's {@link HeaderColumn} and 22 | * {@link ContentColumn}.
23 | *

24 | * The class has general information like as width, 25 | * name of the column. 26 | *

27 | * 28 | * @author XDEV Software(FHAE) 29 | * 30 | */ 31 | public class TemplateColumn 32 | { 33 | private int width; 34 | private boolean hasHeaderColumn = true; 35 | private HeaderColumn headerColumn = null; 36 | private ContentColumn contentColumn = null; 37 | private String columnName = null; 38 | private boolean visible = true; 39 | 40 | 41 | /** 42 | * Create a instance of this {@link TemplateColumn}. The {@link #columnName} 43 | * default value is set to NewColumn 44 | */ 45 | public TemplateColumn() 46 | { 47 | this("NewColumn"); 48 | } 49 | 50 | /** 51 | * Create a instance of this {@link TemplateColumn}. 52 | * 53 | * @param columnName 54 | */ 55 | public TemplateColumn(final String columnName) 56 | { 57 | this.columnName = columnName; 58 | this.headerColumn = new HeaderColumn(); 59 | this.contentColumn = new ContentColumn(); 60 | } 61 | 62 | 63 | /** 64 | * 65 | * @param contentColumn 66 | */ 67 | public void setContentColumn(ContentColumn contentColumn) 68 | { 69 | this.contentColumn = contentColumn; 70 | } 71 | 72 | public void setVisible(boolean visible) 73 | { 74 | this.visible = visible; 75 | } 76 | 77 | public void setHasHeaderColumn(boolean hasHeaderColumn) 78 | { 79 | this.hasHeaderColumn = hasHeaderColumn; 80 | } 81 | 82 | 83 | public void setHeaderColumn(HeaderColumn headerColumn) 84 | { 85 | this.headerColumn = headerColumn; 86 | } 87 | 88 | 89 | public void setWidth(int width) 90 | { 91 | this.width = width; 92 | } 93 | 94 | 95 | public void setColumnName(String columnName) 96 | { 97 | this.columnName = columnName; 98 | } 99 | 100 | 101 | public int getWidth() 102 | { 103 | return this.width; 104 | } 105 | 106 | 107 | public HeaderColumn getHeaderColumn() 108 | { 109 | return this.headerColumn; 110 | } 111 | 112 | public boolean isVisible() 113 | { 114 | return visible; 115 | } 116 | 117 | public ContentColumn getContentColumn() 118 | { 119 | return this.contentColumn; 120 | } 121 | 122 | 123 | public boolean hasHeaderColumn() 124 | { 125 | return this.hasHeaderColumn; 126 | } 127 | 128 | 129 | public String getColumnName() 130 | { 131 | return columnName; 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/TemplateConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import net.sf.jasperreports.engine.JasperReport; 24 | 25 | 26 | /** 27 | * A {@link TemplateConfig} is a pre-configuration object of a 28 | * {@link JasperReport}. 29 | * 30 | * 31 | * @author XDEV Software(FHAE) 32 | */ 33 | public class TemplateConfig 34 | { 35 | /** 36 | * Default height of the header label. 37 | */ 38 | public static int DEFAULT_HEADER_LABEL_HEIGHT = 25; 39 | /** 40 | * Default height of the header band. 41 | */ 42 | public static int DEFAULT_HEADER_BAND_HEIGHT = 30; 43 | /** 44 | * Default height of the detail textfield. 45 | */ 46 | public static int DEFAULT_DETAIL_TEXTFIELD_HEIGHT = 19; 47 | /** 48 | * Default height of the detail band. 49 | */ 50 | public static int DEFAULT_DETAIL_BAND_HEIGHT = 20; 51 | 52 | /** 53 | * Default y-position of component's in the bands. 54 | */ 55 | public static int DEFAULT_COMPONENT_Y_POSITION = 0; 56 | 57 | /** 58 | * Default sheet name. 59 | */ 60 | private static String DEFAULT_SHEET_NAME = "Sheet1"; 61 | 62 | private String sheetName = DEFAULT_SHEET_NAME; 63 | private PageProperties pagePropertiesObj = new DefaultPageProperties(); 64 | private List allColumns = new ArrayList<>(); 65 | 66 | private boolean blankWhenNullValue = false; 67 | 68 | 69 | public TemplateConfig() 70 | { 71 | 72 | } 73 | 74 | /** 75 | * Add a {@link TemplateColumn} to the current list. 76 | * 77 | * @param col 78 | * the {@link TemplateColumn} to be added in the list 79 | */ 80 | public void addColumn(TemplateColumn col) 81 | { 82 | this.allColumns.add(col); 83 | } 84 | 85 | /** 86 | * Return a list of all {@link TemplateColumn} of this {@link TemplateConfig}. 87 | * 88 | * @return 89 | * a {@link List} with all {@link TemplateColumn} 90 | */ 91 | public List getColumns() 92 | { 93 | return this.allColumns; 94 | } 95 | 96 | 97 | /** 98 | * Returns the {@link ContentColumn} with the specified fieldName. 99 | * 100 | * @param fieldName 101 | * as a {@link String} 102 | * 103 | * @return the {@link ContentColumn} for the specified fieldName, or null if 104 | * no column is found. 105 | */ 106 | public ContentColumn getContentColumnByFieldName(final String fieldName) 107 | { 108 | for(TemplateColumn col : getColumns()) 109 | { 110 | final ContentColumn contentCol = col.getContentColumn(); 111 | if(contentCol == null) 112 | { 113 | continue; 114 | } 115 | else if(contentCol.getFieldName().equals(fieldName)) 116 | { 117 | return contentCol; 118 | } 119 | } 120 | 121 | return null; 122 | } 123 | 124 | 125 | /** 126 | * Returns the {@link HeaderColumn} with the specified headerText. 127 | * 128 | * @param headerText 129 | * as a {@link String} 130 | * 131 | * @return the {@link HeaderColumn} for the specified headerText, or null if 132 | * no column is found. 133 | * 134 | * @see HeaderColumn#getProperty() 135 | */ 136 | public HeaderColumn getHeaderColumnByFieldName(final String headerText) 137 | { 138 | for(TemplateColumn col : getColumns()) 139 | { 140 | final HeaderColumn headerCol = col.getHeaderColumn(); 141 | if(headerCol == null) 142 | { 143 | continue; 144 | } 145 | else if(headerCol.getProperty().equals(headerText)) 146 | { 147 | return headerCol; 148 | } 149 | } 150 | 151 | return null; 152 | } 153 | 154 | public TemplateColumn getTemplateColumn(final String columnName) 155 | { 156 | for(TemplateColumn col : getColumns()) 157 | { 158 | if(col.getColumnName().equals(columnName)) 159 | { 160 | return col; 161 | } 162 | } 163 | 164 | return null; 165 | } 166 | 167 | 168 | /** 169 | * Check the template if any header column is set. 170 | * 171 | * @return {@code true} if one or more header columns are define, otherwise 172 | * {@code false} 173 | */ 174 | public boolean hasAnyHeader() 175 | { 176 | for(TemplateColumn col : getColumns()) 177 | { 178 | if(col.hasHeaderColumn()) 179 | { 180 | return true; 181 | } 182 | } 183 | return false; 184 | } 185 | 186 | 187 | // //////////////////////////////////////////// 188 | // /////SETTER 189 | // //////////////////////////////////////////// 190 | 191 | /** 192 | * Set the excel sheet name for this {@link TemplateConfig}. 193 | *

194 | * Note - Excel allows sheet names up to 31 chars in length but other 195 | * applications allow more. Excel does not crash with names longer than 31 196 | * chars, but silently truncates such names to 31 chars. 197 | *

198 | * 199 | * @param name 200 | * the excel sheet name 201 | */ 202 | public void setSheetName(String name) 203 | { 204 | this.sheetName = name; 205 | } 206 | 207 | 208 | public void setBlankWhenNullValue(boolean blankWhenNullValue) 209 | { 210 | this.blankWhenNullValue = blankWhenNullValue; 211 | } 212 | 213 | 214 | // //////////////////////////////////////////// 215 | // /////GETTER 216 | // //////////////////////////////////////////// 217 | 218 | 219 | 220 | public PageProperties getPageProperties() 221 | { 222 | return this.pagePropertiesObj; 223 | } 224 | 225 | 226 | public String getSheetName() 227 | { 228 | return this.sheetName; 229 | } 230 | 231 | 232 | public boolean isBlankWhenNullValue() 233 | { 234 | return this.blankWhenNullValue; 235 | } 236 | 237 | } 238 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/builder/DefaultJTableConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config.builder; 19 | 20 | import java.util.HashMap; 21 | 22 | import javax.swing.JTable; 23 | import javax.swing.table.TableColumn; 24 | import javax.swing.table.TableColumnModel; 25 | 26 | import xdev.tableexport.config.ColumnStyle; 27 | import xdev.tableexport.config.ContentColumn; 28 | import xdev.tableexport.config.DefaultColumnStyle; 29 | import xdev.tableexport.config.HeaderColumn; 30 | import xdev.tableexport.config.TemplateColumn; 31 | import xdev.tableexport.config.TemplateConfig; 32 | import xdev.tableexport.utils.NullPatternConverter; 33 | 34 | 35 | /** 36 | * The {@link DefaultJTableConfigBuilder} class provides a easy way to analyzes 37 | * {@code T} and create a {@link TemplateConfig}. 38 | * 39 | * @author XDEV Software(FHAE) 40 | * 41 | * @param 42 | * The implementor's type 43 | */ 44 | public class DefaultJTableConfigBuilder implements ExportConfigBuilder 45 | { 46 | private T table; 47 | 48 | private ColumnStyle defaultContentStyle = DefaultColumnStyle.DEFAULT_COLUMN_STYLE; 49 | private ColumnStyle defaultHeaderStyle = DefaultColumnStyle.DEFAULT_HEADER_STYLE; 50 | private NullPatternConverter patternConverter = new NullPatternConverter(); 51 | private HashMap fieldnameToColumn = new HashMap<>(); 52 | 53 | 54 | /** 55 | * Create a instance of the {@link DefaultJTableConfigBuilder}. 56 | * 57 | * @param table 58 | * a object extends {@link JTable} 59 | */ 60 | public DefaultJTableConfigBuilder(T table) 61 | { 62 | this.table = table; 63 | } 64 | 65 | 66 | /** 67 | * Create a {@link TemplateColumn} from a {@link JTable}.
68 | * Loop through the {@link TableColumnModel} columns and build for each 69 | * column a {@link HeaderColumn} and {@link ContentColumn}. 70 | * 71 | * 72 | * @return the generated {@link TemplateConfig} 73 | */ 74 | @Override 75 | public TemplateConfig createConfig() 76 | { 77 | final TemplateConfig config = new TemplateConfig(); 78 | 79 | config.setSheetName("JTable-Export"); 80 | 81 | final TableColumnModel columnModel = this.table.getColumnModel(); 82 | for(int col = 0; col < columnModel.getColumnCount(); col++) 83 | { 84 | 85 | final TableColumn tableHeaderColumn = table.getTableHeader().getColumnModel() 86 | .getColumn(col); 87 | // Header 88 | final String columnIdentifier = tableHeaderColumn.getIdentifier().toString(); 89 | 90 | TemplateColumn tColumn = null; 91 | 92 | if(this.fieldnameToColumn.get(columnIdentifier) != null) 93 | { 94 | tColumn = this.fieldnameToColumn.get(columnIdentifier); 95 | } 96 | else 97 | { 98 | //create new template column and prepare the column with the default values 99 | tColumn = new TemplateColumn(); 100 | 101 | tColumn.setWidth(tableHeaderColumn.getWidth()); 102 | tColumn.setHasHeaderColumn(true); 103 | 104 | //build header column 105 | final HeaderColumn headerColumn = new HeaderColumn(); 106 | headerColumn.setStyle(this.defaultHeaderStyle.clone()); 107 | headerColumn.setProperty(columnIdentifier); 108 | tColumn.setHeaderColumn(headerColumn); 109 | 110 | //build content column 111 | final ContentColumn contentColumn = new ContentColumn(); 112 | contentColumn.setFieldName(columnIdentifier); 113 | contentColumn.setStyle(this.defaultContentStyle.clone()); 114 | // Search the Model index of the column 115 | int modelIndex = columnModel.getColumn(col).getModelIndex(); 116 | handleColumnValueClass(contentColumn,table.getModel().getColumnClass(modelIndex)); 117 | contentColumn.setProperty(patternConverter.getExportPattern(null)); 118 | tColumn.setContentColumn(contentColumn); 119 | 120 | tColumn.setColumnName(columnIdentifier); 121 | } 122 | 123 | config.addColumn(tColumn); 124 | } 125 | 126 | return config; 127 | } 128 | 129 | 130 | public void handleColumnValueClass(ContentColumn column, Class columnValueClass) 131 | { 132 | column.setColumnValueClass(columnValueClass); 133 | } 134 | 135 | 136 | @Override 137 | public void setPredefinedColumnMap(HashMap fieldnameToColumn) 138 | { 139 | this.fieldnameToColumn = fieldnameToColumn; 140 | } 141 | 142 | @Override 143 | public void setDefaultContentColumnStyle(ColumnStyle style) 144 | { 145 | this.defaultContentStyle = style; 146 | } 147 | 148 | 149 | @Override 150 | public void setDefaultHeaderColumnStyle(ColumnStyle style) 151 | { 152 | this.defaultHeaderStyle = style; 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/builder/ExportConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config.builder; 19 | 20 | import xdev.tableexport.config.ColumnStyle; 21 | import xdev.tableexport.config.ContentColumn; 22 | import xdev.tableexport.config.HeaderColumn; 23 | import xdev.tableexport.config.TemplateColumn; 24 | import xdev.tableexport.config.TemplateConfig; 25 | 26 | import java.util.HashMap; 27 | 28 | import net.sf.jasperreports.engine.JasperReport; 29 | 30 | 31 | /** 32 | * Builder used to construct a {@link TemplateConfig}. A {@link TemplateConfig} 33 | * is a pre-configuration object of a {@link JasperReport}. 34 | * 35 | * @author XDEV Software(FHAE) 36 | * 37 | */ 38 | public interface ExportConfigBuilder 39 | { 40 | /** 41 | * Create a default {@link TemplateConfig}. 42 | * 43 | * @return the {@link TemplateConfig} 44 | */ 45 | public TemplateConfig createConfig(); 46 | 47 | /** 48 | * Map a default {@link HeaderColumn} to the caption string ( identifier) 49 | * 50 | * @param fieldnameToColumn 51 | */ 52 | public void setPredefinedColumnMap(HashMap fieldnameToColumn); 53 | 54 | 55 | /** 56 | * Set the default {@link ColumnStyle} for the {@link HeaderColumn}. 57 | */ 58 | public void setDefaultHeaderColumnStyle(final ColumnStyle style); 59 | 60 | 61 | /** 62 | * Set the default {@link ColumnStyle} for the {@link ContentColumn}. 63 | */ 64 | public void setDefaultContentColumnStyle(final ColumnStyle style); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/builder/JTableViewConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config.builder; 19 | import xdev.tableexport.config.ContentColumn; 20 | 21 | import javax.swing.JTable; 22 | 23 | 24 | public class JTableViewConfigBuilder extends DefaultJTableConfigBuilder 25 | { 26 | public JTableViewConfigBuilder(JTable table) 27 | { 28 | super(table); 29 | } 30 | 31 | /** 32 | * Ignore the given columnValueClass and call each time {@link ContentColumn#setColumnValueClass ContentColumn#setColumnValueClass(String.class)}. 33 | * @param column 34 | * @param columnValueClass 35 | */ 36 | @Override 37 | public void handleColumnValueClass(ContentColumn column, Class columnValueClass) 38 | { 39 | super.handleColumnValueClass(column, String.class); 40 | } 41 | 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/builder/VTConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config.builder; 19 | 20 | import java.util.HashMap; 21 | 22 | import javax.swing.SwingConstants; 23 | 24 | import xdev.tableexport.config.ColumnAlignment; 25 | import xdev.tableexport.config.ColumnStyle; 26 | import xdev.tableexport.config.ContentColumn; 27 | import xdev.tableexport.config.DefaultColumnStyle; 28 | import xdev.tableexport.config.HeaderColumn; 29 | import xdev.tableexport.config.TemplateColumn; 30 | import xdev.tableexport.config.TemplateConfig; 31 | import xdev.tableexport.utils.PatternConverter; 32 | import xdev.tableexport.utils.VirtualTableColumnPatternConverter; 33 | import xdev.vt.VirtualTable; 34 | import xdev.vt.VirtualTableColumn; 35 | 36 | 37 | public class VTConfigBuilder implements ExportConfigBuilder 38 | { 39 | 40 | private VirtualTable vt; 41 | private ColumnStyle defaultContentStyle = DefaultColumnStyle.DEFAULT_COLUMN_STYLE; 42 | private ColumnStyle defaultHeaderStyle = DefaultColumnStyle.DEFAULT_HEADER_STYLE; 43 | private PatternConverter> patternConverter = new VirtualTableColumnPatternConverter(); 44 | private HashMap fieldnameToColumn = new HashMap(); 45 | 46 | 47 | public VTConfigBuilder(VirtualTable vt) 48 | { 49 | this.vt = vt; 50 | } 51 | 52 | 53 | @Override 54 | public TemplateConfig createConfig() 55 | { 56 | final TemplateConfig config = new TemplateConfig(); 57 | 58 | config.setSheetName(this.vt.getName()); 59 | 60 | for(VirtualTableColumn vtColumn : this.vt.columns()) 61 | { 62 | if(!vtColumn.isVisible()) 63 | continue; 64 | 65 | final String columnIdentifier = vtColumn.getName(); 66 | 67 | // Create templatecolumn 68 | TemplateColumn tColumn = null; 69 | if(this.fieldnameToColumn.get(columnIdentifier) != null) 70 | { 71 | tColumn = this.fieldnameToColumn.get(columnIdentifier); 72 | } 73 | else 74 | { 75 | 76 | // create new template column and prepare the column with the 77 | // default values 78 | tColumn = new TemplateColumn(); 79 | 80 | tColumn.setWidth(vtColumn.getPreferredWidth()); 81 | tColumn.setHasHeaderColumn(true); 82 | 83 | // build header column 84 | tColumn.setHasHeaderColumn(true); 85 | final HeaderColumn headerColumn = new HeaderColumn(); 86 | headerColumn.setStyle(this.defaultHeaderStyle.clone()); 87 | headerColumn.setProperty(columnIdentifier); 88 | tColumn.setHeaderColumn(headerColumn); 89 | 90 | // build content column 91 | final ContentColumn contentColumn = new ContentColumn(); 92 | contentColumn.setFieldName(vtColumn.getName()); 93 | contentColumn.setColumnValueClass(vtColumn.getType().getJavaClass()); 94 | contentColumn.setStyle(this.defaultContentStyle.clone()); 95 | contentColumn.setProperty(patternConverter.getExportPattern(vtColumn)); 96 | contentColumn.getStyle().setHorizontalAlignment(getColumnAlignmentFromVtAlignment( 97 | this.vt.getColumn(columnIdentifier).getHorizontalAlignment())); 98 | 99 | tColumn.setContentColumn(contentColumn); 100 | tColumn.setColumnName(vtColumn.getName()); 101 | } 102 | 103 | config.addColumn(tColumn); 104 | } 105 | 106 | return config; 107 | } 108 | 109 | 110 | /** 111 | * Changes the VT-HorizontalAlignment to a 112 | * ContentColumn-HorizontalAlignment. 113 | * 114 | * @param vtAlignment 115 | * {@link SwingConstants} with the alignment 116 | * @return {@link ColumnAlignment} suitable for the VT-HorizontalAlignment, 117 | * of {@link ColumnAlignment}.LEFT if it isn't (VT-HorizontalAlignment)RIGHT,LEFT,CENTER. 118 | */ 119 | private ColumnAlignment getColumnAlignmentFromVtAlignment(int vtAlignment) 120 | { 121 | switch(vtAlignment) 122 | { 123 | case SwingConstants.CENTER: 124 | return ColumnAlignment.CENTER; 125 | 126 | case SwingConstants.LEFT: 127 | return ColumnAlignment.LEFT; 128 | 129 | case SwingConstants.RIGHT: 130 | return ColumnAlignment.RIGHT; 131 | 132 | default: 133 | return ColumnAlignment.LEFT; 134 | 135 | } 136 | 137 | } 138 | 139 | 140 | @Override 141 | public void setPredefinedColumnMap(HashMap fieldnameToColumn) 142 | { 143 | this.fieldnameToColumn = fieldnameToColumn; 144 | } 145 | 146 | 147 | @Override 148 | public void setDefaultContentColumnStyle(ColumnStyle style) 149 | { 150 | this.defaultContentStyle = style; 151 | } 152 | 153 | 154 | @Override 155 | public void setDefaultHeaderColumnStyle(ColumnStyle style) 156 | { 157 | this.defaultHeaderStyle = style; 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/config/builder/XdevTableConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.config.builder; 19 | 20 | import java.util.HashMap; 21 | 22 | import javax.swing.JTable; 23 | import javax.swing.table.TableColumnModel; 24 | 25 | import xdev.tableexport.config.ColumnStyle; 26 | import xdev.tableexport.config.ContentColumn; 27 | import xdev.tableexport.config.DefaultColumnStyle; 28 | import xdev.tableexport.config.HeaderColumn; 29 | import xdev.tableexport.config.TemplateColumn; 30 | import xdev.tableexport.config.TemplateConfig; 31 | import xdev.tableexport.utils.PatternConverter; 32 | import xdev.tableexport.utils.VirtualTableColumnPatternConverter; 33 | import xdev.ui.VirtualTableEditor; 34 | import xdev.vt.VirtualTable; 35 | import xdev.vt.VirtualTableColumn; 36 | import xdev.vt.VirtualTableWrapper; 37 | 38 | 39 | /** 40 | * The {@link XdevTableConfigBuilder} class provides a easy way to analyzes 41 | * {@code T} and create a {@link TemplateConfig}. 42 | * 43 | * @author XDEV Software(FHAE) 44 | * 45 | * @param 46 | * The implementor's type 47 | */ 48 | public class XdevTableConfigBuilder implements 49 | ExportConfigBuilder 50 | { 51 | private T table; 52 | private ColumnStyle defaultContentStyle = DefaultColumnStyle.DEFAULT_COLUMN_STYLE; 53 | private ColumnStyle defaultHeaderStyle = DefaultColumnStyle.DEFAULT_HEADER_STYLE; 54 | private PatternConverter> patternConverter = new VirtualTableColumnPatternConverter(); 55 | private HashMap fieldnameToColumn = new HashMap(); 56 | 57 | 58 | /** 59 | * Create a instance of the {@link XdevTableConfigBuilder}. 60 | * 61 | * @param table 62 | * a object that extends {@link JTable} and 63 | * {@link VirtualTableEditor} 64 | */ 65 | public XdevTableConfigBuilder(T table) 66 | { 67 | this.table = table; 68 | } 69 | 70 | 71 | @Override 72 | public TemplateConfig createConfig() 73 | { 74 | final TemplateConfig config = new TemplateConfig(); 75 | 76 | final VirtualTableWrapper vtWrapper = this.table.getVirtualTableWrapper(); 77 | final VirtualTable vt = vtWrapper.getVirtualTable(); 78 | 79 | config.setSheetName(vt.getName()); 80 | 81 | final TableColumnModel columnModel = this.table.getColumnModel(); 82 | for(int col = 0; col < columnModel.getColumnCount(); col++) 83 | { 84 | // Search the Model(VT) index of the column 85 | int modelIndex = columnModel.getColumn(col).getModelIndex(); 86 | // Convert the column index to the vt column index 87 | int vtColumnIndex = vtWrapper.viewToModelColumn(modelIndex); 88 | final VirtualTableColumn vtColumn = vt.getColumnAt(vtColumnIndex); 89 | final String columnIdentifier = getColumnIdentifier(vtColumn); 90 | 91 | 92 | // Create templatecolumn 93 | TemplateColumn tColumn = null; 94 | 95 | if(this.fieldnameToColumn.get(columnIdentifier) != null) 96 | { 97 | tColumn = this.fieldnameToColumn.get(columnIdentifier); 98 | } 99 | else 100 | { 101 | // create new template column and prepare the column with the 102 | // default values 103 | tColumn = new TemplateColumn(); 104 | 105 | tColumn.setWidth(vtColumn.getPreferredWidth()); 106 | tColumn.setHasHeaderColumn(true); 107 | 108 | // build header column 109 | tColumn.setHasHeaderColumn(true); 110 | final HeaderColumn headerColumn = new HeaderColumn(); 111 | headerColumn.setStyle(this.defaultHeaderStyle.clone()); 112 | headerColumn.setProperty(columnIdentifier); 113 | 114 | tColumn.setHeaderColumn(headerColumn); 115 | 116 | // build content column 117 | final ContentColumn contentColumn = new ContentColumn(); 118 | contentColumn.setFieldName(vtColumn.getName()); 119 | contentColumn.setColumnValueClass(vtColumn.getType().getJavaClass()); 120 | contentColumn.setProperty(patternConverter.getExportPattern(vtColumn)); 121 | contentColumn.setStyle(this.defaultContentStyle.clone()); 122 | tColumn.setContentColumn(contentColumn); 123 | 124 | tColumn.setContentColumn(contentColumn); 125 | tColumn.setColumnName(vtColumn.getName()); 126 | } 127 | 128 | config.addColumn(tColumn); 129 | } 130 | 131 | return config; 132 | } 133 | 134 | 135 | private String getColumnIdentifier(final VirtualTableColumn vtColumn) 136 | { 137 | return vtColumn.getCaption().equals("") ? vtColumn.getName() : vtColumn.getCaption(); 138 | } 139 | 140 | 141 | @Override 142 | public void setPredefinedColumnMap(HashMap fieldnameToColumn) 143 | { 144 | this.fieldnameToColumn = fieldnameToColumn; 145 | } 146 | 147 | 148 | @Override 149 | public void setDefaultContentColumnStyle(ColumnStyle style) 150 | { 151 | this.defaultContentStyle = style; 152 | } 153 | 154 | 155 | @Override 156 | public void setDefaultHeaderColumnStyle(ColumnStyle style) 157 | { 158 | this.defaultHeaderStyle = style; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/datasource/DefaultBooleanToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.datasource; 19 | 20 | import java.util.Locale; 21 | 22 | import xdev.tableexport.utils.DataSourceResourceBundle; 23 | 24 | 25 | /** 26 | * This ValueToStringConverter convert a {@link Boolean} value to a 27 | * {@link String}. To determine the correct {@link String} the 28 | * {@link DataSourceResourceBundle} is used. 29 | * 30 | *

31 | * Waring: The local's {@link Locale#GERMANY} and 32 | * {@link Locale#US} are supported. 33 | *

34 | * 35 | * @author XDEV Software (FHAE) 36 | * 37 | * @see DataSourceResourceBundle 38 | * 39 | */ 40 | public class DefaultBooleanToStringConverter implements ValueConverter 41 | { 42 | private String trueValue = DataSourceResourceBundle 43 | .getString("jtableRendererDataSource.trueValue"); 44 | private String falseValue = DataSourceResourceBundle 45 | .getString("jtableRendererDataSource.falseValue"); 46 | 47 | /** 48 | * Convert the given {@link Boolean} into a String. 49 | * The values of the {@link Boolean} determine by reading the {@link DataSourceResourceBundle}. 50 | * 51 | * 52 | * @param value 53 | * a {@link Boolean} to convert 54 | * @return a the local specific {@link String} value. If the {@code value} is null a empty string is returned. 55 | * 56 | */ 57 | @Override 58 | public String getValue(Boolean value) 59 | { 60 | if(value==null) return ""; 61 | if(value) 62 | { 63 | return trueValue; 64 | } 65 | else 66 | { 67 | return falseValue; 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/datasource/ValueConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.datasource; 19 | 20 | /** 21 | * 22 | * ValueConverter to convert an input type {@code I} into a the output type 23 | * {@code O}. 24 | * 25 | * @author XDEV Software(FHAE) 26 | * 27 | * @param 28 | * the input type 29 | * @param 30 | * the output type 31 | */ 32 | public interface ValueConverter 33 | { 34 | /** 35 | * Convert the given input type {@code I} into the output type {@code O}. 36 | * 37 | * @param value 38 | * the input type instance to be mapped to an output type 39 | * instance. 40 | * @return the output type instance for the passed input type instance. 41 | * 42 | */ 43 | public O getValue(I value); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/datasource/XdevJTableRendererDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.datasource; 19 | 20 | import java.awt.Component; 21 | 22 | import javax.swing.JCheckBox; 23 | import javax.swing.JLabel; 24 | import javax.swing.JTable; 25 | import javax.swing.table.TableCellRenderer; 26 | 27 | import xdev.lang.NotNull; 28 | import xdev.reports.jasper.JRJTableRendererDataSource; 29 | 30 | 31 | /** 32 | * 33 | * A data source implementation that allows to access the renderer output of a 34 | * {@link JTable}. 35 | * 36 | *

37 | * Waring: Works only for columns which are rendered by a 38 | * {@link TableCellRenderer} extending {@link JLabel} or {@link JCheckBox}. 39 | * If the {@link TableCellRenderer} extending a {@link JCheckBox} the {@link ValueConverter} is used to determine the {@link String} value. 40 | *

41 | * 42 | * @author XDEV Software(FHAE) 43 | * 44 | * @see ValueConverter 45 | * @see DefaultBooleanToStringConverter 46 | * 47 | */ 48 | public class XdevJTableRendererDataSource extends JRJTableRendererDataSource 49 | { 50 | private ValueConverter booleanToStringConverter = new DefaultBooleanToStringConverter(); 51 | 52 | 53 | /** 54 | * Straight forward constructor to wrap a given (non-null) {@link JTable}. 55 | * 56 | * @param table 57 | * the {@link JTable} to wrap 58 | */ 59 | public XdevJTableRendererDataSource(@NotNull final JTable table) 60 | { 61 | super(table); 62 | } 63 | 64 | 65 | public void setBooleanToStringConverter(ValueConverter booleanToStringConverter) 66 | { 67 | this.booleanToStringConverter = booleanToStringConverter; 68 | } 69 | 70 | /** 71 | * Returns the {@link TableCellRenderer} value for the described item. 72 | * 73 | * @param value 74 | * value to be processed by the renderer 75 | * @param row 76 | * rowIndex of the {@link TableCellRenderer} to use 77 | * @param col 78 | * columnIndex of the {@link TableCellRenderer} to use 79 | * @return the {@link TableCellRenderer} value for the described item. 80 | */ 81 | protected String getRendererValue(final Object value, final int row, final int col) 82 | { 83 | Component cpn = this.table.getCellRenderer(row,col).getTableCellRendererComponent( 84 | this.table,value,false,false,row,col); 85 | 86 | if(cpn instanceof JLabel) 87 | { 88 | return ((JLabel)cpn).getText(); 89 | } 90 | else if(cpn instanceof JCheckBox) 91 | { 92 | return booleanToStringConverter.getValue(((JCheckBox)cpn).isSelected()); 93 | } 94 | else 95 | { 96 | return ""; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/datasource/XdevTableDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.datasource; 19 | 20 | import javax.swing.JTable; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRField; 24 | import net.sf.jasperreports.engine.JRRewindableDataSource; 25 | import xdev.lang.NotNull; 26 | import xdev.ui.TableSupport; 27 | import xdev.ui.VirtualTableEditor; 28 | import xdev.ui.XdevTable; 29 | import xdev.vt.VirtualTable; 30 | import xdev.vt.VirtualTableColumn; 31 | import xdev.vt.XdevClob; 32 | 33 | 34 | /** 35 | * 36 | * {@link XdevTable} data source implementation that allows to access 37 | * the data of a {@link JTable} with a {@link VirtualTableEditor}. 38 | * 39 | *

40 | * Specially column moving and sorting are supported. 41 | *

42 | * 43 | * 44 | * @author XDEV Software (FHAE) 45 | * 46 | * @param 47 | * type of the table 48 | * 49 | */ 50 | public class XdevTableDataSource implements 51 | JRRewindableDataSource 52 | { 53 | 54 | /** 55 | * The current row index. Initialized to -1 as first row is retrieved by the 56 | * first next() call. 57 | */ 58 | protected int currentRowIndex = -1; 59 | 60 | private final T table; 61 | private final VirtualTable vt; 62 | 63 | 64 | /** 65 | * Straight forward constructor to wrap a given (non-null) 66 | * {@link XdevTable} 67 | * 68 | * @param table 69 | * the T to wrap 70 | */ 71 | public XdevTableDataSource(@NotNull final T table) 72 | { 73 | super(); 74 | if(table == null) 75 | { 76 | throw new IllegalArgumentException("table must not be null"); 77 | } 78 | this.table = table; 79 | this.vt = this.table.getVirtualTableWrapper().getVirtualTable(); 80 | } 81 | 82 | 83 | @Override 84 | public Object getFieldValue(JRField jrField) throws JRException 85 | { 86 | try 87 | { 88 | int index = TableSupport.getTableRowConverter().viewToModel(table,currentRowIndex); 89 | 90 | final VirtualTableColumn col= vt.getColumn(jrField.getName()); 91 | switch(col.getType()) 92 | { 93 | 94 | case BINARY: 95 | return "BINARY"; 96 | 97 | case LONGVARBINARY: 98 | return "LONGVARBINARY"; 99 | 100 | case VARBINARY: 101 | return "VARBINARY"; 102 | 103 | case BLOB: 104 | return "BLOB"; 105 | 106 | case CLOB: 107 | 108 | final XdevClob xClob = ((XdevClob)this.vt.getValueAt(index,jrField.getName())); 109 | return xClob == null ? null : xClob.toString(); 110 | default: 111 | return vt.getRow(index).get(vt.getColumnIndex(jrField.getName())); 112 | } 113 | } 114 | catch(Exception e) 115 | { 116 | throw new JRException("Unable to get value for field '" + jrField.getName(),e); 117 | } 118 | } 119 | 120 | 121 | /** 122 | * Moves the internal row cursor to the next row. 123 | * 124 | * @return if the internal row cursor points to an existing row 125 | * @throws JRException 126 | * can never happen 127 | */ 128 | @Override 129 | public boolean next() throws JRException 130 | { 131 | return ++this.currentRowIndex < this.table.getRowCount(); 132 | } 133 | 134 | 135 | /** 136 | * {@inheritDoc} 137 | */ 138 | @Override 139 | public void moveFirst() throws JRException 140 | { 141 | this.currentRowIndex = -1; 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/ExportException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export; 19 | 20 | /** 21 | *

22 | * This is the base class for exception thrown if any error occurs while processing an export. 23 | *

24 | * @author XDEV Software(FHAE) 25 | */ 26 | public class ExportException extends Exception 27 | { 28 | 29 | /** 30 | * 31 | */ 32 | private static final long serialVersionUID = -3114768551530983515L; 33 | 34 | 35 | /** 36 | * Constructs an {@code ExportException} with the specified 37 | * detail message and nested exception. 38 | * 39 | * @param message the detail message 40 | * @param cause the nested exception 41 | */ 42 | public ExportException(String message, Throwable cause) 43 | { 44 | super(message,cause); 45 | } 46 | 47 | 48 | /** 49 | * Constructs an {@code ExportException} with the specified 50 | * detail message. 51 | * 52 | * @param message the detail message 53 | */ 54 | public ExportException(String message) 55 | { 56 | super(message); 57 | } 58 | 59 | 60 | /** 61 | * Constructs an {@code ExportException} with the specified 62 | * nested exception. 63 | * 64 | * @param cause the nested exception 65 | */ 66 | public ExportException(Throwable cause) 67 | { 68 | super(cause); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/ReportExporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export; 19 | 20 | import java.util.HashMap; 21 | 22 | import net.sf.jasperreports.engine.JRRewindableDataSource; 23 | import net.sf.jasperreports.engine.JasperFillManager; 24 | import net.sf.jasperreports.engine.JasperPrint; 25 | import net.sf.jasperreports.engine.JasperReport; 26 | import xdev.tableexport.export.writer.ExportWriter; 27 | 28 | 29 | public class ReportExporter 30 | { 31 | 32 | private JasperReport internalReport; 33 | private JRRewindableDataSource internalDataSource; 34 | private JasperPrint jasperPrint; 35 | private ExportWriter exportWriter; 36 | 37 | 38 | public ReportExporter(JasperReport report, JRRewindableDataSource ds, ExportWriter writer) 39 | { 40 | this.internalDataSource = ds; 41 | this.internalReport = report; 42 | this.exportWriter = writer; 43 | } 44 | 45 | 46 | public void export() throws ExportException, IllegalArgumentException 47 | { 48 | if(this.internalDataSource == null) 49 | { 50 | throw new IllegalArgumentException("dataSource should not be null"); 51 | } 52 | if(this.internalReport == null) 53 | { 54 | throw new IllegalArgumentException("report should not be null"); 55 | } 56 | 57 | try 58 | { 59 | this.jasperPrint = JasperFillManager.fillReport(this.internalReport, 60 | new HashMap(),this.internalDataSource); 61 | } 62 | catch(Exception e) 63 | { 64 | throw new ExportException("The Report can't fill." + e.getMessage(), e); 65 | } 66 | 67 | this.exportWriter.write(this.jasperPrint); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/CSVToFileWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.File; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRExporter; 24 | import net.sf.jasperreports.engine.JRExporterParameter; 25 | import net.sf.jasperreports.engine.JasperPrint; 26 | import net.sf.jasperreports.engine.export.JRCsvExporter; 27 | 28 | 29 | /** 30 | * Write the generated report object into CSV format. 31 | * 32 | *

33 | * The generated CSV content is placed into a {@code File}. 34 | *

35 | * 36 | * @author XDEV Software(FHAE) 37 | */ 38 | @SuppressWarnings("deprecation") 39 | public class CSVToFileWriter implements ExportWriter 40 | { 41 | 42 | private final File file; 43 | 44 | 45 | /** 46 | * Constructs a {@link CSVToFileWriter} object given a {@link File} object. 47 | * 48 | * @param file a {@link File} object to write to. 49 | */ 50 | public CSVToFileWriter(final File file) 51 | { 52 | this.file = file; 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public void write(JasperPrint jasperPrint) throws ExportWriterException 60 | { 61 | final JRExporter exporter = new JRCsvExporter(); 62 | try 63 | { 64 | exporter.setParameter(JRExporterParameter.OUTPUT_FILE,this.file); 65 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 66 | 67 | exporter.exportReport(); 68 | } 69 | catch(JRException e) 70 | { 71 | throw new ExportWriterException(e); 72 | } 73 | catch(Exception ie) 74 | { 75 | throw new ExportWriterException(ie); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/CSVToOutputStreamWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.OutputStream; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRExporter; 24 | import net.sf.jasperreports.engine.JRExporterParameter; 25 | import net.sf.jasperreports.engine.JasperPrint; 26 | import net.sf.jasperreports.engine.export.JRCsvExporter; 27 | 28 | 29 | /** 30 | * Write the generated report object into CSV format. 31 | * 32 | *

33 | * The generated CSV content is placed into a {@code OutputStream}. 34 | *

35 | * 36 | * @author XDEV Software(FHAE) 37 | */ 38 | @SuppressWarnings("deprecation") 39 | public class CSVToOutputStreamWriter implements ExportWriter 40 | { 41 | private final OutputStream stream; 42 | 43 | 44 | /** 45 | * Constructs a {@link CSVToOutputStreamWriter} object given a 46 | * {@link OutputStream} object. 47 | * * 48 | * @param stream 49 | * a {@link OutputStream} object to write to. 50 | */ 51 | public CSVToOutputStreamWriter(final OutputStream stream) 52 | { 53 | this.stream = stream; 54 | } 55 | 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public void write(JasperPrint jasperPrint) throws ExportWriterException 62 | { 63 | final JRExporter exporter = new JRCsvExporter(); 64 | try 65 | { 66 | exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,this.stream); 67 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 68 | 69 | exporter.exportReport(); 70 | } 71 | catch(JRException e) 72 | { 73 | throw new ExportWriterException(e); 74 | } 75 | catch(IllegalArgumentException ie) 76 | { 77 | throw new ExportWriterException(ie); 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/ExportWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import net.sf.jasperreports.engine.JasperPrint; 21 | 22 | 23 | /** 24 | * All reports exporting in XDEV is done through this interface. 25 | * There is an implementation of this interface for every export format (like PDF, XLS) that XDEV supports at the moment. 26 | * 27 | * 28 | * @author XDEV Software(FHAE) 29 | */ 30 | public interface ExportWriter 31 | { 32 | 33 | /** 34 | * Starts the export process and write the report. 35 | * 36 | * @param jasperPrint the generated {@link JasperPrint} object 37 | * @throws ExportWriterException 38 | */ 39 | public void write(final JasperPrint jasperPrint) throws ExportWriterException; 40 | 41 | 42 | 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/ExportWriterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import xdev.tableexport.export.*; 21 | 22 | 23 | /** 24 | * An {@code ExportWriterException} is a {@code ExportException} 25 | * thrown if an attempt to write the report fails. 26 | * 27 | * @author XDEV Software(FHAE) 28 | */ 29 | public class ExportWriterException extends ExportException 30 | { 31 | /** 32 | * 33 | */ 34 | private static final long serialVersionUID = -3338632252117720093L; 35 | 36 | 37 | /** 38 | * Constructs an {@code ExportWriterException} with the specified 39 | * detail message and nested exception. 40 | * 41 | * @param message the detail message 42 | * @param cause the nested exception 43 | */ 44 | public ExportWriterException(String message, Throwable cause) 45 | { 46 | super(message,cause); 47 | } 48 | 49 | 50 | /** 51 | * Constructs an {@code ExportWriterException} with the specified 52 | * detail message. 53 | * 54 | * @param message the detail message 55 | */ 56 | public ExportWriterException(String message) 57 | { 58 | super(message); 59 | } 60 | 61 | 62 | /** 63 | * Constructs an {@code ExportWriterException} with the specified 64 | * nested exception. 65 | * 66 | * @param cause the nested exception 67 | */ 68 | public ExportWriterException(Throwable cause) 69 | { 70 | super(cause); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/HtmlToFileWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.File; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JasperExportManager; 24 | import net.sf.jasperreports.engine.JasperPrint; 25 | 26 | 27 | /** 28 | * Write the generated report object into HTML format. 29 | * 30 | *

31 | * The generated HTML content is placed into a {@code File}. 32 | *

33 | * 34 | * @author XDEV Software(FHAE) 35 | */ 36 | public class HtmlToFileWriter implements ExportWriter 37 | { 38 | private final File file; 39 | 40 | 41 | /** 42 | * Constructs a {@link HtmlToFileWriter} object given a {@link File} object. 43 | * 44 | * 45 | * @param file a {@link File} object to write to. 46 | */ 47 | public HtmlToFileWriter(final File file) 48 | { 49 | this.file = file; 50 | } 51 | 52 | 53 | /** 54 | * {@inheritDoc} 55 | */ 56 | @Override 57 | public void write(JasperPrint jasperPrint) throws ExportWriterException 58 | { 59 | try 60 | { 61 | JasperExportManager.exportReportToHtmlFile(jasperPrint,this.file.getAbsolutePath()); 62 | } 63 | catch(JRException e) 64 | { 65 | throw new ExportWriterException(e); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/HtmlToOutputStreamWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.OutputStream; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRExporterParameter; 24 | import net.sf.jasperreports.engine.JasperPrint; 25 | import net.sf.jasperreports.engine.export.HtmlExporter; 26 | 27 | 28 | /** 29 | * Write the generated report object into HTML format. 30 | * 31 | *

32 | * The generated HTML content is placed into a {@code OutputStream}. 33 | *

34 | * 35 | * @author XDEV Software(FHAE) 36 | */ 37 | @SuppressWarnings("deprecation") 38 | public class HtmlToOutputStreamWriter implements ExportWriter 39 | { 40 | private final OutputStream outputStream; 41 | 42 | 43 | /** 44 | * Constructs a {@link HtmlToOutputStreamWriter} object given a 45 | * {@link OutputStream} object. 46 | * 47 | * 48 | * @param outputStream 49 | * a {@link OutputStream} object to write to. 50 | */ 51 | public HtmlToOutputStreamWriter(final OutputStream outputStream) 52 | { 53 | this.outputStream = outputStream; 54 | } 55 | 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public void write(final JasperPrint jasperPrint) throws ExportWriterException 62 | { 63 | try 64 | { 65 | final HtmlExporter exporter = new HtmlExporter(); 66 | 67 | exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,this.outputStream); 68 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 69 | exporter.exportReport(); 70 | 71 | } 72 | catch(final JRException e) 73 | { 74 | throw new ExportWriterException(e); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/PdfToFileWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | import java.io.File; 20 | 21 | import net.sf.jasperreports.engine.JRException; 22 | import net.sf.jasperreports.engine.JasperExportManager; 23 | import net.sf.jasperreports.engine.JasperPrint; 24 | 25 | 26 | /** 27 | * Write the generated report object into PDF format. 28 | * 29 | *

30 | * The generated PDF content is placed into a {@code File}. 31 | *

32 | * 33 | * @author XDEV Software(FHAE) 34 | */ 35 | public class PdfToFileWriter implements ExportWriter 36 | { 37 | private final File file; 38 | 39 | /** 40 | * Constructs a {@link PdfToFileWriter} object given a {@link File} object. 41 | * 42 | * 43 | * @param file a {@link File} object to write to. 44 | */ 45 | public PdfToFileWriter(final File file) 46 | { 47 | this.file = file; 48 | } 49 | 50 | /** 51 | * {@inheritDoc} 52 | */ 53 | @Override 54 | public void write(JasperPrint jasperPrint) 55 | throws ExportWriterException 56 | { 57 | try 58 | { 59 | JasperExportManager.exportReportToPdfFile(jasperPrint,this.file.getAbsolutePath()); 60 | } 61 | catch(JRException e) 62 | { 63 | throw new ExportWriterException(e); 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/PdfToOutputStreamWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.OutputStream; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JasperExportManager; 24 | import net.sf.jasperreports.engine.JasperPrint; 25 | 26 | 27 | /** 28 | * Write the generated report object into PDF format. 29 | * 30 | *

31 | * The generated PDF content is placed into a {@code OutputStream}. 32 | *

33 | * 34 | * @author XDEV Software(FHAE) 35 | */ 36 | public class PdfToOutputStreamWriter implements ExportWriter 37 | { 38 | private final OutputStream outputstream; 39 | 40 | 41 | /** 42 | * Constructs a {@link PdfToOutputStreamWriter} object given a {@link OutputStream} object. 43 | * 44 | * 45 | * @param outputstream 46 | * a {@link OutputStream} object to write to. 47 | */ 48 | public PdfToOutputStreamWriter(final OutputStream outputstream) 49 | { 50 | this.outputstream = outputstream; 51 | } 52 | 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | @Override 58 | public void write(JasperPrint jasperPrint) throws ExportWriterException 59 | { 60 | try 61 | { 62 | JasperExportManager.exportReportToPdfStream(jasperPrint,this.outputstream); 63 | } 64 | catch(JRException e) 65 | { 66 | throw new ExportWriterException(e); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/PrintWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import net.sf.jasperreports.engine.JRException; 21 | import net.sf.jasperreports.engine.JRExporterParameter; 22 | import net.sf.jasperreports.engine.JasperPrint; 23 | import net.sf.jasperreports.engine.export.JRPrintServiceExporter; 24 | import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter; 25 | 26 | 27 | @SuppressWarnings("deprecation") 28 | public class PrintWriter implements ExportWriter 29 | { 30 | 31 | private final boolean displayPageDialog; 32 | private final boolean displayPageDialogOnlyOnce; 33 | private final boolean displayPrintDialog; 34 | private final boolean displayPrintDialogOnlyOnce; 35 | 36 | 37 | public PrintWriter(boolean displayPageDialog, boolean displayPageDialogOnlyOnce, 38 | boolean displayPrintDialog, boolean displayPrintDialogOnlyOnce) 39 | { 40 | this.displayPageDialog = displayPageDialog; 41 | this.displayPageDialogOnlyOnce = displayPageDialogOnlyOnce; 42 | this.displayPrintDialog = displayPrintDialog; 43 | this.displayPrintDialogOnlyOnce = displayPrintDialogOnlyOnce; 44 | } 45 | 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public void write(JasperPrint jasperPrint) throws ExportWriterException 52 | { 53 | try 54 | { 55 | final JRPrintServiceExporter exporter = new JRPrintServiceExporter(); 56 | 57 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 58 | exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, 59 | this.displayPageDialog); 60 | exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG_ONLY_ONCE, 61 | this.displayPageDialogOnlyOnce); 62 | exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, 63 | this.displayPrintDialog); 64 | exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG_ONLY_ONCE, 65 | this.displayPrintDialogOnlyOnce); 66 | exporter.exportReport(); 67 | } 68 | catch(JRException e) 69 | { 70 | throw new ExportWriterException(e); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/ReportToPreviewWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | import net.sf.jasperreports.engine.JasperPrint; 20 | import net.sf.jasperreports.view.JasperViewer; 21 | 22 | public class ReportToPreviewWriter implements ExportWriter 23 | { 24 | 25 | 26 | /** 27 | * Show the report in a the {@link JasperViewer}. 28 | * 29 | * @param jasperPrint the generated {@link JasperPrint} object 30 | * 31 | */ 32 | @Override 33 | public void write(JasperPrint jasperPrint) throws ExportWriterException 34 | { 35 | JasperViewer.viewReport(jasperPrint,false); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/RtfToFileWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.File; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRExporter; 24 | import net.sf.jasperreports.engine.JRExporterParameter; 25 | import net.sf.jasperreports.engine.JasperPrint; 26 | import net.sf.jasperreports.engine.export.JRRtfExporter; 27 | 28 | 29 | /** 30 | * Write the generated report object into RTF format. 31 | * 32 | *

33 | * The generated RTF content is placed into a {@code File}. 34 | *

35 | * 36 | * @author XDEV Software(FHAE) 37 | */ 38 | @SuppressWarnings("deprecation") 39 | public class RtfToFileWriter implements ExportWriter 40 | { 41 | 42 | private final File file; 43 | 44 | 45 | /** 46 | * Constructs a {@link RtfToFileWriter} object given a {@link File} object. 47 | * 48 | * @param file a {@link File} object to write to. 49 | */ 50 | public RtfToFileWriter(final File file) 51 | { 52 | this.file = file; 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public void write(JasperPrint jasperPrint) throws ExportWriterException 60 | { 61 | final JRExporter exporter = new JRRtfExporter(); 62 | try 63 | { 64 | exporter.setParameter(JRExporterParameter.OUTPUT_FILE,this.file); 65 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 66 | 67 | exporter.exportReport(); 68 | } 69 | catch(JRException e) 70 | { 71 | throw new ExportWriterException(e); 72 | } 73 | catch(Exception ie) 74 | { 75 | throw new ExportWriterException(ie); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/RtfToOutputStreamWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.OutputStream; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRExporter; 24 | import net.sf.jasperreports.engine.JRExporterParameter; 25 | import net.sf.jasperreports.engine.JasperPrint; 26 | import net.sf.jasperreports.engine.export.JRRtfExporter; 27 | 28 | 29 | /** 30 | * Write the generated report object into RTF format. 31 | * 32 | *

33 | * The generated RTF content is placed into a {@code OutputStream}. 34 | *

35 | * 36 | * @author XDEV Software(FHAE) 37 | */ 38 | @SuppressWarnings("deprecation") 39 | public class RtfToOutputStreamWriter implements ExportWriter 40 | { 41 | private final OutputStream stream; 42 | 43 | 44 | /** 45 | * Constructs a {@link RtfToOutputStreamWriter} object given a 46 | * {@link OutputStream} object. 47 | * * 48 | * @param stream 49 | * a {@link OutputStream} object to write to. 50 | */ 51 | public RtfToOutputStreamWriter(final OutputStream stream) 52 | { 53 | this.stream = stream; 54 | } 55 | 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public void write(JasperPrint jasperPrint) throws ExportWriterException 62 | { 63 | final JRExporter exporter = new JRRtfExporter(); 64 | try 65 | { 66 | exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,this.stream); 67 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 68 | 69 | exporter.exportReport(); 70 | } 71 | catch(JRException e) 72 | { 73 | throw new ExportWriterException(e); 74 | } 75 | catch(IllegalArgumentException ie) 76 | { 77 | throw new ExportWriterException(ie); 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/XMLToFileWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.File; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRExporter; 24 | import net.sf.jasperreports.engine.JRExporterParameter; 25 | import net.sf.jasperreports.engine.JasperPrint; 26 | import net.sf.jasperreports.engine.export.JRXmlExporter; 27 | 28 | 29 | /** 30 | * Write the generated report object into XML format. 31 | * 32 | *

33 | * The generated XML content is placed into a {@code File}. 34 | *

35 | * 36 | * @author XDEV Software(FHAE) 37 | */ 38 | @SuppressWarnings("deprecation") 39 | public class XMLToFileWriter implements ExportWriter 40 | { 41 | 42 | private final File file; 43 | 44 | 45 | /** 46 | * Constructs a {@link XMLToFileWriter} object given a {@link File} object. 47 | * 48 | * @param file a {@link File} object to write to. 49 | */ 50 | public XMLToFileWriter(final File file) 51 | { 52 | this.file = file; 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public void write(JasperPrint jasperPrint) throws ExportWriterException 60 | { 61 | final JRExporter exporter = new JRXmlExporter(); 62 | try 63 | { 64 | exporter.setParameter(JRExporterParameter.OUTPUT_FILE,this.file); 65 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 66 | 67 | exporter.exportReport(); 68 | } 69 | catch(JRException e) 70 | { 71 | throw new ExportWriterException(e); 72 | } 73 | catch(Exception ie) 74 | { 75 | throw new ExportWriterException(ie); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/XMLToOutputStreamWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.OutputStream; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JRExporter; 24 | import net.sf.jasperreports.engine.JRExporterParameter; 25 | import net.sf.jasperreports.engine.JasperPrint; 26 | import net.sf.jasperreports.engine.export.JRXmlExporter; 27 | 28 | 29 | /** 30 | * Write the generated report object into XML format. 31 | * 32 | *

33 | * The generated XML content is placed into a {@code OutputStream}. 34 | *

35 | * 36 | * @author XDEV Software(FHAE) 37 | */ 38 | @SuppressWarnings("deprecation") 39 | public class XMLToOutputStreamWriter implements ExportWriter 40 | { 41 | private final OutputStream stream; 42 | 43 | 44 | /** 45 | * Constructs a {@link XMLToOutputStreamWriter} object given a 46 | * {@link OutputStream} object. 47 | * * 48 | * @param stream 49 | * a {@link OutputStream} object to write to. 50 | */ 51 | public XMLToOutputStreamWriter(final OutputStream stream) 52 | { 53 | this.stream = stream; 54 | } 55 | 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public void write(JasperPrint jasperPrint) throws ExportWriterException 62 | { 63 | final JRExporter exporter = new JRXmlExporter(); 64 | try 65 | { 66 | exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,this.stream); 67 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 68 | 69 | exporter.exportReport(); 70 | } 71 | catch(JRException e) 72 | { 73 | throw new ExportWriterException(e); 74 | } 75 | catch(IllegalArgumentException ie) 76 | { 77 | throw new ExportWriterException(ie); 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/XlsToFileWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import xdev.tableexport.utils.ExportUtils; 21 | 22 | import java.io.File; 23 | 24 | import net.sf.jasperreports.engine.JRException; 25 | import net.sf.jasperreports.engine.JasperPrint; 26 | import net.sf.jasperreports.engine.export.JRXlsExporter; 27 | 28 | 29 | /** 30 | * Write the generated report object into XLS format. 31 | * 32 | *

33 | * The generated XLS content is placed into a {@code File}. 34 | *

35 | * 36 | * @author XDEV Software(FHAE) 37 | */ 38 | public class XlsToFileWriter implements ExportWriter 39 | { 40 | private final File file; 41 | private final String sheetName; 42 | private final Boolean freezeHeadline; 43 | 44 | 45 | /** 46 | * Constructs a {@link XlsToFileWriter} object given a {@link File} object. 47 | * No freeze headline are created. 48 | * 49 | *

50 | * Note - Excel allows sheet names up to 31 chars in length but other 51 | * applications allow more. Excel does not crash with names longer than 31 52 | * chars, but silently truncates such names to 31 chars. 53 | *

54 | * 55 | * @param file 56 | * a {@link File} object to write to. 57 | * @param sheetName 58 | * the excel sheet name 59 | */ 60 | public XlsToFileWriter(final File file, final String sheetName) 61 | { 62 | this(file,sheetName,false); 63 | } 64 | 65 | 66 | /** 67 | * Constructs a {@link XlsToFileWriter} object given a {@link File} object. 68 | * 69 | *

70 | * Note - Excel allows sheet names up to 31 chars in length but other 71 | * applications allow more. Excel does not crash with names longer than 31 72 | * chars, but silently truncates such names to 31 chars. 73 | *

74 | * 75 | * @param file 76 | * a {@link File} object to write to. 77 | * @param freezeHeadline 78 | * if true the freeze pane for the first row is 79 | * @param sheetName 80 | * the excel sheet name 81 | */ 82 | public XlsToFileWriter(final File file, final String sheetName, final Boolean freezeHeadline) 83 | { 84 | this.file = file; 85 | this.sheetName = sheetName; 86 | this.freezeHeadline = freezeHeadline; 87 | } 88 | 89 | 90 | /** 91 | * {@inheritDoc} 92 | */ 93 | @Override 94 | public void write(JasperPrint jasperPrint) throws ExportWriterException 95 | { 96 | final JRXlsExporter exporterXLS = new JRXlsExporter(); 97 | try 98 | { 99 | ExportUtils.prepareExcelExporter(exporterXLS,jasperPrint,this.sheetName, 100 | this.freezeHeadline,this.file); 101 | exporterXLS.exportReport(); 102 | } 103 | catch(JRException e) 104 | { 105 | throw new ExportWriterException(e); 106 | } 107 | catch(Exception ie) 108 | { 109 | throw new ExportWriterException(ie); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/XlsToOutputStreamWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.OutputStream; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JasperPrint; 24 | import net.sf.jasperreports.engine.export.JRXlsExporter; 25 | import xdev.tableexport.utils.ExportUtils; 26 | 27 | 28 | /** 29 | * Write the generated report object into XLS format. 30 | * 31 | *

32 | * The generated XLS content is placed into a {@code OutputStream}. 33 | *

34 | * 35 | * @author XDEV Software(FHAE) 36 | */ 37 | public class XlsToOutputStreamWriter implements ExportWriter 38 | { 39 | 40 | private final OutputStream stream; 41 | private final String sheetName; 42 | private final Boolean freezeHeadline; 43 | 44 | /** 45 | * Constructs a {@link XlsToOutputStreamWriter} object given a {@link OutputStream} object. 46 | * No freeze headline are created. 47 | * 48 | *

49 | * Note - Excel allows sheet names up to 31 chars in length but other applications allow more. 50 | * Excel does not crash with names longer than 31 chars, but silently truncates such names to 51 | * 31 chars. 52 | *

53 | * 54 | * @param stream a {@link OutputStream} object to write to. 55 | * @param sheetName the excel sheet name 56 | */ 57 | public XlsToOutputStreamWriter(final OutputStream stream, final String sheetName) 58 | { 59 | this(stream,sheetName,false); 60 | } 61 | 62 | /** 63 | * Constructs a {@link XlsToOutputStreamWriter} object given a {@link OutputStream} object. 64 | * 65 | *

66 | * Note - Excel allows sheet names up to 31 chars in length but other applications allow more. 67 | * Excel does not crash with names longer than 31 chars, but silently truncates such names to 68 | * 31 chars. 69 | *

70 | * 71 | * @param stream a {@link OutputStream} object to write to. 72 | * @param freezeHeadline if true the freeze pane for the first row is 73 | * created 74 | * @param sheetName the excel sheet name 75 | */ 76 | public XlsToOutputStreamWriter(final OutputStream stream, final String sheetName, final Boolean freezeHeadline) 77 | { 78 | this.stream = stream; 79 | this.sheetName = sheetName; 80 | this.freezeHeadline = freezeHeadline; 81 | } 82 | 83 | 84 | /** 85 | * {@inheritDoc} 86 | */ 87 | @Override 88 | public void write(JasperPrint jasperPrint) throws ExportWriterException 89 | { 90 | final JRXlsExporter exporterXLS = new JRXlsExporter(); 91 | try 92 | { 93 | ExportUtils.prepareExcelExporter(exporterXLS,jasperPrint,this.sheetName,this.freezeHeadline,this.stream); 94 | exporterXLS.exportReport(); 95 | } 96 | catch(JRException e) 97 | { 98 | throw new ExportWriterException(e); 99 | } 100 | catch(IllegalArgumentException ie) 101 | { 102 | throw new ExportWriterException(ie); 103 | } 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/XlsxToFileWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import xdev.tableexport.utils.ExportUtils; 21 | 22 | import java.io.File; 23 | 24 | import net.sf.jasperreports.engine.JRException; 25 | import net.sf.jasperreports.engine.JasperPrint; 26 | import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter; 27 | 28 | 29 | /** 30 | * Write the generated report object into XLSX format. 31 | * 32 | *

33 | * The generated XLSX content is placed into a {@code File}. 34 | *

35 | * 36 | * @author XDEV Software(FHAE) 37 | */ 38 | public class XlsxToFileWriter implements ExportWriter 39 | { 40 | 41 | private final File file; 42 | private final String sheetName; 43 | private final Boolean freezeHeadline; 44 | 45 | 46 | /** 47 | * Constructs a {@link XlsxToFileWriter} object given a {@link File} object. 48 | * No freeze headline are created. 49 | * 50 | *

51 | * Note - Excel allows sheet names up to 31 chars in length but other applications allow more. 52 | * Excel does not crash with names longer than 31 chars, but silently truncates such names to 53 | * 31 chars. 54 | *

55 | * 56 | * @param file a {@link File} object to write to. 57 | * @param sheetName the excel sheet name 58 | */ 59 | public XlsxToFileWriter(final File file, final String sheetName) 60 | { 61 | this(file,sheetName,false); 62 | } 63 | 64 | /** 65 | * Constructs a {@link XlsxToFileWriter} object given a {@link File} object. 66 | * 67 | *

68 | * Note - Excel allows sheet names up to 31 chars in length but other applications allow more. 69 | * Excel does not crash with names longer than 31 chars, but silently truncates such names to 70 | * 31 chars. 71 | *

72 | * 73 | * @param file a {@link File} object to write to. 74 | * @param sheetName the excel sheet name 75 | * @param freezeHeadline if true the freeze pane for the first row is 76 | */ 77 | public XlsxToFileWriter(final File file, final String sheetName, final Boolean freezeHeadline) 78 | { 79 | this.file = file; 80 | this.sheetName = sheetName; 81 | this.freezeHeadline = freezeHeadline; 82 | } 83 | 84 | 85 | /** 86 | * {@inheritDoc} 87 | */ 88 | @Override 89 | public void write(JasperPrint jasperPrint) throws ExportWriterException 90 | { 91 | final JRXlsxExporter exporterXLSX = new JRXlsxExporter(); 92 | try 93 | { 94 | ExportUtils.prepareExcelExporter(exporterXLSX,jasperPrint,this.sheetName,this.freezeHeadline,this.file); 95 | exporterXLSX.exportReport(); 96 | } 97 | catch(JRException e) 98 | { 99 | throw new ExportWriterException(e); 100 | } 101 | catch(Exception ie) 102 | { 103 | throw new ExportWriterException(ie); 104 | } 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/export/writer/XlsxToOutputStreamWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.export.writer; 19 | 20 | import java.io.OutputStream; 21 | 22 | import net.sf.jasperreports.engine.JRException; 23 | import net.sf.jasperreports.engine.JasperPrint; 24 | import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter; 25 | import xdev.tableexport.utils.ExportUtils; 26 | 27 | 28 | /** 29 | * Write the generated report object into XLSX format. 30 | * 31 | *

32 | * The generated XLSX content is placed into a {@code OutputStream}. 33 | *

34 | * 35 | * @author XDEV Software(FHAE) 36 | */ 37 | public class XlsxToOutputStreamWriter implements ExportWriter 38 | { 39 | private final OutputStream stream; 40 | private final String sheetName; 41 | private final Boolean freezeHeadline; 42 | 43 | 44 | /** 45 | * Constructs a {@link XlsxToOutputStreamWriter} object given a 46 | * {@link OutputStream} object. No freeze headline are created. 47 | *

48 | * Note - Excel allows sheet names up to 31 chars in length but other 49 | * applications allow more. Excel does not crash with names longer than 31 50 | * chars, but silently truncates such names to 31 chars. 51 | *

52 | * 53 | * @param stream 54 | * a {@link OutputStream} object to write to. 55 | * @param sheetName 56 | * the excel sheet name 57 | */ 58 | public XlsxToOutputStreamWriter(final OutputStream stream, final String sheetName) 59 | { 60 | this(stream,sheetName,false); 61 | } 62 | 63 | 64 | /** 65 | * Constructs a {@link XlsxToOutputStreamWriter} object given a 66 | * {@link OutputStream} object. 67 | * 68 | *

69 | * Note - Excel allows sheet names up to 31 chars in length but other 70 | * applications allow more. Excel does not crash with names longer than 31 71 | * chars, but silently truncates such names to 31 chars. 72 | *

73 | * 74 | * @param stream 75 | * a {@link OutputStream} object to write to. 76 | * @param sheetName 77 | * the excel sheet name 78 | * @param freezeHeadline 79 | * if true the freeze pane for the first row is 80 | */ 81 | public XlsxToOutputStreamWriter(final OutputStream stream, final String sheetName, 82 | final Boolean freezeHeadline) 83 | { 84 | this.stream = stream; 85 | this.sheetName = sheetName; 86 | this.freezeHeadline = freezeHeadline; 87 | } 88 | 89 | 90 | /** 91 | * {@inheritDoc} 92 | */ 93 | @Override 94 | public void write(JasperPrint jasperPrint) throws ExportWriterException 95 | { 96 | final JRXlsxExporter exporterXLSX = new JRXlsxExporter(); 97 | try 98 | { 99 | ExportUtils.prepareExcelExporter(exporterXLSX,jasperPrint,this.sheetName, 100 | this.freezeHeadline,this.stream); 101 | exporterXLSX.exportReport(); 102 | } 103 | catch(JRException e) 104 | { 105 | throw new ExportWriterException(e); 106 | } 107 | catch(IllegalArgumentException ie) 108 | { 109 | throw new ExportWriterException(ie); 110 | } 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/utils/DataSourceResourceBundle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.utils; 19 | 20 | import java.text.MessageFormat; 21 | import java.util.ResourceBundle; 22 | 23 | 24 | /** 25 | * Helper class for BI suite resource bundle. 26 | * 27 | * @author XDEV Software 28 | * 29 | */ 30 | public class DataSourceResourceBundle 31 | { 32 | /** 33 | * serialVersionUID. 34 | */ 35 | private static ResourceBundle resourceBundle; 36 | 37 | /** 38 | * name of the language properties file. 39 | */ 40 | private static final String BUNDLE_NAME = ".xdevdatasource"; 41 | 42 | 43 | /** 44 | * @return the ResourceBundle for the calendar package 45 | */ 46 | private static ResourceBundle getBundle() 47 | { 48 | if(resourceBundle == null) 49 | { 50 | resourceBundle = ResourceBundle.getBundle(DataSourceResourceBundle.class.getPackage() 51 | .getName() + BUNDLE_NAME); 52 | } 53 | 54 | return resourceBundle; 55 | } 56 | 57 | 58 | /** 59 | * Return a specified String from the bundle of the calendar. 60 | * 61 | * @param key 62 | * the key to lookup the value 63 | * @param args 64 | * optional values to replace the placeholder with 65 | * @return a String 66 | */ 67 | public static String getString(String key, Object... args) 68 | { 69 | String str = getBundle().getString(key); 70 | 71 | if(args != null && args.length > 0) 72 | { 73 | str = MessageFormat.format(str,args); 74 | } 75 | 76 | return str; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/utils/ExportUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.utils; 19 | 20 | import java.io.File; 21 | import java.io.OutputStream; 22 | 23 | import net.sf.jasperreports.engine.JRAbstractExporter; 24 | import net.sf.jasperreports.engine.JRExporterParameter; 25 | import net.sf.jasperreports.engine.JRPropertiesUtil; 26 | import net.sf.jasperreports.engine.JasperPrint; 27 | import net.sf.jasperreports.engine.export.JRXlsAbstractExporter; 28 | import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter; 29 | 30 | 31 | /** 32 | *

33 | * The {@code ExportUtils} class provides utility methods for preparing the {@link JRAbstractExporter} 34 | *

35 | * 36 | * 37 | * @author XDEV Software(FHAE) 38 | */ 39 | @SuppressWarnings("deprecation") 40 | public class ExportUtils 41 | { 42 | 43 | /** 44 | * Prepare the {@code exporter} with all required {@link JRExporterParameter}. 45 | * 46 | * @param exporter 47 | * 48 | * @param jasperPrint An instance of the {@link JasperPrint} represents a report document that can be exported to other formats. 49 | * 50 | * @param sheetName An string representing custom sheet name 51 | * 52 | * @param stream the outputstream 53 | * 54 | * @throws IllegalArgumentException 55 | */ 56 | public static void prepareExcelExporter(final JRXlsAbstractExporter exporter, 57 | final JasperPrint jasperPrint, final String sheetName, final Boolean freezeHeadline, final OutputStream stream) 58 | throws IllegalArgumentException 59 | { 60 | initDefaultParameter(exporter,jasperPrint,sheetName,freezeHeadline); 61 | exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,stream); 62 | } 63 | 64 | 65 | /** 66 | * Prepare the {@code exporter} with all required {@link JRExporterParameter}. 67 | * 68 | * @param exporter 69 | * 70 | * @param jasperPrint An instance of the {@link JasperPrint} represents a report document that can be exported to other formats. 71 | * 72 | * @param sheetName An string representing custom sheet name 73 | * 74 | * @param file the output file 75 | * 76 | * @throws IllegalArgumentException 77 | */ 78 | public static void prepareExcelExporter(final JRXlsAbstractExporter exporter, 79 | final JasperPrint jasperPrint, final String sheetName, final Boolean freezeHeadline, final File file) 80 | throws IllegalArgumentException 81 | { 82 | initDefaultParameter(exporter,jasperPrint,sheetName,freezeHeadline); 83 | exporter.setParameter(JRExporterParameter.OUTPUT_FILE,file); 84 | } 85 | 86 | private static void initDefaultParameter(final JRXlsAbstractExporter exporter, 87 | final JasperPrint jasperPrint, final String sheetName, final Boolean freezeHeadline) throws IllegalArgumentException 88 | { 89 | exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 90 | exporter.setParameter(JRExporterParameter.IGNORE_PAGE_MARGINS,Boolean.FALSE); 91 | exporter.setParameter(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE); 92 | exporter.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.FALSE); 93 | 94 | exporter.setParameter(JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE,Boolean.TRUE); 95 | exporter.setParameter(JRXlsAbstractExporterParameter.IS_IGNORE_CELL_BACKGROUND, 96 | Boolean.FALSE); 97 | exporter.setParameter(JRXlsAbstractExporterParameter.SHEET_NAMES,new String[]{sheetName}); 98 | 99 | 100 | 101 | exporter.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, 102 | Boolean.TRUE); 103 | exporter.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, 104 | Boolean.TRUE); 105 | 106 | if(freezeHeadline) 107 | { 108 | final JRPropertiesUtil util = JRPropertiesUtil 109 | .getInstance(exporter.getJasperReportsContext()); 110 | util.setProperty(JRXlsAbstractExporter.PROPERTY_FREEZE_ROW_EDGE,"2"); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/utils/NullPatternConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.utils; 19 | 20 | 21 | public class NullPatternConverter implements PatternConverter 22 | { 23 | @Override 24 | public String getExportPattern(Object obj) 25 | { 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/utils/PatternConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.utils; 19 | import net.sf.jasperreports.engine.design.JRDesignTextField; 20 | 21 | /** 22 | * Converter which converts to an export pattern-String. 23 | * 24 | * @author XDEV Software(FHAE) 25 | */ 26 | public interface PatternConverter 27 | { 28 | /** 29 | * Return the converted export pattern. 30 | *

31 | * The export pattern is used in the report to define the datatype and the presentation. 32 | * {@link JRDesignTextField#setPattern(String)}. 33 | *

34 | * 35 | * @param obj 36 | * the object to convert 37 | * @return the converted export pattern 38 | */ 39 | public String getExportPattern(T obj); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/xdev/tableexport/utils/VirtualTableColumnPatternConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDEV BI Suite - XDEV BI Suite 3 | * Copyright © 2011 XDEV Software (https://xdev.software) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | */ 18 | package xdev.tableexport.utils; 19 | 20 | import xdev.ui.text.TextFormat; 21 | import xdev.vt.VirtualTableColumn; 22 | 23 | import java.text.DecimalFormat; 24 | import java.text.Format; 25 | import java.text.SimpleDateFormat; 26 | 27 | 28 | public class VirtualTableColumnPatternConverter implements PatternConverter> 29 | { 30 | @Override 31 | public String getExportPattern(VirtualTableColumn obj) 32 | { 33 | TextFormat t = obj.getTextFormat(); 34 | Format format = t.createFormat(t.getType()); 35 | 36 | if(format instanceof SimpleDateFormat) 37 | { 38 | return ((SimpleDateFormat)format).toPattern(); 39 | } 40 | else if(format instanceof DecimalFormat) 41 | { 42 | String pattern = ((DecimalFormat)format).toPattern(); 43 | 44 | if(pattern.contains("\u00A4")) 45 | { 46 | String symbol = ((DecimalFormat)format).getCurrency().getSymbol(); 47 | pattern = pattern.replace("\u00A4",symbol); 48 | } 49 | return pattern; 50 | } 51 | return null; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/resources/xdev/lic/pj.properties: -------------------------------------------------------------------------------- 1 | plugin = XDEV BI Suite 2 | -------------------------------------------------------------------------------- /src/main/resources/xdev/tableexport/utils/xdevdatasource.properties: -------------------------------------------------------------------------------- 1 | # ================================================================== 2 | # DataSource localization properties 3 | # ================================================================== 4 | 5 | # JTableRendererBooleanValues 6 | jtableRendererDataSource.trueValue= WAHR 7 | jtableRendererDataSource.falseValue= FALSCH 8 | 9 | -------------------------------------------------------------------------------- /src/main/resources/xdev/tableexport/utils/xdevdatasource_en.properties: -------------------------------------------------------------------------------- 1 | # ================================================================== 2 | # DataSource localization properties 3 | # ================================================================== 4 | 5 | # JTableRendererBooleanValues 6 | jtableRendererDataSource.trueValue= TRUE 7 | jtableRendererDataSource.falseValue= FALSE 8 | 9 | --------------------------------------------------------------------------------