Project

General

Profile

« Previous | Next » 

Revision 2339

Added by sgarg almost 20 years ago

Made changes to fix bug# 1538. Changed the code of the normalize function in MetaCatUtil.java. Earlier code was not taking care of characters above 123.

In DBSAXHandler.java, added call to normalize function before text is written to db.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatUtil.java
243 243
    {
244 244
        StringBuffer str = new StringBuffer();
245 245

  
246
        int len = (s != null) ? s.length() : 0;
247
        for (int i = 0; i < len; i++) {
248
            char ch = s.charAt(i);
249
            switch (ch) {
250
            case '<':
251
                {
252
                    str.append("&lt;");
253
                    break;
254
                }
255
            case '>':
256
                {
257
                    str.append("&gt;");
258
                    break;
259
                }
260
            case '&':
261
                {
262
                    str.append("&amp;");
263
                    break;
264
                }
265
            case '"':
266
                {
267
                    str.append("&quot;");
268
                    break;
269
                }
270
            case '\r':
271
            case '\n':
272
                {
273
                    // else, default append char
274
                }
275
            default:
276
                {
277
                    str.append(ch);
278
                }
279
            }
280
        }
281
        return (str.toString());
246
             int len = (s != null) ? s.length() : 0;
247
             for (int i = 0; i < len; i++) {
248
                 char ch = s.charAt(i);
249
                 switch (ch) {
250
                     case '<': {
251
                         str.append("&lt;");
252
                         break;
253
                     }
254
                     case '>': {
255
                         str.append("&gt;");
256
                         break;
257
                     }
258
                     case '&': {
259
                         str.append("&amp;");
260
                         break;
261
                     }
262
                     case '"': {
263
                         str.append("&quot;");
264
                         break;
265
                     }
266
                     default: {
267
                         if ((ch<128)&&(ch>31)) {
268
                             str.append(ch);
269
                         }
270
                         else if (ch<32) {
271
                             if (ch== 10) {
272
                                 str.append(ch);
273
                             }
274
                             if (ch==13) {
275
                                 str.append(ch);
276
                             }
277
                             if (ch==9) {
278
                                 str.append(ch);
279
                             }
280
                             // otherwise skip
281
                         }
282
                         else {
283
                             str.append("&#");
284
                             str.append(Integer.toString(ch));
285
                             str.append(';');
286
                         }
287
                     }
288
                 }
289
             }
290
             String temp = str.toString();
291
             temp = temp.trim();
292
             if (temp.length()<1) temp = " ";
293
             return temp;
282 294
    }
283 295

  
284 296
    /**
src/edu/ucsb/nceas/metacat/DBSAXHandler.java
427 427
        }
428 428
    }
429 429

  
430
    /* 
430
    /*
431 431
     * Run a separate thread to build the XML index for this document.  This
432 432
     * thread is run asynchronously in order to more quickly return control to
433 433
     * the submitting user.  The run method checks to see if the document has
......
445 445
        } catch (Exception e) {
446 446
            MetaCatUtil.debugMessage("Error in DBSAXHandler.run "
447 447
                    + e.getMessage(), 30);
448
        } 
448
        }
449 449
    }
450 450

  
451 451
    /*
......
496 496
                // make sure the while loop will be ended in reseaonable time
497 497
                long stopTime = System.currentTimeMillis();
498 498
                if ((stopTime - startTime) > INDEXDELAY) { throw new Exception(
499
                        "Couldn't find the docid for index build in"
499
                        "Couldn't find the docid for index build in "
500 500
                                + "reseaonable time!"); }
501 501
            }//while
502 502
        } catch (Exception e) {
......
862 862
                }
863 863

  
864 864
                // Write the content of the node to the database
865
                nodeId = node.writeChildNodeToDB("TEXT", null, data, docid);
865
                nodeId = node.writeChildNodeToDB("TEXT", null,
866
                                                 MetaCatUtil.normalize(data),
867
                                                 docid);
866 868
            }//while
867 869
        }//if
868 870
        return nodeId;

Also available in: Unified diff