Browse Source

Relative URIs in the configuration file are evaluated relative to the base URI of the configuration file

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1058945 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_1rc1old
Simon Pepping 13 years ago
parent
commit
4c8a18e4a5

+ 3
- 0
src/documentation/content/xdocs/trunk/configuration.xml View File

</td> </td>
<td>disabled</td> <td>disabled</td>
</tr> </tr>
<tr>
<td colspan="4">Relative URIs for the above three properties are evaluated relative to the base URI of the configuration file. If the configuration is provided programmatically, the base URI can be set with <code>FopFactory.setUserConfigBaseURI</code>; default is the current working directory.</td>
</tr>
<tr> <tr>
<td>hyphenation-pattern</td> <td>hyphenation-pattern</td>
<td>String, attribute lang, attribute country (optional)</td> <td>String, attribute lang, attribute country (optional)</td>

+ 10
- 0
src/java/org/apache/fop/apps/FopFactory.java View File

import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
config.setUserConfig(userConfig); config.setUserConfig(userConfig);
} }


/**
* Set the base URI for the user configuration
* Useful for programmatic configurations
* @param baseURI the base URI
*/
public void setUserConfigBaseURI(URI baseURI) {
config.setBaseURI(baseURI);
}

/** /**
* Get the user configuration. * Get the user configuration.
* @return the user configuration * @return the user configuration

+ 47
- 5
src/java/org/apache/fop/apps/FopFactoryConfigurator.java View File

import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


/** Fop factory configuration */ /** Fop factory configuration */
private Configuration cfg = null; private Configuration cfg = null;


/** The base URI of the configuration file **/
private URI baseURI = null;

/** /**
* Default constructor * Default constructor
* @param factory fop factory * @param factory fop factory


// base definitions for relative path resolution // base definitions for relative path resolution
if (cfg.getChild("base", false) != null) { if (cfg.getChild("base", false) != null) {
String path = cfg.getChild("base").getValue(null);
if (baseURI != null) {
path = baseURI.resolve(path).normalize().toString();
}
try { try {
factory.setBaseURL(
cfg.getChild("base").getValue(null));
factory.setBaseURL(path);
} catch (MalformedURLException mfue) { } catch (MalformedURLException mfue) {
LogUtil.handleException(log, mfue, strict); LogUtil.handleException(log, mfue, strict);
} }
} }
if (cfg.getChild("hyphenation-base", false) != null) { if (cfg.getChild("hyphenation-base", false) != null) {
String path = cfg.getChild("hyphenation-base").getValue(null);
if (baseURI != null) {
path = baseURI.resolve(path).normalize().toString();
}
try { try {
factory.setHyphenBaseURL(
cfg.getChild("hyphenation-base").getValue(null));
factory.setHyphenBaseURL(path);
} catch (MalformedURLException mfue) { } catch (MalformedURLException mfue) {
LogUtil.handleException(log, mfue, strict); LogUtil.handleException(log, mfue, strict);
} }
} }


// configure font manager // configure font manager
new FontManagerConfigurator(cfg).configure(factory.getFontManager(), strict);
new FontManagerConfigurator(cfg, baseURI).configure(factory.getFontManager(), strict);


// configure image loader framework // configure image loader framework
configureImageLoading(cfg.getChild("image-loading", false), strict); configureImageLoading(cfg.getChild("image-loading", false), strict);
*/ */
public void setUserConfig(Configuration cfg) throws FOPException { public void setUserConfig(Configuration cfg) throws FOPException {
this.cfg = cfg; this.cfg = cfg;
setBaseURI();
configure(this.factory); configure(this.factory);
} }


public Configuration getUserConfig() { public Configuration getUserConfig() {
return this.cfg; return this.cfg;
} }

/**
* @return the baseURI
*/
public URI getBaseURI() {
return baseURI;
}

/**
* @param baseURI the baseURI to set
*/
public void setBaseURI(URI baseURI) {
this.baseURI = baseURI;
}

private void setBaseURI() throws FOPException {
String[] locationParts = cfg.getLocation().split(":");
try {
if (locationParts != null && locationParts.length >= 2
&& "file".equals(locationParts[0])) {
baseURI = new URI(locationParts[0], locationParts[1], null);
}
if (baseURI == null) {
baseURI = new File(System.getProperty("user.dir")).toURI();
}
} catch (URISyntaxException e) {
throw new FOPException(e);
}
}

} }

+ 18
- 1
src/java/org/apache/fop/fonts/FontManagerConfigurator.java View File



import java.io.File; import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;




private final Configuration cfg; private final Configuration cfg;


private URI baseURI = null;

/** /**
* Main constructor * Main constructor
* @param cfg the font manager configuration object * @param cfg the font manager configuration object
this.cfg = cfg; this.cfg = cfg;
} }


/**
* Main constructor
* @param cfg the font manager configuration object
* @param baseURI the base URI of the configuration
*/
public FontManagerConfigurator(Configuration cfg, URI baseURI) {
this.cfg = cfg;
this.baseURI = baseURI;
}

/** /**
* Initializes font settings from the user configuration * Initializes font settings from the user configuration
* @param fontManager a font manager * @param fontManager a font manager
} }
} }
if (cfg.getChild("font-base", false) != null) { if (cfg.getChild("font-base", false) != null) {
String path = cfg.getChild("font-base").getValue(null);
if (baseURI != null) {
path = baseURI.resolve(path).normalize().toString();
}
try { try {
fontManager.setFontBaseURL(cfg.getChild("font-base").getValue(null));
fontManager.setFontBaseURL(path);
} catch (MalformedURLException mfue) { } catch (MalformedURLException mfue) {
LogUtil.handleException(log, mfue, true); LogUtil.handleException(log, mfue, true);
} }

+ 4
- 0
status.xml View File

<context id="API" title="Changes to the End-User API"/> <context id="API" title="Changes to the End-User API"/>
<context id="Extensions" title="Changes to the Bundled Extensions"/> <context id="Extensions" title="Changes to the Bundled Extensions"/>
<context id="Images" title="Changes to the Image Support"/> <context id="Images" title="Changes to the Image Support"/>
<context id="Config" title="Changes to the User Configuration"/>
</contexts> </contexts>


<changes> <changes>
documents. Example: the fix of marks layering will be such a case when it's done. documents. Example: the fix of marks layering will be such a case when it's done.
--> -->
<release version="FOP Trunk" date="TBD"> <release version="FOP Trunk" date="TBD">
<action context="Config" dev="SP" type="fix">
Bugfix: relative URIs in the configuration file (base, font-base, hyphenation-base) are evaluated relative to the base URI of the configuration file.
</action>
<action context="Layout" dev="AD" type="fix" fixes-bug="49848"> <action context="Layout" dev="AD" type="fix" fixes-bug="49848">
Bugfix: correct behavior of keep-together.within-line in case there are nested inlines Bugfix: correct behavior of keep-together.within-line in case there are nested inlines
</action> </action>

+ 1
- 1
test/test-no-xml-metrics.xconf View File

<base>./</base> <base>./</base>


<!-- Font Base URL for resolving relative font URLs --> <!-- Font Base URL for resolving relative font URLs -->
<font-base>./test/resources/fonts</font-base>
<font-base>./resources/fonts</font-base>
<renderers> <renderers>
<renderer mime="application/pdf"> <renderer mime="application/pdf">

Loading…
Cancel
Save