git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@628826 13f79535-47bb-0310-9956-ffa450edef68pull/15/head
import org.apache.fop.Version; | import org.apache.fop.Version; | ||||
import org.apache.fop.fo.FOEventHandler; | import org.apache.fop.fo.FOEventHandler; | ||||
import org.apache.fop.pdf.PDFEncryptionParams; | |||||
import org.apache.fop.render.Renderer; | import org.apache.fop.render.Renderer; | ||||
import org.apache.fop.render.RendererFactory; | import org.apache.fop.render.RendererFactory; | ||||
import org.apache.fop.render.XMLHandlerRegistry; | import org.apache.fop.render.XMLHandlerRegistry; | ||||
import org.apache.fop.render.pdf.PDFRenderer; | |||||
/** | /** | ||||
* This is the user agent for FOP. | * This is the user agent for FOP. | ||||
public class FOUserAgent { | public class FOUserAgent { | ||||
/** Defines the default target resolution (72dpi) for FOP */ | /** Defines the default target resolution (72dpi) for FOP */ | ||||
public static final float DEFAULT_TARGET_RESOLUTION = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION; | |||||
public static final float DEFAULT_TARGET_RESOLUTION | |||||
= FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION; | |||||
private static Log log = LogFactory.getLog("FOP"); | private static Log log = LogFactory.getLog("FOP"); | ||||
}; | }; | ||||
/** | |||||
* Default constructor | |||||
* @see org.apache.fop.apps.FopFactory | |||||
* @deprecated Provided for compatibility only. Please use the methods from | |||||
* FopFactory to construct FOUserAgent instances! | |||||
*/ | |||||
public FOUserAgent() throws FOPException { | |||||
this(FopFactory.newInstance()); | |||||
} | |||||
/** | /** | ||||
* Main constructor. <b>This constructor should not be called directly. Please use the | * Main constructor. <b>This constructor should not be called directly. Please use the | ||||
* methods from FopFactory to construct FOUserAgent instances!</b> | * methods from FopFactory to construct FOUserAgent instances!</b> | ||||
return this.uriResolver; | return this.uriResolver; | ||||
} | } | ||||
/** | |||||
* Returns the parameters for PDF encryption. | |||||
* @return the PDF encryption parameters, null if not applicable | |||||
* @deprecated Use (PDFEncryptionParams)getRendererOptions().get("encryption-params") | |||||
* instead. | |||||
*/ | |||||
public PDFEncryptionParams getPDFEncryptionParams() { | |||||
return (PDFEncryptionParams)getRendererOptions().get(PDFRenderer.ENCRYPTION_PARAMS); | |||||
} | |||||
/** | |||||
* Sets the parameters for PDF encryption. | |||||
* @param pdfEncryptionParams the PDF encryption parameters, null to | |||||
* disable PDF encryption | |||||
* @deprecated Use getRendererOptions().put("encryption-params", | |||||
* new PDFEncryptionParams(..)) instead or set every parameter separately: | |||||
* getRendererOptions().put("noprint", Boolean.TRUE). | |||||
*/ | |||||
public void setPDFEncryptionParams(PDFEncryptionParams pdfEncryptionParams) { | |||||
getRendererOptions().put(PDFRenderer.ENCRYPTION_PARAMS, pdfEncryptionParams); | |||||
} | |||||
/** | /** | ||||
* Attempts to resolve the given URI. | * Attempts to resolve the given URI. | ||||
* Will use the configured resolver and if not successful fall back | * Will use the configured resolver and if not successful fall back |
// Java | // Java | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
// XML | |||||
import org.xml.sax.helpers.DefaultHandler; | import org.xml.sax.helpers.DefaultHandler; | ||||
// FOP | |||||
import org.apache.fop.fo.FOTreeBuilder; | import org.apache.fop.fo.FOTreeBuilder; | ||||
/** | /** | ||||
* @param ua FOUserAgent object | * @param ua FOUserAgent object | ||||
* @param stream the output stream | * @param stream the output stream | ||||
* @throws FOPException if setting up the DefaultHandler fails | * @throws FOPException if setting up the DefaultHandler fails | ||||
* @deprecated End-users should use {@link FopFactory#newFop(String, FOUserAgent, OutputStream)} | |||||
* instead! This constructor will become invisible with FOP 1.0. | |||||
*/ | */ | ||||
public Fop(String outputFormat, FOUserAgent ua, OutputStream stream) throws FOPException { | |||||
Fop(String outputFormat, FOUserAgent ua, OutputStream stream) throws FOPException { | |||||
this.outputFormat = outputFormat; | this.outputFormat = outputFormat; | ||||
foUserAgent = ua; | foUserAgent = ua; | ||||
} | } | ||||
/** | /** | ||||
* Constructor for use with already-created FOUserAgents. It uses MIME types to select the | |||||
* output format (ex. "application/pdf" for PDF). | |||||
* @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). | |||||
* @param ua FOUserAgent object | |||||
* @throws FOPException if setting up the DefaultHandler fails | |||||
* @deprecated End-users should use {@link FopFactory#newFop(String, FOUserAgent)} instead! | |||||
* This constructor will become invisible with FOP 1.0. | |||||
*/ | |||||
public Fop(String outputFormat, FOUserAgent ua) throws FOPException { | |||||
this.outputFormat = outputFormat; | |||||
foUserAgent = ua; | |||||
if (foUserAgent == null) { | |||||
foUserAgent = FopFactory.newInstance().newFOUserAgent(); | |||||
} | |||||
createDefaultHandler(); | |||||
} | |||||
/** | |||||
* Constructor for FOP with a default FOUserAgent. It uses MIME types to select the | |||||
* output format (ex. "application/pdf" for PDF). | |||||
* @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). | |||||
* @deprecated End-users should use {@link FopFactory#newFop(String)} instead! | |||||
* This constructor will become invisible with FOP 1.0. | |||||
*/ | |||||
public Fop(String outputFormat) { | |||||
this.outputFormat = outputFormat; | |||||
foUserAgent = FopFactory.newInstance().newFOUserAgent(); | |||||
} | |||||
/** | |||||
* Get the FOUserAgent instance for this process | |||||
* Get the FOUserAgent instance associated with the rendering run represented by this instance. | |||||
* @return the user agent | * @return the user agent | ||||
*/ | */ | ||||
public FOUserAgent getUserAgent() { | public FOUserAgent getUserAgent() { | ||||
return foUserAgent; | return foUserAgent; | ||||
} | } | ||||
/** | |||||
* Set the OutputStream to use to output the result of the Render | |||||
* (if applicable) | |||||
* @param stream the stream to output the result of rendering to | |||||
* @deprecated Use one of the factory methods on {@link FopFactory} with an OutputStream | |||||
* parameter instead. This method will be removed with FOP 1.0. | |||||
*/ | |||||
public void setOutputStream(OutputStream stream) { | |||||
this.stream = stream; | |||||
} | |||||
/** | /** | ||||
* Creates a DefaultHandler object used to generate the document. | * Creates a DefaultHandler object used to generate the document. | ||||
* Note this object implements the ContentHandler interface. | * Note this object implements the ContentHandler interface. | ||||
} | } | ||||
/** | /** | ||||
* Returns the DefaultHandler object used to generate the document. | |||||
* Checking for null and the exception is only for the deprecated constructor. | |||||
* Returns the DefaultHandler object that will receive the SAX stream containing the | |||||
* FO document to be rendered. | |||||
* @return the SAX DefaultHandler for handling the SAX events. | * @return the SAX DefaultHandler for handling the SAX events. | ||||
* @throws FOPException if setting up the DefaultHandler fails | * @throws FOPException if setting up the DefaultHandler fails | ||||
*/ | */ | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Get the version of FOP | |||||
* @return the version string | |||||
* @deprecated Use {@link org.apache.fop.Version#getVersion()} instead! | |||||
* This method will be removed with FOP 1.0. | |||||
*/ | |||||
public static String getVersion() { | |||||
return org.apache.fop.Version.getVersion(); | |||||
} | |||||
} | } |
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.URISyntaxException; | |||||
import java.net.URL; | import java.net.URL; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
* @throws FOPException when the constructor fails | * @throws FOPException when the constructor fails | ||||
*/ | */ | ||||
public Fop newFop(String outputFormat) throws FOPException { | public Fop newFop(String outputFormat) throws FOPException { | ||||
return new Fop(outputFormat, newFOUserAgent()); | |||||
return newFop(outputFormat, newFOUserAgent()); | |||||
} | } | ||||
/** | /** | ||||
* @throws FOPException when the constructor fails | * @throws FOPException when the constructor fails | ||||
*/ | */ | ||||
public Fop newFop(String outputFormat, FOUserAgent userAgent) throws FOPException { | public Fop newFop(String outputFormat, FOUserAgent userAgent) throws FOPException { | ||||
if (userAgent == null) { | |||||
throw new NullPointerException("The userAgent parameter must not be null!"); | |||||
} | |||||
return new Fop(outputFormat, userAgent); | |||||
return newFop(outputFormat, userAgent, null); | |||||
} | } | ||||
/** | /** | ||||
* @throws FOPException when the constructor fails | * @throws FOPException when the constructor fails | ||||
*/ | */ | ||||
public Fop newFop(String outputFormat, OutputStream stream) throws FOPException { | public Fop newFop(String outputFormat, OutputStream stream) throws FOPException { | ||||
return new Fop(outputFormat, newFOUserAgent(), stream); | |||||
return newFop(outputFormat, newFOUserAgent(), stream); | |||||
} | } | ||||
/** | /** | ||||
} | } | ||||
/** | /** | ||||
* cleans the base url | |||||
* @param base | |||||
* @return | |||||
* @throws MalformedURLException | |||||
* @throws URISyntaxException | |||||
* Checks if the given base URL is acceptable. It also normalizes the URL. | |||||
* @param base the base URL to check | |||||
* @return the normalized URL | |||||
* @throws MalformedURLException if there's a problem with a file URL | |||||
*/ | */ | ||||
private String checkBaseURL(String base) throws MalformedURLException { | private String checkBaseURL(String base) throws MalformedURLException { | ||||
if (!base.endsWith("/")) { | if (!base.endsWith("/")) { | ||||
/** | /** | ||||
* Sets the base URL. | * Sets the base URL. | ||||
* @param base base URL | * @param base base URL | ||||
* @throws MalformedURLException | |||||
* @throws URISyntaxException | |||||
* @throws MalformedURLException if there's a problem with a file URL | |||||
*/ | */ | ||||
public void setBaseURL(String base) throws MalformedURLException { | public void setBaseURL(String base) throws MalformedURLException { | ||||
this.base = checkBaseURL(base); | this.base = checkBaseURL(base); | ||||
/** | /** | ||||
* Sets the font base URL. | * Sets the font base URL. | ||||
* @param fontBase font base URL | * @param fontBase font base URL | ||||
* @throws MalformedURLException | |||||
* @throws URISyntaxException | |||||
* @throws MalformedURLException if there's a problem with a file URL | |||||
*/ | */ | ||||
public void setFontBaseURL(String fontBase) throws MalformedURLException { | public void setFontBaseURL(String fontBase) throws MalformedURLException { | ||||
this.fontBase = checkBaseURL(fontBase); | this.fontBase = checkBaseURL(fontBase); | ||||
/** | /** | ||||
* Sets the hyphen base URL. | * Sets the hyphen base URL. | ||||
* @param hyphenBase hythen base URL | * @param hyphenBase hythen base URL | ||||
* @throws MalformedURLException | |||||
* @throws URISyntaxException | |||||
* @throws MalformedURLException if there's a problem with a file URL | |||||
* */ | * */ | ||||
public void setHyphenBaseURL(final String hyphenBase) throws MalformedURLException { | public void setHyphenBaseURL(final String hyphenBase) throws MalformedURLException { | ||||
if (hyphenBase != null) { | if (hyphenBase != null) { | ||||
} | } | ||||
/** | /** | ||||
* sets the HyphenationTreeResolver | |||||
* @param hyphResolver | |||||
* Sets the HyphenationTreeResolver to be used for resolving user-supplied hyphenation files. | |||||
* @param hyphResolver the HyphenationTreeResolver instance | |||||
*/ | */ | ||||
public void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver) { | public void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver) { | ||||
this.hyphResolver = hyphResolver; | this.hyphResolver = hyphResolver; | ||||
return (this.fontCache != null); | return (this.fontCache != null); | ||||
} | } | ||||
/** | |||||
* Returns the font cache instance used by this factory. | |||||
* @return the font cache | |||||
*/ | |||||
public FontCache getFontCache() { | public FontCache getFontCache() { | ||||
return this.fontCache; | return this.fontCache; | ||||
} | } |