cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/generation SearchGenerator.java
Date Sat, 27 Sep 2003 13:21:11 GMT
joerg       2003/09/27 06:21:11

  Modified:    src/blocks/lucene/java/org/apache/cocoon/generation
                        SearchGenerator.java
  Log:
  fixed namespace output (bug 23434, thanks to Conal Tuohy)
  
  Revision  Changes    Path
  1.4       +91 -51    cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/generation/SearchGenerator.java
  
  Index: SearchGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/generation/SearchGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SearchGenerator.java	4 Sep 2003 09:38:38 -0000	1.3
  +++ SearchGenerator.java	27 Sep 2003 13:21:11 -0000	1.4
  @@ -128,6 +128,7 @@
    * @author <a href="mailto:berni_huber@a1.net">Bernhard Huber</a>
    * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
    * @author <a href="mailto:jeremy@apache.org">Jeremy Quinn</a>
  + * @author <a href="mailto:conal@nzetc.org">Conal Tuohy</a>
    * @version CVS $Id$
    */
   public class SearchGenerator extends ServiceableGenerator
  @@ -137,12 +138,17 @@
       /**
        * The XML namespace for the output document.
        */
  -    protected final static String namespace = "http://apache.org/cocoon/search/1.0";
  +    protected final static String NAMESPACE = "http://apache.org/cocoon/search/1.0";
  +
  +    /**
  +     * The XML namespace prefix for the output document.
  +     */
  +    protected final static String PREFIX = "search";
   
       /**
        * The XML namespace for xlink
        */
  -    protected final static String xlinkNamespace = "http://www.w3.org/1999/xlink";
  +    protected final static String XLINK_NAMESPACE = "http://www.w3.org/1999/xlink";
   
       /**
        * Description of the Field
  @@ -150,11 +156,17 @@
       protected final static String CDATA = "CDATA";
   
       /**
  -     * Root element of generated xml content, ie <code>results</code>.
  +     * Name of root element of generated xml content, ie <code>results</code>.
        */
       protected final static String RESULTS_ELEMENT = "results";
   
       /**
  +     * Qualified name of root element of generated xml content, ie <code>search:results</code>.
  +     */
  +    protected final static String Q_RESULTS_ELEMENT = PREFIX + ":" + RESULTS_ELEMENT;
  +
  +
  +    /**
        * Attribute <code>date</code> of <code>results</code> element.
        * It contains the date a long value, indicating when a search
        * generated this xml content.
  @@ -169,23 +181,34 @@
   
       /**
        * Attribute <code>start-index</code> of <code>results</code>
element.
  -     * Echos the <code>startIndex</code> query parameter.
  +     * Echoes the <code>startIndex</code> query parameter.
        */
       protected final static String START_INDEX_ATTRIBUTE = "start-index";
   
       /**
        * Attribute <code>page-length</code> of <code>results</code>
element.
  -     * Echos the <code>pageLenth</code> query parameter.
  +     * Echoes the <code>pageLenth</code> query parameter.
        */
       protected final static String PAGE_LENGTH_ATTRIBUTE = "page-length";
   
       /**
  +     * Attribute <code>name</code> of <code>hit</code> element.
  +     */
  +    protected final static String NAME_ATTRIBUTE = "name";
  +    
  +    /**
        * Child element of generated xml content, ie <code>hits</code>.
        * This element describes all hits.
        */
       protected final static String HITS_ELEMENT = "hits";
   
       /**
  +     * QName of child element of generated xml content, ie <code>search:hits</code>.
  +     * This element describes all hits.
  +     */
  +    protected final static String Q_HITS_ELEMENT = PREFIX + ":" + HITS_ELEMENT;
  +
  +    /**
        * Attribute <code>total-count</code> of <code>hits</code>
element.
        * The value describes total number of hits found by the search engine.
        */
  @@ -204,6 +227,12 @@
       protected final static String HIT_ELEMENT = "hit";
   
       /**
  +     * QName of child element of generated xml content, ie <code>search:hit</code>.
  +     * This element describes a single hit.
  +     */
  +    protected final static String Q_HIT_ELEMENT = PREFIX + ":" + HIT_ELEMENT;
  +
  +    /**
        * Attribute <code>rank</code> of <code>hit</code> element.
        * The value describes the count index of this hits, ranging between 0, and
        * total-count minus 1.
  @@ -231,18 +260,34 @@
       protected final static String FIELD_ELEMENT = "field";
   
       /**
  +     * QName of child element <code>search:field</code> of the <code>hit</code>
element.
  +     */
  +    protected final static String Q_FIELD_ELEMENT = PREFIX + ":" + FIELD_ELEMENT;
  +
  +    /**
        * Child element of generated xml content, ie <code>navigation</code>.
        * This element describes some hints for easier navigation.
        */
       protected final static String NAVIGATION_ELEMENT = "navigation";
   
       /**
  -     * Child element of generated xml content, ie <code>navigation</code>.
  +     * QName of child element of generated xml content, ie <code>search:navigation</code>.
  +     */
  +    protected final static String Q_NAVIGATION_ELEMENT = PREFIX + ":" + NAVIGATION_ELEMENT;
  +
  +    /**
  +     * Child element of generated xml content, ie <code>navigation-page</code>.
        * This element describes the start-index of page containing hits.
        */
       protected final static String NAVIGATION_PAGE_ELEMENT = "navigation-page";
   
       /**
  +     * QName of child element of generated xml content, ie <code>search:navigation-page</code>.
  +     * This element describes the start-index of page containing hits.
  +     */
  +    protected final static String Q_NAVIGATION_PAGE_ELEMENT = PREFIX + ":" + NAVIGATION_PAGE_ELEMENT;
  +
  +    /**
        * Attribute <code>has-next</code> of <code>navigation-page</code>
element.
        * The value is true if a next navigation control should be presented.
        */
  @@ -438,16 +483,15 @@
   
           // try getting the queryString from the generator sitemap params
           
  -        queryString = "";
           queryString = par.getParameter(QUERY_PARAM, "");
           
           // try getting the queryString from the request params
           if (queryString.equals("")) {
  -					param_name = par.getParameter(QUERY_STRING_PARAM, QUERY_STRING_PARAM_DEFAULT);
  -					if (request.getParameter(param_name) != null) {
  -							queryString = request.getParameter(param_name);
  -					}
  -				}
  +            param_name = par.getParameter(QUERY_STRING_PARAM, QUERY_STRING_PARAM_DEFAULT);
  +            if (request.getParameter(param_name) != null) {
  +                queryString = request.getParameter(param_name);
  +            }
  +        }
           // always try lookup the start index from the request params
           // get startIndex
           startIndex = null;
  @@ -523,14 +567,14 @@
   
           // Start the document and set the namespace.
           this.contentHandler.startDocument();
  -        this.contentHandler.startPrefixMapping("search", namespace);
  -        this.contentHandler.startPrefixMapping("xlink", xlinkNamespace);
  +        this.contentHandler.startPrefixMapping(PREFIX, NAMESPACE);
  +        this.contentHandler.startPrefixMapping("xlink", XLINK_NAMESPACE);
   
           generateResults();
   
           // End the document.
           this.contentHandler.endPrefixMapping("xlink");
  -        this.contentHandler.endPrefixMapping("");
  +        this.contentHandler.endPrefixMapping(PREFIX);
           this.contentHandler.endDocument();
       }
   
  @@ -538,7 +582,7 @@
       /**
        * Create an Integer.
        * <p>
  -     *   Create an Integer from String s, iff conversion fails return null.
  +     *   Create an Integer from String s, if conversion fails return null.
        * </p>
        *
        * @param  s  Converting s to an Integer
  @@ -579,24 +623,20 @@
           long time = System.currentTimeMillis();
   
           atts.clear();
  -        atts.addAttribute(namespace, DATE_ATTRIBUTE,
  -            DATE_ATTRIBUTE, CDATA, String.valueOf(time));
  +        atts.addAttribute("", DATE_ATTRIBUTE, DATE_ATTRIBUTE, CDATA, String.valueOf(time));
           if (queryString != null && queryString.length() > 0)
  -            atts.addAttribute(namespace, QUERY_STRING_ATTRIBUTE,
  -                QUERY_STRING_ATTRIBUTE, CDATA, String.valueOf(queryString));
  -        atts.addAttribute(namespace, START_INDEX_ATTRIBUTE,
  -            START_INDEX_ATTRIBUTE, CDATA, String.valueOf(startIndex));
  -        atts.addAttribute(namespace, PAGE_LENGTH_ATTRIBUTE,
  -            PAGE_LENGTH_ATTRIBUTE, CDATA, String.valueOf(pageLength));
  +            atts.addAttribute("", QUERY_STRING_ATTRIBUTE, QUERY_STRING_ATTRIBUTE, CDATA,
String.valueOf(queryString));
  +        atts.addAttribute("", START_INDEX_ATTRIBUTE, START_INDEX_ATTRIBUTE, CDATA, String.valueOf(startIndex));
  +        atts.addAttribute("", PAGE_LENGTH_ATTRIBUTE, PAGE_LENGTH_ATTRIBUTE, CDATA, String.valueOf(pageLength));
   
  -        contentHandler.startElement(namespace, RESULTS_ELEMENT, RESULTS_ELEMENT, atts);
  +        contentHandler.startElement(NAMESPACE, RESULTS_ELEMENT, Q_RESULTS_ELEMENT, atts);
   
           // build xml from the hits
           generateHits(pager);
           generateNavigation(pager);
   
           // End root element.
  -        contentHandler.endElement(namespace, "results", "results");
  +        contentHandler.endElement(NAMESPACE, RESULTS_ELEMENT, Q_RESULTS_ELEMENT);
       }
   
   
  @@ -610,13 +650,13 @@
       private void generateHits(LuceneCocoonPager pager) throws SAXException {
           if (pager != null && pager.hasNext()) {
               atts.clear();
  -            atts.addAttribute(namespace, TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE,
  +            atts.addAttribute("", TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE,
                   CDATA, String.valueOf(pager.getCountOfHits()));
  -            atts.addAttribute(namespace, COUNT_OF_PAGES_ATTRIBUTE, COUNT_OF_PAGES_ATTRIBUTE,
  +            atts.addAttribute("", COUNT_OF_PAGES_ATTRIBUTE, COUNT_OF_PAGES_ATTRIBUTE,
                   CDATA, String.valueOf(pager.getCountOfPages()));
  -            contentHandler.startElement(namespace, HITS_ELEMENT, HITS_ELEMENT, atts);
  +            contentHandler.startElement(NAMESPACE, HITS_ELEMENT, Q_HITS_ELEMENT, atts);
               generateHit(pager);
  -            contentHandler.endElement(namespace, HITS_ELEMENT, HITS_ELEMENT);
  +            contentHandler.endElement(NAMESPACE, HITS_ELEMENT, Q_HITS_ELEMENT);
           }
       }
   
  @@ -642,13 +682,13 @@
               String uri = doc.get(LuceneXMLIndexer.URL_FIELD);
   
               atts.clear();
  -            atts.addAttribute(namespace, RANK_ATTRIBUTE, RANK_ATTRIBUTE, CDATA,
  +            atts.addAttribute("", RANK_ATTRIBUTE, RANK_ATTRIBUTE, CDATA,
                       String.valueOf(counter));
  -            atts.addAttribute(namespace, SCORE_ATTRIBUTE, SCORE_ATTRIBUTE, CDATA,
  +            atts.addAttribute("", SCORE_ATTRIBUTE, SCORE_ATTRIBUTE, CDATA,
                       String.valueOf(score));
  -            atts.addAttribute(namespace, URI_ATTRIBUTE, URI_ATTRIBUTE, CDATA,
  +            atts.addAttribute("", URI_ATTRIBUTE, URI_ATTRIBUTE, CDATA,
                       String.valueOf(uri));
  -            contentHandler.startElement(namespace, HIT_ELEMENT, HIT_ELEMENT, atts);
  +            contentHandler.startElement(NAMESPACE, HIT_ELEMENT, Q_HIT_ELEMENT, atts);
               // fix me, add here a summary of this hit
               for (Enumeration e = doc.fields(); e.hasMoreElements(); ) {
                   Field field = (Field)e.nextElement();
  @@ -656,15 +696,15 @@
                       if (LuceneXMLIndexer.URL_FIELD.equals(field.name()))
                           continue;
                       atts.clear();
  -                    atts.addAttribute(namespace, "name", "name", CDATA, field.name());
  -                    contentHandler.startElement(namespace, FIELD_ELEMENT, FIELD_ELEMENT,
atts);
  +                    atts.addAttribute("", NAME_ATTRIBUTE, NAME_ATTRIBUTE, CDATA, field.name());
  +                    contentHandler.startElement(NAMESPACE, FIELD_ELEMENT, Q_FIELD_ELEMENT,
atts);
                       String value = field.stringValue();
                       contentHandler.characters(value.toCharArray(), 0, value.length());
  -                    contentHandler.endElement(namespace, FIELD_ELEMENT, FIELD_ELEMENT);
  +                    contentHandler.endElement(NAMESPACE, FIELD_ELEMENT, Q_FIELD_ELEMENT);
                   }
               }
   
  -            contentHandler.endElement(namespace, HIT_ELEMENT, HIT_ELEMENT);
  +            contentHandler.endElement(NAMESPACE, HIT_ELEMENT, Q_HIT_ELEMENT);
           }
       }
   
  @@ -681,31 +721,31 @@
           if (pager != null) {
               // generate navigation element
               atts.clear();
  -            atts.addAttribute(namespace, TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE,
  +            atts.addAttribute("", TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE,
                   CDATA, String.valueOf(pager.getCountOfHits()));
  -            atts.addAttribute(namespace, COUNT_OF_PAGES_ATTRIBUTE, COUNT_OF_PAGES_ATTRIBUTE,
  +            atts.addAttribute("", COUNT_OF_PAGES_ATTRIBUTE, COUNT_OF_PAGES_ATTRIBUTE,
                   CDATA, String.valueOf(pager.getCountOfPages()));
  -            atts.addAttribute(namespace, HAS_NEXT_ATTRIBUTE, HAS_NEXT_ATTRIBUTE,
  +            atts.addAttribute("", HAS_NEXT_ATTRIBUTE, HAS_NEXT_ATTRIBUTE,
                   CDATA, String.valueOf(pager.hasNext()));
  -            atts.addAttribute(namespace, HAS_PREVIOUS_ATTRIBUTE, HAS_PREVIOUS_ATTRIBUTE,
  +            atts.addAttribute("", HAS_PREVIOUS_ATTRIBUTE, HAS_PREVIOUS_ATTRIBUTE,
                   CDATA, String.valueOf(pager.hasPrevious()));
  -            atts.addAttribute(namespace, NEXT_INDEX_ATTRIBUTE, NEXT_INDEX_ATTRIBUTE,
  +            atts.addAttribute("", NEXT_INDEX_ATTRIBUTE, NEXT_INDEX_ATTRIBUTE,
                   CDATA, String.valueOf(pager.nextIndex()));
  -            atts.addAttribute(namespace, PREVIOUS_INDEX_ATTRIBUTE, PREVIOUS_INDEX_ATTRIBUTE,
  +            atts.addAttribute("", PREVIOUS_INDEX_ATTRIBUTE, PREVIOUS_INDEX_ATTRIBUTE,
                   CDATA, String.valueOf(pager.previousIndex()));
  -            contentHandler.startElement(namespace, NAVIGATION_ELEMENT, NAVIGATION_ELEMENT,
atts);
  +            contentHandler.startElement(NAMESPACE, NAVIGATION_ELEMENT, Q_NAVIGATION_ELEMENT,
atts);
               int count_of_pages = pager.getCountOfPages();
               for (int i = 0, page_start_index = 0;
                       i < count_of_pages;
                       i++, page_start_index += pageLength.intValue()) {
                   atts.clear();
  -                atts.addAttribute(namespace, START_INDEX_ATTRIBUTE, START_INDEX_ATTRIBUTE,
  +                atts.addAttribute("", START_INDEX_ATTRIBUTE, START_INDEX_ATTRIBUTE,
                       CDATA, String.valueOf(page_start_index));
  -                contentHandler.startElement(namespace, NAVIGATION_PAGE_ELEMENT, NAVIGATION_PAGE_ELEMENT,
atts);
  -                contentHandler.endElement(namespace, NAVIGATION_PAGE_ELEMENT, NAVIGATION_PAGE_ELEMENT);
  +                contentHandler.startElement(NAMESPACE, NAVIGATION_PAGE_ELEMENT, Q_NAVIGATION_PAGE_ELEMENT,
atts);
  +                contentHandler.endElement(NAMESPACE, NAVIGATION_PAGE_ELEMENT, Q_NAVIGATION_PAGE_ELEMENT);
               }
               // navigation is EMPTY element
  -            contentHandler.endElement(namespace, NAVIGATION_ELEMENT, NAVIGATION_ELEMENT);
  +            contentHandler.endElement(NAMESPACE, NAVIGATION_ELEMENT, Q_NAVIGATION_ELEMENT);
           }
       }
   
  @@ -714,7 +754,7 @@
        * Build hits from a query input, and setup paging object.
        *
        * @since
  -     * @throws  ProcessingException  iff an error occurs
  +     * @throws  ProcessingException  if an error occurs
        */
       private LuceneCocoonPager buildHits() throws ProcessingException {
   
  
  
  

Mime
View raw message