Project

General

Profile

« Previous | Next » 

Revision 2093

Added by Jing Tao over 20 years ago

Fixed a bug the text filed in path xml query maybe splited.

View differences:

src/edu/ucsb/nceas/metacat/QuerySpecification.java
1 1
/**
2 2
 *  '$RCSfile$'
3
 *    Purpose: A Class that represents a structured query, and can be 
4
 *             constructed from an XML serialization conforming to 
5
 *             pathquery.dtd. The printSQL() method can be used to print 
3
 *    Purpose: A Class that represents a structured query, and can be
4
 *             constructed from an XML serialization conforming to
5
 *             pathquery.dtd. The printSQL() method can be used to print
6 6
 *             a SQL serialization of the query.
7 7
 *  Copyright: 2000 Regents of the University of California and the
8 8
 *             National Center for Ecological Analysis and Synthesis
......
50 50
/**
51 51
 * A Class that represents a structured query, and can be constructed from an
52 52
 * XML serialization conforming to
53
 * 
53
 *
54 54
 * @see pathquery.dtd. The printSQL() method can be used to print a SQL
55 55
 *      serialization of the query.
56 56
 */
......
115 115

  
116 116
    private int countAttributeReturnField = 0;
117 117

  
118
    private StringBuffer textBuffer = new StringBuffer();
119

  
118 120
    /**
119 121
     * construct an instance of the QuerySpecification class
120
     * 
122
     *
121 123
     * @param queryspec
122 124
     *            the XML representation of the query (should conform to
123 125
     *            pathquery.dtd) as a Reader
......
157 159

  
158 160
    /**
159 161
     * construct an instance of the QuerySpecification class
160
     * 
162
     *
161 163
     * @param queryspec
162 164
     *            the XML representation of the query (should conform to
163 165
     *            pathquery.dtd) as a String
......
174 176
    /**
175 177
     * construct an instance of the QuerySpecification class which don't need
176 178
     * to parser a xml document
177
     * 
179
     *
178 180
     * @param accNumberSeparator
179 181
     *            the separator between doc version
180 182
     */
......
193 195

  
194 196
    /**
195 197
     * Method to set user name
196
     * 
198
     *
197 199
     * @param myName
198 200
     *            the user name
199 201
     */
......
209 211

  
210 212
    /**
211 213
     * Method to set user group
212
     * 
214
     *
213 215
     * @param myGroup
214 216
     *            the user group
215 217
     */
......
340 342
     * can get docid from both user specified query and access control query.
341 343
     * We don't need to checking permission after we get the doclist. It will
342 344
     * be good to performance
343
     *  
345
     *
344 346
     */
345 347
    public String getAccessQuery()
346 348
    {
......
604 606
            currentPathexpr = null;
605 607
        } else if (leaving.getTagName().equals("querygroup")) {
606 608
            QueryGroup leavingGroup = (QueryGroup) queryStack.pop();
609
        } else if (leaving.getTagName().equals("meta_file_id")) {
610
              meta_file_id = textBuffer.toString().trim();
611
        } else if (leaving.getTagName().equals("querytitle")) {
612
              queryTitle = textBuffer.toString().trim();
613
        } else if (leaving.getTagName().equals("value")) {
614
              currentValue = textBuffer.toString().trim();
615
        } else if (leaving.getTagName().equals("pathexpr")) {
616
              currentPathexpr = textBuffer.toString().trim();
617
        } else if (leaving.getTagName().equals("returndoctype")) {
618
              returnDocList.add(textBuffer.toString().trim());
619
        } else if (leaving.getTagName().equals("filterdoctype")) {
620
              filterDocList.add(textBuffer.toString().trim());
621
        } else if (leaving.getTagName().equals("returnfield")) {
622
              handleReturnField(textBuffer.toString().trim());
623
        } else if (leaving.getTagName().equals("filterdoctype")) {
624
              filterDocList.add(textBuffer.toString().trim());
625
        } else if (leaving.getTagName().equals("owner")) {
626
              ownerList.add(textBuffer.toString().trim());
627
        } else if (leaving.getTagName().equals("site")) {
628
              siteList.add(textBuffer.toString().trim());
607 629
        }
630

  
631
        //rest textBuffer
632
        textBuffer = null;
633
        textBuffer = new StringBuffer();
634

  
608 635
    }
609 636

  
610 637
    /**
......
614 641
     */
615 642
    public void characters(char ch[], int start, int length)
616 643
    {
644
      // buffer all text nodes for same element. This is for text was splited
645
      // into different nodes
646
      textBuffer.append(new String(ch, start, length));
617 647

  
618
        String inputString = new String(ch, start, length);
619
        BasicNode currentNode = (BasicNode) elementStack.peek();
620
        String currentTag = currentNode.getTagName();
621
        if (currentTag.equals("meta_file_id")) {
622
            meta_file_id = inputString;
623
        } else if (currentTag.equals("querytitle")) {
624
            queryTitle = inputString;
625
        } else if (currentTag.equals("value")) {
626
            currentValue = inputString;
627
        } else if (currentTag.equals("pathexpr")) {
628
            currentPathexpr = inputString;
629
        } else if (currentTag.equals("returndoctype")) {
630
            returnDocList.add(inputString);
631
        } else if (currentTag.equals("filterdoctype")) {
632
            filterDocList.add(inputString);
633
        } else if (currentTag.equals("returnfield")) {
634
            handleReturnField(inputString);
635
        } else if (currentTag.equals("filterdoctype")) {
636
            filterDocList.add(inputString);
637
        } else if (currentTag.equals("owner")) {
638
            ownerList.add(inputString);
639
        } else if (currentTag.equals("site")) {
640
            siteList.add(inputString);
641
        }
642 648
    }
