Author: vgritsenko
Date: Wed Mar 14 20:47:19 2007
New Revision: 518460

URL: http://svn.apache.org/viewvc?view=rev&rev=518460
Log:
cleanup, rest of the patch from bug #41808

Modified:
    
xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/ResourceSetImpl.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
    xml/xindice/trunk/java/src/org/apache/xindice/util/ByteArrayInput.java
    xml/xindice/trunk/java/src/org/apache/xindice/util/SymbolSerializer.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedInput.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedOutput.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/AttrImpl.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/CharacterDataImpl.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ContainerNodeImpl.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DocumentImpl.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ElementImpl.java
    
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/EntityReferenceImpl.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java
    xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
    
xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/CompressedDOMTests.java

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/ResourceSetImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/ResourceSetImpl.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/ResourceSetImpl.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/ResourceSetImpl.java 
Wed Mar 14 20:47:19 2007
@@ -30,7 +30,6 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.xmldb.api.base.ErrorCodes;
 import org.xmldb.api.base.Resource;
 import org.xmldb.api.base.ResourceIterator;
 import org.xmldb.api.base.ResourceSet;
@@ -79,39 +78,31 @@
 
     protected void initResources(Document document) throws XMLDBException {
         NodeList nodes = document.getDocumentElement().getChildNodes();
-        this.resources =
-                Collections.synchronizedList(new ArrayList(nodes.getLength()));
+        this.resources = Collections.synchronizedList(new 
ArrayList(nodes.getLength()));
 
         int i = 0;
         while (i < nodes.getLength()) {
-            try {
-                XMLResource resource;
-                Node n = nodes.item(i);
-
-                String documentId = null;
-                if (n instanceof Element) {
-                    documentId = ((Element) n).getAttributeNS(
-                            NodeSource.SOURCE_NS, NodeSource.SOURCE_KEY);
-                }
-
-                if (bytes != null) {
-                    DocumentImpl doc = new DocumentImpl();
-                    doc.setSymbols(symbols);
-                    doc.importNode(n, true);
-                    doc.appendChild(n);
-                    byte[] b = DOMCompressor.Compress(doc, symbols);
-                    resource = new XMLResourceImpl(null, documentId, 
collection,
-                                                   symbols, b);
-                } else {
-                    resource = new XMLResourceImpl(null, documentId, 
collection,
-                                                   TextWriter.toString(n));
-                }
-
-                i++;
-                resources.add(resource);
-            } catch (Exception e) {
-                throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e);
+            Node n = nodes.item(i);
+
+            String documentId = null;
+            if (n instanceof Element) {
+                documentId = ((Element) 
n).getAttributeNS(NodeSource.SOURCE_NS, NodeSource.SOURCE_KEY);
+            }
+
+            XMLResource resource;
+            if (bytes != null) {
+                DocumentImpl doc = new DocumentImpl();
+                doc.setSymbols(symbols);
+                doc.importNode(n, true);
+                doc.appendChild(n);
+                byte[] b = DOMCompressor.compress(doc, symbols);
+                resource = new XMLResourceImpl(null, documentId, collection, 
symbols, b);
+            } else {
+                resource = new XMLResourceImpl(null, documentId, collection, 
TextWriter.toString(n));
             }
+
+            i++;
+            resources.add(resource);
         }
     }
 
@@ -214,8 +205,6 @@
             i++;
         }
 
-        XMLResource result = new XMLResourceImpl(null, null,
-                                                 collection, 
TextWriter.toString(doc));
-        return result;
+        return new XMLResourceImpl(null, null, collection, 
TextWriter.toString(doc));
     }
 }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Wed Mar 
14 20:47:19 2007
@@ -817,10 +817,10 @@
         if (log.isDebugEnabled()) {
             log.debug(debugHeader() + "Get object: " + key);
         }
