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.

AbstractRenderer.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*
  2. * Copyright 1999-2005 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.render;
  18. // Java
  19. import java.awt.geom.Rectangle2D;
  20. import java.io.IOException;
  21. import java.io.OutputStream;
  22. import java.util.List;
  23. import java.util.Iterator;
  24. import java.util.Set;
  25. // XML
  26. import org.w3c.dom.Document;
  27. // FOP
  28. import org.apache.fop.apps.FOPException;
  29. import org.apache.fop.area.Area;
  30. import org.apache.fop.area.BeforeFloat;
  31. import org.apache.fop.area.Block;
  32. import org.apache.fop.area.BlockViewport;
  33. import org.apache.fop.area.BodyRegion;
  34. import org.apache.fop.area.CTM;
  35. import org.apache.fop.area.NormalFlow;
  36. import org.apache.fop.area.Footnote;
  37. import org.apache.fop.area.LineArea;
  38. import org.apache.fop.area.MainReference;
  39. import org.apache.fop.area.Span;
  40. import org.apache.fop.area.Page;
  41. import org.apache.fop.area.PageViewport;
  42. import org.apache.fop.area.RegionViewport;
  43. import org.apache.fop.area.RegionReference;
  44. import org.apache.fop.area.Trait;
  45. import org.apache.fop.area.OffDocumentItem;
  46. import org.apache.fop.area.inline.Container;
  47. import org.apache.fop.area.inline.ForeignObject;
  48. import org.apache.fop.area.inline.Image;
  49. import org.apache.fop.area.inline.InlineArea;
  50. import org.apache.fop.area.inline.InlineParent;
  51. import org.apache.fop.area.inline.Leader;
  52. import org.apache.fop.area.inline.Space;
  53. import org.apache.fop.area.inline.Viewport;
  54. import org.apache.fop.area.inline.TextArea;
  55. import org.apache.fop.area.inline.Character;
  56. import org.apache.fop.apps.FOUserAgent;
  57. import org.apache.fop.fo.Constants;
  58. import org.apache.fop.fonts.FontInfo;
  59. import org.apache.commons.logging.Log;
  60. import org.apache.commons.logging.LogFactory;
  61. // Avalon
  62. import org.apache.avalon.framework.configuration.Configurable;
  63. import org.apache.avalon.framework.configuration.Configuration;
  64. import org.apache.avalon.framework.configuration.ConfigurationException;
  65. /**
  66. * Abstract base class for all renderers. The Abstract renderer does all the
  67. * top level processing of the area tree and adds some abstract methods to
  68. * handle viewports. This keeps track of the current block and inline position.
  69. */
  70. public abstract class AbstractRenderer
  71. implements Renderer, Configurable, Constants {
  72. /**
  73. * user agent
  74. */
  75. protected FOUserAgent userAgent;
  76. /**
  77. * logging instance
  78. */
  79. protected static Log logger = LogFactory.getLog("org.apache.fop.render");
  80. /**
  81. * block progression position
  82. */
  83. protected int currentBPPosition = 0;
  84. /**
  85. * inline progression position
  86. */
  87. protected int currentIPPosition = 0;
  88. /**
  89. * the block progression position of the containing block used for
  90. * absolutely positioned blocks
  91. */
  92. protected int containingBPPosition = 0;
  93. /**
  94. * the inline progression position of the containing block used for
  95. * absolutely positioned blocks
  96. */
  97. protected int containingIPPosition = 0;
  98. private Set warnedXMLHandlers;
  99. /**
  100. * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
  101. */
  102. public void configure(Configuration conf) throws ConfigurationException {
  103. }
  104. /**
  105. * Returns the Commons-Logging instance for this class
  106. * @return The Commons-Logging instance
  107. */
  108. protected Log getLogger() {
  109. return logger;
  110. }
  111. /**
  112. * @see org.apache.fop.render.Renderer
  113. */
  114. public abstract void setupFontInfo(FontInfo fontInfo);
  115. /**
  116. * @see org.apache.fop.render.Renderer
  117. */
  118. public void setUserAgent(FOUserAgent agent) {
  119. userAgent = agent;
  120. }
  121. /** @see org.apache.fop.render.Renderer */
  122. public void startRenderer(OutputStream outputStream)
  123. throws IOException { }
  124. /** @see org.apache.fop.render.Renderer */
  125. public void stopRenderer()
  126. throws IOException { }
  127. /**
  128. * Check if this renderer supports out of order rendering. If this renderer
  129. * supports out of order rendering then it means that the pages that are
  130. * not ready will be prepared and a future page will be rendered.
  131. *
  132. * @return True if the renderer supports out of order rendering
  133. * @see org.apache.fop.render.Renderer
  134. */
  135. public boolean supportsOutOfOrder() {
  136. return false;
  137. }
  138. /**
  139. * @see org.apache.fop.render.Renderer
  140. */
  141. public void processOffDocumentItem(OffDocumentItem oDI) { }
  142. /**
  143. * Prepare a page for rendering. This is called if the renderer supports
  144. * out of order rendering. The renderer should prepare the page so that a
  145. * page further on in the set of pages can be rendered. The body of the
  146. * page should not be rendered. The page will be rendered at a later time
  147. * by the call to render page.
  148. *
  149. * @see org.apache.fop.render.Renderer
  150. */
  151. public void preparePage(PageViewport page) { }
  152. /**
  153. * Utility method to convert a page sequence title to a string. Some
  154. * renderers may only be able to use a string title. A title is a sequence
  155. * of inline areas that this method attempts to convert to an equivalent
  156. * string.
  157. *
  158. * @param title The Title to convert
  159. * @return An expanded string representing the title
  160. */
  161. protected String convertTitleToString(LineArea title) {
  162. List children = title.getInlineAreas();
  163. String str = convertToString(children);
  164. return str.trim();
  165. }
  166. private String convertToString(List children) {
  167. StringBuffer sb = new StringBuffer();
  168. for (int count = 0; count < children.size(); count++) {
  169. InlineArea inline = (InlineArea) children.get(count);
  170. if (inline instanceof Character) {
  171. sb.append(((Character) inline).getChar());
  172. } else if (inline instanceof TextArea) {
  173. sb.append(((TextArea) inline).getTextArea());
  174. } else if (inline instanceof InlineParent) {
  175. sb.append(convertToString(
  176. ((InlineParent) inline).getChildAreas()));
  177. } else {
  178. sb.append(" ");
  179. }
  180. }
  181. return sb.toString();
  182. }
  183. /** @see org.apache.fop.render.Renderer */
  184. public void startPageSequence(LineArea seqTitle) {
  185. //do nothing
  186. }
  187. // normally this would be overriden to create a page in the
  188. // output
  189. /** @see org.apache.fop.render.Renderer */
  190. public void renderPage(PageViewport page)
  191. throws IOException, FOPException {
  192. Page p = page.getPage();
  193. renderPageAreas(p);
  194. }
  195. /**
  196. * Renders page areas.
  197. *
  198. * @param page The page whos page areas are to be rendered
  199. */
  200. protected void renderPageAreas(Page page) {
  201. /* Spec does not appear to specify whether fo:region-body should
  202. appear above or below side regions in cases of overlap. FOP
  203. decision is to have fo:region-body on top, hence it is rendered
  204. last here. */
  205. RegionViewport viewport;
  206. viewport = page.getRegionViewport(FO_REGION_BEFORE);
  207. renderRegionViewport(viewport);
  208. viewport = page.getRegionViewport(FO_REGION_START);
  209. renderRegionViewport(viewport);
  210. viewport = page.getRegionViewport(FO_REGION_END);
  211. renderRegionViewport(viewport);
  212. viewport = page.getRegionViewport(FO_REGION_AFTER);
  213. renderRegionViewport(viewport);
  214. viewport = page.getRegionViewport(FO_REGION_BODY);
  215. renderRegionViewport(viewport);
  216. }
  217. /**
  218. * Renders a region viewport. <p>
  219. *
  220. * The region may clip the area and it establishes a position from where
  221. * the region is placed.</p>
  222. *
  223. * @param port The region viewport to be rendered
  224. */
  225. protected void renderRegionViewport(RegionViewport port) {
  226. if (port != null) {
  227. Rectangle2D view = port.getViewArea();
  228. // The CTM will transform coordinates relative to
  229. // this region-reference area into page coords, so
  230. // set origin for the region to 0,0.
  231. currentBPPosition = 0;
  232. currentIPPosition = 0;
  233. RegionReference regionReference = port.getRegionReference();
  234. handleRegionTraits(port);
  235. // shouldn't the viewport have the CTM
  236. startVParea(regionReference.getCTM());
  237. // do after starting viewport area
  238. if (regionReference.getRegionClass() == FO_REGION_BODY) {
  239. renderBodyRegion((BodyRegion) regionReference);
  240. } else {
  241. renderRegion(regionReference);
  242. }
  243. endVParea();
  244. }
  245. }
  246. /**
  247. * (todo) Description of the Method
  248. *
  249. * @param ctm The coordinate transformation matrix to use
  250. */
  251. protected void startVParea(CTM ctm) { }
  252. /**
  253. * Handle the traits for a region
  254. * This is used to draw the traits for the given page region.
  255. * (See Sect. 6.4.1.2 of XSL-FO spec.)
  256. * @param rv the RegionViewport whose region is to be drawn
  257. */
  258. protected void handleRegionTraits(RegionViewport rv) {
  259. // draw border and background
  260. }
  261. /**
  262. * (todo) Description of the Method
  263. */
  264. protected void endVParea() { }
  265. /**
  266. * Renders a region reference area.
  267. *
  268. * @param region The region reference area
  269. */
  270. protected void renderRegion(RegionReference region) {
  271. List blocks = region.getBlocks();
  272. renderBlocks(null, blocks);
  273. }
  274. /**
  275. * Renders a body region area.
  276. *
  277. * @param region The body region
  278. */
  279. protected void renderBodyRegion(BodyRegion region) {
  280. BeforeFloat bf = region.getBeforeFloat();
  281. if (bf != null) {
  282. renderBeforeFloat(bf);
  283. }
  284. MainReference mr = region.getMainReference();
  285. if (mr != null) {
  286. renderMainReference(mr);
  287. }
  288. Footnote foot = region.getFootnote();
  289. if (foot != null) {
  290. renderFootnote(foot);
  291. }
  292. }
  293. /**
  294. * Renders a before float area.
  295. *
  296. * @param bf The before float area
  297. */
  298. protected void renderBeforeFloat(BeforeFloat bf) {
  299. List blocks = bf.getChildAreas();
  300. if (blocks != null) {
  301. renderBlocks(null, blocks);
  302. Block sep = bf.getSeparator();
  303. if (sep != null) {
  304. renderBlock(sep);
  305. }
  306. }
  307. }
  308. /**
  309. * Renders a footnote
  310. *
  311. * @param footnote The footnote
  312. */
  313. protected void renderFootnote(Footnote footnote) {
  314. currentBPPosition += footnote.getTop();
  315. List blocks = footnote.getChildAreas();
  316. if (blocks != null) {
  317. Block sep = footnote.getSeparator();
  318. if (sep != null) {
  319. renderBlock(sep);
  320. }
  321. renderBlocks(null, blocks);
  322. }
  323. }
  324. /**
  325. * Renders the main reference area.
  326. * <p>
  327. * The main reference area contains a list of spans that are
  328. * stacked on the page.
  329. * The spans contain a list of normal flow reference areas
  330. * that are positioned into columns.
  331. * </p>
  332. *
  333. * @param mr The main reference area
  334. */
  335. protected void renderMainReference(MainReference mr) {
  336. int saveIPPos = currentIPPosition;
  337. Span span = null;
  338. List spans = mr.getSpans();
  339. int saveBPPos = currentBPPosition;
  340. int saveSpanBPPos = saveBPPos;
  341. for (int count = 0; count < spans.size(); count++) {
  342. span = (Span) spans.get(count);
  343. int offset = (mr.getWidth()
  344. - (mr.getColumnCount() - 1) * mr.getColumnGap())
  345. / mr.getColumnCount() + mr.getColumnGap();
  346. for (int c = 0; c < span.getColumnCount(); c++) {
  347. NormalFlow flow = (NormalFlow) span.getNormalFlow(c);
  348. if (flow != null) {
  349. currentBPPosition = saveSpanBPPos;
  350. renderFlow(flow);
  351. currentIPPosition += flow.getIPD();
  352. currentIPPosition += offset;
  353. }
  354. }
  355. currentIPPosition = saveIPPos;
  356. currentBPPosition = saveSpanBPPos + span.getHeight();
  357. saveSpanBPPos = currentBPPosition;
  358. }
  359. currentBPPosition = saveBPPos;
  360. }
  361. /**
  362. * Renders a flow reference area.
  363. *
  364. * @param flow The flow reference area
  365. */
  366. protected void renderFlow(NormalFlow flow) {
  367. // the normal flow reference area contains stacked blocks
  368. List blocks = flow.getChildAreas();
  369. if (blocks != null) {
  370. renderBlocks(null, blocks);
  371. }
  372. }
  373. /**
  374. * Handle block traits.
  375. * This method is called when the correct ip and bp posiiton is
  376. * set. This should be overridden to draw border and background
  377. * traits for the block area.
  378. *
  379. * @param block the block area
  380. */
  381. protected void handleBlockTraits(Block block) {
  382. // draw border and background
  383. }
  384. /**
  385. * Renders a block viewport.
  386. *
  387. * @param bv The block viewport
  388. * @param children The children to render within the block viewport
  389. */
  390. protected void renderBlockViewport(BlockViewport bv, List children) {
  391. // clip and position viewport if necessary
  392. if (bv.getPositioning() == Block.ABSOLUTE) {
  393. // save positions
  394. int saveIP = currentIPPosition;
  395. int saveBP = currentBPPosition;
  396. CTM ctm = bv.getCTM();
  397. currentIPPosition = 0;
  398. currentBPPosition = 0;
  399. startVParea(ctm);
  400. handleBlockTraits(bv);
  401. renderBlocks(bv, children);
  402. endVParea();
  403. // clip if necessary
  404. currentIPPosition = saveIP;
  405. currentBPPosition = saveBP;
  406. } else {
  407. // save position and offset
  408. int saveIP = currentIPPosition;
  409. int saveBP = currentBPPosition;
  410. handleBlockTraits(bv);
  411. renderBlocks(bv, children);
  412. currentIPPosition = saveIP;
  413. currentBPPosition = saveBP + bv.getAllocBPD();
  414. }
  415. }
  416. /**
  417. * Renders a list of block areas.
  418. *
  419. * @param parent the parent block if the parent is a block, otherwise
  420. * a null value.
  421. * @param blocks The block areas
  422. */
  423. protected void renderBlocks(Block parent, List blocks) {
  424. int saveIP = currentIPPosition;
  425. int saveBP = currentBPPosition;
  426. // Calculate the position of the content rectangle.
  427. if (parent != null && !Boolean.TRUE.equals(parent.getTrait(Trait.IS_VIEWPORT_AREA))) {
  428. currentBPPosition += parent.getBorderAndPaddingWidthBefore();
  429. /* This is unnecessary now as we're going to use the *-indent traits
  430. currentIPPosition += parent.getBorderAndPaddingWidthStart();
  431. Integer spaceStart = (Integer) parent.getTrait(Trait.SPACE_START);
  432. if (spaceStart != null) {
  433. currentIPPosition += spaceStart.intValue();
  434. }*/
  435. }
  436. // the position of the containing block is used for
  437. // absolutely positioned areas
  438. int contBP = currentBPPosition;
  439. int contIP = currentIPPosition;
  440. containingBPPosition = currentBPPosition;
  441. containingIPPosition = currentIPPosition;
  442. for (int count = 0; count < blocks.size(); count++) {
  443. Object obj = blocks.get(count);
  444. if (obj instanceof Block) {
  445. currentIPPosition = contIP;
  446. containingBPPosition = contBP;
  447. containingIPPosition = contIP;
  448. renderBlock((Block) obj);
  449. containingBPPosition = contBP;
  450. containingIPPosition = contIP;
  451. } else {
  452. // a line area is rendered from the top left position
  453. // of the line, each inline object is offset from there
  454. LineArea line = (LineArea) obj;
  455. currentIPPosition = contIP
  456. + parent.getStartIndent()
  457. + line.getStartIndent();
  458. renderLineArea(line);
  459. currentBPPosition += line.getAllocBPD();
  460. }
  461. currentIPPosition = saveIP;
  462. }
  463. }
  464. /**
  465. * Renders a block area.
  466. *
  467. * @param block The block area
  468. */
  469. protected void renderBlock(Block block) {
  470. List children = block.getChildAreas();
  471. if (block instanceof BlockViewport) {
  472. if (children != null) {
  473. renderBlockViewport((BlockViewport) block, children);
  474. } else {
  475. handleBlockTraits(block);
  476. // simply move position
  477. currentBPPosition += block.getAllocBPD();
  478. }
  479. } else {
  480. // save position and offset
  481. int saveIP = currentIPPosition;
  482. int saveBP = currentBPPosition;
  483. if (block.getPositioning() == Block.ABSOLUTE) {
  484. currentIPPosition = containingIPPosition + block.getXOffset();
  485. currentBPPosition = containingBPPosition + block.getYOffset();
  486. handleBlockTraits(block);
  487. if (children != null) {
  488. renderBlocks(block, children);
  489. }
  490. // absolute blocks do not effect the layout
  491. currentBPPosition = saveBP;
  492. } else {
  493. // relative blocks are offset
  494. currentIPPosition += block.getXOffset();
  495. currentBPPosition += block.getYOffset();
  496. handleBlockTraits(block);
  497. if (children != null) {
  498. renderBlocks(block, children);
  499. }
  500. // stacked and relative blocks effect stacking
  501. currentIPPosition = saveIP;
  502. currentBPPosition = saveBP + block.getAllocBPD();
  503. }
  504. }
  505. }
  506. protected void renderTextDecoration(InlineArea area) {
  507. //getLogger().debug("renderTextDecoration for " + area + " -> " + area.getTrait(Trait.UNDERLINE));
  508. }
  509. /**
  510. * Renders a line area. <p>
  511. *
  512. * A line area may have grouped styling for its children such as underline,
  513. * background.</p>
  514. *
  515. * @param line The line area
  516. */
  517. protected void renderLineArea(LineArea line) {
  518. List children = line.getInlineAreas();
  519. for (int count = 0; count < children.size(); count++) {
  520. InlineArea inline = (InlineArea) children.get(count);
  521. renderInlineArea(inline);
  522. }
  523. }
  524. protected void renderInlineArea(InlineArea inlineArea) {
  525. renderTextDecoration(inlineArea);
  526. if (inlineArea instanceof TextArea) {
  527. renderText((TextArea) inlineArea);
  528. } else if (inlineArea instanceof InlineParent) {
  529. renderInlineParent((InlineParent) inlineArea);
  530. } else if (inlineArea instanceof Space) {
  531. renderInlineSpace((Space) inlineArea);
  532. } else if (inlineArea instanceof Character) {
  533. renderCharacter((Character) inlineArea);
  534. } else if (inlineArea instanceof Viewport) {
  535. renderViewport((Viewport) inlineArea);
  536. } else if (inlineArea instanceof Leader) {
  537. renderLeader((Leader) inlineArea);
  538. }
  539. }
  540. /** @see org.apache.fop.render.Renderer */
  541. protected void renderCharacter(Character ch) {
  542. currentIPPosition += ch.getAllocIPD();
  543. }
  544. /** @see org.apache.fop.render.Renderer */
  545. protected void renderInlineSpace(Space space) {
  546. // an inline space moves the inline progression position
  547. // for the current block by the width or height of the space
  548. // it may also have styling (only on this object) that needs
  549. // handling
  550. currentIPPosition += space.getAllocIPD();
  551. }
  552. /** @see org.apache.fop.render.Renderer */
  553. protected void renderLeader(Leader area) {
  554. currentIPPosition += area.getAllocIPD();
  555. }
  556. /** @see org.apache.fop.render.Renderer */
  557. protected void renderText(TextArea text) {
  558. currentIPPosition += text.getAllocIPD();
  559. }
  560. /** @see org.apache.fop.render.Renderer */
  561. protected void renderInlineParent(InlineParent ip) {
  562. int saveIP = currentIPPosition;
  563. Iterator iter = ip.getChildAreas().iterator();
  564. while (iter.hasNext()) {
  565. renderInlineArea((InlineArea) iter.next());
  566. }
  567. currentIPPosition = saveIP + ip.getAllocIPD();
  568. }
  569. /** @see org.apache.fop.render.Renderer */
  570. protected void renderViewport(Viewport viewport) {
  571. Area content = viewport.getContent();
  572. int saveBP = currentBPPosition;
  573. currentBPPosition += viewport.getOffset();
  574. Rectangle2D contpos = viewport.getContentPosition();
  575. if (content instanceof Image) {
  576. renderImage((Image) content, contpos);
  577. } else if (content instanceof Container) {
  578. renderContainer((Container) content);
  579. } else if (content instanceof ForeignObject) {
  580. renderForeignObject((ForeignObject) content, contpos);
  581. }
  582. currentIPPosition += viewport.getAllocIPD();
  583. currentBPPosition = saveBP;
  584. }
  585. /**
  586. * Renders an image area.
  587. *
  588. * @param image The image
  589. * @param pos The target position of the image
  590. * (todo) Make renderImage() protected
  591. */
  592. public void renderImage(Image image, Rectangle2D pos) {
  593. // Default: do nothing.
  594. // Some renderers (ex. Text) don't support images.
  595. }
  596. /**
  597. * Tells the renderer to render an inline container.
  598. * @param cont The inline container area
  599. */
  600. protected void renderContainer(Container cont) {
  601. int saveIP = currentIPPosition;
  602. int saveBP = currentBPPosition;
  603. List blocks = cont.getBlocks();
  604. renderBlocks(null, blocks);
  605. currentIPPosition = saveIP;
  606. currentBPPosition = saveBP;
  607. }
  608. /**
  609. * Renders a foreign object area.
  610. *
  611. * @param fo The foreign object area
  612. * @param pos The target position of the foreign object
  613. * (todo) Make renderForeignObject() protected
  614. */
  615. public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
  616. // Default: do nothing.
  617. // Some renderers (ex. Text) don't support foreign objects.
  618. }
  619. /**
  620. * Render the xml document with the given xml namespace.
  621. * The Render Context is by the handle to render into the current
  622. * rendering target.
  623. * @param ctx rendering context
  624. * @param doc DOM Document containing the source document
  625. * @param namespace Namespace URI of the document
  626. */
  627. public void renderXML(RendererContext ctx, Document doc,
  628. String namespace) {
  629. String mime = ctx.getMimeType();
  630. XMLHandler handler = userAgent.getXMLHandlerRegistry().getXMLHandler(
  631. mime, namespace);
  632. if (handler != null) {
  633. try {
  634. handler.handleXML(ctx, doc, namespace);
  635. } catch (Throwable t) {
  636. // could not handle document
  637. getLogger().error("Some XML content will be ignored. "
  638. + "Could not render XML", t);
  639. }
  640. } else {
  641. if (warnedXMLHandlers == null) {
  642. warnedXMLHandlers = new java.util.HashSet();
  643. }
  644. if (!warnedXMLHandlers.contains(namespace)) {
  645. // no handler found for document
  646. warnedXMLHandlers.add(namespace);
  647. getLogger().warn("Some XML content will be ignored. "
  648. + "No handler defined for XML: " + namespace);
  649. }
  650. }
  651. }
  652. /**
  653. * Get the MIME type of the renderer.
  654. *
  655. * @return The MIME type of the renderer
  656. */
  657. public String getMimeType() {
  658. return null;
  659. }
  660. }