Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r278 - trunk/sites/psi/java/ch/psi/idok/gwt/twiki/client

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r278 - trunk/sites/psi/java/ch/psi/idok/gwt/twiki/client


Chronological Thread 
  • From: "AFS account Roman Geus" <geus AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r278 - trunk/sites/psi/java/ch/psi/idok/gwt/twiki/client
  • Date: Thu, 16 Oct 2008 17:29:38 +0200
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: geus
Date: Thu Oct 16 17:29:37 2008
New Revision: 278

Log:
Updated IdokSearchTwikiMashup GWT module to use the IdokSearchTwikiUtil class


Modified:

trunk/sites/psi/java/ch/psi/idok/gwt/twiki/client/IdokSearchTwikiMashup.java

Modified:
trunk/sites/psi/java/ch/psi/idok/gwt/twiki/client/IdokSearchTwikiMashup.java
==============================================================================
---
trunk/sites/psi/java/ch/psi/idok/gwt/twiki/client/IdokSearchTwikiMashup.java
(original)
+++
trunk/sites/psi/java/ch/psi/idok/gwt/twiki/client/IdokSearchTwikiMashup.java
Thu Oct 16 17:29:37 2008
@@ -12,18 +12,13 @@

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
-import com.google.gwt.http.client.URL;
import com.google.gwt.i18n.client.DateTimeFormat;
-import com.google.gwt.i18n.client.NumberFormat;
-import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

@@ -34,43 +29,15 @@
public class IdokSearchTwikiMashup implements EntryPoint {

/**
- * Base URL of iDok search ReST interface
- */
- static final String REST_BASE_URL =
"https://dms02.psi.ch/api/v1/search/";;
-
- /**
- * Render diagnostic output if set to true
- */
- static final boolean debug = false;
-
- /**
* Number of requested search hits
*/
static final int MAX_HITS = 100;

/**
- * iDok repository to search in, formatted as $PROJECT/$REPOSITORY
- */
- String repository = null;
-
- /**
- * Date format for parsing from iDok meta data
- */
- final private DateTimeFormat dataFormatIn;
-
- /**
* Date format for rendering search results
*/
- final private DateTimeFormat dataFormatOut;
-
- /**
- * Constructor
- */
- public IdokSearchTwikiMashup() {
- dataFormatIn = DateTimeFormat
- .getFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
- dataFormatOut = DateTimeFormat.getFormat("dd.MM.yyy - HH:mm");
- }
+ static final private DateTimeFormat dataFormatOut = DateTimeFormat
+ .getFormat("dd.MM.yyy - HH:mm");

/**
* Called after the HTML document has finished loading.
@@ -95,6 +62,7 @@
RootPanel idokEnabledPanel = RootPanel.get("idokEnabled");
if (idokEnabledPanel != null)
idokEnabled = idokEnabledPanel.getElement().getInnerText();
+ String repository = null;
if ("on".equalsIgnoreCase(idokEnabled)
|| "yes".equalsIgnoreCase(idokEnabled)
|| "true".equalsIgnoreCase(idokEnabled)) {
@@ -109,42 +77,21 @@
}

// Call iDok search ReST interface
- if (queryParam != null && repository != null)
- doRestCall(repository,
TwikiToLuceneConverter.convert(queryParam));
- }
+ if (queryParam != null && repository != null) {
+ final String repositorY = repository;
+ IdokSearchUtil.doRestCall(repository, TwikiToLuceneConverter
+ .convert(queryParam), MAX_HITS, new
RestCallbackHandler() {

- /**
- * Call the iDok search ReST interface and obtain the result using the
JSONP
- * method
- *
- * @param repository
- * the iDok repository in $PRJ/$REPO format, example:
ait/intern
- * @param query
- * the iDok query string
- */
- protected void doRestCall(String repository, String query) {
- String url = REST_BASE_URL + repository + "?q=" + query
- + "&outputfields=env,meta&num=" + MAX_HITS;
- GWT.log("Requesting " + url + " using JSONP", null);
-
- JSONRequest.get(URL.encode(url) + "&callback=",
- new JSONRequestHandler() {
- public void onRequestComplete(JavaScriptObject jso) {
- GWT.log("entering callback", null);
- if (jso != null) {
- if (debug) {
- final Label lb = new Label();
- lb.setText("result: " + jso.toString());
- RootPanel.get("slot2").add(lb);
- }
- JSONObject json = new JSONObject(jso);
- processQueryResult(json.get("xml").isString()
- .stringValue());
- } else
- Window.alert("ReST request timed out");
+ public void onFailure() {
+ Window.alert("ReST call to iDok search service failed");
+ }
+
+ public void onSuccess(String xmlString) {
+ processQueryResult(repositorY, xmlString);
+ }
+ });
+ }

- }
- });
}

/**
@@ -155,8 +102,9 @@
*
* @param xmlString
* the XML data obtained from ReST service
+ * @param repository
*/
- protected void processQueryResult(String xmlString) {
+ protected void processQueryResult(String repository, String xmlString) {
try {
final String idokImgHtml = "<img border=\"0\" height=\"16\"
width=\"16\" align=\"top\" src=\"/twiki/pub/TWiki/TWikiDocGraphics/dms.gif\"
alt=\"dms\"/>";

@@ -212,35 +160,25 @@
buf.append("</div>");

// Format right column: author
- if (hit.getMeta() != null
- &&
hit.getMeta().containsKey("svn:entry:last-author")) {
+ String author = hit.getAuthor();
+ if (author != null) {
buf.append("<div class=\"twikiRight twikiSRAuthor\">");
- buf.append(hit.getMeta().get("svn:entry:last-author"));
- buf.append("</div>");
+ buf.append(hit.getAuthor());
+ buf.append("</div>");
}

// Format middle column: file size and date
buf.append("<div class=\"twikiRight twikiSRRev\">");
- String fileSizeString = hit.getMeta().get("auto:filesize");
- if (hit.getMeta() != null && fileSizeString != null) {
- try {
- long fileSize = Long.parseLong(fileSizeString);
- buf.append(IdokSearchUtil.formatByteSize(fileSize));
- } catch (NumberFormatException e) {
- buf.append("unknown size");
- }
- } else
+ long size = hit.getSize();
+ if (size != -1)
+ buf.append(IdokSearchUtil.formatByteSize(size));
+ else
buf.append("unknown size");
- if (hit.getMeta() != null
- && hit.getMeta()
- .containsKey("svn:entry:committed-date")) {
- try {
- Date date = dataFormatIn.parse(hit.getMeta().get(
- "svn:entry:committed-date"));
- String dateString = dataFormatOut.format(date);
- buf.append(" - <i>" + dateString + "</i>");
- } catch (IllegalArgumentException e) {
- }
+
+ Date date = hit.getDate();
+ if (date != null) {
+ String dateString = dataFormatOut.format(date);
+ buf.append(" - <i>" + dateString + "</i>");
}
buf.append("</div>");
buf



  • [idok-commit] idok commit r278 - trunk/sites/psi/java/ch/psi/idok/gwt/twiki/client, AFS account Roman Geus, 10/16/2008

Archive powered by MHonArc 2.6.19.

Top of Page