瀏覽代碼

Seshadri G.K.: memory buffering


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194257 13f79535-47bb-0310-9956-ffa450edef68
pull/33/head
arved 23 年之前
父節點
當前提交
a7de5c5cad

+ 26
- 0
src/org/apache/fop/apps/CommandLineOptions.java 查看文件

/* output: text file */ /* output: text file */
private static final int TXT_OUTPUT = 6; private static final int TXT_OUTPUT = 6;


/* System buffers */
private static final int BUFFER_FILE = 7;
/* use debug mode*/ /* use debug mode*/
Boolean errorDump = new Boolean(false); Boolean errorDump = new Boolean(false);
/* show configuration information */ /* show configuration information */
File xmlfile = null; File xmlfile = null;
/* name of output file */ /* name of output file */
File outfile = null; File outfile = null;
/* name of buffer file */
File bufferFile = null;
/* input mode */ /* input mode */
int inputmode = NOT_SET; int inputmode = NOT_SET;
/*output mode */ /*output mode */
int outputmode = NOT_SET; int outputmode = NOT_SET;
/* buffer mode */
int buffermode = NOT_SET;
/* language for user information */ /* language for user information */
String language = null; String language = null;


} else { } else {
throw new FOPException("Don't know what to do with " + args[i]); 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 { } else {
printUsage(); printUsage();
return false; return false;
return language; return language;
} }


public File getBufferFile() {
return bufferFile;
}
public Boolean isQuiet() { public Boolean isQuiet() {
return quiet; return quiet;
} }

+ 3
- 1
src/org/apache/fop/apps/CommandLineStarter.java 查看文件



XMLReader parser = inputHandler.getParser(); XMLReader parser = inputHandler.getParser();
setParserFeatures(parser); setParserFeatures(parser);
Driver driver = new Driver();
driver.setBufferFile(commandLineOptions.getBufferFile());


Driver driver = new Driver();
if (errorDump) { if (errorDump) {
driver.setErrorDump(true); driver.setErrorDump(true);
} }

+ 14
- 2
src/org/apache/fop/apps/Driver.java 查看文件

/*
/* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the * For details on use and redistribution please refer to the
* LICENSE file included with these sources." * LICENSE file included with these sources."
import org.apache.fop.tools.DocumentInputSource; import org.apache.fop.tools.DocumentInputSource;
import org.apache.fop.tools.DocumentReader; import org.apache.fop.tools.DocumentReader;


import org.apache.fop.system.BufferManager;


// DOM // DOM
import org.w3c.dom.Document; import org.w3c.dom.Document;
/** If true, full error stacks are reported */ /** If true, full error stacks are reported */
private boolean _errorDump = false; private boolean _errorDump = false;


/** the system resources that FOP will use */
private BufferManager _bufferManager;

/** create a new Driver */ /** create a new Driver */
public Driver() { public Driver() {
_stream = null; _stream = null;
_treeBuilder = new FOTreeBuilder();
_bufferManager = new BufferManager();
_treeBuilder = new FOTreeBuilder();
_treeBuilder.setBufferManager(_bufferManager);
setupDefaultMappings(); setupDefaultMappings();
} }


} }
} }


/* Set up the system buffers */
public void setBufferFile(File bufferFile) {
this._bufferManager.addBufferFile(bufferFile);
}
/** /**
* format the formatting object tree into an area tree * format the formatting object tree into an area tree
*/ */

+ 24
- 48
src/org/apache/fop/fo/FONode.java 查看文件

/*-- $Id$ -- /*-- $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; package org.apache.fop.fo;


// FOP // FOP
import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOPException;
import org.apache.fop.layout.Area; import org.apache.fop.layout.Area;
import org.apache.fop.layout.LinkSet; import org.apache.fop.layout.LinkSet;
import org.apache.fop.system.BufferManager;


// Java // Java
import java.util.Vector; import java.util.Vector;


protected FObj parent; protected FObj parent;


public BufferManager bufferManager;
public Vector children = new Vector(); // made public for searching for id's public Vector children = new Vector(); // made public for searching for id's


/** value of marker before layout begins */ /** value of marker before layout begins */


protected FONode(FObj parent) { protected FONode(FObj parent) {
this.parent = parent; this.parent = parent;
if (parent != null) {
this.bufferManager = parent.bufferManager;
}
} }


public void setIsInTableCell() { public void setIsInTableCell() {
return this.parent; return this.parent;
} }


