Author: tmortagne
Date: 2008-01-19 19:05:14 +0100 (Sat, 19 Jan 2008)
New Revision: 6967
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearch.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchException.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchMessageTool.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPlugin.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPluginApi.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchQuery.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchResult.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/resources/globalsearch/
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/resources/globalsearch/ApplicationResources.properties
Modified:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerMessageTool.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPlugin.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPluginApi.java
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/doc/Wiki.java
Log:
XAWM-40: Create a multiwiki version of search, searchDocuments, and
searchDocumentsNames.
HQL query has some limitations :
- Does not support "*" in SELECT.
- All ORDER BY fiels has to be listed in SELECT query part.
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearch.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearch.java
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearch.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -0,0 +1,539 @@
+package com.xpn.xwiki.plugin.globalsearch;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+import
com.xpn.xwiki.plugin.applicationmanager.core.plugin.XWikiPluginMessageTool;
+import com.xpn.xwiki.plugin.globalsearch.tools.GlobalSearchQuery;
+import com.xpn.xwiki.plugin.globalsearch.tools.GlobalSearchResult;
+
+/**
+ * Tool to be able to make and merge multi wikis search queries.
+ *
+ * @version $Id: $
+ */
+final class GlobalSearch
+{
+ /**
+ * Key to use with [EMAIL PROTECTED] XWikiContext#get(Object)}.
+ */
+ public static final String MESSAGETOOL_CONTEXT_KEY =
"globalsearchmessagetool";
+
+ /**
+ * The logging tool.
+ */
+ protected static final Log LOG = LogFactory.getLog(GlobalSearch.class);
+
+ /**
+ * Hql "select" keyword.
+ */
+ private static final String SELECT_KEYWORD = "select";
+
+ /**
+ * Hql "select distinct" keyword.
+ */
+ private static final String SELECT_DISTINCT_KEYWORD = "select distinct";
+
+ /**
+ * Hql "from" keyword.
+ */
+ private static final String FROM_KEYWORD = "from";
+
+ /**
+ * Hql "where" keyword.
+ */
+ private static final String WHERE_KEYWORD = "where";
+
+ /**
+ * Hql "order by" keyword.
+ */
+ private static final String ORDER_KEYWORD = "order by";
+
+ /**
+ * Hql "order by" descendant keyword.
+ */
+ private static final String ORDER_DESC = "desc";
+
+ /**
+ * Name of the field containing document space in the HQL query.
+ */
+ private static final String HQL_DOC_SPACE = "doc.web";
+
+ /**
+ * Name of the field containing document name in the HQL query.
+ */
+ private static final String HQL_DOC_NAME = "doc.name";
+
+ /**
+ * The searchDocument and searchDocumentsNames initial select query part.
+ */
+ private static final String SEARCHDOC_INITIAL_SELECT = "select distinct
doc.web, doc.name";
+
+ /**
+ * The searchDocument and searchDocumentsNames initial select query part
when distinct documents
+ * by language.
+ */
+ private static final String SEARCHDOC_INITIAL_SELECT_LANG =
+ "select distinct doc.web, doc.name, doc.language";
+
+ /**
+ * The searchDocument and searchDocumentsNames initial from query part.
+ */
+ private static final String SEARCHDOC_INITIAL_FROM = " from XWikiDocument
as doc";
+
+ /**
+ * Comma.
+ */
+ private static final String FIELD_SEPARATOR = ",";
+
+ //
////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * The plugin internationalization service.
+ */
+ private XWikiPluginMessageTool messageTool;
+
+ /**
+ * Hidden constructor of GlobalSearch only access via getInstance().
+ *
+ * @param messageTool the plugin internationalization service.
+ */
+ GlobalSearch(XWikiPluginMessageTool messageTool)
+ {
+ this.messageTool = messageTool;
+ }
+
+ //
////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param context the XWiki context.
+ * @return the names of all virtual wikis.
+ * @throws XWikiException error when getting the list of virtual wikis.
+ */
+ private Collection getAllWikiNameList(XWikiContext context) throws
XWikiException
+ {
+ Collection wikiNames =
context.getWiki().getVirtualWikisDatabaseNames(context);
+
+ if (!wikiNames.contains(context.getMainXWiki())) {
+ wikiNames.add(context.getMainXWiki());
+ }
+
+ return wikiNames;
+ }
+
+ /**
+ * Execute query in all provided wikis and return list containing alla
results.
+ *
+ * @param query the query parameters.
+ * @param context the XWiki context.
+ * @return the search result as list of [EMAIL PROTECTED]
GlobalSearchResult} containing all selected
+ * fields values.
+ * @throws XWikiException error when executing query.
+ */
+ public Collection search(GlobalSearchQuery query, XWikiContext context)
throws XWikiException
+ {
+ List resultList = Collections.EMPTY_LIST;
+
+ List selectColumns = parseSelectColumns(query.getHql());
+ List orderColumns = parseOrderColumns(query.getHql());
+
+ Collection wikiNameList;
+ if (context.isVirtual()) {
+ wikiNameList = query.getWikiNameList();
+ if (wikiNameList.isEmpty()) {
+ wikiNameList = getAllWikiNameList(context);
+ }
+ } else {
+ wikiNameList = new ArrayList(1);
+ wikiNameList.add(context.getMainXWiki());
+ }
+
+ int max =
+ query.getMax() > 0 ? query.getMax() + (query.getStart() > 0 ?
query.getStart() : 0)
+ : 0;
+
+ String database = context.getDatabase();
+ try {
+ resultList = new LinkedList();
+
+ for (Iterator it = wikiNameList.iterator(); it.hasNext();) {
+ String wikiName = (String) it.next();
+
+ context.setDatabase(wikiName);
+
+ List resultsTmp =
+ context.getWiki().getStore().search(query.getHql(), max, 0,
+ query.getParameterList(), context);
+
+ insertResults(wikiName, resultList, resultsTmp, query,
selectColumns,
+ orderColumns, context);
+ }
+ } finally {
+ context.setDatabase(database);
+ }
+
+ if (resultList.size() > max || query.getStart() > 0) {
+ resultList =
+ resultList.subList(query.getStart() > 0 ? query.getStart() : 0,
+ resultList.size() > max ? max : resultList.size());
+ }
+
+ return resultList;
+ }
+
+ /**
+ * Insert a list of result in the sorted main list.
+ *
+ * @param wikiName the name of the wiki from where the list
<code>list</code> come.
+ * @param sortedList the sorted main list.
+ * @param list the list to insert.
+ * @param query the query parameters.
+ * @param selectColumns the names of selected fields.
+ * @param orderColumns the fields to order.
+ * @param context the XWiki context.
+ */
+ private void insertResults(String wikiName, List sortedList, Collection
list,
+ GlobalSearchQuery query, List selectColumns, List orderColumns,
XWikiContext context)
+ {
+ boolean sort = !sortedList.isEmpty();
+
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ Object[] objects = (Object[]) it.next();
+
+ GlobalSearchResult result = new GlobalSearchResult(wikiName,
selectColumns, objects);
+
+ if (sort) {
+ insertResult(sortedList, result, query, selectColumns,
orderColumns, context);
+ } else {
+ sortedList.add(result);
+ }
+ }
+ }
+
+ /**
+ * Insert a result of result in the sorted main list.
+ *
+ * @param sortedList the sorted main list.
+ * @param result the fields values to insert.
+ * @param query the query parameters.
+ * @param selectColumns the names of selected fields.
+ * @param orderColumns the fields to order.
+ * @param context the XWiki context.
+ */
+ private void insertResult(List sortedList, GlobalSearchResult result,
+ GlobalSearchQuery query, List selectColumns, List orderColumns,
XWikiContext context)
+ {
+ int max =
+ query.getMax() > 0 ? query.getMax() + (query.getStart() > 0 ?
query.getStart() : 0)
+ : -1;
+
+ int index = 0;
+ for (Iterator itSorted = sortedList.iterator(); itSorted.hasNext()
+ && (max <= 0 || index < max); ++index) {
+ GlobalSearchResult sortedResult = (GlobalSearchResult)
itSorted.next();
+
+ if (compare(sortedResult, result, orderColumns) > 0) {
+ break;
+ }
+ }
+
+ if (max <= 0 || index < max) {
+ sortedList.add(index, result);
+ }
+ }
+
+ /**
+ * Compare two results depends on list of order fields.
+ *
+ * @param result1 the first result to compare.
+ * @param result2 the second result to compare.
+ * @param orderColumns the list of order fields.
+ * @return a negative integer, zero, or a positive integer as
<code>map1</code> is less than,
+ * equal to, or greater than <code>map2</code>.
+ */
+ private int compare(GlobalSearchResult result1, GlobalSearchResult
result2, List orderColumns)
+ {
+ for (Iterator it = orderColumns.iterator(); it.hasNext();) {
+ int result = compare(result1, result2, (Object[]) it.next());
+
+ if (result != 0) {
+ return result;
+ }
+ }
+
+ return 0;
+ }
+
+ /**
+ * Compare two results depends on order fields.
+ *
+ * @param result1 the first result to compare.
+ * @param result2 the second result to compare.
+ * @param orderField the order fields.
+ * @return a negative integer, zero, or a positive integer as
<code>map1</code> is less than,
+ * equal to, or greater than <code>map2</code>.
+ */
+ private int compare(GlobalSearchResult result1, GlobalSearchResult result2,
+ Object[] orderField)
+ {
+ int result = 0;
+
+ String fieldName = (String) orderField[0];
+ boolean fieldAsc = ((Boolean) orderField[1]).booleanValue();
+
+ Object value1 = result1.get(fieldName);
+ Object value2 = result2.get(fieldName);
+
+ if (value1 instanceof String) {
+ result = ((String) value1).compareToIgnoreCase((String) value2);
+ } else if (value1 instanceof Comparable) {
+ result = ((Comparable) value1).compareTo(value2);
+ }
+
+ return fieldAsc ? result : -result;
+ }
+
+ /**
+ * Extract names of selected fields from hql query.
+ *
+ * @param hql the hql query. The hql has some constraints:
+ * <ul>
+ * <li>"*" is not supported in SELECT clause.</li>
+ * <li>All ORDER BY fields has to be listed in SELECT
clause.</li>
+ * </ul>
+ * @return the names of selected fields from hql query.
+ */
+ private List parseSelectColumns(String hql)
+ {
+ List columnList = new ArrayList();
+
+ int selectEnd = 0;
+ int selectIndex = hql.toLowerCase().indexOf(SELECT_DISTINCT_KEYWORD);
+ if (selectIndex < 0) {
+ selectIndex = hql.toLowerCase().indexOf(SELECT_KEYWORD);
+
+ if (selectIndex < 0) {
+ selectIndex = 0;
+ } else {
+ selectEnd = SELECT_KEYWORD.length();
+ }
+ } else {
+ selectEnd = SELECT_DISTINCT_KEYWORD.length();
+ }
+
+ int fromIndex = hql.toLowerCase().indexOf(FROM_KEYWORD);
+
+ if (fromIndex >= 0) {
+ String selectContent = hql.substring(selectIndex + selectEnd + 1,
fromIndex);
+ String[] columnsTable = selectContent.split(FIELD_SEPARATOR);
+ for (int i = 0; i < columnsTable.length; ++i) {
+ String[] column = columnsTable[i].trim().split("\\s");
+ String columnName = column[0];
+ columnList.add(columnName);
+ }
+ }
+
+ return columnList;
+ }
+
+ /**
+ * Extract names of "order by" fields from hql query.
+ *
+ * @param hql the hql query.
+ * @return the names of "order by" fields from hql query.
+ */
+ private List parseOrderColumns(String hql)
+ {
+ List columnList = new ArrayList();
+
+ int orderIndex = hql.toLowerCase().lastIndexOf(ORDER_KEYWORD);
+
+ if (orderIndex >= 0) {
+ String orderContent = hql.substring(orderIndex +
ORDER_KEYWORD.length() + 1);
+ String[] columnsTable = orderContent.split(FIELD_SEPARATOR);
+ for (int i = 0; i < columnsTable.length; ++i) {
+ String orderField = columnsTable[i];
+ Object[] orderFieldTable = orderContent.split("\\s+");
+
+ orderField = (String) orderFieldTable[0];
+
+ Boolean asc = Boolean.TRUE;
+ if (orderFieldTable.length > 1
+ && ((String)
orderFieldTable[1]).trim().toLowerCase().equals(ORDER_DESC)) {
+ asc = Boolean.FALSE;
+ }
+
+ columnList.add(new Object[] {orderField.trim(), asc});
+ }
+ }
+
+ return columnList;
+ }
+
+ /**
+ * @param queryPrefix the start of the SQL query (for example "select
distinct doc.web,
+ * doc.name")
+ * @param whereSQL the where clause to append
+ * @return the full formed SQL query, to which the order by columns have
been added as returned
+ * columns (this is required for example for HSQLDB).
+ */
+ protected String createSearchDocumentsHQLQuery(String queryPrefix, String
whereSQL)
+ {
+ StringBuffer hql = new StringBuffer(queryPrefix);
+
+ String normalizedWhereSQL;
+ if (whereSQL == null) {
+ normalizedWhereSQL = "";
+ } else {
+ normalizedWhereSQL = whereSQL.trim();
+ }
+
+ Collection orderColumns = parseOrderColumns(normalizedWhereSQL);
+
+ for (Iterator it = orderColumns.iterator(); it.hasNext();) {
+ Object[] orderField = (Object[]) it.next();
+ if (!orderField.equals(HQL_DOC_SPACE) &&
!orderField.equals(HQL_DOC_NAME)) {
+ hql.append(FIELD_SEPARATOR);
+ hql.append(orderField[0]);
+ }
+ }
+
+ hql.append(SEARCHDOC_INITIAL_FROM);
+
+ if (normalizedWhereSQL.length() != 0) {
+ if ((!normalizedWhereSQL.startsWith(WHERE_KEYWORD))
+ && (!normalizedWhereSQL.startsWith(FIELD_SEPARATOR))) {
+ hql.append(" ");
+ hql.append(WHERE_KEYWORD);
+ hql.append(" ");
+ } else {
+ hql.append(" ");
+ }
+ hql.append(normalizedWhereSQL);
+ }
+
+ return hql.toString();
+ }
+
+ /**
+ * Search wiki pages in all provided wikis and return list containing found
+ * [EMAIL PROTECTED] XWikiDocument}.
+ *
+ * @param query the query parameters.
+ * @param distinctbylanguage when a document has multiple version for each
language it is
+ * returned as one document a language.
+ * @param customMapping inject custom mapping in session.
+ * @param checkRight if true check for each found document if context's
user has "view" rights
+ * for it.
+ * @param context the XWiki context.
+ * @return the found [EMAIL PROTECTED] XWikiDocument}.
+ * @throws XWikiException error when searching for documents.
+ */
+ private Collection searchDocumentsNamesInfos(GlobalSearchQuery query,
+ boolean distinctbylanguage, boolean customMapping, boolean checkRight,
+ XWikiContext context) throws XWikiException
+ {
+ if (!query.getHql().toLowerCase().startsWith(SELECT_KEYWORD)) {
+ String select =
+ distinctbylanguage ? SEARCHDOC_INITIAL_SELECT_LANG :
SEARCHDOC_INITIAL_SELECT;
+
+ query.setHql(createSearchDocumentsHQLQuery(select,
query.getHql()));
+ }
+
+ return search(query, context);
+ }
+
+ /**
+ * Search wiki pages in all provided wikis and return list containing found
+ * [EMAIL PROTECTED] XWikiDocument}.
+ *
+ * @param query the query parameters.
+ * @param distinctbylanguage when a document has multiple version for each
language it is
+ * returned as one document a language.
+ * @param customMapping inject custom mapping in session.
+ * @param checkRight if true check for each found document if context's
user has "view" rights
+ * for it.
+ * @param context the XWiki context.
+ * @return the found [EMAIL PROTECTED] XWikiDocument}.
+ * @throws XWikiException error when searching for documents.
+ */
+ public Collection searchDocuments(GlobalSearchQuery query, boolean
distinctbylanguage,
+ boolean customMapping, boolean checkRight, XWikiContext context)
throws XWikiException
+ {
+ Collection results =
+ searchDocumentsNamesInfos(query, distinctbylanguage,
customMapping, checkRight,
+ context);
+
+ List documents = new ArrayList(results.size());
+
+ String database = context.getDatabase();
+ try {
+ for (Iterator it = results.iterator(); it.hasNext();) {
+ GlobalSearchResult result = (GlobalSearchResult) it.next();
+
+ XWikiDocument doc = new XWikiDocument();
+ doc.setSpace((String) result.get(HQL_DOC_SPACE));
+ doc.setName((String) result.get(HQL_DOC_NAME));
+
+ context.setDatabase(result.getWikiName());
+
+ doc = context.getWiki().getStore().loadXWikiDoc(doc, context);
+
+ if (checkRight) {
+ if
(!context.getWiki().getRightService().checkAccess("view", doc, context)) {
+ continue;
+ }
+ }
+
+ documents.add(doc);
+ }
+ } finally {
+ context.setDatabase(database);
+ }
+
+ return documents;
+ }
+
+ /**
+ * Search wiki pages in all provided wikis and return list containing found
+ * [EMAIL PROTECTED] XWikiDocument}.
+ *
+ * @param query the query parameters.
+ * @param distinctbylanguage when a document has multiple version for each
language it is
+ * returned as one document a language.
+ * @param customMapping inject custom mapping in session.
+ * @param checkRight if true check for each found document if context's
user has "view" rights
+ * for it.
+ * @param context the XWiki context.
+ * @return the found [EMAIL PROTECTED] XWikiDocument}.
+ * @throws XWikiException error when searching for documents.
+ */
+ public Collection searchDocumentsNames(GlobalSearchQuery query, boolean
distinctbylanguage,
+ boolean customMapping, boolean checkRight, XWikiContext context)
throws XWikiException
+ {
+ Collection results =
+ searchDocumentsNamesInfos(query, distinctbylanguage,
customMapping, checkRight,
+ context);
+
+ List documentsNames = new ArrayList(results.size());
+
+ for (Iterator it = results.iterator(); it.hasNext();) {
+ GlobalSearchResult result = (GlobalSearchResult) it.next();
+
+ documentsNames.add(result.getWikiName() + ":" +
result.get(HQL_DOC_SPACE) + "."
+ + result.get(HQL_DOC_NAME));
+ }
+
+ return documentsNames;
+ }
+}
Property changes on:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearch.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchException.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchException.java
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchException.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -0,0 +1,107 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.xpn.xwiki.plugin.globalsearch;
+
+import com.xpn.xwiki.plugin.PluginException;
+
+/**
+ * Global Search plugin base exception.
+ *
+ * @version $Id: $
+ */
+public class GlobalSearchException extends PluginException
+{
+ /**
+ * Global Search plugin error identifier.
+ */
+ public static final int MODULE_PLUGIN_GLOABLSEARCH = 60;
+
+ /**
+ * Error when trying to create wiki descriptor that already exists.
+ */
+ public static final int ERROR_FS_CANT_ACCESS_FIELD = 60000;
+
+ // //////
+
+ /**
+ * The default GlobalSearchException.
+ */
+ private static final GlobalSearchException DEFAULT_EXCEPTION = new
GlobalSearchException();
+
+ // //////
+
+ /**
+ * Create an GlobalSearchException.
+ *
+ * @param code the error code.
+ * @param message a literal message about this error.
+ */
+ public GlobalSearchException(int code, String message)
+ {
+ super(GlobalSearchException.class, code, message);
+ }
+
+ /**
+ * Create an GlobalSearchException. Replace any parameters found in the
<code>message</code>
+ * by the passed <code>args</code> parameters. The format is the one used
by
+ * [EMAIL PROTECTED] java.text.MessageFormat}.
+ *
+ * @param code the error code.
+ * @param message a literal message about this error.
+ * @param e the exception this exception wrap.
+ * @param args the array of parameters to use for replacing "{N}" elements
in the string. See
+ * [EMAIL PROTECTED] java.text.MessageFormat} for the full
syntax
+ */
+ public GlobalSearchException(int code, String message, Throwable e,
Object[] args)
+ {
+ super(GlobalSearchException.class, code, message, e, args);
+ }
+
+ /**
+ * Create an GlobalSearchException.
+ *
+ * @param code the error code.
+ * @param message a literal message about this error.
+ * @param e the exception this exception wrap.
+ */
+ public GlobalSearchException(int code, String message, Throwable e)
+ {
+ super(GlobalSearchException.class, code, message, e);
+ }
+
+ // //////
+
+ /**
+ * Create default GlobalSearchException.
+ */
+ private GlobalSearchException()
+ {
+ super(GlobalSearchException.class, 0, "No error");
+ }
+
+ /**
+ * @return unique instance of the default GlobalSearchException.
+ */
+ public static GlobalSearchException getDefaultException()
+ {
+ return DEFAULT_EXCEPTION;
+ }
+}
Property changes on:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchException.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchMessageTool.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchMessageTool.java
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchMessageTool.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -0,0 +1,57 @@
+package com.xpn.xwiki.plugin.globalsearch;
+
+import java.util.Locale;
+
+import com.xpn.xwiki.XWikiContext;
+import
com.xpn.xwiki.plugin.applicationmanager.core.plugin.XWikiPluginMessageTool;
+
+/**
+ * Global Search plugin translation messages manager.
+ * <p>
+ * The main use of this class is construct [EMAIL PROTECTED]
XWikiPluginMessageTool} with the correct
+ * [EMAIL PROTECTED] java.util.ResourceBundle} and to list all the message
keys used internally in the plugin.
+ *
+ * @version $Id: $
+ */
+public class GlobalSearchMessageTool extends XWikiPluginMessageTool
+{
+ /**
+ * Used as [EMAIL PROTECTED] GlobalSearchException} message when provided
field does not exist in the
+ * document.
+ */
+ public static final String ERROR_CANTACCESSFIELD =
+ "globalsearch.plugin.error.cantaccessdocfield";
+
+ /**
+ * Used as [EMAIL PROTECTED] GlobalSearchException} message when failed to
get document translations.
+ */
+ public static final String ERROR_DOCUMENTTRANSLATIONS =
+ "globalsearch.plugin.error.documenttranslations";
+
+ /**
+ * Used as [EMAIL PROTECTED] org.apache.commons.logging.Log} log message
when trying to search documents.
+ */
+ public static final String LOG_SEARCHDOCUMENTS =
"globalsearch.plugin.log.searchdocuments";
+
+ /**
+ * Used as [EMAIL PROTECTED] org.apache.commons.logging.Log} log message
when trying to get document from
+ * name.
+ */
+ public static final String LOG_GETDOCUMENTFROMNAME =
+ "globalsearch.plugin.log.getdocumentfromname";
+
+ /**
+ * Call for [EMAIL PROTECTED]
XWikiPluginMessageTool#XWikiPluginMessageTool(ResourceBundle, XWikiContext)}.
+ * Construct ResourceBundle based on [EMAIL PROTECTED]
GlobalSearchPlugin#PLUGIN_NAME} +
+ * "/ApplicationResources".
+ *
+ * @param locale the [EMAIL PROTECTED] Locale} used to load the [EMAIL
PROTECTED] ResourceBundle}.
+ * @param plugin tyhe plugin.
+ * @param context the [EMAIL PROTECTED] com.xpn.xwiki.XWikiContext}
object, used to get access to XWiki
+ * primitives for loading documents
+ */
+ GlobalSearchMessageTool(Locale locale, GlobalSearchPlugin plugin,
XWikiContext context)
+ {
+ super(locale, plugin, context);
+ }
+}
Property changes on:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchMessageTool.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPlugin.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPlugin.java
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPlugin.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -0,0 +1,73 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.xpn.xwiki.plugin.globalsearch;
+
+import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
+import com.xpn.xwiki.plugin.XWikiPluginInterface;
+import com.xpn.xwiki.XWikiContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Entry point of the Global Search plugin.
+ *
+ * @version $Id: $
+ */
+public class GlobalSearchPlugin extends XWikiDefaultPlugin
+{
+ /**
+ * Identifier of Global Search plugin.
+ */
+ public static final String PLUGIN_NAME = "globalsearch";
+
+ //
////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * The logging tool.
+ */
+ protected static final Log LOG =
LogFactory.getLog(GlobalSearchPlugin.class);
+
+ //
////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Construct the entry point of the Global Search plugin.
+ *
+ * @param name the identifier of the plugin.
+ * @param className the class name of the entry point of the plugin.
+ * @param context the XWiki context.
+ */
+ public GlobalSearchPlugin(String name, String className, XWikiContext
context)
+ {
+ super(PLUGIN_NAME, className, context);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @see
com.xpn.xwiki.plugin.XWikiDefaultPlugin#getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface,
+ * com.xpn.xwiki.XWikiContext)
+ */
+ public com.xpn.xwiki.api.Api getPluginApi(XWikiPluginInterface plugin,
XWikiContext context)
+ {
+ return new GlobalSearchPluginApi((GlobalSearchPlugin) plugin, context);
+ }
+}
Property changes on:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPlugin.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPluginApi.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPluginApi.java
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPluginApi.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -0,0 +1,182 @@
+package com.xpn.xwiki.plugin.globalsearch;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Locale;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.plugin.PluginApi;
+import com.xpn.xwiki.plugin.applicationmanager.core.api.XWikiExceptionApi;
+import
com.xpn.xwiki.plugin.applicationmanager.core.plugin.XWikiPluginMessageTool;
+import com.xpn.xwiki.plugin.globalsearch.tools.GlobalSearchQuery;
+
+/**
+ * API tool to be able to make and merge multi wikis search queries.
+ *
+ * @version $Id: $
+ */
+public class GlobalSearchPluginApi extends PluginApi
+{
+ /**
+ * Field name of the last error code inserted in context.
+ */
+ public static final String CONTEXT_LASTERRORCODE = "lasterrorcode";
+
+ /**
+ * Field name of the last API exception inserted in context.
+ */
+ public static final String CONTEXT_LASTEXCEPTION = "lastexception";
+
+ /**
+ * Logging tool.
+ */
+ protected static final Log LOG =
LogFactory.getLog(GlobalSearchPluginApi.class);
+
+ /**
+ * The plugin internationalization service.
+ */
+ private XWikiPluginMessageTool messageTool;
+
+ /**
+ * Tool to be able to make and merge multi wikis search queries.
+ */
+ private GlobalSearch search;
+
+ /**
+ * Create an instance of GlobalSearchPluginApi.
+ *
+ * @param plugin the entry point of the Global Search plugin.
+ * @param context the XWiki context.
+ */
+ public GlobalSearchPluginApi(GlobalSearchPlugin plugin, XWikiContext
context)
+ {
+ super(plugin, context);
+
+ // Message Tool
+ Locale locale = (Locale) context.get("locale");
+ this.messageTool = new GlobalSearchMessageTool(locale, plugin,
context);
+ context.put(GlobalSearch.MESSAGETOOL_CONTEXT_KEY, this.messageTool);
+
+ this.search = new GlobalSearch(messageTool);
+ }
+
+ /**
+ * Create a new instance of [EMAIL PROTECTED] GlobalSearchQuery} and
return it.
+ *
+ * @return a new instance of [EMAIL PROTECTED] GlobalSearchQuery} and
return it.
+ */
+ public GlobalSearchQuery newQuery()
+ {
+ return new GlobalSearchQuery();
+ }
+
+ /**
+ * Execute query in all provided wikis and return list containing all
results.
+ *
+ * @param query the query parameters. The hql has some constraints:
+ * <ul>
+ * <li>"*" is not supported in SELECT clause.</li>
+ * <li>All ORDER BY fields has to be listed in SELECT
clause.</li>
+ * </ul>
+ * @return the search result as list of
+ * [EMAIL PROTECTED]
com.xpn.xwiki.plugin.globalsearch.tools.GlobalSearchResult} containing all
+ * selected fields values.
+ * @throws XWikiException error when executing query.
+ */
+ public Collection search(GlobalSearchQuery query) throws XWikiException
+ {
+ Collection results = Collections.EMPTY_LIST;
+
+ try {
+ if (hasProgrammingRights()) {
+ results = search.search(query, this.context);
+ }
+ } catch (GlobalSearchException e) {
+
LOG.error(messageTool.get(GlobalSearchMessageTool.LOG_SEARCHDOCUMENTS), e);
+
+ this.context.put(CONTEXT_LASTERRORCODE, new Integer(e.getCode()));
+ this.context.put(CONTEXT_LASTEXCEPTION, new XWikiExceptionApi(e,
this.context));
+ }
+
+ return results;
+ }
+
+ /**
+ * Search wiki pages in all provided wikis and return list containing found
+ * [EMAIL PROTECTED] com.xpn.xwiki.api.Document}.
+ *
+ * @param query the query parameters. The hql has some constraints:
+ * <ul>
+ * <li>"*" is not supported in SELECT clause.</li>
+ * <li>All ORDER BY fields has to be listed in SELECT
clause.</li>
+ * </ul>
+ * @param distinctbylanguage when a document has multiple version for each
language it is
+ * returned as one document a language.
+ * @return the found [EMAIL PROTECTED] com.xpn.xwiki.api.Document}.
+ * @throws XWikiException error when executing query.
+ */
+ public Collection searchDocuments(GlobalSearchQuery query, boolean
distinctbylanguage)
+ throws XWikiException
+ {
+ Collection documentList = Collections.EMPTY_LIST;
+
+ try {
+ Collection documents =
+ search.searchDocuments(query, distinctbylanguage, false, true,
this.context);
+
+ documentList = new ArrayList(documents.size());
+ for (Iterator it = documents.iterator(); it.hasNext();) {
+ documentList.add(((XWikiDocument)
it.next()).newDocument(context));
+ }
+ } catch (GlobalSearchException e) {
+
LOG.error(messageTool.get(GlobalSearchMessageTool.LOG_SEARCHDOCUMENTS), e);
+
+ this.context.put(CONTEXT_LASTERRORCODE, new Integer(e.getCode()));
+ this.context.put(CONTEXT_LASTEXCEPTION, new XWikiExceptionApi(e,
this.context));
+ }
+
+ return documentList;
+ }
+
+ /**
+ * Search wiki pages in all provided wikis and return list containing found
+ * [EMAIL PROTECTED] com.xpn.xwiki.api.Document}.
+ *
+ * @param query the query parameters. The hql has some constraints:
+ * <ul>
+ * <li>"*" is not supported in SELECT clause.</li>
+ * <li>All ORDER BY fields has to be listed in SELECT
clause.</li>
+ * </ul>
+ * @param distinctbylanguage when a document has multiple version for each
language it is
+ * returned as one document a language.
+ * @param checkRight if true check for each found document if context's
user has "view" rights
+ * for it.
+ * @return the found [EMAIL PROTECTED] com.xpn.xwiki.api.Document}.
+ * @throws XWikiException error when executing query.
+ */
+ public Collection searchDocumentsNames(GlobalSearchQuery query, boolean
distinctbylanguage,
+ boolean checkRight) throws XWikiException
+ {
+ Collection results = Collections.EMPTY_LIST;
+
+ try {
+ results =
+ search.searchDocumentsNames(query, distinctbylanguage, false,
checkRight,
+ this.context);
+ } catch (GlobalSearchException e) {
+
LOG.error(messageTool.get(GlobalSearchMessageTool.LOG_SEARCHDOCUMENTS), e);
+
+ this.context.put(CONTEXT_LASTERRORCODE, new Integer(e.getCode()));
+ this.context.put(CONTEXT_LASTEXCEPTION, new XWikiExceptionApi(e,
this.context));
+ }
+
+ return results;
+ }
+}
Property changes on:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/GlobalSearchPluginApi.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchQuery.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchQuery.java
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchQuery.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -0,0 +1,154 @@
+package com.xpn.xwiki.plugin.globalsearch.tools;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Contains all parameters for a global search query.
+ *
+ * @version $Id: $
+ */
+public class GlobalSearchQuery
+{
+ /**
+ * The names of wikis where to search.
+ */
+ private List wikiNameList = new ArrayList();
+
+ /**
+ * The hql query.
+ */
+ private String hql;
+
+ /**
+ * The values to insert in the named query.
+ */
+ private List parameterList = new ArrayList();
+
+ /**
+ * The maximum number of results.
+ */
+ private int max;
+
+ /**
+ * The first index of the result.
+ */
+ private int start;
+
+ /**
+ * @param wikiNameList names of wikis where to search.
+ */
+ public void addWikiNameList(Collection wikiNameList)
+ {
+ this.wikiNameList.addAll(wikiNameList);
+ }
+
+ /**
+ * @param wikiNameList the names of wikis where to search.
+ */
+ public void setWikiNameList(Collection wikiNameList)
+ {
+ this.wikiNameList.clear();
+ if (wikiNameList != null) {
+ this.addWikiNameList(wikiNameList);
+ }
+ }
+
+ /**
+ * @param wikiName a name of wiki where to search.
+ */
+ public void addWikiName(String wikiName)
+ {
+ this.wikiNameList.add(wikiName);
+ }
+
+ /**
+ * @return the names of wikis where to search.
+ */
+ public Collection getWikiNameList()
+ {
+ return this.wikiNameList;
+ }
+
+ /**
+ * @param hql the hql query.
+ */
+ public void setHql(String hql)
+ {
+ this.hql = hql;
+ }
+
+ /**
+ * @return the hql query.
+ */
+ public String getHql()
+ {
+ return this.hql;
+ }
+
+ /**
+ * @param values values to insert in the named query.
+ */
+ public void addParameterList(Collection values)
+ {
+ this.parameterList.addAll(values);
+ }
+
+ /**
+ * @param values the values to insert in the named query.
+ */
+ public void setParameterList(Collection values)
+ {
+ this.parameterList.clear();
+ this.parameterList.addAll(values);
+ }
+
+ /**
+ * @param value a value to insert in the named query.
+ */
+ public void addParameter(Object value)
+ {
+ this.parameterList.add(value);
+ }
+
+ /**
+ * @return the values to insert in the named query.
+ */
+ public List getParameterList()
+ {
+ return this.parameterList;
+ }
+
+ /**
+ * @param max the maximum number of results.
+ */
+ public void setMax(int max)
+ {
+ this.max = max;
+ }
+
+ /**
+ * @return the maximum number of results.
+ */
+ public int getMax()
+ {
+ return this.max;
+ }
+
+ /**
+ * @param start the index of the first result.
+ */
+ public void setStart(int start)
+ {
+ this.start = start;
+ }
+
+ /**
+ * @return the index of the first result.
+ */
+ public int getStart()
+ {
+ return this.start;
+ }
+}
Property changes on:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchQuery.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchResult.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchResult.java
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchResult.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -0,0 +1,94 @@
+package com.xpn.xwiki.plugin.globalsearch.tools;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * Contains one query result line.
+ *
+ * @version $Id: $
+ */
+public class GlobalSearchResult extends HashMap
+{
+ /**
+ * The name of the wiki where this was found.
+ */
+ private String wikiName;
+
+ /**
+ * The found values.
+ */
+ private Collection result;
+
+ /**
+ * Create new [EMAIL PROTECTED] GlobalSearchResult} instance.
+ */
+ public GlobalSearchResult()
+ {
+
+ }
+
+ /**
+ * Create new [EMAIL PROTECTED] GlobalSearchResult} instance.
+ *
+ * @param wikiName the name of the wiki where this was found.
+ * @param names the names of the columns to link with values.
+ * @param values the found values.
+ */
+ public GlobalSearchResult(String wikiName, Iterable names, Object[] values)
+ {
+ setWikiName(wikiName);
+
+ this.result = new ArrayList(values.length);
+ Iterator nameIt = names.iterator();
+ for (int i = 0; i < values.length; ++i) {
+ Object value = values[i];
+
+ this.result.add(value);
+ put(nameIt.next(), value);
+ }
+ }
+
+ /**
+ * @param wikiName the name of the wiki where this was found.
+ */
+ public void setWikiName(String wikiName)
+ {
+ this.wikiName = wikiName;
+ }
+
+ /**
+ * @return the name of the wiki where this was found.
+ */
+ public String getWikiName()
+ {
+ return wikiName;
+ }
+
+ /**
+ * @param result the found values.
+ */
+ public void setResult(Collection result)
+ {
+ this.result = new ArrayList(result);
+ }
+
+ /**
+ * @param result the found values.
+ */
+ public void setResult(Object[] result)
+ {
+ this.result = Arrays.asList(result);
+ }
+
+ /**
+ * @return the found values.
+ */
+ public Collection getResult()
+ {
+ return result;
+ }
+}
Property changes on:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/globalsearch/tools/GlobalSearchResult.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerMessageTool.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerMessageTool.java
2008-01-18 20:02:53 UTC (rev 6966)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerMessageTool.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -1,7 +1,6 @@
package com.xpn.xwiki.plugin.wikimanager;
import java.util.Locale;
-import java.util.ResourceBundle;
import com.xpn.xwiki.XWikiContext;
import
com.xpn.xwiki.plugin.applicationmanager.core.plugin.XWikiPluginMessageTool;
@@ -10,7 +9,7 @@
* Wiki Manager plugin translation messages manager.
* <p>
* The main use of this class is construct [EMAIL PROTECTED]
XWikiPluginMessageTool} with the correct
- * [EMAIL PROTECTED] ResourceBundle} and to list all the message keys used
internally in the plugin.
+ * [EMAIL PROTECTED] java.util.ResourceBundle} and to list all the message
keys used internally in the plugin.
*
* @version $Id: $
*/
@@ -189,12 +188,12 @@
* "/ApplicationResources".
*
* @param locale the [EMAIL PROTECTED] Locale} used to load the [EMAIL
PROTECTED] ResourceBundle}.
+ * @param plugin the plugin.
* @param context the [EMAIL PROTECTED] com.xpn.xwiki.XWikiContext}
object, used to get access to XWiki
* primitives for loading documents
*/
- WikiManagerMessageTool(Locale locale, XWikiContext context)
+ WikiManagerMessageTool(Locale locale, WikiManagerPlugin plugin,
XWikiContext context)
{
- super(ResourceBundle.getBundle(WikiManagerPlugin.PLUGIN_NAME +
"/ApplicationResources",
- locale == null ? Locale.ENGLISH : locale), context);
+ super(locale, plugin, context);
}
}
Modified:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPlugin.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPlugin.java
2008-01-18 20:02:53 UTC (rev 6966)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPlugin.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -22,6 +22,8 @@
import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
import com.xpn.xwiki.plugin.XWikiPluginInterface;
+import com.xpn.xwiki.plugin.globalsearch.GlobalSearchPlugin;
+import com.xpn.xwiki.plugin.globalsearch.GlobalSearchPluginApi;
import com.xpn.xwiki.XWikiContext;
import org.apache.commons.logging.Log;
@@ -49,6 +51,11 @@
//
////////////////////////////////////////////////////////////////////////////
/**
+ * Tool to be able to make and merge multi wikis search queries.
+ */
+ private XWikiPluginInterface searchPlugin;
+
+ /**
* Construct the entry point of the Wiki Manager plugin.
*
* @param name the identifier of the plugin.
@@ -63,6 +70,23 @@
/**
* [EMAIL PROTECTED]
*
+ * @see
com.xpn.xwiki.plugin.XWikiDefaultPlugin#init(com.xpn.xwiki.XWikiContext)
+ */
+ public void init(XWikiContext context)
+ {
+ super.init(context);
+
+ searchPlugin =
context.getWiki().getPlugin(GlobalSearchPlugin.PLUGIN_NAME, context);
+ if (searchPlugin == null) {
+ searchPlugin =
+ new GlobalSearchPlugin(GlobalSearchPlugin.PLUGIN_NAME,
GlobalSearchPlugin.class
+ .getName(), context);
+ }
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ *
* @see
com.xpn.xwiki.plugin.XWikiDefaultPlugin#getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface,
* com.xpn.xwiki.XWikiContext)
*/
@@ -70,4 +94,13 @@
{
return new WikiManagerPluginApi((WikiManagerPlugin) plugin, context);
}
+
+ /**
+ * @param context the XWiki context.
+ * @return the global search plugin api.
+ */
+ public GlobalSearchPluginApi getGlobalSearchApiPlugin(XWikiContext context)
+ {
+ return (GlobalSearchPluginApi) searchPlugin.getPluginApi(searchPlugin,
context);
+ }
}
Modified:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPluginApi.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPluginApi.java
2008-01-18 20:02:53 UTC (rev 6966)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/WikiManagerPluginApi.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -22,6 +22,7 @@
import com.xpn.xwiki.plugin.applicationmanager.core.api.XWikiExceptionApi;
import
com.xpn.xwiki.plugin.applicationmanager.core.plugin.XWikiPluginMessageTool;
+import com.xpn.xwiki.plugin.globalsearch.GlobalSearchPluginApi;
import com.xpn.xwiki.plugin.PluginApi;
import com.xpn.xwiki.plugin.wikimanager.doc.Wiki;
import com.xpn.xwiki.plugin.wikimanager.doc.XWikiServer;
@@ -52,7 +53,7 @@
public static final String CONTEXT_LASTERRORCODE = "lasterrorcode";
/**
- * Field name of the last api exception inserted in context.
+ * Field name of the last API exception inserted in context.
*/
public static final String CONTEXT_LASTEXCEPTION = "lastexception";
@@ -65,12 +66,17 @@
* The default WikiManager managed exception.
*/
private XWikiExceptionApi defaultException;
+
+ /**
+ * API tool to be able to make and merge multi wikis search queries.
+ */
+ private GlobalSearchPluginApi searchApi;
/**
* The plugin internationalization service.
*/
private XWikiPluginMessageTool messageTool;
-
+
/**
* Create an instance of the Wiki Manager plugin user api.
*
@@ -86,9 +92,10 @@
// Message Tool
Locale locale = (Locale) context.get("locale");
- this.messageTool = new WikiManagerMessageTool(locale, context);
-
+ this.messageTool = new WikiManagerMessageTool(locale, plugin, context);
context.put(WikiManager.MESSAGETOOL_CONTEXT_KEY, this.messageTool);
+
+ searchApi = plugin.getGlobalSearchApiPlugin(context);
}
/**
@@ -106,6 +113,14 @@
{
return this.messageTool;
}
+
+ /**
+ * @return the GlobalSearch plugin api.
+ */
+ public GlobalSearchPluginApi getSearchApi()
+ {
+ return this.searchApi;
+ }
//
////////////////////////////////////////////////////////////////////////////
// Wikis management
Modified:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/doc/Wiki.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/doc/Wiki.java
2008-01-18 20:02:53 UTC (rev 6966)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/java/com/xpn/xwiki/plugin/wikimanager/doc/Wiki.java
2008-01-19 18:05:14 UTC (rev 6967)
@@ -87,4 +87,18 @@
return (XWikiServer)
XWikiServerClass.getInstance(context).newXObjectDocument(doc, id,
context);
}
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ try {
+ return getWikiName();
+ } catch (XWikiException e) {
+ return super.toString();
+ }
+ }
}
Added:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/resources/globalsearch/ApplicationResources.properties
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/resources/globalsearch/ApplicationResources.properties
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/resources/globalsearch/ApplicationResources.properties
2008-01-19 18:05:14 UTC (rev 6967)
@@ -0,0 +1,8 @@
+# comments
+
+# messages
+globalsearch.plugin.error.cantaccessdocfield=Can't access document field [{0}]
+
+# log
+globalsearch.plugin.log.searchdocuments=Documents search failed
+globalsearch.plugin.log.getdocumentfromname=Trying to get document from name
[{0}]
Property changes on:
xwiki-platform/xwiki-plugins/trunk/wiki-manager/src/main/resources/globalsearch/ApplicationResources.properties
___________________________________________________________________
Name: svn:eol-style
+ native
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications