You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2001/02/16 10:28:33 UTC

cvs commit: xml-batik/xdocs rasterizerTutorial.xml

tkormann    01/02/16 01:28:33

  Modified:    samples/tests test.css
               sources/org/apache/batik/bridge ConcreteGVTBuilder.java
                        DocumentLoader.java URIResolver.java
               xdocs    rasterizerTutorial.xml
  Log:
  update document loader cache policy.
  Now a document can not be removed from the cache if it's tagged as 'in-progress'.
  
  Revision  Changes    Path
  1.3       +2 -2      xml-batik/samples/tests/test.css
  
  Index: test.css
  ===================================================================
  RCS file: /home/cvs/xml-batik/samples/tests/test.css,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- test.css	2001/01/19 03:23:14	1.2
  +++ test.css	2001/02/16 09:28:31	1.3
  @@ -1,11 +1,11 @@
   
   .title {
  -  font-family: Verdana, Helvetica; 
  +  font-family: Arial, Helvetica; 
     font-size: 16;
     text-anchor: middle;
   }
   .legend {
  -  font-family: Verdana, Helvetica; 
  +  font-family: Arial, Helvetica; 
     font-size: 10;
     text-anchor: middle;
   }
  
  
  
  1.8       +4 -1      xml-batik/sources/org/apache/batik/bridge/ConcreteGVTBuilder.java
  
  Index: ConcreteGVTBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/ConcreteGVTBuilder.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ConcreteGVTBuilder.java	2001/02/11 20:36:41	1.7
  +++ ConcreteGVTBuilder.java	2001/02/16 09:28:32	1.8
  @@ -53,7 +53,7 @@
    * @author <a href="mailto:etissandier@ilog.fr">Emmanuel Tissandier</a>
    * @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: ConcreteGVTBuilder.java,v 1.7 2001/02/11 20:36:41 hillion Exp $
  + * @version $Id: ConcreteGVTBuilder.java,v 1.8 2001/02/16 09:28:32 tkormann Exp $
    */
   public class ConcreteGVTBuilder implements GVTBuilder, SVGConstants {
       /**
  @@ -105,6 +105,9 @@
                   root.getChildren().add(treeRoot);
               }
           }
  +        // inform the document loader that the specified document is
  +        // no more in progress
  +        ctx.getDocumentLoader().dispose(svgDocument);
           return root;
       }
   
  
  
  
  1.7       +67 -22    xml-batik/sources/org/apache/batik/bridge/DocumentLoader.java
  
  Index: DocumentLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/DocumentLoader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DocumentLoader.java	2001/02/13 16:21:12	1.6
  +++ DocumentLoader.java	2001/02/16 09:28:32	1.7
  @@ -15,6 +15,7 @@
   import java.util.List;
   import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
   import org.apache.batik.dom.svg.SVGDocumentFactory;
  +import org.apache.batik.dom.util.DocumentDescriptor;
   import org.w3c.dom.DOMException;
   import org.w3c.dom.Document;
   import org.w3c.dom.Node;
  @@ -24,7 +25,7 @@
    * This class is responsible on loading an SVG document.
    *
    * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
  - * @version $Id: DocumentLoader.java,v 1.6 2001/02/13 16:21:12 tkormann Exp $
  + * @version $Id: DocumentLoader.java,v 1.7 2001/02/16 09:28:32 tkormann Exp $
    */
   public class DocumentLoader {
   
  @@ -48,13 +49,16 @@
       private HashMap documentMap = new HashMap();
   
       /**
  -     * A list of the <tt>DocumentState</tt>. Each time a document is
  -     * loaded, the first item becomes this document.
  -     *
  -     * WARNING: tagged private as no element of this List should be
  -     * referenced outside of this class.
  +     * A list of the cached documents that can be removed from the
  +     * cache at any time.
  +     */
  +    private List cachedDocs = new LinkedList();
  +
  +    /**
  +     * A list of the <tt>DocumentState</tt> that represents the
  +     * documents in progress.
        */
  -    private List documentList = new LinkedList();
  +    private List currentDocs = new LinkedList();
   
       /**
        * The current number of cached nodes.
  @@ -64,7 +68,7 @@
       /**
        * The size of the cache.
        */
  -    protected int size;
  +    private int size;
   
       /**
        * Constructs a new <tt>DocumentLoader</tt>.
  @@ -102,9 +106,12 @@
           Document document = (Document) documentMap.get(uri);
           if (document != null) {
               //System.out.println("reusing: "+uri);
  -            DocumentState state = getDocumentState(document);
  -            documentList.remove(state);
  -            documentList.add(0, state);
  +            DocumentState state = getDocumentState(cachedDocs, document);
  +            // move the state if the document is cached and not in progress
  +            if (state != null) {
  +                cachedDocs.remove(state);
  +                cachedDocs.add(0, state);
  +            }
           } else {
               //System.out.println("loading: "+uri);
               // load the document
  @@ -112,38 +119,67 @@
               // update the cache
               int num = getNodeCount(document.getDocumentElement());
               while ((currentCachedNodeCount + num) > size &&
  -                    documentList.size() > 0) {
  +                    cachedDocs.size() > 0) {
                   // remove the oldest document loaded
  -                int i = documentList.size()-1;
  -                DocumentState state = (DocumentState) documentList.get(i);
  -                documentList.remove(i);
  +                int i = cachedDocs.size()-1;
  +                DocumentState state = (DocumentState)cachedDocs.get(i);
  +                cachedDocs.remove(i);
                   documentMap.remove(state.uri);
                   currentCachedNodeCount -= state.nodeCount;
               }
               currentCachedNodeCount += num;
               // add the new loaded document to the cache
  -            DocumentState state = new DocumentState(uri, document, num);
  -            documentList.add(0, state);
  +            DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
  +            DocumentState state = new DocumentState(uri, document, num, desc);
  +            currentDocs.add(0, state);
               documentMap.put(uri, document);
           }
           return document;
       }
   
       /**
  +     * Disposes and releases all resources allocated for the specified
  +     * document. It's the document loader's responsability to
  +     * physically removed the specified document from the cache when
  +     * needed. The specified document is in fact just tagged as no
  +     * more in progress.
  +     *
  +     * @param document the document to dispose
  +     */
  +    public void dispose(Document document) {
  +        DocumentState state = getDocumentState(currentDocs, document);
  +        if (state != null) {
  +            //System.out.println("disposing "+state.document);
  +            // allow GC of the DocumentDescriptor
  +            state.desc = null;
  +            // remove the state from the 'in progress' list
  +            currentDocs.remove(state);
  +            // add the state to the cached document list. The document
  +            // is tagged as no more in progress and can be removed
  +            // from the cache at any time
  +            cachedDocs.add(0, state);
  +        }
  +    }
  +
  +    /**
        * Disposes and releases all resources allocated by this document loader.
        */
       public void dispose() {
  -        //System.out.println("disposing...");
  +        if (currentDocs.size() > 0) {
  +            System.err.println(
  +                "WARNING: The loader still has "+currentDocs.size()+" documents marked in progress.");
  +        }
  +        //System.out.println("purge the cache");
           documentMap.clear();
  -        documentList.clear();
  +        cachedDocs.clear();
       }
   
       /**
        * Returns the <tt>DocumentState</tt> of the specified Document.
        * @param document the document
        */
  -    protected DocumentState getDocumentState(Document document) {
  -        for (Iterator i = documentList.iterator(); i.hasNext();) {
  +    protected DocumentState getDocumentState(List l, Document document) {
  +        for (Iterator i = l.iterator(); i.hasNext();) {
               DocumentState state = (DocumentState) i.next();
               if (state.document == document) {
                   return state;
  @@ -171,11 +207,20 @@
           private String uri;
           private Document document;
           private int nodeCount;
  +        private DocumentDescriptor desc;
   
  -        public DocumentState(String uri, Document document, int nodeCount) {
  +        public DocumentState(String uri,
  +                             Document document,
  +                             int nodeCount,
  +                             DocumentDescriptor desc) {
               this.uri = uri;
               this.document = document;
               this.nodeCount = nodeCount;
  +            this.desc = desc;
  +        }
  +
  +        public DocumentDescriptor getDocumentDescriptor() {
  +            return desc;
           }
   
           public String getURI() {
  
  
  
  1.3       +2 -2      xml-batik/sources/org/apache/batik/bridge/URIResolver.java
  
  Index: URIResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/URIResolver.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- URIResolver.java	2001/02/11 20:36:41	1.2
  +++ URIResolver.java	2001/02/16 09:28:32	1.3
  @@ -30,7 +30,7 @@
    * This class is used to resolve the URI that can be found in a SVG document.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: URIResolver.java,v 1.2 2001/02/11 20:36:41 hillion Exp $
  + * @version $Id: URIResolver.java,v 1.3 2001/02/16 09:28:32 tkormann Exp $
    */
   public class URIResolver {
       /**
  @@ -92,7 +92,7 @@
   
           URL url = new URL(((SVGOMDocument)document).getURLObject(), uri);
           Document doc = documentLoader.loadDocument(url.toString());
  -
  +        documentLoader.dispose(doc);
           String ref = url.getRef();
           if (url.getRef() == null) {
               return doc;
  
  
  
  1.6       +3 -3      xml-batik/xdocs/rasterizerTutorial.xml
  
  Index: rasterizerTutorial.xml
  ===================================================================
  RCS file: /home/cvs/xml-batik/xdocs/rasterizerTutorial.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- rasterizerTutorial.xml	2001/01/17 23:55:27	1.5
  +++ rasterizerTutorial.xml	2001/02/16 09:28:33	1.6
  @@ -11,7 +11,7 @@
   
   <!-- ========================================================================= -->
   <!-- author tkormann@apache.org                                                -->
  -<!-- version $Id: rasterizerTutorial.xml,v 1.5 2001/01/17 23:55:27 tkormann Exp $ -->      
  +<!-- version $Id: rasterizerTutorial.xml,v 1.6 2001/02/16 09:28:33 tkormann Exp $ -->      
   <!-- ========================================================================= -->
   
   <document>
  @@ -234,9 +234,9 @@
                        String outputFilename,
                        Rectangle aoi) throws Exception {
           <strong>trans.addTranscodingHint(JPEGTranscoder.KEY_WIDTH,
  -                                 new Integer(aoi.width));</strong>
  +                                 new Float(aoi.width));</strong>
           <strong>trans.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT,
  -                                 new Integer(aoi.height));</strong>
  +                                 new Float(aoi.height));</strong>
           <strong>trans.addTranscodingHint(JPEGTranscoder.KEY_AOI, aoi);</strong>
           String svgURI = new File(inputFilename).toURL().toString();
           TranscoderInput input = new TranscoderInput(svgURI);