diff options
author | Mehdi Houshmand <mehdi@apache.org> | 2012-06-22 08:27:42 +0000 |
---|---|---|
committer | Mehdi Houshmand <mehdi@apache.org> | 2012-06-22 08:27:42 +0000 |
commit | a97e0be88b38483a36aa5101df08f370a5f53433 (patch) | |
tree | fd6651f55d8a6243a62ddf155dcc5478066d8a51 /src/java | |
parent | c36ffee9dfbf111899bbca5f994e334ca6b95011 (diff) | |
download | xmlgraphics-fop-a97e0be88b38483a36aa5101df08f370a5f53433.tar.gz xmlgraphics-fop-a97e0be88b38483a36aa5101df08f370a5f53433.zip |
Predominantly clean up and javadocs, very little functional change here
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_URI_Unification@1352800 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
16 files changed, 164 insertions, 92 deletions
diff --git a/src/java/org/apache/fop/afp/AFPResourceLevel.java b/src/java/org/apache/fop/afp/AFPResourceLevel.java index 7dcff1183..860ca3d26 100644 --- a/src/java/org/apache/fop/afp/AFPResourceLevel.java +++ b/src/java/org/apache/fop/afp/AFPResourceLevel.java @@ -145,18 +145,18 @@ public class AFPResourceLevel { } /** - * Returns the destination file path of the external resource group file + * Returns the URI of the external resource group. * - * @return the destination file path of the external resource group file + * @return the destination URI of the external resource group */ - public URI getExternalUri() { + public URI getExternalURI() { return this.extUri; } /** - * Sets the external destination of the resource + * Sets the URI of the external resource group. * - * @param filePath the external resource group file + * @param filePath the URI of the external resource group */ public void setExternalUri(URI uri) { this.extUri = uri; diff --git a/src/java/org/apache/fop/afp/AFPStreamer.java b/src/java/org/apache/fop/afp/AFPStreamer.java index 2ee341b5b..072dc1796 100644 --- a/src/java/org/apache/fop/afp/AFPStreamer.java +++ b/src/java/org/apache/fop/afp/AFPStreamer.java @@ -34,8 +34,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.afp.modca.ResourceGroup; import org.apache.fop.afp.modca.StreamedResourceGroup; -import org.apache.fop.apps.io.TempResourceURIGenerator; import org.apache.fop.apps.io.InternalResourceResolver; +import org.apache.fop.apps.io.TempResourceURIGenerator; /** * Manages the streaming of the AFP output @@ -119,7 +119,7 @@ public class AFPStreamer implements Streamable { return null; } if (level.isExternal()) { - URI uri = level.getExternalUri(); + URI uri = level.getExternalURI(); if (uri == null) { LOG.warn("No file path provided for external resource, using default."); uri = defaultResourceGroupUri; diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSet.java b/src/java/org/apache/fop/afp/fonts/CharacterSet.java index 8881a2649..49e7f99ba 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSet.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSet.java @@ -115,7 +115,7 @@ public class CharacterSet { } this.codePage = codePage; this.encoding = encoding; - this.encoder = CharactersetEncoder.newInstance(encoding, charsetType); + this.encoder = charsetType.getEncoder(encoding); this.accessor = accessor; this.characterSetOrientations = new HashMap<String, CharacterSetOrientation>(4); diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java index e145de745..7331178f5 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java @@ -40,6 +40,7 @@ import org.apache.fop.afp.AFPConstants; import org.apache.fop.afp.AFPEventProducer; import org.apache.fop.afp.util.AFPResourceAccessor; import org.apache.fop.afp.util.StructuredFieldReader; +import org.apache.fop.apps.io.InternalResourceResolver; import org.apache.fop.fonts.Typeface; /** @@ -148,7 +149,7 @@ public abstract class CharacterSetBuilder { throws IOException { URI uri; try { - uri = new URI(uriStr.trim()); + uri = InternalResourceResolver.cleanURI(uriStr.trim()); } catch (URISyntaxException e) { throw new MalformedURLException("Invalid uri: " + uriStr + " (" + e.getMessage() + ")"); } diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetType.java b/src/java/org/apache/fop/afp/fonts/CharacterSetType.java index 8eaaa089b..060d949ac 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetType.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetType.java @@ -19,13 +19,39 @@ package org.apache.fop.afp.fonts; +import org.apache.fop.afp.fonts.CharactersetEncoder.DefaultEncoder; +import org.apache.fop.afp.fonts.CharactersetEncoder.EbcdicDoubleByteLineDataEncoder; + /** * An enumeration of AFP characterset types. */ public enum CharacterSetType { /** Double byte character sets; these do NOT have the shift-in;shift-out operators */ - DOUBLE_BYTE, + DOUBLE_BYTE { + @Override + CharactersetEncoder getEncoder(String encoding) { + return new DefaultEncoder(encoding, true); + } + }, /** Double byte character sets; these can have the shift-in;shift-out operators */ - DOUBLE_BYTE_LINE_DATA, - SINGLE_BYTE; + DOUBLE_BYTE_LINE_DATA { + @Override + CharactersetEncoder getEncoder(String encoding) { + return new EbcdicDoubleByteLineDataEncoder(encoding); + } + }, + SINGLE_BYTE { + @Override + CharactersetEncoder getEncoder(String encoding) { + return new DefaultEncoder(encoding, false); + } + }; + + /** + * Returns the character-set encoder + * + * @param encoding + * @return + */ + abstract CharactersetEncoder getEncoder(String encoding); } diff --git a/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java b/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java index f101bdab4..983c308cd 100644 --- a/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java +++ b/src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java @@ -87,7 +87,7 @@ public abstract class CharactersetEncoder { */ public static EncodedChars encodeSBCS(CharSequence chars, String encoding) throws CharacterCodingException { - CharactersetEncoder encoder = newInstance(encoding, CharacterSetType.SINGLE_BYTE); + CharactersetEncoder encoder = CharacterSetType.SINGLE_BYTE.getEncoder(encoding); return encoder.encode(chars); } @@ -97,8 +97,8 @@ public abstract class CharactersetEncoder { * sequence it will return its EBCDIC code-point, however, the "Shift In - Shift Out" operators * are removed from the sequence of bytes. These are only used in Line Data. */ - private static final class EbcdicDoubleByteLineDataEncoder extends CharactersetEncoder { - private EbcdicDoubleByteLineDataEncoder(String encoding) { + static final class EbcdicDoubleByteLineDataEncoder extends CharactersetEncoder { + EbcdicDoubleByteLineDataEncoder(String encoding) { super(encoding); } @Override @@ -115,10 +115,10 @@ public abstract class CharactersetEncoder { * the primary format for most Latin character sets. This can also be used for Unicode double- * byte character sets (DBCS). */ - private static final class DefaultEncoder extends CharactersetEncoder { + static final class DefaultEncoder extends CharactersetEncoder { private final boolean isDBCS; - private DefaultEncoder(String encoding, boolean isDBCS) { + DefaultEncoder(String encoding, boolean isDBCS) { super(encoding); this.isDBCS = isDBCS; } @@ -130,24 +130,6 @@ public abstract class CharactersetEncoder { } /** - * Returns an new instance of a {@link CharactersetEncoder}. - * - * @param encoding the encoding for the underlying character encoder - * @param isEbcdicDBCS whether or not this wraps a double-byte EBCDIC code page. - * @return the CharactersetEncoder - */ - static CharactersetEncoder newInstance(String encoding, CharacterSetType charsetType) { - switch (charsetType) { - case DOUBLE_BYTE_LINE_DATA: - return new EbcdicDoubleByteLineDataEncoder(encoding); - case DOUBLE_BYTE: - return new DefaultEncoder(encoding, true); - default: - return new DefaultEncoder(encoding, false); - } - } - - /** * A container for encoded character bytes */ // CSOFF: FinalClass - disabling "final" modifier so that this class can be mocked diff --git a/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java b/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java index 9133e81dd..374074b8a 100644 --- a/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java +++ b/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java @@ -21,8 +21,9 @@ package org.apache.fop.apps; import java.net.URI; -import org.apache.fop.apps.io.ResourceResolver; import org.apache.fop.apps.io.InternalResourceResolver; +import org.apache.fop.apps.io.ResourceResolver; +import org.apache.fop.apps.io.ResourceResolverFactory; import org.apache.fop.fonts.FontCacheManager; import org.apache.fop.fonts.FontCacheManagerFactory; import org.apache.fop.fonts.FontDetector; @@ -105,7 +106,8 @@ public final class EnvironmentalProfileFactory { private static FontManager createFontManager(URI defaultBaseUri, ResourceResolver resourceResolver, FontDetector fontDetector, FontCacheManager fontCacheManager) { - return new FontManager(new InternalResourceResolver(defaultBaseUri, resourceResolver), fontDetector, - fontCacheManager); + InternalResourceResolver internalResolver = ResourceResolverFactory.createInternalResourceResolver( + defaultBaseUri, resourceResolver); + return new FontManager(internalResolver, fontDetector, fontCacheManager); } } diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index fc9287401..488b62474 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -402,11 +402,12 @@ public class FOUserAgent { * @return A {@link javax.xml.transform.Source} object, or null if the URI * cannot be resolved. */ - public Source resolveURI(String uri) { - // TODO: What do we want to do when resources aren't found??? + public StreamSource resolveURI(String uri) { + // TODO: What do we want to do when resources aren't found??? We also need to remove this + // method entirely try { // Have to do this so we can resolve data URIs - Source src = new StreamSource(resourceResolver.getResource(uri)); + StreamSource src = new StreamSource(resourceResolver.getResource(uri)); src.setSystemId(uri); return src; } catch (URISyntaxException use) { diff --git a/src/java/org/apache/fop/apps/FopFactory.java b/src/java/org/apache/fop/apps/FopFactory.java index a149d593c..ec7266957 100644 --- a/src/java/org/apache/fop/apps/FopFactory.java +++ b/src/java/org/apache/fop/apps/FopFactory.java @@ -39,6 +39,7 @@ import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.xmlgraphics.util.UnitConv; import org.apache.fop.apps.io.InternalResourceResolver; +import org.apache.fop.apps.io.ResourceResolverFactory; import org.apache.fop.fo.ElementMapping; import org.apache.fop.fo.ElementMappingRegistry; import org.apache.fop.fonts.FontManager; @@ -88,7 +89,8 @@ public final class FopFactory implements ImageContext { private FopFactory(FopFactoryConfig config) { this.config = config; - this.resolver = new InternalResourceResolver(config.getBaseURI(), config.getResourceResolver()); + this.resolver = ResourceResolverFactory.createInternalResourceResolver(config.getBaseURI(), + config.getResourceResolver()); this.elementMappingRegistry = new ElementMappingRegistry(this); this.colorSpaceCache = new ColorSpaceCache(resolver); this.rendererFactory = new RendererFactory(config.preferRenderer()); diff --git a/src/java/org/apache/fop/apps/io/InternalResourceResolver.java b/src/java/org/apache/fop/apps/io/InternalResourceResolver.java index 4ea391c8a..4d664c8f5 100644 --- a/src/java/org/apache/fop/apps/io/InternalResourceResolver.java +++ b/src/java/org/apache/fop/apps/io/InternalResourceResolver.java @@ -39,16 +39,16 @@ import org.apache.xmlgraphics.util.uri.DataURIResolver; */ public class InternalResourceResolver { private final URI baseUri; - private final ResourceResolver uriResolver; + private final ResourceResolver resourceResolver; private final DataURIResolver dataSchemeResolver = new DataURIResolver(); /** * @param baseUri the base URI from which to resolve relative URIs - * @param uriResolver the resolver to delegate to + * @param resourceResolver the resolver to delegate to */ - public InternalResourceResolver(URI baseUri, ResourceResolver uriResolver) { + InternalResourceResolver(URI baseUri, ResourceResolver resourceResolver) { this.baseUri = baseUri; - this.uriResolver = uriResolver; + this.resourceResolver = resourceResolver; } /** @@ -87,7 +87,7 @@ public class InternalResourceResolver { if (uri.getScheme() != null && uri.getScheme().startsWith("data")) { return new Resource(resolveDataURI(uri.toASCIIString())); } - return uriResolver.getResource(resolveFromBase(uri)); + return resourceResolver.getResource(resolveFromBase(uri)); } /** @@ -98,7 +98,7 @@ public class InternalResourceResolver { * @throws IOException if an I/O error occurrred */ public OutputStream getOutputStream(URI uri) throws IOException { - return uriResolver.getOutputStream(resolveFromBase(uri)); + return resourceResolver.getOutputStream(resolveFromBase(uri)); } /** diff --git a/src/java/org/apache/fop/apps/io/ResourceResolver.java b/src/java/org/apache/fop/apps/io/ResourceResolver.java index 3d20aaebc..a3a9cf0c3 100644 --- a/src/java/org/apache/fop/apps/io/ResourceResolver.java +++ b/src/java/org/apache/fop/apps/io/ResourceResolver.java @@ -23,10 +23,29 @@ import java.io.IOException; import java.io.OutputStream; import java.net.URI; +/** + * Implementations of this resource resolver allow FOP users to control the URI resolution + * mechanism. All resource and output stream acquisition goes through this when its implementation + * is given to the {@link org.apache.fop.apps.EnvironmentProfile}. + */ public interface ResourceResolver { + /** + * Get a resource given the URI pointing to said resource. + * + * @param uri the resource URI + * @return the resource + * @throws IOException if an I/O error occured during resource acquisition + */ Resource getResource(URI uri) throws IOException; + /** + * Gets an output stream of a given URI. + * + * @param uri the output stream URI + * @return the output stream + * @throws IOException if an I/O error occured while creating an output stream + */ OutputStream getOutputStream(URI uri) throws IOException; } diff --git a/src/java/org/apache/fop/apps/io/ResourceResolverFactory.java b/src/java/org/apache/fop/apps/io/ResourceResolverFactory.java index 2e6c8af39..881db20f7 100644 --- a/src/java/org/apache/fop/apps/io/ResourceResolverFactory.java +++ b/src/java/org/apache/fop/apps/io/ResourceResolverFactory.java @@ -28,24 +28,59 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +/** + * A factory class for {@link ResourceResolver}s. + */ public final class ResourceResolverFactory { private ResourceResolverFactory() { } + /** + * Returns the default resource resolver, this is most basic resolver which can be used when + * no there are no I/O or file access restrictions. + * + * @return the default resource resolver + */ public static ResourceResolver createDefaultResourceResolver() { return DefaultResourceResolver.INSTANCE; } - public static ResourceResolver createTempAwareResourceResolver(TempResourceResolver tempResourceResolver, - ResourceResolver defaultResourceResolver) { - return new TempAwareResourceResolver(tempResourceResolver, defaultResourceResolver); + /** + * A helper merthod that creates an internal resource resolver using the default resover: + * {@link ResourceResolverFactory#createDefaultResourceResolver()}. + * + * @param baseURI the base URI from which to resolve URIs + * @return the default internal resource resolver + */ + public static InternalResourceResolver createDefaultInternalResourceResolver(URI baseURI) { + return new InternalResourceResolver(baseURI, createDefaultResourceResolver()); } - public static InternalResourceResolver createDefaultWrapper() { - // Not sure if this is the right place for this, but I don't have any better ideas as of yet - URI thisUri = new File(".").getAbsoluteFile().toURI(); - return new InternalResourceResolver(thisUri, new DefaultResourceResolver()); + /** + * Creates an interal resource resolver given a base URI and a resource resolver. + * + * @param baseURI the base URI from which to resolve URIs + * @param resolver the resource resolver + * @return the internal resource resolver + */ + public static InternalResourceResolver createInternalResourceResolver(URI baseURI, + ResourceResolver resolver) { + return new InternalResourceResolver(baseURI, resolver); + } + + /** + * Creates a temporary-resource-schema aware resource resolver. Temporary resource URIs are + * created by {@link TempResourceURIGenerator}. + * + * @param tempResourceResolver the temporary-resource-schema resolver to use + * @param defaultResourceResolver the default resource resolver to use + * @return the ressource resolver + */ + public static ResourceResolver createTempAwareResourceResolver( + TempResourceResolver tempResourceResolver, + ResourceResolver defaultResourceResolver) { + return new TempAwareResourceResolver(tempResourceResolver, defaultResourceResolver); } public static SchemaAwareResourceResolverBuilder createSchemaAwareResourceResolverBuilder( @@ -53,16 +88,14 @@ public final class ResourceResolverFactory { return new SchemaAwareResourceResolverBuilderImpl(defaultResolver); } - - private static final class DefaultResourceResolver implements ResourceResolver { private static final ResourceResolver INSTANCE = new DefaultResourceResolver(); private final TempAwareResourceResolver delegate; - private DefaultResourceResolver() { - delegate = new TempAwareResourceResolver(new DefaultTempResourceResolver(), + private DefaultResourceResolver() { + delegate = new TempAwareResourceResolver(new DefaultTempResourceResolver(), new NormalResourceResolver()); } @@ -123,7 +156,6 @@ public final class ResourceResolverFactory { public OutputStream getOutputStream(String id) throws IOException { File file = getTempFile(id); - // TODO handle error file.createNewFile(); return new FileOutputStream(file); } @@ -145,7 +177,8 @@ public final class ResourceResolverFactory { private final ResourceResolver defaultResolver; - private SchemaAwareResourceResolver(Map<String, ResourceResolver> schemaHandlingResourceResolvers, + private SchemaAwareResourceResolver( + Map<String, ResourceResolver> schemaHandlingResourceResolvers, ResourceResolver defaultResolver) { this.schemaHandlingResourceResolvers = schemaHandlingResourceResolvers; this.defaultResolver = defaultResolver; @@ -177,7 +210,7 @@ public final class ResourceResolverFactory { } private static final class CompletedSchemaAwareResourceResolverBuilder - implements SchemaAwareResourceResolverBuilder { + implements SchemaAwareResourceResolverBuilder { private static final SchemaAwareResourceResolverBuilder INSTANCE = new CompletedSchemaAwareResourceResolverBuilder(); @@ -193,7 +226,7 @@ public final class ResourceResolverFactory { } private static final class ActiveSchemaAwareResourceResolverBuilder - implements SchemaAwareResourceResolverBuilder { + implements SchemaAwareResourceResolverBuilder { private final Map<String, ResourceResolver> schemaHandlingResourceResolvers = new HashMap<String, ResourceResolver>(); @@ -204,7 +237,8 @@ public final class ResourceResolverFactory { this.defaultResolver = defaultResolver; } - public void registerResourceResolverForSchema(String schema, ResourceResolver resourceResolver) { + public void registerResourceResolverForSchema(String schema, + ResourceResolver resourceResolver) { schemaHandlingResourceResolvers.put(schema, resourceResolver); } @@ -216,7 +250,7 @@ public final class ResourceResolverFactory { } private static final class SchemaAwareResourceResolverBuilderImpl - implements SchemaAwareResourceResolverBuilder { + implements SchemaAwareResourceResolverBuilder { private SchemaAwareResourceResolverBuilder delegate; @@ -224,7 +258,8 @@ public final class ResourceResolverFactory { this.delegate = new ActiveSchemaAwareResourceResolverBuilder(defaultResolver); } - public void registerResourceResolverForSchema(String schema, ResourceResolver resourceResolver) { + public void registerResourceResolverForSchema(String schema, + ResourceResolver resourceResolver) { delegate.registerResourceResolverForSchema(schema, resourceResolver); } diff --git a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java index 0def335a1..c4fe19444 100644 --- a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java @@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.io.InternalResourceResolver; import org.apache.fop.apps.io.ResourceResolver; +import org.apache.fop.apps.io.ResourceResolverFactory; import org.apache.fop.fonts.substitute.FontSubstitutions; import org.apache.fop.fonts.substitute.FontSubstitutionsConfigurator; import org.apache.fop.util.LogUtil; @@ -89,13 +90,14 @@ public class FontManagerConfigurator { try { URI fontBase = InternalResourceResolver.getBaseURI(cfg.getChild("font-base").getValue( null)); - fontManager.setResourceResolver(new InternalResourceResolver( + fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver( defaultBaseUri.resolve(fontBase), resourceResolver)); } catch (URISyntaxException use) { LogUtil.handleException(log, use, true); } } else { - fontManager.setResourceResolver(new InternalResourceResolver(defaultBaseUri, resourceResolver)); + fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver( + defaultBaseUri, resourceResolver)); } // [GA] permit configuration control over base14 kerning; without this, diff --git a/src/java/org/apache/fop/render/pdf/PDFRendererConfig.java b/src/java/org/apache/fop/render/pdf/PDFRendererConfig.java index 0337ef5a7..ffb092b33 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRendererConfig.java +++ b/src/java/org/apache/fop/render/pdf/PDFRendererConfig.java @@ -19,6 +19,8 @@ package org.apache.fop.render.pdf; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.EnumMap; import java.util.HashMap; @@ -33,6 +35,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; +import org.apache.fop.apps.io.InternalResourceResolver; import org.apache.fop.fonts.DefaultFontConfig; import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser; import org.apache.fop.pdf.PDFAMode; @@ -98,8 +101,8 @@ public final class PDFRendererConfig implements RendererConfig { return (PDFEncryptionParams) configOptions.get(ENCRYPTION_PARAMS); } - public String getOutputProfileURI() { - return (String) configOptions.get(OUTPUT_PROFILE); + public URI getOutputProfileURI() { + return (URI) configOptions.get(OUTPUT_PROFILE); } public Boolean getDisableSRGBColorSpace() { @@ -171,12 +174,13 @@ public final class PDFRendererConfig implements RendererConfig { } put(ENCRYPTION_PARAMS, encryptionConfig); } - // TODO: Check this, I'm pretty sure the getChild(Str, bool) should be false!!! - put(OUTPUT_PROFILE, parseConfig(cfg, OUTPUT_PROFILE)); + put(OUTPUT_PROFILE, InternalResourceResolver.cleanURI(parseConfig(cfg, OUTPUT_PROFILE))); put(DISABLE_SRGB_COLORSPACE, Boolean.valueOf(parseConfig(cfg, DISABLE_SRGB_COLORSPACE))); put(VERSION, getPDFDocVersion(cfg)); } catch (ConfigurationException e) { LogUtil.handleException(LOG, e, strict); + } catch (URISyntaxException use) { + LogUtil.handleException(LOG, use, strict); } } diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java index daffe2d3f..2a6a364e6 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java @@ -24,17 +24,14 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Map; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; - import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.xmlgraphics.image.loader.util.ImageUtil; import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil; import org.apache.xmlgraphics.xmp.Metadata; import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter; @@ -42,6 +39,7 @@ import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema; import org.apache.fop.accessibility.Accessibility; import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.apps.io.InternalResourceResolver; import org.apache.fop.fo.extensions.xmp.XMPMetadata; import org.apache.fop.pdf.PDFAMode; import org.apache.fop.pdf.PDFArray; @@ -118,7 +116,7 @@ class PDFRenderingUtil { private boolean disableSRGBColorSpace = false; /** Optional URI to an output profile to be used. */ - private String outputProfileURI; + private URI outputProfileURI; private Version maxPDFVersion; @@ -198,7 +196,7 @@ class PDFRenderingUtil { } s = (String) userAgent.getRendererOption(OUTPUT_PROFILE); if (s != null) { - this.outputProfileURI = s; + this.outputProfileURI = URI.create(s); } Object disableSRGBColorSpace = userAgent.getRendererOption(DISABLE_SRGB_COLORSPACE); if (disableSRGBColorSpace != null) { @@ -230,7 +228,7 @@ class PDFRenderingUtil { * Sets the output color profile for the PDF renderer. * @param outputProfileURI the URI to the output color profile */ - public void setOutputProfileURI(String outputProfileURI) { + public void setOutputProfileURI(URI outputProfileURI) { this.outputProfileURI = outputProfileURI; } @@ -303,15 +301,7 @@ class PDFRenderingUtil { InputStream in = null; if (this.outputProfileURI != null) { this.outputProfile = pdfDoc.getFactory().makePDFICCStream(); - Source src = getUserAgent().resolveURI(this.outputProfileURI); - if (src == null) { - throw new IOException("Output profile not found: " + this.outputProfileURI); - } - if (src instanceof StreamSource) { - in = ((StreamSource)src).getInputStream(); - } else { - in = new URL(src.getSystemId()).openStream(); - } + in = getUserAgent().getResourceResolver().getResource(outputProfileURI); try { profile = ColorProfileUtil.getICC_Profile(in); } finally { @@ -471,8 +461,13 @@ class PDFRenderingUtil { //Create embedded file PDFEmbeddedFile file = new PDFEmbeddedFile(); this.pdfDoc.registerObject(file); - Source src = getUserAgent().resolveURI(embeddedFile.getSrc()); - InputStream in = ImageUtil.getInputStream(src); + URI srcURI; + try { + srcURI = InternalResourceResolver.cleanURI(embeddedFile.getSrc()); + } catch (URISyntaxException use) { + throw new RuntimeException(use); + } + InputStream in = getUserAgent().getResourceResolver().getResource(srcURI); if (in == null) { throw new FileNotFoundException(embeddedFile.getSrc()); } diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java index 2199df4f9..e5eba3ea2 100644 --- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java +++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java @@ -19,6 +19,8 @@ package org.apache.fop.svg; +import java.io.File; +import java.net.URI; import java.util.List; import org.apache.avalon.framework.configuration.Configuration; @@ -85,7 +87,8 @@ public class PDFDocumentGraphics2DConfigurator { FontInfo fontInfo = new FontInfo(); final boolean strict = false; if (cfg != null) { - InternalResourceResolver resourceResolver = ResourceResolverFactory.createDefaultWrapper(); + URI thisUri = new File(".").getAbsoluteFile().toURI(); + InternalResourceResolver resourceResolver = ResourceResolverFactory.createDefaultInternalResourceResolver(thisUri); //TODO The following could be optimized by retaining the FontManager somewhere FontManager fontManager = new FontManager(resourceResolver, FontDetectorFactory.createDefault(), FontCacheManagerFactory.createDefault()); |