Project

General

Profile

« Previous | Next » 

Revision 460

Added by bojilova over 24 years ago

on character(cbuf, start, len) included:
if currentNode.getTagName().equals("title")
currentDocument.setTitle(cbuf)
instead of using:
currentDocument.setTitleFromChildElement() in endDocument() call

View differences:

src/edu/ucsb/nceas/metacat/DBSAXHandler.java
47 47
   private String       user = null;
48 48

  
49 49
   private static final int MAXDATACHARS = 4000;
50
   private static final int MAXTITLELEN = 1000;
50 51

  
51 52
   /** Construct an instance of the handler class 
52 53
    *
......
93 94

  
94 95
   /** SAX Handler that receives notification of end of the document */
95 96
   public void endDocument() throws SAXException {
96
     currentDocument.setTitleFromChildElement();
97
// NOT NEEDED ANY MORE - use currentDocument.setTitle() from characters(cbuf,start,end)
98
//     currentDocument.setTitleFromChildElement();
97 99
     MetaCatUtil.debugMessage("end Document");
100
// NOT NEEDED ANY MORE - Accession# is generated at the very beginning before the parsing
98 101
//     if ((docid != null) && (!docid.equals(currentDocument.getDocID()))) {
99 102
//       throw (new SAXException("New document ID generated:",
100 103
//           new AccessionNumberGeneratedException(currentDocument.getDocID())));
......
148 151
     currentNode = new DBSAXNode(conn, localName, parentNode,
149 152
                                 currentDocument.getRootNodeID(),docid,
150 153
                                 currentDocument.getDoctype());
151

  
154
                                 
152 155
     // Add all of the attributes
153 156
     for (int i=0; i<atts.getLength(); i++) {
154 157
       currentNode.setAttribute(atts.getLocalName(i), atts.getValue(i), docid);
......
159 162
     nodeStack.push(currentNode);
160 163
  }
161 164

  
162
   /** SAX Handler that is called for each XML text node */
163
   public void characters(char[] cbuf, int start, int len) {
165
  /** SAX Handler that is called for each XML text node */
166
  public void characters(char[] cbuf, int start, int len) throws SAXException {
164 167
     MetaCatUtil.debugMessage("CHARACTERS");
165 168
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
166 169
     String data = null;
......
186 189
       // Write the content of the node to the database
187 190
       currentNode.writeChildNodeToDB("TEXT", null, data, docid);
188 191
     }
192

  
193
     // write the title of document if there are tag <title>
194
     if ( currentNode.getTagName().equals("title") ) {
195
       if ( leftover > MAXTITLELEN ) 
196
         currentDocument.setTitle(new String(cbuf, start, MAXTITLELEN));
197
       else
198
         currentDocument.setTitle(new String(cbuf, start, leftover));
199
     } 
200
      
189 201
   }
190 202

  
191 203
   /** 

Also available in: Unified diff