2.) Apps.Document dropped. 3.) Validity checking added to fo.pagination.SinglePageMasterReference git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197737 13f79535-47bb-0310-9956-ffa450edef68tags/Root_Temp_KnuthStylePageBreaking
@@ -1,77 +0,0 @@ | |||
/* | |||
* Copyright 1999-2004 The Apache Software Foundation. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
package org.apache.fop.apps; | |||
// FOP | |||
import org.apache.fop.fo.FOInputHandler; | |||
import org.apache.fop.render.Renderer; | |||
// SAX | |||
import org.xml.sax.SAXException; | |||
/** | |||
* Class storing information for the FOP Document being processed, and managing | |||
* the processing of it. | |||
*/ | |||
public class Document { | |||
/** The parent Driver object */ | |||
private Driver driver; | |||
/** The Renderer being used for this document */ | |||
protected Renderer renderer; | |||
/** | |||
* Structure handler used to notify structure | |||
* events such as start end element. | |||
*/ | |||
public FOInputHandler foInputHandler; | |||
/** | |||
* Main constructor | |||
* @param driver the Driver object that is the "parent" of this Document | |||
*/ | |||
public Document(Driver driver) { | |||
this.driver = driver; | |||
} | |||
/** | |||
* Public accessor for the parent Driver of this Document | |||
* @return the parent Driver for this Document | |||
*/ | |||
public Driver getDriver() { | |||
return driver; | |||
} | |||
/** | |||
* Get the renderer for this document | |||
* @return the renderer for this document | |||
*/ | |||
public Renderer getRenderer() { | |||
return renderer; | |||
} | |||
/** | |||
* @return the FOInputHandler for parsing this FO Tree | |||
*/ | |||
public FOInputHandler getFOInputHandler() { | |||
return foInputHandler; | |||
} | |||
} |
@@ -194,8 +194,6 @@ public class Driver { | |||
private Log log = null; | |||
private FOUserAgent userAgent = null; | |||
private Document currentDocument = null; | |||
/** | |||
* Main constructor for the Driver class. | |||
*/ | |||
@@ -469,30 +467,20 @@ public class Driver { | |||
validateOutputStream(); | |||
} | |||
/** Document creation is hard-wired for now, but needs to be made | |||
accessible through the API and/or configuration */ | |||
if (currentDocument == null) { | |||
currentDocument = new Document(this); | |||
} | |||
// TODO: - do this stuff in a better way | |||
// PIJ: I guess the structure handler should be created by the renderer. | |||
if (rendererType == RENDER_MIF) { | |||
foInputHandler = new MIFHandler(currentDocument, stream); | |||
foInputHandler = new MIFHandler(userAgent, stream); | |||
} else if (rendererType == RENDER_RTF) { | |||
foInputHandler = new RTFHandler(currentDocument, stream); | |||
foInputHandler = new RTFHandler(userAgent, stream); | |||
} else { | |||
if (renderer == null) { | |||
throw new IllegalStateException( | |||
"Renderer not set when using standard foInputHandler"); | |||
} | |||
currentDocument.renderer = renderer; | |||
foInputHandler = new FOTreeHandler(currentDocument, stream, true); | |||
foInputHandler = new FOTreeHandler(userAgent, renderer, stream, true); | |||
} | |||
currentDocument.foInputHandler = foInputHandler; | |||
foInputHandler.setLogger(getLogger()); | |||
treeBuilder.setFOInputHandler(foInputHandler); | |||
@@ -21,10 +21,10 @@ package org.apache.fop.fo; | |||
// Java | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
import org.xml.sax.SAXException; | |||
// FOP | |||
import org.apache.fop.apps.Document; | |||
import org.apache.fop.apps.Driver; | |||
// Apache | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.area.AreaTree; | |||
import org.apache.fop.fo.flow.BasicLink; | |||
@@ -47,8 +47,8 @@ import org.apache.fop.fo.pagination.Flow; | |||
import org.apache.fop.fo.pagination.PageSequence; | |||
import org.apache.fop.fonts.FontInfo; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
import org.xml.sax.SAXException; | |||
/** | |||
* Abstract class defining what should be done with SAX events that map to | |||
@@ -63,20 +63,18 @@ import org.xml.sax.SAXException; | |||
*/ | |||
public abstract class FOInputHandler { | |||
/** | |||
* The Document object that is controlling the FO Tree being built | |||
/** | |||
* The FOUserAgent for this process | |||
*/ | |||
public Document doc = null; | |||
private FOUserAgent foUserAgent; | |||
/** | |||
* The Font information relevant for this document | |||
*/ | |||
protected FontInfo fontInfo; | |||
/** | |||
* logging instance | |||
*/ | |||
protected Log logger = null; | |||
/** Logger for FOInputHandler-related messages **/ | |||
protected static Log logger = LogFactory.getLog(FOInputHandler.class); | |||
/** | |||
* The current set of id's in the FO tree. | |||
@@ -86,11 +84,10 @@ public abstract class FOInputHandler { | |||
/** | |||
* Main constructor | |||
* @param document the apps.Document implementation that is controlling | |||
* the FO Tree being built | |||
* @param FOUserAgent the apps.FOUserAgent instance for this process | |||
*/ | |||
public FOInputHandler(Document document) { | |||
doc = document; | |||
public FOInputHandler(FOUserAgent foUserAgent) { | |||
this.foUserAgent = foUserAgent; | |||
this.fontInfo = new FontInfo(); | |||
} | |||
@@ -102,14 +99,6 @@ public abstract class FOInputHandler { | |||
return idReferences; | |||
} | |||
/** | |||
* Sets the Commons-Logging instance for this class | |||
* @param logger The Commons-Logging instance | |||
*/ | |||
public void setLogger(Log logger) { | |||
this.logger = logger; | |||
} | |||
/** | |||
* Returns the Commons-Logging instance for this class | |||
* @return The Commons-Logging instance | |||
@@ -119,19 +108,11 @@ public abstract class FOInputHandler { | |||
} | |||
/** | |||
* Returns the Document object associated with this FOInputHandler. | |||
* @return the Document object | |||
*/ | |||
public Document getDocument() { | |||
return doc; | |||
} | |||
/** | |||
* Returns the Driver object associated with this FOInputHandler. | |||
* @return the Driver object | |||
* Returns the User Agent object associated with this FOInputHandler. | |||
* @return the User Agent object | |||
*/ | |||
public Driver getDriver() { | |||
return doc.getDriver(); | |||
public FOUserAgent getUserAgent() { | |||
return foUserAgent; | |||
} | |||
/** |
@@ -20,13 +20,13 @@ package org.apache.fop.fo; | |||
// Java | |||
import java.util.ListIterator; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
// XML | |||
import org.xml.sax.Attributes; | |||
import org.xml.sax.Locator; | |||
import org.apache.commons.logging.Log; | |||
// FOP | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
@@ -34,6 +34,8 @@ import org.apache.fop.util.CharUtilities; | |||
import org.apache.fop.fo.extensions.ExtensionElementMapping; | |||
import org.apache.fop.fo.extensions.svg.SVGElementMapping; | |||
/** | |||
* base class for nodes in the XML tree | |||
* | |||
@@ -55,6 +57,9 @@ public abstract class FONode { | |||
/** Marks column number of this object in the input file **/ | |||
public int column; | |||
/** Logger for fo-tree related messages **/ | |||
private static Log log = LogFactory.getLog(FONode.class); | |||
/** | |||
* Main constructor. | |||
* @param parent parent of this node | |||
@@ -75,12 +80,21 @@ public abstract class FONode { | |||
} | |||
} | |||
/** | |||
* Recursively goes up the FOTree hierarchy until the fo:root is found, | |||
* which returns the parent FOInputHandler. | |||
* @return the FOInputHandler object that is the parent of the FO Tree | |||
*/ | |||
public FOInputHandler getFOInputHandler() { | |||
return parent.getFOInputHandler(); | |||
} | |||
/** | |||
* Returns the user agent for the node. | |||
* @return FOUserAgent | |||
*/ | |||
public FOUserAgent getUserAgent() { | |||
return getFOInputHandler().getDriver().getUserAgent(); | |||
return getFOInputHandler().getUserAgent(); | |||
} | |||
/** | |||
@@ -88,7 +102,7 @@ public abstract class FONode { | |||
* @return the logger | |||
*/ | |||
public Log getLogger() { | |||
return getFOInputHandler().getDriver().getLogger(); | |||
return log; | |||
} | |||
/** | |||
@@ -200,15 +214,6 @@ public abstract class FONode { | |||
return false; | |||
} | |||
/** | |||
* Recursively goes up the FOTree hierarchy until the fo:root is found, | |||
* which returns the parent FOInputHandler. | |||
* @return the FOInputHandler object that is the parent of the FO Tree | |||
*/ | |||
public FOInputHandler getFOInputHandler() { | |||
return parent.getFOInputHandler(); | |||
} | |||
/** | |||
* This is a hook for an FOTreeVisitor subclass to be able to access | |||
* this object. |
@@ -28,7 +28,7 @@ import java.util.Iterator; | |||
import org.xml.sax.SAXException; | |||
// FOP | |||
import org.apache.fop.apps.Document; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.area.AreaTree; | |||
import org.apache.fop.area.Title; | |||
@@ -56,6 +56,7 @@ import org.apache.fop.layoutmgr.ContentLayoutManager; | |||
import org.apache.fop.layoutmgr.InlineStackingLayoutManager; | |||
import org.apache.fop.layoutmgr.LMiter; | |||
import org.apache.fop.layoutmgr.PageLayoutManager; | |||
import org.apache.fop.render.Renderer; | |||
/** | |||
@@ -99,29 +100,35 @@ public class FOTreeHandler extends FOInputHandler { | |||
/** Useful only for allowing subclasses of AddLMVisitor to be set by those | |||
extending FOP **/ | |||
private AddLMVisitor addLMVisitor = null; | |||
/** | |||
* the renderer to use to output the area tree | |||
*/ | |||
private Renderer renderer; | |||
/** | |||
* Main constructor | |||
* @param document the apps.Document implementation that governs this | |||
* FO Tree | |||
* @param userAgent the apps.userAgent implementation that governs | |||
* this FO Tree | |||
* @param OutputStream stream to use to output results of renderer | |||
* | |||
* | |||
* @param store if true then use the store pages model and keep the | |||
* area tree in memory | |||
* area tree in memory | |||
*/ | |||
public FOTreeHandler(Document doc, OutputStream stream, boolean store) throws FOPException { | |||
super(doc); | |||
areaTree = new AreaTree(doc.getRenderer()); | |||
public FOTreeHandler(FOUserAgent userAgent, Renderer renderer, | |||
OutputStream stream, boolean store) throws FOPException { | |||
super(userAgent); | |||
this.renderer = renderer; | |||
areaTree = new AreaTree(renderer); | |||
try { | |||
doc.getRenderer().setupFontInfo(fontInfo); | |||
renderer.setupFontInfo(fontInfo); | |||
// check that the "any,normal,400" font exists | |||
if (!fontInfo.isSetupValid()) { | |||
throw new FOPException( | |||
"No default font defined by OutputConverter"); | |||
"No default font defined by OutputConverter"); | |||
} | |||
doc.getRenderer().startRenderer(stream); | |||
renderer.startRenderer(stream); | |||
} catch (IOException e) { | |||
throw new FOPException(e); | |||
} | |||
@@ -161,8 +168,8 @@ public class FOTreeHandler extends FOInputHandler { | |||
throw new SAXException("Error: No fo:page-sequence child " + | |||
"found within fo:root element."); | |||
} | |||
getAreaTree().endDocument(); | |||
getDriver().getRenderer().stopRenderer(); | |||
areaTree.endDocument(); | |||
renderer.stopRenderer(); | |||
} catch (IOException ex) { | |||
throw new SAXException(ex); | |||
} | |||
@@ -226,8 +233,8 @@ public class FOTreeHandler extends FOInputHandler { | |||
} | |||
} | |||
getAreaTree().addBookmarksToAreaTree(pageSequence.getRoot().getBookmarks()); | |||
formatPageSequence(pageSequence, getAreaTree()); | |||
areaTree.addBookmarksToAreaTree(pageSequence.getRoot().getBookmarks()); | |||
formatPageSequence(pageSequence, areaTree); | |||
} | |||
/** | |||
@@ -609,12 +616,5 @@ public class FOTreeHandler extends FOInputHandler { | |||
*/ | |||
public void endPageNumber(PageNumber pagenum) { | |||
} | |||
/** | |||
* @return the current Area Tree object | |||
*/ | |||
public AreaTree getAreaTree() { | |||
return areaTree; | |||
} | |||
} |
@@ -18,6 +18,11 @@ | |||
package org.apache.fop.fo.pagination; | |||
// XML | |||
import org.xml.sax.Attributes; | |||
import org.xml.sax.Locator; | |||
// FOP | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FOTreeVisitor; | |||
@@ -42,6 +47,14 @@ public class SinglePageMasterReference extends PageMasterReference | |||
this.state = FIRST; | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) | |||
* XSL/FOP Content Model: empty | |||
*/ | |||
protected void validateChildNode(Locator loc, String nsURI, String localName) { | |||
invalidChildError(loc, nsURI, localName); | |||
} | |||
/** | |||
* @see org.apache.fop.fo.pagination.SubSequenceSpecifier | |||
*/ |
@@ -46,7 +46,6 @@ import java.util.Map; | |||
import java.util.Vector; | |||
import org.apache.fop.fonts.FontInfo; | |||
import org.apache.fop.apps.Document; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.InputHandler; | |||
import org.apache.fop.area.Area; |
@@ -22,7 +22,7 @@ package org.apache.fop.render.mif; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
import org.apache.fop.apps.Document; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.fo.Constants; | |||
import org.apache.fop.fo.FOInputHandler; | |||
@@ -61,6 +61,7 @@ public class MIFHandler extends FOInputHandler { | |||
/** the MIFFile instance */ | |||
protected MIFFile mifFile; | |||
/** the OutputStream to write to */ | |||
protected OutputStream outStream; | |||
@@ -70,10 +71,11 @@ public class MIFHandler extends FOInputHandler { | |||
/** | |||
* Creates a new MIF handler on a given OutputStream. | |||
* @param ua FOUserAgent instance for this process | |||
* @param os OutputStream to write to | |||
*/ | |||
public MIFHandler(Document doc, OutputStream os) { | |||
super(doc); | |||
public MIFHandler(FOUserAgent ua, OutputStream os) { | |||
super(ua); | |||
outStream = os; | |||
FontSetup.setup(fontInfo, null); | |||
} |
@@ -27,6 +27,7 @@ import java.util.Iterator; | |||
import org.apache.commons.logging.impl.SimpleLog; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.fo.FOInputHandler; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.flow.BasicLink; | |||
@@ -57,7 +58,6 @@ import org.apache.fop.fo.properties.Property; | |||
import org.apache.fop.fo.properties.StringProperty; | |||
import org.apache.fop.fo.Constants; | |||
import org.apache.fop.fo.FOText; | |||
import org.apache.fop.apps.Document; | |||
import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes; | |||
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfAfterContainer; | |||
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfBeforeContainer; | |||
@@ -122,11 +122,11 @@ public class RTFHandler extends FOInputHandler { | |||
/** | |||
* Creates a new RTF structure handler. | |||
* @param doc the Document for which this RTFHandler is processing | |||
* @param userAgent the FOUserAgent for this process | |||
* @param os OutputStream to write to | |||
*/ | |||
public RTFHandler(Document doc, OutputStream os) { | |||
super(doc); | |||
public RTFHandler(FOUserAgent userAgent, OutputStream os) { | |||
super(userAgent); | |||
this.os = os; | |||
bDefer = false; | |||
bDeferredExecution = false; |
@@ -18,7 +18,6 @@ | |||
package org.apache.fop.render.svg; | |||
import org.apache.fop.apps.Document; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.area.PageViewport; | |||
import org.apache.fop.area.Title; |