Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 91   Methods: 2
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TextQuery.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: TextQuery.java 578602 2007-09-23 20:33:31Z natalia $
 18    */
 19   
 20    package org.apache.xindice.tools.command;
 21   
 22    import org.apache.xindice.tools.XMLTools;
 23    import org.apache.xindice.client.TextQueryService;
 24    import org.xmldb.api.base.Collection;
 25    import org.xmldb.api.base.ResourceIterator;
 26    import org.xmldb.api.base.ResourceSet;
 27    import org.xmldb.api.modules.XMLResource;
 28    import org.xmldb.api.DatabaseManager;
 29   
 30    /**
 31    * TextQuery is designed to enable the user to query a Collection for
 32    * Documents that match Lucene query.
 33    *
 34    * @version $Revision: 578602 $, $Date: 2007-09-23 13:33:31 -0700 (Sun, 23 Sep 2007) $
 35    */
 36    public class TextQuery extends Command {
 37   
 38  0 public boolean execute(XMLTools.Config table) throws Exception {
 39  0 if (table.getString(XMLTools.COLLECTION) == null) {
 40  0 System.out.println("ERROR : Collection name and switch required");
 41  0 return false;
 42    }
 43   
 44  0 if ("".equals(table.getString(XMLTools.QUERY))) {
 45  0 System.out.println("ERROR : Query and switch required");
 46  0 return false;
 47    }
 48   
 49  0 Collection col = null;
 50  0 try {
 51  0 String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
 52    table.getBoolean(XMLTools.LOCAL));
 53  0 String querystring = table.getString(XMLTools.QUERY);
 54   
 55  0 col = DatabaseManager.getCollection(colstring);
 56   
 57  0 if (col == null) {
 58  0 System.out.println("ERROR : Collection not found!");
 59  0 return false;
 60    }
 61   
 62  0 TextQueryService service = (TextQueryService) col.getService("TextQueryService", "1.0");
 63   
 64  0 ResourceSet resultSet = service.query(querystring);
 65  0 ResourceIterator results = resultSet.getIterator();
 66   
 67  0 while (results.hasMoreResources()) {
 68  0 XMLResource resource = (XMLResource) results.nextResource();
 69  0 String documentstr = (String) resource.getContent();
 70  0 System.out.println(documentstr);
 71    }
 72    } finally {
 73  0 if (col != null) {
 74  0 col.close();
 75    }
 76    }
 77   
 78  0 return true;
 79    }
 80   
 81  0 public void usage() {
 82  0 System.out.println("Format: xindice text -c <context> [-l [-d <path>]] [-v] [parameters...]");
 83  0 System.out.println();
 84  0 System.out.println("Searches collection for documents matching given text query");
 85  0 System.out.println();
 86  0 System.out.println("Command-specific switches:");
 87  0 System.out.println(" -q|--query <query>");
 88  0 System.out.println(" Lucene text query");
 89  0 System.out.println();
 90    }
 91    }