From ef55fa9d3dd9a748899431bb8ba0b40c7bfce507 Mon Sep 17 00:00:00 2001 From: William Victor Mote Date: Tue, 6 May 2003 05:17:07 +0000 Subject: [PATCH] Make StructureHandler and most of its methods abstract. It is never instantiated, has a bunch of empty classes that appear to be patterns. If those classes were to be filled in with logic, it would create problems in the subclasses. Also, any changes to signature now in the subclasses will cause the parent method to be used, which is probably not what would be wanted. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196405 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/apps/LayoutHandler.java | 165 ++++++++++++++-- .../org/apache/fop/apps/StructureHandler.java | 184 +++++------------- src/java/org/apache/fop/mif/MIFHandler.java | 126 ++++++++++-- .../apache/fop/rtf/renderer/RTFHandler.java | 126 ++++++++++-- 4 files changed, 432 insertions(+), 169 deletions(-) diff --git a/src/java/org/apache/fop/apps/LayoutHandler.java b/src/java/org/apache/fop/apps/LayoutHandler.java index cc687cd23..348d8112b 100644 --- a/src/java/org/apache/fop/apps/LayoutHandler.java +++ b/src/java/org/apache/fop/apps/LayoutHandler.java @@ -3,34 +3,34 @@ * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ - * + * * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. - * + * * 4. The names "FOP" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * apache@apache.org. - * + * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE @@ -42,12 +42,12 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ============================================================================ - * + * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation and was originally created by * James Tauber . For more information on the Apache * Software Foundation, please see . - */ + */ package org.apache.fop.apps; // Java @@ -55,6 +55,9 @@ import java.io.IOException; import java.io.OutputStream; import java.util.List; +// Avalon +import org.apache.avalon.framework.logger.AbstractLogEnabled; + // SAX import org.xml.sax.SAXException; @@ -68,6 +71,21 @@ import org.apache.fop.fo.pagination.LayoutMasterSet; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.layout.FontInfo; import org.apache.fop.render.Renderer; +import org.apache.fop.apps.StructureHandler; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.Flow; +import org.apache.fop.fo.pagination.PageSequenceMaster; +import org.apache.fop.fo.pagination.SimplePageMaster; +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.flow.TableRow; /** * Layout handler that receives the structure events. @@ -168,7 +186,7 @@ public class LayoutHandler extends StructureHandler { if (MEM_PROFILE_WITH_GC) { System.gc(); // This takes time but gives better results } - + initialMemory = runtime.totalMemory() - runtime.freeMemory(); startTime = System.currentTimeMillis(); } @@ -233,8 +251,8 @@ public class LayoutHandler extends StructureHandler { * @param seqTitle the title of the page sequence * @param lms the layout master set */ - public void startPageSequence(PageSequence pageSeq, - org.apache.fop.fo.Title seqTitle, + public void startPageSequence(PageSequence pageSeq, + org.apache.fop.fo.Title seqTitle, LayoutMasterSet lms) { Title title = null; if (seqTitle != null) { @@ -258,7 +276,7 @@ public class LayoutHandler extends StructureHandler { if (collectStatistics) { if (MEM_PROFILE_WITH_GC) { // This takes time but gives better results - System.gc(); + System.gc(); } long memoryNow = runtime.totalMemory() - runtime.freeMemory(); if (getLogger().isDebugEnabled()) { @@ -268,6 +286,125 @@ public class LayoutHandler extends StructureHandler { pageSequence.format(areaTree); } + public void startFlow(Flow fl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endFlow(Flow) + */ + public void endFlow(Flow fl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startBlock(Block) + */ + public void startBlock(Block bl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endBlock(Block) + */ + public void endBlock(Block bl) { + } + + public void startTable(Table tbl) { + } + + public void endTable(Table tbl) { + } + + public void startHeader(TableBody th) { + } + + public void endHeader(TableBody th) { + } + + public void startFooter(TableBody tf) { + } + + public void endFooter(TableBody tf) { + } + + public void startBody(TableBody tb) { + } + + public void endBody(TableBody tb) { + } + + public void startRow(TableRow tr) { + } + + public void endRow(TableRow tr) { + } + + public void startCell(TableCell tc) { + } + + public void endCell(TableCell tc) { + } + + // Lists + public void startList(ListBlock lb) { + } + + public void endList(ListBlock lb) { + } + + public void startListItem(ListItem li) { + } + + public void endListItem(ListItem li) { + } + + public void startListLabel() { + } + + public void endListLabel() { + } + + public void startListBody() { + } + + public void endListBody() { + } + + // Static Regions + public void startStatic() { + } + + public void endStatic() { + } + + public void startMarkup() { + } + + public void endMarkup() { + } + + public void startLink() { + } + + public void endLink() { + } + + public void image(ExternalGraphic eg) { + } + + public void pageRef() { + } + + public void foreignObject(InstreamForeignObject ifo) { + } + + public void footnote() { + } + + public void leader(Leader l) { + } + + public void characters(char data[], int start, int length) { + } + /** * Process an area tree. * If a store pages model is used this can read and send all the diff --git a/src/java/org/apache/fop/apps/StructureHandler.java b/src/java/org/apache/fop/apps/StructureHandler.java index d63833acd..1e22e9e20 100644 --- a/src/java/org/apache/fop/apps/StructureHandler.java +++ b/src/java/org/apache/fop/apps/StructureHandler.java @@ -3,34 +3,34 @@ * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ - * + * * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. - * + * * 4. The names "FOP" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * apache@apache.org. - * + * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE @@ -42,12 +42,12 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ============================================================================ - * + * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation and was originally created by * James Tauber . For more information on the Apache * Software Foundation, please see . - */ + */ package org.apache.fop.apps; // Java @@ -81,7 +81,7 @@ import org.xml.sax.SAXException; * Sub-classes can then implement various methods to handle * the FO Tree when the SAX events occur. */ -public class StructureHandler extends AbstractLogEnabled { +abstract public class StructureHandler extends AbstractLogEnabled { /** * The current set of id's in the FO tree. * This is used so we know if the FO tree contains duplicates. @@ -114,182 +114,100 @@ public class StructureHandler extends AbstractLogEnabled { * This method is called to indicate the start of a new document run. * @throws SAXException In case of a problem */ - public void startDocument() throws SAXException { - } + abstract public void startDocument() throws SAXException; /** * This method is called to indicate the end of a document run. * @throws SAXException In case of a problem */ - public void endDocument() throws SAXException { - } + abstract public void endDocument() throws SAXException; - public void startPageSequence(PageSequence pageSeq, Title seqTitle, LayoutMasterSet lms) { + abstract public void startPageSequence(PageSequence pageSeq, Title seqTitle, LayoutMasterSet lms); - } + abstract public void endPageSequence(PageSequence pageSeq) throws FOPException; - public void endPageSequence(PageSequence pageSeq) throws FOPException { + abstract public void startFlow(Flow fl); - } + abstract public void endFlow(Flow fl); - public void startFlow(Flow fl) { + abstract public void startBlock(Block bl); - } - - public void endFlow(Flow fl) { - - } - - public void startBlock(Block bl) { - - } - - public void endBlock(Block bl) { - - } + abstract public void endBlock(Block bl); // Tables - public void startTable(Table tbl) { - - } - - public void endTable(Table tbl) { - - } - - public void startHeader(TableBody th) { + abstract public void startTable(Table tbl); - } + abstract public void endTable(Table tbl); - public void endHeader(TableBody th) { + abstract public void startHeader(TableBody th); - } + abstract public void endHeader(TableBody th); - public void startFooter(TableBody tf) { + abstract public void startFooter(TableBody tf); - } + abstract public void endFooter(TableBody tf); - public void endFooter(TableBody tf) { + abstract public void startBody(TableBody tb); - } + abstract public void endBody(TableBody tb); - public void startBody(TableBody tb) { + abstract public void startRow(TableRow tr); - } + abstract public void endRow(TableRow tr); - public void endBody(TableBody tb) { + abstract public void startCell(TableCell tc); - } - - public void startRow(TableRow tr) { - - } - - public void endRow(TableRow tr) { - - } - - public void startCell(TableCell tc) { - - } - - public void endCell(TableCell tc) { - - } + abstract public void endCell(TableCell tc); // Lists - public void startList(ListBlock lb) { + abstract public void startList(ListBlock lb); - } + abstract public void endList(ListBlock lb); - public void endList(ListBlock lb) { + abstract public void startListItem(ListItem li); - } + abstract public void endListItem(ListItem li); - public void startListItem(ListItem li) { + abstract public void startListLabel(); - } + abstract public void endListLabel(); - public void endListItem(ListItem li) { - - } - - public void startListLabel() { - - } - - public void endListLabel() { - - } - - public void startListBody() { - - } - - public void endListBody() { - - } + abstract public void startListBody(); + abstract public void endListBody(); // Static Regions - public void startStatic() { - - } + abstract public void startStatic(); - public void endStatic() { + abstract public void endStatic(); - } + abstract public void startMarkup(); + abstract public void endMarkup(); - public void startMarkup() { - } + abstract public void startLink(); - public void endMarkup() { + abstract public void endLink(); - } + abstract public void image(ExternalGraphic eg); - public void startLink() { + abstract public void pageRef(); - } + abstract public void foreignObject(InstreamForeignObject ifo); - public void endLink() { + abstract public void footnote(); - } + abstract public void leader(Leader l); - - public void image(ExternalGraphic eg) { - - } - - public void pageRef() { - - } - - public void foreignObject(InstreamForeignObject ifo) { - - } - - public void footnote() { - - } - - public void leader(Leader l) { - - } - - - public void characters(char data[], int start, int length) { - - } + abstract public void characters(char data[], int start, int length); public void pageBreak() { } - } diff --git a/src/java/org/apache/fop/mif/MIFHandler.java b/src/java/org/apache/fop/mif/MIFHandler.java index 3418e09d2..fd9b11a8c 100644 --- a/src/java/org/apache/fop/mif/MIFHandler.java +++ b/src/java/org/apache/fop/mif/MIFHandler.java @@ -3,34 +3,34 @@ * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ - * + * * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. - * + * * 4. The names "FOP" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * apache@apache.org. - * + * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE @@ -42,12 +42,12 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ============================================================================ - * + * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation and was originally created by * James Tauber . For more information on the Apache * Software Foundation, please see . - */ + */ package org.apache.fop.mif; // Java @@ -68,6 +68,15 @@ import org.apache.fop.fo.pagination.PageSequenceMaster; import org.apache.fop.fo.pagination.SimplePageMaster; import org.apache.fop.layout.FontInfo; import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.flow.TableRow; // TODO: do we really want every method throwing a SAXException @@ -78,7 +87,7 @@ import org.apache.fop.apps.FOPException; * This builds an MIF file and writes it to the output. */ public class MIFHandler extends StructureHandler { - + /** the MIFFile instance */ protected MIFFile mifFile; /** the OutputStream to write to */ @@ -223,6 +232,101 @@ public class MIFHandler extends StructureHandler { para = null; } + public void startTable(Table tbl) { + } + + public void endTable(Table tbl) { + } + + public void startHeader(TableBody th) { + } + + public void endHeader(TableBody th) { + } + + public void startFooter(TableBody tf) { + } + + public void endFooter(TableBody tf) { + } + + public void startBody(TableBody tb) { + } + + public void endBody(TableBody tb) { + } + + public void startRow(TableRow tr) { + } + + public void endRow(TableRow tr) { + } + + public void startCell(TableCell tc) { + } + + public void endCell(TableCell tc) { + } + + // Lists + public void startList(ListBlock lb) { + } + + public void endList(ListBlock lb) { + } + + public void startListItem(ListItem li) { + } + + public void endListItem(ListItem li) { + } + + public void startListLabel() { + } + + public void endListLabel() { + } + + public void startListBody() { + } + + public void endListBody() { + } + + // Static Regions + public void startStatic() { + } + + public void endStatic() { + } + + public void startMarkup() { + } + + public void endMarkup() { + } + + public void startLink() { + } + + public void endLink() { + } + + public void image(ExternalGraphic eg) { + } + + public void pageRef() { + } + + public void foreignObject(InstreamForeignObject ifo) { + } + + public void footnote() { + } + + public void leader(Leader l) { + } + /** * @see org.apache.fop.apps.StructureHandler#characters(char[], int, int) */ diff --git a/src/java/org/apache/fop/rtf/renderer/RTFHandler.java b/src/java/org/apache/fop/rtf/renderer/RTFHandler.java index 610aac25f..4a902624f 100644 --- a/src/java/org/apache/fop/rtf/renderer/RTFHandler.java +++ b/src/java/org/apache/fop/rtf/renderer/RTFHandler.java @@ -3,34 +3,34 @@ * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ - * + * * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. - * + * * 4. The names "FOP" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * apache@apache.org. - * + * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE @@ -42,12 +42,12 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ============================================================================ - * + * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation and was originally created by * James Tauber . For more information on the Apache * Software Foundation, please see . - */ + */ package org.apache.fop.rtf.renderer; // Java @@ -68,6 +68,15 @@ import org.apache.fop.fo.pagination.LayoutMasterSet; import org.apache.fop.fo.Title; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.flow.Flow; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.flow.TableRow; // JFOR import org.jfor.jfor.rtflib.rtfdoc.RtfFile; @@ -82,7 +91,7 @@ import org.jfor.jfor.rtflib.rtfdoc.RtfDocumentArea; * @author bdelacretaz@apache.org */ public class RTFHandler extends StructureHandler { - + private FontInfo fontInfo = new FontInfo(); private RtfFile rtfFile; private final OutputStream os; @@ -190,6 +199,101 @@ public class RTFHandler extends StructureHandler { public void endBlock(Block bl) { } + public void startTable(Table tbl) { + } + + public void endTable(Table tbl) { + } + + public void startHeader(TableBody th) { + } + + public void endHeader(TableBody th) { + } + + public void startFooter(TableBody tf) { + } + + public void endFooter(TableBody tf) { + } + + public void startBody(TableBody tb) { + } + + public void endBody(TableBody tb) { + } + + public void startRow(TableRow tr) { + } + + public void endRow(TableRow tr) { + } + + public void startCell(TableCell tc) { + } + + public void endCell(TableCell tc) { + } + + // Lists + public void startList(ListBlock lb) { + } + + public void endList(ListBlock lb) { + } + + public void startListItem(ListItem li) { + } + + public void endListItem(ListItem li) { + } + + public void startListLabel() { + } + + public void endListLabel() { + } + + public void startListBody() { + } + + public void endListBody() { + } + + // Static Regions + public void startStatic() { + } + + public void endStatic() { + } + + public void startMarkup() { + } + + public void endMarkup() { + } + + public void startLink() { + } + + public void endLink() { + } + + public void image(ExternalGraphic eg) { + } + + public void pageRef() { + } + + public void foreignObject(InstreamForeignObject ifo) { + } + + public void footnote() { + } + + public void leader(Leader l) { + } + /** * @see org.apache.fop.apps.StructureHandler#characters(char[], int, int) */ -- 2.39.5