您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FopFactory.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  2. * Copyright 2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.apps;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.net.MalformedURLException;
  22. import java.util.Collection;
  23. import java.util.Collections;
  24. import java.util.Set;
  25. import javax.xml.transform.Source;
  26. import javax.xml.transform.TransformerException;
  27. import javax.xml.transform.URIResolver;
  28. import org.xml.sax.SAXException;
  29. import org.apache.avalon.framework.configuration.Configuration;
  30. import org.apache.avalon.framework.configuration.ConfigurationException;
  31. import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  32. import org.apache.commons.logging.Log;
  33. import org.apache.commons.logging.LogFactory;
  34. import org.apache.fop.fo.ElementMapping;
  35. import org.apache.fop.fo.ElementMappingRegistry;
  36. import org.apache.fop.hyphenation.HyphenationTreeResolver;
  37. import org.apache.fop.image.ImageFactory;
  38. import org.apache.fop.layoutmgr.LayoutManagerMaker;
  39. import org.apache.fop.render.RendererFactory;
  40. import org.apache.fop.render.XMLHandlerRegistry;
  41. import org.apache.fop.util.ContentHandlerFactoryRegistry;
  42. /**
  43. * Factory class which instantiates new Fop and FOUserAgent instances. This class also holds
  44. * environmental information and configuration used by FOP. Information that may potentially be
  45. * different for each rendering run can be found and managed in the FOUserAgent.
  46. */
  47. public class FopFactory {
  48. /** Defines the default source resolution (72dpi) for FOP */
  49. private static final float DEFAULT_SOURCE_RESOLUTION = 72.0f; //dpi
  50. /** Defines the default page-height */
  51. private static final String DEFAULT_PAGE_HEIGHT = "11in";
  52. /** Defines the default page-width */
  53. private static final String DEFAULT_PAGE_WIDTH = "8.26in";
  54. /** logger instance */
  55. private static Log log = LogFactory.getLog(FopFactory.class);
  56. /** Factory for Renderers and FOEventHandlers */
  57. private RendererFactory rendererFactory = new RendererFactory();
  58. /** Registry for XML handlers */
  59. private XMLHandlerRegistry xmlHandlers = new XMLHandlerRegistry();
  60. /** The registry for ElementMapping instances */
  61. private ElementMappingRegistry elementMappingRegistry;
  62. /** The registry for ContentHandlerFactory instance */
  63. private ContentHandlerFactoryRegistry contentHandlerFactoryRegistry
  64. = new ContentHandlerFactoryRegistry();
  65. /** Our default resolver if none is set */
  66. private URIResolver foURIResolver = new FOURIResolver();
  67. /** A user settable URI Resolver */
  68. private URIResolver uriResolver = null;
  69. /** The resolver for user-supplied hyphenation patterns */
  70. private HyphenationTreeResolver hyphResolver;
  71. private ImageFactory imageFactory = new ImageFactory();
  72. /** user configuration */
  73. private Configuration userConfig = null;
  74. /** The base URL for all font URL resolutions */
  75. private String fontBaseURL;
  76. /**
  77. * FOP has the ability, for some FO's, to continue processing even if the
  78. * input XSL violates that FO's content model. This is the default
  79. * behavior for FOP. However, this flag, if set, provides the user the
  80. * ability for FOP to halt on all content model violations if desired.
  81. */
  82. private boolean strictValidation = true;
  83. /** Allows enabling kerning on the base 14 fonts, default is false */
  84. private boolean enableBase14Kerning = false;
  85. /** Source resolution in dpi */
  86. private float sourceResolution = DEFAULT_SOURCE_RESOLUTION;
  87. private String pageHeight = DEFAULT_PAGE_HEIGHT;
  88. private String pageWidth = DEFAULT_PAGE_WIDTH;
  89. /** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
  90. private boolean breakIndentInheritanceOnReferenceAreaBoundary = false;
  91. /** Optional overriding LayoutManagerMaker */
  92. private LayoutManagerMaker lmMakerOverride = null;
  93. private Set ignoredNamespaces = new java.util.HashSet();
  94. /**
  95. * Main constructor.
  96. */
  97. protected FopFactory() {
  98. this.elementMappingRegistry = new ElementMappingRegistry(this);
  99. }
  100. /**
  101. * Returns a new FopFactory instance.
  102. * @return the requested FopFactory instance.
  103. */
  104. public static FopFactory newInstance() {
  105. return new FopFactory();
  106. }
  107. /**
  108. * Returns a new FOUserAgent instance. Use the FOUserAgent to configure special values that
  109. * are particular to a rendering run. Don't reuse instances over multiple rendering runs but
  110. * instead create a new one each time and reuse the FopFactory.
  111. * @return the newly created FOUserAgent instance initialized with default values
  112. */
  113. public FOUserAgent newFOUserAgent() {
  114. FOUserAgent userAgent = new FOUserAgent(this);
  115. return userAgent;
  116. }
  117. /**
  118. * Returns a new {@link Fop} instance. FOP will be configured with a default user agent
  119. * instance.
  120. * <p>
  121. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  122. * use the constants defined in {@link MimeConstants}.
  123. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  124. * @return the new Fop instance
  125. * @throws FOPException when the constructor fails
  126. */
  127. public Fop newFop(String outputFormat) throws FOPException {
  128. return new Fop(outputFormat, newFOUserAgent());
  129. }
  130. /**
  131. * Returns a new {@link Fop} instance. Use this factory method if you want to configure this
  132. * very rendering run, i.e. if you want to set some metadata like the title and author of the
  133. * document you want to render. In that case, create a new {@link FOUserAgent}
  134. * instance using {@link #newFOUserAgent()}.
  135. * <p>
  136. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  137. * use the constants defined in {@link MimeConstants}.
  138. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  139. * @param userAgent the user agent that will be used to control the rendering run
  140. * @return the new Fop instance
  141. * @throws FOPException when the constructor fails
  142. */
  143. public Fop newFop(String outputFormat, FOUserAgent userAgent) throws FOPException {
  144. if (userAgent == null) {
  145. throw new NullPointerException("The userAgent parameter must not be null!");
  146. }
  147. return new Fop(outputFormat, userAgent);
  148. }
  149. /**
  150. * Returns a new {@link Fop} instance. FOP will be configured with a default user agent
  151. * instance. Use this factory method if your output type requires an output stream.
  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, newFOUserAgent(), stream);
  162. }
  163. /**
  164. * Returns a new {@link Fop} instance. Use this factory method if your output type
  165. * requires an output stream and you want to configure this very rendering run,
  166. * i.e. if you want to set some metadata like the title and author of the document
  167. * you want to render. In that case, create a new {@link FOUserAgent} instance
  168. * using {@link #newFOUserAgent()}.
  169. * <p>
  170. * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
  171. * use the constants defined in {@link MimeConstants}.
  172. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
  173. * @param userAgent the user agent that will be used to control the rendering run
  174. * @param stream the output stream
  175. * @return the new Fop instance
  176. * @throws FOPException when the constructor fails
  177. */
  178. public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream)
  179. throws FOPException {
  180. if (userAgent == null) {
  181. throw new NullPointerException("The userAgent parameter must not be null!");
  182. }
  183. return new Fop(outputFormat, userAgent, stream);
  184. }
  185. /**
  186. * Returns a new {@link Fop} instance. Use this factory method if you want to supply your
  187. * own {@link org.apache.fop.render.Renderer Renderer} or
  188. * {@link org.apache.fop.fo.FOEventHandler FOEventHandler}
  189. * instance instead of the default ones created internally by FOP.
  190. * @param userAgent the user agent that will be used to control the rendering run
  191. * @return the new Fop instance
  192. * @throws FOPException when the constructor fails
  193. */
  194. public Fop newFop(FOUserAgent userAgent) throws FOPException {
  195. if (userAgent.getRendererOverride() == null
  196. && userAgent.getFOEventHandlerOverride() == null) {
  197. throw new IllegalStateException("Either the overriding renderer or the overriding"
  198. + " FOEventHandler must be set when this factory method is used!");
  199. }
  200. return newFop(null, userAgent);
  201. }
  202. /** @return the RendererFactory */
  203. public RendererFactory getRendererFactory() {
  204. return this.rendererFactory;
  205. }
  206. /** @return the XML handler registry */
  207. public XMLHandlerRegistry getXMLHandlerRegistry() {
  208. return this.xmlHandlers;
  209. }
  210. /** @return the element mapping registry */
  211. public ElementMappingRegistry getElementMappingRegistry() {
  212. return this.elementMappingRegistry;
  213. }
  214. /** @return the content handler factory registry */
  215. public ContentHandlerFactoryRegistry getContentHandlerFactoryRegistry() {
  216. return this.contentHandlerFactoryRegistry;
  217. }
  218. /** @return the image factory */
  219. public ImageFactory getImageFactory() {
  220. return this.imageFactory;
  221. }
  222. /**
  223. * Add the element mapping with the given class name.
  224. * @param elementMapping the class name representing the element mapping.
  225. */
  226. public void addElementMapping(ElementMapping elementMapping) {
  227. this.elementMappingRegistry.addElementMapping(elementMapping);
  228. }
  229. /**
  230. * Sets an explicit LayoutManagerMaker instance which overrides the one
  231. * defined by the AreaTreeHandler.
  232. * @param lmMaker the LayoutManagerMaker instance
  233. */
  234. public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker) {
  235. this.lmMakerOverride = lmMaker;
  236. }
  237. /**
  238. * Returns the overriding LayoutManagerMaker instance, if any.
  239. * @return the overriding LayoutManagerMaker or null
  240. */
  241. public LayoutManagerMaker getLayoutManagerMakerOverride() {
  242. return this.lmMakerOverride;
  243. }
  244. /**
  245. * Sets the font base URL.
  246. * @param fontBaseURL font base URL
  247. */
  248. public void setFontBaseURL(String fontBaseURL) {
  249. this.fontBaseURL = fontBaseURL;
  250. }
  251. /** @return the font base URL */
  252. public String getFontBaseURL() {
  253. return this.fontBaseURL;
  254. }
  255. /**
  256. * Sets the URI Resolver. It is used for resolving factory-level URIs like hyphenation
  257. * patterns and as backup for URI resolution performed during a rendering run.
  258. * @param resolver the new URI resolver
  259. */
  260. public void setURIResolver(URIResolver resolver) {
  261. this.uriResolver = resolver;
  262. }
  263. /**
  264. * Returns the URI Resolver.
  265. * @return the URI Resolver
  266. */
  267. public URIResolver getURIResolver() {
  268. return this.uriResolver;
  269. }
  270. /** @return the HyphenationTreeResolver for resolving user-supplied hyphenation patterns. */
  271. public HyphenationTreeResolver getHyphenationTreeResolver() {
  272. return this.hyphResolver;
  273. }
  274. /**
  275. * Activates strict XSL content model validation for FOP
  276. * Default is false (FOP will continue processing where it can)
  277. * @param validateStrictly true to turn on strict validation
  278. */
  279. public void setStrictValidation(boolean validateStrictly) {
  280. this.strictValidation = validateStrictly;
  281. }
  282. /**
  283. * Returns whether FOP is strictly validating input XSL
  284. * @return true of strict validation turned on, false otherwise
  285. */
  286. public boolean validateStrictly() {
  287. return strictValidation;
  288. }
  289. /**
  290. * @return true if the indent inheritance should be broken when crossing reference area
  291. * boundaries (for more info, see the javadoc for the relative member variable)
  292. */
  293. public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
  294. return breakIndentInheritanceOnReferenceAreaBoundary;
  295. }
  296. /**
  297. * Controls whether to enable a feature that breaks indent inheritance when crossing
  298. * reference area boundaries.
  299. * <p>
  300. * This flag controls whether FOP will enable special code that breaks property
  301. * inheritance for start-indent and end-indent when the evaluation of the inherited
  302. * value would cross a reference area. This is described under
  303. * http://wiki.apache.org/xmlgraphics-fop/IndentInheritance as is intended to
  304. * improve interoperability with commercial FO implementations and to produce
  305. * results that are more in line with the expectation of unexperienced FO users.
  306. * Note: Enabling this features violates the XSL specification!
  307. * @param value true to enable the feature
  308. */
  309. public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) {
  310. this.breakIndentInheritanceOnReferenceAreaBoundary = value;
  311. }
  312. /** @return true if kerning on base 14 fonts is enabled */
  313. public boolean isBase14KerningEnabled() {
  314. return this.enableBase14Kerning;
  315. }
  316. /**
  317. * Controls whether kerning is activated on base 14 fonts.
  318. * @param value true if kerning should be activated
  319. */
  320. public void setBase14KerningEnabled(boolean value) {
  321. this.enableBase14Kerning = value;
  322. }
  323. /** @return the resolution for resolution-dependant input */
  324. public float getSourceResolution() {
  325. return this.sourceResolution;
  326. }
  327. /**
  328. * Returns the conversion factor from pixel units to millimeters. This
  329. * depends on the desired source resolution.
  330. * @return float conversion factor
  331. * @see #getSourceResolution()
  332. */
  333. public float getSourcePixelUnitToMillimeter() {
  334. return 25.4f / getSourceResolution();
  335. }
  336. /**
  337. * Sets the source resolution in dpi. This value is used to interpret the pixel size
  338. * of source documents like SVG images and bitmap images without resolution information.
  339. * @param dpi resolution in dpi
  340. */
  341. public void setSourceResolution(int dpi) {
  342. this.sourceResolution = dpi;
  343. }
  344. /**
  345. * Gets the default page-height to use as fallback,
  346. * in case page-height="auto"
  347. *
  348. * @return the page-height, as a String
  349. */
  350. public String getPageHeight() {
  351. return this.pageHeight;
  352. }
  353. /**
  354. * Sets the page-height to use as fallback, in case
  355. * page-height="auto"
  356. *
  357. * @param pageHeight page-height as a String
  358. */
  359. public void setPageHeight(String pageHeight) {
  360. this.pageHeight = pageHeight;
  361. }
  362. /**
  363. * Gets the default page-width to use as fallback,
  364. * in case page-width="auto"
  365. *
  366. * @return the page-width, as a String
  367. */
  368. public String getPageWidth() {
  369. return this.pageWidth;
  370. }
  371. /**
  372. * Sets the page-width to use as fallback, in case
  373. * page-width="auto"
  374. *
  375. * @param pageWidth page-width as a String
  376. */
  377. public void setPageWidth(String pageWidth) {
  378. this.pageWidth = pageWidth;
  379. }
  380. /**
  381. * Adds a namespace to the set of ignored namespaces.
  382. * If FOP encounters a namespace which it cannot handle, it issues a warning except if this
  383. * namespace is in the ignored set.
  384. * @param namespaceURI the namespace URI
  385. */
  386. public void ignoreNamespace(String namespaceURI) {
  387. this.ignoredNamespaces.add(namespaceURI);
  388. }
  389. /**
  390. * Adds a collection of namespaces to the set of ignored namespaces.
  391. * If FOP encounters a namespace which it cannot handle, it issues a warning except if this
  392. * namespace is in the ignored set.
  393. * @param namespaceURIs the namespace URIs
  394. */
  395. public void ignoreNamespaces(Collection namespaceURIs) {
  396. this.ignoredNamespaces.addAll(namespaceURIs);
  397. }
  398. /**
  399. * Indicates whether a namespace URI is on the ignored list.
  400. * @param namespaceURI the namespace URI
  401. * @return true if the namespace is ignored by FOP
  402. */
  403. public boolean isNamespaceIgnored(String namespaceURI) {
  404. return this.ignoredNamespaces.contains(namespaceURI);
  405. }
  406. /** @return the set of namespaces that are ignored by FOP */
  407. public Set getIgnoredNamespace() {
  408. return Collections.unmodifiableSet(this.ignoredNamespaces);
  409. }
  410. //------------------------------------------- Configuration stuff
  411. /**
  412. * Set the user configuration.
  413. * @param userConfigFile the configuration file
  414. * @throws IOException if an I/O error occurs
  415. * @throws SAXException if a parsing error occurs
  416. */
  417. public void setUserConfig(File userConfigFile)
  418. throws SAXException, IOException {
  419. try {
  420. DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
  421. setUserConfig(cfgBuilder.buildFromFile(userConfigFile));
  422. } catch (ConfigurationException cfge) {
  423. log.error("Error loading configuration: "
  424. + cfge.getMessage());
  425. }
  426. }
  427. /**
  428. * Set the user configuration from an URI.
  429. * @param uri the URI to the configuration file
  430. * @throws IOException if an I/O error occurs
  431. * @throws SAXException if a parsing error occurs
  432. */
  433. public void setUserConfig(String uri)
  434. throws SAXException, IOException {
  435. try {
  436. DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
  437. setUserConfig(cfgBuilder.build(uri));
  438. } catch (ConfigurationException cfge) {
  439. log.error("Error loading configuration: "
  440. + cfge.getMessage());
  441. }
  442. }
  443. /**
  444. * Set the user configuration.
  445. * @param userConfig configuration
  446. */
  447. public void setUserConfig(Configuration userConfig) {
  448. this.userConfig = userConfig;
  449. try {
  450. initUserConfig();
  451. } catch (ConfigurationException cfge) {
  452. log.error("Error initializing factory configuration: "
  453. + cfge.getMessage());
  454. }
  455. }
  456. /**
  457. * Get the user configuration.
  458. * @return the user configuration
  459. */
  460. public Configuration getUserConfig() {
  461. return userConfig;
  462. }
  463. /**
  464. * Initializes user agent settings from the user configuration
  465. * file, if present: baseURL, resolution, default page size,...
  466. *
  467. * @throws ConfigurationException when there is an entry that
  468. * misses the required attribute
  469. */
  470. public void initUserConfig() throws ConfigurationException {
  471. log.debug("Initializing User Agent Configuration");
  472. setFontBaseURL(getBaseURLfromConfig(userConfig, "font-base"));
  473. final String hyphBase = getBaseURLfromConfig(userConfig, "hyphenation-base");
  474. if (hyphBase != null) {
  475. this.hyphResolver = new HyphenationTreeResolver() {
  476. public Source resolve(String href) {
  477. return resolveURI(href, hyphBase);
  478. }
  479. };
  480. }
  481. if (userConfig.getChild("source-resolution", false) != null) {
  482. this.sourceResolution
  483. = userConfig.getChild("source-resolution").getValueAsFloat(
  484. DEFAULT_SOURCE_RESOLUTION);
  485. log.info("Source resolution set to: " + sourceResolution
  486. + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
  487. }
  488. if (userConfig.getChild("strict-validation", false) != null) {
  489. this.strictValidation = userConfig.getChild("strict-validation").getValueAsBoolean();
  490. }
  491. if (userConfig.getChild("break-indent-inheritance", false) != null) {
  492. this.breakIndentInheritanceOnReferenceAreaBoundary
  493. = userConfig.getChild("break-indent-inheritance").getValueAsBoolean();
  494. }
  495. Configuration pageConfig = userConfig.getChild("default-page-settings");
  496. if (pageConfig.getAttribute("height", null) != null) {
  497. setPageHeight(pageConfig.getAttribute("height"));
  498. log.info("Default page-height set to: " + pageHeight);
  499. }
  500. if (pageConfig.getAttribute("width", null) != null) {
  501. setPageWidth(pageConfig.getAttribute("width"));
  502. log.info("Default page-width set to: " + pageWidth);
  503. }
  504. }
  505. /**
  506. * Retrieves and verifies a base URL.
  507. * @param cfg The Configuration object to retrieve the base URL from
  508. * @param name the element name for the base URL
  509. * @return the requested base URL or null if not available
  510. */
  511. public static String getBaseURLfromConfig(Configuration cfg, String name) {
  512. if (cfg.getChild(name, false) != null) {
  513. try {
  514. String cfgBaseDir = cfg.getChild(name).getValue(null);
  515. if (cfgBaseDir != null) {
  516. File dir = new File(cfgBaseDir);
  517. if (dir.isDirectory()) {
  518. cfgBaseDir = dir.toURL().toExternalForm();
  519. }
  520. }
  521. log.info(name + " set to: " + cfgBaseDir);
  522. return cfgBaseDir;
  523. } catch (MalformedURLException mue) {
  524. log.error("Base URL in user config is malformed!");
  525. }
  526. }
  527. return null;
  528. }
  529. //------------------------------------------- URI resolution
  530. /**
  531. * Attempts to resolve the given URI.
  532. * Will use the configured resolver and if not successful fall back
  533. * to the default resolver.
  534. * @param uri URI to access
  535. * @param base the base URI to resolve against
  536. * @return A {@link javax.xml.transform.Source} object, or null if the URI
  537. * cannot be resolved.
  538. * @see org.apache.fop.apps.FOURIResolver
  539. */
  540. public Source resolveURI(String uri, String base) {
  541. Source source = null;
  542. //RFC 2397 data URLs don't need to be resolved, just decode them.
  543. boolean bypassURIResolution = uri.startsWith("data:");
  544. if (!bypassURIResolution && uriResolver != null) {
  545. try {
  546. source = uriResolver.resolve(uri, base);
  547. } catch (TransformerException te) {
  548. log.error("Attempt to resolve URI '" + uri + "' failed: ", te);
  549. }
  550. }
  551. if (source == null) {
  552. // URI Resolver not configured or returned null, use default resolver
  553. try {
  554. source = foURIResolver.resolve(uri, base);
  555. } catch (TransformerException te) {
  556. log.error("Attempt to resolve URI '" + uri + "' failed: ", te);
  557. }
  558. }
  559. return source;
  560. }
  561. }