643 649

  
644 650
    /**
......
808 814
    /**
809 815
     * This method prints sql based upon the <returnfield> tag in the
810 816
     * pathquery document. This allows for customization of the returned fields.
811
     * If the boolean useXMLIndex paramter is false, it uses a recursive query on 
812
     * xml_nodes to find the fields to be included by their path expression, and 
817
     * If the boolean useXMLIndex paramter is false, it uses a recursive query on
818
     * xml_nodes to find the fields to be included by their path expression, and
813 819
     * avoids the use of the xml_index table.
814
     * 
820
     *
815 821
     * @param doclist the list of document ids to search
816
     * @param unaccessableNodePair the node pairs (start id and end id) which 
822
     * @param unaccessableNodePair the node pairs (start id and end id) which
817 823
     *            this user should not access
818
     * @param useXMLIndex a boolean flag indicating whether to search using 
824
     * @param useXMLIndex a boolean flag indicating whether to search using
819 825
     *            xml_index
820 826
     */
821 827
    public String printExtendedSQL(String doclist,
......
833 839
                if (firstfield) {
834 840
                    firstfield = false;
835 841
                } else {
836
                    self.append(" UNION ");   
842
                    self.append(" UNION ");
837 843
                }
838 844
                String path  = (String) returnFieldList.elementAt(i);
839 845
                self.append("select xml_nodes.docid, ");
......
842 848
                self.append("from xml_nodes, xml_documents ");
843 849
                self.append("where parentnodeid IN ");
844 850
                self.append(QueryTerm.useNestedStatements(path));
845
                
851

  
846 852
                self.append(" AND xml_nodes.docid in (");
847 853
                self.append(doclist);
848 854
                self.append(") AND xml_nodes.nodetype = 'TEXT'");
849 855
                self.append(" AND xml_nodes.rootnodeid = xml_documents.rootnodeid");
850
                
856

  
851 857
                addAccessRestrictionSQL(unaccessableNodePair, self);
852 858
            }
853 859

  
854 860
            return self.toString();
855 861
        }
856 862
    }
857
    
863

  
858 864
    /**
859 865
     * This method prints sql based upon the <returnfield> tag in the
860 866
     * pathquery document. This allows for customization of the returned fields.
861 867
     * It uses the xml_index table and so assumes that this table has been
862 868
     * built.
863
     * 
869
     *
864 870
     * @param doclist the list of document ids to search
865
     * @param unaccessableNodePair the node pairs (start id and end id) 
871
     * @param unaccessableNodePair the node pairs (start id and end id)
866 872
     *            which this user should not access
867 873
     */
868
    public String printExtendedSQL(String doclist, 
874
    public String printExtendedSQL(String doclist,
869 875
            Hashtable unaccessableNodePair)
870 876
    {
871 877
        StringBuffer self = new StringBuffer();
......
904 910
     * containing the start nodeid and the value containing the end nodeid.
905 911
     * Any nodes between these start and end nodeid values will be excluded
906 912
     * from the results.
907
     * 
913
     *
908 914
     * @param unaccessableNodePair hash of start/end nodeid pairs to restrict
909
     * @param self a stringbuffer to which the genrated SQL is appended 
915
     * @param self a stringbuffer to which the genrated SQL is appended
910 916
     */
911
    private void addAccessRestrictionSQL(Hashtable unaccessableNodePair, 
917
    private void addAccessRestrictionSQL(Hashtable unaccessableNodePair,
912 918
            StringBuffer self)
913 919
    {
914 920
        // add control part for extended query
......
934 940
    /**
935 941
     * This method prints sql that finds the values of attributes in the xml
936 942
     * documents based upon the whether the returnfield tag in the pathquery
937
     * document has an attribute symbol (@). This allows for customization of 
943
     * document has an attribute symbol (@). This allows for customization of
938 944
     * the returned fields.
939
     * 
945
     *
940 946
     * @param doclist the list of document ids to search
941
     * @param useXMLIndex a boolean flag indicating whether to search using 
947
     * @param useXMLIndex a boolean flag indicating whether to search using
942 948
     *            xml_index
943 949
     */
944 950
    public String printAttributeQuery(String doclist, boolean useXMLIndex)
......
958 964
                if (firstfield) {
959 965
                    firstfield = false;
960 966
                } else {
961
                    self.append(" UNION ");   
967
                    self.append(" UNION ");
962 968
                }
963 969
                self.append("select xml_nodes.docid, '");
964 970
                self.append(returnPath);
......
973 979
                self.append(") AND xml_nodes.nodetype = 'ATTRIBUTE'");
974 980
                self.append(" AND xml_nodes.rootnodeid = xml_documents.rootnodeid");
975 981
            }
976
            
982

  
977 983
            MetaCatUtil.debugMessage("Attribute query: " + self.toString(), 30);
978 984

  
979
            return self.toString();            
985
            return self.toString();
980 986
        }
981 987
    }
982 988

  
983 989
    /**
984 990
     * This method prints sql that finds the values of attributes in the xml
985 991
     * documents based upon the whether the returnfield tag in the pathquery
986
     * document has an attribute symbol (@). This allows for customization of 
992
     * document has an attribute symbol (@). This allows for customization of
987 993
     * the returned fields.
988
     * 
994
     *
989 995
     * @param doclist the list of document ids to search
990 996
     */
991 997
    public String printAttributeQuery(String doclist)

Also available in: Unified diff