From dfbc6541081135b845df8bcc0be633669cbe3553 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Tue, 16 Mar 2004 06:49:35 +0000 Subject: [PATCH] Synchronized changes to base URL handling from HEAD. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197452 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/apps/FOFileHandler.java | 1 + .../org/apache/fop/apps/InputHandler.java | 25 +++++++++++++++++++ .../org/apache/fop/apps/XSLTInputHandler.java | 2 ++ .../apache/fop/configuration/FOUserAgent.java | 7 ++---- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/fop/apps/FOFileHandler.java b/src/java/org/apache/fop/apps/FOFileHandler.java index a8a003e6f..cce1681eb 100644 --- a/src/java/org/apache/fop/apps/FOFileHandler.java +++ b/src/java/org/apache/fop/apps/FOFileHandler.java @@ -39,6 +39,7 @@ public class FOFileHandler extends InputHandler { */ public FOFileHandler(File fofile) { this.fofile = fofile; + setBaseURL(fofile); } /** diff --git a/src/java/org/apache/fop/apps/InputHandler.java b/src/java/org/apache/fop/apps/InputHandler.java index 6ace226fd..4efa2c91f 100644 --- a/src/java/org/apache/fop/apps/InputHandler.java +++ b/src/java/org/apache/fop/apps/InputHandler.java @@ -41,6 +41,31 @@ public abstract class InputHandler { */ public abstract InputSource getInputSource(); + protected String baseURL = null; + + /** + * Get the base URL associated with this input source + * @return the input source + */ + public String getBaseURL() { + return baseURL; + } + + /** + * Attempts to set a default base URL from the parent of the file passed + * as an argument. Sets baseURL to the URL derived, or to an + * empty string if that fails. + * @param file + */ + protected void setBaseURL(File file) { + try { + baseURL = + new File(file.getAbsolutePath()).getParentFile().toURL().toExternalForm(); + } catch (Exception e) { + baseURL = ""; + } + } + /** * Get the SAX parser associated with this input handler. * @return the SAX parser diff --git a/src/java/org/apache/fop/apps/XSLTInputHandler.java b/src/java/org/apache/fop/apps/XSLTInputHandler.java index 882033616..9aa83eeeb 100644 --- a/src/java/org/apache/fop/apps/XSLTInputHandler.java +++ b/src/java/org/apache/fop/apps/XSLTInputHandler.java @@ -55,6 +55,7 @@ public class XSLTInputHandler extends InputHandler { public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) { this.xmlSource = new StreamSource(xmlfile); this.xsltSource = new StreamSource(xsltfile); + setBaseURL(xmlfile); xsltParams = params; } @@ -67,6 +68,7 @@ public class XSLTInputHandler extends InputHandler { public XSLTInputHandler(File xmlfile, File xsltfile) { this.xmlSource = new StreamSource(xmlfile); this.xsltSource = new StreamSource(xsltfile); + setBaseURL(xmlfile); } /** diff --git a/src/java/org/apache/fop/configuration/FOUserAgent.java b/src/java/org/apache/fop/configuration/FOUserAgent.java index 7e7a46f25..fc35f0b25 100644 --- a/src/java/org/apache/fop/configuration/FOUserAgent.java +++ b/src/java/org/apache/fop/configuration/FOUserAgent.java @@ -20,11 +20,9 @@ package org.apache.fop.configuration; // Java import java.util.Map; +import java.util.logging.Logger; import java.io.InputStream; -// Avalon -import org.apache.avalon.framework.logger.LogEnabled; -import org.apache.avalon.framework.logger.Logger; /** * The User Agent for fo. @@ -46,7 +44,7 @@ import org.apache.avalon.framework.logger.Logger; * These areas may contain resolveable areas that will be processed * with other resolveable areas */ -public class FOUserAgent implements LogEnabled { +public class FOUserAgent { private Logger log; /** Map containing various default values */ @@ -59,7 +57,6 @@ public class FOUserAgent implements LogEnabled { /** * Sets the logger. * @param log Logger to use - * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger) */ public void enableLogging(Logger log) { this.log = log; -- 2.39.5