[Yanel-commits] rev 43983 - in
public/yanel/trunk/src/contributions/resources/search/src:
build java/org/wyona/yanel/impl/resources/search
michi at wyona.com
michi at wyona.com
Tue Aug 4 16:13:46 CEST 2009
Author: michi
Date: 2009-08-04 16:13:45 +0200 (Tue, 04 Aug 2009)
New Revision: 43983
Modified:
public/yanel/trunk/src/contributions/resources/search/src/build/dependencies.xml
public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java
Log:
external search provider implemented
Modified: public/yanel/trunk/src/contributions/resources/search/src/build/dependencies.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/search/src/build/dependencies.xml 2009-08-04 13:56:58 UTC (rev 43982)
+++ public/yanel/trunk/src/contributions/resources/search/src/build/dependencies.xml 2009-08-04 14:13:45 UTC (rev 43983)
@@ -11,12 +11,15 @@
<dependency groupId="wyona-org-yanel" artifactId="yanel-impl" version="${yanel.source.version}"/>
<dependency groupId="javax.servlet" artifactId="servlet-api" version="2.3"/>
<dependency groupId="wyona-org-meguni" artifactId="wyona-org-meguni" version="0.1-rREVISION"/>
+ <dependency groupId="avalon-framework" artifactId="avalon-framework-api" version="4.3"/>
+ <dependency groupId="avalon-framework" artifactId="avalon-framework-impl" version="4.3"/>
</artifact:dependencies>
<artifact:dependencies pathId="maven2.resource.classpath" filesetId="maven2.resource.fileset">
<remoteRepository refid="wyona.remote.repository"/>
<dependency groupId="wyona-org-meguni" artifactId="wyona-org-meguni" version="0.1-rREVISION"/>
- <!-- No resource specific libs yet -->
+ <dependency groupId="avalon-framework" artifactId="avalon-framework-api" version="4.3"/>
+ <dependency groupId="avalon-framework" artifactId="avalon-framework-impl" version="4.3"/>
</artifact:dependencies>
<property name="maven2.cp" refid="maven2.classpath"/>
Modified: public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java 2009-08-04 13:56:58 UTC (rev 43982)
+++ public/yanel/trunk/src/contributions/resources/search/src/java/org/wyona/yanel/impl/resources/search/SearchResource.java 2009-08-04 14:13:45 UTC (rev 43983)
@@ -4,6 +4,7 @@
package org.wyona.yanel.impl.resources.search;
+import org.wyona.yanel.core.attributes.viewable.View;
import org.wyona.yanel.impl.resources.BasicXMLResource;
import java.io.ByteArrayInputStream;
@@ -14,12 +15,36 @@
import org.wyona.meguni.parser.Parser;
import org.wyona.meguni.util.ResultSet;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationUtil;
+
/**
* Search resource
*/
public class SearchResource extends BasicXMLResource {
private static Logger log = Logger.getLogger(SearchResource.class);
+
+ /**
+ * @see org.wyona.yanel.core.api.attributes.ViewableV2#getView(String)
+ */
+ public View getView(String viewId) throws Exception {
+ String provider = getRequest().getParameter("provider");
+ if (provider != null && !provider.equals("yanel")) {
+ ExternalSearchProvider esp = getExternalSearchProvider(provider);
+ if (esp != null) {
+ View view = new View();
+ view.setResponse(false); // this resource writes the response itself
+
+ javax.servlet.http.HttpServletResponse response = getResponse();
+ response.setStatus(307);
+ String query = getRequest().getParameter("q");
+ response.setHeader("Location", esp.getURL() + query);
+ return view;
+ }
+ }
+ return super.getView(viewId);
+ }
/*
* @see org.wyona.yanel.impl.resources.BasicXMLResource#getContentXML(String)
@@ -136,9 +161,49 @@
}
/**
- * @see ViewableV2#exists()
+ * @see org.wyona.yanel.core.api.attributes.ViewableV2#exists()
*/
- public boolean exists() {
+ public boolean exists() throws Exception {
return true;
}
+
+ /**
+ *
+ */
+ private ExternalSearchProvider getExternalSearchProvider(String providerId) throws Exception {
+ org.w3c.dom.Document customConfigDoc = getConfiguration().getCustomConfiguration();
+ if (customConfigDoc != null) {
+ Configuration config = ConfigurationUtil.toConfiguration(customConfigDoc.getDocumentElement());
+ Configuration externalSearchProvidersConfig = config.getChild("external-search-providers");
+ Configuration[] searchProviders = externalSearchProvidersConfig.getChildren("provider");
+ for (int i = 0; i < searchProviders.length; i++) {
+ if (searchProviders[i].getAttribute("id").equals(providerId)) {
+ return new ExternalSearchProvider(providerId, searchProviders[i].getAttribute("url"), null);
+ }
+ }
+ }
+ return null;
+ }
}
+
+/**
+ *
+ */
+class ExternalSearchProvider {
+
+ private String url;
+
+ /**
+ *
+ */
+ public ExternalSearchProvider(String id, String url, String label) {
+ this.url = url;
+ }
+
+ /**
+ *
+ */
+ public String getURL() {
+ return url;
+ }
+}
More information about the Yanel-commits
mailing list