Project

General

Profile

« Previous | Next » 

Revision 821

Added by bojilova over 22 years ago

added support for Namespaces.
Metacat now can store and retrieve XML documents with Namespaces.
Namespace is stored as separate record in xml_nodes table with type "NAMESPACE"
where nodename is the prefix and nodedata is the uri of the namespace.

View differences:

DBSAXHandler.java
32 32
import java.io.StringReader;
33 33
import java.util.Stack;
34 34
import java.util.Vector;
35
import java.util.Hashtable;
35 36
import java.util.Enumeration;
36 37
import java.util.EmptyStackException;
37 38

  
......
68 69
   private Thread   xmlIndex;
69 70
   private boolean endDocument = false;
70 71
   private int serverCode = 1;
72
   private Hashtable namespaces = new Hashtable();
71 73

  
72 74
   private static final int MAXDATACHARS = 4000;
73 75
// DOCTITLE attr cleared from the db
......
142 144
     }
143 145
   }
144 146

  
147
   /** SAX Handler that is called at the start of Namespace */
148
   public void startPrefixMapping(String prefix, String uri) 
149
                                          throws SAXException
150
   {
151
    MetaCatUtil.debugMessage("NAMESPACE");
152

  
153
    namespaces.put(prefix, uri);
154
   }
155
   
145 156
   /** SAX Handler that is called at the start of each XML element */
146 157
   public void startElement(String uri, String localName,
147 158
                            String qName, Attributes atts) 
148 159
               throws SAXException {
149
     MetaCatUtil.debugMessage("Start ELEMENT " + localName);
150

  
160
     MetaCatUtil.debugMessage("Start ELEMENT " + qName);
161
 
151 162
     DBSAXNode parentNode = null;
152 163
     DBSAXNode currentNode = null;
153 164

  
......
197 208
     }      
198 209

  
199 210
     // Create the current node representation
200
     currentNode = new DBSAXNode(conn, localName, parentNode,
211
     currentNode = new DBSAXNode(conn, qName, parentNode,
201 212
                                 currentDocument.getRootNodeID(),docid,
202 213
                                 currentDocument.getDoctype());
203 214
                               
215
     // Add all of the namespaces
216
     String prefix;
217
     String nsuri;
218
     Enumeration prefixes = namespaces.keys();
219
     while ( prefixes.hasMoreElements() ) {
220
       prefix = (String)prefixes.nextElement();
221
       nsuri = (String)namespaces.get(prefix);
222
       currentNode.setNamespace(prefix, nsuri, docid);
223
     }
224
     namespaces = null;
225
     namespaces = new Hashtable();
226

  
204 227
     // Add all of the attributes
205 228
     for (int i=0; i<atts.getLength(); i++) {
206
       currentNode.setAttribute(atts.getLocalName(i), atts.getValue(i), docid);
229
       currentNode.setAttribute(atts.getQName(i), atts.getValue(i), docid);
207 230
     }      
208 231

  
209 232
     // Add the node to the stack, so that any text data can be 
......
309 332
       // Write the content of the node to the database
310 333
       currentNode.writeChildNodeToDB("TEXT", null, data, docid);
311 334
     }
312

  
313
// DOCTITLE attr cleared from the db
314
//     // write the title of document if there are tag <title>
315
//     if ( currentNode.getTagName().equals("title") ) {
316
//       if ( leftover > MAXTITLELEN ) 
317
//         currentDocument.setTitle(new String(cbuf, start, MAXTITLELEN));
318
//       else
319
//         currentDocument.setTitle(new String(cbuf, start, leftover));
320
//     }
321 335
   }
322 336

  
323 337
   /** 
......
372 386
   /** SAX Handler that is called at the end of each XML element */
373 387
   public void endElement(String uri, String localName,
374 388
                          String qName) throws SAXException {
375
     MetaCatUtil.debugMessage("End ELEMENT " + localName);
389
     MetaCatUtil.debugMessage("End ELEMENT " + qName);
376 390

  
377 391
     // Get the node from the stack
378 392
     DBSAXNode currentNode = (DBSAXNode)nodeStack.pop();
......
389 403
     doctype = publicId;
390 404
     systemid = systemId;
391 405

  
392
//System.out.println("Start DTD");
393
//System.out.println("DOCNAME: " + docname);
394
//System.out.println("DOCTYPE: " + doctype);
395
//System.out.println("  SYSID: " + systemid);
396

  
397 406
     MetaCatUtil.debugMessage("Start DTD");
398 407
     MetaCatUtil.debugMessage("DOCNAME: " + docname);
399 408
     MetaCatUtil.debugMessage("DOCTYPE: " + doctype);
......
405 414
    */
406 415
   public void endDTD() throws SAXException {
407 416
    
408
//System.out.println("end DTD");
409 417
     MetaCatUtil.debugMessage("end DTD");
410 418
   }
411 419

  
......
471 479
   public void attributeDecl(String eName, String aName,
472 480
                        String type, String valueDefault, String value)
473 481
                        throws org.xml.sax.SAXException {
482

  
474 483
//System.out.println("ATTRIBUTEDECL: " + eName + " " 
475 484
//                        + aName + " " + type + " " + valueDefault + " "
476 485
//                        + value);

Also available in: Unified diff