Apache Nutch is an extensible and scalable web crawler
Fix formatting
Sami Siren69410b142b12
diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.javaindex f6b78ce31..52ffba30a 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java@@ -111,7 +111,7 @@ public class BaseSearch {}/**- * Call plugins participating PreSearch activities+ * Call plugins participating PreSearch activities.*/void callPreSearch(ServiceLocator locator) {LOG.info("presearch");@@ -121,7 +121,7 @@ public class BaseSearch {}/**- * Call plugins participating Search activities+ * Call plugins participating Search activities.*/void callSearch() {for (int i = 0; i < search.length; i++) {@@ -130,7 +130,7 @@ public class BaseSearch {}/**- * Call plugins participating postSearch activities+ * Call plugins participating postSearch activities.*/void callPostSearch(ServiceLocator locator) {LOG.info("postsearch");@@ -140,7 +140,7 @@ public class BaseSearch {}/**- * Entry point to execute the search+ * Entry point to execute the search.*/public void doSearch() {// create contextdiff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/NavigationHelper.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/NavigationHelper.javaindex 81209bf0d..d9fde67b2 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/NavigationHelper.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/NavigationHelper.java@@ -17,9 +17,7 @@package org.apache.nutch.webapp.common;/**- * Helper class to aid when forming search result navigation- *- *+ * Helper class to aid when forming search result navigation.*/public class NavigationHelper {@@ -50,8 +48,8 @@ public class NavigationHelper {}/**- * Is there a previous page available- *+ * Is there a previous page available.+ ** @return*/protected boolean hasPrev() {@@ -66,16 +64,16 @@ public class NavigationHelper {return end < totalHits && (!getShowAllHits());}- /**- * Proceed to next page+ /**+ * Proceed to next page.*/protected void nextPage() {start += hitsPerPage;}/**- * Returns offset to next page- *+ * Returns offset to next page.+ ** @return*/public long getNextPageStart() {@@ -83,14 +81,14 @@ public class NavigationHelper {}/**- * Proceed to previous page+ * Proceed to previous page.*/public void prev() {start -= hitsPerPage;}/**- * Get a page number+ * Get a page number.* @return*/public int getPageNumber() {@@ -98,7 +96,6 @@ public class NavigationHelper {}/**- ** @return*/protected boolean getShowAllHits() {@@ -106,7 +103,7 @@ public class NavigationHelper {}/**- * Returns the numer of last hit on page+ * Returns the number of last hit on page.* @return*/public long getEnd() {diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/PluginResourceLoader.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/PluginResourceLoader.javaindex dec9608ce..5ee8febff 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/PluginResourceLoader.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/PluginResourceLoader.java@@ -141,8 +141,9 @@ public class PluginResourceLoader extends ClassLoader {ArrayList paths = new ArrayList();- if(LOG.isDebugEnabled()){- LOG.debug("PluginResourceLoader : dynamically setting jars based on plugins implementing UIExtensionPoint.");+ if (LOG.isDebugEnabled()) {+ LOG.debug("PluginResourceLoader : dynamically setting jars based "+ + "on plugins implementing UIExtensionPoint.");}ExtensionPoint point = locator.getPluginRepository().getExtensionPoint(@@ -164,15 +165,13 @@ public class PluginResourceLoader extends ClassLoader {// classloaders.add(loader);- URL urls[] = loader.getURLs();+ URL[] urls = loader.getURLs();for (int k = 0; k < urls.length; k++) {URL url = urls[k];if (!seen.contains(url)) {paths.add(url);- if(LOG.isDebugEnabled()){- LOG.debug("Adding to classpath:" + url);- }+ LOG.debug("Adding to classpath:" + url);}seen.add(url);}@@ -183,11 +182,6 @@ public class PluginResourceLoader extends ClassLoader {}- /*- * s (non-Javadoc)- *- * @see java.lang.ClassLoader#getResource(java.lang.String)- */public URL getResource(String name) {Iterator i = classloaders.iterator();@@ -201,11 +195,6 @@ public class PluginResourceLoader extends ClassLoader {return null;}- /*- * (non-Javadoc)- *- * @see java.lang.ClassLoader#getResourceAsStream(java.lang.String)- */public InputStream getResourceAsStream(String name) {Iterator i = classloaders.iterator();@@ -219,11 +208,6 @@ public class PluginResourceLoader extends ClassLoader {return null;}- /*- * (non-Javadoc)- *- * @see java.lang.ClassLoader#getResources(java.lang.String)- */public Enumeration getResources(String name) throws IOException {Iterator i = classloaders.iterator();@@ -237,11 +221,6 @@ public class PluginResourceLoader extends ClassLoader {return null;}- /*- * (non-Javadoc)- *- * @see java.lang.ClassLoader#loadClass(java.lang.String)- */public Class loadClass(String name) throws ClassNotFoundException {try {diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.javaindex 118edee04..daee65365 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.java@@ -28,9 +28,9 @@ import javax.servlet.http.HttpServletResponse;/*** Preferences represents (extendable) configuration object that is persistable- * into user browser (as cookie)- *- * cookie is in format key-1<KEYVALSEPARATOR>value-1<VALVALSEPARATOR>key-2<KEYVALSEPARATOR>value-2<VALVALSEPARATOR>key-n<KEYVALSEPARATOR>value-n+ * into user browser (as cookie).+ *+ * Cookie is in format key-1<KEYVALSEPARATOR>value-1<VALVALSEPARATOR>key-2<KEYVALSEPARATOR>value-2<VALVALSEPARATOR>key-n<KEYVALSEPARATOR>value-n*/public class Preferences extends HashMap {@@ -43,44 +43,49 @@ public class Preferences extends HashMap {public static final String KEY_HITS_PER_DUP = "S";public static final String KEY_DUP_FIELD = "D";-- static final String DEFAULTKEYVALSEPARATOR="_";- static final String DEFAULTVALVALSEPARATOR="-";- // Name of web ui cookie that stores users cutomized user preferences- public static String COOKIE_NAME = "NUTCH";+ static final String DEFAULTKEYVALSEPARATOR = "_";++ static final String DEFAULTVALVALSEPARATOR = "-";- // default preferences, used for all who have not customized- static Preferences defaults = new Preferences();+ /**+ * Name of web ui cookie that stores users cutomized user preferences.+ */+ public static final String COOKIE_NAME = "NUTCH";++ /**+ * Default preferences, used for all who have not customized.+ */+ static final Preferences DEFAULTS = new Preferences();static {// results per page- defaults.put(KEY_RESULTS_PER_PAGE, "10");+ DEFAULTS.put(KEY_RESULTS_PER_PAGE, "10");// dup field- defaults.put(KEY_DUP_FIELD, "site");+ DEFAULTS.put(KEY_DUP_FIELD, "site");}/**- ** @return locale of user (from preferences if set, or from request)*/public Locale getLocale(HttpServletRequest request) {- if (containsKey(KEY_LOCALE))+ if (containsKey(KEY_LOCALE)) {return new Locale((String) get(KEY_LOCALE));- else+ } else {return request.getLocale();+ }}/*** Persist Preferences as cookie.- * @param request+ * @param request* @param response* @param prefs preferences object to persist- */+ */public static void setPreferencesCookie(HttpServletRequest request,HttpServletResponse response, Preferences prefs) {- if (defaults.equals(prefs)) {+ if (DEFAULTS.equals(prefs)) {removeCookie(response);} else {setPreferencesCookie(response, prefs);@@ -96,7 +101,7 @@ public class Preferences extends HashMap {/*** Remove cookie from browser- *+ ** @param response*/public static void removeCookie(HttpServletResponse response) {@@ -106,13 +111,13 @@ public class Preferences extends HashMap {}/**- * Parse Preferences from cookie- *+ * Parse Preferences from cookie.+ ** @param request*/public static Preferences parseCookie(HttpServletRequest request) {// find right cookie- Cookie c[] = request.getCookies();+ Cookie[] c = request.getCookies();if (c != null) {for (int i = 0; i < c.length; i++) {@@ -121,7 +126,7 @@ public class Preferences extends HashMap {}}}- return defaults;+ return DEFAULTS;}/**@@ -138,17 +143,17 @@ public class Preferences extends HashMap {* @param data String to parse* @param valueValueSeparator delimiter between keyValue pairs* @param keyValueSeparator delimiter between key & value- * @return parsed Preferences+ * @return parsed Preferences*/public static Preferences parse(String data, String valueValueSeparator, String keyValueSeparator) {Preferences p = new Preferences();- p.putAll(defaults);+ p.putAll(DEFAULTS);String[] dataitems = data.split(valueValueSeparator);for (int i = 0; i < dataitems.length; i++) {String keyvalue[] = dataitems[i].split(keyValueSeparator);if (keyvalue.length == 2) {try {- p.put(keyvalue[0], URLDecoder.decode((String)keyvalue[1],"UTF-8"));+ p.put(keyvalue[0], URLDecoder.decode((String) keyvalue[1], "UTF-8"));} catch (UnsupportedEncodingException e) {e.printStackTrace();}@@ -156,9 +161,9 @@ public class Preferences extends HashMap {}return p;}-+/**- * Return int value or default if non existing+ * Return int value or default if non existing.* @param name* @param defaultVal* @return@@ -173,7 +178,7 @@ public class Preferences extends HashMap {}/**- * Return String value or default if non existing+ * Return String value or default if non existing.* @param name* @param defaultVal* @return@@ -188,12 +193,14 @@ public class Preferences extends HashMap {for (int i = 0; i < keys.length; i++) {try {- txt.append(keys[i].toString()).append(DEFAULTKEYVALSEPARATOR).append(URLEncoder.encode((String)get(keys[i]),"UTF-8"));+ txt.append(keys[i].toString()).append(DEFAULTKEYVALSEPARATOR).append(+ URLEncoder.encode((String) get(keys[i]), "UTF-8"));} catch (UnsupportedEncodingException e) {e.printStackTrace();}- if (i < keys.length - 1)+ if (i < keys.length - 1) {txt.append(DEFAULTVALVALSEPARATOR);+ }}return txt.toString();@@ -201,12 +208,12 @@ public class Preferences extends HashMap {/*** Get (cached) Preferences instance from request (first from request- * attribute then from cookie)- *+ * attribute then from cookie).+ ** @param request- * @return Preferences object from request or null if not+ * @return Preferences object from request or null if not available*/- public static Preferences getPreferences(HttpServletRequest request) {+ public static Preferences getPreferences(final HttpServletRequest request) {Preferences prefs = (Preferences) request.getAttribute(Preferences.class.getName());// processing localediff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.javaindex 93d368743..aba4f28b5 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java@@ -34,15 +34,15 @@ import org.apache.nutch.searcher.Summary;/*** Search is a bean that represents an ongoing search.- *+ ** After search searchBean that represents the search user doing (also the* results) might be a good candidate for caching ?- *+ **/public class Search implements Writable {private static final long serialVersionUID = 1L;-+public static final String REQ_ATTR_SEARCH="nutchSearch";public static final Log LOG = LogFactory.getLog(Search.class);@@ -58,11 +58,11 @@ public class Search implements Writable {// Number of results per pageint hitsPerPage;-+// Number of hits required, for example clustering plugin might require more// than hitsPerPage hitsint hitsRequired=0;-+String sortColumn;boolean sortDesc;@@ -87,13 +87,13 @@ public class Search implements Writable {/*** Perform search described by this bean- *+ ** @param bean*/public void performSearch() {LOG.info("performing search, requiring:" + getHitsRequired());-+try {LOG.info("query:" + getQuery());LOG.info("endOffset:" + getStartOffset() + getHitsRequired());@@ -101,9 +101,10 @@ public class Search implements Writable {LOG.info("dupField:" + getDupField());LOG.info("sortField:" + getSortColumn());LOG.info("descending:" + isSortDesc());-- hits = locator.getNutchBean().search(getQuery(), getStartOffset() + getHitsRequired(),- getHitsPerDup(), getDupField(), getSortColumn(), isSortDesc());++ hits = locator.getNutchBean().search(getQuery(),+ getStartOffset() + getHitsRequired(), getHitsPerDup(), getDupField(),+ getSortColumn(), isSortDesc());} catch (IOException e) {hits = new Hits(0, new Hit[0]);}@@ -125,7 +126,7 @@ public class Search implements Writable {public void init(){int endOffset=hits.getLength();-+navigationHelper = new NavigationHelper(startOffset, endOffset, hitsPerPage, hits.getTotal(), hits.totalIsExact());@@ -135,17 +136,16 @@ public class Search implements Writable {.getNextPageStart()));}}--+/**- * gets the results of search to display- *+ * Gets the results of search to display.+ ** @return*/public List getResults() {-+int len=Math.min(details.length,getHitsPerPage());-+if (results == null) {results = new ArrayList(len);for (int i = 0; i < len; i++) {@@ -167,9 +167,9 @@ public class Search implements Writable {}return ret;}-+public Search(){-+}public Search(ServiceLocator locator) {@@ -178,14 +178,16 @@ public class Search implements Writable {form = locator.getSearchForm();queryString = form.getValueString(SearchForm.NAME_QUERYSTRING);- if (queryString == null)+ if (queryString == null) {queryString = "";+ }htmlQueryString = Entities.encode(queryString);startOffset = parseInt(form.getValueString(SearchForm.NAME_START), 0);hitsPerPage = parseInt(form.getValueString(SearchForm.NAME_HITSPERPAGE),prefs.getInt(Preferences.KEY_RESULTS_PER_PAGE, 10));- hitsPerDup = parseInt(form.getValueString(SearchForm.NAME_HITSPERDUP), prefs.getInt(+ hitsPerDup = parseInt(form.getValueString(SearchForm.NAME_HITSPERDUP),+ prefs.getInt(Preferences.KEY_HITS_PER_DUP, 2));sortColumn = form.getValueString(SearchForm.NAME_SORTCOLUMN);@@ -194,8 +196,9 @@ public class Search implements Writable {.getValueString(SearchForm.NAME_SORTREVERSE)));dupField = form.getValueString(SearchForm.NAME_DUPCOLUMN);- if (dupField == null)+ if (dupField == null) {dupField = "site";+ }try {query = Query.parse(queryString, locator.getConfiguration());@@ -235,7 +238,7 @@ public class Search implements Writable {protected void setHitsPerSite(int hitsPerSite) {this.hitsPerDup = hitsPerSite;}-+/*** @return Returns the query.*/@@ -267,8 +270,8 @@ public class Search implements Writable {}/**- * Returns true if sort is descending- *+ * Returns true if sort is descending.+ ** @return Returns sort order*/public boolean isSortDesc() {@@ -276,8 +279,8 @@ public class Search implements Writable {}/**- * Set sort order- *+ * Set sort order.+ ** @param sortAsc* The sortAsc to set.*/@@ -392,7 +395,7 @@ public class Search implements Writable {/*** returns start, end, total, used for printing message on search page, this- * is why offset is +1'd+ * is why offset is +1'd.*/public String[] getResultInfo() {return new String[] { Long.toString(startOffset + 1),@@ -423,7 +426,6 @@ public class Search implements Writable {}/**- ** @return*/public List getFormProperties() {@@ -441,8 +443,8 @@ public class Search implements Writable {}/**- * return boolean if there are results- *+ * Return true if there are results.+ ** @return*/public boolean getHasResults() {@@ -454,79 +456,76 @@ public class Search implements Writable {}/**- * Return number of hits required, if not specified defaults to HitsPerPage+ * Return number of hits required, if not specified defaults to HitsPerPage.* @return*/public int getHitsRequired() {- if(hitsRequired!=0) {- return hitsRequired;- }+ if (hitsRequired != 0) {+ return hitsRequired;+ }return getHitsPerPage();}/**- * Set number of hits required+ * Set number of hits required.* @param hitsRequired*/public void setHitsRequired(int hitsRequired) {this.hitsRequired = hitsRequired;}- /**- * Launch search+ /**+ * Launch search.*/public void launchSearch() {- BaseSearch bs=new BaseSearch(locator);+ BaseSearch bs = new BaseSearch(locator);bs.doSearch();}public void write(DataOutput out) throws IOException {LOG.info("writing hits");hits.write(out);--out.writeInt(show.length);- for(int i=0;i<show.length;i++){+ for (int i = 0; i < show.length; i++) {show[i].write(out);}out.writeInt(details.length);- for(int i=0;i<details.length;i++){+ for (int i = 0; i < details.length; i++) {details[i].write(out);}out.writeInt(summaries.length);- for(int i=0;i<summaries.length;i++){+ for (int i = 0; i < summaries.length; i++) {summaries[i].write(out);}}public void readFields(DataInput in) throws IOException {- hits=new Hits();+ hits = new Hits();hits.readFields(in);- int showlength=in.readInt();- show=new Hit[showlength];- for(int i=0;i<showlength;i++){- show[i]=new Hit();+ int showlength = in.readInt();+ show = new Hit[showlength];+ for (int i = 0; i < showlength; i++) {+ show[i] = new Hit();show[i].readFields(in);}- int detailsLength=in.readInt();- details=new HitDetails[detailsLength];- for(int i=0;i<detailsLength;i++){- details[i]=new HitDetails();+ int detailsLength = in.readInt();+ details = new HitDetails[detailsLength];+ for (int i = 0; i < detailsLength; i++) {+ details[i] = new HitDetails();details[i].readFields(in);}- int summariesLength=in.readInt();- summaries=new Summary[summariesLength];- for(int i=0;i<summariesLength;i++){- summaries[i]=new Summary();+ int summariesLength = in.readInt();+ summaries = new Summary[summariesLength];+ for (int i = 0; i < summariesLength; i++) {+ summaries[i] = new Summary();summaries[i].readFields(in);}--}+}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.javaindex 4bc295dde..e9223f9e9 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java@@ -28,17 +28,17 @@ import java.util.Map;* SearchForm is a representation of query parameters submitted as part of* search form. It provides functionality to preserve all required parameters* for example when creating link to "next page"- *+ ** Plugins participating in search- *+ ** @see org.apache.nutch.webapp.extension.PreSearch,* @see org.apache.nutch.webapp.extension.Search,* @see org.apache.nutch.webapp.extension.PostSearch- *+ ** can by reading (existing) or setting values to/from this map make sure that* those parameters are persisted to forms/links requiring them without any* special tricks.- *+ **/public class SearchForm {@@ -46,9 +46,9 @@ public class SearchForm {* General HTTP parameter name wich contains hits per page value*/public static final String NAME_HITSPERPAGE = "hitsPerPage";-- public static final String NAME_HITSPERDUP ="hitsPerDup";-++ public static final String NAME_HITSPERDUP = "hitsPerDup";+public static final String NAME_START = "start";public static final String NAME_QUERYSTRING = "query";@@ -68,8 +68,8 @@ public class SearchForm {ArrayList active;/**- * KeyValue presents a class that holds key value pair- *+ * KeyValue presents a class that holds key value pair.+ **/public static class KeyValue {@@ -140,8 +140,8 @@ public class SearchForm {}/**- * Sets value for provided key- *+ * Sets value for provided key.+ ** @param key* the key to set the value on* @param value@@ -158,8 +158,8 @@ public class SearchForm {}/**- * Gets the real value contained in keyed KeyValue- *+ * Gets the real value contained in keyed KeyValue.+ ** @param key* @return*/@@ -167,13 +167,14 @@ public class SearchForm {if (n_values.containsKey(key) && !active.contains(n_values.get(key))) {active.add(n_values.get(key));return (String) ((KeyValue) n_values.get(key)).getValue();- } else+ } else {return null;+ }}/**- * Gets the String value contained in keyed KeyValue- *+ * Gets the String value contained in keyed KeyValue.+ ** @param key* @return Object.toString()*/@@ -184,8 +185,9 @@ public class SearchForm {// get only the 1st parametern_values.put(key, new KeyValue(key, ((String[]) o_values.get(key))[0]));active.add(n_values.get(key));- } else+ } else {return null;+ }try {return (String) ((KeyValue) n_values.get(key)).getValue();@@ -195,8 +197,8 @@ public class SearchForm {}/**- * Remove named key (and the KeyValue)- *+ * Remove named key (and the KeyValue).+ ** @param key* @return*/@@ -204,12 +206,13 @@ public class SearchForm {if (n_values.containsKey(key)) {active.remove(n_values.get(key));return (KeyValue) n_values.remove(key);- } else+ } else {return null;+ }}/**- * Get named KeyValue object+ * Get named KeyValue object.** @param key* @return named object or null if not existing@@ -222,19 +225,14 @@ public class SearchForm {}/**- * returns list of KeyValue objects that have been read or set- *+ * Returns list of KeyValue objects that have been read or set.+ ** @return List containing KeyValue objects*/public List getActive() {return active;}- /*- * (non-Javadoc)- *- * @see java.lang.Object#toString()- */public String toString() {StringBuffer sb = new StringBuffer();@@ -268,7 +266,7 @@ public class SearchForm {* Returns a string usable in urls that contains all active parameters and* their values, if submitted encoding does not work values are encoded with* utf-8 encoding.- *+ ** @param encoding* @return*/@@ -293,7 +291,7 @@ public class SearchForm {sb.append(URLEncoder.encode(kv.getKey(), encoding)).append("=").append(URLEncoder.encode(kv.getValue(), encoding));} else {- sb.append(URLEncoder.encode(kv.getKey(),"utf-8")).append("=").append(+ sb.append(URLEncoder.encode(kv.getKey(), "utf-8")).append("=").append(URLEncoder.encode(kv.getValue(), "utf-8"));}if (i.hasNext()) {@@ -302,7 +300,7 @@ public class SearchForm {}return sb.toString();}-+public Object clone(){SearchForm newForm=new SearchForm(new HashMap());newForm.active.addAll(active);diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchResultBean.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchResultBean.javaindex 50be35df0..cfd8d86b1 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchResultBean.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchResultBean.java@@ -47,8 +47,8 @@ public class SearchResultBean {}/**- * Url of search result- *+ * Url of search result.+ ** @return*/public String getUrl() {@@ -56,8 +56,8 @@ public class SearchResultBean {}/**- * Title of search result- *+ * Title of search result.+ ** @return*/public String getTitle() {@@ -66,8 +66,8 @@ public class SearchResultBean {}/**- * Id of search result- *+ * Id of search result.+ ** @return*/public String getId() {@@ -75,8 +75,8 @@ public class SearchResultBean {}/**- * Summary of search result- *+ * Summary of search result.+ ** @return*/public String getSummary() {@@ -84,8 +84,8 @@ public class SearchResultBean {}/**- * Url of search result in encoded form- *+ * Url of search result in encoded form.+ ** @return*/public String getEncodedUrl() {@@ -93,8 +93,8 @@ public class SearchResultBean {}/**- * Title of search result in encoded form- *+ * Title of search result in encoded form.+ ** @return*/public String getEncodedTitle() {@@ -102,10 +102,10 @@ public class SearchResultBean {}/**- * "more" url this should be replaced with help of SearchForm- *+ * "more" url this should be replaced with help of SearchForm.+ ** @return- *+ **/public String getMoreUrl() throws UnsupportedEncodingException {String more = "";@@ -119,8 +119,8 @@ public class SearchResultBean {}/**- * Dedup field name- *+ * Dedup field name.+ ** @return*/public String getDedupValue() {@@ -128,14 +128,15 @@ public class SearchResultBean {}/**- * QueryString in encoded form- *+ * QueryString in encoded form.+ ** @return*/public String getUrlEncodedQuery() {try {- if (search.getQueryString() != null)+ if (search.getQueryString() != null) {return URLEncoder.encode(search.getQueryString(), "UTF-8");+ }} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();@@ -144,8 +145,8 @@ public class SearchResultBean {}/**- * HitDetails of search result- *+ * HitDetails of search result.+ ** @return*/public HitDetails getDetails() {@@ -153,8 +154,8 @@ public class SearchResultBean {}/**- * Hit of search result- *+ * Hit of search result.+ ** @return*/public Hit getHit() {@@ -163,10 +164,10 @@ public class SearchResultBean {/*** Boolean indicating that there are other, lower-scoring hits with the same- * dedup value- *+ * dedup value.+ ** @see Hit#moreFromDupExcluded()- *+ ** @return true if more dups available*/public boolean getHasMore() {diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServiceLocator.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServiceLocator.javaindex bbcdcd40f..d27f6473e 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServiceLocator.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServiceLocator.java@@ -30,54 +30,58 @@ import org.apache.nutch.searcher.NutchBean;public interface ServiceLocator {/**- * Return active Configuration instance (application context)- *+ * Return active Configuration instance (application context).+ ** @return*/public Configuration getConfiguration();/**- * Return active PluginRepsository instance (application instance)- *+ * Return active PluginRepsository instance (application instance).+ ** @return*/public PluginRepository getPluginRepository();/**- * Return active SearchForm (request instance)- *+ * Return active SearchForm (request instance).+ ** @return*/public SearchForm getSearchForm();/**- * Return active Preferences (request context)- *+ * Return active Preferences (request context).+ ** @return*/public Preferences getPreferences();/**- * Return active NutchBean (application context)- *+ * Return active NutchBean (application context).+ ** @return*/public NutchBean getNutchBean();/**- * Return active PluginResourceLoader (application context)- *+ * Return active PluginResourceLoader (application context).+ ** @return*/public PluginResourceLoader getPluginResourceLoader(ClassLoader loader);/**- * Return active Search (request context)- *+ * Return active Search (request context).+ ** @return*/public Search getSearch();+ /**+ * Return active locale+ * @return+ */public Locale getLocale();-+}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServletContextServiceLocator.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServletContextServiceLocator.javaindex 1dc1cce9f..c94afff7f 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServletContextServiceLocator.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/ServletContextServiceLocator.java@@ -37,33 +37,34 @@ public abstract class ServletContextServiceLocator implements ServiceLocator {.getName();/**- * Logger+ * Logger.*/- public static final Log LOG = LogFactory.getLog(ServletContextServiceLocator.class);+ public static final Log LOG = LogFactory+ .getLog(ServletContextServiceLocator.class);/**- * ServletContext this ServiceLocator is bound to+ * ServletContext this ServiceLocator is bound to.*/protected ServletContext servletContext;/**- * Active configuration+ * Active configuration.*/protected Configuration config;/**- * Active PluginRepository+ * Active PluginRepository.*/private PluginRepository repository;/**- * Active NutchBean+ * Active NutchBean.*/private NutchBean bean;/**- * Private Constructor used to create new ServiceLocator when needed- *+ * Private Constructor used to create new ServiceLocator when needed.+ ** @param servletContext*/private ServletContextServiceLocator(ServletContext servletContext) {@@ -80,7 +81,7 @@ public abstract class ServletContextServiceLocator implements ServiceLocator {/*** Factory method to get handle to ServiceLocator, or if none exists in* ServletContext then one is created.- *+ ** @param context* @return ServiceLocator instance bound to ServletContext*/@@ -110,37 +111,18 @@ public abstract class ServletContextServiceLocator implements ServiceLocator {return locator;}- /*- * (non-Javadoc)- *- * @see org.apache.nutch.webapp.common.ServiceLocator#getConfiguration()- */public Configuration getConfiguration() {return config;}- /*- * (non-Javadoc)- *- * @see org.apache.nutch.webapp.common.ServiceLocator#getPluginRepository()- */public PluginRepository getPluginRepository() {+ public PluginRepository getPluginRepository() {return repository;}- /*- * (non-Javadoc)- *- * @see org.apache.nutch.webapp.common.ServiceLocator#getNutchBean()- */public NutchBean getNutchBean() {return bean;}- /*- * (non-Javadoc)- *- * @see org.apache.nutch.webapp.common.ServiceLocator#getPluginResourceLoader(java.lang.ClassLoader)- */public PluginResourceLoader getPluginResourceLoader(ClassLoader loader) {return PluginResourceLoader.getInstance(this, loader);}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Startable.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Startable.javaindex 6ddcab3c3..c96b4654d 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Startable.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Startable.java@@ -18,9 +18,15 @@ package org.apache.nutch.webapp.common;import javax.servlet.ServletContext;-/** Controllers wishing to be initialized must extend this interface- *+/**+ * Controllers wishing to be initialized must extend this interface.*/public interface Startable {- public void start(ServletContext servletContext);++ /**+ * This method gets called when plugin initializes.+ *+ * @param servletContext+ */+ void start(ServletContext servletContext);}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.javaindex a3b800c00..8c4989187 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.java@@ -42,7 +42,7 @@ import java.lang.ClassLoader;/*** This class is responsible for parsing web.xml definitions from plugins (put* there by jspc when precompiling jsp files).- *+ ** Extracted information is used at runtime when dispatching requests targetted* to jsp resources to the precompiled servlet classes.*/@@ -120,7 +120,7 @@ public class WebAppModule {public WebAppModule(ClassLoader loader, ServletConfig config) {servletConfig = config;- this.loader=loader;+ this.loader = loader;init(loader.getResourceAsStream("META-INF/jsp-servlet-mappings.xml"));}@@ -175,7 +175,7 @@ public class WebAppModule {*/public void dispatch(String relPath, HttpServletRequest request,HttpServletResponse response) {-+HttpServlet servletObject;if (servletObjects.containsKey(relPath)) {servletObject = (HttpServlet) servletObjects.get(relPath);diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebappInstanceServiceLocator.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebappInstanceServiceLocator.javaindex f0f2b161c..64f8f33e8 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebappInstanceServiceLocator.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebappInstanceServiceLocator.java@@ -72,7 +72,6 @@ public class WebappInstanceServiceLocator implements ServiceLocator {}/**- ** @param request* @return*/@@ -82,7 +81,6 @@ public class WebappInstanceServiceLocator implements ServiceLocator {}/**- ** @param request* @param locator*/@@ -96,42 +94,22 @@ public class WebappInstanceServiceLocator implements ServiceLocator {}}- /*- * (non-Javadoc)- * @see org.apache.nutch.webapp.common.ServiceLocator#getConfiguration()- */public Configuration getConfiguration() {return contextLocator.getConfiguration();}- /*- * (non-Javadoc)- * @see org.apache.nutch.webapp.common.ServiceLocator#getPluginRepository()- */public PluginRepository getPluginRepository() {return contextLocator.getPluginRepository();}- /*- * (non-Javadoc)- * @see org.apache.nutch.webapp.common.ServiceLocator#getNutchBean()- */public NutchBean getNutchBean() {return contextLocator.getNutchBean();}- /*- * (non-Javadoc)- * @see org.apache.nutch.webapp.common.ServiceLocator#getPluginResourceLoader(java.lang.ClassLoader)- */public PluginResourceLoader getPluginResourceLoader(ClassLoader loader) {return contextLocator.getPluginResourceLoader(loader);}- /*- * (non-Javadoc)- * @see org.apache.nutch.webapp.common.ServiceLocator#getLocale()- */public Locale getLocale() {return getPreferences().getLocale(request);}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/CachedController.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/CachedController.javaindex 1e5a21dec..f2190dae0 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/CachedController.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/CachedController.java@@ -36,16 +36,15 @@ public class CachedController extends NutchController {public void nutchPerform(ComponentContext tileContext,HttpServletRequest request, HttpServletResponse response,ServletContext servletContext) throws ServletException, IOException {--+ServiceLocator locator = getServiceLocator(request);NutchBean bean = locator.getNutchBean();LOG.info("Cache request from " + request.getRemoteAddr());-+Hit hit = new Hit(Integer.parseInt(request.getParameter("idx")),Integer.parseInt(request.getParameter("id")));-+HitDetails details = bean.getDetails(hit);String id = "idx=" + hit.getIndexNo() + "&id=" + hit.getIndexDocNo();@@ -54,24 +53,23 @@ public class CachedController extends NutchController {String content = null;String contentType = (String) metaData.get(Metadata.CONTENT_TYPE);-+if (contentType.startsWith("text/html")) {- // FIXME : it's better to emit the original 'byte' sequence+ // FIXME : it's better to emit the original 'byte' sequence// with 'charset' set to the value of 'CharEncoding',// but I don't know how to emit 'byte sequence' in JSP.- // out.getOutputStream().write(bean.getContent(details)) may work,+ // out.getOutputStream().write(bean.getContent(details)) may work,// but I'm not sure.- String encoding = (String) metaData.get("CharEncodingForConversion");+ String encoding = (String) metaData.get("CharEncodingForConversion");if (encoding != null) {try {content = new String(bean.getContent(details), encoding);- }- catch (UnsupportedEncodingException e) {+ } catch (UnsupportedEncodingException e) {//fallback to configured charset- content = new String(bean.getContent(details), locator.getConfiguration().get("parser.character.encoding.default"));+ content = new String(bean.getContent(details), locator+ .getConfiguration().get("parser.character.encoding.default"));}- }- else {+ } else {//construct String with system default encodingcontent = new String(bean.getContent(details));}@@ -86,6 +84,7 @@ public class CachedController extends NutchController {// page idrequest.setAttribute("id", id);// page content if html- request.setAttribute("isHtml", new Boolean(contentType.startsWith("text/html")));+ request.setAttribute("isHtml", new Boolean(contentType+ .startsWith("text/html")));}}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/I18NPageController.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/I18NPageController.javaindex d86361d71..61911cf51 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/I18NPageController.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/I18NPageController.java@@ -56,8 +56,9 @@ public class I18NPageController extends NutchController {String attrName = (String) tileContext.getAttribute("attrName");// if not available use default- if (attrName == null)+ if (attrName == null) {attrName = "content";+ }// get users preferred localeLocale locale = locator.getLocale();@@ -70,13 +71,15 @@ public class I18NPageController extends NutchController {if (content == null) {content = new StringBuffer();List suffixes = calculateSuffixes(locale);-- if(!suffixes.contains(servletContext.getInitParameter("javax.servlet.jsp.jstl.fmt.fallbackLocale"))){- suffixes.add(servletContext.getInitParameter("javax.servlet.jsp.jstl.fmt.fallbackLocale"));++ if (!suffixes.contains(servletContext+ .getInitParameter("javax.servlet.jsp.jstl.fmt.fallbackLocale"))) {+ suffixes.add(servletContext+ .getInitParameter("javax.servlet.jsp.jstl.fmt.fallbackLocale"));}Iterator iterator = suffixes.iterator();-+while (iterator.hasNext()) {String postfix = (String) iterator.next();String name = concatPostfix(baseName, postfix);@@ -145,13 +148,13 @@ public class I18NPageController extends NutchController {* Concat postfix to the name. Take care of existing filename extension.* Transform the given name "name.ext" to have "name" + "postfix" + "ext". If* there is no ext, return "name" + "postfix".- *+ ** @param name* Filename.* @param postfix* Postfix to add.* @return Concatenated filename.- *+ ** This method is borrowed from I18NFactorySet.java wich is part of tiles* (struts)*/@@ -161,5 +164,5 @@ public class I18NPageController extends NutchController {}return "/" + postfix + name;}-+}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/NutchController.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/NutchController.javaindex e3fb6d2a3..26e9624ea 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/NutchController.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/NutchController.java@@ -40,11 +40,11 @@ import org.apache.struts.tiles.Controller;public abstract class NutchController implements Controller {public static final Log LOG = LogFactory.getLog(NutchController.class);-+public final void execute(ComponentContext tileContext,HttpServletRequest request, HttpServletResponse response,ServletContext servletContext) throws ServletException, IOException {-+request.setCharacterEncoding("UTF-8");try {@@ -54,9 +54,9 @@ public abstract class NutchController implements Controller {e.printStackTrace(LogUtil.getInfoStream(LOG));}}-+/**- * Nutch controllers overwrite this method+ * Nutch controllers overwrite this method.** @param tileContext* @param request@@ -70,8 +70,8 @@ public abstract class NutchController implements Controller {ServletContext servletContext) throws ServletException, IOException;/**- * Get Active service locator from request or create on if not exiting- *+ * Get Active service locator from request or create on if none exists.+ ** @param request* @return*/@@ -107,13 +107,6 @@ public abstract class NutchController implements Controller {}}- /*- * (non-Javadoc)- *- * @see org.apache.struts.tiles.Controller#perform(org.apache.struts.tiles.ComponentContext,- * javax.servlet.http.HttpServletRequest,- * javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext)- */public void perform(ComponentContext tileContext, HttpServletRequest request,HttpServletResponse response, ServletContext servletContext)throws ServletException, IOException {@@ -123,7 +116,7 @@ public abstract class NutchController implements Controller {/*** Get servlet context service locator, this one cannot access request* specific information as preferences etc.- *+ ** @param servletContext* @return*/diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/PreferencesController.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/PreferencesController.javaindex 6c6984882..19df88d2d 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/PreferencesController.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/PreferencesController.java@@ -28,7 +28,7 @@ import org.apache.nutch.webapp.common.ServiceLocator;import org.apache.struts.tiles.ComponentContext;/**- * Simple controller for preferences page+ * Simple controller for preferences page.*/public class PreferencesController extends NutchController {@@ -40,9 +40,9 @@ public class PreferencesController extends NutchController {if (tileContext.getAttribute("action").equals("save")) {LOG.info("save");- Preferences p=Preferences.parse(request.getQueryString(),"&", "=");+ Preferences p = Preferences.parse(request.getQueryString(), "&", "=");LOG.info("setting cookie");- Preferences.setPreferencesCookie(request,response,p);+ Preferences.setPreferencesCookie(request, response, p);LOG.info("setting attribute");request.setAttribute("preferences", p);} else {diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.javaindex fda416290..0328b8d8b 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.java@@ -27,17 +27,19 @@ import org.apache.nutch.webapp.common.Search;import org.apache.nutch.webapp.common.ServiceLocator;import org.apache.struts.tiles.ComponentContext;-/* This is the main controller of nutch search application+/**+ * This is the main controller of nutch search application.*/public class SearchController extends NutchController {-- public void nutchPerform(ComponentContext tileContext, HttpServletRequest request,- HttpServletResponse response, ServletContext servletContext)++ public void nutchPerform(ComponentContext tileContext,+ HttpServletRequest request, HttpServletResponse response,+ ServletContext servletContext)throws ServletException, IOException {-- ServiceLocator locator=getServiceLocator(request);-- Search search=locator.getSearch();++ ServiceLocator locator = getServiceLocator(request);++ Search search = locator.getSearch();search.launchSearch();}}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PostSearchExtensionPoint.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PostSearchExtensionPoint.javaindex 1d0415c5d..0db770782 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PostSearchExtensionPoint.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PostSearchExtensionPoint.java@@ -20,12 +20,12 @@ import org.apache.nutch.webapp.common.ServiceLocator;/*** Plugins extending this extension point are run after the actual- * search+ * search.*/public interface PostSearchExtensionPoint {public static final String X_POINT_ID=PostSearchExtensionPoint.class.getName();-+void doPostSearch(ServiceLocator locator);-+}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PreSearchExtensionPoint.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PreSearchExtensionPoint.javaindex 0a4d9aa3b..d02add86f 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PreSearchExtensionPoint.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/PreSearchExtensionPoint.java@@ -20,10 +20,10 @@ import org.apache.nutch.webapp.common.ServiceLocator;/*** Plugins extending this extension point are run before the actual- * search+ * search.*/public interface PreSearchExtensionPoint {-+public static final String X_POINT_ID=PreSearchExtensionPoint.class.getName();void doPreSearch(ServiceLocator locator);diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/SearchExtensionPoint.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/SearchExtensionPoint.javaindex 48df58dfd..3c25605ad 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/SearchExtensionPoint.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/SearchExtensionPoint.java@@ -20,11 +20,10 @@ import org.apache.nutch.webapp.common.ServiceLocator;/*** Plugins extending this interface can provide logic that- * is run in parallel with the nutch search.- *+ * is run in parallel with the nutch search.*/public interface SearchExtensionPoint {-+public static final String X_POINT_ID=SearchExtensionPoint.class.getName();void doSearch(ServiceLocator locator);diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/UIExtensionPoint.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/UIExtensionPoint.javaindex f50a2bf43..ba2f2e690 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/UIExtensionPoint.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/extension/UIExtensionPoint.java@@ -19,7 +19,7 @@ package org.apache.nutch.webapp.extension;/*** Plugins implementing UIExtensionPoint can provide* extensions web ui in form of layout components- * or ui logic+ * or ui logic.*/public interface UIExtensionPoint {diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/CachedServlet.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/CachedServlet.javaindex 0ddab00b9..ff320e8e4 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/CachedServlet.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/CachedServlet.java@@ -33,13 +33,12 @@ import java.io.IOException;/*** A servlet that serves raw Content of any mime type.- *+ ** If it fails with java.lang.OutOfMemoryError, you may have to increase heap* size when starting container, such as -Xms1024M -Xmx1024M- *+ ** @author John Xing*/-public class CachedServlet extends NutchHttpServlet {private static final long serialVersionUID = 1L;@@ -66,7 +65,8 @@ public class CachedServlet extends NutchHttpServlet {byte[] bytes = getServiceLocator().getNutchBean().getContent(details);// pass all original headers? only these for now.- Metadata metadata = getServiceLocator().getNutchBean().getParseData(details).getContentMeta();+ Metadata metadata = getServiceLocator().getNutchBean()+ .getParseData(details).getContentMeta();String contentType = metadata.get(Response.CONTENT_TYPE);// String lastModified = metadata.get(Metadata.LAST_MODIFIED);// String contentLength = metadata.get(Metadata.CONTENT_LENGTH);diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.javaindex dc035164d..6d7f9d410 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.java@@ -74,7 +74,7 @@ public class JspDispatcherServlet extends NutchHttpServlet {*/protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {-+//get jsp include path_info from request objectString relPath=(String)request.getAttribute("javax.servlet.include.path_info");diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.javaindex 149916f2b..0c39c8773 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.java@@ -25,50 +25,54 @@ import org.apache.nutch.webapp.common.ServiceLocator;import org.apache.nutch.webapp.common.ServletContextServiceLocator;/**- * Abstract base Servlet for nutch+ * Abstract base Servlet for nutch.*/-public abstract class NutchHttpServlet extends HttpServlet{+public abstract class NutchHttpServlet extends HttpServlet {private static final long serialVersionUID = 1L;private ServiceLocator locator;-+public void init(final ServletConfig servletConfig) throws ServletException {super.init(servletConfig);- locator = ServletContextServiceLocator.getInstance(getServletContext());+ locator = ServletContextServiceLocator.getInstance(getServletContext());}-+/**- * Return context relative path- *+ * Return context relative path.+ ** @return*/public String getContextRelativePath(final HttpServletRequest request) {return request.getRequestURI().substring(request.getContextPath().length());}-+/**- * Removes the first part of path String and returns new String- * if there is no path available return null- * @param path original path+ * Removes the first part of path String and returns new String if there is no+ * path available return null.+ *+ * @param path+ * original path* @return*/- public String getMappingRelativePath(final String path){-- String relPath=null;-- if(path.indexOf("/",(path.startsWith("/")?1:0))!=-1){- relPath=path.substring(path.indexOf('/',(path.startsWith("/")?1:0)));- }-+ public String getMappingRelativePath(final String path) {++ String relPath = null;++ if (path.indexOf("/", (path.startsWith("/") ? 1 : 0)) != -1) {+ relPath = path.substring(path+ .indexOf('/', (path.startsWith("/") ? 1 : 0)));+ }+return relPath;}/*** Get ServiceLocator instance+ ** @return*/- public ServiceLocator getServiceLocator(){+ public ServiceLocator getServiceLocator() {return locator;}}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/OpenSearchServlet.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/OpenSearchServlet.javaindex 5ec31db18..e23b48dec 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/OpenSearchServlet.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/OpenSearchServlet.java@@ -19,17 +19,20 @@ package org.apache.nutch.webapp.servlet;import java.io.IOException;import java.net.URLEncoder;-import java.util.Map;import java.util.HashMap;-import java.util.Set;import java.util.HashSet;+import java.util.Map;+import java.util.Set;-import javax.servlet.ServletException;import javax.servlet.ServletConfig;+import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;--import javax.xml.parsers.*;+import javax.xml.parsers.DocumentBuilderFactory;+import javax.xml.transform.Transformer;+import javax.xml.transform.TransformerFactory;+import javax.xml.transform.dom.DOMSource;+import javax.xml.transform.stream.StreamResult;import org.apache.nutch.searcher.Hit;import org.apache.nutch.searcher.HitDetails;@@ -37,17 +40,18 @@ import org.apache.nutch.searcher.Hits;import org.apache.nutch.searcher.NutchBean;import org.apache.nutch.searcher.Query;import org.apache.nutch.searcher.Summary;-import org.w3c.dom.*;-import javax.xml.transform.TransformerFactory;-import javax.xml.transform.Transformer;-import javax.xml.transform.dom.DOMSource;-import javax.xml.transform.stream.StreamResult;+import org.w3c.dom.Attr;+import org.w3c.dom.Document;+import org.w3c.dom.Element;+import org.w3c.dom.Node;/*** Present search results using A9's OpenSearch extensions to RSS, plus a few* Nutch-specific extensions.*/public class OpenSearchServlet extends NutchHttpServlet {+ private static final int DEFAULT_NUMBER_OF_HITS = 10;+private static final long serialVersionUID = 1L;private static final Map NS_MAP = new HashMap();@@ -75,19 +79,22 @@ public class OpenSearchServlet extends NutchHttpServlet {// get parameters from requestrequest.setCharacterEncoding("UTF-8");String queryString = request.getParameter("query");- if (queryString == null)+ if (queryString == null) {queryString = "";+ }String urlQuery = URLEncoder.encode(queryString, "UTF-8");int start = 0; // first hit to displayString startString = request.getParameter("start");- if (startString != null)+ if (startString != null) {start = Integer.parseInt(startString);+ }- int hitsPerPage = 10; // number of hits to display+ int hitsPerPage = DEFAULT_NUMBER_OF_HITS; // number of hits to displayString hitsString = request.getParameter("hitsPerPage");- if (hitsString != null)+ if (hitsString != null) {hitsPerPage = Integer.parseInt(hitsString);+ }String sort = request.getParameter("sort");boolean reverse = sort != null@@ -119,14 +126,15 @@ public class OpenSearchServlet extends NutchHttpServlet {+ (reverse ? "&reverse=true" : "")+ (dedupField == null ? "" : "&dedupField=" + dedupField));- Query query = Query.parse(queryString, getServiceLocator().getConfiguration());+ Query query = Query.parse(queryString, getServiceLocator()+ .getConfiguration());NutchBean.LOG.info("query: " + queryString);// execute the queryHits hits;try {- hits = getServiceLocator().getNutchBean().search(query, start + hitsPerPage, hitsPerDup, dedupField,- sort, reverse);+ hits = getServiceLocator().getNutchBean().search(query,+ start + hitsPerPage, hitsPerDup, dedupField, sort, reverse);} catch (IOException e) {NutchBean.LOG.warn("Search Error", e);hits = new Hits(0, new Hit[0]);@@ -140,7 +148,8 @@ public class OpenSearchServlet extends NutchHttpServlet {Hit[] show = hits.getHits(start, end - start);HitDetails[] details = getServiceLocator().getNutchBean().getDetails(show);- Summary[] summaries = getServiceLocator().getNutchBean().getSummary(details, query);+ Summary[] summaries = getServiceLocator().getNutchBean().getSummary(+ details, query);String requestUrl = request.getRequestURL().toString();String base = requestUrl.substring(0, requestUrl.lastIndexOf('/'));@@ -188,8 +197,10 @@ public class OpenSearchServlet extends NutchHttpServlet {String url = detail.getValue("url");String id = "idx=" + hit.getIndexNo() + "&id=" + hit.getIndexDocNo();- if (title == null || title.equals("")) // use url for docs w/o title+ if (title == null || title.equals("")) {+ // use url for docs w/o titletitle = url;+ }Element item = addNode(doc, channel, "item");@@ -212,8 +223,9 @@ public class OpenSearchServlet extends NutchHttpServlet {for (int j = 0; j < detail.getLength(); j++) { // add all from detailString field = detail.getField(j);- if (!SKIP_DETAILS.contains(field))+ if (!SKIP_DETAILS.contains(field)) {addNode(doc, item, "nutch", field, detail.getValue(j));+ }}}diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.javaindex 4342d76f1..6e203e117 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.java@@ -28,11 +28,11 @@ import org.apache.nutch.plugin.PluginDescriptor;/*** Simple Servlet that serves resources from plugins.- *+ ** Plugin must put resources to be exposed into path /resources/ for example* resource /resources/possible/sub/folder/resource.jpg will then be available* in location <contextPath>/resources/<plugin_id>/possible/sub/folder/resource.jpg- *+ **/public class ResourceServlet extends NutchHttpServlet {@@ -41,8 +41,8 @@ public class ResourceServlet extends NutchHttpServlet {private static final long serialVersionUID = 1L;/**- * Extract plugin id from path- *+ * Extract plugin id from path.+ ** @param path* @return*/@@ -59,8 +59,8 @@ public class ResourceServlet extends NutchHttpServlet {}/**- * Extract plugin relative path from path- *+ * Extract plugin relative path from path.+ ** @param path* @return*/@@ -96,7 +96,8 @@ public class ResourceServlet extends NutchHttpServlet {byte[] buffer = new byte[response.getBufferSize()];int len;- String contentType = getServletContext().getMimeType(path).toString();+ String contentType = getServletContext().getMimeType(path)+ .toString();response.setContentType(contentType);while ((len = is.read(buffer)) != -1) {@@ -110,7 +111,7 @@ public class ResourceServlet extends NutchHttpServlet {}}}-+//of no resource was found dispay errorresponse.setContentType("text/plain");PrintWriter pw = response.getWriter();diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.javaindex ca40846b5..113ee5c30 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.java@@ -48,13 +48,14 @@ import org.apache.struts.tiles.xmlDefinition.XmlParser;import org.xml.sax.SAXException;/**- * Tiles DefinitionsFactory that can be extended by activated plugins+ * Tiles DefinitionsFactory that can be extended by activated plugins.*/public class ExtendableDefinitionsFactory implements DefinitionsFactory {private static final long serialVersionUID = 1L;- public static final Log LOG = LogFactory.getLog(ExtendableDefinitionsFactory.class);+ public static final Log LOG = LogFactory+ .getLog(ExtendableDefinitionsFactory.class);DefinitionsFactoryConfig config;@@ -66,23 +67,12 @@ public class ExtendableDefinitionsFactory implements DefinitionsFactory {HashMap locales = new HashMap();- /*- * (non-Javadoc)- *- * @see org.apache.struts.tiles.DefinitionsFactory#getDefinition(java.lang.String,- * javax.servlet.ServletRequest, javax.servlet.ServletContext)- */public ComponentDefinition getDefinition(String name, ServletRequest request,ServletContext servletContext) throws NoSuchDefinitionException,DefinitionsFactoryException {return (ComponentDefinition) definitions.get(name);}- /*- * (non-Javadoc)- *- * @see org.apache.struts.tiles.xmlDefinition.DefinitionsFactory#putDefinition(org.apache.struts.tiles.ComponentDefinition)- */public void putDefinition(ComponentDefinition definition) {LOG.info("putting definition:" + definition.getName());definitions.put(definition.getName(), definition);@@ -96,7 +86,7 @@ public class ExtendableDefinitionsFactory implements DefinitionsFactory {protected XmlDefinitionsSet getDefinitions() {LOG.debug("getDefinitions()");-+XmlDefinitionsSet definitions = new XmlDefinitionsSet();//// core definitions@@ -109,9 +99,9 @@ public class ExtendableDefinitionsFactory implements DefinitionsFactory {InputStream input = servletContext.getResourceAsStream(files[i]);LOG.info("Stream: " + input);-+if (input != null) {- parseXMLDefinitionSet(input, definitions, files[i], "nutch-core");+ parseXMLDefinitionSet(input, definitions, files[i], "nutch-core");} else {LOG.info("Cannot find static " + files[i]);}@@ -138,7 +128,8 @@ public class ExtendableDefinitionsFactory implements DefinitionsFactory {addToSet(definitions, extension);}} else {- LOG.info("Cannot find extension point '" + UIExtensionPoint.X_POINT_ID + "'");+ LOG.info("Cannot find extension point '" + UIExtensionPoint.X_POINT_ID+ + "'");}try {@@ -169,8 +160,8 @@ public class ExtendableDefinitionsFactory implements DefinitionsFactory {protected void parseXMLDefinitionSet(InputStream input,XmlDefinitionsSet definitions, String info, String pluginid) {- XmlDefinitionsSet newSet=new XmlDefinitionsSet();-+ XmlDefinitionsSet newSet = new XmlDefinitionsSet();+try {xmlParser.parse(input, newSet);} catch (IOException e) {@@ -183,31 +174,25 @@ public class ExtendableDefinitionsFactory implements DefinitionsFactory {e.printStackTrace();}-// LOG.info("Definitions:" + definitions.getDefinitions().size() + " : "-// + definitions.toString());-- copySet(definitions,newSet);-+ // LOG.info("Definitions:" + definitions.getDefinitions().size() + " : "+ // + definitions.toString());++ copySet(definitions, newSet);+}private void copySet(XmlDefinitionsSet definitions2, XmlDefinitionsSet newSet) {-- Iterator iterator=newSet.getDefinitions().keySet().iterator();-- while(iterator.hasNext()){- String key=(String)iterator.next();++ Iterator iterator = newSet.getDefinitions().keySet().iterator();++ while (iterator.hasNext()) {+ String key = (String) iterator.next();LOG.info("adding: " + key);- XmlDefinition value=newSet.getDefinition(key);+ XmlDefinition value = newSet.getDefinition(key);definitions2.putDefinition(value);}}- /*- * (non-Javadoc)- *- * @see org.apache.struts.tiles.DefinitionsFactory#init(org.apache.struts.tiles.DefinitionsFactoryConfig,- * javax.servlet.ServletContext)- */public void init(DefinitionsFactoryConfig config,ServletContext servletContext) throws DefinitionsFactoryException {this.config = config;@@ -227,22 +212,23 @@ public class ExtendableDefinitionsFactory implements DefinitionsFactory {this.definitions = definitions.getDefinitions();}-+private void initDefinitions(XmlDefinitionsSet definitions) {Iterator i = definitions.getDefinitions().keySet().iterator();while (i.hasNext()) {String key = (String) i.next();- if(LOG.isDebugEnabled()){+ if (LOG.isDebugEnabled()) {LOG.debug("Initializing controller: " + key);}XmlDefinition d = definitions.getDefinition(key);try {- Controller controller=d.getOrCreateController();- if(controller!=null){- //check if it is implementing Startable, if so execute lifecycle method- if(controller instanceof Startable) {- ((Startable)controller).start(servletContext);+ Controller controller = d.getOrCreateController();+ if (controller != null) {+ // check if it is implementing Startable, if so execute lifecycle+ // method+ if (controller instanceof Startable) {+ ((Startable) controller).start(servletContext);}}} catch (Exception e) {@@ -251,21 +237,10 @@ public class ExtendableDefinitionsFactory implements DefinitionsFactory {}}- /*- * (non-Javadoc)- *- * @see org.apache.struts.tiles.DefinitionsFactory#destroy()- */public void destroy() {LOG.info("destroy()");}- /*- * (non-Javadoc)- *- * @see org.apache.struts.tiles.DefinitionsFactory#setConfig(org.apache.struts.tiles.DefinitionsFactoryConfig,- * javax.servlet.ServletContext)- */public void setConfig(DefinitionsFactoryConfig config,ServletContext servletContext) throws DefinitionsFactoryException {this.config = config;diff --git a/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/NutchRequestProcessor.java b/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/NutchRequestProcessor.javaindex 1f78acbab..986cbee95 100644--- a/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/NutchRequestProcessor.java+++ b/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/NutchRequestProcessor.java@@ -26,7 +26,7 @@ import org.apache.struts.tiles.TilesRequestProcessor;public class NutchRequestProcessor extends TilesRequestProcessor {-+/*** Process locale, override the default functionality and prevent* session from being created.@@ -34,12 +34,13 @@ public class NutchRequestProcessor extends TilesRequestProcessor {protected void processLocale(HttpServletRequest request,HttpServletResponse response) {- ServiceLocator locator=WebappInstanceServiceLocator.getFrom(request);+ ServiceLocator locator = WebappInstanceServiceLocator.getFrom(request);- if(locator==null) {- locator=new WebappInstanceServiceLocator(request, getServletContext());- WebappInstanceServiceLocator.register(request, (WebappInstanceServiceLocator)locator);- }+ if (locator == null) {+ locator = new WebappInstanceServiceLocator(request, getServletContext());+ WebappInstanceServiceLocator.register(request,+ (WebappInstanceServiceLocator) locator);+ }Config.set(request, Config.FMT_LOCALE, locator.getLocale());}diff --git a/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.java b/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.javaindex 830c484a9..06e08b1f2 100644--- a/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.java+++ b/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.java@@ -20,15 +20,15 @@ import junit.framework.TestCase;public class TestNutchHttpServlet extends TestCase {- /*- * Test method for 'org.apache.nutch.webapp.servlet.NutchHttpServlet.getMappingRelativePath(String)'- */public void testGetMappingRelativePath() {-- NutchHttpServlet servlet=new NutchHttpServlet(){};- assertEquals(null,servlet.getMappingRelativePath("test.jsp"));- assertEquals("/kissa.jsp",servlet.getMappingRelativePath("/somepath/kissa.jsp"));- assertEquals("/kissa.jsp",servlet.getMappingRelativePath("somepath/kissa.jsp"));+ NutchHttpServlet servlet = new NutchHttpServlet() {+ };++ assertEquals(null, servlet.getMappingRelativePath("test.jsp"));+ assertEquals("/kissa.jsp", servlet+ .getMappingRelativePath("/somepath/kissa.jsp"));+ assertEquals("/kissa.jsp", servlet+ .getMappingRelativePath("somepath/kissa.jsp"));}}