Author: vgritsenko Date: Wed Feb 28 19:10:46 2007 New Revision: 513115 URL: http://svn.apache.org/viewvc?view=rev&rev=513115 Log: <action dev="VG" type="fix" fixes-bug="41605" due-to="Natalia Shilenkova"> Fix support of uncompressed collections. Add test cases. </action>
Modified: xml/xindice/trunk/build.bat xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DOMCompressor.java xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/ElementImpl.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/xml/sax/SAXEventGeneratorTest.java xml/xindice/trunk/src/documentation/content/xdocs/mail.xml xml/xindice/trunk/src/documentation/content/xdocs/related.xml xml/xindice/trunk/status.xml Modified: xml/xindice/trunk/build.bat URL: http://svn.apache.org/viewvc/xml/xindice/trunk/build.bat?view=diff&rev=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/build.bat (original) +++ xml/xindice/trunk/build.bat Wed Feb 28 19:10:46 2007 @@ -45,7 +45,7 @@ set PATH=%JAVA_HOME%\bin :noJavaHome -:: ----- Use Ant shipped with Cocoon. Ignore installed in the system Ant +:: ----- Use Ant shipped with Xindice. Ignore installed in the system Ant set OLD_ANT_HOME=%ANT_HOME% set ANT_HOME=tools Modified: xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java?view=diff&rev=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/client/xmldb/embed/CollectionImpl.java Wed Feb 28 19:10:46 2007 @@ -30,6 +30,7 @@ import org.apache.xindice.core.meta.MetaData; import org.apache.xindice.core.query.QueryUtil; import org.apache.xindice.util.Configuration; +import org.apache.xindice.xml.TextWriter; import org.apache.xindice.xml.dom.DocumentImpl; import org.w3c.dom.Document; @@ -119,9 +120,11 @@ DocumentImpl doc = (DocumentImpl) entry; // This should probably just pass the document. - return new XMLResourceImpl(id, id, this, - doc.getSymbols(), - doc.getDataBytes()); + if (doc.getDataBytes() == null) { + return new XMLResourceImpl(id, id, this, TextWriter.toString(doc)); + } else { + return new XMLResourceImpl(id, id, this, doc.getSymbols(), doc.getDataBytes()); + } } else if (entry instanceof byte[]) { return new BinaryResourceImpl(id, this, (byte[])entry); @@ -201,13 +204,12 @@ } else if (res instanceof XMLResource) { try { - String name = ""; Node content = ((XMLResourceImpl) res).getContentAsDOM(); if (content != null && content instanceof Document) { if (res.getId() != null) { col.insertDocument(res.getId(), (Document) content); } else { - name = col.insertDocument((Document) content).toString(); + String name = col.insertDocument((Document) content).toString(); ((XMLResourceImpl) res).setId(name); } } else { 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=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Wed Feb 28 19:10:46 2007 @@ -742,6 +742,11 @@ } document = parseDocument(key, value.toString()); + flushSymbolTable(); + + if (documentCache != null) { + documentCache.putDocument(this, key, document); + } } DBObserver.getInstance().loadDocument(this, record, document); @@ -1038,7 +1043,8 @@ } /** - * Turns an XML string into a parsed document and caches it. + * Turns an XML string into a parsed document retrieved + * from the uncompressed collection. * * @param key The key to use when caching * @param xml The string to parse @@ -1047,14 +1053,11 @@ private Document parseDocument(Key key, String xml) throws DBException { try { Document doc = DOMParser.toDocument(xml); + ((DBDocument) doc).setSource(new NodeSource(this, key)); - // Have to move it to Xindice DOM for XMLObject AutoLinking - byte[] b = DOMCompressor.Compress(doc, symbols); - doc = new DocumentImpl(b, symbols, new NodeSource(this, key)); - - if (documentCache != null) { - documentCache.putDocument(this, key, b); - } + // Have to compress to update collection's SymbolTable, + // which is used even for uncompressed collections + DOMCompressor.Compress(doc, symbols); return doc; } catch (Exception e) { Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java?view=diff&rev=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexManager.java Wed Feb 28 19:10:46 2007 @@ -469,19 +469,13 @@ this.action = action; try { - SAXEventGenerator events = new SAXEventGenerator(doc); + SAXEventGenerator events = new SAXEventGenerator(symbols, doc); events.setContentHandler(this); events.setProperty(HANDLER, this); events.start(); if (action == ACTION_CREATE || action == ACTION_UPDATE) { - try { - collection.flushSymbolTable(); - } catch (Exception e) { - if (log.isWarnEnabled()) { - log.warn("ignored exception", e); - } - } + collection.flushSymbolTable(); } } catch (Exception e) { if (log.isWarnEnabled()) { Modified: xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DOMCompressor.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DOMCompressor.java?view=diff&rev=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DOMCompressor.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/xml/dom/DOMCompressor.java Wed Feb 28 19:10:46 2007 @@ -295,6 +295,7 @@ * @throws XindiceException if an Exception occurs */ public static byte[] Compress(Node node, SymbolTable symbols) throws XindiceException { + // FIXME ByteArrayOutputStream throws no IOExceptions, so throws clause on method isn't necessary. try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); BufferedOutputStream buf = new BufferedOutputStream(bos, 4096); 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=513115&r1=513114&r2=513115 ============================================================================== --- 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 Feb 28 19:10:46 2007 @@ -541,6 +541,10 @@ nodeName = qualifiedName; if (prefix != null) { setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + prefix, namespaceURI); + nsURI = namespaceURI; + } else { + removeAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + nsURI); + nsURI = null; } invokeHandlers(UserDataHandler.NODE_RENAMED, this, null); 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=513115&r1=513114&r2=513115 ============================================================================== --- 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 Feb 28 19:10:46 2007 @@ -142,6 +142,7 @@ protected String nodeValue; // DOM Level 2 Stuff + protected Document ownerDocument; // The Document object associated with this node protected String nsURI; // Just for caching so we don't have to walk the tree // DOM Level 3 Stuff @@ -162,10 +163,24 @@ 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) { + this.ownerDocument = (Document) parentNode; + } else { + this.ownerDocument = parentNode.getOwnerDocument(); + } } public NodeImpl(NodeImpl parentNode, boolean dirty) { this.parentNode = parentNode; + if (parentNode == null) { + ownerDocument = null; + } else if (parentNode.getNodeType() == DOCUMENT_TYPE_NODE) { + this.ownerDocument = (Document) parentNode; + } else { + this.ownerDocument = parentNode.getOwnerDocument(); + } if (dirty) { setDirty(); } @@ -335,8 +350,7 @@ return (Document) this; } - return parentNode != null ? parentNode.getOwnerDocument() - : null; + return ownerDocument; } /** @@ -520,8 +534,8 @@ protected final synchronized Node cloneNode(boolean deep, boolean invokeHandler) { DocumentImpl doc = (DocumentImpl) getOwnerDocument(); - if (deep) { - // FIXME Does not account for non compressed documents + // compressed documents + if (deep && this.data != null) { byte[] data = this.data; int pos = this.pos; int len = this.len; @@ -566,6 +580,7 @@ case Node.ELEMENT_NODE: newNode = new ElementImpl(this, data, pos, len); + newNode.setNodeName(getNodeName()); break; case Node.ENTITY_REFERENCE_NODE: @@ -590,6 +605,8 @@ } } if (newNode != null) { + // cloned node must not have a parent + newNode.parentNode = null; if (invokeHandler) { invokeHandlers(UserDataHandler.NODE_CLONED, this, newNode); } @@ -598,47 +615,54 @@ } checkLoaded(); - Node node = null; + NodeImpl node = null; switch (getNodeType()) { case Node.ATTRIBUTE_NODE: - Attr attr = doc.createAttribute(nodeName); + AttrImpl attr = (AttrImpl) doc.createAttribute(nodeName); attr.setValue(nodeValue); node = attr; break; case Node.CDATA_SECTION_NODE: - node = doc.createCDATASection(nodeValue); + node = (NodeImpl) doc.createCDATASection(nodeValue); break; case Node.COMMENT_NODE: - node = doc.createComment(nodeValue); + node = (NodeImpl) doc.createComment(nodeValue); break; case Node.DOCUMENT_FRAGMENT_NODE: - node = doc.createDocumentFragment(); + node = (NodeImpl) doc.createDocumentFragment(); break; case Node.ELEMENT_NODE: - Element elem = doc.createElement(nodeName); + ElementImpl elem = (ElementImpl) doc.createElement(nodeName); NamedNodeMap attrs = getAttributes(); int size = attrs.getLength(); for (int i = 0; i < size; i++) { Attr a = (Attr) attrs.item(i); elem.setAttribute(a.getName(), a.getValue()); } + + if (getPrefix() != null) { + elem.nsURI = lookupNamespaceURI(getPrefix()); + } else { + elem.nsURI = lookupDefaultNamespaceURI(); + } + node = elem; break; case Node.ENTITY_REFERENCE_NODE: - node = doc.createEntityReference(nodeValue); + node = (NodeImpl) doc.createEntityReference(nodeValue); break; case Node.PROCESSING_INSTRUCTION_NODE: - node = doc.createProcessingInstruction(nodeName, nodeValue); + node = (NodeImpl) doc.createProcessingInstruction(nodeName, nodeValue); break; case Node.TEXT_NODE: - node = doc.createTextNode(nodeValue); + node = (NodeImpl) doc.createTextNode(nodeValue); break; default: @@ -648,7 +672,15 @@ break; } + if (node != null && deep) { + NodeList list = getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + node.appendChild(list.item(i).cloneNode(deep)); + } + } + if (node != null && invokeHandler) { + node.parentNode = null; invokeHandlers(UserDataHandler.NODE_CLONED, this, node); } 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=513115&r1=513114&r2=513115 ============================================================================== --- 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 Feb 28 19:10:46 2007 @@ -24,9 +24,7 @@ import org.apache.xindice.util.ByteArrayInput; import org.apache.xindice.xml.SymbolTable; import org.apache.xindice.xml.XMLCompressedInput; -import org.apache.xindice.xml.dom.CompressedDocument; import org.apache.xindice.xml.dom.DOMCompressor; -import org.apache.xindice.xml.dom.DocumentImpl; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -116,20 +114,12 @@ this.len = len; } - public SAXEventGenerator(Document doc) { + public SAXEventGenerator(SymbolTable symbols, Document doc) { try { - if (doc instanceof CompressedDocument) { - CompressedDocument cDoc = new DocumentImpl(doc); - symbols = cDoc.getSymbols(); - data = cDoc.getDataBytes(); - pos = cDoc.getDataPos(); - len = cDoc.getDataLen(); - } else { - symbols = new SymbolTable(); - data = DOMCompressor.Compress(doc, symbols); - pos = 0; - len = data.length; - } + 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()) { @@ -230,7 +220,7 @@ public void parse(String systemId) throws IOException, SAXException { } - private final String getLocalName(String qname) { + private String getLocalName(String qname) { int idx = qname.indexOf(":"); if (idx != -1) { return qname.substring(idx + 1); @@ -239,8 +229,8 @@ } } - private final boolean isNSAttr(final String qName) { - return (("xmlns".equals(qName)) || qName.startsWith("xmlns:")); + private boolean isNSAttr(final String qName) { + return "xmlns".equals(qName) || qName.startsWith("xmlns:"); } public boolean processContainer(boolean element, int pos, int len) throws IOException, SAXException { Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/sax/SAXEventGeneratorTest.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/sax/SAXEventGeneratorTest.java?view=diff&rev=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/sax/SAXEventGeneratorTest.java (original) +++ xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/sax/SAXEventGeneratorTest.java Wed Feb 28 19:10:46 2007 @@ -88,7 +88,7 @@ protected void setUp() throws Exception { // Xindice parsing doc = DOMParser.toDocument(XML); - generator = new SAXEventGenerator(doc); + generator = new SAXEventGenerator(null, doc); xindiceHandler = new LoggingContentHandler(); generator.setContentHandler(xindiceHandler); generator.start(); Modified: xml/xindice/trunk/src/documentation/content/xdocs/mail.xml URL: http://svn.apache.org/viewvc/xml/xindice/trunk/src/documentation/content/xdocs/mail.xml?view=diff&rev=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/src/documentation/content/xdocs/mail.xml (original) +++ xml/xindice/trunk/src/documentation/content/xdocs/mail.xml Wed Feb 28 19:10:46 2007 @@ -39,7 +39,7 @@ <li> <link href="faq.html">FAQs</link> </li> - <li>Mailing list archives - a veritable goldmine of Cocoon-specific information - if you know where to look!</li> + <li>Mailing list archives - a veritable goldmine of Xindice-specific information - if you know where to look!</li> </ol> </section> Modified: xml/xindice/trunk/src/documentation/content/xdocs/related.xml URL: http://svn.apache.org/viewvc/xml/xindice/trunk/src/documentation/content/xdocs/related.xml?view=diff&rev=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/src/documentation/content/xdocs/related.xml (original) +++ xml/xindice/trunk/src/documentation/content/xdocs/related.xml Wed Feb 28 19:10:46 2007 @@ -295,7 +295,7 @@ </td> <td> CocoBlog is a - <fork href="http://xml.apache.org/cocoon">Cocoon</fork> + <fork href="http://cocoon.apache.org/">Cocoon</fork> and Xindice-based weblogging software tool developed by <fork href="http://www.beblogging.com">Ugo Cei</fork>. </td> Modified: xml/xindice/trunk/status.xml URL: http://svn.apache.org/viewvc/xml/xindice/trunk/status.xml?view=diff&rev=513115&r1=513114&r2=513115 ============================================================================== --- xml/xindice/trunk/status.xml (original) +++ xml/xindice/trunk/status.xml Wed Feb 28 19:10:46 2007 @@ -98,6 +98,9 @@ <changes> <release version="1.1b5-dev" date="Feb 22 2007"> + <action dev="VG" type="fix" fixes-bug="41605" due-to="Natalia Shilenkova"> + Fix support of uncompressed collections. Add test cases. + </action> <action dev="VG" type="update"> Updated Xindice docs to work with latest Forrest (0.8-dev, trunk). </action>