-        String className = null;
 
         Document doc = getDocument(key);
         if (doc != null) {
+            String className = null;
             NodeList childNodes = doc.getChildNodes();
             int size = childNodes.getLength();
             for (int i = 0; i < size; i++) {
@@ -1057,7 +1057,7 @@
 
             // Have to compress to update collection's SymbolTable,
             // which is used even for uncompressed collections
-            DOMCompressor.Compress(doc, symbols);
+            DOMCompressor.compress(doc, symbols);
 
             return doc;
         } catch (Exception e) {
@@ -1128,21 +1128,16 @@
         byte[] documentBytes;
 
         if (compressed) {
-            try {
-                documentBytes = DOMCompressor.Compress(document, symbols);
-                if (log.isTraceEnabled()) {
-                    log.trace(localDebugHeader + "length=" + 
documentBytes.length);
-                }
+            documentBytes = DOMCompressor.compress(document, symbols);
+            if (log.isTraceEnabled()) {
+                log.trace(localDebugHeader + "length=" + documentBytes.length);
+            }
 
-                // Why must it be re-created?
-                document = new DocumentImpl(documentBytes, symbols, new 
NodeSource(this, key));
-                if (log.isTraceEnabled()) {
-                    log.trace(localDebugHeader + "packedDocument: length=" + 
documentBytes.length +
-                              " document=<" + TextWriter.toString(document) + 
">");
-                }
-            } catch (Exception e) {
-                throw new DBException(FaultCodes.COL_CANNOT_STORE,
-                                      localDebugHeader + "Error compressing 
Document '" + key + "'", e);
+            // Why must it be re-created?
+            document = new DocumentImpl(documentBytes, symbols, new 
NodeSource(this, key));
+            if (log.isTraceEnabled()) {
+                log.trace(localDebugHeader + "packedDocument: length=" + 
documentBytes.length +
+                          " document=<" + TextWriter.toString(document) + ">");
             }
         } else {
             try {

Modified: xml/xindice/trunk/java/src/org/apache/xindice/util/ByteArrayInput.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/util/ByteArrayInput.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/util/ByteArrayInput.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/util/ByteArrayInput.java Wed 
Mar 14 20:47:19 2007
@@ -35,8 +35,8 @@
         super(buf);
     }
 
-    public ByteArrayInput(byte[] buf, int pos, int count) {
-        super(buf, pos, count);
+    public ByteArrayInput(byte[] buf, int pos, int length) {
+        super(buf, pos, length);
     }
 
     /**
@@ -88,4 +88,3 @@
         return new ByteArrayInput(buf, pos, count);
     }
 }
-

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/util/SymbolSerializer.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/util/SymbolSerializer.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/util/SymbolSerializer.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/util/SymbolSerializer.java 
Wed Mar 14 20:47:19 2007
@@ -47,7 +47,7 @@
     /**
      * The collection's SymbolTable
      */
-    private SymbolTable syms;
+    private final SymbolTable syms;
 
     /**
      * Last time we caught a SymbolTable modification
@@ -82,21 +82,14 @@
                 Element elem = syms.streamToXML(doc);
                 doc.appendChild(elem);
 
-                try {
-                    symBytes = DOMCompressor.Compress(doc, hcSyms);
-                    lastMod = lm;
-                } catch (Exception e) {
-                    if (log.isErrorEnabled()) {
-                        log.error("Problem compressing Symbol Table!  Very 
Bad!", e);
-                    }
-                }
+                symBytes = DOMCompressor.compress(doc, hcSyms);
+                lastMod = lm;
             }
         }
 
         Hashtable result = new Hashtable();
         //result.put("timestamp", new Long(lm));
         result.put("symbols", symBytes);
-        result.put("document", new byte[0]);
         return result;
     }
 
@@ -141,6 +134,6 @@
      * @return Last modified stamp
      */
     public long getLastModified() {
-        return lastMod;
+        return syms.getLastModified();
     }
 }

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedInput.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedInput.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedInput.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedInput.java 
Wed Mar 14 20:47:19 2007
@@ -83,7 +83,7 @@
                 } else {
                     return Node.ENTITY_REFERENCE_NODE;
                 }
-                
+
             case Signatures.Elem:
                 return Node.ELEMENT_NODE;
 
@@ -119,6 +119,7 @@
                 }
 
         }
+
         return Signatures.Unknown;
     }
 
@@ -168,7 +169,7 @@
             case Signatures.NoContent:
                 // Do Nothing
                                break;
-                               
+
             default:
                 if (log.isWarnEnabled()) {
                     log.warn("invalid size : " + sizeType);
@@ -204,7 +205,7 @@
             case Signatures.NoContent:
                 // Do Nothing
                                break;
-                               
+
             default:
                 if (log.isWarnEnabled()) {
                     log.warn("invalid signature type : " + countType);

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedOutput.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedOutput.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedOutput.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/XMLCompressedOutput.java 
Wed Mar 14 20:47:19 2007
@@ -30,7 +30,9 @@
  * @version $Revision$, $Date$
  */
 public class XMLCompressedOutput extends DataOutputStream {
-    protected SymbolTable st = null;
+
+    protected SymbolTable st;
+
 
     public XMLCompressedOutput(OutputStream os, SymbolTable st) {
         super(os);
@@ -111,5 +113,3 @@
         }
     }
 }
-
-

Modified: xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/AttrImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/AttrImpl.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/AttrImpl.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/AttrImpl.java Wed Mar 
14 20:47:19 2007
@@ -51,7 +51,7 @@
         this.nsURI = nsURI;
         this.symbolID = symbolID;
         this.nodeValue = nodeValue;
-        childNodes.clear();
+
         TextImpl text = new TextImpl(this, false);
         text.nodeValue = nodeValue;
         childNodes.add(text);
@@ -88,6 +88,7 @@
     public void setNodeValue(String nodeValue) throws DOMException {
         checkLoaded();
         checkReadOnly();
+
         childNodes.clear();
         TextImpl text = new TextImpl(this, false);
         text.nodeValue = nodeValue;
@@ -101,13 +102,7 @@
 
     protected boolean isNodeTypeValid(short type) {
         return type == Node.TEXT_NODE ||
-                type == Node.ENTITY_REFERENCE_NODE;
-    }
-
-    protected void checkLoaded() {
-        if (!loaded) {
-            loaded = true;
-        }
+               type == Node.ENTITY_REFERENCE_NODE;
     }
 
     /**

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/CharacterDataImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/CharacterDataImpl.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/CharacterDataImpl.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/CharacterDataImpl.java 
Wed Mar 14 20:47:19 2007
@@ -28,6 +28,8 @@
 import org.w3c.dom.CharacterData;
 import org.w3c.dom.DOMException;
 
+import java.io.IOException;
+
 /**
  * CharacterDataImpl
  *
@@ -60,10 +62,9 @@
     protected final void checkLoaded() {
         if (loaded) {
             return;
-        } else {
-            loaded = true;
         }
 
+        loaded = true;
         try {
             if (data != null) {
                 DocumentImpl doc = (DocumentImpl) getOwnerDocument();
@@ -83,7 +84,7 @@
                 xci.read(buf);
                 nodeValue = new String(buf, "UTF-8");
             }
-        } catch (Exception e) {
+        } catch (IOException e) {
             if (log.isWarnEnabled()) {
                 log.warn("ignored exception", e);
             }

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ContainerNodeImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ContainerNodeImpl.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ContainerNodeImpl.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ContainerNodeImpl.java 
Wed Mar 14 20:47:19 2007
@@ -81,10 +81,9 @@
     protected void checkLoaded() {
         if (loaded) {
             return;
-        } else {
-            loaded = true;
         }
 
+        loaded = true;
         try {
             if (data != null) {
                 DocumentImpl doc = (DocumentImpl) getOwnerDocument();
@@ -105,19 +104,19 @@
             // Have to skip the attributes
             in.readSignature();
             in.readContentSize();
-            in.readShort(); // Element Symbol
+            in.readShort();                          // Element Symbol
             int attrCount = in.readAttributeCount();
             for (int i = 0; i < attrCount; i++) {
-                in.readShort(); // Attribute Symbol
-                in.skip(in.readShort()); // Attribute Length
+                in.readShort();                      // Attribute Symbol
+                in.skip(in.readShort());             // Attribute Length
             }
         } else {
             in.readInt();
         }
 
-        while (bis.available() > 0) {
+        while (in.available() > 0) {
             int pos = bis.getPos();
-            in.readSignature(); // Skip signature
+            in.readSignature();             // Skip signature
             int len = in.readContentSize();
             if (len == 0) {
                 len = 1;

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DocumentImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DocumentImpl.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DocumentImpl.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DocumentImpl.java Wed 
Mar 14 20:47:19 2007
@@ -21,7 +21,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.xindice.util.XindiceException;
 import org.apache.xindice.xml.NodeSource;
 import org.apache.xindice.xml.SymbolTable;
 import org.apache.xindice.xml.dom.traversal.TreeWalkerImpl;
@@ -48,6 +47,7 @@
 import org.w3c.dom.traversal.NodeIterator;
 import org.w3c.dom.traversal.TreeWalker;
 
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
@@ -72,26 +72,42 @@
     private boolean readOnly;
     private DOMConfiguration domConfig = new DOMConfigurationImpl();
 
-
+    /**
+     * Create empty dirty document.
+     */
     public DocumentImpl() {
         super(null, true);
     }
 
-    public DocumentImpl(byte[] data, int pos, int len) {
-        super(null, data, pos, len);
-    }
-
-    public DocumentImpl(byte[] data) {
-        this(data, 0, data.length);
+    /**
+     * Create document from the compressed data.
+     *
+     * @param data compressed document data
+     * @param symbols symbol table used to compress a document
+     */
+    public DocumentImpl(byte[] data, SymbolTable symbols) {
+        super(null, data, 0, data.length);
+        this.symbols = symbols;
     }
 
+    /**
+     * Create document from the compressed data.
+     *
+     * @param data compressed document data
+     * @param symbols symbol table used to compress a document
+     * @param source identifies document origin
+     */
     public DocumentImpl(byte[] data, SymbolTable symbols, NodeSource source) {
-        this(data);
-        this.symbols = symbols;
+        this(data, symbols);
         this.source = source;
     }
 
-    public DocumentImpl(Document doc) throws XindiceException {
+    /**
+     * Create a compressed document out of another document.
+     *
+     * @param doc document to copy
+     */
+    public DocumentImpl(Document doc) {
         super(null, true);
 
         boolean compress = true;
@@ -111,7 +127,7 @@
             if (symbols == null) {
                 symbols = new SymbolTable();
             }
-            data = DOMCompressor.Compress(doc, symbols);
+            data = DOMCompressor.compress(doc, symbols);
             pos = 0;
             len = data.length;
         }
@@ -129,15 +145,14 @@
     protected void checkLoaded() {
         if (loaded) {
             return;
-        } else {
-            loaded = true;
         }
 
+        loaded = true;
         try {
             if (data != null) {
                 loadChildren(symbols);
             }
-        } catch (Exception e) {
+        } catch (IOException e) {
             if (log.isWarnEnabled()) {
                 log.warn("ignored exception", e);
             }
@@ -361,10 +376,10 @@
     }
 
     public Node importNode(Node importedNode, boolean deep) {
-               return importNode(importedNode, deep, true, true);
-       }
+        return importNode(importedNode, deep, true, true);
+    }
 
-       private Node importNode(Node importedNode, boolean deep, boolean 
importNamespaces, boolean invokeHandler) {
+    private Node importNode(Node importedNode, boolean deep, boolean 
importNamespaces, boolean invokeHandler) {
         try {
             // If we're a Xindice Compressed DOM Node, and share the same 
symbol table,
             // then we're golden
@@ -375,9 +390,9 @@
                     NodeImpl clone = (NodeImpl) impl.cloneNode(deep, false);
                     clone.setParentNode(this);
 
-                                       if (importNamespaces) {
-                                               importNamespaces(importedNode, 
clone);
-                                       }
+                    if (importNamespaces) {
+                        importNamespaces(importedNode, clone);
+                    }
                     if (invokeHandler) {
                         invokeHandlers(UserDataHandler.NODE_IMPORTED, 
importedNode, clone);
                     }
@@ -413,9 +428,9 @@
                         elem.setAttributeNode(ai);
                     }
                     result = elem;
-                                       if (importNamespaces) {
-                                               importNamespaces(importedNode, 
result);
-                                       }
+                    if (importNamespaces) {
+                        importNamespaces(importedNode, result);
+                    }
                     break;
 
                 case Node.ENTITY_REFERENCE_NODE:

Modified: xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ElementImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ElementImpl.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ElementImpl.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ElementImpl.java Wed 
Mar 14 20:47:19 2007
@@ -26,11 +26,12 @@
 import org.apache.xindice.xml.NodeSource;
 import org.apache.xindice.xml.SymbolTable;
 import org.apache.xindice.xml.XMLCompressedInput;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NamedNodeMap;
+
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
 import org.w3c.dom.TypeInfo;
 import org.w3c.dom.UserDataHandler;
 
@@ -90,10 +91,9 @@
     protected void checkLoaded() {
         if (loaded) {
             return;
-        } else {
-            loaded = true;
         }
 
+        loaded = true;
         try {
             if (data != null) {
                 DocumentImpl doc = (DocumentImpl) getOwnerDocument();
@@ -112,7 +112,7 @@
 
                 loadChildren(st);
             }
-        } catch (Exception e) {
+        } catch (IOException e) {
             if (log.isWarnEnabled()) {
                 log.warn("ignored exception", e);
             }

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/EntityReferenceImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/EntityReferenceImpl.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/EntityReferenceImpl.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/EntityReferenceImpl.java 
Wed Mar 14 20:47:19 2007
@@ -29,6 +29,8 @@
 import org.w3c.dom.EntityReference;
 import org.w3c.dom.Node;
 
+import java.io.IOException;
+
 /**
  * EntityReferenceImpl
  *
@@ -60,10 +62,9 @@
     protected void checkLoaded() {
         if (loaded) {
             return;
-        } else {
-            loaded = true;
         }
 
+        loaded = true;
         try {
             if (data != null) {
                 DocumentImpl doc = (DocumentImpl) getOwnerDocument();
@@ -116,7 +117,7 @@
                         }
                 }
             }
-        } catch (Exception e) {
+        } catch (IOException e) {
             if (log.isWarnEnabled()) {
                 log.warn("ignored exception", e);
             }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/NodeImpl.java Wed Mar 
14 20:47:19 2007
@@ -37,9 +37,9 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Set;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * NodeImpl implements the foundation of the Xindice compressed DOM.
@@ -150,19 +150,26 @@
     protected HashMap handlers;
     protected Object key;
 
-
+    /**
+     * Create empty node
+     */
     public NodeImpl() {
     }
 
-    public NodeImpl(byte[] data, int pos, int len) {
+    /**
+     * Create node from compressed data
+     *
+     * @param parentNode the parent node
+     * @param data compressed document data byte array
+     * @param pos offset in the data byte array
+     * @param len length of node's data
+     */
+    public NodeImpl(NodeImpl parentNode, byte[] data, int pos, int len) {
+        this.parentNode = parentNode;
         this.data = data;
         this.pos = pos;
         this.len = len;
-    }
 
-    public NodeImpl(NodeImpl parentNode, byte[] data, int pos, int len) {
-        this(data, pos, len);
-        this.parentNode = parentNode;
         if (parentNode == null) {
             ownerDocument = null;
         } else if (parentNode.getNodeType() == DOCUMENT_TYPE_NODE) {
@@ -174,6 +181,7 @@
 
     public NodeImpl(NodeImpl parentNode, boolean dirty) {
         this.parentNode = parentNode;
+
         if (parentNode == null) {
             ownerDocument = null;
         } else if (parentNode.getNodeType() == DOCUMENT_TYPE_NODE) {
@@ -181,6 +189,7 @@
         } else {
             this.ownerDocument = parentNode.getOwnerDocument();
         }
+
         if (dirty) {
             setDirty();
         }
@@ -534,6 +543,7 @@
 
     protected final synchronized Node cloneNode(boolean deep, boolean 
invokeHandler) {
         DocumentImpl doc = (DocumentImpl) getOwnerDocument();
+
         // compressed documents
         if (deep && this.data != null) {
             byte[] data = this.data;
@@ -541,15 +551,9 @@
             int len = this.len;
 
             if (dirty) {
-                try {
-                    data = DOMCompressor.Compress(this, doc.getSymbols());
-                    pos = 0;
-                    len = data.length;
-                } catch (Exception e) {
-                    if (log.isWarnEnabled()) {
-                        log.warn("ignored exception", e);
-                    }
-                }
+                data = DOMCompressor.compress(this, doc.getSymbols());
+                pos = 0;
+                len = data.length;
             }
 
             NodeImpl newNode = null;

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java 
Wed Mar 14 20:47:19 2007
@@ -115,17 +115,10 @@
     }
 
     public SAXEventGenerator(SymbolTable symbols, Document doc) {
-        try {
-            this.symbols = symbols != null ? symbols : new SymbolTable();
-            data = DOMCompressor.Compress(doc, this.symbols);
-            pos = 0;
-            len = data.length;
-        } catch (Exception e) {
-            // This shouldn't happen
-            if (log.isErrorEnabled()) {
-                log.error("No message", e);
-            }
-        }
+        this.symbols = symbols != null ? symbols : new SymbolTable();
+        data = DOMCompressor.compress(doc, this.symbols);
+        pos = 0;
+        len = data.length;
     }
 
     /**
@@ -340,7 +333,7 @@
                         } else {
                             tin.readInt();
                         }
-                        
+
                         byte[] buf = new byte[tbis.available()];
                         tin.read(buf);
 
@@ -362,7 +355,7 @@
                             case Node.COMMENT_NODE:
                                 // TODO: This
                                 break;
-                                
+
                             default:
                                 if (log.isWarnEnabled()) {
                                     log.warn("invalid type : " + type);
@@ -378,7 +371,7 @@
 
                 case Node.NOTATION_NODE:
                     break;
-                    
+
                 default:
                     if (log.isWarnEnabled()) {
                         log.warn("invalid node type : " + type);

Modified: 
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- 
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java 
(original)
+++ 
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java 
Wed Mar 14 20:47:19 2007
@@ -23,7 +23,10 @@
 import org.apache.xindice.core.query.XPathQueryResolver;
 import org.apache.xindice.util.Configuration;
 import org.apache.xindice.xml.TextWriter;
+import org.apache.xindice.xml.SymbolTable;
 import org.apache.xindice.xml.dom.DOMParser;
+import org.apache.xindice.xml.dom.DOMCompressor;
+import org.apache.xindice.xml.dom.DocumentImpl;
 
 import junit.framework.TestCase;
 import org.w3c.dom.Document;
@@ -129,6 +132,23 @@
         }
 
         assertEquals(1, resultCount);
+    }
+
+    public void testCompressedDocument() throws Exception {
+        // Compress the document with own symbol table
+        Document document = DOMParser.toDocument(XML);
+        SymbolTable symbols = new SymbolTable();
+        byte[] data = DOMCompressor.compress(document, symbols);
+        Document compressedDoc = new DocumentImpl(data, symbols, null);
+
+        // Store it in the collection
+        collection.insertDocument("document", compressedDoc);
+        Document res = collection.getDocument("document");
+
+        // Must match
+        String expected = TextWriter.toString(document);
+        String actual   = TextWriter.toString(res);
+        assertEquals("Documents do not match", expected, actual);
     }
 
 // FIXME Define semantics of document cache, and write tests for it

Modified: 
xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/CompressedDOMTests.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/CompressedDOMTests.java?view=diff&rev=518460&r1=518459&r2=518460
==============================================================================
--- 
xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/CompressedDOMTests.java
 (original)
+++ 
xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/CompressedDOMTests.java
 Wed Mar 14 20:47:19 2007
@@ -37,7 +37,7 @@
         public Document getDocument(String xml) throws Exception {
             SymbolTable symbols = new SymbolTable();
             Document doc = DOMParser.toDocument(xml);
-            return new DocumentImpl(DOMCompressor.Compress(doc, symbols), 
symbols, null);
+            return new DocumentImpl(DOMCompressor.compress(doc, symbols), 
symbols, null);
         }
     }
 


Reply via email to