Project

General

Profile

« Previous | Next » 

Revision 3766

Added by Jing Tao over 16 years ago

Add a new string buffer to store normalized query xml itself.

View differences:

src/edu/ucsb/nceas/metacat/QuerySpecification.java
84 84

  
85 85
    /** The root query group that contains the recursive query constraints */
86 86
    private QueryGroup query = null;
87
    
88
    /** A string buffer to stored normalized query (Sometimes, the query have 
89
     * a value like "&", it will cause problem in html transform). So we need a
90
     * normalized query xml string.
91
     */
92
    private StringBuffer xml = new StringBuffer();
87 93

  
88 94
    // Query data structures used temporarily during XML parsing
89 95
    private Stack elementStack;
......
551 557
    public void startElement(String uri, String localName, String qName,
552 558
            Attributes atts) throws SAXException
553 559
    {
560
        logMetacat.debug("start at startElement "+localName);
554 561
        BasicNode currentNode = new BasicNode(localName);
562
        //write element name into xml buffer.
563
        xml.append("<");
564
        xml.append(localName);
555 565
        // add attributes to BasicNode here
556 566
        if (atts != null) {
557 567
            int len = atts.getLength();
558 568
            for (int i = 0; i < len; i++) {
559 569
                currentNode
560 570
                        .setAttribute(atts.getLocalName(i), atts.getValue(i));
571
                xml.append(" ");
572
                xml.append(atts.getLocalName(i));
573
                xml.append("=\"");
574
                xml.append(atts.getValue(i));
575
                xml.append("\"");
561 576
            }
562 577
        }
578
        xml.append(">");
563 579

  
564 580
        elementStack.push(currentNode);
565 581
        if (currentNode.getTagName().equals("querygroup")) {
......
573 589
            }
574 590
            queryStack.push(currentGroup);
575 591
        }
592
        logMetacat.debug("end in startElement "+localName);
576 593
    }
577 594

  
578 595
    /**
......
583 600
    public void endElement(String uri, String localName, String qName)
584 601
            throws SAXException
585 602
    {
603
    	 logMetacat.debug("start in endElement "+localName);
586 604
        BasicNode leaving = (BasicNode) elementStack.pop();
587 605
        if (leaving.getTagName().equals("queryterm")) {
588 606
            boolean isCaseSensitive = (new Boolean(leaving
......
608 626
              queryTitle = textBuffer.toString().trim();
609 627
        } else if (leaving.getTagName().equals("value")) {
610 628
              currentValue = textBuffer.toString().trim();
629
              currentValue = MetaCatUtil.normalize(currentValue);
611 630
        } else if (leaving.getTagName().equals("pathexpr")) {
612 631
              currentPathexpr = textBuffer.toString().trim();
613 632
        } else if (leaving.getTagName().equals("returndoctype")) {
......
621 640
        } else if (leaving.getTagName().equals("owner")) {
622 641
              ownerList.add(textBuffer.toString().trim());
623 642
        }
624

  
643
        String normalizedXML = textBuffer.toString().trim();
644
        logMetacat.debug("================before normailze "+normalizedXML);
645
        normalizedXML =  MetaCatUtil.normalize(normalizedXML);
646
        logMetacat.debug("================after normailze "+normalizedXML);
647
        xml.append(normalizedXML);
648
        xml.append("</");
649
        xml.append(localName);
650
        xml.append(">");
625 651
        //rest textBuffer
626 652
        textBuffer = new StringBuffer();
627 653

  
628 654
    }
655
    
656
    /**
657
     * Gets normailized query string in xml format, which can be transformed
658
     * to html
659
     */
660
    public String getNormalizedXMLQuery()
661
    {
662
    	//System.out.println("normailized xml \n"+xml.toString());
663
    	return xml.toString();
664
    }
665
    
629 666

  
630 667
    /**
631 668
     * callback method used by the SAX Parser when the text sequences of an xml
......
636 673
    {
637 674
      // buffer all text nodes for same element. This is for text was splited
638 675
      // into different nodes
639
      textBuffer.append(new String(ch, start, length));
676
      String text = new String(ch, start, length);
677
      logMetacat.debug("the text in characters "+text);
678
      textBuffer.append(text);
640 679

  
641 680
    }
642 681

  

Also available in: Unified diff