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.

FOUserAgent.java 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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. // Java
  20. import java.io.File;
  21. import java.io.IOException;
  22. import java.io.OutputStream;
  23. import java.net.URISyntaxException;
  24. import java.util.Date;
  25. import java.util.Map;
  26. import javax.xml.transform.Source;
  27. import javax.xml.transform.stream.StreamSource;
  28. import org.apache.commons.logging.Log;
  29. import org.apache.commons.logging.LogFactory;
  30. import org.apache.xmlgraphics.image.loader.ImageContext;
  31. import org.apache.xmlgraphics.image.loader.ImageManager;
  32. import org.apache.xmlgraphics.image.loader.ImageSessionContext;
  33. import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext;
  34. import org.apache.xmlgraphics.image.loader.util.SoftMapCache;
  35. import org.apache.xmlgraphics.util.UnitConv;
  36. import org.apache.fop.Version;
  37. import org.apache.fop.accessibility.Accessibility;
  38. import org.apache.fop.accessibility.DummyStructureTreeEventHandler;
  39. import org.apache.fop.accessibility.StructureTreeEventHandler;
  40. import org.apache.fop.apps.io.InternalResourceResolver;
  41. import org.apache.fop.configuration.Configuration;
  42. import org.apache.fop.configuration.ConfigurationException;
  43. import org.apache.fop.events.DefaultEventBroadcaster;
  44. import org.apache.fop.events.Event;
  45. import org.apache.fop.events.EventBroadcaster;
  46. import org.apache.fop.events.EventListener;
  47. import org.apache.fop.events.FOPEventListenerProxy;
  48. import org.apache.fop.events.LoggingEventListener;
  49. import org.apache.fop.fo.ElementMappingRegistry;
  50. import org.apache.fop.fo.FOEventHandler;
  51. import org.apache.fop.fonts.FontManager;
  52. import org.apache.fop.hyphenation.HyphenationTreeCache;
  53. import org.apache.fop.layoutmgr.LayoutManagerMaker;
  54. import org.apache.fop.render.ImageHandlerRegistry;
  55. import org.apache.fop.render.Renderer;
  56. import org.apache.fop.render.RendererConfig;
  57. import org.apache.fop.render.RendererConfig.RendererConfigParser;
  58. import org.apache.fop.render.RendererConfigOption;
  59. import org.apache.fop.render.RendererFactory;
  60. import org.apache.fop.render.XMLHandlerRegistry;
  61. import org.apache.fop.render.intermediate.IFDocumentHandler;
  62. import org.apache.fop.util.ColorSpaceCache;
  63. import org.apache.fop.util.ContentHandlerFactoryRegistry;
  64. /**
  65. * This is the user agent for FOP.
  66. * It is the entity through which you can interact with the XSL-FO processing and is
  67. * used by the processing to obtain user configurable options.
  68. * <p>
  69. * Renderer specific extensions (that do not produce normal areas on
  70. * the output) will be done like so:
  71. * <br>
  72. * The extension will create an area, custom if necessary
  73. * <br>
  74. * this area will be added to the user agent with a key
  75. * <br>
  76. * the renderer will know keys for particular extensions
  77. * <br>
  78. * eg. bookmarks will be held in a special hierarchical area representing
  79. * the title and bookmark structure
  80. * <br>
  81. * These areas may contain resolvable areas that will be processed
  82. * with other resolvable areas
  83. */
  84. public class FOUserAgent {
  85. private static Log log = LogFactory.getLog("FOP");
  86. private final FopFactory factory;
  87. private final InternalResourceResolver resourceResolver;
  88. private float targetResolution = FopFactoryConfig.DEFAULT_TARGET_RESOLUTION;
  89. private Map rendererOptions = new java.util.HashMap();
  90. private File outputFile;
  91. private IFDocumentHandler documentHandlerOverride;
  92. private Renderer rendererOverride;
  93. private FOEventHandler foEventHandlerOverride;
  94. private boolean locatorEnabled = true; // true by default (for error messages).
  95. private boolean conserveMemoryPolicy;
  96. private EventBroadcaster eventBroadcaster = new FOPEventBroadcaster();
  97. private StructureTreeEventHandler structureTreeEventHandler
  98. = DummyStructureTreeEventHandler.INSTANCE;
  99. private boolean pdfUAEnabled;
  100. /** Producer: Metadata element for the system/software that produces
  101. * the document. (Some renderers can store this in the document.)
  102. */
  103. protected String producer = "Apache FOP Version " + Version.getVersion();
  104. /** Creator: Metadata element for the user that created the
  105. * document. (Some renderers can store this in the document.)
  106. */
  107. protected String creator;
  108. /** Creation Date: Override of the date the document was created.
  109. * (Some renderers can store this in the document.)
  110. */
  111. protected Date creationDate;
  112. /** Author of the content of the document. */
  113. protected String author;
  114. /** Title of the document. */
  115. protected String title;
  116. /** Subject of the document. */
  117. protected String subject;
  118. /** Set of keywords applicable to this document. */
  119. protected String keywords;
  120. private final ImageSessionContext imageSessionContext;
  121. private final SoftMapCache pdfObjectCache = new SoftMapCache(true);
  122. /**
  123. * Main constructor. <b>This constructor should not be called directly. Please use the
  124. * methods from FopFactory to construct FOUserAgent instances!</b>
  125. * @param factory the factory that provides environment-level information
  126. * @param resourceResolver the resolver used to acquire resources
  127. * @see org.apache.fop.apps.FopFactory
  128. */
  129. FOUserAgent(final FopFactory factory, InternalResourceResolver resourceResolver) {
  130. this.factory = factory;
  131. this.resourceResolver = resourceResolver;
  132. setTargetResolution(factory.getTargetResolution());
  133. setAccessibility(factory.isAccessibilityEnabled());
  134. setKeepEmptyTags(factory.isKeepEmptyTags());
  135. imageSessionContext = new AbstractImageSessionContext(factory.getFallbackResolver()) {
  136. public ImageContext getParentContext() {
  137. return factory;
  138. }
  139. public float getTargetResolution() {
  140. return FOUserAgent.this.getTargetResolution();
  141. }
  142. public Source resolveURI(String uri) {
  143. return FOUserAgent.this.resolveURI(uri);
  144. }
  145. };
  146. }
  147. /**
  148. * Returns a new {@link Fop} instance. Use this factory method if your output type
  149. * requires an output stream and you want to configure this very rendering run,
  150. * i.e. if you want to set some metadata like the title and author of the document
  151. * you want to render. In that case, create a new {@link FOUserAgent} instance
  152. * using {@link org.apache.fop.apps.FopFactory#newFOUserAgent() newFOUserAgent()}.
  153. * <p>
  154. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  155. * use the constants defined in {@link MimeConstants}.
  156. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  157. * @param stream the output stream
  158. * @return the new Fop instance
  159. * @throws FOPException when the constructor fails
  160. */
  161. public Fop newFop(String outputFormat, OutputStream stream) throws FOPException {
  162. return new Fop(outputFormat, this, stream);
  163. }
  164. /**
  165. * Returns a new {@link Fop} instance. Use this factory method if you want to configure this
  166. * very rendering run, i.e. if you want to set some metadata like the title and author of the
  167. * document you want to render. In that case, create a new {@link FOUserAgent}
  168. * instance using {@link org.apache.fop.apps.FopFactory#newFOUserAgent() newFOUserAgent()}.
  169. * <p>
  170. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  171. * use the constants defined in {@link MimeConstants}.
  172. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  173. * @return the new Fop instance
  174. * @throws FOPException when the constructor fails
  175. */
  176. public Fop newFop(String outputFormat) throws FOPException {
  177. return newFop(outputFormat, null);
  178. }
  179. /**
  180. * Returns the resource resolver.
  181. *
  182. * @return the resource resolver
  183. */
  184. public InternalResourceResolver getResourceResolver() {
  185. return resourceResolver;
  186. }
  187. // ---------------------------------------------- rendering-run dependent stuff
  188. /**
  189. * Sets an explicit document handler to use which overrides the one that would be
  190. * selected by default.
  191. * @param documentHandler the document handler instance to use
  192. */
  193. public void setDocumentHandlerOverride(IFDocumentHandler documentHandler) {
  194. if (isAccessibilityEnabled()) {
  195. setStructureTreeEventHandler(documentHandler.getStructureTreeEventHandler());
  196. }
  197. this.documentHandlerOverride = documentHandler;
  198. }
  199. /**
  200. * Returns the overriding {@link IFDocumentHandler} instance, if any.
  201. * @return the overriding document handler or null
  202. */
  203. public IFDocumentHandler getDocumentHandlerOverride() {
  204. return this.documentHandlerOverride;
  205. }
  206. /**
  207. * Sets an explicit renderer to use which overrides the one defined by the
  208. * render type setting.
  209. * @param renderer the Renderer instance to use
  210. */
  211. public void setRendererOverride(Renderer renderer) {
  212. this.rendererOverride = renderer;
  213. }
  214. /**
  215. * Returns the overriding Renderer instance, if any.
  216. * @return the overriding Renderer or null
  217. */
  218. public Renderer getRendererOverride() {
  219. return rendererOverride;
  220. }
  221. /**
  222. * Sets an explicit FOEventHandler instance which overrides the one
  223. * defined by the render type setting.
  224. * @param handler the FOEventHandler instance
  225. */
  226. public void setFOEventHandlerOverride(FOEventHandler handler) {
  227. this.foEventHandlerOverride = handler;
  228. }
  229. /**
  230. * Returns the overriding FOEventHandler instance, if any.
  231. * @return the overriding FOEventHandler or null
  232. */
  233. public FOEventHandler getFOEventHandlerOverride() {
  234. return this.foEventHandlerOverride;
  235. }
  236. /**
  237. * Sets the producer of the document.
  238. * @param producer source of document
  239. */
  240. public void setProducer(String producer) {
  241. this.producer = producer;
  242. }
  243. /**
  244. * Returns the producer of the document
  245. * @return producer name
  246. */
  247. public String getProducer() {
  248. return producer;
  249. }
  250. /**
  251. * Sets the creator of the document.
  252. * @param creator of document
  253. */
  254. public void setCreator(String creator) {
  255. this.creator = creator;
  256. }
  257. /**
  258. * Returns the creator of the document
  259. * @return creator name
  260. */
  261. public String getCreator() {
  262. return creator;
  263. }
  264. /**
  265. * Sets the creation date of the document.
  266. * @param creationDate date of document
  267. */
  268. public void setCreationDate(Date creationDate) {
  269. this.creationDate = creationDate;
  270. }
  271. /**
  272. * Returns the creation date of the document
  273. * @return creation date of document
  274. */
  275. public Date getCreationDate() {
  276. return creationDate;
  277. }
  278. /**
  279. * Sets the author of the document.
  280. * @param author of document
  281. */
  282. public void setAuthor(String author) {
  283. this.author = author;
  284. }
  285. /**
  286. * Returns the author of the document
  287. * @return author name
  288. */
  289. public String getAuthor() {
  290. return author;
  291. }
  292. /**
  293. * Sets the title of the document. This will override any title coming from
  294. * an fo:title element.
  295. * @param title of document
  296. */
  297. public void setTitle(String title) {
  298. this.title = title;
  299. }
  300. /**
  301. * Returns the title of the document
  302. * @return title name
  303. */
  304. public String getTitle() {
  305. return title;
  306. }
  307. /**
  308. * Sets the subject of the document.
  309. * @param subject of document
  310. */
  311. public void setSubject(String subject) {
  312. this.subject = subject;
  313. }
  314. /**
  315. * Returns the subject of the document
  316. * @return the subject
  317. */
  318. public String getSubject() {
  319. return subject;
  320. }
  321. /**
  322. * Sets the keywords for the document.
  323. * @param keywords for the document
  324. */
  325. public void setKeywords(String keywords) {
  326. this.keywords = keywords;
  327. }
  328. /**
  329. * Returns the keywords for the document
  330. * @return the keywords
  331. */
  332. public String getKeywords() {
  333. return keywords;
  334. }
  335. /**
  336. * Returns the renderer options
  337. * @return renderer options
  338. */
  339. public Map getRendererOptions() {
  340. return rendererOptions;
  341. }
  342. /**
  343. * Gets the renderer options given an interface representing renderer configuration options.
  344. *
  345. * @param option the renderer option
  346. * @return the value
  347. */
  348. public Object getRendererOption(RendererConfigOption option) {
  349. return rendererOptions.get(option.getName());
  350. }
  351. /**
  352. * Attempts to resolve the given URI.
  353. * Will use the configured resolver and if not successful fall back
  354. * to the default resolver.
  355. * @param uri URI to access
  356. * @return A {@link javax.xml.transform.Source} object, or null if the URI
  357. * cannot be resolved.
  358. */
  359. public StreamSource resolveURI(String uri) {
  360. // TODO: What do we want to do when resources aren't found??? We also need to remove this
  361. // method entirely
  362. try {
  363. // Have to do this so we can resolve data URIs
  364. StreamSource src = new StreamSource(resourceResolver.getResource(uri));
  365. src.setSystemId(uri);
  366. return src;
  367. } catch (URISyntaxException use) {
  368. return null;
  369. } catch (IOException ioe) {
  370. return null;
  371. }
  372. }
  373. /**
  374. * Sets the output File.
  375. * @param f the output File
  376. */
  377. public void setOutputFile(File f) {
  378. this.outputFile = f;
  379. }
  380. /**
  381. * Gets the output File.
  382. * @return the output File
  383. */
  384. public File getOutputFile() {
  385. return outputFile;
  386. }
  387. /**
  388. * Returns the conversion factor from pixel units to millimeters. This
  389. * depends on the desired target resolution.
  390. * @return float conversion factor
  391. * @see #getTargetResolution()
  392. */
  393. public float getTargetPixelUnitToMillimeter() {
  394. return UnitConv.IN2MM / this.targetResolution;
  395. }
  396. /** @return the resolution for resolution-dependant output */
  397. public float getTargetResolution() {
  398. return this.targetResolution;
  399. }
  400. /**
  401. * Sets the target resolution in dpi. This value defines the target resolution of
  402. * bitmap images generated by the bitmap renderers (such as the TIFF renderer) and of
  403. * bitmap images generated by filter effects in Apache Batik.
  404. * @param dpi resolution in dpi
  405. */
  406. public void setTargetResolution(float dpi) {
  407. this.targetResolution = dpi;
  408. if (log.isDebugEnabled()) {
  409. log.debug("target-resolution set to: " + targetResolution
  410. + "dpi (px2mm=" + getTargetPixelUnitToMillimeter() + ")");
  411. }
  412. }
  413. /**
  414. * Sets the target resolution in dpi. This value defines the target resolution of
  415. * bitmap images generated by the bitmap renderers (such as the TIFF renderer) and of
  416. * bitmap images generated by filter effects in Apache Batik.
  417. * @param dpi resolution in dpi
  418. */
  419. public void setTargetResolution(int dpi) {
  420. setTargetResolution((float)dpi);
  421. }
  422. /**
  423. * Returns the image session context for the image package.
  424. * @return the ImageSessionContext instance for this rendering run
  425. */
  426. public ImageSessionContext getImageSessionContext() {
  427. return this.imageSessionContext;
  428. }
  429. // ---------------------------------------------- environment-level stuff
  430. // (convenience access to FopFactory methods)
  431. /**
  432. * Returns the conversion factor from pixel units to millimeters. This
  433. * depends on the desired source resolution.
  434. * @return float conversion factor
  435. * @see #getSourceResolution()
  436. */
  437. public float getSourcePixelUnitToMillimeter() {
  438. return factory.getSourcePixelUnitToMillimeter();
  439. }
  440. /** @return the resolution for resolution-dependant input */
  441. public float getSourceResolution() {
  442. return factory.getSourceResolution();
  443. }
  444. /**
  445. * Gets the default page-height to use as fallback,
  446. * in case page-height="auto"
  447. *
  448. * @return the page-height, as a String
  449. * @see FopFactory#getPageHeight()
  450. */
  451. public String getPageHeight() {
  452. return factory.getPageHeight();
  453. }
  454. /**
  455. * Gets the default page-width to use as fallback,
  456. * in case page-width="auto"
  457. *
  458. * @return the page-width, as a String
  459. * @see FopFactory#getPageWidth()
  460. */
  461. public String getPageWidth() {
  462. return factory.getPageWidth();
  463. }
  464. /**
  465. * Returns whether FOP is strictly validating input XSL
  466. * @return true of strict validation turned on, false otherwise
  467. * @see FopFactory#validateStrictly()
  468. */
  469. public boolean validateStrictly() {
  470. return factory.validateStrictly();
  471. }
  472. /**
  473. * @return true if the indent inheritance should be broken when crossing reference area
  474. * boundaries (for more info, see the javadoc for the relative member variable)
  475. * @see FopFactory#isBreakIndentInheritanceOnReferenceAreaBoundary()
  476. */
  477. public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
  478. return factory.isBreakIndentInheritanceOnReferenceAreaBoundary();
  479. }
  480. /**
  481. * @return the RendererFactory
  482. */
  483. public RendererFactory getRendererFactory() {
  484. return factory.getRendererFactory();
  485. }
  486. /**
  487. * @return the XML handler registry
  488. */
  489. public XMLHandlerRegistry getXMLHandlerRegistry() {
  490. return factory.getXMLHandlerRegistry();
  491. }
  492. /**
  493. * Controls the use of SAXLocators to provide location information in error
  494. * messages.
  495. *
  496. * @param enableLocator <code>false</code> if SAX Locators should be disabled
  497. */
  498. public void setLocatorEnabled(boolean enableLocator) {
  499. locatorEnabled = enableLocator;
  500. }
  501. /**
  502. * Checks if the use of Locators is enabled
  503. * @return true if context information should be stored on each node in the FO tree.
  504. */
  505. public boolean isLocatorEnabled() {
  506. return locatorEnabled;
  507. }
  508. /**
  509. * Returns the event broadcaster that control events sent inside a processing run. Clients
  510. * can register event listeners with the event broadcaster to listen for events that occur
  511. * while a document is being processed.
  512. * @return the event broadcaster.
  513. */
  514. public EventBroadcaster getEventBroadcaster() {
  515. return this.eventBroadcaster;
  516. }
  517. public boolean isPdfUAEnabled() {
  518. return pdfUAEnabled;
  519. }
  520. public void setPdfUAEnabled(boolean pdfUAEnabled) {
  521. this.pdfUAEnabled = pdfUAEnabled;
  522. }
  523. private class FOPEventBroadcaster extends DefaultEventBroadcaster {
  524. private EventListener rootListener;
  525. public FOPEventBroadcaster() {
  526. //Install a temporary event listener that catches the first event to
  527. //do some initialization.
  528. this.rootListener = new EventListener() {
  529. public void processEvent(Event event) {
  530. if (!listeners.hasEventListeners()) {
  531. //Backwards-compatibility: Make sure at least the LoggingEventListener is
  532. //plugged in so no events are just silently swallowed.
  533. addEventListener(
  534. new LoggingEventListener(LogFactory.getLog(FOUserAgent.class)));
  535. }
  536. //Replace with final event listener
  537. rootListener = new FOPEventListenerProxy(
  538. listeners, FOUserAgent.this);
  539. rootListener.processEvent(event);
  540. }
  541. };
  542. }
  543. /** {@inheritDoc} */
  544. public void broadcastEvent(Event event) {
  545. rootListener.processEvent(event);
  546. }
  547. }
  548. /**
  549. * Check whether memory-conservation is enabled.
  550. *
  551. * @return true if FOP is to conserve as much as possible
  552. */
  553. public boolean isConserveMemoryPolicyEnabled() {
  554. return this.conserveMemoryPolicy;
  555. }
  556. /**
  557. * Control whether memory-conservation should be enabled
  558. *
  559. * @param conserveMemoryPolicy the cachingEnabled to set
  560. */
  561. public void setConserveMemoryPolicy(boolean conserveMemoryPolicy) {
  562. this.conserveMemoryPolicy = conserveMemoryPolicy;
  563. }
  564. /**
  565. * Check whether complex script features are enabled.
  566. *
  567. * @return true if FOP is to use complex script features
  568. */
  569. public boolean isComplexScriptFeaturesEnabled() {
  570. return factory.isComplexScriptFeaturesEnabled();
  571. }
  572. /**
  573. * Returns the renderer configuration object for a particular MIME type.
  574. *
  575. * @param mimeType the config MIME type
  576. * @param configCreator the parser for creating the config for the first run of parsing.
  577. * @return the renderer configuration object
  578. * @throws FOPException if an error occurs when creating the config object
  579. */
  580. public RendererConfig getRendererConfig(String mimeType, RendererConfigParser configCreator)
  581. throws FOPException {
  582. return factory.getRendererConfig(this, getRendererConfiguration(mimeType), configCreator);
  583. }
  584. /**
  585. * Returns a {@link Configuration} object for which contains renderer configuration for a given
  586. * MIME type.
  587. *
  588. * @param mimeType the renderer configuration MIME type
  589. * @return the configuration object
  590. */
  591. public Configuration getRendererConfiguration(String mimeType) {
  592. Configuration cfg = getUserConfig();
  593. String type = "renderer";
  594. String mime = "mime";
  595. if (cfg == null) {
  596. if (log.isDebugEnabled()) {
  597. log.debug("userconfig is null");
  598. }
  599. return null;
  600. }
  601. Configuration userConfig = null;
  602. Configuration[] cfgs = cfg.getChild(type + "s").getChildren(type);
  603. for (Configuration child : cfgs) {
  604. try {
  605. if (child.getAttribute(mime).equals(mimeType)) {
  606. userConfig = child;
  607. break;
  608. }
  609. } catch (ConfigurationException e) {
  610. // silently pass over configurations without mime type
  611. }
  612. }
  613. log.debug((userConfig == null ? "No u" : "U")
  614. + "ser configuration found for MIME type " + mimeType);
  615. return userConfig;
  616. }
  617. /**
  618. * Activates accessibility (for output formats that support it).
  619. *
  620. * @param accessibility <code>true</code> to enable accessibility support
  621. */
  622. public void setAccessibility(boolean accessibility) {
  623. if (accessibility) {
  624. getRendererOptions().put(Accessibility.ACCESSIBILITY, Boolean.TRUE);
  625. }
  626. }
  627. /**
  628. * Check if accessibility is enabled.
  629. * @return true if accessibility is enabled
  630. */
  631. public boolean isAccessibilityEnabled() {
  632. Boolean enabled = (Boolean)this.getRendererOptions().get(Accessibility.ACCESSIBILITY);
  633. if (enabled != null) {
  634. return enabled;
  635. } else {
  636. return false;
  637. }
  638. }
  639. /**
  640. * Sets the document's structure tree event handler, for use by accessible
  641. * output formats.
  642. *
  643. * @param structureTreeEventHandler The structure tree event handler to set
  644. */
  645. public void setStructureTreeEventHandler(StructureTreeEventHandler structureTreeEventHandler) {
  646. this.structureTreeEventHandler = structureTreeEventHandler;
  647. }
  648. /**
  649. * Returns the document's structure tree event handler, for use by
  650. * accessible output formats.
  651. *
  652. * @return The structure tree event handler
  653. */
  654. public StructureTreeEventHandler getStructureTreeEventHandler() {
  655. return this.structureTreeEventHandler;
  656. }
  657. /** @see FopFactory#getLayoutManagerMakerOverride() */
  658. public LayoutManagerMaker getLayoutManagerMakerOverride() {
  659. return factory.getLayoutManagerMakerOverride();
  660. }
  661. /** @see FopFactory#getContentHandlerFactoryRegistry() */
  662. public ContentHandlerFactoryRegistry getContentHandlerFactoryRegistry() {
  663. return factory.getContentHandlerFactoryRegistry();
  664. }
  665. /** @see FopFactory#getImageManager() */
  666. public ImageManager getImageManager() {
  667. return factory.getImageManager();
  668. }
  669. /** @see FopFactory#getElementMappingRegistry() */
  670. public ElementMappingRegistry getElementMappingRegistry() {
  671. return factory.getElementMappingRegistry();
  672. }
  673. /** @see FopFactory#getFontManager() */
  674. public FontManager getFontManager() {
  675. return factory.getFontManager();
  676. }
  677. /**
  678. * Indicates whether a namespace URI is on the ignored list.
  679. * @param namespaceURI the namespace URI
  680. * @return true if the namespace is ignored by FOP
  681. */
  682. public boolean isNamespaceIgnored(String namespaceURI) {
  683. return factory.isNamespaceIgnored(namespaceURI);
  684. }
  685. /**
  686. * Is the user configuration to be validated?
  687. * @return if the user configuration should be validated
  688. */
  689. public boolean validateUserConfigStrictly() {
  690. return factory.validateUserConfigStrictly();
  691. }
  692. /**
  693. * Get the user configuration.
  694. * @return the user configuration
  695. */
  696. public Configuration getUserConfig() {
  697. return factory.getUserConfig();
  698. }
  699. /** @return the image handler registry */
  700. public ImageHandlerRegistry getImageHandlerRegistry() {
  701. return factory.getImageHandlerRegistry();
  702. }
  703. /** @return the color space cache */
  704. public ColorSpaceCache getColorSpaceCache() {
  705. return factory.getColorSpaceCache();
  706. }
  707. /** @see FopFactory#getHyphenationPatternNames() */
  708. public Map<String, String> getHyphenationPatternNames() {
  709. return factory.getHyphenationPatternNames();
  710. }
  711. public InternalResourceResolver getHyphenationResourceResolver() {
  712. return factory.getHyphenationResourceResolver();
  713. }
  714. public SoftMapCache getPDFObjectCache() {
  715. return pdfObjectCache;
  716. }
  717. public HyphenationTreeCache getHyphenationTreeCache() {
  718. return factory.getHyphenationTreeCache();
  719. }
  720. public void setKeepEmptyTags(boolean b) {
  721. getRendererOptions().put(Accessibility.KEEP_EMPTY_TAGS, b);
  722. }
  723. public boolean isKeepEmptyTags() {
  724. Boolean enabled = (Boolean)getRendererOptions().get(Accessibility.KEEP_EMPTY_TAGS);
  725. if (enabled != null) {
  726. return enabled;
  727. } else {
  728. return true;
  729. }
  730. }
  731. }