You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FopFactory.java 27KB

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