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

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