<formatter type="xml" usefile="true"/>
<classpath>
<pathelement location="${build.dir}/test-classes"/>
+ <path refid="libs-build-classpath"/>
<fileset dir="build">
<include name="fop-transcoder-allinone.jar"/>
</fileset>
</junit>
</target>
+ <target name="junit-userconfig" depends="junit-compile" if="junit.present" description="Runs FOP's user config JUnit tests">
+ <echo message="Running user config tests"/>
+ <junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
+ <sysproperty key="basedir" value="${basedir}"/>
+ <sysproperty key="jawa.awt.headless" value="true"/>
+ <sysproperty key="fop.layoutengine.disabled" value="${layoutengine.disabled}"/>
+ <sysproperty key="fop.layoutengine.testset" value="standard"/>
+ <formatter type="brief" usefile="false"/>
+ <formatter type="plain" usefile="true"/>
+ <formatter type="xml" usefile="true"/>
+ <classpath>
+ <pathelement location="${build.dir}/test-classes"/>
+ <path refid="libs-run-classpath"/>
+ </classpath>
+ <test name="org.apache.fop.config.UserConfigTestSuite" todir="${junit.reports.dir}" outfile="TEST-userconfig"/>
+ </junit>
+ </target>
+
<target name="junit-basic" depends="junit-compile" description="Runs FOP's JUnit basic tests" if="junit.present">
<echo message="Running basic functionality tests for fop.jar"/>
<junit dir="${basedir}" haltonfailure="${junit.haltonfailure}" fork="${junit.fork}" errorproperty="fop.junit.error" failureproperty="fop.junit.failure">
</junit>
</target>
- <target name="junit" depends="junit-basic, junit-transcoder, junit-text-linebreak, junit-layout, junit-fotree, junit-intermediate-format" description="Runs all of FOP's JUnit tests" if="junit.present">
+ <target name="junit" depends="junit-userconfig, junit-basic, junit-transcoder, junit-text-linebreak, junit-layout, junit-fotree, junit-intermediate-format" description="Runs all of FOP's JUnit tests" if="junit.present">
<fail>
<condition>
<or>
<tr>
<th>Element</th>
<th>Data Type (for the value)</th>
+ <th>Description</th>
<th>Default Value</th>
</tr>
<tr>
<td>base</td>
<td>URL or directory</td>
<td>Specifies the base URL based on which relative URL will be resolved.</td>
+ <td>current directory</td>
</tr>
<tr>
<td>font-base</td>
<td>URL or directory</td>
<td>Specifies the base URL based on which relative font URLs will be resolved.
- If not specified defaults to the base URL above.
</td>
+ <td>base URL/directory (above)</td>
</tr>
<tr>
<td>hyphenation-base</td>
files will be resolved. If not specified, support for user-supplied hyphenation
patterns remains disabled.
</td>
+ <td>disabled</td>
</tr>
<tr>
<td>source-resolution</td>
Resolution in dpi (dots per inch) which is used internally to determine the pixel
size for SVG images and bitmap images without resolution information.
</td>
+ <td>72 dpi</td>
</tr>
<tr>
<td>target-resolution</td>
images generated by bitmap renderers (such as the TIFF renderer) and by bitmaps
generated by Apache Batik for filter effects and such.
</td>
+ <td>72 dpi</td>
+ </tr>
+ <tr>
+ <td>strict-configuration</td>
+ <td>Boolean (true, false)</td>
+ <td>
+ Setting this option to 'true' will cause FOP to strictly verify the contents of the
+ FOP configuration file to ensure that defined resources (such as fonts and base
+ URLs/directories) are valid and available to FOP. Any errors found will cause FOP to
+ immediately raise an exception.</td>
+ <td>false</td>
</tr>
<tr>
<td>strict-validation</td>
Setting this option to 'false' causes FOP to be more forgiving about XSL-FO validity,
for example, you're allowed to specify a border on a region-body which is supported
by some FO implementations but is non-standard. Note that such a border would
- currently have no effect in Apache FOP.</td>
+ currently have no effect in Apache FOP.</td>
+ <td>true</td>
</tr>
<tr>
<td>break-indent-inheritance</td>
the desired behaviour and because the behaviour among the commercial implementations
varies. The default for this option (i.e. false) is to behave exactly like the
specification describes.</td>
+ <td>false</td>
</tr>
<tr>
<td>default-page-settings</td>
Specifies the default width and height of a page if "auto" is specified
for either or both values. Use "height" and "width" attributes on the
default-page-settings element to specify the two values.</td>
+ <td>"height" 11 inches, "width" 8.26 inches</td>
</tr>
<tr>
<td>renderers</td>
<td>(see text below)</td>
<td>Contains the configuration for each renderer. See below.</td>
+ <td>N/A</td>
</tr>
</table>
<p>
<source><![CDATA[
<fop version="1.0">
+ <!-- Strict user configuration -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Strict FO validation -->
+ <strict-validation>true</strict-validation>
+
<!-- Base URL for resolving relative URLs -->
<base>./</base>
type="xsd:positiveInteger" minOccurs="0">
</xsd:element>
<xsd:element name="strict-validation" type="xsd:boolean" minOccurs="0"></xsd:element>
+ <xsd:element name="strict-configuration" type="xsd:boolean" minOccurs="0"></xsd:element>
<xsd:element name="break-indent-inheritance"
type="xsd:boolean" minOccurs="0">
</xsd:element>
try {
absoluteURL = f.toURL();
} catch (MalformedURLException mfue) {
- log.error("Could not convert filename to URL: " + mfue.getMessage(), mfue);
+ log.error("Could not convert filename to URL: " + mfue.getMessage());
}
} else {
URL baseURL = toBaseURL(base);
// the href contains only a path then file: is assumed
absoluteURL = new URL("file:" + href);
} catch (MalformedURLException mfue) {
- log.error("Error with URL '" + href + "': " + mue.getMessage(), mue);
+ log.error("Error with URL '" + href + "': " + mue.getMessage());
return null;
}
}
}
absoluteURL = new URL(baseURL, href);
} catch (MalformedURLException mfue) {
- log.error("Error with URL '" + href + "': " + mfue.getMessage(), mfue);
+ log.error("Error with URL '" + href + "': " + mfue.getMessage());
return null;
}
}
//Note: This is on "debug" level since the caller is supposed to handle this
log.debug("File not found: " + effURL);
} catch (java.io.IOException ioe) {
- log.error("Error with opening URL '" + href + "': " + ioe.getMessage(), ioe);
+ log.error("Error with opening URL '" + href + "': " + ioe.getMessage());
}
return null;
}
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
-// avalon configuration
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
// commons logging
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class FOUserAgent {
/** Defines the default target resolution (72dpi) for FOP */
- public static final float DEFAULT_TARGET_RESOLUTION = 72.0f; //dpi
+ public static final float DEFAULT_TARGET_RESOLUTION = FopFactory.DEFAULT_TARGET_RESOLUTION;
private static Log log = LogFactory.getLog("FOP");
/**
* Default constructor
+ * @throws FOPException
* @see org.apache.fop.apps.FopFactory
* @deprecated Provided for compatibility only. Please use the methods from
* FopFactory to construct FOUserAgent instances!
*/
- public FOUserAgent() {
+ public FOUserAgent() throws FOPException {
this(FopFactory.newInstance());
}
throw new NullPointerException("The factory parameter must not be null");
}
this.factory = factory;
- if (factory.getUserConfig() != null) {
- configure(factory.getUserConfig());
- }
+ setBaseURL(factory.getBaseURL());
+ setTargetResolution(factory.getTargetResolution());
}
/** @return the associated FopFactory instance */
public Map getRendererOptions() {
return rendererOptions;
}
-
- /**
- * Configures the FOUserAgent through the factory's configuration.
- * @param cfg Avalon Configuration Object
- * @see org.apache.avalon.framework.configuration.Configurable
- */
- protected void configure(Configuration cfg) {
- setBaseURL(FopFactory.getBaseURLfromConfig(cfg, "base"));
- if (cfg.getChild("target-resolution", false) != null) {
- this.targetResolution
- = cfg.getChild("target-resolution").getValueAsFloat(
- DEFAULT_TARGET_RESOLUTION);
- log.info("Target resolution set to: " + targetResolution
- + "dpi (px2mm=" + getTargetPixelUnitToMillimeter() + ")");
- }
- }
- /**
- * Returns the configuration subtree for a specific renderer.
- * @param mimeType MIME type of the renderer
- * @return the requested configuration subtree, null if there's no configuration
- */
- public Configuration getUserRendererConfig(String mimeType) {
-
- Configuration cfg = getFactory().getUserConfig();
- if (cfg == null || mimeType == null) {
- return null;
- }
-
- Configuration userRendererConfig = null;
-
- Configuration[] cfgs
- = cfg.getChild("renderers").getChildren("renderer");
- for (int i = 0; i < cfgs.length; ++i) {
- Configuration child = cfgs[i];
- try {
- if (child.getAttribute("mime").equals(mimeType)) {
- userRendererConfig = child;
- break;
- }
- } catch (ConfigurationException e) {
- // silently pass over configurations without mime type
- }
- }
- log.debug((userRendererConfig == null ? "No u" : "U")
- + "ser configuration found for MIME type " + mimeType);
- return userRendererConfig;
- }
-
/**
* Sets the base URL.
* @param baseURL base URL
* bitmap images generated by filter effects in Apache Batik.
* @param dpi resolution in dpi
*/
- public void setTargetResolution(int dpi) {
+ public void setTargetResolution(float dpi) {
this.targetResolution = dpi;
+ log.info("target-resolution set to: " + targetResolution
+ + "dpi (px2mm=" + getTargetPixelUnitToMillimeter() + ")");
+ }
+
+ /**
+ * Sets the target resolution in dpi. This value defines the target resolution of
+ * bitmap images generated by the bitmap renderers (such as the TIFF renderer) and of
+ * bitmap images generated by filter effects in Apache Batik.
+ * @param dpi resolution in dpi
+ */
+ public void setTargetResolution(int dpi) {
+ setTargetResolution((float)dpi);
}
// ---------------------------------------------- environment-level stuff
/** @return the font base URL */
public String getFontBaseURL() {
String fontBaseURL = getFactory().getFontBaseURL();
- return fontBaseURL != null ? fontBaseURL : this.baseURL;
+ return fontBaseURL != null ? fontBaseURL : getBaseURL();
}
/**
public XMLHandlerRegistry getXMLHandlerRegistry() {
return getFactory().getXMLHandlerRegistry();
}
-
}
import org.apache.fop.util.ContentHandlerFactoryRegistry;
/**
- * Factory class which instantiates new Fop and FOUserAgent instances. This class also holds
- * environmental information and configuration used by FOP. Information that may potentially be
- * different for each rendering run can be found and managed in the FOUserAgent.
+ * Factory class which instantiates new Fop and FOUserAgent instances. This
+ * class also holds environmental information and configuration used by FOP.
+ * Information that may potentially be different for each rendering run can be
+ * found and managed in the FOUserAgent.
*/
public class FopFactory {
+
+ /** Defines the default target resolution (72dpi) for FOP */
+ public static final float DEFAULT_TARGET_RESOLUTION = 72.0f; //dpi
/** Defines the default source resolution (72dpi) for FOP */
private static final float DEFAULT_SOURCE_RESOLUTION = 72.0f; //dpi
+
/** Defines the default page-height */
private static final String DEFAULT_PAGE_HEIGHT = "11in";
+
/** Defines the default page-width */
private static final String DEFAULT_PAGE_WIDTH = "8.26in";
+
+ /** Defines if FOP should use strict validation for FO and user config */
+ private static final boolean DEFAULT_STRICT_FO_VALIDATION = true;
+
+ /** Defines if FOP should validate the user config strictly */
+ private static final boolean DEFAULT_STRICT_USERCONFIG_VALIDATION = true;
+
+ /** Defines if FOP should use an alternative rule to determine text indents */
+ private static final boolean DEFAULT_BREAK_INDENT_INHERITANCE = false;
/** logger instance */
private static Log log = LogFactory.getLog(FopFactory.class);
/** Our default resolver if none is set */
private URIResolver foURIResolver = new FOURIResolver();
+
/** A user settable URI Resolver */
private URIResolver uriResolver = null;
/** user configuration */
private Configuration userConfig = null;
- /** The base URL for all font URL resolutions */
+ /**
+ * The base URL for all URL resolutions, especially for
+ * external-graphics.
+ */
+ private String baseURL;
+
+ /** The base URL for all font URL resolutions. */
private String fontBaseURL;
-
+
+ /** The base URL for all hyphen URL resolutions. */
+ private String hyphenBaseURL;
+
/**
* FOP has the ability, for some FO's, to continue processing even if the
* input XSL violates that FO's content model. This is the default
* behavior for FOP. However, this flag, if set, provides the user the
- * ability for FOP to halt on all content model violations if desired.
+ * ability for FOP to halt on all content model violations if desired.
*/
- private boolean strictValidation = true;
+ private boolean strictFOValidation = DEFAULT_STRICT_FO_VALIDATION;
+ /**
+ * FOP will validate the contents of the user configuration strictly
+ * (e.g. base-urls and font urls/paths).
+ */
+ private boolean strictUserConfigValidation = DEFAULT_STRICT_USERCONFIG_VALIDATION;
+
/** Allows enabling kerning on the base 14 fonts, default is false */
private boolean enableBase14Kerning = false;
/** Source resolution in dpi */
private float sourceResolution = DEFAULT_SOURCE_RESOLUTION;
+
+ /** Target resolution in dpi */
+ private float targetResolution = DEFAULT_TARGET_RESOLUTION;
+
+ /** Page height */
private String pageHeight = DEFAULT_PAGE_HEIGHT;
+
+ /** Page width */
private String pageWidth = DEFAULT_PAGE_WIDTH;
/** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
- private boolean breakIndentInheritanceOnReferenceAreaBoundary = false;
+ private boolean breakIndentInheritanceOnReferenceAreaBoundary
+ = DEFAULT_BREAK_INDENT_INHERITANCE;
/** Optional overriding LayoutManagerMaker */
private LayoutManagerMaker lmMakerOverride = null;
* are particular to a rendering run. Don't reuse instances over multiple rendering runs but
* instead create a new one each time and reuse the FopFactory.
* @return the newly created FOUserAgent instance initialized with default values
+ * @throws FOPException
*/
public FOUserAgent newFOUserAgent() {
FOUserAgent userAgent = new FOUserAgent(this);
return this.lmMakerOverride;
}
+ /**
+ * Sets the base URL.
+ * @param baseURL base URL
+ */
+ void setBaseURL(String baseURL) {
+ this.baseURL = baseURL;
+ }
+
+ /**
+ * Returns the base URL.
+ * @return the base URL
+ */
+ public String getBaseURL() {
+ return this.baseURL;
+ }
+
/**
* Sets the font base URL.
* @param fontBaseURL font base URL
return this.fontBaseURL;
}
+ /** @return the hyphen base URL */
+ public String getHyphenBaseURL() {
+ return hyphenBaseURL;
+ }
+
+ /**
+ * Sets the hyphen base URL.
+ * @param hyphenBaseURL hythen base URL
+ */
+ public void setHyphenBaseURL(final String hyphenBaseURL) {
+ if (hyphenBaseURL != null) {
+ this.hyphResolver = new HyphenationTreeResolver() {
+ public Source resolve(String href) {
+ return resolveURI(href, hyphenBaseURL);
+ }
+ };
+ }
+ this.hyphenBaseURL = hyphenBaseURL;
+ }
+
/**
* Sets the URI Resolver. It is used for resolving factory-level URIs like hyphenation
* patterns and as backup for URI resolution performed during a rendering run.
* @param validateStrictly true to turn on strict validation
*/
public void setStrictValidation(boolean validateStrictly) {
- this.strictValidation = validateStrictly;
+ this.strictFOValidation = validateStrictly;
}
/**
* @return true of strict validation turned on, false otherwise
*/
public boolean validateStrictly() {
- return strictValidation;
+ return strictFOValidation;
}
/**
public float getSourcePixelUnitToMillimeter() {
return 25.4f / getSourceResolution();
}
-
+
/**
* Sets the source resolution in dpi. This value is used to interpret the pixel size
* of source documents like SVG images and bitmap images without resolution information.
* @param dpi resolution in dpi
*/
- public void setSourceResolution(int dpi) {
+ public void setSourceResolution(float dpi) {
this.sourceResolution = dpi;
+ log.info("source-resolution set to: " + sourceResolution
+ + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
+ }
+
+ /** @return the resolution for resolution-dependant output */
+ public float getTargetResolution() {
+ return this.targetResolution;
+ }
+
+ /**
+ * Returns the conversion factor from pixel units to millimeters. This
+ * depends on the desired target resolution.
+ * @return float conversion factor
+ * @see #getTargetResolution()
+ */
+ public float getTargetPixelUnitToMillimeter() {
+ return 25.4f / this.targetResolution;
+ }
+
+ /**
+ * Sets the source resolution in dpi. This value is used to interpret the pixel size
+ * of source documents like SVG images and bitmap images without resolution information.
+ * @param dpi resolution in dpi
+ */
+ public void setTargetResolution(float dpi) {
+ this.targetResolution = dpi;
+ }
+
+ /**
+ * Sets the source resolution in dpi. This value is used to interpret the pixel size
+ * of source documents like SVG images and bitmap images without resolution information.
+ * @param dpi resolution in dpi
+ */
+ public void setSourceResolution(int dpi) {
+ setSourceResolution((float)dpi);
}
/**
*/
public void setPageHeight(String pageHeight) {
this.pageHeight = pageHeight;
+ log.info("Default page-height set to: " + pageHeight);
}
/**
*/
public void setPageWidth(String pageWidth) {
this.pageWidth = pageWidth;
+ log.info("Default page-width set to: " + pageWidth);
}
/**
* @throws IOException if an I/O error occurs
* @throws SAXException if a parsing error occurs
*/
- public void setUserConfig(File userConfigFile)
- throws SAXException, IOException {
+ public void setUserConfig(File userConfigFile) throws SAXException, IOException {
try {
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
setUserConfig(cfgBuilder.buildFromFile(userConfigFile));
- } catch (ConfigurationException cfge) {
- log.error("Error loading configuration: "
- + cfge.getMessage());
+ } catch (ConfigurationException e) {
+ throw new FOPException(e);
}
}
* @throws IOException if an I/O error occurs
* @throws SAXException if a parsing error occurs
*/
- public void setUserConfig(String uri)
- throws SAXException, IOException {
+ public void setUserConfig(String uri) throws SAXException, IOException {
try {
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
setUserConfig(cfgBuilder.build(uri));
- } catch (ConfigurationException cfge) {
- log.error("Error loading configuration: "
- + cfge.getMessage());
+ } catch (ConfigurationException e) {
+ throw new FOPException(e);
}
}
/**
* Set the user configuration.
* @param userConfig configuration
+ * @throws FOPException if a configuration problem occurs
*/
- public void setUserConfig(Configuration userConfig) {
+ public void setUserConfig(Configuration userConfig) throws FOPException {
this.userConfig = userConfig;
try {
- initUserConfig();
- } catch (ConfigurationException cfge) {
- log.error("Error initializing factory configuration: "
- + cfge.getMessage());
+ configure(userConfig);
+ } catch (ConfigurationException e) {
+ throw new FOPException(e);
}
}
public Configuration getUserConfig() {
return userConfig;
}
-
+
+ /**
+ * Returns the configuration subtree for a specific renderer.
+ * @param mimeType MIME type of the renderer
+ * @return the requested configuration subtree, null if there's no configuration
+ */
+ public Configuration getUserRendererConfig(String mimeType) {
+ if (userConfig == null || mimeType == null) {
+ return null;
+ }
+
+ Configuration userRendererConfig = null;
+
+ Configuration[] cfgs
+ = userConfig.getChild("renderers").getChildren("renderer");
+ for (int i = 0; i < cfgs.length; ++i) {
+ Configuration child = cfgs[i];
+ try {
+ if (child.getAttribute("mime").equals(mimeType)) {
+ userRendererConfig = child;
+ break;
+ }
+ } catch (ConfigurationException e) {
+ // silently pass over configurations without mime type
+ }
+ }
+ log.debug((userRendererConfig == null ? "No u" : "U")
+ + "ser configuration found for MIME type " + mimeType);
+ return userRendererConfig;
+ }
+
/**
* Initializes user agent settings from the user configuration
* file, if present: baseURL, resolution, default page size,...
*
* @throws ConfigurationException when there is an entry that
* misses the required attribute
+ * Configures the FopFactory.
+ * @param cfg Avalon Configuration Object
+ * @see org.apache.avalon.framework.configuration.Configurable
*/
- public void initUserConfig() throws ConfigurationException {
- log.debug("Initializing User Agent Configuration");
- setFontBaseURL(getBaseURLfromConfig(userConfig, "font-base"));
- final String hyphBase = getBaseURLfromConfig(userConfig, "hyphenation-base");
- if (hyphBase != null) {
- this.hyphResolver = new HyphenationTreeResolver() {
- public Source resolve(String href) {
- return resolveURI(href, hyphBase);
+ public void configure(Configuration cfg) throws ConfigurationException {
+ log.info("Initializing FopFactory Configuration");
+
+ if (cfg.getChild("strict-configuration", false) != null) {
+ this.strictUserConfigValidation
+ = cfg.getChild("strict-configuration").getValueAsBoolean();
+ }
+ if (cfg.getChild("strict-validation", false) != null) {
+ this.strictFOValidation = cfg.getChild("strict-validation").getValueAsBoolean();
+ }
+ if (cfg.getChild("base", false) != null) {
+ try {
+ setBaseURL(getBaseURLfromConfig(cfg, "base"));
+ } catch (ConfigurationException e) {
+ if (strictUserConfigValidation) {
+ throw e;
}
- };
+ log.error(e.getMessage());
+ }
}
- if (userConfig.getChild("source-resolution", false) != null) {
- this.sourceResolution
- = userConfig.getChild("source-resolution").getValueAsFloat(
- DEFAULT_SOURCE_RESOLUTION);
- log.info("Source resolution set to: " + sourceResolution
- + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
+ if (cfg.getChild("font-base", false) != null) {
+ try {
+ setFontBaseURL(getBaseURLfromConfig(cfg, "font-base"));
+ } catch (ConfigurationException e) {
+ if (strictUserConfigValidation) {
+ throw e;
+ }
+ log.error(e.getMessage());
+ }
}
- if (userConfig.getChild("strict-validation", false) != null) {
- this.strictValidation = userConfig.getChild("strict-validation").getValueAsBoolean();
+ if (cfg.getChild("hyphenation-base", false) != null) {
+ try {
+ setHyphenBaseURL(getBaseURLfromConfig(cfg, "hyphenation-base"));
+ } catch (ConfigurationException e) {
+ if (strictUserConfigValidation) {
+ throw e;
+ }
+ log.error(e.getMessage());
+ }
+ }
+ if (cfg.getChild("source-resolution", false) != null) {
+ setSourceResolution(
+ cfg.getChild("source-resolution").getValueAsFloat(DEFAULT_SOURCE_RESOLUTION));
}
- if (userConfig.getChild("break-indent-inheritance", false) != null) {
- this.breakIndentInheritanceOnReferenceAreaBoundary
- = userConfig.getChild("break-indent-inheritance").getValueAsBoolean();
+ if (cfg.getChild("target-resolution", false) != null) {
+ setTargetResolution(
+ cfg.getChild("target-resolution").getValueAsFloat(DEFAULT_TARGET_RESOLUTION));
}
- Configuration pageConfig = userConfig.getChild("default-page-settings");
+ if (cfg.getChild("break-indent-inheritance", false) != null) {
+ setBreakIndentInheritanceOnReferenceAreaBoundary(
+ cfg.getChild("break-indent-inheritance").getValueAsBoolean());
+ }
+ Configuration pageConfig = cfg.getChild("default-page-settings");
if (pageConfig.getAttribute("height", null) != null) {
- setPageHeight(pageConfig.getAttribute("height"));
- log.info("Default page-height set to: " + pageHeight);
+ setPageHeight(pageConfig.getAttribute("height", DEFAULT_PAGE_HEIGHT));
}
if (pageConfig.getAttribute("width", null) != null) {
- setPageWidth(pageConfig.getAttribute("width"));
- log.info("Default page-width set to: " + pageWidth);
+ setPageWidth(pageConfig.getAttribute("width", DEFAULT_PAGE_WIDTH));
}
}
* @param cfg The Configuration object to retrieve the base URL from
* @param name the element name for the base URL
* @return the requested base URL or null if not available
- */
- public static String getBaseURLfromConfig(Configuration cfg, String name) {
+ * @throws ConfigurationException
+ */
+ public static String getBaseURLfromConfig(Configuration cfg, String name)
+ throws ConfigurationException {
if (cfg.getChild(name, false) != null) {
try {
- String cfgBaseDir = cfg.getChild(name).getValue(null);
- if (cfgBaseDir != null) {
- File dir = new File(cfgBaseDir);
+ String cfgBasePath = cfg.getChild(name).getValue(null);
+ if (cfgBasePath != null) {
+ // Is the path a dirname?
+ File dir = new File(cfgBasePath);
+// if (!dir.exists()) {
+// throw new ConfigurationException("Base URL '" + name
+// + "' references non-existent resource '"
+// + cfgBasePath + "'");
+// } else if (dir.isDirectory()) {
if (dir.isDirectory()) {
- cfgBaseDir = dir.toURL().toExternalForm();
+ // Yes, convert it into a URL
+ cfgBasePath = dir.toURL().toExternalForm();
}
+ // Otherwise, this is already a URL
}
- log.info(name + " set to: " + cfgBaseDir);
- return cfgBaseDir;
+ log.info(name + " set to: " + cfgBasePath);
+ return cfgBasePath;
} catch (MalformedURLException mue) {
- log.error("Base URL in user config is malformed!");
+ throw new ConfigurationException("Base URL '" + name
+ + "' in user config is malformed!");
}
}
return null;
}
+ /**
+ * Is the user configuration to be validated?
+ * @param strictUserConfigValidation strict user config validation
+ */
+ public void setStrictUserConfigValidation(boolean strictUserConfigValidation) {
+ this.strictUserConfigValidation = strictUserConfigValidation;
+ }
+
+ /**
+ * Is the user configuration to be validated?
+ * @return if the user configuration should be validated
+ */
+ public boolean validateUserConfigStrictly() {
+ return this.strictUserConfigValidation;
+ }
+
//------------------------------------------- URI resolution
/**
}
return colorSpace;
}
-
}
import org.apache.fop.fonts.base14.CourierBoldOblique;
import org.apache.fop.fonts.base14.Symbol;
import org.apache.fop.fonts.base14.ZapfDingbats;
+import org.apache.fop.render.PrintRenderer;
// commons logging
import org.apache.commons.logging.Log;
};
}
+
/**
* Builds a list of EmbedFontInfo objects for use with the setup() method.
+ *
* @param cfg Configuration object
+ * @param renderer calling Renderer object
* @return List the newly created list of fonts
* @throws ConfigurationException if something's wrong with the config data
*/
- public static List buildFontListFromConfiguration(Configuration cfg)
+ public static List buildFontListFromConfiguration(Configuration cfg, PrintRenderer renderer)
throws ConfigurationException {
List fontList = new java.util.ArrayList();
- Configuration[] font = cfg.getChild("fonts").getChildren("font");
- for (int i = 0; i < font.length; i++) {
- Configuration[] triple = font[i].getChildren("font-triplet");
- List tripleList = new java.util.ArrayList();
- for (int j = 0; j < triple.length; j++) {
- int weight = FontUtil.parseCSS2FontWeight(triple[j].getAttribute("weight"));
- tripleList.add(FontInfo.createFontKey(triple[j].getAttribute("name"),
- triple[j].getAttribute("style"),
- weight));
- }
-
- EmbedFontInfo efi;
- efi = new EmbedFontInfo(font[i].getAttribute("metrics-url", null),
- font[i].getAttributeAsBoolean("kerning", false),
- tripleList, font[i].getAttribute("embed-url", null));
-
- if (log.isDebugEnabled()) {
- log.debug("Adding font " + efi.getEmbedFile()
- + ", metric file " + efi.getMetricsFile());
- for (int j = 0; j < tripleList.size(); ++j) {
- FontTriplet triplet = (FontTriplet) tripleList.get(j);
- log.debug("Font triplet "
- + triplet.getName() + ", "
- + triplet.getStyle() + ", "
- + triplet.getWeight());
+
+ FontResolver fontResolver = renderer.getFontResolver();
+ if (fontResolver == null) {
+ //Ensure that we have minimal font resolution capabilities
+ fontResolver = FontSetup.createMinimalFontResolver();
+ }
+
+ boolean strict
+ = renderer.getUserAgent().getFactory().validateUserConfigStrictly();
+
+ Configuration[] fonts = cfg.getChildren("fonts");
+ for (int f = 0; f < fonts.length; f++) {
+
+ Configuration[] font = fonts[f].getChildren("font");
+ for (int i = 0; i < font.length; i++) {
+
+ String metricsUrl = font[i].getAttribute("metrics-url", null);
+ String embedUrl = font[i].getAttribute("embed-url", null);
+
+ if (metricsUrl == null && embedUrl == null) {
+ if (strict) {
+ throw new ConfigurationException(
+ "Font configuration without metric-url or embed-url");
+ }
+ log.error("Font configuration without metric-url or embed-url");
+ continue;
+ }
+
+ if (metricsUrl != null && fontResolver.resolve(metricsUrl) == null) {
+ if (strict) {
+ throw new ConfigurationException("Failed to resolve font metric-url '"
+ + metricsUrl + "'");
+ }
+ log.error("Failed to resolve font metric-url '" + metricsUrl + "'");
+ continue;
+ }
+
+ if (embedUrl != null && fontResolver.resolve(embedUrl) == null) {
+ if (strict) {
+ throw new ConfigurationException("Failed to resolve font with embed-url '"
+ + embedUrl + "'");
+ }
+ log.error("Failed to resolve font with embed-url '" + embedUrl + "'");
+ continue;
+ }
+
+ boolean useKerning = font[i].getAttributeAsBoolean("kerning", false);
+
+ Configuration[] triple = font[i].getChildren("font-triplet");
+ List tripleList = new java.util.ArrayList();
+ for (int j = 0; j < triple.length; j++) {
+ String name = triple[j].getAttribute("name");
+ if (name == null) {
+ if (strict) {
+ throw new ConfigurationException("font-triplet without name");
+ }
+ log.error("font-triplet without name");
+ continue;
+ }
+
+ String weightStr = triple[j].getAttribute("weight");
+ if (weightStr == null) {
+ if (strict) {
+ throw new ConfigurationException("font-triplet without weight");
+ }
+ log.error("font-triplet without weight");
+ continue;
+ }
+ int weight = FontUtil.parseCSS2FontWeight(weightStr);
+
+ String style = triple[j].getAttribute("style");
+ if (style == null) {
+ if (strict) {
+ throw new ConfigurationException("font-triplet without style");
+ }
+ log.error("font-triplet without style");
+ continue;
+ }
+
+ tripleList.add(FontInfo.createFontKey(name,
+ style, weight));
+ }
+
+ EmbedFontInfo configFontInfo = new EmbedFontInfo(metricsUrl,
+ useKerning, tripleList, embedUrl);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Adding font " + configFontInfo.getEmbedFile()
+ + ", metric file " + configFontInfo.getMetricsFile());
+ for (int j = 0; j < tripleList.size(); ++j) {
+ FontTriplet triplet = (FontTriplet) tripleList.get(j);
+ log.debug("Font triplet "
+ + triplet.getName() + ", "
+ + triplet.getStyle() + ", "
+ + triplet.getWeight());
+ }
}
+ fontList.add(configFontInfo);
}
-
- fontList.add(efi);
}
return fontList;
+ }
+
+ /**
+ * Builds a list of EmbedFontInfo objects for use with the setup() method.
+ *
+ * @param cfg Configuration object
+ * @return List the newly created list of fonts
+ * @throws ConfigurationException if something's wrong with the config data
+ */
+ public static List buildFontListFromConfiguration(Configuration cfg)
+ throws ConfigurationException {
+ return buildFontListFromConfiguration(cfg, null);
}
}
-
/**
* user agent
*/
- protected FOUserAgent userAgent;
+ protected FOUserAgent userAgent = null;
/**
* block progression position
userAgent = agent;
}
+ /**
+ * @see org.apache.fop.render.Renderer#getUserAgent()
+ */
+ public FOUserAgent getUserAgent() {
+ return userAgent;
+ }
+
/** @see org.apache.fop.render.Renderer#startRenderer(OutputStream) */
public void startRenderer(OutputStream outputStream)
throws IOException { }
if (handler != null) {
try {
//Optional XML handler configuration
- Configuration cfg = userAgent.getUserRendererConfig(getMimeType());
+ Configuration cfg = userAgent.getFactory().getUserRendererConfig(getMimeType());
if (cfg != null) {
cfg = getHandlerConfig(cfg, namespace);
if (cfg != null) {
/** Font configuration */
protected FontInfo fontInfo;
+ /** Font resolver */
+ protected FontResolver fontResolver = null;
+
/** list of fonts */
protected List fontList = null;
-
+
/**
* Set up the font info
*
*/
public void setupFontInfo(FontInfo inFontInfo) {
this.fontInfo = inFontInfo;
- FontResolver resolver = new DefaultFontResolver(userAgent);
- FontSetup.setup(fontInfo, fontList, resolver,
+ FontSetup.setup(fontInfo, fontList, fontResolver,
userAgent.getFactory().isBase14KerningEnabled());
}
renderXML(context, doc, ns);
}
-
+
+ /**
+ * Get FontResolver
+ *
+ * @return FontResolver
+ */
+ public FontResolver getFontResolver() {
+ if (this.fontResolver == null) {
+ this.fontResolver = new DefaultFontResolver(super.userAgent);
+ }
+ return this.fontResolver;
+ }
}
Configuration userRendererConfig = null;
if (mimeType != null) {
userRendererConfig
- = userAgent.getUserRendererConfig(mimeType);
+ = userAgent.getFactory().getUserRendererConfig(mimeType);
}
if (userRendererConfig != null) {
try {
this.filterMap = PDFFilterList.buildFilterMapFromConfiguration(cfg);
//Font configuration
- List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
+ List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg, this);
if (this.fontList == null) {
this.fontList = cfgFonts;
} else {
this.autoRotateLandscape = cfg.getChild("auto-rotate-landscape").getValueAsBoolean(false);
//Font configuration
- List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
+ List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg, this);
if (this.fontList == null) {
this.fontList = cfgFonts;
} else {
public void configure(Configuration cfg) throws ConfigurationException {
super.configure(cfg);
//Font configuration
- List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg);
+ List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg, this);
if (this.fontList == null) {
this.fontList = cfgFonts;
} else {
<changes>
<release version="FOP Trunk">
+ <action context="Code" dev="VH" type="fix" fixes-bug="40120" due-to="Adrian Cumiskey">
+ Stricter FOP user configuration checking
+ </action>
<action context="Code" dev="AD" type="fix" fixes-bug="41572" due-to="Erwin Tratar">
Fix parsing 'url(...)' when the URL itself contains a bracketed part.
</action>
--- /dev/null
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Strict configuration On -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./</font-base>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <!-- this font has an embed-url that does not exist on filesystem -->
+ <font metrics-url="test/resources/fonts/glb12.ttf.xml" embed-url="test/resources/fonts/doesnotexist.ttf">
+ <font-triplet name="Gladiator-Ansi" style="normal" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
--- /dev/null
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Strict configuration On -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./</font-base>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <!-- this font has a malformed embed-url -->
+ <font metrics-url="test/resources/fonts/glb12.ttf.xml" embed-url="badprotocol:test/resources/fonts/glb12.ttf">
+ <font-triplet name="Gladiator-Ansi" style="normal" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
--- /dev/null
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Strict configuration On -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./</font-base>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <!-- this font is without a metrics-url -->
+ <font>
+ <font-triplet name="Gladiator" style="normal" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
--- /dev/null
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Strict configuration On -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./doesnotexist/</font-base>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <!-- this font is with a relative metrics-url
+ so should call upon the bad font-base -->
+ <font metrics-url="test/resources/fonts/glb12.ttf.xml" embed-url="test/resources/fonts/glb12.ttf">
+ <font-triplet name="Gladiator" style="normal" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
--- /dev/null
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Strict configuration On -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./</font-base>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <font metrics-url="test/resources/fonts/glb12.ttf.xml">
+ <!-- this font-triplet has a missing style attribute -->
+ <font-triplet name="Gladiator" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
--- /dev/null
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Strict configuration On -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./</font-base>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <!-- this font has a metrics-url that does not exist on filesystem -->
+ <font metrics-url="test/resources/fonts/doesnotexist.ttf.ansi.xml">
+ <font-triplet name="Gladiator-Ansi" style="normal" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
--- /dev/null
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Strict configuration On -->
+ <strict-configuration>true</strict-configuration>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./</font-base>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <fonts>
+ <!-- this font has a malformed metrics-url -->
+ <font metrics-url="badprotocol:test/resources/fonts/glb12.ttf.xml">
+ <font-triplet name="Gladiator" style="normal" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+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.render.pdf.BasePDFTestCase;
+import org.xml.sax.SAXException;
+
+/**
+ * Basic runtime test for FOP's font configuration. It is used to verify that
+ * nothing obvious is broken after compiling.
+ */
+public abstract class BaseUserConfigTestCase extends BasePDFTestCase {
+
+ protected static DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
+
+ /** logging instance */
+ protected Log log = LogFactory.getLog(BaseUserConfigTestCase.class);
+
+
+ /**
+ * @see junit.framework.TestCase#TestCase(String)
+ */
+ public BaseUserConfigTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.render.pdf.BasePDFTestCase#init()
+ */
+ protected void init() {
+ // do nothing
+ }
+
+ /**
+ * Test using a standard FOP font
+ * @throws Exception checkstyle wants a comment here, even a silly one
+ */
+ public void testUserConfig() throws Exception {
+ try {
+ fopFactory.setUserConfig(getUserConfig());
+ final File baseDir = getBaseDir();
+ final String fontFOFilePath = getFontFOFilePath();
+ File foFile = new File(baseDir, fontFOFilePath);
+ final boolean dumpOutput = false;
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ convertFO(foFile, foUserAgent, dumpOutput);
+ fail( getName() + ": Expected Configuration Exception" );
+ } catch (FOPException e) {
+ // this *should* happen!
+ } catch (Exception e) {
+ fail( getName() + ": Expected FOPException but got: " + e.getMessage() );
+ }
+ }
+
+
+ /**
+ * get test FOP config File
+ * @return fo test filepath
+ */
+ protected String getFontFOFilePath() {
+ return "test/xml/bugtests/font.fo";
+ }
+
+ /**
+ * get test FOP Configuration
+ * @return fo test filepath
+ * @throws IOException
+ * @throws SAXException
+ * @throws ConfigurationException
+ */
+ protected Configuration getUserConfig(String configString)
+ throws ConfigurationException, SAXException, IOException {
+ return cfgBuilder.build(new ByteArrayInputStream(configString.getBytes()));
+ }
+
+ /**
+ * get test FOP Configuration
+ * @return fo test filepath
+ * @throws IOException
+ * @throws SAXException
+ * @throws ConfigurationException
+ */
+ protected Configuration getUserConfig()
+ throws ConfigurationException, SAXException, IOException {
+ return cfgBuilder.buildFromFile(getUserConfigFile());
+ }
+
+ /** get base config directory */
+ protected String getBaseConfigDir() {
+ return "test/config";
+ }
+
+ /**
+ * @return user config File
+ */
+ protected abstract File getUserConfigFile();
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.io.File;
+
+//
+/**
+ * this font has an embed-url that does not exist on filesystem.
+ */
+public class EmbedUrlBadTestCase extends BaseUserConfigTestCase {
+
+ public EmbedUrlBadTestCase(String name) {
+ super(name);
+ }
+
+ protected File getUserConfigFile() {
+ return new File( getBaseConfigDir() + "/test_embedurl_bad.xconf");
+ }
+
+ public String getName() {
+ return "test_embedurl_bad.xconf";
+ }
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.io.File;
+
+// this font has a malformed embed-url
+public class EmbedUrlMalformedTestCase extends BaseUserConfigTestCase {
+
+ public EmbedUrlMalformedTestCase(String name) {
+ super(name);
+ }
+
+ protected File getUserConfigFile() {
+ return new File( getBaseConfigDir() + "/test_embedurl_malformed.xconf");
+ }
+
+ public String getName() {
+ return "test_embedurl_malformed.xconf";
+ }
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.io.File;
+
+// this font is without a metrics-url or an embed-url
+public class FontAttributesMissingTestCase extends BaseUserConfigTestCase {
+
+ public FontAttributesMissingTestCase(String name) {
+ super(name);
+ }
+
+ protected File getUserConfigFile() {
+ return new File( getBaseConfigDir() + "/test_fontattributes_missing.xconf");
+ }
+
+ public String getName() {
+ return "test_fontattributes_missing.xconf";
+ }
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.io.File;
+
+// this font base does not exist and a relative font path is used
+public class FontBaseBadTestCase extends BaseUserConfigTestCase {
+
+ public FontBaseBadTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFile()
+ */
+ protected File getUserConfigFile() {
+ return new File( getBaseConfigDir() + "/test_fontbase_bad.xconf");
+ }
+
+ /**
+ * @return configuration filename
+ */
+ public String getName() {
+ return "test_fontbase_bad.xconf";
+ }
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.io.File;
+
+// this font has an embed-url that does not exist on filesystem
+public class FontTripletAttributeMissingTestCase extends BaseUserConfigTestCase {
+
+ public FontTripletAttributeMissingTestCase(String name) {
+ super(name);
+ }
+
+ protected File getUserConfigFile() {
+ return new File( getBaseConfigDir() + "/test_fonttripletattribute_missing.xconf");
+ }
+
+ public String getName() {
+ return "test_fonttripletattribute_missing.xconf";
+ }
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.io.File;
+
+// this font has a metrics-url that does not exist on filesystem
+public class MetricsUrlBadTestCase extends BaseUserConfigTestCase {
+
+ /**
+ * @see junit.framework.TestCase#TestCase(String)
+ */
+ public MetricsUrlBadTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFile()
+ */
+ protected File getUserConfigFile() {
+ return new File( getBaseConfigDir() + "/test_metricsurl_bad.xconf");
+ }
+
+ public String getName() {
+ return "test_metricsurl_bad.xconf";
+ }
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.io.File;
+
+// this font has a malformed metrics-url
+public class MetricsUrlMalformedTestCase extends BaseUserConfigTestCase {
+
+ public MetricsUrlMalformedTestCase(String name) {
+ super(name);
+ }
+
+ protected File getUserConfigFile() {
+ return new File( getBaseConfigDir() + "/test_metricsurl_malformed.xconf");
+ }
+
+ public String getName() {
+ return "test_metricsurl_malformed.xconf";
+ }
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for font configuration.
+ */
+public class UserConfigTestSuite {
+
+ /**
+ * Builds the test suite
+ * @return the test suite
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Basic functionality test suite for user configuration");
+ //$JUnit-BEGIN$
+ suite.addTest(new TestSuite(FontBaseBadTestCase.class));
+ suite.addTest(new TestSuite(FontAttributesMissingTestCase.class));
+ suite.addTest(new TestSuite(FontTripletAttributeMissingTestCase.class));
+ suite.addTest(new TestSuite(MetricsUrlBadTestCase.class));
+ suite.addTest(new TestSuite(EmbedUrlBadTestCase.class));
+ suite.addTest(new TestSuite(MetricsUrlMalformedTestCase.class));
+ suite.addTest(new TestSuite(EmbedUrlMalformedTestCase.class));
+ //$JUnit-END$
+ return suite;
+ }
+
+}
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.fop.AbstractFOPTestCase;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
-import junit.framework.TestCase;
-
/**
* Base class for automated tests that create PDF files
*/
-public class BasePDFTestCase extends TestCase {
+public class BasePDFTestCase extends AbstractFOPTestCase {
/** the FopFactory */
protected final FopFactory fopFactory = FopFactory.newInstance();
*/
protected BasePDFTestCase(String name) {
super(name);
+ init();
+ }
+ /**
+ * initalizes the test
+ */
+ protected void init() {
final File uc = getUserConfigFile();
try {