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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. && userAgent.getDocumentHandlerOverride() == null) {
  227. throw new IllegalStateException("An overriding renderer,"
  228. + " FOEventHandler or IFDocumentHandler must be set on the user agent"
  229. + " when this factory method is used!");
  230. }
  231. return newFop(null, userAgent);
  232. }
  233. /** @return the RendererFactory */
  234. public RendererFactory getRendererFactory() {
  235. return this.rendererFactory;
  236. }
  237. /** @return the XML handler registry */
  238. public XMLHandlerRegistry getXMLHandlerRegistry() {
  239. return this.xmlHandlers;
  240. }
  241. /** @return the image handler registry */
  242. public ImageHandlerRegistry getImageHandlerRegistry() {
  243. return this.imageHandlers;
  244. }
  245. /** @return the element mapping registry */
  246. public ElementMappingRegistry getElementMappingRegistry() {
  247. return this.elementMappingRegistry;
  248. }
  249. /** @return the content handler factory registry */
  250. public ContentHandlerFactoryRegistry getContentHandlerFactoryRegistry() {
  251. return this.contentHandlerFactoryRegistry;
  252. }
  253. /**
  254. * Returns the image manager.
  255. * @return the image manager
  256. */
  257. public ImageManager getImageManager() {
  258. return this.imageManager;
  259. }
  260. /**
  261. * Add the element mapping with the given class name.
  262. * @param elementMapping the class name representing the element mapping.
  263. */
  264. public void addElementMapping(ElementMapping elementMapping) {
  265. this.elementMappingRegistry.addElementMapping(elementMapping);
  266. }
  267. /**
  268. * Sets an explicit LayoutManagerMaker instance which overrides the one
  269. * defined by the AreaTreeHandler.
  270. * @param lmMaker the LayoutManagerMaker instance
  271. */
  272. public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker) {
  273. this.lmMakerOverride = lmMaker;
  274. }
  275. /**
  276. * Returns the overriding LayoutManagerMaker instance, if any.
  277. * @return the overriding LayoutManagerMaker or null
  278. */
  279. public LayoutManagerMaker getLayoutManagerMakerOverride() {
  280. return this.lmMakerOverride;
  281. }
  282. /**
  283. * Sets the base URL.
  284. * @param base the base URL
  285. * @throws MalformedURLException if there's a problem with a file URL
  286. */
  287. public void setBaseURL(String base) throws MalformedURLException {
  288. this.base = foURIResolver.checkBaseURL(base);
  289. }
  290. /**
  291. * Returns the base URL.
  292. * @return the base URL
  293. */
  294. public String getBaseURL() {
  295. return this.base;
  296. }
  297. /**
  298. * Sets the font base URL.
  299. * @param fontBase font base URL
  300. * @throws MalformedURLException if there's a problem with a file URL
  301. * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
  302. */
  303. public void setFontBaseURL(String fontBase) throws MalformedURLException {
  304. getFontManager().setFontBaseURL(fontBase);
  305. }
  306. /**
  307. * @return the font base URL
  308. * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
  309. */
  310. public String getFontBaseURL() {
  311. return getFontManager().getFontBaseURL();
  312. }
  313. /** @return the hyphen base URL */
  314. public String getHyphenBaseURL() {
  315. return this.hyphenBase;
  316. }
  317. /**
  318. * Sets the hyphen base URL.
  319. * @param hyphenBase hythen base URL
  320. * @throws MalformedURLException if there's a problem with a file URL
  321. * */
  322. public void setHyphenBaseURL(final String hyphenBase) throws MalformedURLException {
  323. if (hyphenBase != null) {
  324. setHyphenationTreeResolver(
  325. new HyphenationTreeResolver() {
  326. public Source resolve(String href) {
  327. return resolveURI(href, hyphenBase);
  328. }
  329. });
  330. }
  331. this.hyphenBase = foURIResolver.checkBaseURL(hyphenBase);
  332. }
  333. /**
  334. * Sets the URI Resolver. It is used for resolving factory-level URIs like hyphenation
  335. * patterns and as backup for URI resolution performed during a rendering run.
  336. * @param uriResolver the new URI resolver
  337. */
  338. public void setURIResolver(URIResolver uriResolver) {
  339. foURIResolver.setCustomURIResolver(uriResolver);
  340. }
  341. /**
  342. * Returns the URI Resolver.
  343. * @return the URI Resolver
  344. */
  345. public URIResolver getURIResolver() {
  346. return foURIResolver;
  347. }
  348. /**
  349. * Returns the FO URI Resolver.
  350. * @return the FO URI Resolver
  351. */
  352. public FOURIResolver getFOURIResolver() {
  353. return foURIResolver;
  354. }
  355. /** @return the HyphenationTreeResolver for resolving user-supplied hyphenation patterns. */
  356. public HyphenationTreeResolver getHyphenationTreeResolver() {
  357. return this.hyphResolver;
  358. }
  359. /**
  360. * Sets the HyphenationTreeResolver to be used for resolving user-supplied hyphenation files.
  361. * @param hyphResolver the HyphenationTreeResolver instance
  362. */
  363. public void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver) {
  364. this.hyphResolver = hyphResolver;
  365. }
  366. /**
  367. * Activates strict XSL content model validation for FOP
  368. * Default is false (FOP will continue processing where it can)
  369. * @param validateStrictly true to turn on strict validation
  370. */
  371. public void setStrictValidation(boolean validateStrictly) {
  372. this.strictFOValidation = validateStrictly;
  373. }
  374. /**
  375. * Returns whether FOP is strictly validating input XSL
  376. * @return true of strict validation turned on, false otherwise
  377. */
  378. public boolean validateStrictly() {
  379. return strictFOValidation;
  380. }
  381. /**
  382. * @return true if the indent inheritance should be broken when crossing reference area
  383. * boundaries (for more info, see the javadoc for the relative member variable)
  384. */
  385. public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
  386. return breakIndentInheritanceOnReferenceAreaBoundary;
  387. }
  388. /**
  389. * Controls whether to enable a feature that breaks indent inheritance when crossing
  390. * reference area boundaries.
  391. * <p>
  392. * This flag controls whether FOP will enable special code that breaks property
  393. * inheritance for start-indent and end-indent when the evaluation of the inherited
  394. * value would cross a reference area. This is described under
  395. * http://wiki.apache.org/xmlgraphics-fop/IndentInheritance as is intended to
  396. * improve interoperability with commercial FO implementations and to produce
  397. * results that are more in line with the expectation of unexperienced FO users.
  398. * Note: Enabling this features violates the XSL specification!
  399. * @param value true to enable the feature
  400. */
  401. public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) {
  402. this.breakIndentInheritanceOnReferenceAreaBoundary = value;
  403. }
  404. /**
  405. * @return true if kerning on base 14 fonts is enabled
  406. * @deprecated use getFontManager().isBase14KerningEnabled() instead
  407. */
  408. public boolean isBase14KerningEnabled() {
  409. return getFontManager().isBase14KerningEnabled();
  410. }
  411. /**
  412. * Controls whether kerning is activated on base 14 fonts.
  413. * @param value true if kerning should be activated
  414. * @deprecated use getFontManager().setBase14KerningEnabled(boolean) instead
  415. */
  416. public void setBase14KerningEnabled(boolean value) {
  417. getFontManager().setBase14KerningEnabled(value);
  418. }
  419. /** @return the resolution for resolution-dependant input */
  420. public float getSourceResolution() {
  421. return this.sourceResolution;
  422. }
  423. /**
  424. * Returns the conversion factor from pixel units to millimeters. This
  425. * depends on the desired source resolution.
  426. * @return float conversion factor
  427. * @see #getSourceResolution()
  428. */
  429. public float getSourcePixelUnitToMillimeter() {
  430. return 25.4f / getSourceResolution();
  431. }
  432. /**
  433. * Sets the source resolution in dpi. This value is used to interpret the pixel size
  434. * of source documents like SVG images and bitmap images without resolution information.
  435. * @param dpi resolution in dpi
  436. */
  437. public void setSourceResolution(float dpi) {
  438. this.sourceResolution = dpi;
  439. if (log.isDebugEnabled()) {
  440. log.debug("source-resolution set to: " + sourceResolution
  441. + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
  442. }
  443. }
  444. /** @return the resolution for resolution-dependant output */
  445. public float getTargetResolution() {
  446. return this.targetResolution;
  447. }
  448. /**
  449. * Returns the conversion factor from pixel units to millimeters. This
  450. * depends on the desired target resolution.
  451. * @return float conversion factor
  452. * @see #getTargetResolution()
  453. */
  454. public float getTargetPixelUnitToMillimeter() {
  455. return 25.4f / this.targetResolution;
  456. }
  457. /**
  458. * Sets the source resolution in dpi. This value is used to interpret the pixel size
  459. * of source documents like SVG images and bitmap images without resolution information.
  460. * @param dpi resolution in dpi
  461. */
  462. public void setTargetResolution(float dpi) {
  463. this.targetResolution = dpi;
  464. }
  465. /**
  466. * Sets the source resolution in dpi. This value is used to interpret the pixel size
  467. * of source documents like SVG images and bitmap images without resolution information.
  468. * @param dpi resolution in dpi
  469. */
  470. public void setSourceResolution(int dpi) {
  471. setSourceResolution((float)dpi);
  472. }
  473. /**
  474. * Gets the default page-height to use as fallback,
  475. * in case page-height="auto"
  476. *
  477. * @return the page-height, as a String
  478. */
  479. public String getPageHeight() {
  480. return this.pageHeight;
  481. }
  482. /**
  483. * Sets the page-height to use as fallback, in case
  484. * page-height="auto"
  485. *
  486. * @param pageHeight page-height as a String
  487. */
  488. public void setPageHeight(String pageHeight) {
  489. this.pageHeight = pageHeight;
  490. if (log.isDebugEnabled()) {
  491. log.debug("Default page-height set to: " + pageHeight);
  492. }
  493. }
  494. /**
  495. * Gets the default page-width to use as fallback,
  496. * in case page-width="auto"
  497. *
  498. * @return the page-width, as a String
  499. */
  500. public String getPageWidth() {
  501. return this.pageWidth;
  502. }
  503. /**
  504. * Sets the page-width to use as fallback, in case
  505. * page-width="auto"
  506. *
  507. * @param pageWidth page-width as a String
  508. */
  509. public void setPageWidth(String pageWidth) {
  510. this.pageWidth = pageWidth;
  511. if (log.isDebugEnabled()) {
  512. log.debug("Default page-width set to: " + pageWidth);
  513. }
  514. }
  515. /**
  516. * Adds a namespace to the set of ignored namespaces.
  517. * If FOP encounters a namespace which it cannot handle, it issues a warning except if this
  518. * namespace is in the ignored set.
  519. * @param namespaceURI the namespace URI
  520. */
  521. public void ignoreNamespace(String namespaceURI) {
  522. this.ignoredNamespaces.add(namespaceURI);
  523. }
  524. /**
  525. * Adds a collection of namespaces to the set of ignored namespaces.
  526. * If FOP encounters a namespace which it cannot handle, it issues a warning except if this
  527. * namespace is in the ignored set.
  528. * @param namespaceURIs the namespace URIs
  529. */
  530. public void ignoreNamespaces(Collection namespaceURIs) {
  531. this.ignoredNamespaces.addAll(namespaceURIs);
  532. }
  533. /**
  534. * Indicates whether a namespace URI is on the ignored list.
  535. * @param namespaceURI the namespace URI
  536. * @return true if the namespace is ignored by FOP
  537. */
  538. public boolean isNamespaceIgnored(String namespaceURI) {
  539. return this.ignoredNamespaces.contains(namespaceURI);
  540. }
  541. /** @return the set of namespaces that are ignored by FOP */
  542. public Set getIgnoredNamespace() {
  543. return Collections.unmodifiableSet(this.ignoredNamespaces);
  544. }
  545. //------------------------------------------- Configuration stuff
  546. /**
  547. * Set the user configuration.
  548. * @param userConfigFile the configuration file
  549. * @throws IOException if an I/O error occurs
  550. * @throws SAXException if a parsing error occurs
  551. */
  552. public void setUserConfig(File userConfigFile) throws SAXException, IOException {
  553. config.setUserConfig(userConfigFile);
  554. }
  555. /**
  556. * Set the user configuration from an URI.
  557. * @param uri the URI to the configuration file
  558. * @throws IOException if an I/O error occurs
  559. * @throws SAXException if a parsing error occurs
  560. */
  561. public void setUserConfig(String uri) throws SAXException, IOException {
  562. config.setUserConfig(uri);
  563. }
  564. /**
  565. * Set the user configuration.
  566. * @param userConfig configuration
  567. * @throws FOPException if a configuration problem occurs
  568. */
  569. public void setUserConfig(Configuration userConfig) throws FOPException {
  570. config.setUserConfig(userConfig);
  571. }
  572. /**
  573. * Get the user configuration.
  574. * @return the user configuration
  575. */
  576. public Configuration getUserConfig() {
  577. return config.getUserConfig();
  578. }
  579. /**
  580. * Is the user configuration to be validated?
  581. * @param strictUserConfigValidation strict user config validation
  582. */
  583. public void setStrictUserConfigValidation(boolean strictUserConfigValidation) {
  584. this.strictUserConfigValidation = strictUserConfigValidation;
  585. this.foURIResolver.setThrowExceptions(strictUserConfigValidation);
  586. }
  587. /**
  588. * Is the user configuration to be validated?
  589. * @return if the user configuration should be validated
  590. */
  591. public boolean validateUserConfigStrictly() {
  592. return this.strictUserConfigValidation;
  593. }
  594. //------------------------------------------- Font related stuff
  595. /**
  596. * Whether or not to cache results of font triplet detection/auto-config
  597. * @param useCache use cache or not
  598. * @deprecated use getFontManager().setUseCache(boolean) instead
  599. */
  600. public void setUseCache(boolean useCache) {
  601. getFontManager().setUseCache(useCache);
  602. }
  603. /**
  604. * Cache results of font triplet detection/auto-config?
  605. * @return whether this factory is uses the cache
  606. * @deprecated use getFontManager().useCache() instead
  607. */
  608. public boolean useCache() {
  609. return getFontManager().useCache();
  610. }
  611. /**
  612. * Returns the font cache instance used by this factory.
  613. * @return the font cache
  614. * @deprecated use getFontManager().getFontCache() instead
  615. */
  616. public FontCache getFontCache() {
  617. return getFontManager().getFontCache();
  618. }
  619. /**
  620. * Returns the font manager.
  621. * @return the font manager
  622. */
  623. public FontManager getFontManager() {
  624. return this.fontManager;
  625. }
  626. /**
  627. * Attempts to resolve the given URI.
  628. * Will use the configured resolver and if not successful fall back
  629. * to the default resolver.
  630. * @param href URI to access
  631. * @param baseUri the base URI to resolve against
  632. * @return A {@link javax.xml.transform.Source} object, or null if the URI
  633. * cannot be resolved.
  634. * @see org.apache.fop.apps.FOURIResolver
  635. */
  636. public Source resolveURI(String href, String baseUri) {
  637. Source source = null;
  638. try {
  639. source = foURIResolver.resolve(href, baseUri);
  640. } catch (TransformerException e) {
  641. log.error("Attempt to resolve URI '" + href + "' failed: ", e);
  642. }
  643. return source;
  644. }
  645. /**
  646. * Create (if needed) and return an ICC ColorSpace instance.
  647. *
  648. * The ICC profile source is taken from the src attribute of the color-profile FO element.
  649. * If the ICC ColorSpace is not yet in the cache a new one is created and stored in the cache.
  650. *
  651. * The FOP URI resolver is used to try and locate the ICC file.
  652. * If that fails null is returned.
  653. *
  654. * @param baseUri a base URI to resolve relative URIs
  655. * @param iccProfileSrc ICC Profile source to return a ColorSpace for
  656. * @return ICC ColorSpace object or null if ColorSpace could not be created
  657. */
  658. public ColorSpace getColorSpace(String baseUri, String iccProfileSrc) {
  659. return colorSpaceCache.get(baseUri, iccProfileSrc);
  660. }
  661. }