public FOUserAgent getUserAgent() {
if (userAgent == null) {
userAgent = new FOUserAgent();
- userAgent.setLogger(getLogger());
}
return userAgent;
}
import java.io.IOException;
import java.io.InputStream;
-import org.apache.commons.logging.Log;
-
// FOP
import org.apache.fop.pdf.PDFEncryptionParams;
*/
public class FOUserAgent {
- private Log log;
/** Map containing various default values */
public Map defaults = new java.util.HashMap();
/** Map containing XML handlers for various document types */
private PDFEncryptionParams pdfEncryptionParams;
private float px2mm = 0.35277777777777777778f; //72dpi (=25.4/dpi)
- /**
- * Sets the logger.
- * @param log Logger to use
- */
- public void setLogger(Log log) {
- this.log = log;
- }
-
- /**
- * Returns the logger to use.
- * (todo) This breaks IoC/SoC. Should be improved.
- */
- public Log getLogger() {
- return this.log;
- }
-
/**
* Sets the base URL.
* @param baseURL base URL
import java.util.Set;
import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.ElementMapping.Maker;
*/
protected Map fobjTable = new java.util.HashMap();
+ /**
+ * logging instance
+ */
+ protected Log log = LogFactory.getLog(FOTreeBuilder.class);
+
/**
* Set of mapped namespaces.
*/
}
private Log getLogger() {
- return userAgent.getLogger();
+ return log;
}
/**
return;
}
// load dimensions
- if (!fopimage.load(FopImage.DIMENSIONS, getUserAgent().getLogger())) {
+ if (!fopimage.load(FopImage.DIMENSIONS)) {
// error
url = null;
return;
// FOP
import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Base class to implement the FopImage interface.
* @see FopImage
*/
public abstract class AbstractFopImage implements FopImage {
+
+ /**
+ * logging instance
+ */
+ protected static Log log = LogFactory.getLog(AbstractFopImage.class);
+
/**
* Keeps track of what has been loaded.
*/
* @param ua the user agent for handling logging etc.
* @return true if the loading was successful
*/
- public synchronized boolean load(int type, Log logger) {
+ public synchronized boolean load(int type) {
if ((loaded & type) != 0) {
return true;
}
boolean success = true;
if (((type & DIMENSIONS) != 0) && ((loaded & DIMENSIONS) == 0)) {
- success = success && loadDimensions(logger);
+ success = success && loadDimensions();
if (!success) {
return false;
loaded = loaded | DIMENSIONS;
}
if (((type & BITMAP) != 0) && ((loaded & BITMAP) == 0)) {
- success = success && loadBitmap(logger);
+ success = success && loadBitmap();
if (success) {
loaded = loaded | BITMAP;
}
}
if (((type & ORIGINAL_DATA) != 0) && ((loaded & ORIGINAL_DATA) == 0)) {
- success = success && loadOriginalData(logger);
+ success = success && loadOriginalData();
if (success) {
loaded = loaded | ORIGINAL_DATA;
}
* @param ua the user agent
* @return true if the loading was successful
*/
- protected boolean loadDimensions(Log logger) {
+ protected boolean loadDimensions() {
return false;
}
* @param ua the user agent
* @return true if the loading was successful
*/
- protected boolean loadBitmap(Log logger) {
+ protected boolean loadBitmap() {
return false;
}
* @param ua the user agent
* @return true if the loading was successful
*/
- protected boolean loadOriginalData(Log logger) {
+ protected boolean loadOriginalData() {
return false;
}
* the information.
*
* @param type the type of loading required
- * @param logger the Commons-logging component
* @return boolean true if the information could be loaded
*/
- boolean load(int type, Log logger);
+ boolean load(int type);
/**
* Returns the image width.
* @param ua the user agent for loading
* @return True if the load process succeeded
*/
- protected boolean loadBitmap(Log logger) {
+ protected boolean loadBitmap() {
int[] tmpMap = null;
try {
URLConnection con = new DummyConnection(inputStream);
try {
tmpMap = consumer.getImage();
} catch (Exception ex) {
- logger.error("Image grabbing interrupted : "
+ log.error("Image grabbing interrupted : "
+ ex.getMessage(), ex);
return false;
}
this.isTransparent = false;
}
} catch (Exception ex) {
- logger.error("Error while loading image "
+ log.error("Error while loading image "
+ "" + " : "
+ ex.getClass() + " - "
+ ex.getMessage(), ex);
import java.util.Iterator;
import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
// FOP
import org.apache.fop.image.analyser.ImageReaderFactory;
*/
public class ImageFactory {
+ /**
+ * logging instance
+ */
+ protected static Log log = LogFactory.getLog(FopImage.class);
+
private static ImageFactory factory = new ImageFactory();
private ImageCache cache = new ContextImageCache(true);
* @return the fop image instance
*/
public static FopImage loadImage(String href, FOUserAgent ua) {
- Log log = ua.getLogger();
InputStream in = openStream(href, ua);
* @return a new FopImage object
*/
protected static InputStream openStream(String href, FOUserAgent ua) {
- Log log = ua.getLogger();
+
// Get the absolute URL
URL absoluteURL = null;
InputStream in = null;
import org.apache.fop.image.FopImage;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
/**
* Factory for ImageReader objects.
*
private static ArrayList formats = new ArrayList();
+ protected static Log log = LogFactory.getLog(ImageReaderFactory.class);
+
static {
registerFormat(new JPEGReader());
registerFormat(new BMPReader());
}
}
} catch (IOException ex) {
- ua.getLogger().error(
- "Error while recovering Image Informations ("
- + uri + ")", ex);
+ log.error("Error while recovering Image Informations ("
+ + uri + ")", ex);
}
return null;
}
if (batik) {
try {
Loader loader = new Loader();
- return loader.getImage(uri, bis, ua.getLogger(),
+ return loader.getImage(uri, bis,
ua.getPixelUnitToMillimeter());
} catch (NoClassDefFoundError e) {
batik = false;
*/
class Loader {
private FopImage.ImageInfo getImage(String uri, InputStream fis,
- Log logger, float pixelUnitToMM) {
+ float pixelUnitToMM) {
// parse document and get the size attributes of the svg element
try {
Element e = doc.getRootElement();
String s;
- SVGUserAgent userAg = new SVGUserAgent(logger, pixelUnitToMM,
+ SVGUserAgent userAg = new SVGUserAgent(pixelUnitToMM,
new AffineTransform());
BridgeContext ctx = new BridgeContext(userAg);
UnitProcessor.Context uctx =
import org.apache.fop.image.FopImage;
import org.apache.fop.apps.FOUserAgent;
+// Commons-Logging
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/** ImageReader object for XML document image type. */
public class XMLReader implements ImageReader {
+ /**
+ * logging instance
+ */
+ private Log log = LogFactory.getLog(XMLReader.class);
+
private static Map converters = new java.util.HashMap();
/**
info.data = doc;
Element root = doc.getDocumentElement();
- ua.getLogger().debug("XML image namespace: " + root.getAttribute("xmlns"));
+ log.debug("XML image namespace: " + root.getAttribute("xmlns"));
String ns = root.getAttribute("xmlns");
info.str = ns;
}
}
} catch (Exception e) {
- ua.getLogger().warn("Error while constructing image from XML", e);
+ log.warn("Error while constructing image from XML", e);
try {
is.reset();
} catch (IOException ioe) {
import org.apache.fop.fo.PropertyManager;
import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.ListIterator;
import java.util.Map;
protected ListIterator childLMiter;
protected boolean bInited = false;
+ /**
+ * logging instance
+ */
+ protected static Log log = LogFactory.getLog(AbstractLayoutManager.class);
+
/**
* Abstract layout manager.
*/
return userAgent;
}
- protected Log getLogger() {
- return userAgent.getLogger();
- }
-
public void setParent(LayoutManager lm) {
this.parentLM = lm;
}
if (overflow == Overflow.HIDDEN) {
clip = true;
} else if (overflow == Overflow.ERROR_IF_OVERFLOW) {
- getLogger().error("contents overflows block-container viewport: clipping");
+ log.error("contents overflows block-container viewport: clipping");
clip = true;
}
}
while ((curLM = getChildLM()) != null) {
if (curLM.generatesInlineAreas()) {
- getLogger().error("inline area not allowed under flow - ignoring");
+ log.error("inline area not allowed under flow - ignoring");
curLM.setFinished(true);
continue;
}
*/
public Marker retrieveMarker(String name, int pos, int boundary) {
// error cannot retrieve markers in flow
- getLogger().error("Cannot retrieve a marker from the flow");
+ log.error("Cannot retrieve a marker from the flow");
return null;
}
}
// ignore nested blocks for now
if (!curLM.generatesInlineAreas()) {
- getLogger().warn("ignoring block inside inline fo");
+ log.warn("ignoring block inside inline fo");
curLM.setFinished(true);
continue;
}
while (bpIter.hasPrevious() && bpIter.previous() != prev) {
}
if (prev != null && bpIter.next() != prev) {
- getLogger().error("findHyphenPoss: problem!");
+ log.error("findHyphenPoss: problem!");
return null;
}
StringBuffer sbChars = new StringBuffer(30);
prev = bp;
}
vecInlineBreaks.remove(vecInlineBreaks.size() - 1); // remove last
- getLogger().debug("Word to hyphenate: " + sbChars.toString());
+ log.debug("Word to hyphenate: " + sbChars.toString());
// Now find all hyphenation points in this word (get in an array of offsets)
// hyphProps are from the block level?. Note that according to the spec,
}
RegionViewport reg = curPage.getPage().getRegionViewport(regionClass);
if (reg == null) {
- getLogger().error("no region viewport: shouldn't happen");
+ log.error("no region viewport: shouldn't happen");
}
StaticContentLayoutManager lm = getStaticContentLayoutManager(flow);
lm.setUserAgent(getUserAgent());
lm.addAreas(new BreakPossPosIter(vecBreakPoss, 0,
vecBreakPoss.size()), null);
} else {
- getLogger().error("bp==null cls=" + regionClass);
+ log.error("bp==null cls=" + regionClass);
}
}
//lm.flush();
if ((columnCount > 1) && (r.overflow == Overflow.SCROLL)) {
// recover by setting 'column-count' to 1. This is allowed but
// not required by the spec.
- getLogger().error("Setting 'column-count' to 1 because "
+ log.error("Setting 'column-count' to 1 because "
+ "'overflow' is set to 'scroll'");
columnCount = 1;
}
replaceLM = (LayoutManager)list.get(0);
replaceLM.setParent(this);
replaceLM.initialize();
- getLogger().debug("retrieved: " + replaceLM + ":" + list.size());
+ log.debug("retrieved: " + replaceLM + ":" + list.size());
} else {
- getLogger().debug("found no marker with name: " + name);
+ log.debug("found no marker with name: " + name);
}
}
}
if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
blockBreaks.add(bp);
if (bp.isForcedBreak()) {
- getLogger().error("Forced breaks are not allowed in "
+ log.error("Forced breaks are not allowed in "
+ "static content - ignoring");
return null;
}
*/
public void addMarker(Map marks, boolean start, boolean isfirst) {
// error markers not allowed in static
- getLogger().error("Cannot add marker to static areas");
+ log.error("Cannot add marker to static areas");
}
}
if (prevPos != null) {
// ASSERT (prevPos.getLM() == this)
if (prevPos.getLM() != this) {
- getLogger().error(
+ log.error(
"TextLayoutManager.resetPosition: " + "LM mismatch!!!");
}
LeafPosition tbp = (LeafPosition) prevPos;
if (columns == null) {
setFinished(true);
- getLogger().warn("ignoring fo:table-body with undefined fo:table-columns");
+ log.warn("ignoring fo:table-body with undefined fo:table-columns");
return null;
}
while ((curLM = getChildLM()) != null) {
if (curLM.generatesInlineAreas()) {
- getLogger().error("table-cell must contain block areas - ignoring");
+ log.error("table-cell must contain block areas - ignoring");
curLM.setFinished(true);
continue;
}
if (back.getURL() != null) { // TODO: implement
ImageFactory fact = ImageFactory.getInstance();
FopImage fopimage = fact.getImage(back.getURL(), userAgent);
- if (fopimage != null && fopimage.load(FopImage.DIMENSIONS, userAgent.getLogger())) {
+ if (fopimage != null && fopimage.load(FopImage.DIMENSIONS)) {
if (back.getRepeat() == BackgroundRepeat.REPEAT) {
// create a pattern for the image
} else {
if (back.getURL() != null) {
ImageFactory fact = ImageFactory.getInstance();
FopImage fopimage = fact.getImage(back.getURL(), userAgent);
- if (fopimage != null && fopimage.load(FopImage.DIMENSIONS, userAgent.getLogger())) {
+ if (fopimage != null && fopimage.load(FopImage.DIMENSIONS)) {
if (back.getRepeat() == BackgroundRepeat.REPEAT) {
// create a pattern for the image
} else {
if (fopimage == null) {
return;
}
- if (!fopimage.load(FopImage.DIMENSIONS, userAgent.getLogger())) {
+ if (!fopimage.load(FopImage.DIMENSIONS)) {
return;
}
String mime = fopimage.getMimeType();
if ("text/xml".equals(mime)) {
- if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent.getLogger())) {
+ if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
return;
}
Document doc = ((XMLImage) fopimage).getDocument();
renderDocument(doc, ns, pos);
} else if ("image/svg+xml".equals(mime)) {
- if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent.getLogger())) {
+ if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
return;
}
Document doc = ((XMLImage) fopimage).getDocument();
renderDocument(doc, ns, pos);
} else if ("image/eps".equals(mime)) {
- if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent.getLogger())) {
+ if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
return;
}
FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
int xobj = pdfDoc.addImage(currentContext, pdfimage).getXNumber();
fact.releaseImage(url, userAgent);
} else if ("image/jpeg".equals(mime)) {
- if (!fopimage.load(FopImage.ORIGINAL_DATA, userAgent.getLogger())) {
+ if (!fopimage.load(FopImage.ORIGINAL_DATA)) {
return;
}
FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
placeImage((int) pos.getX() / 1000,
(int) pos.getY() / 1000, w, h, xobj);
} else {
- if (!fopimage.load(FopImage.BITMAP, userAgent.getLogger())) {
+ if (!fopimage.load(FopImage.BITMAP)) {
return;
}
FopPDFImage pdfimage = new FopPDFImage(fopimage, url);
import org.apache.fop.svg.SVGUserAgent;
import org.apache.fop.fonts.FontInfo;
+// Commons-Logging
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
/* org.w3c.dom.Document is not imported to avoid conflict with
- org.apache.fop.control.Document */
+ org.apache.fop.apps.Document */
import java.io.OutputStream;
* The properties from the PDF renderer are subject to change.
*/
public class PDFXMLHandler implements XMLHandler {
+
+ /**
+ * logging instance
+ */
+ private Log log = LogFactory.getLog(PDFXMLHandler.class);
+
/**
* The PDF document that is being drawn into.
*/
int yOffset = pdfInfo.currentYPosition;
SVGUserAgent ua
- = new SVGUserAgent(context.getUserAgent().getLogger(),
- context.getUserAgent().getPixelUnitToMillimeter(),
+ = new SVGUserAgent(context.getUserAgent().getPixelUnitToMillimeter(),
new AffineTransform());
GVTBuilder builder = new GVTBuilder();
try {
root = builder.build(ctx, doc);
} catch (Exception e) {
- context.getUserAgent().getLogger().error("svg graphic could not be built: "
+ log.error("svg graphic could not be built: "
+ e.getMessage(), e);
return;
}
root.paint(graphics);
pdfInfo.currentStream.add(graphics.getString());
} catch (Exception e) {
- context.getUserAgent().getLogger().error("svg graphic could not be rendered: "
+ log.error("svg graphic could not be rendered: "
+ e.getMessage(), e);
}
/**
* @see org.apache.fop.image.FopImage#load(int, org.apache.commons.logging.Log)
*/
- public boolean load(int type, Log logger) {
+ public boolean load(int type) {
switch (type) {
case FopImage.DIMENSIONS: break;
case FopImage.BITMAP: break;
if (back.getURL() != null) {
ImageFactory fact = ImageFactory.getInstance();
FopImage fopimage = fact.getImage(back.getURL(), userAgent);
- if (fopimage != null && fopimage.load(FopImage.DIMENSIONS, userAgent.getLogger())) {
+ if (fopimage != null && fopimage.load(FopImage.DIMENSIONS)) {
if (back.getRepeat() == BackgroundRepeat.REPEAT) {
// create a pattern for the image
} else {
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.ViewBox;
import org.apache.batik.gvt.GraphicsNode;
+
// FOP
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.XMLHandler;
import org.apache.fop.render.RendererContext;
import org.apache.fop.svg.SVGUserAgent;
+// Commons-Logging
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* PostScript XML handler.
* This handler handles XML for foreign objects when rendering to PostScript.
*/
public class PSXMLHandler implements XMLHandler {
+ /**
+ * logging instance
+ */
+ private Log log = LogFactory.getLog(PSXMLHandler.class);
+
/**
* The PostScript generator that is being used to drawn into.
*/
PSGenerator gen = psInfo.psGenerator;
SVGUserAgent ua
- = new SVGUserAgent(context.getUserAgent().getLogger(),
- context.getUserAgent().getPixelUnitToMillimeter(),
- new AffineTransform());
+ = new SVGUserAgent(
+ context.getUserAgent().getPixelUnitToMillimeter(),
+ new AffineTransform());
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(ua);
try {
root = builder.build(ctx, doc);
} catch (Exception e) {
- context.getUserAgent().getLogger().error("SVG graphic could not be built: "
+ log.error("SVG graphic could not be built: "
+ e.getMessage(), e);
return;
}
root.paint(graphics);
//psInfo.currentStream.add(graphics.getString());
} catch (Exception e) {
- context.getUserAgent().getLogger().error("SVG graphic could not be rendered: "
+ log.error("SVG graphic could not be rendered: "
+ e.getMessage(), e);
}
//psInfo.pdfState.pop();
gen.writeln("%SVG graphic end ---");
} catch (IOException ioe) {
- context.getUserAgent().getLogger().error("SVG graphic could not be rendered: "
+ log.error("SVG graphic could not be rendered: "
+ ioe.getMessage(), ioe);
}
}
JpegImage jpeg = new JpegImage(ii);
SimpleLog logger = new SimpleLog("FOP/SVG");
logger.setLevel(SimpleLog.LOG_LEVEL_INFO);
- jpeg.load(FopImage.ORIGINAL_DATA, logger);
+ jpeg.load(FopImage.ORIGINAL_DATA);
PDFJpegNode node = new PDFJpegNode(jpeg, origGN);
Rectangle2D imgBounds = getImageBounds(ctx, e);
import java.awt.geom.Dimension2D;
import java.awt.Dimension;
+// Commons-Logging
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* The SVG user agent.
* This is an implementation of the batik svg user agent
*/
public class SVGUserAgent extends UserAgentAdapter {
private AffineTransform currentTransform = null;
- private Log logger;
private float pixelUnitToMillimeter = 0.0f;
+ /**
+ * logging instance
+ */
+ private Log logger = LogFactory.getLog(SVGUserAgent.class);
+
/**
* Creates a new SVGUserAgent.
* @param log an Commons logging instance
* currently in effect
* @param at the current transform
*/
- public SVGUserAgent(Log log, float pixelUnitToMM, AffineTransform at) {
- logger = log;
+ public SVGUserAgent(float pixelUnitToMM, AffineTransform at) {
pixelUnitToMillimeter = pixelUnitToMM;
currentTransform = at;
}
org.apache.fop.apps.Document doc = new org.apache.fop.apps.Document(null);
rend.setupFontInfo(doc.getFontInfo());
FOUserAgent ua = new FOUserAgent();
- ua.setLogger(logger);
rend.setUserAgent(ua);
StorePagesModel sm = AreaTree.createStorePagesModel();
Driver driver = new Driver();
FOUserAgent userAgent = new FOUserAgent();
- userAgent.setLogger(getLogger());
userAgent.setBaseURL(baseURL);
driver.setUserAgent(userAgent);
if (outputPDF) {
driver.setLogger(getLogger());
FOUserAgent userAgent = new FOUserAgent();
userAgent.setBaseURL(this.baseURL);
- userAgent.setLogger(getLogger());
driver.setUserAgent(userAgent);
driver.setRenderer(renderer);
driver.setOutputStream(out);