/* output: text file */
private static final int TXT_OUTPUT = 6;
+ /* System buffers */
+ private static final int BUFFER_FILE = 7;
+
/* use debug mode*/
Boolean errorDump = new Boolean(false);
/* show configuration information */
File xmlfile = null;
/* name of output file */
File outfile = null;
+ /* name of buffer file */
+ File bufferFile = null;
/* input mode */
int inputmode = NOT_SET;
/*output mode */
int outputmode = NOT_SET;
+ /* buffer mode */
+ int buffermode = NOT_SET;
/* language for user information */
String language = null;
} else {
throw new FOPException("Don't know what to do with " + args[i]);
}
+ } else if (args[i].equals("-buf")) {
+ if (buffermode == NOT_SET) {
+ buffermode = BUFFER_FILE;
+ } else {
+ MessageHandler.errorln("ERROR: you can only set one buffer method");
+ printUsage();
+ }
+ if ((i + 1 == args.length) ||
+ (args[i + 1].charAt(0) == '-')) {
+ MessageHandler.errorln("ERROR: you must specify the buffer output file");
+ printUsage();
+ } else {
+ bufferFile = new File (args[i + 1]);
+ i++;
+ }
} else {
printUsage();
return false;
return language;
}
+ public File getBufferFile() {
+ return bufferFile;
+ }
+
public Boolean isQuiet() {
return quiet;
}
XMLReader parser = inputHandler.getParser();
setParserFeatures(parser);
+
+ Driver driver = new Driver();
+ driver.setBufferFile(commandLineOptions.getBufferFile());
- Driver driver = new Driver();
if (errorDump) {
driver.setErrorDump(true);
}
-/*
+/* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources."
import org.apache.fop.tools.DocumentInputSource;
import org.apache.fop.tools.DocumentReader;
+import org.apache.fop.system.BufferManager;
// DOM
import org.w3c.dom.Document;
/** If true, full error stacks are reported */
private boolean _errorDump = false;
+ /** the system resources that FOP will use */
+ private BufferManager _bufferManager;
+
/** create a new Driver */
public Driver() {
_stream = null;
- _treeBuilder = new FOTreeBuilder();
+ _bufferManager = new BufferManager();
+ _treeBuilder = new FOTreeBuilder();
+ _treeBuilder.setBufferManager(_bufferManager);
setupDefaultMappings();
}
}
}
+ /* Set up the system buffers */
+
+ public void setBufferFile(File bufferFile) {
+ this._bufferManager.addBufferFile(bufferFile);
+ }
+
/**
* format the formatting object tree into an area tree
*/
/*-- $Id$ --
-
- ============================================================================
- The Apache Software License, Version 1.1
- ============================================================================
-
- Copyright (C) 1999 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
- APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (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 <jtauber@jtauber.com>. For more information on the Apache
- Software Foundation, please see <http://www.apache.org/>.
-
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources."
*/
+
package org.apache.fop.fo;
// FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.layout.Area;
import org.apache.fop.layout.LinkSet;
+import org.apache.fop.system.BufferManager;
// Java
import java.util.Vector;
protected FObj parent;
+ public BufferManager bufferManager;
+
public Vector children = new Vector(); // made public for searching for id's
/** value of marker before layout begins */
protected FONode(FObj parent) {
this.parent = parent;
+ if (parent != null) {
+ this.bufferManager = parent.bufferManager;
+ }
}
public void setIsInTableCell() {
return this.parent;
}
+ public void setBufferManager(BufferManager bufferManager) {
+ this.bufferManager = bufferManager;
+ }
+
+ public BufferManager getBufferManager() {
+ return this.bufferManager;
+ }
+
public void setLinkSet(LinkSet linkSet) {
this.linkSet = linkSet;
for (int i = 0; i < this.children.size(); i++) {
return;
int numChildren = this.children.size();
+
+ if (this.marker <= START)
+ {
+ return;
+ }
+
for (int i = this.marker + 1; i < numChildren; i++) {
FONode fo = (FONode) children.elementAt(i);
fo.resetMarker();
-/*-- $Id$ --
-
- ============================================================================
- The Apache Software License, Version 1.1
- ============================================================================
-
- Copyright (C) 1999 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
- APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (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 <jtauber@jtauber.com>. For more information on the Apache
- Software Foundation, please see <http://www.apache.org/>.
-
+/* $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources."
*/
package org.apache.fop.fo;
import org.apache.fop.datatypes.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.system.BufferManager;
/**
* a text node in the formatting object tree
*/
public class FOText extends FONode {
- protected char[] ca;
+ // protected char[] ca;
protected int start;
protected int length;
public FOText(char[] chars, int s, int e, FObj parent) {
super(parent);
this.start = 0;
- this.ca = new char[e - s];
+ char ca[] = new char[e - s];
for (int i = s; i < e; i++)
- this.ca[i - s] = chars[i];
+ ca[i - s] = chars[i];
this.length = e - s;
+ this.bufferManager = parent.bufferManager;
+ if (this.bufferManager != null) {
+ bufferManager.writeBuffer((Object) this, ca);
+ }
+ else {
+ System.out.println("abnormal exit");
+ System.exit(0);
+ }
}
public void setUnderlined(boolean ul) {
public boolean willCreateArea()
{
+ char ca[] = this.bufferManager.readBuffer((Object) this);
this.whiteSpaceCollapse = this.parent.properties.get(
"white-space-collapse").getEnum();
if(this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE && length > 0) {
return true;
}
+
for (int i = start; i < start + length; i++) {
char ch = ca[i];
if (!((ch == ' ') || (ch == '\n') || (ch == '\r') ||
}
public Status layout(Area area) throws FOPException {
+ char ca[] = this.bufferManager.readBuffer((Object) this);
if (!(area instanceof BlockArea)) {
MessageHandler.errorln("WARNING: text outside block area" +
new String(ca, start, length));
this.red = c.red();
this.green = c.green();
this.blue = c.blue();
-
+
this.verticalAlign = this.parent.properties.get("vertical-align").getEnum();
this.wrapOption =
import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.pagination.Root;
+import org.apache.fop.system.BufferManager;
+
// SAX
import org.xml.sax.helpers.DefaultHandler;
*/
protected FObj rootFObj = null;
- /**
+ public BufferManager bufferManager;
+
+ /**
* set of names of formatting objects encountered but unknown
*/
protected Hashtable unknownFOs = new Hashtable();
if (rootFObj == null) {
rootFObj = fobj;
+ rootFObj.setBufferManager(this.bufferManager);
if (!fobj.getName().equals("fo:root")) {
throw new SAXException(
new FOPException("Root element must" +
*/
public void format(AreaTree areaTree) throws FOPException {
MessageHandler.logln("formatting FOs into areas");
+ this.bufferManager.readComplete();
((Root) this.rootFObj).format(areaTree);
}
{
return (rootFObj != null);
}
-
+
+ public void setBufferManager(BufferManager bufferManager) {
+ this.bufferManager = bufferManager;
+ }
}
--- /dev/null
+/* $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources."
+ */
+
+// Seshadri
+/* This package is to be used for all Oeprating System related activities. */
+/* This buffers data into an array in memory */
+
+ package org.apache.fop.system;
+
+
+// FOP
+
+
+
+// Java
+
+
+public class BufferArray {
+
+
+ public BufferArray() {
+
+ }
+
+}
+
--- /dev/null
+/* $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources."
+ */
+
+// Seshadri
+/* This package is to be used for all Oeprating System related activities. */
+/* This buffers data into a file */
+
+
+
+package org.apache.fop.system;
+
+
+import java.io.*;
+
+
+
+public class BufferFile {
+
+ public BufferFile () {
+
+ }
+
+}
--- /dev/null
+/* $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources."
+ */
+
+// Seshadri
+/* This package is to be used for all Oeprating System related activities.
+ This file manages system buffers */
+
+package org.apache.fop.system;
+
+
+// FOP
+
+import org.apache.fop.fo.FONode;
+
+
+// Java
+
+ import java.io.*;
+ import java.util.Hashtable;
+
+
+public class BufferManager {
+
+
+ protected FileWriter fw;
+ protected FileReader fr;
+ protected char cache[]; // Cache
+ protected long csize; //Cache size
+
+
+ protected File buff=null;
+
+ protected long fp = 0;
+
+ protected long markStart=0; // used to set the current point in the stream while reading
+ protected long markEnd=0;
+ protected long curMark=0;
+
+ // Hash of objects and their offsets within
+
+ Hashtable offSetTable = new Hashtable();
+
+ private class Offset {
+
+ long fp=0; // File Pointer
+ int length;
+ char[] data; // when no buffer is specified
+
+ Offset(long fp,int length,char data[]) {
+ this.fp = fp;
+ this.length = length;
+ this.data = data;
+ }
+ }
+
+
+
+ public void addBufferFile(File buff) {
+
+ if (buff != null)
+ try {
+ fw = new FileWriter(buff);
+ fr = new FileReader(buff);
+ csize = 100000;
+ this.buff = buff;
+ }
+ catch (Exception e) {
+ System.out.println(e);
+ }
+
+ }
+
+ public void writeBuffer(Object obj,char arr[]) {
+
+ int length = arr.length;
+
+ if (buff != null) {
+ offSetTable.put(obj, new Offset(this.fp,length,null));
+ try {
+ fw.write(arr);
+
+ this.fp += length;
+ }
+
+ catch (Exception e) {
+ System.out.println(e);
+ }
+ }
+ else {
+ // Store the data in memory
+ offSetTable.put(obj, new Offset(this.fp,length,arr));
+ }
+
+
+ }
+
+
+public void readComplete() {
+
+ // An indication that manager can close the writable buffers and prepare
+ // for reading..
+ if (buff != null)
+ try {
+
+ fw.close();
+
+ cache = new char[(int) csize];
+ setupCache(curMark);
+
+ }
+ catch (Exception e) {
+ System.out.println(e);
+ }
+}
+
+
+
+
+ public char[] readBuffer(Object obj) {
+
+ Offset values = (Offset) offSetTable.get(obj);
+
+ // Was buffering used?
+
+ if (buff != null) {
+
+
+ char ca[] = new char[values.length];
+
+ // Check if csize is too small
+
+ if (csize < values.length) {
+ System.out.println("Cache size too small");
+ System.exit(0);
+ }
+
+
+ // Is the data outside the cache?
+
+ if (! (values.fp >= markStart && values.fp + values.length <= markEnd)) {
+
+ setupCache(values.fp);
+ }
+
+
+ for (long i = values.fp - markStart,j=0; j < values.length; ++i,++j) {
+
+ ca[(int)j] = cache[(int)i];
+ }
+
+
+ return ca;
+ }
+ else {
+ return values.data;
+ }
+ }
+
+ protected void setupCache(long curMark) {
+
+ try {
+
+ FileReader fr = new FileReader(buff);
+ fr.skip(curMark);
+
+ long rem = buff.length() - curMark;
+ if (rem > csize) {
+
+ rem = csize;
+ }
+
+ fr.read(cache,0,(int)rem);
+
+
+ markStart = curMark;
+ markEnd = rem - 1;
+
+ }
+ catch (Exception e) {
+ System.out.println(e);
+ }
+
+
+ }
+
+
+}