1 23 24 package org.apache.slide.search.basic; 25 26 import org.apache.slide.content.NodeProperty.NamespaceCache; 28 29 import org.apache.slide.search.SearchLanguage; 30 import org.apache.slide.search.SearchQuery; 31 import org.apache.slide.search.QueryScope; 32 import org.apache.slide.search.SearchToken; 33 import org.apache.slide.search.BadQueryException; 34 import org.apache.slide.search.PropertyProvider; 35 36 import org.apache.slide.store.AbstractStore; 37 import org.apache.slide.common.SlideRuntimeException; 38 import org.apache.slide.common.Uri; 39 40 import org.jdom.Element; 41 import org.jdom.Document; 42 43 import org.jdom.input.SAXBuilder; 44 45 import java.io.StringReader ; 46 47 52 public class BasicSearchLanguage extends SearchLanguage { 53 54 static final String GRAMMAR_NAME = 55 "basicsearch"; 56 57 static final String GRAMMAR_NAMESPACE = NamespaceCache.DEFAULT_URI; 58 59 60 static public final String BASIC_QUERY_CLASS = "basicQueryClass"; 61 62 public BasicSearchLanguage () {} 63 64 69 public String getName() { 70 return GRAMMAR_NAME; 71 } 72 73 78 public String getGrammarUri() { 79 return GRAMMAR_NAMESPACE; 80 } 81 82 94 public SearchQuery parseQuery (String queryString, SearchToken token, PropertyProvider propertyProvider) throws BadQueryException { 95 try { 97 Document doc = 98 new SAXBuilder ().build (new StringReader (queryString)); 99 100 Element root = doc.getRootElement(); 101 return parseQuery(root, token, propertyProvider); 102 } 103 catch (Exception e) { 104 e.printStackTrace(); 105 throw new BadQueryException (e.getMessage()); 106 } 107 } 108 109 122 public SearchQuery parseQuery (Element basicSearchElement, SearchToken token, PropertyProvider propertyProvider) throws BadQueryException { 123 boolean useEnvelope = true; 124 125 126 QueryScope scope = BasicQueryImpl.getScope (basicSearchElement); 127 IBasicQuery query = null; 128 129 130 if (useEnvelope) { 131 query = new BasicQueryEnvelope (token, scope); 132 133 } 134 else { 135 136 Uri uri = token.getNamespace().getUri(token.getSlideToken(), token.getSlideContext().getSlidePath(scope.getHref())); 138 139 AbstractStore store = (AbstractStore)uri.getStore(); 140 String className = (String )store.getParameter (BASIC_QUERY_CLASS); 141 142 if (className != null) { 143 try { 144 Class queryClass = Class.forName (className); 145 query = (IBasicQuery) queryClass.newInstance(); 146 ((IBasicQuery) query).init (token); 147 } 148 catch (Exception e) { 149 e.printStackTrace(); 150 throw new SlideRuntimeException (e.getMessage()); 151 } 152 } 153 154 else { 155 query = new BasicQueryImpl(token); 156 } 157 } 158 159 query.parseQueryElement(basicSearchElement, propertyProvider); 161 162 return (SearchQuery) query; 163 } 164 } 165 166 | Popular Tags |