|
From: <j_m...@us...> - 2004-02-29 12:24:42
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item/xmldb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11635/src/org/cobricks/item/xmldb Modified Files: XMLDBAccess.java Log Message: Index: XMLDBAccess.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/xmldb/XMLDBAccess.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** XMLDBAccess.java 21 Feb 2004 18:49:56 -0000 1.3 --- XMLDBAccess.java 29 Feb 2004 12:06:38 -0000 1.4 *************** *** 1,21 **** package org.cobricks.item.xmldb; ! import org.apache.log4j.*; ! ! import org.apache.xindice.client.xmldb.*; ! import org.apache.xindice.client.xmldb.services.*; ! import org.apache.xindice.xml.*; ! import org.apache.xindice.xml.dom.*; ! ! import org.cobricks.category.Category; ! ! import org.cobricks.core.ComponentManagerAdaptor; ! import org.cobricks.core.CoreManager; ! import org.cobricks.core.Ontology; ! import org.cobricks.core.OntologyClass; ! import org.cobricks.core.db.DBAccess; ! import org.cobricks.core.util.LogUtil; ! ! import org.cobricks.user.User; import org.w3c.dom.Document; --- 1,7 ---- package org.cobricks.item.xmldb; ! import org.apache.log4j.Logger; ! import org.apache.xindice.client.xmldb.services.CollectionManager; ! import org.apache.xindice.xml.dom.DocumentImpl; import org.w3c.dom.Document; *************** *** 29,41 **** import org.xml.sax.SAXException; - import org.xmldb.api.*; import org.xmldb.api.DatabaseManager; ! import org.xmldb.api.base.*; ! import org.xmldb.api.modules.*; - import java.io.File; - import java.io.FileNotFoundException; import java.io.StringReader; import java.util.HashMap; import java.util.Iterator; --- 15,32 ---- import org.xml.sax.SAXException; import org.xmldb.api.DatabaseManager; ! import org.xmldb.api.base.Collection; ! import org.xmldb.api.base.Database; ! import org.xmldb.api.base.XMLDBException; ! import org.xmldb.api.base.Resource; ! import org.xmldb.api.base.ResourceSet; ! import org.xmldb.api.base.ResourceIterator; ! import org.xmldb.api.modules.XMLResource; ! import org.xmldb.api.modules.XPathQueryService; ! import org.xmldb.api.modules.XUpdateQueryService; import java.io.StringReader; + import java.util.HashMap; import java.util.Iterator; *************** *** 43,69 **** import java.util.Properties; import java.util.Set; ! import java.sql.Date; ! import java.sql.Timestamp; ! import java.util.Calendar; ! import java.util.TimeZone; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; - import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; ! import javax.xml.transform.Result; ! import javax.xml.transform.Source; ! import javax.xml.transform.Templates; import javax.xml.transform.Transformer; ! import javax.xml.transform.TransformerConfigurationException; ! import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; ! import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; ! import javax.xml.transform.sax.SAXResult; ! import javax.xml.transform.sax.SAXSource; ! import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamResult; ! import javax.xml.transform.stream.StreamSource; --- 34,53 ---- import java.util.Properties; import java.util.Set; ! ! import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; ! ! import javax.xml.transform.Transformer; ! import javax.xml.transform.TransformerFactory; ! import javax.xml.transform.dom.DOMSource; ! import javax.xml.transform.stream.StreamResult; ! *************** *** 82,86 **** * */ ! public class XMLDBAccess { /** * The classname where to find the database impl. (at the moment only xindice) --- 66,70 ---- * */ ! public class XMLDBAccess implements Runnable { /** * The classname where to find the database impl. (at the moment only xindice) *************** *** 103,107 **** */ private static final int DEFAULT_PORTNUMBER = 4080; ! /** * The XML prologue to a XUpdate command. --- 87,94 ---- */ private static final int DEFAULT_PORTNUMBER = 4080; ! /** ! * Default delay in milli seconds for the init thread to wait ! */ ! private static final int DEFAULT_INIT_DELAY = 10000; /** * The XML prologue to a XUpdate command. *************** *** 149,166 **** /** ! *This constructor also initalizes the connection to the db by connecting to ! *the specified collection name using the properties to determine where to ! *connect to. * @param submittedProperties Needed information for the init method. ! * @param collectionName Each instance of XMLDBAccess is tied to one * specific collection * @param pathCollectionDescriptor Path to the descriptor file of this * collection. - * @throws Exception TMP */ ! public XMLDBAccess(Properties submittedProperties, String collectionName, ! String pathCollectionDescriptor) throws Exception { this.properties = submittedProperties; ! online = this.init(collectionName, pathCollectionDescriptor); } --- 136,182 ---- /** ! * Some methods have to add an extra xml version / encoding prologue ! */ ! private String xmlEncoding = "UTF-8"; ! /** ! * The collection name; stored as instance variable because the run() method ! * does not have the ability to get parameters. ! */ ! private String collectionName; ! /** ! * The path to the collection descriptor; stored as instance variable because ! * the run() method does not have the ability to get parameters. ! */ ! private String pathToCollection; ! /** ! * The initial delay; stored as instance variable because the run() method ! * does not have the ability to get parameters. ! */ ! private int initDelay = XMLDBAccess.DEFAULT_INIT_DELAY; ! /** ! * This constructor constructs a new XMLDBAccess instance. It does <b>not</b> ! * initialize the connection. * @param submittedProperties Needed information for the init method. ! * @param submCollectionName Each instance of XMLDBAccess is tied to one * specific collection * @param pathCollectionDescriptor Path to the descriptor file of this * collection. */ ! public XMLDBAccess(Properties submittedProperties, String submCollectionName, ! String pathCollectionDescriptor) { this.properties = submittedProperties; ! this.pathToCollection = pathCollectionDescriptor; ! this.collectionName = submCollectionName; ! int delay = -1; ! try { ! delay = Integer.parseInt( ! properties.getProperty("item.xmldb.initdelay")); ! } catch (Exception e) { ! logger.info("No / illegal delay property. Using default value"); ! } ! if (delay >= 0) { ! this.initDelay = delay; ! } ! //this.init(collectionName, pathCollectionDescriptor); } *************** *** 170,186 **** * exist, they are created. Also needed indexer are created (if there is * a correct descriptor). ! * @param collectionName The name of the collection which should be * initialized * @param pathCollectionDescriptor Path to the descriptor file of this * collection. - * @return Was the attempt to initalize successfull? * @throws Exception */ ! private boolean init(String collectionName, String pathCollectionDescriptor) { // I. Setting up the xmldb Engine Class c; Database database; logger.info("Initializing the DB access for collection: " ! + collectionName); if (properties.getProperty("item.xmldb.hostname") != null) { --- 186,203 ---- * exist, they are created. Also needed indexer are created (if there is * a correct descriptor). ! * @param submCollectionName The name of the collection which should be * initialized * @param pathCollectionDescriptor Path to the descriptor file of this * collection. * @throws Exception */ ! ! private void init(String submCollectionName, String pathCollectionDescriptor) ! { // I. Setting up the xmldb Engine Class c; Database database; logger.info("Initializing the DB access for collection: " ! + submCollectionName); if (properties.getProperty("item.xmldb.hostname") != null) { *************** *** 190,193 **** --- 207,214 ---- } + if (properties.getProperty("item.xml.encoding") != null) { + this.xmlEncoding = properties.getProperty("item.xml.encoding"); + } + try { this.portnumber = *************** *** 205,234 **** "Fatal error while trying to instantiate org.apache.xindice." + "client.xmldb.DatabaseImpl. Giving up to launch XindiceHelper"); ! ! return false; } //II. Verify the correct collection structure and create it,if necessary ! collection = this.getConnected("/db/cobricks/" + collectionName); ! if (!this.verifyCollectionStructure(collectionName, collection)) { // There was a fatal error, the collection structure could neither // be verified nor be "repaired" --> Exit init and set offline logger.warn("Could not verify the collection structure for: " ! + collectionName); ! return false; } else { //The collection is o.k. now, let's check the indexes. //If there are problems whith this check, proceed. ! collectionDesc = new XMLDBCollectionDescriptor(collectionName); try { collectionDesc.readFromFile(new java.io.File( pathCollectionDescriptor)); ! this.checkIndexes(collectionDesc, collectionName); } catch (NullPointerException e) { //Is thrown when the path is not correct. ! logger.warn("Tabledescriptor " + collectionName + "not found." + "path: " + pathCollectionDescriptor); } --- 226,256 ---- "Fatal error while trying to instantiate org.apache.xindice." + "client.xmldb.DatabaseImpl. Giving up to launch XindiceHelper"); ! this.online = false; ! return; } //II. Verify the correct collection structure and create it,if necessary ! collection = this.getConnected("/db/cobricks/" + submCollectionName); ! if (!this.verifyCollectionStructure(submCollectionName, collection)) { // There was a fatal error, the collection structure could neither // be verified nor be "repaired" --> Exit init and set offline logger.warn("Could not verify the collection structure for: " ! + submCollectionName); ! this.online = false; ! return; } else { //The collection is o.k. now, let's check the indexes. //If there are problems whith this check, proceed. ! collectionDesc = new XMLDBCollectionDescriptor(submCollectionName); try { collectionDesc.readFromFile(new java.io.File( pathCollectionDescriptor)); ! this.checkIndexes(collectionDesc, submCollectionName); } catch (NullPointerException e) { //Is thrown when the path is not correct. ! logger.warn("Tabledescriptor " + submCollectionName + "not found." + "path: " + pathCollectionDescriptor); } *************** *** 250,255 **** + " is not open"); } ! ! return true; } } --- 272,277 ---- + " is not open"); } ! this.online = tmpStatus; ! return; } } *************** *** 298,310 **** * @param desc The descriptor contains all the necessary information about * the indexer ! * @param collectionName The name of the collcetion to be checked.. mainly ! * needed for logging purposes. */ private void checkIndexes(XMLDBCollectionDescriptor desc, ! String collectionName) { CollectionManager colman; String[] indexArr; boolean hasMismatch = false; ! logger.info("Checking the indexes for: " + collectionName); try { --- 320,332 ---- * @param desc The descriptor contains all the necessary information about * the indexer ! * @param submCollectionName The name of the collcetion to be checked.. ! * mainly needed for logging purposes. */ private void checkIndexes(XMLDBCollectionDescriptor desc, ! String submCollectionName) { CollectionManager colman; String[] indexArr; boolean hasMismatch = false; ! logger.info("Checking the indexes for: " + submCollectionName); try { *************** *** 322,326 **** if ((indexArr != null) && (indexArr.length > 0)) { for (int i = 0; i < indexArr.length; i++) { ! if (!(this.collectionDesc.getIndexes().containsKey(indexArr[i]))) { // IMPORTANT TO KNOW: COMPARING RELIES ONLY ON THE NAMES! logger.info("Index not found in the collection descriptor:" --- 344,349 ---- if ((indexArr != null) && (indexArr.length > 0)) { for (int i = 0; i < indexArr.length; i++) { ! if (!(this.collectionDesc.getIndexes() ! .containsKey(indexArr[i]))) { // IMPORTANT TO KNOW: COMPARING RELIES ONLY ON THE NAMES! logger.info("Index not found in the collection descriptor:" *************** *** 334,338 **** } else { logger.info("No indexer in indexdescriptor in collection: " ! + collectionName); } --- 357,361 ---- } else { logger.info("No indexer in indexdescriptor in collection: " ! + submCollectionName); } *************** *** 415,419 **** * subcollection of the cobricks collection. If the cobricks collection * doesn't exist, it tries to create both. ! * @param collectionName Name the collection should have * (needed if creation is necessary). * @param submittedCollection The collection to verify. --- 438,442 ---- * subcollection of the cobricks collection. If the cobricks collection * doesn't exist, it tries to create both. ! * @param submCollectionName Name the collection should have * (needed if creation is necessary). * @param submittedCollection The collection to verify. *************** *** 421,425 **** * problems, false otherwise */ ! private boolean verifyCollectionStructure(String collectionName, Collection submittedCollection) { //If the collection is null: The collection doesn't exist. --- 444,448 ---- * problems, false otherwise */ ! private boolean verifyCollectionStructure(String submCollectionName, Collection submittedCollection) { //If the collection is null: The collection doesn't exist. *************** *** 428,432 **** Collection cobricks = null; ! logger.info("The subcollection" + collectionName + "was not found. Trying to find the cobricks collection"); --- 451,455 ---- Collection cobricks = null; ! logger.info("The subcollection" + submCollectionName + "was not found. Trying to find the cobricks collection"); *************** *** 470,474 **** // (Because we would have been returned with false, //if we had a failure while creating it) ! collection = this.createCollection(collectionName, cobricks); if (collection == null) { --- 493,497 ---- // (Because we would have been returned with false, //if we had a failure while creating it) ! collection = this.createCollection(submCollectionName, cobricks); if (collection == null) { *************** *** 493,503 **** (XMLResource) collection.createResource(String.valueOf(key), "XMLResource"); ! document.setContent(xmlData); collection.storeResource(document); logger.debug("Data inserted, id is:" + key); ! logger.debug("inserted:"+xmlData); } catch (Exception e) { logger.warn("Exception occured while trying to insert data" ! + (key)); } } else { --- 516,526 ---- (XMLResource) collection.createResource(String.valueOf(key), "XMLResource"); ! document.setContent(this.addXMLPrologue(xmlData)); collection.storeResource(document); logger.debug("Data inserted, id is:" + key); ! logger.debug("inserted:" + xmlData); } catch (Exception e) { logger.warn("Exception occured while trying to insert data" ! + (key), e); } } else { *************** *** 616,620 **** result = result + (String) res.getContent(); ! logger.debug("retrieved: "+ (String) res.getContent()); } } catch (XMLDBException e) { --- 639,643 ---- result = result + (String) res.getContent(); ! logger.debug("retrieved: " + (String) res.getContent()); } } catch (XMLDBException e) { *************** *** 630,634 **** * This method removes all xml data (NO whole documents) which is found * @param xPath The xPath of the data to delete. - * @throws Exception TBD! */ public final void removeEntry(String xPath) { --- 653,656 ---- *************** *** 647,651 **** /** ! * This method updates SIMPLE (no child nodes) xml data via passing it * directly to the XUpdate-Engine. * Also very important: The old note to update <b>must not</b> have any --- 669,673 ---- /** ! * This method updates SIMPLE (no child nodes) XML data via passing it * directly to the XUpdate-Engine. * Also very important: The old note to update <b>must not</b> have any *************** *** 653,660 **** * text, use XPath: ../text() to match. * @see http://www.xmldb.org/xupdate/xupdate-wd.html#N6d2633 ! * @param xPath The xPath where the data to update is located ! * @param simpleXML The xml data to update - no child nodes * @throws XMLDBException Common Reasons: Problem accessing the db, ! * invalid arguments (XPath wrong, xml data not simple /invalid), * old node has child nodes. */ --- 675,682 ---- * text, use XPath: ../text() to match. * @see http://www.xmldb.org/xupdate/xupdate-wd.html#N6d2633 ! * @param xPath The XPath where the data to update is located ! * @param simpleXML The XML data to update - no child nodes * @throws XMLDBException Common Reasons: Problem accessing the db, ! * invalid arguments (XPath wrong, XML data not simple /invalid), * old node has child nodes. */ *************** *** 666,671 **** " <xu:update select=\"" + xPath + "\">" + simpleXML + "</xu:update>"; ! logger.debug("Performing data update:" + xupdate); ! this.performXUpdate(xupdate); /*} catch (Exception e) { --- 688,692 ---- " <xu:update select=\"" + xPath + "\">" + simpleXML + "</xu:update>"; ! this.performXUpdate(xupdate); /*} catch (Exception e) { *************** *** 675,679 **** }*/ } else { ! logger.warn("DBAccess status is offline-can't insert" + xPath); } } --- 696,700 ---- }*/ } else { ! logger.warn("DBAccess status is offline -can't insert" + xPath); } } *************** *** 733,738 **** xupdate = xupdate + "</xu:append>"; } - - logger.debug("Performing data update:" + xupdate); this.performXUpdate(xupdate); --- 754,757 ---- *************** *** 757,761 **** * @param xml The xml data to insert * @param useInsertAfter Perform an append or an insert-after? - * @throws XMLDBException TBD! */ public final void insertEntry(String xPath, String xml, --- 776,779 ---- *************** *** 788,792 **** * @param e The base node as an dom element node. * @param useInsertAfter Use insert-after or append? ! * @throws XMLDBException TBD! */ private void insertEntry(String xPath, Element e, boolean useInsertAfter) --- 806,811 ---- * @param e The base node as an dom element node. * @param useInsertAfter Use insert-after or append? ! * @throws XMLDBException May occur - is thrown because this is only an ! * utility. */ private void insertEntry(String xPath, Element e, boolean useInsertAfter) *************** *** 830,837 **** } ! logger.debug("Perform xupdate: " + DATABASE_UPDATE_PROLOGUE + xUpdate ! + DATABASE_UPDATE_EPILOGUE); ! service.update(DATABASE_UPDATE_PROLOGUE + xUpdate ! + DATABASE_UPDATE_EPILOGUE); } --- 849,856 ---- } ! logger.debug("Perform xupdate: " + this.addXMLPrologue( ! DATABASE_UPDATE_PROLOGUE + xUpdate + DATABASE_UPDATE_EPILOGUE)); ! service.update(this.addXMLPrologue(DATABASE_UPDATE_PROLOGUE + xUpdate ! + DATABASE_UPDATE_EPILOGUE)); } *************** *** 840,847 **** * @param xPath XPath Expression: Match the nodes where to remove the attr. * @param attributeName The name of the attribute to remove ! * @throws Exception TBD! */ private void removeAttribute(String xPath, String attributeName) ! throws Exception { this.removeEntry(xPath + "/@" + attributeName); } --- 859,866 ---- * @param xPath XPath Expression: Match the nodes where to remove the attr. * @param attributeName The name of the attribute to remove ! * @throws XMLDBException May occur in case there are db problems. */ private void removeAttribute(String xPath, String attributeName) ! throws XMLDBException { this.removeEntry(xPath + "/@" + attributeName); } *************** *** 867,874 **** * @param attributeName The name of the attribute to append * @param newval The value of the attribe to append. ! * @throws Exception TBD! */ private void addAttribute(String xPath, String attributeName, String newval) ! throws Exception { String xUp = "<xu:append select=\"" + xPath + xPath + "@" + attributeName --- 886,893 ---- * @param attributeName The name of the attribute to append * @param newval The value of the attribe to append. ! * @throws XMLDBException May occur in case there are db problems. */ private void addAttribute(String xPath, String attributeName, String newval) ! throws XMLDBException { String xUp = "<xu:append select=\"" + xPath + xPath + "@" + attributeName *************** *** 1010,1017 **** * @param baseXPath The XPath which points <b>exactly</b> to the node to * update, it must not match to several nodes. - * @throws Exception TBD */ public final void update(final String oldXML, final String newXML, ! final String baseXPath) { Document oldDoc = null; Document newDoc = null; --- 1029,1035 ---- * @param baseXPath The XPath which points <b>exactly</b> to the node to * update, it must not match to several nodes. */ public final void update(final String oldXML, final String newXML, ! final String baseXPath) throws XMLDBException{ Document oldDoc = null; Document newDoc = null; *************** *** 1024,1030 **** + "Check if your old XML data is equivalent to the data in the" + " db."); ! ! return; ! } try { --- 1042,1049 ---- + "Check if your old XML data is equivalent to the data in the" + " db."); ! IllegalArgumentException ee = new IllegalArgumentException(); ! ee.setStackTrace(e.getStackTrace()); ! throw ee; ! } try { *************** *** 1033,1041 **** logger.warn("Error during update: The new XML data is not valid." + "Aborting update."); ! ! return; } - - try { logger.debug("Traversing the old data"); visitOldNode(oldDoc.getDocumentElement(), --- 1052,1059 ---- logger.warn("Error during update: The new XML data is not valid." + "Aborting update."); ! IllegalArgumentException ee = new IllegalArgumentException(); ! ee.setStackTrace(e.getStackTrace()); ! throw ee; } logger.debug("Traversing the old data"); visitOldNode(oldDoc.getDocumentElement(), *************** *** 1046,1052 **** baseXPath + "/" + oldDoc.getDocumentElement().getTagName(), newDoc.getDocumentElement()); - } catch (Exception e) { - logger.error("Exception during update", e); - } } --- 1064,1067 ---- *************** *** 1062,1069 **** * @param newNode The node corresponding to the old node (or null if * it doesn't exist). ! * @throws Exception TBD! */ private void visitOldNode(final Node oldNode, final String currentXPath, ! final Node newNode) throws Exception { if (oldNode instanceof Element && newNode instanceof Element) { //logger.debug("--Current tag: "+((Element)oldNode).getTagName()); --- 1077,1084 ---- * @param newNode The node corresponding to the old node (or null if * it doesn't exist). ! * @throws XMLDBException Is thrown if any problem is encountered. */ private void visitOldNode(final Node oldNode, final String currentXPath, ! final Node newNode) throws XMLDBException { if (oldNode instanceof Element && newNode instanceof Element) { //logger.debug("--Current tag: "+((Element)oldNode).getTagName()); *************** *** 1077,1081 **** if (((Element) newNode).hasAttribute(currAttrName)) { //Attribute was found: ! if (!((Element) newNode).getAttribute(currAttrName).equals(currAttrValue)) { //There is a difference logger.debug("Difference in attr. found: " --- 1092,1097 ---- if (((Element) newNode).hasAttribute(currAttrName)) { //Attribute was found: ! if (!((Element) newNode).getAttribute(currAttrName) ! .equals(currAttrValue)) { //There is a difference logger.debug("Difference in attr. found: " *************** *** 1181,1188 **** * @param currentXPath The XPath points to the current new node. * @param newNode The current new node. ! * @throws Exception TBD */ private void visitNewNode(final Node oldNode, final String currentXPath, ! final Node newNode) throws Exception { if (newNode instanceof Element && oldNode instanceof Element) { //Comparing the attributes: --- 1197,1204 ---- * @param currentXPath The XPath points to the current new node. * @param newNode The current new node. ! * @throws XMLDBException Is thrown if any problem is encountered. */ private void visitNewNode(final Node oldNode, final String currentXPath, ! final Node newNode) throws XMLDBException { if (newNode instanceof Element && oldNode instanceof Element) { //Comparing the attributes: *************** *** 1328,1345 **** used[j] = true; //Mark as used matchFound = true; // we have a good match - - //logger.debug("paired:"+String.valueOf(i)+"<->"+String.valueOf(j)); res[i][1] = secNodes.item(j); //store the match } - - /* - //There was no match found, but this node is still available - if (indexOfSecondChoice == -1) { //There is no second choice - - //yet - indexOfSecondChoice = j; - } - */ - // } j++; --- 1344,1349 ---- *************** *** 1348,1363 **** } - /* - - if (!matchFound && (indexOfSecondChoice != -1)) { - // There was no ideal partner found, let's give it the second - //choice - res[i][1] = secNodes.item(indexOfSecondChoice); - used[indexOfSecondChoice] = true; - } else if (!matchFound) { - //There was no ideal partner and no unused partner. - res[i][1] = null; - } - */ } --- 1352,1355 ---- *************** *** 1421,1442 **** return equals; } ! public void normalizeNodes(String docKey) throws XMLDBException { XMLResource current = (XMLResource) collection.getResource(docKey); String res = (String) current.getContent(); res = res.replaceAll(">( )*\n( )*\n", ">\n"); ! this.removeDocument(docKey); this.insertDocument(res, docKey); } /** * This method normalizes all elements of this collection. * In the current version of xindice, 1.1b3 there is still an issue that * modifiying elements with xupdate may produce blank lines between the tags ! * This can lead to huge growth. This normalizer tool removes these blank ! * lines. */ ! ! public void normalizeAllNodes() { ResourceSet toNorm = this.retrieveResources("/*"); logger.info("Starting to normalize all Elements."); --- 1413,1440 ---- return equals; } + /** + * This method normalizes one document by removing new lines between tags. + * @param docKey The document key to normalize. + * @throws XMLDBException Low-level helper method, may throw Exceptions + * from underlying engine. + */ ! private void normalizeNodes(String docKey) throws XMLDBException { XMLResource current = (XMLResource) collection.getResource(docKey); String res = (String) current.getContent(); res = res.replaceAll(">( )*\n( )*\n", ">\n"); ! this.removeDocument(docKey); this.insertDocument(res, docKey); } + /** * This method normalizes all elements of this collection. * In the current version of xindice, 1.1b3 there is still an issue that * modifiying elements with xupdate may produce blank lines between the tags ! * This can lead to huge growth. This normalizer tool removes these blank ! * lines. */ ! public final void normalizeAllNodes() { ResourceSet toNorm = this.retrieveResources("/*"); logger.info("Starting to normalize all Elements."); *************** *** 1444,1448 **** ResourceIterator it = null; int counter = 0; ! try { if (toNorm != null) { --- 1442,1446 ---- ResourceIterator it = null; int counter = 0; ! try { if (toNorm != null) { *************** *** 1480,1496 **** logger.info("Normalizing complete. Normalized " + counter); - } /** ! * Updates an existing entry by removing the old one and creating a new one * @param xmlData The new XML data to be inserted * @param key The key is needed in order to find the old information which * should be replaced. - * @deprecated don't use it anymore... use the single update/remove/insert - * entries... * */ ! public final void updateData(String xmlData, String key) { try { this.removeDocument(key); --- 1478,1493 ---- logger.info("Normalizing complete. Normalized " + counter); } /** ! * Updates an existing whole document ! * by removing the old one and creating a new one. ! * <b>Very inefficent. Use only in emergency case </b> * @param xmlData The new XML data to be inserted * @param key The key is needed in order to find the old information which * should be replaced. * */ ! public final void updateWholeDocument(String xmlData, String key) { try { this.removeDocument(key); *************** *** 1499,1504 **** + "for updating."); } ! this.insertDocument(xmlData, key); } } --- 1496,1538 ---- + "for updating."); } + this.insertDocument(xmlData, key); + } + /** + * In case the XML db is on the same machine and the new xindice 1.1 is used + * the xml db server starts at the same time cobricks does. So it is necessary + * to make a seperate init thread and let this thread wait a certain time. + */ + public final void run() { + try { + Thread.sleep(this.initDelay); + } catch (Exception e) { + logger.error("Fatal error during sleeping - init could fail", e); + } + this.init(this.collectionName, this.pathToCollection); + } ! /** ! * This method adds a xml version and encoding declaration if necessary ( ! * in case it is missing and the encoding is different from UTF-8. ! * There are known issues with xindice and encoding other than UTF-8. ! * At this time, there is no support for documents other than UTF-8 by ! * Cobricks. Maybe Xindice does in future releases a better encoding handling, ! * that's why this method is implemented. ! * But in the default case this method <b> does nothing </b>. ! * <i>There are known issues with xml encoding other than UTF-8 and there ! * might be other problems with using e.g. XUpdate-Commands with non-UTF-8 ! * encoding. </i> ! * @param input The xml data to add the prologue ! * @return xml data with prologue (if needed). ! */ ! ! ! private String addXMLPrologue(String input) { ! if ((!input.startsWith("<?")) && (!this.xmlEncoding.equals("UTF-8"))) { ! return "<?xml version=\"1.0\" encoding=\"" + this.xmlEncoding ! + "\"?>" + "\n" + input; ! } else { ! return input; ! } } } |