I am using a large open source library and need to generate personal subclasses of a few of the classes. What are the best strategies? I would like to keep the original library unaltered and be easily able to reconfigure when it is updated. It is unlikely that my code is worth contributing to the project (though I am happy to write in a way that permits this).
The problem is a general one but I will illustrate it with my example. I am using Apache PDFBox which has a routine to write to java.awt.Graphics2D
. I have replaced this by the Apache Batik toolkit which provides a subclass of Graphics2D (org.apache.batik.svggen.SVGGraphics2D
) so I can capture the SVG representation. I create an instance
public static org.apache.batik.svggen.SVGGraphics2D createSVG() {
org.w3c.dom.DOMImplementation domImpl =
org.apache.batik.dom.GenericDOMImplementation.getDOMImplementation();
org.w3c.dom.Document document =
domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);
return new org.apache.batik.svggen.SVGGraphics2D(document);
}
The place where PDFBox uses the graphics is org.apache.pdfbox.PDFReader
which I have edited to allow for the new graphics:
protected void showPage(int pageNumber)
{
try
{
PageDrawer drawer = new PageDrawer();
PageWrapper wrapper = new PageWrapper( this );
PDPage page = (PDPage)pages.get(pageNumber);
wrapper.displayPage( page );
PDRectangle cropBox = page.findCropBox();
Dimension drawDimension = cropBox.createDimension();
svg = PDFPagePanel.createSVG(); // MY EDIT!!!!!!!!!
drawer.drawPage( svg, page, drawDimension );
writeSVG(pageNumber);
}
catch (IOException exception)
{
exception.printStackTrace();
}
}
I have got it to work (that's not the problem). My concern is that I have had to hack/edit and recompile a number of the distributed PDFBox classes simply to generate and use the subclass. I end up with classes such as PMRPDFReader in the same packages as the library. It's very messy - I can't immediately remember where I made the edits, etc.
I feel I ought ought to be able to use the library as-is and simply add/link my subclasses. I use maven so maybe there is a way of excluding the original classes.
Here's how I would do this:
For deployment, you then have two options:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With