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 28KB

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