Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

FopFactory.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.apps;
  19. import java.awt.color.ColorSpace;
  20. import java.io.File;
  21. import java.io.IOException;
  22. import java.io.OutputStream;
  23. import java.net.MalformedURLException;
  24. import java.util.Collection;
  25. import java.util.Collections;
  26. import java.util.Set;
  27. import javax.xml.transform.Source;
  28. import javax.xml.transform.TransformerException;
  29. import javax.xml.transform.URIResolver;
  30. import org.xml.sax.SAXException;
  31. import org.apache.avalon.framework.configuration.Configuration;
  32. import org.apache.commons.logging.Log;
  33. import org.apache.commons.logging.LogFactory;
  34. import org.apache.xmlgraphics.image.loader.ImageContext;
  35. import org.apache.xmlgraphics.image.loader.ImageManager;
  36. import org.apache.fop.fo.ElementMapping;
  37. import org.apache.fop.fo.ElementMappingRegistry;
  38. import org.apache.fop.fonts.FontCache;
  39. import org.apache.fop.fonts.FontManager;
  40. import org.apache.fop.hyphenation.HyphenationTreeResolver;
  41. import org.apache.fop.layoutmgr.LayoutManagerMaker;
  42. import org.apache.fop.render.RendererFactory;
  43. import org.apache.fop.render.XMLHandlerRegistry;
  44. import org.apache.fop.util.ColorSpaceCache;
  45. import org.apache.fop.util.ContentHandlerFactoryRegistry;
  46. /**
  47. * Factory class which instantiates new Fop and FOUserAgent instances. This
  48. * class also holds environmental information and configuration used by FOP.
  49. * Information that may potentially be different for each rendering run can be
  50. * found and managed in the FOUserAgent.
  51. */
  52. public class FopFactory implements ImageContext {
  53. /** logger instance */
  54. private static Log log = LogFactory.getLog(FopFactory.class);
  55. /** Factory for Renderers and FOEventHandlers */
  56. private RendererFactory rendererFactory;
  57. /** Registry for XML handlers */
  58. private XMLHandlerRegistry xmlHandlers;
  59. /** The registry for ElementMapping instances */
  60. private ElementMappingRegistry elementMappingRegistry;
  61. /** The registry for ContentHandlerFactory instance */
  62. private ContentHandlerFactoryRegistry contentHandlerFactoryRegistry
  63. = new ContentHandlerFactoryRegistry();
  64. /** The resolver for user-supplied hyphenation patterns */
  65. private HyphenationTreeResolver hyphResolver = null;
  66. private ColorSpaceCache colorSpaceCache = null;
  67. /** Image manager for loading and caching image objects */
  68. private ImageManager imageManager;
  69. /** Font manager for font substitution, autodetection and caching **/
  70. private FontManager fontManager;
  71. /** Configuration layer used to configure fop */
  72. private FopFactoryConfigurator config = null;
  73. /**
  74. * The base URL for all URL resolutions, especially for
  75. * external-graphics.
  76. */
  77. private String base = null;
  78. /** The base URL for all hyphen URL resolutions. */
  79. private String hyphenBase = null;
  80. /**
  81. * FOP has the ability, for some FO's, to continue processing even if the
  82. * input XSL violates that FO's content model. This is the default
  83. * behavior for FOP. However, this flag, if set, provides the user the
  84. * ability for FOP to halt on all content model violations if desired.
  85. */
  86. private boolean strictFOValidation = FopFactoryConfigurator.DEFAULT_STRICT_FO_VALIDATION;
  87. /**
  88. * FOP will validate the contents of the user configuration strictly
  89. * (e.g. base-urls and font urls/paths).
  90. */
  91. private boolean strictUserConfigValidation
  92. = FopFactoryConfigurator.DEFAULT_STRICT_USERCONFIG_VALIDATION;
  93. /** Source resolution in dpi */
  94. private float sourceResolution = FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION;
  95. /** Target resolution in dpi */
  96. private float targetResolution = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
  97. /** Page height */
  98. private String pageHeight = FopFactoryConfigurator.DEFAULT_PAGE_HEIGHT;
  99. /** Page width */
  100. private String pageWidth = FopFactoryConfigurator.DEFAULT_PAGE_WIDTH;
  101. /** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
  102. private boolean breakIndentInheritanceOnReferenceAreaBoundary
  103. = FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE;
  104. /** Optional overriding LayoutManagerMaker */
  105. private LayoutManagerMaker lmMakerOverride = null;
  106. private Set ignoredNamespaces;
  107. private FOURIResolver foURIResolver;
  108. /**
  109. * Main constructor.
  110. */
  111. protected FopFactory() {
  112. this.config = new FopFactoryConfigurator(this);
  113. this.elementMappingRegistry = new ElementMappingRegistry(this);
  114. this.foURIResolver = new FOURIResolver(validateUserConfigStrictly());
  115. this.colorSpaceCache = new ColorSpaceCache(foURIResolver);
  116. this.imageManager = new ImageManager(this);
  117. this.rendererFactory = new RendererFactory();
  118. this.xmlHandlers = new XMLHandlerRegistry();
  119. this.ignoredNamespaces = new java.util.HashSet();
  120. }
  121. /**
  122. * Returns a new FopFactory instance.
  123. * @return the requested FopFactory instance.
  124. */
  125. public static FopFactory newInstance() {
  126. return new FopFactory();
  127. }
  128. /**
  129. * Returns a new FOUserAgent instance. Use the FOUserAgent to configure special values that
  130. * are particular to a rendering run. Don't reuse instances over multiple rendering runs but
  131. * instead create a new one each time and reuse the FopFactory.
  132. * @return the newly created FOUserAgent instance initialized with default values
  133. * @throws FOPException
  134. */
  135. public FOUserAgent newFOUserAgent() {
  136. FOUserAgent userAgent = new FOUserAgent(this);
  137. return userAgent;
  138. }
  139. /**
  140. * Returns a new {@link Fop} instance. FOP will be configured with a default user agent
  141. * instance.
  142. * <p>
  143. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  144. * use the constants defined in {@link MimeConstants}.
  145. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  146. * @return the new Fop instance
  147. * @throws FOPException when the constructor fails
  148. */
  149. public Fop newFop(String outputFormat) throws FOPException {
  150. return newFop(outputFormat, newFOUserAgent());
  151. }
  152. /**
  153. * Returns a new {@link Fop} instance. Use this factory method if you want to configure this
  154. * very rendering run, i.e. if you want to set some metadata like the title and author of the
  155. * document you want to render. In that case, create a new {@link FOUserAgent}
  156. * instance using {@link #newFOUserAgent()}.
  157. * <p>
  158. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  159. * use the constants defined in {@link MimeConstants}.
  160. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  161. * @param userAgent the user agent that will be used to control the rendering run
  162. * @return the new Fop instance
  163. * @throws FOPException when the constructor fails
  164. */
  165. public Fop newFop(String outputFormat, FOUserAgent userAgent) throws FOPException {
  166. return newFop(outputFormat, userAgent, null);
  167. }
  168. /**
  169. * Returns a new {@link Fop} instance. FOP will be configured with a default user agent
  170. * instance. Use this factory method if your output type requires an output stream.
  171. * <p>
  172. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  173. * use the constants defined in {@link MimeConstants}.
  174. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  175. * @param stream the output stream
  176. * @return the new Fop instance
  177. * @throws FOPException when the constructor fails
  178. */
  179. public Fop newFop(String outputFormat, OutputStream stream) throws FOPException {
  180. return newFop(outputFormat, newFOUserAgent(), stream);
  181. }
  182. /**
  183. * Returns a new {@link Fop} instance. Use this factory method if your output type
  184. * requires an output stream and you want to configure this very rendering run,
  185. * i.e. if you want to set some metadata like the title and author of the document
  186. * you want to render. In that case, create a new {@link FOUserAgent} instance
  187. * using {@link #newFOUserAgent()}.
  188. * <p>
  189. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  190. * use the constants defined in {@link MimeConstants}.
  191. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  192. * @param userAgent the user agent that will be used to control the rendering run
  193. * @param stream the output stream
  194. * @return the new Fop instance
  195. * @throws FOPException when the constructor fails
  196. */
  197. public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream)
  198. throws FOPException {
  199. if (userAgent == null) {
  200. throw new NullPointerException("The userAgent parameter must not be null!");
  201. }
  202. return new Fop(outputFormat, userAgent, stream);
  203. }
  204. /**
  205. * Returns a new {@link Fop} instance. Use this factory method if you want to supply your
  206. * own {@link org.apache.fop.render.Renderer Renderer} or
  207. * {@link org.apache.fop.fo.FOEventHandler FOEventHandler}
  208. * instance instead of the default ones created internally by FOP.
  209. * @param userAgent the user agent that will be used to control the rendering run
  210. * @return the new Fop instance
  211. * @throws FOPException when the constructor fails
  212. */
  213. public Fop newFop(FOUserAgent userAgent) throws FOPException {
  214. if (userAgent.getRendererOverride() == null
  215. && userAgent.getFOEventHandlerOverride() == null) {
  216. throw new IllegalStateException("Either the overriding renderer or the overriding"
  217. + " FOEventHandler must be set when this factory method is used!");
  218. }
  219. return newFop(null, userAgent);
  220. }
  221. /** @return the RendererFactory */
  222. public RendererFactory getRendererFactory() {
  223. return this.rendererFactory;
  224. }
  225. /** @return the XML handler registry */
  226. public XMLHandlerRegistry getXMLHandlerRegistry() {
  227. return this.xmlHandlers;
  228. }
  229. /** @return the element mapping registry */
  230. public ElementMappingRegistry getElementMappingRegistry() {
  231. return this.elementMappingRegistry;
  232. }
  233. /** @return the content handler factory registry */
  234. public ContentHandlerFactoryRegistry getContentHandlerFactoryRegistry() {
  235. return this.contentHandlerFactoryRegistry;
  236. }
  237. /**
  238. * Returns the image manager.
  239. * @return the image manager
  240. */
  241. public ImageManager getImageManager() {
  242. return this.imageManager;
  243. }
  244. /**
  245. * Add the element mapping with the given class name.
  246. * @param elementMapping the class name representing the element mapping.
  247. */
  248. public void addElementMapping(ElementMapping elementMapping) {
  249. this.elementMappingRegistry.addElementMapping(elementMapping);
  250. }
  251. /**
  252. * Sets an explicit LayoutManagerMaker instance which overrides the one
  253. * defined by the AreaTreeHandler.
  254. * @param lmMaker the LayoutManagerMaker instance
  255. */
  256. public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker) {
  257. this.lmMakerOverride = lmMaker;
  258. }
  259. /**
  260. * Returns the overriding LayoutManagerMaker instance, if any.
  261. * @return the overriding LayoutManagerMaker or null
  262. */
  263. public LayoutManagerMaker getLayoutManagerMakerOverride() {
  264. return this.lmMakerOverride;
  265. }
  266. /**
  267. * Sets the base URL.
  268. * @param base the base URL
  269. * @throws MalformedURLException if there's a problem with a file URL
  270. */
  271. public void setBaseURL(String base) throws MalformedURLException {
  272. this.base = foURIResolver.checkBaseURL(base);
  273. }
  274. /**
  275. * Returns the base URL.
  276. * @return the base URL
  277. */
  278. public String getBaseURL() {
  279. return this.base;
  280. }
  281. /**
  282. * Sets the font base URL.
  283. * @param fontBase font base URL
  284. * @throws MalformedURLException if there's a problem with a file URL
  285. * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
  286. */
  287. public void setFontBaseURL(String fontBase) throws MalformedURLException {
  288. getFontManager().setFontBaseURL(fontBase);
  289. }
  290. /**
  291. * @return the font base URL
  292. * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
  293. */
  294. public String getFontBaseURL() {
  295. return getFontManager().getFontBaseURL();
  296. }
  297. /** @return the hyphen base URL */
  298. public String getHyphenBaseURL() {
  299. return this.hyphenBase;
  300. }
  301. /**
  302. * Sets the hyphen base URL.
  303. * @param hyphenBase hythen base URL
  304. * @throws MalformedURLException if there's a problem with a file URL
  305. * */
  306. public void setHyphenBaseURL(final String hyphenBase) throws MalformedURLException {
  307. if (hyphenBase != null) {
  308. setHyphenationTreeResolver(
  309. new HyphenationTreeResolver() {
  310. public Source resolve(String href) {
  311. return resolveURI(href, hyphenBase);
  312. }
  313. });
  314. }
  315. this.hyphenBase = foURIResolver.checkBaseURL(hyphenBase);
  316. }
  317. /**
  318. * Sets the URI Resolver. It is used for resolving factory-level URIs like hyphenation
  319. * patterns and as backup for URI resolution performed during a rendering run.
  320. * @param uriResolver the new URI resolver
  321. */
  322. public void setURIResolver(URIResolver uriResolver) {
  323. foURIResolver.setCustomURIResolver(uriResolver);
  324. }
  325. /**
  326. * Returns the URI Resolver.
  327. * @return the URI Resolver
  328. */
  329. public URIResolver getURIResolver() {
  330. return foURIResolver;
  331. }
  332. /**
  333. * Returns the FO URI Resolver.
  334. * @return the FO URI Resolver
  335. */
  336. public FOURIResolver getFOURIResolver() {
  337. return foURIResolver;
  338. }
  339. /** @return the HyphenationTreeResolver for resolving user-supplied hyphenation patterns. */
  340. public HyphenationTreeResolver getHyphenationTreeResolver() {
  341. return this.hyphResolver;
  342. }
  343. /**
  344. * Sets the HyphenationTreeResolver to be used for resolving user-supplied hyphenation files.
  345. * @param hyphResolver the HyphenationTreeResolver instance
  346. */
  347. public void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver) {
  348. this.hyphResolver = hyphResolver;
  349. }
  350. /**
  351. * Activates strict XSL content model validation for FOP
  352. * Default is false (FOP will continue processing where it can)
  353. * @param validateStrictly true to turn on strict validation
  354. */
  355. public void setStrictValidation(boolean validateStrictly) {
  356. this.strictFOValidation = validateStrictly;
  357. }
  358. /**
  359. * Returns whether FOP is strictly validating input XSL
  360. * @return true of strict validation turned on, false otherwise
  361. */
  362. public boolean validateStrictly() {
  363. return strictFOValidation;
  364. }
  365. /**
  366. * @return true if the indent inheritance should be broken when crossing reference area
  367. * boundaries (for more info, see the javadoc for the relative member variable)
  368. */
  369. public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
  370. return breakIndentInheritanceOnReferenceAreaBoundary;
  371. }
  372. /**
  373. * Controls whether to enable a feature that breaks indent inheritance when crossing
  374. * reference area boundaries.
  375. * <p>
  376. * This flag controls whether FOP will enable special code that breaks property
  377. * inheritance for start-indent and end-indent when the evaluation of the inherited
  378. * value would cross a reference area. This is described under
  379. * http://wiki.apache.org/xmlgraphics-fop/IndentInheritance as is intended to
  380. * improve interoperability with commercial FO implementations and to produce
  381. * results that are more in line with the expectation of unexperienced FO users.
  382. * Note: Enabling this features violates the XSL specification!
  383. * @param value true to enable the feature
  384. */
  385. public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) {
  386. this.breakIndentInheritanceOnReferenceAreaBoundary = value;
  387. }
  388. /**
  389. * @return true if kerning on base 14 fonts is enabled
  390. * @deprecated use getFontManager().isBase14KerningEnabled() instead
  391. */
  392. public boolean isBase14KerningEnabled() {
  393. return getFontManager().isBase14KerningEnabled();
  394. }
  395. /**
  396. * Controls whether kerning is activated on base 14 fonts.
  397. * @param value true if kerning should be activated
  398. * @deprecated use getFontManager().setBase14KerningEnabled(boolean) instead
  399. */
  400. public void setBase14KerningEnabled(boolean value) {
  401. getFontManager().setBase14KerningEnabled(value);
  402. }
  403. /** @return the resolution for resolution-dependant input */
  404. public float getSourceResolution() {
  405. return this.sourceResolution;
  406. }
  407. /**
  408. * Returns the conversion factor from pixel units to millimeters. This
  409. * depends on the desired source resolution.
  410. * @return float conversion factor
  411. * @see #getSourceResolution()
  412. */
  413. public float getSourcePixelUnitToMillimeter() {
  414. return 25.4f / getSourceResolution();
  415. }
  416. /**
  417. * Sets the source resolution in dpi. This value is used to interpret the pixel size
  418. * of source documents like SVG images and bitmap images without resolution information.
  419. * @param dpi resolution in dpi
  420. */
  421. public void setSourceResolution(float dpi) {
  422. this.sourceResolution = dpi;
  423. if (log.isDebugEnabled()) {
  424. log.debug("source-resolution set to: " + sourceResolution
  425. + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
  426. }
  427. }
  428. /** @return the resolution for resolution-dependant output */
  429. public float getTargetResolution() {
  430. return this.targetResolution;
  431. }
  432. /**
  433. * Returns the conversion factor from pixel units to millimeters. This
  434. * depends on the desired target resolution.
  435. * @return float conversion factor
  436. * @see #getTargetResolution()
  437. */
  438. public float getTargetPixelUnitToMillimeter() {
  439. return 25.4f / this.targetResolution;
  440. }
  441. /**
  442. * Sets the source resolution in dpi. This value is used to interpret the pixel size
  443. * of source documents like SVG images and bitmap images without resolution information.
  444. * @param dpi resolution in dpi
  445. */
  446. public void setTargetResolution(float dpi) {
  447. this.targetResolution = dpi;
  448. }
  449. /**
  450. * Sets the source resolution in dpi. This value is used to interpret the pixel size
  451. * of source documents like SVG images and bitmap images without resolution information.
  452. * @param dpi resolution in dpi
  453. */
  454. public void setSourceResolution(int dpi) {
  455. setSourceResolution((float)dpi);
  456. }
  457. /**
  458. * Gets the default page-height to use as fallback,
  459. * in case page-height="auto"
  460. *
  461. * @return the page-height, as a String
  462. */
  463. public String getPageHeight() {
  464. return this.pageHeight;
  465. }
  466. /**
  467. * Sets the page-height to use as fallback, in case
  468. * page-height="auto"
  469. *
  470. * @param pageHeight page-height as a String
  471. */
  472. public void setPageHeight(String pageHeight) {
  473. this.pageHeight = pageHeight;
  474. if (log.isDebugEnabled()) {
  475. log.debug("Default page-height set to: " + pageHeight);
  476. }
  477. }
  478. /**
  479. * Gets the default page-width to use as fallback,
  480. * in case page-width="auto"
  481. *
  482. * @return the page-width, as a String
  483. */
  484. public String getPageWidth() {
  485. return this.pageWidth;
  486. }
  487. /**
  488. * Sets the page-width to use as fallback, in case
  489. * page-width="auto"
  490. *
  491. * @param pageWidth page-width as a String
  492. */
  493. public void setPageWidth(String pageWidth) {
  494. this.pageWidth = pageWidth;
  495. if (log.isDebugEnabled()) {
  496. log.debug("Default page-width set to: " + pageWidth);
  497. }
  498. }
  499. /**
  500. * Adds a namespace to the set of ignored namespaces.
  501. * If FOP encounters a namespace which it cannot handle, it issues a warning except if this
  502. * namespace is in the ignored set.
  503. * @param namespaceURI the namespace URI
  504. */
  505. public void ignoreNamespace(String namespaceURI) {
  506. this.ignoredNamespaces.add(namespaceURI);
  507. }
  508. /**
  509. * Adds a collection of namespaces to the set of ignored namespaces.
  510. * If FOP encounters a namespace which it cannot handle, it issues a warning except if this
  511. * namespace is in the ignored set.
  512. * @param namespaceURIs the namespace URIs
  513. */
  514. public void ignoreNamespaces(Collection namespaceURIs) {
  515. this.ignoredNamespaces.addAll(namespaceURIs);
  516. }
  517. /**
  518. * Indicates whether a namespace URI is on the ignored list.
  519. * @param namespaceURI the namespace URI
  520. * @return true if the namespace is ignored by FOP
  521. */
  522. public boolean isNamespaceIgnored(String namespaceURI) {
  523. return this.ignoredNamespaces.contains(namespaceURI);
  524. }
  525. /** @return the set of namespaces that are ignored by FOP */
  526. public Set getIgnoredNamespace() {
  527. return Collections.unmodifiableSet(this.ignoredNamespaces);
  528. }
  529. //------------------------------------------- Configuration stuff
  530. /**
  531. * Set the user configuration.
  532. * @param userConfigFile the configuration file
  533. * @throws IOException if an I/O error occurs
  534. * @throws SAXException if a parsing error occurs
  535. */
  536. public void setUserConfig(File userConfigFile) throws SAXException, IOException {
  537. config.setUserConfig(userConfigFile);
  538. }
  539. /**
  540. * Set the user configuration from an URI.
  541. * @param uri the URI to the configuration file
  542. * @throws IOException if an I/O error occurs
  543. * @throws SAXException if a parsing error occurs
  544. */
  545. public void setUserConfig(String uri) throws SAXException, IOException {
  546. config.setUserConfig(uri);
  547. }
  548. /**
  549. * Set the user configuration.
  550. * @param userConfig configuration
  551. * @throws FOPException if a configuration problem occurs
  552. */
  553. public void setUserConfig(Configuration userConfig) throws FOPException {
  554. config.setUserConfig(userConfig);
  555. }
  556. /**
  557. * Get the user configuration.
  558. * @return the user configuration
  559. */
  560. public Configuration getUserConfig() {
  561. return config.getUserConfig();
  562. }
  563. /**
  564. * Is the user configuration to be validated?
  565. * @param strictUserConfigValidation strict user config validation
  566. */
  567. public void setStrictUserConfigValidation(boolean strictUserConfigValidation) {
  568. this.strictUserConfigValidation = strictUserConfigValidation;
  569. this.foURIResolver.setThrowExceptions(strictUserConfigValidation);
  570. }
  571. /**
  572. * Is the user configuration to be validated?
  573. * @return if the user configuration should be validated
  574. */
  575. public boolean validateUserConfigStrictly() {
  576. return this.strictUserConfigValidation;
  577. }
  578. //------------------------------------------- Font related stuff
  579. /**
  580. * Whether or not to cache results of font triplet detection/auto-config
  581. * @param useCache use cache or not
  582. * @deprecated use getFontManager().setUseCache(boolean) instead
  583. */
  584. public void setUseCache(boolean useCache) {
  585. getFontManager().setUseCache(useCache);
  586. }
  587. /**
  588. * Cache results of font triplet detection/auto-config?
  589. * @return whether this factory is uses the cache
  590. * @deprecated use getFontManager().useCache() instead
  591. */
  592. public boolean useCache() {
  593. return getFontManager().useCache();
  594. }
  595. /**
  596. * Returns the font cache instance used by this factory.
  597. * @return the font cache
  598. * @deprecated use getFontManager().getFontCache() instead
  599. */
  600. public FontCache getFontCache() {
  601. return getFontManager().getFontCache();
  602. }
  603. /**
  604. * Returns the font manager
  605. * @return the font manager
  606. */
  607. public FontManager getFontManager() {
  608. if (fontManager == null) {
  609. this.fontManager = new FontManager(this);
  610. }
  611. return this.fontManager;
  612. }
  613. /**
  614. * Attempts to resolve the given URI.
  615. * Will use the configured resolver and if not successful fall back
  616. * to the default resolver.
  617. * @param href URI to access
  618. * @param baseUri the base URI to resolve against
  619. * @return A {@link javax.xml.transform.Source} object, or null if the URI
  620. * cannot be resolved.
  621. * @see org.apache.fop.apps.FOURIResolver
  622. */
  623. public Source resolveURI(String href, String baseUri) {
  624. Source source = null;
  625. try {
  626. source = foURIResolver.resolve(href, baseUri);
  627. } catch (TransformerException e) {
  628. log.error("Attempt to resolve URI '" + href + "' failed: ", e);
  629. }
  630. return source;
  631. }
  632. /**
  633. * Create (if needed) and return an ICC ColorSpace instance.
  634. *
  635. * The ICC profile source is taken from the src attribute of the color-profile FO element.
  636. * If the ICC ColorSpace is not yet in the cache a new one is created and stored in the cache.
  637. *
  638. * The FOP URI resolver is used to try and locate the ICC file.
  639. * If that fails null is returned.
  640. *
  641. * @param baseUri a base URI to resolve relative URIs
  642. * @param iccProfileSrc ICC Profile source to return a ColorSpace for
  643. * @return ICC ColorSpace object or null if ColorSpace could not be created
  644. */
  645. public ColorSpace getColorSpace(String baseUri, String iccProfileSrc) {
  646. return colorSpaceCache.get(baseUri, iccProfileSrc);
  647. }
  648. }