public void setBufferManager(BufferManager bufferManager) {
this.bufferManager = bufferManager;
}
public BufferManager getBufferManager() {
return this.bufferManager;
}
public void setLinkSet(LinkSet linkSet) { public void setLinkSet(LinkSet linkSet) {
this.linkSet = linkSet; this.linkSet = linkSet;
for (int i = 0; i < this.children.size(); i++) { for (int i = 0; i < this.children.size(); i++) {
return; return;
int numChildren = this.children.size(); int numChildren = this.children.size();
if (this.marker <= START)
{
return;
}
for (int i = this.marker + 1; i < numChildren; i++) { for (int i = this.marker + 1; i < numChildren; i++) {
FONode fo = (FONode) children.elementAt(i); FONode fo = (FONode) children.elementAt(i);
fo.resetMarker(); fo.resetMarker();

+ 20
- 53
src/org/apache/fop/fo/FOText.java 查看文件

/*-- $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; package org.apache.fop.fo;
import org.apache.fop.datatypes.*; import org.apache.fop.datatypes.*;
import org.apache.fop.fo.properties.*; import org.apache.fop.fo.properties.*;
import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOPException;
import org.apache.fop.system.BufferManager;


/** /**
* a text node in the formatting object tree * a text node in the formatting object tree
*/ */
public class FOText extends FONode { public class FOText extends FONode {


protected char[] ca;
// protected char[] ca;
protected int start; protected int start;
protected int length; protected int length;


public FOText(char[] chars, int s, int e, FObj parent) { public FOText(char[] chars, int s, int e, FObj parent) {
super(parent); super(parent);
this.start = 0; this.start = 0;
this.ca = new char[e - s];
char ca[] = new char[e - s];
for (int i = s; i < e; i++) for (int i = s; i < e; i++)
this.ca[i - s] = chars[i];
ca[i - s] = chars[i];
this.length = e - s; 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 void setUnderlined(boolean ul) {


public boolean willCreateArea() public boolean willCreateArea()
{ {
char ca[] = this.bufferManager.readBuffer((Object) this);
this.whiteSpaceCollapse = this.parent.properties.get( this.whiteSpaceCollapse = this.parent.properties.get(
"white-space-collapse").getEnum(); "white-space-collapse").getEnum();
if(this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE && length > 0) { if(this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE && length > 0) {
return true; return true;
} }
for (int i = start; i < start + length; i++) { for (int i = start; i < start + length; i++) {
char ch = ca[i]; char ch = ca[i];
if (!((ch == ' ') || (ch == '\n') || (ch == '\r') || if (!((ch == ' ') || (ch == '\n') || (ch == '\r') ||
} }


public Status layout(Area area) throws FOPException { public Status layout(Area area) throws FOPException {
char ca[] = this.bufferManager.readBuffer((Object) this);
if (!(area instanceof BlockArea)) { if (!(area instanceof BlockArea)) {
MessageHandler.errorln("WARNING: text outside block area" + MessageHandler.errorln("WARNING: text outside block area" +
new String(ca, start, length)); new String(ca, start, length));
this.red = c.red(); this.red = c.red();
this.green = c.green(); this.green = c.green();
this.blue = c.blue(); this.blue = c.blue();
this.verticalAlign = this.parent.properties.get("vertical-align").getEnum(); this.verticalAlign = this.parent.properties.get("vertical-align").getEnum();


this.wrapOption = this.wrapOption =

+ 11
- 2
src/org/apache/fop/fo/FOTreeBuilder.java 查看文件

import org.apache.fop.messaging.MessageHandler; import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.pagination.Root; import org.apache.fop.fo.pagination.Root;
import org.apache.fop.system.BufferManager;



// SAX // SAX
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
*/ */
protected FObj rootFObj = null; protected FObj rootFObj = null;


/**
public BufferManager bufferManager;
/**
* set of names of formatting objects encountered but unknown * set of names of formatting objects encountered but unknown
*/ */
protected Hashtable unknownFOs = new Hashtable(); protected Hashtable unknownFOs = new Hashtable();


if (rootFObj == null) { if (rootFObj == null) {
rootFObj = fobj; rootFObj = fobj;
rootFObj.setBufferManager(this.bufferManager);
if (!fobj.getName().equals("fo:root")) { if (!fobj.getName().equals("fo:root")) {
throw new SAXException( throw new SAXException(
new FOPException("Root element must" + new FOPException("Root element must" +
*/ */
public void format(AreaTree areaTree) throws FOPException { public void format(AreaTree areaTree) throws FOPException {
MessageHandler.logln("formatting FOs into areas"); MessageHandler.logln("formatting FOs into areas");
this.bufferManager.readComplete();
((Root) this.rootFObj).format(areaTree); ((Root) this.rootFObj).format(areaTree);
} }


{ {
return (rootFObj != null); return (rootFObj != null);
} }

public void setBufferManager(BufferManager bufferManager) {
this.bufferManager = bufferManager;
}
} }

+ 29
- 0
src/org/apache/fop/system/BufferArray.java 查看文件

/* $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() {
}
}

+ 26
- 0
src/org/apache/fop/system/BufferFile.java 查看文件

/* $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 () {
}
}

+ 190
- 0
src/org/apache/fop/system/BufferManager.java 查看文件

/* $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);
}
}
}

Loading…
取消
儲存