[Yanel-commits] rev 29812 - public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend

michi at wyona.com michi at wyona.com
Wed Dec 12 21:22:40 CET 2007


Author: michi
Date: 2007-12-12 21:22:40 +0100 (Wed, 12 Dec 2007)
New Revision: 29812

Modified:
   public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend/FindFriendResource.java
Log:
methods refactored and new order

Modified: public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend/FindFriendResource.java
===================================================================
--- public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend/FindFriendResource.java	2007-12-12 20:20:39 UTC (rev 29811)
+++ public/yanel/contributions/realms/foaf/src/resources/findfriend/src/java/org/wyona/yanel/impl/resources/findfriend/FindFriendResource.java	2007-12-12 20:22:40 UTC (rev 29812)
@@ -70,8 +70,46 @@
         StringBuffer sb = new StringBuffer("<foaf xmlns=\"http://www.wyona.org/foaf/1.0\">");
         String qs = getRequest().getParameter("q");
         if (qs != null) {
+            sb.append(getLocalResults(qs));
+            sb.append(getThirdPartyResults(qs));
+        }
+        sb.append("</foaf>");
 
-        // Results from Google, Facebook, ...
+        View view = new View();
+        if (viewId != null && viewId.equals("source")) {
+            view.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
+        } else {
+            StreamSource source = new StreamSource(new java.io.StringBufferInputStream(sb.toString()));
+            java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); 
+            getTransformer().transform(source, new StreamResult(baos));
+            view.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
+        }
+        view.setMimeType(getMimeType(viewId));
+        return view;
+    }
+
+    /**
+     *
+     */
+    public ViewDescriptor[] getViewDescriptors() {
+        return null;
+    }
+
+    /**
+     *
+     */
+    private ResultSet getSearchResults(String queryString) throws Exception {
+        String className = getResourceConfigProperty("parser");
+        if (className == null) className = "org.wyona.meguni.parser.impl.MSNParser";
+        Parser parser = (Parser) Class.forName(className).newInstance();
+        return parser.parse(queryString);
+    }
+
+    /**
+     * Results from Google, Facebook, ...
+     */
+    private StringBuffer getThirdPartyResults(String qs) {
+        StringBuffer sb = new StringBuffer("");
         try {
             ResultSet resultSet = getSearchResults(qs.replaceAll(" ", "+") + "+FOAF");
 
@@ -97,14 +135,19 @@
         } catch (Exception e) {
             sb.append("<exception>" + e.getMessage() + "</exception>");
         }
+        return sb;
+    }
 
-        // Results from Wyona-FOAF
-        // TODO: Remove hard-coded ...
-            sb.append("<provider source-name=\"" + "Wyona-FOAF" + "\" source-domain=\"" + "http://foaf.wyona.org" + "\" numberOfResults=\"" + "1" + "\">");
+    /**
+     * Results from Wyona-FOAF
+     */
+    private StringBuffer getLocalResults(String qs) throws Exception {
+        StringBuffer sb = new StringBuffer("");
+        sb.append("<provider source-name=\"" + "Wyona-FOAF" + "\" source-domain=\"" + "http://foaf.wyona.org" + "\" numberOfResults=\"" + "1" + "\">");
 
-            Repository pRepo = getProfilesRepository();
-            Node[] pNodes = pRepo.search(qs);
-            if (pNodes != null) {
+        Repository pRepo = getProfilesRepository();
+        Node[] pNodes = pRepo.search(qs);
+        if (pNodes != null) {
             for (int i = 0; i < pNodes.length; i++) {
                 org.wyona.foaf.api.basics.Person person = new org.wyona.foaf.impl.basics.PersonImpl(pNodes[i].getInputStream());
                 sb.append("<result number=\"" + "1" + "\" source-name=\"" + "Wyona-FOAF" + "\">");
@@ -119,49 +162,19 @@
                 sb.append("<no-results/>");
             }
 
+// TODO: Implement Advanced Search
 /*
             Nodes[] nodes = getRealm().getRepository().searchProperty("firstname", firstname);
             Nodes[] nodes = getRealm().getRepository().searchProperty("lastname", lastname);
 */
 
-            sb.append("</provider>");
-        }
-
-        sb.append("</foaf>");
-
-        View view = new View();
-        if (viewId != null && viewId.equals("source")) {
-            view.setInputStream(new java.io.StringBufferInputStream(sb.toString()));
-        } else {
-            StreamSource source = new StreamSource(new java.io.StringBufferInputStream(sb.toString()));
-            java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); 
-            getTransformer().transform(source, new StreamResult(baos));
-            view.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
-        }
-        view.setMimeType(getMimeType(viewId));
-        return view;
+        sb.append("</provider>");
+        return sb;
     }
 
     /**
      *
      */
-    public ViewDescriptor[] getViewDescriptors() {
-        return null;
-    }
-
-    /**
-     *
-     */
-    private ResultSet getSearchResults(String queryString) throws Exception {
-        String className = getResourceConfigProperty("parser");
-        if (className == null) className = "org.wyona.meguni.parser.impl.MSNParser";
-        Parser parser = (Parser) Class.forName(className).newInstance();
-        return parser.parse(queryString);
-    }
-
-    /**
-     *
-     */
     private Transformer getTransformer() throws Exception {
         File xsltFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "foaf2xhtml.xsl");
         Transformer tf = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltFile));



More information about the Yanel-commits mailing list