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

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