Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/upgrade exist 5x #35

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
Expand All @@ -8,7 +8,6 @@
<groupId>org.exist-db</groupId>
<artifactId>exist-apps-parent</artifactId>
<version>1.8</version>
<relativePath/>
</parent>

<groupId>org.exist.xquery.modules</groupId>
Expand Down Expand Up @@ -48,9 +47,10 @@
<project.build.source>1.8</project.build.source>
<project.build.target>1.8</project.build.target>

<exist.version>4.6.0</exist.version>
<batik.version>1.11</batik.version>
<jfreechart.version>1.5.0</jfreechart.version>
<exist.version>6.0.1</exist.version>
<batik.version>1.14</batik.version>
<jfreechart.version>1.5.3</jfreechart.version>
<jfreesvg.version>5.0.1</jfreesvg.version>

<!-- used in the EXPath Package Descriptor -->
<package-name>http://exist-db.org/xquery/jfreechart</package-name>
Expand All @@ -65,11 +65,6 @@
<artifactId>exist-core</artifactId>
<version>${exist.version}</version>
</dependency>
<dependency>
<groupId>org.exist-db</groupId>
<artifactId>exist-optional</artifactId>
<version>${exist.version}</version>
</dependency>

<!-- JFreechart -->
<dependency>
Expand All @@ -78,6 +73,12 @@
<version>${jfreechart.version}</version>
</dependency>

<dependency>
<groupId>org.jfree</groupId>
<artifactId>org.jfree.svg</artifactId>
<version>${jfreesvg.version}</version>
</dependency>

<!-- Batik -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
Expand All @@ -91,12 +92,6 @@
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.exist-db</groupId>
<artifactId>exist-testkit</artifactId>
<version>${exist.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -105,12 +100,11 @@
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>2.4.0</version>
<version>2.8.3</version>
<scope>test</scope>
</dependency>



</dependencies>

<reporting>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package org.exist.xquery.modules.jfreechart;

import com.evolvedbinary.j8fu.function.ConsumerE;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.exist.dom.QName;
Expand Down Expand Up @@ -108,7 +109,7 @@ public class JFreeCharting extends StrictResponseFunction {
new FunctionParameterSequenceType("data", Type.NODE, Cardinality.EXACTLY_ONE,
"The CategoryDataset or PieDataset, supplied as JFreechart XML.")
},
new SequenceType(Type.EMPTY, Cardinality.EMPTY)
new SequenceType(Type.EMPTY, Cardinality.EMPTY_SEQUENCE)
)
};

Expand All @@ -132,18 +133,22 @@ public Sequence eval(final Sequence[] args, @Nonnull final ResponseWrapper respo
final Configuration config = new Configuration();
config.parse(((NodeValue) args[1].itemAt(0)).getNode());

// Get datastream
@SuppressWarnings("resource")
final Serializer serializer = context.getBroker().getSerializer();

final NodeValue node = (NodeValue) args[2].itemAt(0);
final InputStream is = new NodeInputStream(context.getDatabase(), serializer, node);

// Get serializer
final ConsumerE<ConsumerE<Serializer, IOException>, IOException> withSerializerFn = fn -> {
final Serializer serializer = context.getBroker().borrowSerializer();
try {
fn.accept(serializer);
} finally {
context.getBroker().returnSerializer(serializer);
}
};

// get chart
final JFreeChart chart;
try {
try(InputStream is = new NodeInputStream(context.getDatabase(), withSerializerFn, node);){
chart = JFreeChartFactory.createJFreeChart(chartType, config, is);

} catch (final IllegalArgumentException ex) {
throw new XPathException(this, ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,27 @@ public void render(final JFreeChart chart, final Configuration config, final Out

final Rectangle bounds = new Rectangle(config.getImageWidth(), config.getImageHeight());

// Get a DOMImplementation and create an XML document
final DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
final Document document = domImpl.createDocument(null, "svg", null);

// Create an instance of the SVG Generator
final SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
final Graphics2D svgGenerator = getBatik();

// draw the chart in the SVG generator
chart.draw(svgGenerator, bounds);

final Writer out = new OutputStreamWriter(os, StandardCharsets.UTF_8);
svgGenerator.stream(out, true /* use css */);
((SVGGraphics2D)svgGenerator).stream(out, true /* use css */);
os.flush();
os.close();
}

private Graphics2D getBatik() {
// Get a DOMImplementation and create an XML document
final DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
final Document document = domImpl.createDocument(null, "svg", null);

// Create an instance of the SVG Generator
return new SVGGraphics2D(document);
}

@Override
public String getContentType() {
return ("image/svg+xml");
Expand Down
6 changes: 6 additions & 0 deletions xar-assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
<li>Removed deprecated draft map constructor for compatibility with forthcoming eXist 5.0.0-RC8.</li>
</ul>
</change>
<change version="0.5.0">
<ul>
<li>Compatible with eXist-db v5.3.</li>
<li>Upgrade libraries</li>
</ul>
</change>
</changelog>

</package>