[Yanel-commits] rev 20859 - in
public/yanel/trunk/src/contributions/resources/nutch: conf
src/java/org/wyona/yanel/impl/resources xslt
michi at wyona.com
michi at wyona.com
Thu Dec 14 16:51:16 CET 2006
Author: michi
Date: 2006-12-14 16:51:15 +0100 (Thu, 14 Dec 2006)
New Revision: 20859
Modified:
public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_de.properties
public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_en.properties
public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java
public/yanel/trunk/src/contributions/resources/nutch/xslt/result2xhtml.xsl
Log:
refactored thanks ro David
Modified: public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_de.properties
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_de.properties 2006-12-14 15:50:12 UTC (rev 20858)
+++ public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_de.properties 2006-12-14 15:51:15 UTC (rev 20859)
@@ -1,21 +1,22 @@
title = Abteilungen - Patente - Abteilung
resultsForQuery = Suchergebnisse:
searchFor = Suche nach ...
-results = Ergebnisse
-ofAbout = von
+results = Treffer
+ofAbout = (von insgesamt
+hitsFound = gefundenen Treffern)
for = von
viewResultsAsXml = Ergebnisse als XML sehen
yourSearch = Ihre Suche
didNotMatchAnyDocuments = hat keine Ergebnisse ergeben.
+pages = Seite
+of = von
exception = Fehler:
search = Suche
-hits = Treffer <b>{0}-{1}</b> (von insgesammt {2} gefundenen Seiten):
-pages = <b>{0}</b> von <b>{1}</b> Seiten
cached = Im Cache
-explain = Erklärung
+explain = Erklärung
anchors = Referenzen
next = Weiter
-previous = Zurück
+previous = Zurück
clustering = Clustern
viewAsText = HTML-Version
moreFrom = Mehr von
@@ -23,10 +24,14 @@
branchMark = Sprungmarken
contact = Kontakt
closeWindow = fenster schliessen
-printPage = übersicht drucken
+printPage = Übersicht drucken
fileSystem = Dateisystem
intranet = Intranet
-selectedInternet = Ausgewählte Seiten
+selectedInternet = Ausgewählte Seiten
internet = Internet
hitsPerPage = Treffer pro Seite:
noRefinements = Keine Verfeinerungen
+noSuchCrawlDirectory = Es existiert kein crawl Verzeichnis:
+page = Seite:
+scoreForQuery = Gespeicherte Seiteninformationen:
+scoreExplanation = Seiteninformationen & Rankingberechnungen
Modified: public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_en.properties
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_en.properties 2006-12-14 15:50:12 UTC (rev 20858)
+++ public/yanel/trunk/src/contributions/resources/nutch/conf/nutch_en.properties 2006-12-14 15:51:15 UTC (rev 20859)
@@ -1,16 +1,17 @@
title = Departments - Patents - Department
resultsForQuery = Results for query:
searchFor = Search for ...
-results = Results
-ofAbout = of about
+results = Hits
+ofAbout = (of about
+hitsFound = total hits)
for = for
viewResultsAsXml = View results as XML
yourSearch = Your search
didNotMatchAnyDocuments = did not match any documents.
+pages = page(s)
+of = of
exception = Exception:
search = Search
-hits = hits <b>{0}-{1}</b> (von insgesammt {2} gefundenen Seiten):
-pages = pages
cached = cached
explain = explain
anchors = anchors
@@ -30,3 +31,8 @@
internet = internet
hitsPerPage = Hits Per Page:
noRefinements = no refinements
+noSuchCrawlDirectory = no such crawl directory:
+page = page:
+scoreForQuery = score for query:
+scoreExplanation = score explanation
+
Modified: public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java 2006-12-14 15:50:12 UTC (rev 20858)
+++ public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java 2006-12-14 15:51:15 UTC (rev 20859)
@@ -19,7 +19,9 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.StringBufferInputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
@@ -37,6 +39,10 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.log4j.Category;
+
+import org.apache.nutch.html.Entities;
+import org.apache.nutch.metadata.Metadata;
+
import org.apache.nutch.searcher.Hit;
import org.apache.nutch.searcher.HitDetails;
import org.apache.nutch.searcher.Hits;
@@ -56,6 +62,8 @@
import org.wyona.yarep.core.Repository;
import org.wyona.yarep.core.RepositoryFactory;
import org.wyona.yarep.util.RepoPath;
+
+import javax.servlet.ServletContext;
/**
*
*/
@@ -75,15 +83,21 @@
private int hitsPerPage = 10;
private int numberOfPagesShown = 20;
private int totalHitCount = 100;
+ private long totalHits = 0;
private String defaultFile = "nutch-default.xml";
private String localFile = "nutch-local.xml";
private Path path = null;
private Repository repository = null;
private String language = "en";
- //messages is the name of the ResourceBundle
- private String messages = "nutch";
+ private String show = "";//default is empty, else show either CACHE, EXPLAIN, ANCHORS
+ private String resourceBundle = "nutch";
private RepoPath rp = null;
-
+ private NutchBean nutchBean = null;
+ private ServletContext servletContext = null;
+ private String cachedMimeType = null;
+ private Transformer transformer = null;
+ private I18nTransformer i18nTransformer = null;
+
/**
*
*/
@@ -101,13 +115,13 @@
*
*/
public View getView(Path path, String viewId) {
- return getView(path, viewId, "NO_SEARCH_TERM", start, hitsPerPage, language);
+ return getView(path, viewId, "NO_SEARCH_TERM", start, hitsPerPage, language, show, 0, 0);
}
/**
*
*/
- public View getView(Path path, String viewId, String searchTerm, int start, int hitsPerPage, String language) {
+ public View getView(Path path, String viewId, String searchTerm, int start, int hitsPerPage, String language, String show, int idx, int id) {
View nutchView = null;
this.path = path;
this.language = language;
@@ -115,13 +129,20 @@
rp = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()),
getRepositoryFactory());
repository = rp.getRepo();
-
+ resourceBundle = getMessageBundle(path);
nutchView = new View();
- nutchView.setInputStream(getInputStream(searchTerm, start, hitsPerPage, viewId, language));
- if (viewId != null && viewId.equals("source")) {
- nutchView.setMimeType(XML_MIME_TYPE);
+ nutchView.setInputStream(getInputStream(searchTerm, start, hitsPerPage, viewId, language, show, idx, id));
+ if("cache".equals(show)) {
+ nutchView.setMimeType(cachedMimeType);
+ } else if("explain".equals(show) || "anchors".equals(show)) {
+ log.error("show is " + show);
+ nutchView.setMimeType("text/html");
} else {
- nutchView.setMimeType(XHTML_MIME_TYPE);
+ if (viewId != null && viewId.equals("source")) {
+ nutchView.setMimeType(XML_MIME_TYPE);
+ } else {
+ nutchView.setMimeType(XHTML_MIME_TYPE);
+ }
}
} catch (Exception e) {
log.error(e, e);
@@ -133,7 +154,7 @@
*
*/
public View getView(HttpServletRequest request, String viewId) {
-
+ servletContext = request.getSession().getServletContext();
int _start = 0;
try {
_start = Integer.parseInt(request.getParameter("start"));
@@ -153,115 +174,280 @@
//use fallback language
_language = language;
}
+ int idx = 0;
+ try {
+ idx = Integer.parseInt(request.getParameter("idx"));
+ } catch(Exception e) {
+ idx = 0;
+ }
+ int id = 0;
+ try {
+ id = Integer.parseInt(request.getParameter("id"));
+ } catch(Exception e) {
+ id = 0;
+ }
if(_language == null || ("").equals(_language)) _language = language;
- return getView(new Path(request.getServletPath()), viewId, request.getParameter("query"), _start, _hitsPerPage, _language);
+ return getView(new Path(request.getServletPath()), viewId, request.getParameter("query"), _start, _hitsPerPage, _language, request.getParameter("show"), idx, id);
}
/**
- * Generate result XML
+ *
+ *
*/
- private InputStream getInputStream(String searchTerm, int start, int hitsPerPage, String viewId, String language) {
+ private void setupConfiguration() {
+ configuration = new Configuration();
+ try {
+ String confDir = "file:" + rtd.getConfigFile().getParentFile().getAbsolutePath()
+ + File.separator + "conf";
+ log.debug("Conf Dir: " + confDir);
+ URL defaultResource = new URL(confDir + File.separator + defaultFile);
+ configuration.addDefaultResource(defaultResource);
+ URL finalResource = new URL(confDir + File.separator + localFile);
+ configuration.addFinalResource(finalResource);
+ } catch (MalformedURLException e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+
+ /**
+ *
+ * @param searchTerm
+ */
+ private void setupDocument(String searchTerm) {
+ setupConfiguration();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
try {
DocumentBuilder parser = dbf.newDocumentBuilder();
-/*
- DOMImplementation impl = parser.getDOMImplementation();
- DocumentType doctype = null;
- document = impl.createDocument(NAME_SPACE, "nutch", doctype);
-*/
document = parser.parse(new java.io.StringBufferInputStream("<nutch:nutch xmlns:nutch=\""+NAME_SPACE+"\" xmlns=\""+NAME_SPACE+"\"/>"));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
- // create root element
Element rootElement = document.getDocumentElement();
rootElement.setAttributeNS(NAME_SPACE, "language", language);
- // Generate results
if (searchTerm != null && searchTerm.length() > 0) {
Element queryElement = (Element) rootElement.appendChild(document.createElementNS(NAME_SPACE, "query"));
queryElement.appendChild(document.createTextNode(searchTerm));
resultsElement = (Element) rootElement.appendChild(document.createElementNS(NAME_SPACE, "results"));
resultsElement.setAttributeNS(NAME_SPACE, "start", "" + start);
- configuration = new Configuration();
-
try {
- String confDir = "file:" + rtd.getConfigFile().getParentFile().getAbsolutePath()
- + File.separator + "conf";
- log.debug("Conf Dir: " + confDir);
- URL defaultResource = new URL(confDir + File.separator + defaultFile);
- configuration.addDefaultResource(defaultResource);
- URL finalResource = new URL(confDir + File.separator + localFile);
- configuration.addFinalResource(finalResource);
- } catch (MalformedURLException e) {
- log.error(e.getMessage(), e);
- }
-
- try {
crawlDir = new File(configuration.get("searcher.dir"));
} catch (Exception e) {
log.error(e);
exceptionElement = (Element) resultsElement.appendChild(document.createElementNS(NAME_SPACE, "exception"));
exceptionElement.appendChild(document.createTextNode(e.getMessage()));
}
-
- if (crawlDir != null)
+ if (crawlDir != null) {
createDocument4SearchResult(searchTerm, start, hitsPerPage);
-
+ }
} else {
rootElement.appendChild(document.createElementNS(NAME_SPACE, "no-query"));
}
+ }
+
+ /**
+ * Generate result XML
+ */
+ private InputStream getInputStream(String searchTerm, int start, int hitsPerPage, String viewId, String language, String show, int idx, int id) {
+ setupDocument(searchTerm);
+ if("cache".equals(show)){
+ return new StringBufferInputStream(createCachedDocument4SearchResult(idx, id));
+ } else if("explain".equals(show)) {
+ return createExplanationDocument4SearchResult(idx, id, searchTerm, language);
+ } else if("anchors".equals(show)) {
+ return createAnchorsDocument4SearchResult(idx, id, searchTerm, language);
+ } else {/*will not do anything special cause our document is already created*/}
+ return transformedInputStream(viewId, searchTerm);
+ }
- // Generate InputStream from DOM document
+ /**
+ *
+ * @param viewId
+ * @param searchTerm
+ * @return
+ */
+ private InputStream transformedInputStream(String viewId, String searchTerm) {
try {
- Transformer transformer = null;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
if (viewId != null && viewId.equals("source")) {
transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new javax.xml.transform.dom.DOMSource(document), new StreamResult(byteArrayOutputStream));
return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-
} else {
- File xsltFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "result2xhtml.xsl");
+ File xsltFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile()
+ .getAbsolutePath(), "xslt" + File.separator + "result2xhtml.xsl");
transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltFile));
transformer.setParameter("yanel.path.name", path.getName());
transformer.setParameter("yanel.path", path.toString());
transformer.setParameter("yanel.back2context", backToRoot(path, ""));
transformer.setParameter("yarep.back2realm", backToRoot(new org.wyona.yanel.core.Path(rp.getPath().toString()), ""));
-
-
transformer.transform(new javax.xml.transform.dom.DOMSource(document), new StreamResult(byteArrayOutputStream));
-
InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
- I18nTransformer i18nTransformer = new I18nTransformer(messages, language);
+ i18nTransformer = new I18nTransformer(resourceBundle, language);
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(inputStream, i18nTransformer);
-
- transformer = TransformerFactory.newInstance().newTransformer(getXSLTStreamSource(path, repository));
+ return applyGlobalXslIfExists(i18nTransformer.getInputStream(), searchTerm);
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param inputStream
+ * @param searchTerm
+ * @return
+ */
+ private InputStream applyGlobalXslIfExists(InputStream inputStream, String searchTerm) {
+ StreamSource streamSource = null;
+ try {
+ streamSource = getXSLTStreamSource(path, repository);
+ log.error("streamSource: " + streamSource);
+ if(streamSource != null) {
+ transformer = TransformerFactory.newInstance().newTransformer(streamSource);
transformer.setParameter("yanel.path.name", path.getName());
transformer.setParameter("yanel.path", path.toString());
transformer.setParameter("yanel.back2context", backToRoot(path, ""));
transformer.setParameter("yarep.back2realm", backToRoot(new org.wyona.yanel.core.Path(rp.getPath().toString()), ""));
- byteArrayOutputStream = new ByteArrayOutputStream();
- transformer.transform(new StreamSource(i18nTransformer.getInputStream()), new StreamResult(byteArrayOutputStream));
-
+ transformer.setParameter("hitsPerPage", "" + hitsPerPage);
+ transformer.setParameter("totalHits", "" + totalHits);
+ transformer.setParameter("query", "" + searchTerm);
+ transformer.setParameter("start", "" + start);
+ transformer.setParameter("yanel.meta.lanugage", language);
+ transformer.setParameter("show", show);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ transformer.transform(new StreamSource(inputStream), new StreamResult(byteArrayOutputStream));
inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
- i18nTransformer = new I18nTransformer("global", language);
- saxParser = SAXParserFactory.newInstance().newSAXParser();
+ i18nTransformer = new I18nTransformer(resourceBundle, language);
+ SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(inputStream, i18nTransformer);
-
- return i18nTransformer.getInputStream();
+ return i18nTransformer.getInputStream();
+ } else {
+ return inputStream;
+ }
+ } catch(Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param idx
+ * @param id
+ * @return
+ */
+ private String createCachedDocument4SearchResult(int idx, int id) {
+ String content = null;
+ try {
+ nutchBean = NutchBean.get(servletContext, configuration);
+ Hit hit = new Hit(idx, id);
+ HitDetails details = nutchBean.getDetails(hit);
+ Metadata metaData = nutchBean.getParseData(details).getContentMeta();
+ content = null;
+ String contentType = (String) metaData.get(Metadata.CONTENT_TYPE);
+ log.debug("contentType: " + contentType);
+ cachedMimeType = contentType;
+ if (contentType.startsWith("text/html")) {
+ String encoding = (String) metaData.get("CharEncodingForConversion");
+ log.debug("encoding: " + encoding);
+ if (encoding != null) {
+ try {
+ content = new String(nutchBean.getContent(details), encoding);
+ } catch (Exception e) {
+ content = new String(nutchBean.getContent(details), "windows-1252");
+ }
+ } else {
+ content = new String(nutchBean.getContent(details));
+ }
}
-
} catch (Exception e) {
log.error(e.getMessage(), e);
}
+ log.debug("content:\n" + content);
+ return content;
+ }
+
+ /**
+ *
+ * @param idx
+ * @param id
+ * @param searchTerm
+ * @param language
+ * @return
+ */
+ private InputStream createExplanationDocument4SearchResult(int idx, int id, String searchTerm, String language) {
+ try {
+ nutchBean = NutchBean.get(servletContext, configuration);
+ Hit hit = new Hit(idx, id);
+ Query query = Query.parse(searchTerm, language, configuration);
+ String content = "<html xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" " +
+ "xmlns=\"http://www.w3.org/1999/xhtml\">" +
+ "<head><title><i18n:message key=\"scoreExplanation\"/>: " + searchTerm + "</title></head>" +
+ "<body><table id=\"results\"><tr><td>" +
+ "<h3><i18n:message key=\"page\"/></h3>" +
+ replaceAmpersand(nutchBean.getDetails(hit).toHtml()) +
+ "<h3><i18n:message key=\"scoreForQuery\"/>" + query + "</h3>" +
+ nutchBean.getExplanation(query, hit) +
+ "</td></tr></table></body></html>";
+ I18nTransformer i18nTransformer = new I18nTransformer(resourceBundle, language);
+ SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
+ saxParser.parse(new StringBufferInputStream(content), i18nTransformer);
+ return applyGlobalXslIfExists(i18nTransformer.getInputStream(), searchTerm);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
return null;
}
-
+
/**
- *
+ *
+ * @param idx
+ * @param id
+ * @param searchTerm
+ * @param language
+ * @return
*/
+ private InputStream createAnchorsDocument4SearchResult(int idx, int id, String searchTerm, String language) {
+ try {
+ nutchBean = NutchBean.get(servletContext, configuration);
+ Hit hit = new Hit(idx, id);
+ HitDetails details = nutchBean.getDetails(hit);
+ String listItems = "";
+ String[] anchors = nutchBean.getAnchors(details);
+ if(anchors != null) {
+ for(int i=0; i<anchors.length; i++) {
+ listItems += "<li>" + Entities.encode(anchors[i]) + "</li>";
+ }
+ }
+ String content = "<html xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" " +
+ "xmlns=\"http://www.w3.org/1999/xhtml\">" +
+ "<head><title><i18n:message key=\"anchors\"/>: " + searchTerm + "</title></head>" +
+ "<body><table id=\"results\"><tr><td><h3><i18n:message key=\"anchors\"/></h3>" +
+ replaceAmpersand(details.getValue("url")) +
+ "<ul>" +
+ listItems +
+ "</ul>" +
+ "</td></tr></table></body></html>";
+ log.error("content:\n" + content);
+ I18nTransformer i18nTransformer = new I18nTransformer(resourceBundle, language);
+ SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
+ saxParser.parse(new StringBufferInputStream(content), i18nTransformer);
+ return applyGlobalXslIfExists(i18nTransformer.getInputStream(), searchTerm);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param path
+ * @param backToRoot
+ * @return
+ */
private String backToRoot(Path path, String backToRoot) {
org.wyona.commons.io.Path parent = path.getParent();
if (parent != null && !isRoot(parent)) {
@@ -271,7 +457,9 @@
}
/**
- *
+ *
+ * @param path
+ * @return
*/
private boolean isRoot(org.wyona.commons.io.Path path) {
if (path.toString().equals(File.separator)) return true;
@@ -288,25 +476,22 @@
try {
if (!crawlDir.isDirectory()) {
exceptionElement = (Element) resultsElement.appendChild(document.createElementNS(NAME_SPACE, "exception"));
-
exceptionMessage = "noSuchCrawlDirectory#" + crawlDir;
exceptionElement.appendChild(document.createTextNode(exceptionMessage));
-
log.warn(exceptionMessage);
return;
} else {
- NutchBean nutchBean = new NutchBean(configuration);
+ nutchBean = new NutchBean(configuration);
Query query = Query.parse(searchTerm, configuration);
Hits hits = nutchBean.search(query, totalHitCount);
-
+ totalHits = hits.getTotal();
int range = (int) Math.min(hits.getTotal() - start, hitsPerPage);
resultsElement.setAttributeNS(NAME_SPACE, "hitsPerPage", "" + hitsPerPage);
- resultsElement.setAttributeNS(NAME_SPACE, "totalHits", "" + hits.getTotal());
+ resultsElement.setAttributeNS(NAME_SPACE, "totalHits", "" + totalHits);
resultsElement.setAttributeNS(NAME_SPACE, "currentPageNo", "" + ((start / hitsPerPage) + 1));
resultsElement.setAttributeNS(NAME_SPACE, "numberOfPagesShown", "" + numberOfPagesShown);
Hit[] show = hits.getHits(start, range);
HitDetails[] details = nutchBean.getDetails(show);
-
Summary[] summaries = nutchBean.getSummary(details, query);
Element fetchedDateElement = null;
Element segmentElement = null;
@@ -351,11 +536,9 @@
fragmentElement.setAttributeNS(NAME_SPACE, "highlight", "" + fragments[j].isHighlight());
fragmentElement.setAttributeNS(NAME_SPACE, "ellipsis", "" + fragments[j].isEllipsis());
// Also see org.apache.nutch.searcher.Summary.toHtml()
-
String fragmentValue = replaceAmpersand(fragments[j].toString());
fragmentValue = fragmentValue.replaceAll("<", "<");
fragmentValue = fragmentValue.replaceAll(">", ">");
-
fragmentElement.appendChild(document.createCDATASection(fragmentValue));
// TODO: Why does this not work for all cases? ...
//fragmentElement.appendChild(document.createCDATASection(replaceAmpersand(fragments[j].getText())));
@@ -369,22 +552,24 @@
/**
*
+ * @param path
+ * @param repo
+ * @return
+ * @throws RepositoryException
*/
private StreamSource getXSLTStreamSource(Path path, Repository repo) throws RepositoryException {
Path xsltPath = getXSLTPath(path);
if (xsltPath != null) {
return new StreamSource(repo.getInputStream(new org.wyona.yarep.core.Path(getXSLTPath(path).toString())));
} else {
- File xsltFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile()
- .getParentFile()
- .getAbsolutePath(), "xslt" + File.separator + "result2xhtml.xsl");
- log.debug("XSLT file: " + xsltFile);
- return new StreamSource(xsltFile);
+ return null;
}
}
/**
*
+ * @param path
+ * @return
*/
private Path getXSLTPath(Path path) {
String xsltPath = null;
@@ -396,11 +581,10 @@
java.io.BufferedReader br = new java.io.BufferedReader(rpRTI.getRepo()
.getReader(new org.wyona.yarep.core.Path(new Path(rpRTI.getPath().toString()).getRTIPath()
.toString())));
-
while ((xsltPath = br.readLine()) != null) {
if (xsltPath.indexOf("xslt:") == 0) {
xsltPath = xsltPath.substring(6);
- log.debug("XSLT Path: " + xsltPath);
+ log.error("XSLT Path: " + xsltPath);
return new Path(xsltPath);
}
}
@@ -408,13 +592,43 @@
} catch (Exception e) {
log.warn(e);
}
-
return null;
}
/**
*
+ * @param path
+ * @return
*/
+ private String getMessageBundle(Path path) {
+ String xsltPath = null;
+ try {
+ // TODO: Get yanel RTI yarep properties file name from framework resp. use MapFactory
+ // ...!
+ RepoPath rpRTI = new org.wyona.yarep.util.YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()),
+ yanel.getRepositoryFactory("RTIRepositoryFactory"));
+ java.io.BufferedReader br = new java.io.BufferedReader(rpRTI.getRepo()
+ .getReader(new org.wyona.yarep.core.Path(new Path(rpRTI.getPath().toString()).getRTIPath()
+ .toString())));
+ while ((xsltPath = br.readLine()) != null) {
+ if (xsltPath.indexOf("messageBundle:") == 0) {
+ xsltPath = xsltPath.substring(15);
+ log.error("messageBundle: " + xsltPath);
+ return xsltPath;
+ }
+ }
+ log.error("messageBundle within rti: " + rpRTI.getPath());
+ } catch (Exception e) {
+ log.warn(e);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param path
+ * @return
+ */
private String getMimeType(Path path) {
String mimeType = null;
try {
@@ -425,7 +639,6 @@
java.io.BufferedReader br = new java.io.BufferedReader(rpRTI.getRepo()
.getReader(new org.wyona.yarep.core.Path(new Path(rpRTI.getPath().toString()).getRTIPath()
.toString())));
-
while ((mimeType = br.readLine()) != null) {
if (mimeType.indexOf("mime-type:") == 0) {
mimeType = mimeType.substring(11);
@@ -437,7 +650,6 @@
} catch (Exception e) {
log.warn(e);
}
-
// NOTE: Assuming fallback re dir2xhtml.xsl ...
return "application/xhtml+xml";
}
@@ -462,9 +674,29 @@
return replacedAmpersand;
}
+ /**
+ *
+ * @return
+ */
protected RepositoryFactory getRepositoryFactory() {
return yanel.getRepositoryFactory("DefaultRepositoryFactory");
}
-
+ /**
+ * this method will display the input stream for debugging purposes
+ * @param inputStream
+ */
+ private void debugInputStream(InputStream inputStream) {
+ java.io.InputStreamReader inR = new java.io.InputStreamReader(inputStream) ;
+ java.io.BufferedReader buf = new java.io.BufferedReader (inR) ;
+ String line;
+ try {
+ while((line = buf.readLine()) != null) {
+ log.error("::::" + line) ;
+ }
+ inputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
Modified: public/yanel/trunk/src/contributions/resources/nutch/xslt/result2xhtml.xsl
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/xslt/result2xhtml.xsl 2006-12-14 15:50:12 UTC (rev 20858)
+++ public/yanel/trunk/src/contributions/resources/nutch/xslt/result2xhtml.xsl 2006-12-14 15:51:15 UTC (rev 20859)
@@ -14,11 +14,11 @@
<xsl:output method="html"/>
-->
- <xsl:param name="language" select="/yanel:nutch/@yanel:language"/>
+ <xsl:param name="yanel.meta.language" select="/yanel:nutch/@yanel:language"/>
- <xsl:variable name="query"><xsl:value-of select="/yanel:nutch/yanel:query"/></xsl:variable>
- <xsl:variable name="totalHits" select="/yanel:nutch/yanel:results/@yanel:totalHits" />
- <xsl:variable name="hitsPerPage" select="/yanel:nutch/yanel:results/@yanel:hitsPerPage" />
+ <xsl:param name="query" select="/yanel:nutch/yanel:query"/>
+ <xsl:param name="totalHits" select="/yanel:nutch/yanel:results/@yanel:totalHits" />
+ <xsl:param name="hitsPerPage" select="/yanel:nutch/yanel:results/@yanel:hitsPerPage" />
<xsl:variable name="currentPageNo" select="/yanel:nutch/yanel:results/@yanel:currentPageNo" />
<xsl:variable name="numberOfPagesShown" select="/yanel:nutch/yanel:results/@yanel:numberOfPagesShown" />
<xsl:variable name="range" select="number($numberOfPagesShown div 2)" />
@@ -33,13 +33,13 @@
</head>
<body>
-
- <form>
+ <span id="pageInfo" itemsPerPage="{$hitsPerPage}"/>
+ <form name="search">
<p>
<input type="text" name="query" value="{$query}"/>
- <input type="hidden" name="hitsPerPage" value="{$hitsPerPage}"/>
- <input type="hidden" name="language" value="{$language}"/>
- <input type="submit" value="i18n:attr key=search"/>
+ <input type="hidden" name="yanel.meta.language" value="{$yanel.meta.language}"/>
+ <input type="hidden" name="totalHits" value="{$totalHits}"/>
+ <input type="submit" name="submit" value="i18n:attr key=search"/>
</p>
</form>
@@ -70,59 +70,52 @@
</xsl:template>
<xsl:template match="yanel:results">
- <xsl:apply-templates select="yanel:exception"/>
- <table border="0">
+ <div id="resultHits" hits="{$totalHits}"/>
+ <table width="100%" id="exception">
+ <tr>
+ <td>
+ <xsl:apply-templates select="yanel:exception"/>
+ </td>
+ </tr>
+ </table>
+
+ <xsl:if test="number(@yanel:totalHits) > 0">
+ <table width="100%" id="tableHeadline">
+ <tr>
+ <td colspan="2"><hr/></td>
+ </tr>
+ <tr>
+ <td width="50%"></td>
+ <td align="right">
+ <font size="-1">
+ <i18n:message key="results"/> <b><xsl:value-of select="number(@yanel:start + 1)"/></b>-
+
+ <xsl:variable name="maxHit">
+ <xsl:choose>
+ <xsl:when test="number(@yanel:start + $hitsPerPage) > number(@yanel:totalHits)"><xsl:value-of select="number(@yanel:totalHits)" /></xsl:when>
+ <xsl:otherwise><xsl:value-of select="number(@yanel:start + $hitsPerPage)" /></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <b><xsl:value-of select="$maxHit"/></b> <i18n:message key="ofAbout"/> 
+ <b><xsl:value-of select="number(@yanel:totalHits)"/></b> <i18n:message key="for"/> 
+ <b><xsl:value-of select="$query"/></b><br/>
+ <a href="?query={$query}&hitsPerPage={$hitsPerPage}&start={number(@yanel:start)}&yanel.resource.viewid=source"><i18n:message key="viewResultsAsXml"/></a>
+ </font>
+ </td>
+ </tr>
+ </table>
+ </xsl:if>
+
+ <table border="0" id="results">
<xsl:choose>
<xsl:when test="number(@yanel:totalHits) > 0">
<tr>
- <td colspan="2"><hr/></td>
- </tr>
- <tr>
- <td width="50%"></td>
- <td align="right">
- <font size="-1">
- <i18n:message key="results"/> <b><xsl:value-of select="number(@yanel:start + 1)"/></b>-
-
- <xsl:variable name="maxHit">
- <xsl:choose>
- <xsl:when test="number(@yanel:start + @yanel:hitsPerPage) > number(@yanel:totalHits)"><xsl:value-of select="number(@yanel:totalHits)" /></xsl:when>
- <xsl:otherwise><xsl:value-of select="number(@yanel:start + @yanel:hitsPerPage)" /></xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <b><xsl:value-of select="$maxHit"/></b> <i18n:message key="ofAbout"/> 
- <b><xsl:value-of select="number(@yanel:totalHits)"/></b> <i18n:message key="for"/> 
- <b><xsl:value-of select="$query"/></b><br/>
- <a href="?query={$query}&hitsPerPage={$hitsPerPage}&start={number(@yanel:start)}&yanel.resource.viewid=source"><i18n:message key="viewResultsAsXml"/></a>
- </font>
- </td>
- </tr>
-
- <tr>
<td colspan="2">
<xsl:for-each select="yanel:result">
<xsl:apply-templates select="."/>
</xsl:for-each>
</td>
</tr>
-
- <tr>
- <td colspan="2">
- <table width="100%" border="0">
- <tr>
- <td></td>
- <td align="center">
- <font size="-2">
- <xsl:call-template name="makeLinksForPagening">
- <xsl:with-param name="pageNo">1</xsl:with-param>
- </xsl:call-template>
- </font>
- </td>
- <td></td>
- </tr>
- </table>
- </td>
- </tr>
-
</xsl:when>
<xsl:when test="$query = ''"><!-- if no query inserted show empty form --></xsl:when>
<xsl:otherwise>
@@ -134,6 +127,22 @@
</xsl:otherwise>
</xsl:choose>
</table>
+
+ <xsl:if test="number(@yanel:totalHits) > 0">
+ <table width="100%" border="0" id="pagening">
+ <tr>
+ <td></td>
+ <td align="center">
+ <font size="-2">
+ <xsl:call-template name="makeLinksForPagening">
+ <xsl:with-param name="pageNo">1</xsl:with-param>
+ </xsl:call-template>
+ </font>
+ </td>
+ <td></td>
+ </tr>
+ </table>
+ </xsl:if>
</xsl:template>
<xsl:template name="makeLinksForPagening">
@@ -153,7 +162,7 @@
<xsl:otherwise>
<xsl:if test="number($pageNo) > number($minPage)">
<xsl:if test="number($pageNo) < number($maxPage)">
- <a href="?query={$query}&hitsPerPage={$hitsPerPage}&start={number(number($pageNo - 1) * $hitsPerPage)}"><xsl:value-of select="$pageNo" /></a> 
+ <a href="?query={$query}&hitsPerPage={$hitsPerPage}&start={number(number($pageNo - 1) * $hitsPerPage)}&yanel.meta.language={$yanel.meta.language}"><xsl:value-of select="$pageNo" /></a> 
</xsl:if>
</xsl:if>
</xsl:otherwise>
@@ -174,7 +183,7 @@
<xsl:attribute name="href">
<xsl:value-of select="yanel:url"/>
</xsl:attribute>
- <xsl:value-of select="yanel:title"/>
+ <b><xsl:value-of select="yanel:title"/></b>
</a>
</td>
</tr>
@@ -189,27 +198,46 @@
</td>
</tr>
+ <xsl:variable name="idx"><xsl:value-of select="yanel:hitIndexNo"/></xsl:variable>
+ <xsl:variable name="id"><xsl:value-of select="yanel:hitIndexDocNo"/></xsl:variable>
+
<tr>
- <td clospan="2"><font size="-2" color="green"><xsl:value-of select="yanel:url"/></font></td>
+ <td clospan="2">
+ <font size="-2" color="green"><xsl:value-of select="yanel:url"/></font>
+ <font size="-2">
+ <xsl:text> (</xsl:text><a href="?show=cache&idx={$idx}&id={$id}"><i18n:message key="cached"/></a><xsl:text>)</xsl:text>
+ <xsl:text> (</xsl:text><a href="?show=explain&query={$query}&yanel.meta.language={$yanel.meta.language}&idx={$idx}&id={$id}"><i18n:message key="explain"/></a><xsl:text>)</xsl:text>
+ <xsl:text> (</xsl:text><a href="?show=anchors&idx={$idx}&id={$id}"><i18n:message key="anchors"/></a><xsl:text>)</xsl:text>
+ </font>
+ </td>
</tr>
</table>
</xsl:template>
<xsl:template match="yanel:fragment">
- <xsl:choose>
+ <!-- <xsl:choose>
<xsl:when test="@yanel:highlight = 'true'"><b><xsl:value-of select="."/></b></xsl:when>
<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
- </xsl:choose>
+ </xsl:choose> -->
</xsl:template>
<xsl:template match="yanel:exception">
- <p>
+ <tr>
+ <td colspan="2">
+ <div style="color: red; font-size: 24px;"><i18n:message key="exception"/></div>
+ <xsl:variable name="message"><xsl:value-of select="substring-before(string(.), '#')"/></xsl:variable>
+ <xsl:variable name="directory"><xsl:value-of select="substring-after(string(.), '#')"/></xsl:variable>
+ <i18n:message key="{$message}"/><xsl:value-of select="$directory"/>
+ <xsl:value-of select="."/>
+ </td>
+ </tr>
+ <!-- <p>
<div style="color: red; font-size: 24px;"><i18n:message key="exception"/></div>
<xsl:variable name="message"><xsl:value-of select="substring-before(string(.), '#')"/></xsl:variable>
<xsl:variable name="directory"><xsl:value-of select="substring-after(string(.), '#')"/></xsl:variable>
<i18n:message key="{$message}"/><xsl:value-of select="$directory"/>
- </p>
+ </p> -->
</xsl:template>
</xsl:stylesheet>
More information about the Yanel-commits
mailing list