I use a large open source library and must generate personal subclasses of several classes. What are the best strategies? I would like to keep the original library intact and easily reconfigure it when it is updated. It is unlikely that my code is worth contributing to the project (although I am happy to write in such a way that this is allowed).
The problem is general, but I will illustrate it with an example. I am using Apache PDFBox , which has a program for writing to java.awt.Graphics2D
. I replaced this with the Apache Batik toolkit, which provides a subclass of Graphics2D ( org.apache.batik.svggen.SVGGraphics2D
), so I can capture the SVG view. 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 the PDFBox uses graphics is org.apache.pdfbox.PDFReader
, which I edited to allow 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();
I have a job (this is not a problem). My concern is that I had to hack / edit and recompile a number of distributed PDFBox classes, just to generate and use a subclass. I end up with classes like PMRPDFReader, in the same packages as the library. This is very dirty - I canβt immediately remember where I made the changes, etc.
I feel that I should be able to use the library as is and just add / link my subclasses. I am using maven, so there may be a way to exclude source classes.
source share