This repository has been archived by the owner on Jun 17, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included MIT license to indicate that this whole project is licensed …
…under these terms. (Source header update)
- Loading branch information
Showing
8 changed files
with
2,171 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,977 changes: 1,977 additions & 0 deletions
1,977
sample-generate-report-files/build-res/subfloor.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
sample-generate-report-files/src/sdk/generate/patch/PatchAReportSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014 Thomas Morgner | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package sdk.generate.patch; | ||
|
||
import joptsimple.OptionException; | ||
import joptsimple.OptionParser; | ||
import joptsimple.OptionSet; | ||
import joptsimple.OptionSpec; | ||
import org.pentaho.reporting.engine.classic.core.AbstractReportDefinition; | ||
import org.pentaho.reporting.engine.classic.core.CompoundDataFactory; | ||
import org.pentaho.reporting.engine.classic.core.DataFactory; | ||
import org.pentaho.reporting.engine.classic.core.MasterReport; | ||
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.ConnectionProvider; | ||
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.DriverConnectionProvider; | ||
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.JndiConnectionProvider; | ||
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory; | ||
import org.pentaho.reporting.engine.classic.core.modules.parser.bundle.writer.BundleWriter; | ||
import org.pentaho.reporting.engine.classic.core.modules.parser.bundle.writer.BundleWriterException; | ||
import org.pentaho.reporting.engine.classic.core.util.AbstractStructureVisitor; | ||
import org.pentaho.reporting.libraries.repository.ContentIOException; | ||
import org.pentaho.reporting.libraries.resourceloader.ResourceException; | ||
import org.pentaho.reporting.libraries.resourceloader.ResourceManager; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class PatchAReportSample { | ||
public static void _main(String[] args) throws IOException { | ||
OptionParser parser = new OptionParser(); | ||
OptionSpec<String> source = parser.accepts("source").withRequiredArg().ofType(String.class).required().describedAs("Source File"); | ||
OptionSpec<String> target = parser.accepts("target").withOptionalArg().ofType(String.class).required().describedAs("Target File"); | ||
|
||
try { | ||
OptionSet parse = parser.parse(args); | ||
String sourceText = parse.valueOf(source); | ||
String targetText = parse.valueOf(target); | ||
|
||
processReport(sourceText, targetText); | ||
|
||
} catch (OptionException oe) { | ||
parser.printHelpOn(System.out); | ||
} catch (ResourceException | ContentIOException | BundleWriterException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws ResourceException, ContentIOException, BundleWriterException, IOException { | ||
processReport(args[0], args[1]); | ||
} | ||
|
||
private static void processReport(String sourceText, String targetText) | ||
throws ResourceException, IOException, BundleWriterException, ContentIOException { | ||
|
||
File sourceFile = new File(sourceText); | ||
MasterReport report = (MasterReport) new ResourceManager().createDirectly(sourceFile, MasterReport.class).getResource(); | ||
|
||
MasterReport processedReport = manipulateReport(report); | ||
|
||
BundleWriter.writeReportToZipFile(report, new File(targetText)); | ||
} | ||
|
||
private static MasterReport manipulateReport(MasterReport report) { | ||
new DataSourceStructureVisitor().inspect(report); | ||
return report; | ||
} | ||
|
||
private static class DataSourceStructureVisitor extends AbstractStructureVisitor { | ||
@Override | ||
protected void inspect(AbstractReportDefinition reportDefinition) { | ||
|
||
processAllDataSources(reportDefinition); | ||
processSingleDataSource(reportDefinition, "query"); | ||
super.inspect(reportDefinition); | ||
} | ||
|
||
private void processSingleDataSource(AbstractReportDefinition reportDefinition, String query) { | ||
CompoundDataFactory dataFactory = CompoundDataFactory.normalize(reportDefinition.getDataFactory()); | ||
DataFactory dataFactoryForQuery = dataFactory.getDataFactoryForQuery(query); | ||
if (dataFactoryForQuery != null) { | ||
int idx = dataFactory.indexOfByReference(dataFactory); | ||
dataFactory.set(idx, handleDataSource(reportDefinition, dataFactory)); | ||
} | ||
reportDefinition.setDataFactory(dataFactory); | ||
} | ||
|
||
|
||
private void processAllDataSources(AbstractReportDefinition reportDefinition) { | ||
CompoundDataFactory dataFactory = CompoundDataFactory.normalize(reportDefinition.getDataFactory()); | ||
final int size = dataFactory.size(); | ||
for (int i = 0; i < size; i++) { | ||
dataFactory.set(i, handleDataSource(reportDefinition, dataFactory.getReference(i))); | ||
} | ||
reportDefinition.setDataFactory(dataFactory); | ||
} | ||
|
||
private DataFactory handleDataSource(AbstractReportDefinition reportDefinition, DataFactory dataFactory) { | ||
return dataFactory; | ||
} | ||
} | ||
|
||
|
||
private static DataFactory handleDataSource(AbstractReportDefinition reportDefinition, DataFactory dataFactory) { | ||
// do whatever you want here. | ||
if (dataFactory instanceof SimpleSQLReportDataFactory) { | ||
SimpleSQLReportDataFactory sdf = (SimpleSQLReportDataFactory) dataFactory; | ||
if (isLocalSampleData(sdf)) { | ||
JndiConnectionProvider connectionProvider = new JndiConnectionProvider(); | ||
connectionProvider.setConnectionPath("SampleData"); | ||
sdf.setConnectionProvider(connectionProvider); | ||
} | ||
} | ||
return dataFactory; | ||
} | ||
|
||
private static boolean isLocalSampleData(SimpleSQLReportDataFactory sdf) { | ||
ConnectionProvider cp = sdf.getConnectionProvider(); | ||
if (cp instanceof DriverConnectionProvider) { | ||
DriverConnectionProvider jcp = (DriverConnectionProvider) cp; | ||
if ("org.hsqldb.jdbcDriver".equals(jcp.getDriver()) && | ||
"jdbc:hsqldb:file:./sql/sampledata".equalsIgnoreCase(jcp.getUrl())) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="module-library" exported=""> | ||
<library> | ||
<CLASSES> | ||
<root url="file://$MODULE_DIR$/lib/internal" /> | ||
</CLASSES> | ||
<JAVADOC /> | ||
<SOURCES> | ||
<root url="file://$MODULE_DIR$/lib/internal" /> | ||
<root url="jar://$USER_HOME$/.ideaLibSources/servlet-api-2.5-sources.jar!/" /> | ||
</SOURCES> | ||
<jarDirectory url="file://$MODULE_DIR$/lib/internal" recursive="false" /> | ||
<jarDirectory url="file://$MODULE_DIR$/lib/internal" recursive="false" type="SOURCES" /> | ||
</library> | ||
</orderEntry> | ||
</component> | ||
</module> | ||
|