~ubuntu-branches/ubuntu/karmic/batik/karmic

« back to all changes in this revision

Viewing changes to pdf-transcoder/src/java/org/apache/fop/render/AbstractRenderer.java

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev, Onkar Shinde, Matvey Kozhev
  • Date: 2008-07-19 01:03:05 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080719010305-0b24skqy185kdsb9
Tags: 1.7.dfsg-0ubuntu1
[ Onkar Shinde ]
* New upstream version (LP: #147818)
* debian/control
  - Add Sun JDK 1.5 as build dependency. Fixes FTBFS on buildd. (LP: #150484)
    Also add Sun JRE as runtime dependencies.
  - Add ant-optional as build dependency.
  - Add libxml-commons-external-java and libxmlgraphics-commons-java as
    build and runtime dependencies.
  - Add 'Homepage' field and correct the url.
  - Change standards version to 3.8.0.
  - Modify Maintainer value to match the DebianMaintainerField
    specification.
* debian/rules
  - Change JAVA_HOME_DIRS for Sun JDK.
  - Add jar file names to DEB_JARS to match new build requirements.
  - Extract version from changelog.
  - Delete bundled jar files in clean target.
  - Don't use hardcoded version in install target.
  - Add get-orig-source target.
* debian/README.Debian-source
  - Change the fo tag name to the one used for this version.
* debian/watch
  - Change expression to match src distribution.
* debian/patches/
  - 01_build_xml.patch, 02_fix_jar_target.patch - Refresh for current source.
  - 03_fix_lib_dirs.patch - Fix the library and classpath references needed
    for pdf transcoder build.
  - 04_fix_transcoder_pkg.patch - Fix transcoder-pkg target to not copy
    files from other jar files.

[ Matvey Kozhev ]
* debian/changelog:
  - Added ".dfsg" to version.
* debian/control, debian/rules:
  - Build with openjdk-6-jdk, depend on openjdk-6-jre.
  - Added java-6-sun as an alternate build JAVA_HOME directory.
  - Fixed get-orig-source to not include debian/ and delete the source dir,
    and made it delete jars from lib/, as done in the current batik package.
* debian/wrappers.sh:
  - Changed java-7-icedtea reference to java-6-openjdk, as the former has been
    removed back in Hardy.
  - Added newline.
* debian/libbatik-java.install:
  - Added newline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
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
 
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
7
8
 * 
8
9
 *      http://www.apache.org/licenses/LICENSE-2.0
9
10
 * 
14
15
 * limitations under the License.
15
16
 */
16
17
 
17
 
/* $Id$ */
 
18
/* $Id: AbstractRenderer.java 542237 2007-05-28 14:31:24Z jeremias $ */
18
19
 
19
20
package org.apache.fop.render;
20
21
 
21
22
// Java
 
23
import java.awt.Rectangle;
22
24
import java.awt.geom.Rectangle2D;
23
25
import java.io.IOException;
24
26
import java.io.OutputStream;
25
 
import java.util.Map;
26
27
import java.util.List;
27
28
import java.util.Iterator;
 
29
import java.util.Set;
28
30
 
29
31
// XML
30
32
import org.w3c.dom.Document;
48
50
import org.apache.fop.area.RegionReference;
49
51
import org.apache.fop.area.Trait;
50
52
import org.apache.fop.area.OffDocumentItem;
 
53
import org.apache.fop.area.inline.Character;
51
54
import org.apache.fop.area.inline.Container;
52
55
import org.apache.fop.area.inline.ForeignObject;
53
56
import org.apache.fop.area.inline.Image;
54
57
import org.apache.fop.area.inline.InlineArea;
 
58
import org.apache.fop.area.inline.InlineBlockParent;
55
59
import org.apache.fop.area.inline.InlineParent;
56
60
import org.apache.fop.area.inline.Leader;
57
61
import org.apache.fop.area.inline.Space;
58
62
import org.apache.fop.area.inline.Viewport;
59
63
import org.apache.fop.area.inline.TextArea;
60
 
import org.apache.fop.area.inline.Character;
 
64
import org.apache.fop.area.inline.WordArea;
 
65
import org.apache.fop.area.inline.SpaceArea;
61
66
import org.apache.fop.apps.FOUserAgent;
62
67
import org.apache.fop.fo.Constants;
63
68
import org.apache.fop.fonts.FontInfo;
64
69
import org.apache.commons.logging.Log;
65
70
import org.apache.commons.logging.LogFactory;
66
71
 
67
 
// Avalon
68
 
import org.apache.avalon.framework.configuration.Configurable;
69
 
import org.apache.avalon.framework.configuration.Configuration;
70
 
import org.apache.avalon.framework.configuration.ConfigurationException;
71
 
 
72
72
/**
73
73
 * Abstract base class for all renderers. The Abstract renderer does all the
74
74
 * top level processing of the area tree and adds some abstract methods to
75
75
 * handle viewports. This keeps track of the current block and inline position.
76
76
 */
77
77
public abstract class AbstractRenderer 
78
 
         implements Renderer, Configurable, Constants {
 
78
         implements Renderer, Constants {
79
79
 
 
80
    /** logging instance */
 
81
    protected static Log log = LogFactory.getLog("org.apache.fop.render");
 
82
    
80
83
    /**
81
84
     * user agent
82
85
     */
83
 
    protected FOUserAgent userAgent;
 
86
    protected FOUserAgent userAgent = null;
84
87
 
85
88
    /**
86
 
     * logging instance
87
 
     */
88
 
    protected static Log logger = LogFactory.getLog("org.apache.fop.render");
89
 
    
90
 
    /**
91
89
     * block progression position
92
90
     */
93
91
    protected int currentBPPosition = 0;
109
107
     */
110
108
    protected int containingIPPosition = 0;
111
109
 
112
 
    /**
113
 
     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
114
 
     */
115
 
    public void configure(Configuration conf) throws ConfigurationException {
116
 
    }
117
 
 
118
 
    /**
119
 
     * Returns the Commons-Logging instance for this class
120
 
     * @return  The Commons-Logging instance
121
 
     */
122
 
    protected Log getLogger() {
123
 
        return logger;
124
 
    }
125
 
 
126
 
    /**
127
 
     *  @see org.apache.fop.render.Renderer
 
110
    /** the currently active PageViewport */
 
111
    protected PageViewport currentPageViewport;
 
112
    
 
113
    private Set warnedXMLHandlers;
 
114
    
 
115
    /**
 
116
     *  @see org.apache.fop.render.Renderer#setupFontInfo(FontInfo)
128
117
     */
129
118
    public abstract void setupFontInfo(FontInfo fontInfo);
130
119
 
131
120
    /**
132
 
     *  @see org.apache.fop.render.Renderer
 
121
     *  @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
133
122
     */
134
123
    public void setUserAgent(FOUserAgent agent) {
135
124
        userAgent = agent;
136
125
    }
137
126
 
138
 
    /** @see org.apache.fop.render.Renderer */
 
127
    /**
 
128
     *  @see org.apache.fop.render.Renderer#getUserAgent()
 
129
     */
 
130
    public FOUserAgent getUserAgent() {
 
131
        return userAgent;
 
132
    }
 
133
 
 
134
    /** @see org.apache.fop.render.Renderer#startRenderer(OutputStream) */
139
135
    public void startRenderer(OutputStream outputStream)
140
136
        throws IOException { }
141
137
 
142
 
    /** @see org.apache.fop.render.Renderer */
 
138
    /** @see org.apache.fop.render.Renderer#stopRenderer() */
143
139
    public void stopRenderer()
144
140
        throws IOException { }
145
141
 
156
152
    }
157
153
 
158
154
    /**
159
 
     * @see     org.apache.fop.render.Renderer
 
155
     * @see     org.apache.fop.render.Renderer#processOffDocumentItem(OffDocumentItem)
160
156
     */
161
 
    public void processOffDocumentItem(OffDocumentItem oDI) { }
 
157
    public void processOffDocumentItem(OffDocumentItem odi) { }
162
158
 
 
159
    /** @see org.apache.fop.render.Renderer#getGraphics2DAdapter() */
 
160
    public Graphics2DAdapter getGraphics2DAdapter() {
 
161
        return null;
 
162
    }
 
163
    
 
164
    /** @see org.apache.fop.render.Renderer#getImageAdapter() */
 
165
    public ImageAdapter getImageAdapter() {
 
166
        return null;
 
167
    }
 
168
    
 
169
    /** @return the current PageViewport or null, if none is active */
 
170
    protected PageViewport getCurrentPageViewport() {
 
171
        return this.currentPageViewport;
 
172
    }
 
173
    
163
174
    /**
164
175
     * Prepare a page for rendering. This is called if the renderer supports
165
176
     * out of order rendering. The renderer should prepare the page so that a
167
178
     * page should not be rendered. The page will be rendered at a later time
168
179
     * by the call to render page.
169
180
     *
170
 
     * @see org.apache.fop.render.Renderer
 
181
     * @see org.apache.fop.render.Renderer#preparePage(PageViewport)
171
182
     */
172
183
    public void preparePage(PageViewport page) { }
173
184
 
190
201
        StringBuffer sb = new StringBuffer();
191
202
        for (int count = 0; count < children.size(); count++) {
192
203
            InlineArea inline = (InlineArea) children.get(count);
193
 
            if (inline instanceof Character) {
194
 
                sb.append(((Character) inline).getChar());
195
 
            } else if (inline instanceof TextArea) {
196
 
                sb.append(((TextArea) inline).getTextArea());
 
204
            //if (inline instanceof Character) {
 
205
            //    sb.append(((Character) inline).getChar());
 
206
            /*} else*/ if (inline instanceof TextArea) {
 
207
                sb.append(((TextArea) inline).getText());
197
208
            } else if (inline instanceof InlineParent) {
198
209
                sb.append(convertToString(
199
210
                        ((InlineParent) inline).getChildAreas()));
204
215
        return sb.toString();
205
216
    }
206
217
 
207
 
    /** @see org.apache.fop.render.Renderer */
 
218
    /** @see org.apache.fop.render.Renderer#startPageSequence(LineArea) */
208
219
    public void startPageSequence(LineArea seqTitle) {
209
220
        //do nothing
210
221
    }
211
222
 
212
223
    // normally this would be overriden to create a page in the
213
224
    // output
214
 
    /** @see org.apache.fop.render.Renderer */
 
225
    /** @see org.apache.fop.render.Renderer#renderPage(PageViewport) */
215
226
    public void renderPage(PageViewport page)
216
227
        throws IOException, FOPException {
217
228
 
218
 
        Page p = page.getPage();
219
 
        renderPageAreas(p);
 
229
        this.currentPageViewport = page;
 
230
        try {
 
231
            Page p = page.getPage();
 
232
            renderPageAreas(p);
 
233
        } finally {
 
234
            this.currentPageViewport = null;
 
235
        }
220
236
    }
221
237
 
222
238
    /**
259
275
            currentBPPosition = 0;
260
276
            currentIPPosition = 0;
261
277
 
262
 
            RegionReference region = port.getRegion();
 
278
            RegionReference regionReference = port.getRegionReference();
263
279
            handleRegionTraits(port);
264
280
 
265
281
            //  shouldn't the viewport have the CTM
266
 
            startVParea(region.getCTM());
 
282
            startVParea(regionReference.getCTM(), port.isClip() ? view : null);
267
283
            // do after starting viewport area
268
 
            if (region.getRegionClass() == FO_REGION_BODY) {
269
 
                renderBodyRegion((BodyRegion) region);
 
284
            if (regionReference.getRegionClass() == FO_REGION_BODY) {
 
285
                renderBodyRegion((BodyRegion) regionReference);
270
286
            } else {
271
 
                renderRegion(region);
 
287
                renderRegion(regionReference);
272
288
            }
273
289
            endVParea();
274
290
        }
275
291
    }
276
292
 
277
293
    /**
278
 
     * (todo) Description of the Method
 
294
     * Establishes a new viewport area.
279
295
     *
280
 
     * @param ctm  The coordinate transformation matrix to use
281
 
     */
282
 
    protected void startVParea(CTM ctm) { }
 
296
     * @param ctm the coordinate transformation matrix to use
 
297
     * @param clippingRect the clipping rectangle if the viewport should be clipping, 
 
298
     *                     null if no clipping is performed.
 
299
     */
 
300
    protected abstract void startVParea(CTM ctm, Rectangle2D clippingRect);
 
301
 
 
302
    /**
 
303
     * Signals exit from a viewport area. Subclasses can restore transformation matrices
 
304
     * valid before the viewport area was started.
 
305
     */
 
306
    protected abstract void endVParea();
283
307
 
284
308
    /**
285
309
     * Handle the traits for a region
292
316
    }
293
317
 
294
318
    /**
295
 
     * (todo) Description of the Method
296
 
     */
297
 
    protected void endVParea() { }
298
 
 
299
 
    /**
300
319
     * Renders a region reference area.
301
320
     *
302
321
     * @param region  The region reference area
348
367
     * @param footnote  The footnote
349
368
     */
350
369
    protected void renderFootnote(Footnote footnote) {
 
370
        currentBPPosition += footnote.getTop();
351
371
        List blocks = footnote.getChildAreas();
352
372
        if (blocks != null) {
353
373
            Block sep = footnote.getSeparator();
374
394
 
375
395
        Span span = null;
376
396
        List spans = mr.getSpans();
 
397
        int saveBPPos = currentBPPosition;
 
398
        int saveSpanBPPos = saveBPPos;
377
399
        for (int count = 0; count < spans.size(); count++) {
378
400
            span = (Span) spans.get(count);
379
 
            int offset = (mr.getWidth()
380
 
                    - (span.getColumnCount() - 1) * mr.getColumnGap())
381
 
                    / span.getColumnCount() + mr.getColumnGap();
382
401
            for (int c = 0; c < span.getColumnCount(); c++) {
383
402
                NormalFlow flow = (NormalFlow) span.getNormalFlow(c);
384
403
 
385
 
                renderFlow(flow);
386
 
                currentIPPosition += offset;
 
404
                if (flow != null) {
 
405
                    currentBPPosition = saveSpanBPPos;
 
406
                    renderFlow(flow);
 
407
                    currentIPPosition += flow.getIPD();
 
408
                    currentIPPosition += mr.getColumnGap();
 
409
                }
387
410
            }
388
411
            currentIPPosition = saveIPPos;
389
 
            currentBPPosition += span.getHeight();
 
412
            currentBPPosition = saveSpanBPPos + span.getHeight();
 
413
            saveSpanBPPos = currentBPPosition;
390
414
        }
 
415
        currentBPPosition = saveBPPos;
391
416
    }
392
417
 
393
418
    /**
428
453
            int saveIP = currentIPPosition;
429
454
            int saveBP = currentBPPosition;
430
455
 
 
456
            Rectangle2D clippingRect = null;
 
457
            if (bv.getClip()) {
 
458
                clippingRect = new Rectangle(saveIP, saveBP, bv.getIPD(), bv.getBPD());
 
459
            }
 
460
            
431
461
            CTM ctm = bv.getCTM();
432
462
            currentIPPosition = 0;
433
463
            currentBPPosition = 0;
434
464
 
435
 
            startVParea(ctm);
 
465
            startVParea(ctm, clippingRect);
436
466
            handleBlockTraits(bv);
437
467
            renderBlocks(bv, children);
438
468
            endVParea();
500
530
                        + parent.getStartIndent() 
501
531
                        + line.getStartIndent();
502
532
                renderLineArea(line);
 
533
                //InlineArea child = (InlineArea) line.getInlineAreas().get(0);
503
534
                currentBPPosition += line.getAllocBPD();
504
535
            }
505
536
            currentIPPosition = saveIP;
527
558
            int saveBP = currentBPPosition;
528
559
 
529
560
            if (block.getPositioning() == Block.ABSOLUTE) {
530
 
                currentIPPosition = containingIPPosition + block.getXOffset();
531
 
                currentBPPosition = containingBPPosition + block.getYOffset();
 
561
                currentIPPosition += block.getXOffset();
 
562
                currentBPPosition += block.getYOffset();
 
563
                currentBPPosition += block.getSpaceBefore();
532
564
 
533
565
                handleBlockTraits(block);
534
566
 
542
574
                // relative blocks are offset
543
575
                currentIPPosition += block.getXOffset();
544
576
                currentBPPosition += block.getYOffset();
 
577
                currentBPPosition += block.getSpaceBefore();
545
578
 
546
579
                handleBlockTraits(block);
547
580
 
556
589
        }
557
590
    }
558
591
 
559
 
    protected void renderTextDecoration(InlineArea area) {
560
 
        //getLogger().debug("renderTextDecoration for " + area + " -> " + area.getTrait(Trait.UNDERLINE));
561
 
    }
562
 
 
563
592
    /**
564
593
     * Renders a line area. <p>
565
594
     *
570
599
     */
571
600
    protected void renderLineArea(LineArea line) {
572
601
        List children = line.getInlineAreas();
573
 
 
 
602
        int saveBP = currentBPPosition;
 
603
        currentBPPosition += line.getSpaceBefore();
574
604
        for (int count = 0; count < children.size(); count++) {
575
605
            InlineArea inline = (InlineArea) children.get(count);
576
606
            renderInlineArea(inline);
577
607
        }
 
608
        currentBPPosition = saveBP;
578
609
    }
579
610
 
 
611
    /**
 
612
     * Render the given InlineArea.
 
613
     * @param inlineArea inline area text to render
 
614
     */
580
615
    protected void renderInlineArea(InlineArea inlineArea) {
581
 
        renderTextDecoration(inlineArea);
582
616
        if (inlineArea instanceof TextArea) {
583
617
            renderText((TextArea) inlineArea);
 
618
        //} else if (inlineArea instanceof Character) {
 
619
            //renderCharacter((Character) inlineArea);
 
620
        } else if (inlineArea instanceof WordArea) {
 
621
            renderWord((WordArea) inlineArea);
 
622
        } else if (inlineArea instanceof SpaceArea) {
 
623
            renderSpace((SpaceArea) inlineArea);
584
624
        } else if (inlineArea instanceof InlineParent) {
585
625
            renderInlineParent((InlineParent) inlineArea);
 
626
        } else if (inlineArea instanceof InlineBlockParent) {
 
627
            renderInlineBlockParent((InlineBlockParent) inlineArea);
586
628
        } else if (inlineArea instanceof Space) {
587
629
            renderInlineSpace((Space) inlineArea);
588
 
        } else if (inlineArea instanceof Character) {
589
 
            renderCharacter((Character) inlineArea);
590
630
        } else if (inlineArea instanceof Viewport) {
591
631
            renderViewport((Viewport) inlineArea);
592
632
        } else if (inlineArea instanceof Leader) {
594
634
        }
595
635
    }
596
636
 
597
 
 
598
 
    /** @see org.apache.fop.render.Renderer */
 
637
    /**
 
638
     * Render the given Character.
 
639
     * @param ch the character to render
 
640
     * @deprecated Only TextArea should be used. This method will be removed eventually.
 
641
     */
599
642
    protected void renderCharacter(Character ch) {
600
643
        currentIPPosition += ch.getAllocIPD();
601
644
    }
602
645
 
603
 
    /** @see org.apache.fop.render.Renderer */
 
646
    /** 
 
647
     * Common method to render the background and borders for any inline area.
 
648
     * The all borders and padding are drawn outside the specified area.
 
649
     * @param area the inline area for which the background, border and padding is to be
 
650
     * rendered
 
651
     */
 
652
    protected abstract void renderInlineAreaBackAndBorders(InlineArea area);
 
653
    
 
654
    /**
 
655
     * Render the given Space.
 
656
     * @param space the space to render
 
657
     */
604
658
    protected void renderInlineSpace(Space space) {
 
659
        space.setBPD(0);
 
660
        renderInlineAreaBackAndBorders(space);
605
661
        // an inline space moves the inline progression position
606
662
        // for the current block by the width or height of the space
607
663
        // it may also have styling (only on this object) that needs
609
665
        currentIPPosition += space.getAllocIPD();
610
666
    }
611
667
 
612
 
    /** @see org.apache.fop.render.Renderer */
 
668
    /**
 
669
     * Render the given Leader.
 
670
     * @param area the leader to render
 
671
     */
613
672
    protected void renderLeader(Leader area) {
614
673
        currentIPPosition += area.getAllocIPD();
615
674
    }
616
675
 
617
 
    /** @see org.apache.fop.render.Renderer */
 
676
    /**
 
677
     * Render the given TextArea.
 
678
     * @param text the text to render
 
679
     */
618
680
    protected void renderText(TextArea text) {
619
 
        currentIPPosition += text.getAllocIPD();
620
 
    }
621
 
 
622
 
    /** @see org.apache.fop.render.Renderer */
 
681
        int saveIP = currentIPPosition;
 
682
        int saveBP = currentBPPosition;
 
683
        Iterator iter = text.getChildAreas().iterator();
 
684
        while (iter.hasNext()) {
 
685
            renderInlineArea((InlineArea) iter.next()); 
 
686
        }
 
687
        currentIPPosition = saveIP + text.getAllocIPD();
 
688
    }
 
689
 
 
690
    /**
 
691
     * Render the given WordArea.
 
692
     * @param word the word to render
 
693
     */
 
694
    protected void renderWord(WordArea word) {
 
695
        currentIPPosition += word.getAllocIPD();
 
696
    }
 
697
 
 
698
    /**
 
699
     * Render the given SpaceArea.
 
700
     * @param space the space to render
 
701
     */
 
702
    protected void renderSpace(SpaceArea space) {
 
703
        currentIPPosition += space.getAllocIPD();
 
704
    }
 
705
 
 
706
    /**
 
707
     * Render the given InlineParent.
 
708
     * @param ip the inline parent to render
 
709
     */
623
710
    protected void renderInlineParent(InlineParent ip) {
 
711
        renderInlineAreaBackAndBorders(ip);
624
712
        int saveIP = currentIPPosition;
 
713
        int saveBP = currentBPPosition;
 
714
        currentIPPosition += ip.getBorderAndPaddingWidthStart();
 
715
        currentBPPosition += ip.getOffset();
625
716
        Iterator iter = ip.getChildAreas().iterator();
626
717
        while (iter.hasNext()) {
627
718
            renderInlineArea((InlineArea) iter.next()); 
628
719
        }
629
720
        currentIPPosition = saveIP + ip.getAllocIPD();
630
 
    }
631
 
 
632
 
    /** @see org.apache.fop.render.Renderer */
 
721
        currentBPPosition = saveBP;
 
722
    }
 
723
 
 
724
    /**
 
725
     * Render the given InlineBlockParent.
 
726
     * @param ibp the inline block parent to render
 
727
     */
 
728
    protected void renderInlineBlockParent(InlineBlockParent ibp) {
 
729
        renderInlineAreaBackAndBorders(ibp);
 
730
        currentIPPosition += ibp.getBorderAndPaddingWidthStart();
 
731
        // For inline content the BP position is updated by the enclosing line area
 
732
        int saveBP = currentBPPosition;
 
733
        currentBPPosition += ibp.getOffset();
 
734
        renderBlock(ibp.getChildArea());
 
735
        currentBPPosition = saveBP;
 
736
    }
 
737
 
 
738
    /**
 
739
     * Render the given Viewport.
 
740
     * @param viewport the viewport to render
 
741
     */
633
742
    protected void renderViewport(Viewport viewport) {
634
743
        Area content = viewport.getContent();
635
744
        int saveBP = currentBPPosition;
685
794
    }
686
795
 
687
796
    /**
688
 
     * Set the default xml handler for the given mime type.
689
 
     * @param mime MIME type
690
 
     * @param handler XMLHandler to use
691
 
     */
692
 
    public void setDefaultXMLHandler(FOUserAgent foua, String mime,
693
 
                                     XMLHandler handler) {
694
 
        foua.defaults.put(mime, handler);
695
 
    }
696
 
 
697
 
    /**
698
 
     * Add an xml handler for the given mime type and xml namespace.
699
 
     * @param mime MIME type
700
 
     * @param ns Namespace URI
701
 
     * @param handler XMLHandler to use
702
 
     */
703
 
    public void addXMLHandler(FOUserAgent foua, String mime, String ns,
704
 
                              XMLHandler handler) {
705
 
        Map mh = (Map) foua.handlers.get(mime);
706
 
        if (mh == null) {
707
 
            mh = new java.util.HashMap();
708
 
            foua.handlers.put(mime, mh);
709
 
        }
710
 
        mh.put(ns, handler);
711
 
    }
712
 
 
713
 
    /**
714
797
     * Render the xml document with the given xml namespace.
715
798
     * The Render Context is by the handle to render into the current
716
799
     * rendering target.
718
801
     * @param doc DOM Document containing the source document
719
802
     * @param namespace Namespace URI of the document
720
803
     */
721
 
    public void renderXML(FOUserAgent foua, RendererContext ctx, Document doc,
 
804
    public void renderXML(RendererContext ctx, Document doc,
722
805
                          String namespace) {
723
 
        String mime = ctx.getMimeType();
724
 
        Map mh = (Map) foua.handlers.get(mime);
725
 
        XMLHandler handler = null;
726
 
        if (mh != null) {
727
 
            handler = (XMLHandler) mh.get(namespace);
728
 
        }
729
 
        if (handler == null) {
730
 
            handler = (XMLHandler) foua.defaults.get(mime);
731
 
        }
 
806
        XMLHandler handler = userAgent.getXMLHandlerRegistry().getXMLHandler(
 
807
                this, namespace);
732
808
        if (handler != null) {
733
809
            try {
 
810
                XMLHandlerConfigurator configurator
 
811
                    = new XMLHandlerConfigurator(userAgent);
 
812
                configurator.configure(ctx, namespace);
734
813
                handler.handleXML(ctx, doc, namespace);
735
814
            } catch (Throwable t) {
736
815
                // could not handle document
737
 
                getLogger().error("Some XML content will be ignored. "
 
816
                log.error("Some XML content will be ignored. "
738
817
                        + "Could not render XML", t);
739
818
            }
740
819
        } else {
741
 
            // no handler found for document
742
 
            getLogger().warn("Some XML content will be ignored. "
743
 
                    + "No handler defined for XML: " + namespace);
 
820
            if (warnedXMLHandlers == null) {
 
821
                warnedXMLHandlers = new java.util.HashSet();
 
822
            }
 
823
            if (!warnedXMLHandlers.contains(namespace)) {
 
824
                // no handler found for document
 
825
                warnedXMLHandlers.add(namespace);
 
826
                log.warn("Some XML content will be ignored. "
 
827
                        + "No handler defined for XML: " + namespace);
 
828
            }
744
829
        }
745
830
    }
746
831
 
753
838
        return null;
754
839
    }
755
840
}
756