/* * 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.apps; import java.net.URI; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.apache.avalon.framework.configuration.Configuration; import org.apache.xmlgraphics.image.loader.ImageContext; import org.apache.xmlgraphics.image.loader.ImageManager; import org.apache.fop.apps.io.ResourceResolver; import org.apache.fop.apps.io.ResourceResolverFactory; import org.apache.fop.fonts.FontManager; import org.apache.fop.layoutmgr.LayoutManagerMaker; /** * This is the builder class for {@link FopFactory}. Setters can be chained to * make building a {@link FopFactory} object more concise and intuitive e.g. * *
* {@code * FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(*/ public final class FopFactoryBuilder { private final FopFactoryConfig config; private FopFactoryConfigBuilder fopFactoryConfigBuilder; /** * A builder class for {@link FopFactory} which can be used for setting configuration. This is * a helper constructor that uses the default URI resolver implementation that FOP packages * provide ({@link DefaultResourceResolver}). * * @param defaultBaseURI the default base URI for resolving URIs against */ public FopFactoryBuilder(URI defaultBaseURI) { this(defaultBaseURI, ResourceResolverFactory.createDefaultResourceResolver()); } /** * A builder class for {@link FopFactory} which can be used for setting configuration. * * @param defaultBaseURI the default base URI for resolving URIs against * @param resourceResolver the URI resolver */ public FopFactoryBuilder(URI defaultBaseURI, ResourceResolver resourceResolver) { this(EnvironmentalProfileFactory.createDefault(defaultBaseURI, resourceResolver)); } /** * A builder class for {@link FopFactory} which can be used for setting configuration. * * @param enviro the profile of the FOP deployment environment */ public FopFactoryBuilder(EnvironmentProfile enviro) { config = new FopFactoryConfigImpl(enviro); fopFactoryConfigBuilder = new ActiveFopFactoryConfigBuilder((FopFactoryConfigImpl) config); } /** * Returns the {@link FopFactoryConfig} which is needed to get an instance of * {@link FopFactory}. * * @return build the {@link FopFactoryConfig} * @deprecated Exposing the {@link FopFactoryConfig} is only to maintain backwards compatibility */ public FopFactoryConfig buildConfig() { return buildConfiguration(); } /** * Builds the configuration object used by the FopFactory. * * @return the config for the {@link FopFactory} */ // The {@link FopFactoryConfig} doesn't need to be exposed in the "public" API, this method // should remain package private. FopFactoryConfig buildConfiguration() { fopFactoryConfigBuilder = CompletedFopFactoryConfigBuilder.INSTANCE; return config; } /** * Builds an instance of the the {@link FopFactory}. * * @return the FopFactory instance */ public FopFactory build() { return FopFactory.newInstance(buildConfiguration()); } /** * Gets the base URI used to resolve all URIs within FOP. * * @return the base URI */ URI getBaseURI() { return config.getBaseURI(); } /** * Returns the {@link FontManager} used for managing the fonts within FOP. * * @return the font managing object */ public FontManager getFontManager() { return config.getFontManager(); } /** * Return the {@link ImageManager} used for handling images through out FOP. * * @return the image manager */ public ImageManager getImageManager() { return config.getImageManager(); } /** * Sets whether to include accessibility features in document creation. * * @param enableAccessibility true to set accessibility on * @return) * .setURIResolver( ) * .setPageHeight( ) * .setPageWidth( ) * .setStrictUserConfigValidation( ) * ... etc ... * FopFactory fopFactory = fopFactoryBuilder.build(); * } *
this
*/
public FopFactoryBuilder setAccessibility(boolean enableAccessibility) {
fopFactoryConfigBuilder.setAccessibility(enableAccessibility);
return this;
}
/**
* Sets the {@link LayoutManagerMaker} so that users can configure how FOP creates
* {@link LayoutManager}s.
*
* @param lmMaker he layout manager maker
* @return this
*/
public FopFactoryBuilder setLayoutManagerMakerOverride(
LayoutManagerMaker lmMaker) {
fopFactoryConfigBuilder.setLayoutManagerMakerOverride(lmMaker);
return this;
}
/**
* Sets the base URI, this will be used for resolving all URIs given to FOP.
*
* @param baseURI the base URI
* @return this
*/
public FopFactoryBuilder setBaseURI(URI baseURI) {
fopFactoryConfigBuilder.setBaseURI(baseURI);
return this;
}
/**
* Sets whether to perform strict validation on the FO used.
*
* @param validateStrictly true if the FO is to be strictly validated
* @return this
*/
public FopFactoryBuilder setStrictFOValidation(boolean validateStrictly) {
fopFactoryConfigBuilder.setStrictFOValidation(validateStrictly);
return this;
}
/**
* Sets whether to perform strict alidation on the user-configuration.
*
* @param validateStrictly true if the fop conf is to be strictly validated
* @return this
*/
public FopFactoryBuilder setStrictUserConfigValidation(
boolean validateStrictly) {
fopFactoryConfigBuilder.setStrictUserConfigValidation(validateStrictly);
return this;
}
/**
* Sets whether the indent inheritance should be broken when crossing reference area boundaries.
*
* @param value true to break inheritance when crossing reference area boundaries
* @return this
*/
public FopFactoryBuilder setBreakIndentInheritanceOnReferenceAreaBoundary(
boolean value) {
fopFactoryConfigBuilder.setBreakIndentInheritanceOnReferenceAreaBoundary(value);
return this;
}
/**
* Sets the resolution of resolution-dependent input.
*
* @param dpi the source resolution
* @return this
*/
public FopFactoryBuilder setSourceResolution(float dpi) {
fopFactoryConfigBuilder.setSourceResolution(dpi);
return this;
}
/**
* Sets the resolution of resolution-dependent output.
*
* @param dpi the target resolution
* @return this
*/
public FopFactoryBuilder setTargetResolution(float dpi) {
fopFactoryConfigBuilder.setTargetResolution(dpi);
return this;
}
/**
* Sets the page height of the paginated output.
*
* @param pageHeight the page height
* @return this
*/
public FopFactoryBuilder setPageHeight(String pageHeight) {
fopFactoryConfigBuilder.setPageHeight(pageHeight);
return this;
}
/**
* Sets the page width of the paginated output.
*
* @param pageWidth the page width
* @return this
*/
public FopFactoryBuilder setPageWidth(String pageWidth) {
fopFactoryConfigBuilder.setPageWidth(pageWidth);
return this;
}
/**
* FOP will ignore the specified XML element namespace.
*
* @param namespaceURI the namespace URI to ignore
* @return this
*/
public FopFactoryBuilder ignoreNamespace(String namespaceURI) {
fopFactoryConfigBuilder.ignoreNamespace(namespaceURI);
return this;
}
/**
* FOP will ignore the colletion of XML element namespaces.
*
* @param namespaceURIs a collection of namespace URIs to ignore
* @return this
*/
public FopFactoryBuilder ignoreNamespaces(Collectionthis
*/
public FopFactoryBuilder setConfiguration(Configuration cfg) {
fopFactoryConfigBuilder.setConfiguration(cfg);
return this;
}
/**
* Sets whether to chose a {@link Renderer} in preference to an
* {@link org.apache.fop.render.intermediate.IFDocumentHandler}.
*
* @see {@link RendererFactory}
* @param preferRenderer true to prefer {@link Renderer}
* @return this
*/
public FopFactoryBuilder setPreferRenderer(boolean preferRenderer) {
fopFactoryConfigBuilder.setPreferRenderer(preferRenderer);
return this;
}
public FopFactoryBuilder setComplexScriptFeatures(boolean csf) {
fopFactoryConfigBuilder.setComplexScriptFeaturesEnabled(csf);
return this;
}
public FopFactoryBuilder setHyphPatNames(Map