r1303 - in xwiki/trunk: . src/main/java/com/xpn/xwiki src/main/java/com/xpn/xwiki/doc src/main/java/com/xpn/xwiki/objects/classes src/main/java/com/xpn/xwiki/plugin/query src/main/java/com/xpn/xwiki/util src/test/java/com/xpn/xwiki/test src/test/java/com/xpn/xwiki/test/plugin/query

Ludovic Dubost ludovic at users.forge.objectweb.org
Mon Sep 11 15:31:12 CEST 2006


Author: ludovic
Date: 2006-09-11 15:31:07 +0200 (Mon, 11 Sep 2006)
New Revision: 1303

Added:
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/OrderClause.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/XWikiCriteria.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/XWikiQuery.java
   xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryGeneratorTest.java
Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiContext.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/BaseClass.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/BooleanClass.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/DateClass.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/ListClass.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/NumberClass.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/PropertyClass.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/StringClass.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/IQueryFactory.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/QueryPlugin.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/QueryPluginApi.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/util/Util.java
   xwiki/trunk/src/test/java/com/xpn/xwiki/test/AllTests.java
   xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginTest.java
   xwiki/trunk/xwiki.ipr
   xwiki/trunk/xwiki.iws
   xwiki/trunk/xwikibase.iml
Log:
New Project File with updated libs
Initial implementation of the query generator

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -105,15 +105,12 @@
 import com.xpn.xwiki.notify.XWikiPageNotification;
 import com.xpn.xwiki.objects.BaseObject;
 import com.xpn.xwiki.objects.PropertyInterface;
-import com.xpn.xwiki.objects.classes.BaseClass;
-import com.xpn.xwiki.objects.classes.BooleanClass;
-import com.xpn.xwiki.objects.classes.GroupsClass;
-import com.xpn.xwiki.objects.classes.LevelsClass;
-import com.xpn.xwiki.objects.classes.NumberClass;
-import com.xpn.xwiki.objects.classes.UsersClass;
+import com.xpn.xwiki.objects.classes.*;
 import com.xpn.xwiki.objects.meta.MetaClass;
 import com.xpn.xwiki.plugin.XWikiPluginInterface;
 import com.xpn.xwiki.plugin.XWikiPluginManager;
+import com.xpn.xwiki.plugin.query.XWikiQuery;
+import com.xpn.xwiki.plugin.query.QueryPlugin;
 import com.xpn.xwiki.render.XWikiRenderingEngine;
 import com.xpn.xwiki.render.XWikiVelocityRenderer;
 import com.xpn.xwiki.render.groovy.XWikiGroovyRenderer;
@@ -4033,4 +4030,101 @@
         return name;
 
     }
+
+    public List search(XWikiQuery query, XWikiContext context) throws XWikiException {
+        QueryPlugin qp = (QueryPlugin) getPlugin("query", context);
+        if (qp == null)
+         return null;
+        return qp.search(query);
+    }
+
+    public String searchAsTable(XWikiRequest request, String className, XWikiContext context) throws XWikiException {
+        XWikiQuery query = new XWikiQuery();
+        String columns = request.getParameter("columns");
+        query.setDisplayProperties(StringUtils.split(columns, ", "));
+        Set properties = getDocument(className, context).getxWikiClass().getPropertyList();
+        Iterator propid = properties.iterator();
+        while (propid.hasNext()) {
+            String propname = (String) propid.next();
+            Map map = Util.getObject(request, className + "_" + propname);
+            Iterator mapid = map.keySet().iterator();
+            while (mapid.hasNext()) {
+                String key = (String) mapid.next();
+                String[] data = (String[])map.get(key);
+                if (data.length==1)
+                 query.setParam(className + "_" + propname + key, data[0]);
+                else
+                 query.setParam(className + "_" + propname + key, data);
+            }
+        }
+        return searchAsTable(query, context);
+    }
+
+    public String searchAsTable(XWikiQuery query, XWikiContext context) throws XWikiException {
+        QueryPlugin qp = (QueryPlugin) getPlugin("query", context);
+        if (qp == null)
+         return null;
+        List list = qp.search(query);
+        String result = "{table}\r\n";
+        List headerColumns = new ArrayList();
+        List displayProperties = query.getDisplayProperties();
+        Iterator displayListIt = displayProperties.iterator();
+        while (displayListIt.hasNext()) {
+            String propname = (String) displayListIt.next();
+            PropertyClass pclass = getPropertyClassFromName(propname, context);
+            if (pclass!=null)
+             headerColumns.add(pclass.getPrettyName());
+            else {
+                if (propname.startsWith("doc.")) {
+                    propname = propname.substring(4);
+                    headerColumns.add(XWikiDocument.getInternalPropertyName(propname, context));
+                }
+                else
+                 headerColumns.add(propname);
+
+            }
+        }
+        result += StringUtils.join(headerColumns.toArray(), " | ") + "\r\n";
+        Iterator resultIt = list.iterator();
+        while (resultIt.hasNext()) {
+            List rowColumns = new ArrayList();
+            String docname = (String) resultIt.next();
+            XWikiDocument doc = getDocument(docname, context);
+            displayListIt = displayProperties.iterator();
+            while (displayListIt.hasNext()) {
+                String propname = (String) displayListIt.next();
+                PropertyClass pclass = getPropertyClassFromName(propname, context);
+                if (pclass==null) {
+                    if (propname.startsWith("doc.")) {
+                        propname = propname.substring(4);
+                    }
+                    String value = doc.getInternalProperty(propname);
+                    rowColumns.add((value==null) ? " " : value);
+                }
+                else {
+                 BaseObject bobj = doc.getObject(pclass.getObject().getName());
+                 rowColumns.add(doc.display(pclass.getName(), "view", bobj, context));
+                } 
+            }
+            result += StringUtils.join(rowColumns.toArray(), " | ") + "\r\n";
+        }
+        result += "{table}\r\n";
+        return result;
+    }
+
+    public PropertyClass getPropertyClassFromName(String propPath, XWikiContext context) {
+        int i1 = propPath.indexOf("_");
+        if (i1==-1)
+         return null;
+        else {
+          String className = propPath.substring(0, i1);
+          String propName = propPath.substring(i1+1);
+            try {
+                return (PropertyClass)getDocument(className,context).getxWikiClass().get(propName);
+            } catch (XWikiException e) {
+                return null;
+            }
+        }
+    }
+
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiContext.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiContext.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiContext.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -293,12 +293,12 @@
 
     // Used to avoid recursive loading of documents if there are recursives usage of classes
     public void addDocumentArchive(String  key, Object obj) {
-        classCache.put(key, obj);
+        archiveCache.put(key, obj);
     }
 
     // Used to avoid recursive loading of documents if there are recursives usage of classes
     public Object getDocumentArchive(String key) {
-        return classCache.get(key);
+        return archiveCache.get(key);
     }
 
     public void setLinksAction(String action) {

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -1,405 +1,406 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * 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.
- *
- * @author ludovic
- * @author namphunghai
- * @author sdumitriu
- * @author thomas
- */
-
-package com.xpn.xwiki;
-
-
-// import com.xpn.xwiki.store.XWikiBatcher;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.text.MessageFormat;
-
-import javax.servlet.ServletException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.velocity.exception.MethodInvocationException;
-import org.hibernate.JDBCException;
-
-public class XWikiException extends Exception {
-
-    private static final Log log = LogFactory.getLog(XWikiException.class);
-
-    private int module;
-    private int code;
-    private Throwable exception;
-    private Object[] args;
-    private String message;
-
-    // Module list
-    public static final int MODULE_XWIKI = 0;
-    public static final int MODULE_XWIKI_CONFIG = 1;
-    public static final int MODULE_XWIKI_DOC = 2;
-    public static final int MODULE_XWIKI_STORE = 3;
-    public static final int MODULE_XWIKI_RENDERING = 4;
-    public static final int MODULE_XWIKI_PLUGINS = 5;
-    public static final int MODULE_XWIKI_PERLPLUGINS = 6;
-    public static final int MODULE_XWIKI_CLASSES = 7;
-    public static final int MODULE_XWIKI_USER = 8;
-    public static final int MODULE_XWIKI_ACCESS = 9;
-    public static final int MODULE_XWIKI_EMAIL = 10;
-    public static final int MODULE_XWIKI_APP = 11;
-    public static final int MODULE_XWIKI_EXPORT = 12;
-    public static final int MODULE_XWIKI_DIFF = 13;
-    public static final int MODULE_XWIKI_GROOVY = 14;
-    public static final int MODULE_XWIKI_NOTIFICATION = 15;
-    public static final int MODULE_XWIKI_CACHE = 16;
-
-    public static final int MODULE_PLUGIN_LASZLO = 21;
-
-    // Error list
-    public static final int ERROR_XWIKI_UNKNOWN = 0;
-    public static final int ERROR_XWIKI_NOT_IMPLEMENTED = 1;
-    public static final int ERROR_XWIKI_DOES_NOT_EXIST = 2;
-    public static final int ERROR_XWIKI_INIT_FAILED = 3;
-    public static final int ERROR_XWIKI_MKDIR = 4;
-
-    // Config
-    public static final int ERROR_XWIKI_CONFIG_FILENOTFOUND = 1001;
-    public static final int ERROR_XWIKI_CONFIG_FORMATERROR = 1002;
-
-    // Doc
-    public static final int ERROR_XWIKI_DOC_EXPORT = 2001;
-    public static final int ERROR_DOC_XML_PARSING = 2002;
-    public static final int ERROR_DOC_RCS_PARSING = 2003;
-
-    // Store
-    public static final int ERROR_XWIKI_STORE_CLASSINVOCATIONERROR = 3001;
-    public static final int ERROR_XWIKI_STORE_FILENOTFOUND = 3002;
-    public static final int ERROR_XWIKI_STORE_ARCHIVEFORMAT = 3003;
-    public static final int ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT = 3004;
-
-    public static final int ERROR_XWIKI_STORE_RCS_SAVING_FILE = 3101;
-    public static final int ERROR_XWIKI_STORE_RCS_READING_FILE = 3102;
-    public static final int ERROR_XWIKI_STORE_RCS_DELETING_FILE = 3103;
-    public static final int ERROR_XWIKI_STORE_RCS_READING_REVISIONS = 3103;
-    public static final int ERROR_XWIKI_STORE_RCS_READING_VERSION = 3104;
-    public static final int ERROR_XWIKI_STORE_RCS_SEARCH = 3111;
-    public static final int ERROR_XWIKI_STORE_RCS_LOADING_ATTACHMENT = 3221;
-    public static final int ERROR_XWIKI_STORE_RCS_SAVING_ATTACHMENT = 3222;
-    public static final int ERROR_XWIKI_STORE_RCS_SEARCHING_ATTACHMENT = 3223;
-    public static final int ERROR_XWIKI_STORE_RCS_DELETING_ATTACHMENT = 3224;
-
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_DOC = 3201;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_DOC = 3202;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_DOC = 3203;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_CANNOT_DELETE_UNLOADED_DOC = 3204;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_REVISIONS = 3203;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_VERSION = 3204;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_UNEXISTANT_VERSION = 3205;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_OBJECT = 3211;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT = 3212;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_OBJECT = 3213;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_CLASS = 3221;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_CLASS = 3222;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SEARCH = 3223;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT = 3231;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT = 3232;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_ATTACHMENT = 3233;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT_LIST = 3234;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SEARCHING_ATTACHMENT = 3235;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_CHECK_EXISTS_DOC = 3236;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SWITCH_DATABASE = 3301;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_CREATE_DATABASE = 3401;
-
-    public static final int ERROR_XWIKI_STORE_JCR_SAVING_DOC = 3501;
-    public static final int ERROR_XWIKI_STORE_JCR_READING_DOC = 3502;
-    public static final int ERROR_XWIKI_STORE_JCR_DELETING_DOC = 3503;
-    public static final int ERROR_XWIKI_STORE_JCR_CANNOT_DELETE_UNLOADED_DOC = 3504;
-    public static final int ERROR_XWIKI_STORE_JCR_READING_REVISIONS = 3503;
-    public static final int ERROR_XWIKI_STORE_JCR_READING_VERSION = 3504;
-    public static final int ERROR_XWIKI_STORE_JCR_UNEXISTANT_VERSION = 3505;
-    public static final int ERROR_XWIKI_STORE_JCR_SAVING_OBJECT = 3511;
-    public static final int ERROR_XWIKI_STORE_JCR_LOADING_OBJECT = 3512;
-    public static final int ERROR_XWIKI_STORE_JCR_DELETING_OBJECT = 3513;
-    public static final int ERROR_XWIKI_STORE_JCR_SAVING_CLASS = 3521;
-    public static final int ERROR_XWIKI_STORE_JCR_LOADING_CLASS = 3522;
-    public static final int ERROR_XWIKI_STORE_JCR_SEARCH = 3523;
-    public static final int ERROR_XWIKI_STORE_JCR_LOADING_ATTACHMENT = 3531;
-    public static final int ERROR_XWIKI_STORE_JCR_SAVING_ATTACHMENT = 3532;
-    public static final int ERROR_XWIKI_STORE_JCR_DELETING_ATTACHMENT = 3533;
-    public static final int ERROR_XWIKI_STORE_JCR_SAVING_ATTACHMENT_LIST = 3534;
-    public static final int ERROR_XWIKI_STORE_JCR_SEARCHING_ATTACHMENT = 3535;
-    public static final int ERROR_XWIKI_STORE_JCR_CHECK_EXISTS_DOC = 3536;
-    public static final int ERROR_XWIKI_STORE_JCR_SWITCH_DATABASE = 3601;
-    public static final int ERROR_XWIKI_STORE_JCR_CREATE_DATABASE = 3701;
-    
-    public static final int ERROR_XWIKI_RENDERING_VELOCITY_EXCEPTION = 4001;
-    public static final int ERROR_XWIKI_RENDERING_GROOVY_EXCEPTION = 4002;
-
-    public static final int ERROR_XWIKI_PERLPLUGIN_START_EXCEPTION = 6001;
-    public static final int ERROR_XWIKI_PERLPLUGIN_START = 6002;
-    public static final int ERROR_XWIKI_PERLPLUGIN_PERLSERVER_EXCEPTION = 6003;
-
-    public static final int ERROR_XWIKI_CLASSES_FIELD_DOES_NOT_EXIST = 7001;
-    public static final int ERROR_XWIKI_CLASSES_FIELD_INVALID = 7002;
-    public static final int ERROR_XWIKI_CLASSES_DIFF = 7003;
-    public static final int ERROR_XWIKI_CLASSES_CUSTOMCLASSINVOCATIONERROR = 7004;
-    public static final int ERROR_XWIKI_CLASSES_PROPERTY_CLASS_INSTANCIATION = 7005;
-    public static final int ERROR_XWIKI_CLASSES_PROPERTY_CLASS_IN_METACLASS = 7006;
-    public static final int ERROR_XWIKI_CLASSES_CANNOT_PREPARE_CUSTOM_DISPLAY = 7007;
-
-
-    public static final int ERROR_XWIKI_USER_INIT = 8001;
-    public static final int ERROR_XWIKI_USER_CREATE = 8002;
-    public static final int ERROR_XWIKI_USER_INACTIVE = 8003;
-
-    public static final int ERROR_XWIKI_ACCESS_DENIED = 9001;
-    public static final int ERROR_XWIKI_ACCESS_TOKEN_INVALID = 9002;
-    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_USERS = 9003;
-    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_GROUPS = 9004;
-    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_ADDING_USERS = 9005;
-    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_LISTING_USERS = 9006;
-
-    public static final int ERROR_XWIKI_EMAIL_CANNOT_GET_VALIDATION_CONFIG = 10001;
-    public static final int ERROR_XWIKI_EMAIL_CANNOT_PREPARE_VALIDATION_EMAIL = 10002;
-    public static final int ERROR_XWIKI_EMAIL_ERROR_SENDING_EMAIL = 10003;
-    public static final int ERROR_XWIKI_EMAIL_CONNECT_FAILED = 10004;
-    public static final int ERROR_XWIKI_EMAIL_LOGIN_FAILED = 10005;
-    public static final int ERROR_XWIKI_EMAIL_SEND_FAILED = 10006;
-
-    public static final int ERROR_XWIKI_APP_TEMPLATE_DOES_NOT_EXIST = 11001;
-    public static final int ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY = 11002;
-    public static final int ERROR_XWIKI_APP_ATTACHMENT_NOT_FOUND = 11003;
-    public static final int ERROR_XWIKI_APP_CREATE_USER = 11004;
-    public static final int ERROR_XWIKI_APP_VALIDATE_USER = 11005;
-    public static final int ERROR_XWIKI_APP_INVALID_CHARS = 11006;
-    public static final int ERROR_XWIKI_APP_URL_EXCEPTION = 11007;
-    public static final int ERROR_XWIKI_APP_UPLOAD_PARSE_EXCEPTION = 11008;
-    public static final int ERROR_XWIKI_APP_UPLOAD_FILE_EXCEPTION = 11009;
-    public static final int ERROR_XWIKI_APP_REDIRECT_EXCEPTION = 11010;
-    public static final int ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION = 11011;
-    public static final int ERROR_XWIKI_APP_SERVICE_NOT_FOUND = 11012;
-    public static final int ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE = 11013;
-    public static final int ERROR_XWIKI_APP_JAVA_HEAP_SPACE = 11014;
-    
-    public static final int ERROR_XWIKI_EXPORT_XSL_FILE_NOT_FOUND = 12001;
-    public static final int ERROR_XWIKI_EXPORT_PDF_FOP_FAILED = 12002;
-    public static final int ERROR_XWIKI_EXPORT_XSL_FAILED = 12003;
-    public static final int ERROR_XWIKI_DIFF_CONTENT_ERROR = 13001;
-    public static final int ERROR_XWIKI_DIFF_RENDERED_ERROR = 13002;
-    public static final int ERROR_XWIKI_DIFF_METADATA_ERROR = 13003;
-    public static final int ERROR_XWIKI_DIFF_CLASS_ERROR = 13004;
-    public static final int ERROR_XWIKI_DIFF_OBJECT_ERROR = 13005;
-    public static final int ERROR_XWIKI_DIFF_XML_ERROR = 13005;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_LOCK = 13006;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_LOCK = 13007;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_LOCK = 13008;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_INVALID_MAPPING = 13009;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_MAPPING_INJECTION_FAILED = 13010;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_LINKS = 13011;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_LINKS = 13012;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_LINKS = 13013;
-    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_BACKLINKS = 13014;
-
-    public static final int ERROR_XWIKI_STORE_JCR_SAVING_LOCK = 13106;
-    public static final int ERROR_XWIKI_STORE_JCR_LOADING_LOCK = 13107;
-    public static final int ERROR_XWIKI_STORE_JCR_DELETING_LOCK = 13108;
-    public static final int ERROR_XWIKI_STORE_JCR_INVALID_MAPPING = 13109;
-    public static final int ERROR_XWIKI_STORE_JCR_MAPPING_INJECTION_FAILED = 13110;
-    public static final int ERROR_XWIKI_STORE_JCR_LOADING_LINKS = 13111;
-    public static final int ERROR_XWIKI_STORE_JCR_SAVING_LINKS = 13112;
-    public static final int ERROR_XWIKI_STORE_JCR_DELETING_LINKS = 13113;
-    public static final int ERROR_XWIKI_STORE_JCR_LOADING_BACKLINKS = 13114;
-    public static final int ERROR_XWIKI_STORE_JCR_OTHER = 13130; // temporary
-    
-    public static final int ERROR_XWIKI_GROOVY_COMPILE_FAILED = 14001;
-    public static final int ERROR_XWIKI_GROOVY_EXECUTION_FAILED = 14002;
-
-    public static final int ERROR_XWIKI_NOTIFICATION = 15001;
-
-    public static final int ERROR_CACHE_INITIALIZING = 16001;
-
-    public static final int ERROR_LASZLO_INVALID_XML = 21001;
-    public static final int ERROR_LASZLO_INVALID_DOTDOT = 21002;
-
-
-    public XWikiException(int module, int code, String message, Throwable e, Object[] args) {
-        setModule(module);
-        setCode(code);
-        setException(e);
-        setArgs(args);
-        setMessage(message);
-        if (log.isTraceEnabled())
-            log.trace(getMessage(), e);
-    }
-
-    public XWikiException(int module, int code, String message, Throwable e) {
-        this(module, code, message, e, null);
-    }
-
-    public XWikiException(int module, int code, String message) {
-        this(module, code, message, null, null);
-    }
-
-    public XWikiException() {
-    }
-
-    public int getModule() {
-        return module;
-    }
-
-    public String getModuleName() {
-        return "" + module;
-    }
-
-    public void setModule(int module) {
-        this.module = module;
-    }
-
-    public int getCode() {
-        return code;
-    }
-
-    public void setCode(int code) {
-        this.code = code;
-    }
-
-    public Throwable getException() {
-        return exception;
-    }
-
-    public void setException(Throwable exception) {
-        this.exception = exception;
-    }
-
-    public Object[] getArgs() {
-        return args;
-    }
-
-    public void setArgs(Object[] args) {
-        this.args = args;
-    }
-
-    public void setMessage(String message) {
-        this.message = message;
-    }
-
-    public String getMessage() {
-        StringBuffer buffer = new StringBuffer();
-        buffer.append("Error number ");
-        buffer.append(getCode());
-        buffer.append(" in ");
-        buffer.append(getModuleName());
-        buffer.append(": ");
-
-        if (message != null) {
-            if (args == null)
-                buffer.append(message);
-            else {
-                MessageFormat msgFormat = new MessageFormat(message);
-                try {
-                    buffer.append(msgFormat.format(args));
-                }
-                catch (Exception e) {
-                    buffer.append("Cannot format message " + message + " with args ");
-                    for (int i = 0; i < args.length; i++) {
-                        if (i != 0)
-                            buffer.append(",");
-                        buffer.append(args[i]);
-                    }
-                }
-            }
-        }
-
-        if (exception != null) {
-            buffer.append("\nWrapped Exception: ");
-            buffer.append(exception.getMessage());
-        }
-        return buffer.toString();
-    }
-
-    public String getFullMessage() {
-        StringBuffer buffer = new StringBuffer(getMessage());
-        buffer.append("\n");
-        buffer.append(getStackTraceAsString());
-        buffer.append("\n");
-        /*
-        List list = XWikiBatcher.getSQLStats().getRecentSqlList();
-        if (list.size() > 0) {
-            buffer.append("Recent SQL:\n");
-            for (int i = 0; i < list.size(); i++) {
-                buffer.append(list.get(i));
-                buffer.append("\n");
-            }
-        }
-        */
-        return buffer.toString();
-    }
-
-    public void printStackTrace(PrintWriter s) {
-        super.printStackTrace(s);
-        if (exception != null) {
-            s.write("\n\nWrapped Exception:\n\n");
-            if (exception.getCause()!=null)
-                exception.getCause().printStackTrace(s);
-            else if (exception instanceof org.hibernate.JDBCException) {
-                (((JDBCException) exception).getSQLException()).printStackTrace(s);
-            } else if (exception instanceof MethodInvocationException) {
-                (((MethodInvocationException) exception).getWrappedThrowable()).printStackTrace(s);
-            } else if (exception instanceof ServletException) {
-                (((ServletException) exception).getRootCause()).printStackTrace(s);
-            } else {
-                exception.printStackTrace(s);
-            }
-        }
-    }
-
-    public void printStackTrace(PrintStream s) {
-        super.printStackTrace(s);
-        if (exception != null) {
-            s.print("\n\nWrapped Exception:\n\n");
-            if (exception.getCause()!=null)
-                exception.getCause().printStackTrace(s);
-            else if (exception instanceof org.hibernate.JDBCException) {
-                (((JDBCException) exception).getSQLException()).printStackTrace(s);
-            } else if (exception instanceof MethodInvocationException) {
-                (((MethodInvocationException) exception).getWrappedThrowable()).printStackTrace(s);
-            } else if (exception instanceof ServletException) {
-                (((ServletException) exception).getRootCause()).printStackTrace(s);
-            } else {
-                exception.printStackTrace(s);
-            }
-        }
-    }
-
-    public String getStackTraceAsString() {
-        StringWriter swriter = new StringWriter();
-        PrintWriter pwriter = new PrintWriter(swriter);
-        printStackTrace(pwriter);
-        pwriter.flush();
-        return swriter.getBuffer().toString();
-    }
-
-    public String getStackTraceAsString(Throwable e) {
-        StringWriter swriter = new StringWriter();
-        PrintWriter pwriter = new PrintWriter(swriter);
-        e.printStackTrace(pwriter);
-        pwriter.flush();
-        return swriter.getBuffer().toString();
-    }
-
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * 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.
+ *
+ * @author ludovic
+ * @author namphunghai
+ * @author sdumitriu
+ * @author thomas
+ */
+
+package com.xpn.xwiki;
+
+
+// import com.xpn.xwiki.store.XWikiBatcher;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.MessageFormat;
+
+import javax.servlet.ServletException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.hibernate.JDBCException;
+
+public class XWikiException extends Exception {
+
+    private static final Log log = LogFactory.getLog(XWikiException.class);
+
+    private int module;
+    private int code;
+    private Throwable exception;
+    private Object[] args;
+    private String message;
+
+    // Module list
+    public static final int MODULE_XWIKI = 0;
+    public static final int MODULE_XWIKI_CONFIG = 1;
+    public static final int MODULE_XWIKI_DOC = 2;
+    public static final int MODULE_XWIKI_STORE = 3;
+    public static final int MODULE_XWIKI_RENDERING = 4;
+    public static final int MODULE_XWIKI_PLUGINS = 5;
+    public static final int MODULE_XWIKI_PERLPLUGINS = 6;
+    public static final int MODULE_XWIKI_CLASSES = 7;
+    public static final int MODULE_XWIKI_USER = 8;
+    public static final int MODULE_XWIKI_ACCESS = 9;
+    public static final int MODULE_XWIKI_EMAIL = 10;
+    public static final int MODULE_XWIKI_APP = 11;
+    public static final int MODULE_XWIKI_EXPORT = 12;
+    public static final int MODULE_XWIKI_DIFF = 13;
+    public static final int MODULE_XWIKI_GROOVY = 14;
+    public static final int MODULE_XWIKI_NOTIFICATION = 15;
+    public static final int MODULE_XWIKI_CACHE = 16;
+
+    public static final int MODULE_PLUGIN_LASZLO = 21;
+
+    // Error list
+    public static final int ERROR_XWIKI_UNKNOWN = 0;
+    public static final int ERROR_XWIKI_NOT_IMPLEMENTED = 1;
+    public static final int ERROR_XWIKI_DOES_NOT_EXIST = 2;
+    public static final int ERROR_XWIKI_INIT_FAILED = 3;
+    public static final int ERROR_XWIKI_MKDIR = 4;
+
+    // Config
+    public static final int ERROR_XWIKI_CONFIG_FILENOTFOUND = 1001;
+    public static final int ERROR_XWIKI_CONFIG_FORMATERROR = 1002;
+
+    // Doc
+    public static final int ERROR_XWIKI_DOC_EXPORT = 2001;
+    public static final int ERROR_DOC_XML_PARSING = 2002;
+    public static final int ERROR_DOC_RCS_PARSING = 2003;
+
+    // Store
+    public static final int ERROR_XWIKI_STORE_CLASSINVOCATIONERROR = 3001;
+    public static final int ERROR_XWIKI_STORE_FILENOTFOUND = 3002;
+    public static final int ERROR_XWIKI_STORE_ARCHIVEFORMAT = 3003;
+    public static final int ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT = 3004;
+
+    public static final int ERROR_XWIKI_STORE_RCS_SAVING_FILE = 3101;
+    public static final int ERROR_XWIKI_STORE_RCS_READING_FILE = 3102;
+    public static final int ERROR_XWIKI_STORE_RCS_DELETING_FILE = 3103;
+    public static final int ERROR_XWIKI_STORE_RCS_READING_REVISIONS = 3103;
+    public static final int ERROR_XWIKI_STORE_RCS_READING_VERSION = 3104;
+    public static final int ERROR_XWIKI_STORE_RCS_SEARCH = 3111;
+    public static final int ERROR_XWIKI_STORE_RCS_LOADING_ATTACHMENT = 3221;
+    public static final int ERROR_XWIKI_STORE_RCS_SAVING_ATTACHMENT = 3222;
+    public static final int ERROR_XWIKI_STORE_RCS_SEARCHING_ATTACHMENT = 3223;
+    public static final int ERROR_XWIKI_STORE_RCS_DELETING_ATTACHMENT = 3224;
+
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_DOC = 3201;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_DOC = 3202;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_DOC = 3203;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_CANNOT_DELETE_UNLOADED_DOC = 3204;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_REVISIONS = 3203;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_READING_VERSION = 3204;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_UNEXISTANT_VERSION = 3205;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_OBJECT = 3211;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT = 3212;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_OBJECT = 3213;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_CLASS = 3221;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_CLASS = 3222;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SEARCH = 3223;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT = 3231;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT = 3232;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_ATTACHMENT = 3233;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT_LIST = 3234;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SEARCHING_ATTACHMENT = 3235;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_CHECK_EXISTS_DOC = 3236;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SWITCH_DATABASE = 3301;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_CREATE_DATABASE = 3401;
+
+    public static final int ERROR_XWIKI_STORE_JCR_SAVING_DOC = 3501;
+    public static final int ERROR_XWIKI_STORE_JCR_READING_DOC = 3502;
+    public static final int ERROR_XWIKI_STORE_JCR_DELETING_DOC = 3503;
+    public static final int ERROR_XWIKI_STORE_JCR_CANNOT_DELETE_UNLOADED_DOC = 3504;
+    public static final int ERROR_XWIKI_STORE_JCR_READING_REVISIONS = 3503;
+    public static final int ERROR_XWIKI_STORE_JCR_READING_VERSION = 3504;
+    public static final int ERROR_XWIKI_STORE_JCR_UNEXISTANT_VERSION = 3505;
+    public static final int ERROR_XWIKI_STORE_JCR_SAVING_OBJECT = 3511;
+    public static final int ERROR_XWIKI_STORE_JCR_LOADING_OBJECT = 3512;
+    public static final int ERROR_XWIKI_STORE_JCR_DELETING_OBJECT = 3513;
+    public static final int ERROR_XWIKI_STORE_JCR_SAVING_CLASS = 3521;
+    public static final int ERROR_XWIKI_STORE_JCR_LOADING_CLASS = 3522;
+    public static final int ERROR_XWIKI_STORE_JCR_SEARCH = 3523;
+    public static final int ERROR_XWIKI_STORE_JCR_LOADING_ATTACHMENT = 3531;
+    public static final int ERROR_XWIKI_STORE_JCR_SAVING_ATTACHMENT = 3532;
+    public static final int ERROR_XWIKI_STORE_JCR_DELETING_ATTACHMENT = 3533;
+    public static final int ERROR_XWIKI_STORE_JCR_SAVING_ATTACHMENT_LIST = 3534;
+    public static final int ERROR_XWIKI_STORE_JCR_SEARCHING_ATTACHMENT = 3535;
+    public static final int ERROR_XWIKI_STORE_JCR_CHECK_EXISTS_DOC = 3536;
+    public static final int ERROR_XWIKI_STORE_JCR_SWITCH_DATABASE = 3601;
+    public static final int ERROR_XWIKI_STORE_JCR_CREATE_DATABASE = 3701;
+    
+    public static final int ERROR_XWIKI_RENDERING_VELOCITY_EXCEPTION = 4001;
+    public static final int ERROR_XWIKI_RENDERING_GROOVY_EXCEPTION = 4002;
+
+    public static final int ERROR_XWIKI_PERLPLUGIN_START_EXCEPTION = 6001;
+    public static final int ERROR_XWIKI_PERLPLUGIN_START = 6002;
+    public static final int ERROR_XWIKI_PERLPLUGIN_PERLSERVER_EXCEPTION = 6003;
+
+    public static final int ERROR_XWIKI_CLASSES_FIELD_DOES_NOT_EXIST = 7001;
+    public static final int ERROR_XWIKI_CLASSES_FIELD_INVALID = 7002;
+    public static final int ERROR_XWIKI_CLASSES_DIFF = 7003;
+    public static final int ERROR_XWIKI_CLASSES_CUSTOMCLASSINVOCATIONERROR = 7004;
+    public static final int ERROR_XWIKI_CLASSES_PROPERTY_CLASS_INSTANCIATION = 7005;
+    public static final int ERROR_XWIKI_CLASSES_PROPERTY_CLASS_IN_METACLASS = 7006;
+    public static final int ERROR_XWIKI_CLASSES_CANNOT_PREPARE_CUSTOM_DISPLAY = 7007;
+
+
+    public static final int ERROR_XWIKI_USER_INIT = 8001;
+    public static final int ERROR_XWIKI_USER_CREATE = 8002;
+    public static final int ERROR_XWIKI_USER_INACTIVE = 8003;
+
+    public static final int ERROR_XWIKI_ACCESS_DENIED = 9001;
+    public static final int ERROR_XWIKI_ACCESS_TOKEN_INVALID = 9002;
+    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_USERS = 9003;
+    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_GROUPS = 9004;
+    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_ADDING_USERS = 9005;
+    public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_LISTING_USERS = 9006;
+
+    public static final int ERROR_XWIKI_EMAIL_CANNOT_GET_VALIDATION_CONFIG = 10001;
+    public static final int ERROR_XWIKI_EMAIL_CANNOT_PREPARE_VALIDATION_EMAIL = 10002;
+    public static final int ERROR_XWIKI_EMAIL_ERROR_SENDING_EMAIL = 10003;
+    public static final int ERROR_XWIKI_EMAIL_CONNECT_FAILED = 10004;
+    public static final int ERROR_XWIKI_EMAIL_LOGIN_FAILED = 10005;
+    public static final int ERROR_XWIKI_EMAIL_SEND_FAILED = 10006;
+
+    public static final int ERROR_XWIKI_APP_TEMPLATE_DOES_NOT_EXIST = 11001;
+    public static final int ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY = 11002;
+    public static final int ERROR_XWIKI_APP_ATTACHMENT_NOT_FOUND = 11003;
+    public static final int ERROR_XWIKI_APP_CREATE_USER = 11004;
+    public static final int ERROR_XWIKI_APP_VALIDATE_USER = 11005;
+    public static final int ERROR_XWIKI_APP_INVALID_CHARS = 11006;
+    public static final int ERROR_XWIKI_APP_URL_EXCEPTION = 11007;
+    public static final int ERROR_XWIKI_APP_UPLOAD_PARSE_EXCEPTION = 11008;
+    public static final int ERROR_XWIKI_APP_UPLOAD_FILE_EXCEPTION = 11009;
+    public static final int ERROR_XWIKI_APP_REDIRECT_EXCEPTION = 11010;
+    public static final int ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION = 11011;
+    public static final int ERROR_XWIKI_APP_SERVICE_NOT_FOUND = 11012;
+    public static final int ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE = 11013;
+    public static final int ERROR_XWIKI_APP_JAVA_HEAP_SPACE = 11014;
+    
+    public static final int ERROR_XWIKI_EXPORT_XSL_FILE_NOT_FOUND = 12001;
+    public static final int ERROR_XWIKI_EXPORT_PDF_FOP_FAILED = 12002;
+    public static final int ERROR_XWIKI_EXPORT_XSL_FAILED = 12003;
+    public static final int ERROR_XWIKI_DIFF_CONTENT_ERROR = 13001;
+    public static final int ERROR_XWIKI_DIFF_RENDERED_ERROR = 13002;
+    public static final int ERROR_XWIKI_DIFF_METADATA_ERROR = 13003;
+    public static final int ERROR_XWIKI_DIFF_CLASS_ERROR = 13004;
+    public static final int ERROR_XWIKI_DIFF_OBJECT_ERROR = 13005;
+    public static final int ERROR_XWIKI_DIFF_XML_ERROR = 13005;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_LOCK = 13006;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_LOCK = 13007;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_LOCK = 13008;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_INVALID_MAPPING = 13009;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_MAPPING_INJECTION_FAILED = 13010;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_LINKS = 13011;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_SAVING_LINKS = 13012;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_DELETING_LINKS = 13013;
+    public static final int ERROR_XWIKI_STORE_HIBERNATE_LOADING_BACKLINKS = 13014;
+
+    public static final int ERROR_XWIKI_STORE_JCR_SAVING_LOCK = 13106;
+    public static final int ERROR_XWIKI_STORE_JCR_LOADING_LOCK = 13107;
+    public static final int ERROR_XWIKI_STORE_JCR_DELETING_LOCK = 13108;
+    public static final int ERROR_XWIKI_STORE_JCR_INVALID_MAPPING = 13109;
+    public static final int ERROR_XWIKI_STORE_JCR_MAPPING_INJECTION_FAILED = 13110;
+    public static final int ERROR_XWIKI_STORE_JCR_LOADING_LINKS = 13111;
+    public static final int ERROR_XWIKI_STORE_JCR_SAVING_LINKS = 13112;
+    public static final int ERROR_XWIKI_STORE_JCR_DELETING_LINKS = 13113;
+    public static final int ERROR_XWIKI_STORE_JCR_LOADING_BACKLINKS = 13114;
+    public static final int ERROR_XWIKI_STORE_JCR_OTHER = 13130; // temporary
+
+    public static final int ERROR_XWIKI_STORE_SEARCH_NOTIMPL = 13200;
+
+    public static final int ERROR_XWIKI_GROOVY_COMPILE_FAILED = 14001;
+    public static final int ERROR_XWIKI_GROOVY_EXECUTION_FAILED = 14002;
+
+    public static final int ERROR_XWIKI_NOTIFICATION = 15001;
+
+    public static final int ERROR_CACHE_INITIALIZING = 16001;
+
+    public static final int ERROR_LASZLO_INVALID_XML = 21001;
+    public static final int ERROR_LASZLO_INVALID_DOTDOT = 21002;
+
+
+    public XWikiException(int module, int code, String message, Throwable e, Object[] args) {
+        setModule(module);
+        setCode(code);
+        setException(e);
+        setArgs(args);
+        setMessage(message);
+        if (log.isTraceEnabled())
+            log.trace(getMessage(), e);
+    }
+
+    public XWikiException(int module, int code, String message, Throwable e) {
+        this(module, code, message, e, null);
+    }
+
+    public XWikiException(int module, int code, String message) {
+        this(module, code, message, null, null);
+    }
+
+    public XWikiException() {
+    }
+
+    public int getModule() {
+        return module;
+    }
+
+    public String getModuleName() {
+        return "" + module;
+    }
+
+    public void setModule(int module) {
+        this.module = module;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    public Throwable getException() {
+        return exception;
+    }
+
+    public void setException(Throwable exception) {
+        this.exception = exception;
+    }
+
+    public Object[] getArgs() {
+        return args;
+    }
+
+    public void setArgs(Object[] args) {
+        this.args = args;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public String getMessage() {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("Error number ");
+        buffer.append(getCode());
+        buffer.append(" in ");
+        buffer.append(getModuleName());
+        buffer.append(": ");
+
+        if (message != null) {
+            if (args == null)
+                buffer.append(message);
+            else {
+                MessageFormat msgFormat = new MessageFormat(message);
+                try {
+                    buffer.append(msgFormat.format(args));
+                }
+                catch (Exception e) {
+                    buffer.append("Cannot format message " + message + " with args ");
+                    for (int i = 0; i < args.length; i++) {
+                        if (i != 0)
+                            buffer.append(",");
+                        buffer.append(args[i]);
+                    }
+                }
+            }
+        }
+
+        if (exception != null) {
+            buffer.append("\nWrapped Exception: ");
+            buffer.append(exception.getMessage());
+        }
+        return buffer.toString();
+    }
+
+    public String getFullMessage() {
+        StringBuffer buffer = new StringBuffer(getMessage());
+        buffer.append("\n");
+        buffer.append(getStackTraceAsString());
+        buffer.append("\n");
+        /*
+        List list = XWikiBatcher.getSQLStats().getRecentSqlList();
+        if (list.size() > 0) {
+            buffer.append("Recent SQL:\n");
+            for (int i = 0; i < list.size(); i++) {
+                buffer.append(list.get(i));
+                buffer.append("\n");
+            }
+        }
+        */
+        return buffer.toString();
+    }
+
+    public void printStackTrace(PrintWriter s) {
+        super.printStackTrace(s);
+        if (exception != null) {
+            s.write("\n\nWrapped Exception:\n\n");
+            if (exception.getCause()!=null)
+                exception.getCause().printStackTrace(s);
+            else if (exception instanceof org.hibernate.JDBCException) {
+                (((JDBCException) exception).getSQLException()).printStackTrace(s);
+            } else if (exception instanceof MethodInvocationException) {
+                (((MethodInvocationException) exception).getWrappedThrowable()).printStackTrace(s);
+            } else if (exception instanceof ServletException) {
+                (((ServletException) exception).getRootCause()).printStackTrace(s);
+            } else {
+                exception.printStackTrace(s);
+            }
+        }
+    }
+
+    public void printStackTrace(PrintStream s) {
+        super.printStackTrace(s);
+        if (exception != null) {
+            s.print("\n\nWrapped Exception:\n\n");
+            if (exception.getCause()!=null)
+                exception.getCause().printStackTrace(s);
+            else if (exception instanceof org.hibernate.JDBCException) {
+                (((JDBCException) exception).getSQLException()).printStackTrace(s);
+            } else if (exception instanceof MethodInvocationException) {
+                (((MethodInvocationException) exception).getWrappedThrowable()).printStackTrace(s);
+            } else if (exception instanceof ServletException) {
+                (((ServletException) exception).getRootCause()).printStackTrace(s);
+            } else {
+                exception.printStackTrace(s);
+            }
+        }
+    }
+
+    public String getStackTraceAsString() {
+        StringWriter swriter = new StringWriter();
+        PrintWriter pwriter = new PrintWriter(swriter);
+        printStackTrace(pwriter);
+        pwriter.flush();
+        return swriter.getBuffer().toString();
+    }
+
+    public String getStackTraceAsString(Throwable e) {
+        StringWriter swriter = new StringWriter();
+        PrintWriter pwriter = new PrintWriter(swriter);
+        e.printStackTrace(pwriter);
+        pwriter.flush();
+        return swriter.getBuffer().toString();
+    }
 }
\ No newline at end of file

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -44,6 +44,7 @@
 import com.xpn.xwiki.util.Util;
 import com.xpn.xwiki.web.EditForm;
 import com.xpn.xwiki.web.ObjectAddForm;
+import com.xpn.xwiki.web.XWikiMessageTool;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -70,6 +71,9 @@
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.lang.ref.SoftReference;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -2758,4 +2762,21 @@
         }
         return this.hashCode() + "";
     }
+
+    public static String getInternalPropertyName(String propname, XWikiContext context) {
+        XWikiMessageTool msg = ((XWikiMessageTool)context.get("msg"));
+        String cpropname = StringUtils.capitalize(propname);
+        return (msg==null) ? cpropname : msg.get(cpropname);
+    }
+
+    public String getInternalProperty(String propname) {
+        String methodName = "get" + StringUtils.capitalize(propname);
+        try {
+            Method method = getClass().getDeclaredMethod(methodName, null);
+            return (String) method.invoke(this, null);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/BaseClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/BaseClass.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/BaseClass.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -32,6 +32,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 import org.dom4j.Element;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
@@ -40,6 +41,7 @@
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.plugin.query.XWikiCriteria;
 import com.xpn.xwiki.objects.BaseCollection;
 import com.xpn.xwiki.objects.BaseObject;
 import com.xpn.xwiki.objects.BaseProperty;
@@ -572,4 +574,18 @@
     public void setNameField(String nameField) {
         this.nameField = nameField;
     }
+
+    public String makeQuery(XWikiCriteria query) {
+        List criteriaList = new ArrayList();
+        Iterator classit = getFieldList().iterator();
+        while (classit.hasNext()) {
+            PropertyClass property = (PropertyClass) classit.next();
+            String name = property.getName();
+            Map map = query.getParameters(getName() + "_" + name);
+            if (map.size()>0) {
+              property.makeQuery(map, "", query, criteriaList);
+            }
+        }
+        return StringUtils.join(criteriaList.toArray(), " and ");
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/BooleanClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/BooleanClass.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/BooleanClass.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -179,4 +179,74 @@
 		}
 	}
 
+    public void displaySelectSearch(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
+        select select = new select(prefix + name, 1);
+        select.setMultiple(true);
+        String String0 = getDisplayValue(context, 0);
+        String String1 = getDisplayValue(context, 1);
+
+        option[] options = { new option("---", "" ), new option(String1, "1" ), new option(String0, "0")};
+        options[0].addElement("---");
+        options[1].addElement(String1);
+        options[2].addElement(String0);
+
+        /*
+        try {
+        IntegerProperty prop = (IntegerProperty) object.safeget(name);
+        if (prop!=null) {
+            Integer ivalue = (Integer)prop.getValue();
+            if (ivalue!=null) {
+                int value = ivalue.intValue();
+                if (value==1)
+                    options[1].setSelected(true);
+                else if (value==0)
+                    options[2].setSelected(true);
+            }  else {
+                int value = getDefaultValue();
+                if (value==1)
+                    options[1].setSelected(true);
+                else if (value==0)
+                    options[2].setSelected(true);
+            }
+	        }
+        } catch (Exception e) {
+            // This should not happen
+            e.printStackTrace();
+        }
+        */
+        select.addElement(options);
+        buffer.append(select.toString());
+    }
+
+    public void displayCheckboxSearch(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
+        org.apache.ecs.xhtml.input check = new input(input.checkbox, prefix + name, 1);
+        org.apache.ecs.xhtml.input checkNo = new input(input.hidden, prefix + name, 0);
+
+        /*
+        try {
+        IntegerProperty prop = (IntegerProperty) object.safeget(name);
+        if (prop!=null) {
+            Integer ivalue = (Integer)prop.getValue();
+            if (ivalue!=null) {
+                int value = ivalue.intValue();
+                if (value==1)
+                    check.setChecked(true);
+                else if (value==0)
+                	check.setChecked(false);
+            }
+            else {
+                int value = getDefaultValue();
+                if (value==1)
+                    check.setChecked(true);
+                else
+                    check.setChecked(false);
+            }
+        }} catch (Exception e) {
+            // This should not happen
+            e.printStackTrace();
+        }
+        */
+        buffer.append(check.toString());
+        buffer.append(checkNo.toString());
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/DateClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/DateClass.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/DateClass.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -32,6 +32,7 @@
 import org.dom4j.Element;
 
 import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.web.XWikiMessageTool;
 import com.xpn.xwiki.objects.BaseCollection;
 import com.xpn.xwiki.objects.BaseProperty;
 import com.xpn.xwiki.objects.DateProperty;
@@ -144,4 +145,24 @@
         input.setSize(getSize());
         buffer.append(input.toString());
     }
+
+    public void displaySearch(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
+        input input1 = new input();
+        input1.setType("text");
+        input1.setName(prefix + name + "_from");
+        input1.setID(prefix + name);
+        input1.setSize(getSize());
+
+        input input2 = new input();
+
+        input2.setType("text");
+        input2.setName(prefix + name+ "_to");
+        input2.setID(prefix + name);
+        input2.setSize(getSize());
+
+        buffer.append(((XWikiMessageTool)context.get("msg")).get("from"));
+        buffer.append(input1.toString());
+        buffer.append(((XWikiMessageTool)context.get("msg")).get("to"));
+        buffer.append(input2.toString());
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/ListClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/ListClass.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/ListClass.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -24,10 +24,7 @@
 
 package com.xpn.xwiki.objects.classes;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.ecs.xhtml.input;
@@ -36,6 +33,7 @@
 import org.dom4j.Element;
 
 import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.plugin.query.XWikiCriteria;
 import com.xpn.xwiki.objects.BaseCollection;
 import com.xpn.xwiki.objects.BaseProperty;
 import com.xpn.xwiki.objects.DBStringListProperty;
@@ -289,4 +287,92 @@
 			return value;
 		}
 	}
+
+    protected void displayRadioSearch(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context){
+        List list = getList(context);
+        List selectlist = new ArrayList();
+
+        /*
+        BaseProperty prop =  (BaseProperty)object.safeget(name);
+        if (prop==null) {
+            selectlist = new ArrayList();
+        } else if ((prop instanceof ListProperty)||(prop instanceof DBStringListProperty)) {
+            selectlist = (List) prop.getValue();
+        } else {
+            selectlist = new ArrayList();
+            selectlist.add(prop.getValue());
+        }
+        */
+
+        // Add options from Set
+        for (Iterator it=list.iterator();it.hasNext();) {
+            String value = it.next().toString();
+            input radio = new input(input.radio, prefix + name, value);
+
+            if (selectlist.contains(value))
+                radio.setChecked(true);
+            radio.addElement(value);
+            buffer.append(radio.toString());
+            if(it.hasNext()){
+            	buffer.append("<br/>");
+            }
+        }
+    }
+
+    protected void displaySelectSearch(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context){
+        select select = new select(prefix + name, 1);
+        select.setMultiple(true);
+        select.setSize(getSize());
+        select.setName(prefix + name);
+        select.setID(prefix + name);
+
+        List list = getList(context);
+        List selectlist = new ArrayList();
+
+        /*
+        BaseProperty prop =  (BaseProperty)object.safeget(name);
+        if (prop==null) {
+            selectlist = new ArrayList();
+        } else if ((prop instanceof ListProperty)||(prop instanceof DBStringListProperty)) {
+            selectlist = (List) prop.getValue();
+        } else {
+            selectlist = new ArrayList();
+            selectlist.add(prop.getValue());
+        }
+        */
+
+        // Add options from Set
+        for (Iterator it=list.iterator();it.hasNext();) {
+            String value = it.next().toString();
+            option option = new option(value, value);
+            option.addElement(value);
+            if (selectlist.contains(value))
+                option.setSelected(true);
+            select.addElement(option);
+        }
+
+        buffer.append(select.toString());
+    }
+    
+    public void makeQuery(Map map, String prefix, XWikiCriteria query, List criteriaList) {
+        Object values = map.get(prefix);
+        if ((values==null)||(values.equals(""))) {
+            return;
+        }
+
+        if (values instanceof String) {
+            criteriaList.add("jcr:contains(@f:" + getName() + ",'" + values.toString() + "')");
+            // testQueryGenerator(query, "//*/*/obj/Test/TestClass[jcr:contains(@f:category, '1') or jcr:contains(@f:category, '2')]");
+        }
+        else {
+            String[] valuesarray = (String[])values;
+            String[] criteriaarray = new String[valuesarray.length];
+            for (int i=0;i<valuesarray.length;i++) {
+                criteriaarray[i] = "jcr:contains(@f:" + getName() + ",'" + valuesarray[i] + "')";
+            }
+            criteriaList.add("(" + StringUtils.join(criteriaarray, " or ") + ")");
+        }
+        return;
+    }
+
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/NumberClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/NumberClass.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/NumberClass.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -26,6 +26,8 @@
 import org.apache.ecs.xhtml.input;
 
 import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.web.XWikiMessageTool;
+import com.xpn.xwiki.plugin.query.XWikiCriteria;
 import com.xpn.xwiki.objects.BaseCollection;
 import com.xpn.xwiki.objects.BaseProperty;
 import com.xpn.xwiki.objects.DoubleProperty;
@@ -34,6 +36,9 @@
 import com.xpn.xwiki.objects.LongProperty;
 import com.xpn.xwiki.objects.meta.PropertyMetaClass;
 
+import java.util.Map;
+import java.util.List;
+
 public class NumberClass  extends PropertyClass {
 
     public NumberClass(PropertyMetaClass wclass) {
@@ -112,4 +117,45 @@
         input.setSize(getSize());
         buffer.append(input.toString());
     }
+
+    public void displaySearch(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
+        input input1 = new input();
+        input1.setType("text");
+        input1.setName(prefix + name + "_from");
+        input1.setID(prefix + name);
+        input1.setSize(getSize());
+
+        input input2 = new input();
+
+        input2.setType("text");
+        input2.setName(prefix + name+ "_to");
+        input2.setID(prefix + name);
+        input2.setSize(getSize());
+
+        buffer.append(((XWikiMessageTool)context.get("msg")).get("from"));
+        buffer.append(input1.toString());
+        buffer.append(((XWikiMessageTool)context.get("msg")).get("to"));
+        buffer.append(input2.toString());
+    }
+    
+    public void makeQuery(Map map, String prefix, XWikiCriteria query, List criteriaList) {
+        Number value = (Number)map.get(prefix);
+        if ((value!=null)&&(!value.equals(""))) {
+         criteriaList.add("@f:" + getName() + "=" + value.toString());
+         return;
+        }
+
+        value = (Number)map.get(prefix + "lessthan");
+        if ((value!=null)&&(!value.equals(""))) {
+         criteriaList.add("@f:" + getName() + "<" + value.toString());
+         return;
+        }
+
+        value = (Number)map.get(prefix + "morethan");
+        if ((value!=null)&&(!value.equals(""))) {
+         criteriaList.add("@f:" + getName() + ">" + value.toString());
+         return;
+        }
+    }
+
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/PropertyClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/PropertyClass.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/PropertyClass.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -25,6 +25,7 @@
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.ecs.xhtml.input;
 import org.apache.velocity.VelocityContext;
@@ -34,7 +35,7 @@
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.api.Context;
+import com.xpn.xwiki.plugin.query.XWikiCriteria;
 import com.xpn.xwiki.objects.BaseCollection;
 import com.xpn.xwiki.objects.BaseProperty;
 import com.xpn.xwiki.objects.PropertyInterface;
@@ -347,4 +348,7 @@
     public BaseProperty newProperty() {
         return new BaseProperty();
     }
+
+    public void makeQuery(Map map, String prefix, XWikiCriteria query, List criteriaList) {
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/StringClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/StringClass.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/StringClass.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -26,11 +26,16 @@
 import org.apache.ecs.xhtml.input;
 
 import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.plugin.query.XWikiCriteria;
 import com.xpn.xwiki.objects.BaseCollection;
 import com.xpn.xwiki.objects.BaseProperty;
 import com.xpn.xwiki.objects.StringProperty;
 import com.xpn.xwiki.objects.meta.PropertyMetaClass;
 
+import java.util.Map;
+import java.util.List;
+import java.util.Iterator;
+
 public class StringClass extends PropertyClass {
 
     public StringClass(String name, String prettyname, PropertyMetaClass wclass) {
@@ -77,4 +82,33 @@
         input.setSize(getSize());
         buffer.append(input.toString());
     }
+
+    public void displaySearch(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
+        input input = new input();
+        input.setType("text");
+        input.setName(prefix + name);
+        input.setID(prefix + name);
+        input.setSize(getSize());
+        buffer.append(input.toString());
+    }
+    
+    public void makeQuery(Map map, String prefix, XWikiCriteria query, List criteriaList) {
+        String value = (String)map.get(prefix);
+        if ((value!=null)&&(!value.equals(""))) {
+         criteriaList.add("jcr:like(@f:" + getName() + ", '%" + value + "%')");
+         return;
+        }
+
+        value = (String)map.get(prefix + "exact");
+        if ((value!=null)&&(!value.equals(""))) {
+         criteriaList.add("@f:" + getName() + "='" + value + "'");
+         return;
+        }
+
+        value = (String)map.get(prefix + "not");
+        if ((value!=null)&&(!value.equals(""))) {
+         criteriaList.add("@f:" + getName() + "!='" + value + "'");
+         return;
+        }
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/IQueryFactory.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/IQueryFactory.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/IQueryFactory.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -29,49 +29,58 @@
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.store.XWikiStoreInterface;
 
+import java.util.List;
+
 /** AbstractFactory interface for XWiki Queries */
 public interface IQueryFactory {
-	/** create xpath query 
-	 * @throws XWikiException */
-	IQuery xpath(String q) throws XWikiException;
-	
-	/** create JCRSQL query 
-	 * unsupported for now */
-	IQuery ql(String q) throws XWikiException;
-	
-	/** create query for docs 
-	 * @param docname - full document name (web/name | web.name). name may consist xpath []-selection. if any (name|web) - *
-	 * @param prop - return properties, separated by comma, property start with @, if null - return document
-	 * @param order - properties for sort, separated by ','; order: ascending/descending after prop. name, or +/- before. if null - not sort 
-	 * @throws InvalidQueryException 
-	 * */
-	IQuery getDocs(String docname, String prop, String order) throws XWikiException;
-	
-	/** create query for child documents
-	 * @throws InvalidQueryException
-	 * @param web,docname must be without templates & [] select    
-	 * @see getDocs */
-	IQuery getChildDocs(String docname, String prop, String order) throws XWikiException;
-	
-	/** create query for attachments
-	 * @param attachname - name of attachment, may be *, *[] 
-	 * @see getDocs
-	 * @throws InvalidQueryException
-	 */
-	IQuery getAttachment(String docname, String attachname, String order) throws XWikiException;
-	
-	/** create query for objects
-	 * @param oclass - full name of object class (web/name | web.name).  if any(name|web) - *
-	 * @param prop. for flex-attributes use @f:flexname 
-	 * @see getDocs
-	 * @throws InvalidQueryException
-	 */
-	IQuery getObjects(String docname, String oclass, String prop, String order) throws XWikiException;
-	
-	/** Returns ValueFactory for creating correct jcr values
-	 * @return javax.jcr.ValueFactory */
-	ValueFactory getValueFactory();
-	
-	XWikiContext getContext();
-	XWikiStoreInterface getStore();
+    /** create xpath query
+     * @throws XWikiException */
+    IQuery xpath(String q) throws XWikiException;
+
+    /** create JCRSQL query
+     * unsupported for now */
+    IQuery ql(String q) throws XWikiException;
+
+    /** create query for docs
+     * @param docname - full document name (web/name | web.name). name may consist xpath []-selection. if any (name|web) - *
+     * @param prop - return properties, separated by comma, property start with @, if null - return document
+     * @param order - properties for sort, separated by ','; order: ascending/descending after prop. name, or +/- before. if null - not sort
+     * @throws InvalidQueryException
+     * */
+    IQuery getDocs(String docname, String prop, String order) throws XWikiException;
+
+    /** create query for child documents
+     * @throws InvalidQueryException
+     * @param web,docname must be without templates & [] select
+     * @see getDocs */
+    IQuery getChildDocs(String docname, String prop, String order) throws XWikiException;
+
+    /** create query for attachments
+     * @param attachname - name of attachment, may be *, *[]
+     * @see getDocs
+     * @throws InvalidQueryException
+     */
+    IQuery getAttachment(String docname, String attachname, String order) throws XWikiException;
+
+    /** create query for objects
+     * @param oclass - full name of object class (web/name | web.name).  if any(name|web) - *
+     * @param prop. for flex-attributes use @f:flexname
+     * @see getDocs
+     * @throws InvalidQueryException
+     */
+    IQuery getObjects(String docname, String oclass, String prop, String order) throws XWikiException;
+
+    /** Returns ValueFactory for creating correct jcr values
+     * @return javax.jcr.ValueFactory */
+    ValueFactory getValueFactory();
+
+    XWikiContext getContext();
+    XWikiStoreInterface getStore();
+
+    /**
+     * Generates an XPath query from a XWikiQuery Object
+     * @param query
+     * @return query xpath string
+     */
+    String makeQuery(XWikiQuery query) throws XWikiException;
 }

Added: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/OrderClause.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/OrderClause.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/OrderClause.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -0,0 +1,37 @@
+package com.xpn.xwiki.plugin.query;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ldubost
+ * Date: 7 sept. 2006
+ * Time: 20:20:29
+ * To change this template use File | Settings | File Templates.
+ */
+public class OrderClause extends Object {
+    public final static int ASC = 1;
+    public final static int DESC = 2;
+
+    private String property;
+    private int order;
+
+    public OrderClause(String property, int ascdesc) {
+        setProperty(property);
+        setOrder(ascdesc);
+    }
+
+    public String getProperty() {
+        return property;
+    }
+
+    public void setProperty(String property) {
+        this.property = property;
+    }
+
+    public int getOrder() {
+        return order;
+    }
+
+    public void setOrder(int order) {
+        this.order = order;
+    }
+}

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/QueryPlugin.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/QueryPlugin.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/QueryPlugin.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -35,189 +35,227 @@
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.objects.classes.BaseClass;
 import com.xpn.xwiki.api.Api;
 import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
 import com.xpn.xwiki.plugin.XWikiPluginInterface;
 import com.xpn.xwiki.store.XWikiStoreInterface;
 import com.xpn.xwiki.store.jcr.XWikiJcrStore;
 
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+
 /** Plugin for Query API */
 public class QueryPlugin extends XWikiDefaultPlugin implements IQueryFactory {
-	private static final Log log = LogFactory.getLog(QueryPlugin.class);
-	XWikiContext	context;
-	public QueryPlugin(String name, String className, XWikiContext context) throws XWikiException {
+    private static final Log log = LogFactory.getLog(QueryPlugin.class);
+    XWikiContext	context;
+    public QueryPlugin(String name, String className, XWikiContext context) throws XWikiException {
         super(name, className, context);
         this.context = context;
     }
-	
-	public String getName() { return "query"; }
-	
-	QueryPluginApi queryApi;
-	public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
-		if (queryApi == null)
-			queryApi = new QueryPluginApi(this);
-		return queryApi;
-	}
-	
-	public XWikiContext getContext() {
-		return context;
-	}
-	public XWikiStoreInterface getStore() {
-		return getContext().getWiki().getStore();
-	}
-	
-	ValueFactory valueFactory = null;;
-	public ValueFactory getValueFactory() {
-		if (valueFactory==null) {
-			valueFactory = new ValueFactoryImpl();
-		}
-		return valueFactory;
-	}
-	
-	boolean isHibernate() {
-		return getContext().getWiki().getHibernateStore() != null; 
-	}
-	boolean isJcr() {
-		return getContext().getWiki().getNotCacheStore() instanceof XWikiJcrStore;
-	}
-	
-	/** Translate query string to query tree */
-	protected QueryRootNode parse(String query, String language) throws InvalidQueryException {
-		if (query==null) return null;
-		final QueryRootNode qn = QueryParser.parse(query, language, XWikiNamespaceResolver.getInstance());			
-		return qn;		
-	}
-	/** create xpath query 
-	 * @throws XWikiException */
-	public IQuery xpath(String q) throws XWikiException {
-		if (log.isDebugEnabled())
-			log.debug("create xpath query: "+q);
-		if (isHibernate())
-			try {
-				return new HibernateQuery( parse(q, Query.XPATH), this);
-			} catch (InvalidQueryException e) {
-				throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, "Invalid xpath query: " + q);
-			}
-		if (isJcr())
-			return new JcrQuery( q, Query.XPATH, this );
-		return null;
-	}
-	/** create JCRSQL query 
-	 * unsupported for now 
-	 * @throws XWikiException */
-	public IQuery ql(String q) throws XWikiException {
-		if (log.isDebugEnabled())
-			log.debug("create JCRSQL query: "+q);
-		if (isHibernate())
-			try {
-				return new HibernateQuery( parse(q, Query.SQL), this);
-			} catch (InvalidQueryException e) {
-				throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, "Invalid jcrsql query: " + q);
-			}
-		if (isJcr())
-			return new JcrQuery( q, Query.SQL, this );
-		return null;
-	}
-	/** create query for docs 
-	 * @param web, docname - document.web & .name. it may consist xpath []-selection. if any - *
-	 * @param prop - return property, start with @, if null - return document
-	 * @param order - properties for sort, separated by ','; order: ascending/descending after prop. name, or +/- before. if null - not sort 
-	 * @throws XWikiException 
-	 * */
-	public IQuery getDocs(String docname, String prop, String order) throws XWikiException {
-		return xpath("/"+getXPathName(docname) + getPropertyXPath(prop) + getOrderXPath(order));
-	}
-	/** create query for child documents
-	 * @param web,docname must be without templates & [] select    
-	 * @throws XWikiException 
-	 * @see getDocs */
-	public IQuery getChildDocs(String docname, String prop, String order) throws XWikiException {
-		return xpath("/*/*[@parent='"+getXWikiName(docname)+"']"+ getPropertyXPath(prop) + getOrderXPath(order));
-	}
-	/** create query for attachments
-	 * @param attachname - name of attachment, may be *, *[] 
-	 * @throws XWikiException 
-	 * @see getDocs
-	 */
-	public IQuery getAttachment(String docname, String attachname, String order) throws XWikiException {
-		return xpath("/"+getXPathName(docname)+"/attach/" + attachname + getOrderXPath(order));
-	}
-	/** create query for objects
-	 * @param oweb, oclass - object web & class. if any - *
-	 * @param prop. for flex-attributes use f:flexname 
-	 * @throws XWikiException 
-	 * @see getDocs
-	 */
-	public IQuery getObjects(String docname, String oclass, String prop, String order) throws XWikiException {
-		return xpath("/"+getXPathName(docname)+"/obj/"+getXPathName(oclass) + getPropertyXPath(prop) + getOrderXPath(order));
-	}
-	
-	protected String getXWikiName(String name) {
-		int is = name.indexOf('['),
-		ip = name.indexOf('/');
-		if (is<0 || ip < is)
-			return name.replace('/', '.');
-		return name;
-	}
-	protected String getXPathName(String name) {
-		int is = name.indexOf('['),
-			ip = name.indexOf('.');
-		if (ip>0 && (is<0 || ip < is)) {
-			StringBuffer sb = new StringBuffer(name);
-			sb.setCharAt(ip, '/');
-			return sb.toString();
-		} else
-			return name;
-	}
-	
-	protected String getOrderXPath(String order) {
-		if ("".equals(n2e(order))) return "";
-		final String[] props = StringUtils.split(order,',');		
-		StringBuffer res = new StringBuffer();
-		res.append(" order by ");
-		String comma = "";
-		for (int i=0; i<props.length; i++) {
-			res.append(comma);
-			String prop = props[i].trim();
-			char c = prop.charAt(0);
-			boolean descending = (c == '-');			
-			if (c=='-' || c=='+')
-				prop = prop.substring(1);
-			c = prop.charAt(0);
-			if (c!='@')
-				res.append("@");
-			res.append(prop);
-			if (descending)
-				res.append(" descending");
-			comma = ",";
-		}
-		return res.toString(); 
-	}
-	protected String getPropertyXPath(String prop) {
-		if ("".equals(n2e(prop))) return "";
-		prop = prop.trim();
-		if (prop.charAt(0)=='(') return "/"+prop;
-		
-		final StringBuffer sb = new StringBuffer();
-		final String[] props = StringUtils.split(prop, " ,");
-		sb.append("/");
-		if (props.length>1)
-			sb.append("(");
-		String comma = "";
-		for (int i=0; i<props.length; i++) {
-			final String p = props[i];
-			sb.append(comma);
-			if (p.charAt(0)!='@')
-				sb.append("@");
-			sb.append(p);
-			comma = ",";
-		}
-		if (props.length>1)
-			sb.append(")");
-		
-		return sb.toString();
-	}
-	private final String n2e(String s) {
-		return s==null?"":s;
-	}	
+
+    public String getName() { return "query"; }
+
+    QueryPluginApi queryApi;
+    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
+        if (queryApi == null)
+            queryApi = new QueryPluginApi(this);
+        return queryApi;
+    }
+
+    public XWikiContext getContext() {
+        return context;
+    }
+    public XWikiStoreInterface getStore() {
+        return getContext().getWiki().getStore();
+    }
+
+    ValueFactory valueFactory = null;;
+    public ValueFactory getValueFactory() {
+        if (valueFactory==null) {
+            valueFactory = new ValueFactoryImpl();
+        }
+        return valueFactory;
+    }
+
+    boolean isHibernate() {
+        return getContext().getWiki().getHibernateStore() != null;
+    }
+    boolean isJcr() {
+        return getContext().getWiki().getNotCacheStore() instanceof XWikiJcrStore;
+    }
+
+    /** Translate query string to query tree */
+    protected QueryRootNode parse(String query, String language) throws InvalidQueryException {
+        if (query==null) return null;
+        final QueryRootNode qn = QueryParser.parse(query, language, XWikiNamespaceResolver.getInstance());
+        return qn;
+    }
+    /** create xpath query
+     * @throws XWikiException */
+    public IQuery xpath(String q) throws XWikiException {
+        if (log.isDebugEnabled())
+            log.debug("create xpath query: "+q);
+        if (isHibernate())
+            try {
+                return new HibernateQuery( parse(q, Query.XPATH), this);
+            } catch (InvalidQueryException e) {
+                throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, "Invalid xpath query: " + q);
+            }
+        if (isJcr())
+            return new JcrQuery( q, Query.XPATH, this );
+        return null;
+    }
+    /** create JCRSQL query
+     * unsupported for now
+     * @throws XWikiException */
+    public IQuery ql(String q) throws XWikiException {
+        if (log.isDebugEnabled())
+            log.debug("create JCRSQL query: "+q);
+        if (isHibernate())
+            try {
+                return new HibernateQuery( parse(q, Query.SQL), this);
+            } catch (InvalidQueryException e) {
+                throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, "Invalid jcrsql query: " + q);
+            }
+        if (isJcr())
+            return new JcrQuery( q, Query.SQL, this );
+        return null;
+    }
+    /** create query for docs
+     * @param web, docname - document.web & .name. it may consist xpath []-selection. if any - *
+     * @param prop - return property, start with @, if null - return document
+     * @param order - properties for sort, separated by ','; order: ascending/descending after prop. name, or +/- before. if null - not sort
+     * @throws XWikiException
+     * */
+    public IQuery getDocs(String docname, String prop, String order) throws XWikiException {
+        return xpath("/"+getXPathName(docname) + getPropertyXPath(prop) + getOrderXPath(order));
+    }
+    /** create query for child documents
+     * @param web,docname must be without templates & [] select
+     * @throws XWikiException
+     * @see getDocs */
+    public IQuery getChildDocs(String docname, String prop, String order) throws XWikiException {
+        return xpath("/*/*[@parent='"+getXWikiName(docname)+"']"+ getPropertyXPath(prop) + getOrderXPath(order));
+    }
+    /** create query for attachments
+     * @param attachname - name of attachment, may be *, *[]
+     * @throws XWikiException
+     * @see getDocs
+     */
+    public IQuery getAttachment(String docname, String attachname, String order) throws XWikiException {
+        return xpath("/"+getXPathName(docname)+"/attach/" + attachname + getOrderXPath(order));
+    }
+    /** create query for objects
+     * @param oweb, oclass - object web & class. if any - *
+     * @param prop. for flex-attributes use f:flexname
+     * @throws XWikiException
+     * @see getDocs
+     */
+    public IQuery getObjects(String docname, String oclass, String prop, String order) throws XWikiException {
+        return xpath("/"+getXPathName(docname)+"/obj/"+getXPathName(oclass) + getPropertyXPath(prop) + getOrderXPath(order));
+    }
+
+    protected String getXWikiName(String name) {
+        int is = name.indexOf('['),
+        ip = name.indexOf('/');
+        if (is<0 || ip < is)
+            return name.replace('/', '.');
+        return name;
+    }
+    protected String getXPathName(String name) {
+        int is = name.indexOf('['),
+            ip = name.indexOf('.');
+        if (ip>0 && (is<0 || ip < is)) {
+            StringBuffer sb = new StringBuffer(name);
+            sb.setCharAt(ip, '/');
+            return sb.toString();
+        } else
+            return name;
+    }
+
+    protected String getOrderXPath(String order) {
+        if ("".equals(n2e(order))) return "";
+        final String[] props = StringUtils.split(order,',');
+        StringBuffer res = new StringBuffer();
+        res.append(" order by ");
+        String comma = "";
+        for (int i=0; i<props.length; i++) {
+            res.append(comma);
+            String prop = props[i].trim();
+            char c = prop.charAt(0);
+            boolean descending = (c == '-');
+            if (c=='-' || c=='+')
+                prop = prop.substring(1);
+            c = prop.charAt(0);
+            if (c!='@')
+                res.append("@");
+            res.append(prop);
+            if (descending)
+                res.append(" descending");
+            comma = ",";
+        }
+        return res.toString();
+    }
+    protected String getPropertyXPath(String prop) {
+        if ("".equals(n2e(prop))) return "";
+        prop = prop.trim();
+        if (prop.charAt(0)=='(') return "/"+prop;
+
+        final StringBuffer sb = new StringBuffer();
+        final String[] props = StringUtils.split(prop, " ,");
+        sb.append("/");
+        if (props.length>1)
+            sb.append("(");
+        String comma = "";
+        for (int i=0; i<props.length; i++) {
+            final String p = props[i];
+            sb.append(comma);
+            if (p.charAt(0)!='@')
+                sb.append("@");
+            sb.append(p);
+            comma = ",";
+        }
+        if (props.length>1)
+            sb.append(")");
+
+        return sb.toString();
+    }
+    private final String n2e(String s) {
+        return s==null?"":s;
+    }
+
+    public String makeQuery(XWikiQuery query) throws XWikiException {
+        StringBuffer xpath = new StringBuffer();
+        Set classes = query.getClasses();
+        if (classes.size()>1)
+         throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_SEARCH_NOTIMPL, "Search with more than one class is not implemented");
+        if (classes.size()==0)
+         return "//*/*";
+
+        String className = (String) classes.toArray()[0];
+        BaseClass bclass = context.getWiki().getClass(className, context);
+        xpath.append("//*/*/obj/");
+        xpath.append(className.replace('.','/'));
+        xpath.append("[");
+        xpath.append(bclass.makeQuery(query));
+        xpath.append("]/@name");
+        return xpath.toString();
+    }
+
+    public List search(XWikiQuery query) throws XWikiException {
+        List doclist =  xpath(makeQuery(query)).list();
+        return doclist;
+        /*
+        if (doclist==null)
+         return null;
+        List list = new ArrayList();
+        for (int i=0;i<doclist.size();i++) {
+            list.add(((XWikiDocument)doclist.get(i)).getFullName());
+        }
+        return list;
+        */
+    }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/QueryPluginApi.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/QueryPluginApi.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/QueryPluginApi.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -60,21 +60,21 @@
 	public XWikiStoreInterface getStore() {
 		return qp.getStore();
 	}
+
+    public IQuery xpath(String q) throws XWikiException {
+        if (log.isDebugEnabled())
+            log.debug("create sec xpath query: "+q);
+        if (qp.isHibernate())
+            try {
+                return new SecHibernateQuery( qp.parse(q, Query.XPATH), this);
+            } catch (InvalidQueryException e) {
+                throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, "Invalid xpath query: " + q);
+            }
+        if (qp.isJcr())
+            return new SecJcrQuery( q, Query.XPATH, this );
+        return null;
+    }
 	
-	public IQuery xpath(String q) throws XWikiException {
-		if (log.isDebugEnabled())
-			log.debug("create sec xpath query: "+q);
-		if (qp.isHibernate())
-			try {
-				return new SecHibernateQuery( qp.parse(q, Query.XPATH), this);
-			} catch (InvalidQueryException e) {
-				throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, "Invalid xpath query: " + q);
-			}
-		if (qp.isJcr())
-			return new SecJcrQuery( q, Query.XPATH, this );
-		return null;
-	}
-	
 	public IQuery ql(String q) throws XWikiException {
 		if (log.isDebugEnabled())
 			log.debug("create sec JCRSQL query: "+q);
@@ -91,4 +91,8 @@
 	public ValueFactory getValueFactory() {
 		return qp.getValueFactory();
 	}
+
+    public String makeQuery(XWikiQuery query) throws XWikiException {
+        return qp.makeQuery(query);
+    }
 }

Added: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/XWikiCriteria.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/XWikiCriteria.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/XWikiCriteria.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -0,0 +1,39 @@
+package com.xpn.xwiki.plugin.query;
+
+import com.xpn.xwiki.util.Util;
+
+import java.util.*;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ldubost
+ * Date: 7 sept. 2006
+ * Time: 20:00:39
+ * To change this template use File | Settings | File Templates.
+ */
+public class XWikiCriteria {
+    protected HashMap params = new HashMap();
+
+    public String getParameter(String field) {
+        return (String ) params.get(field);
+    }
+
+    public Map getParameters(String field) {
+       return Util.getSubMap(params, field);
+    }
+
+    public void setParam(String field, Object value) {
+        params.put(field, value);
+    }
+
+    public Set getClasses() {
+        Set set = new HashSet();
+        for(Iterator it=params.keySet().iterator();it.hasNext();) {
+            String key = (String) it.next();
+            String objname = key.substring(0, key.indexOf('_'));
+            if ((!objname.equals("")&&(!objname.equals("doc"))))
+             set.add(objname);
+        }
+        return set;
+    }
+}

Added: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/XWikiQuery.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/XWikiQuery.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/query/XWikiQuery.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -0,0 +1,73 @@
+package com.xpn.xwiki.plugin.query;
+
+import com.xpn.xwiki.util.Util;
+
+import java.util.*;
+import java.lang.reflect.Array;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ldubost
+ * Date: 7 sept. 2006
+ * Time: 20:00:39
+ * To change this template use File | Settings | File Templates.
+ */
+public class XWikiQuery extends XWikiCriteria {
+    protected boolean distinct = false;
+    protected List displayProperties = new ArrayList();
+    protected List addProperties = new ArrayList();
+    protected List groupbyProperties = new ArrayList();
+    protected List orderProperties = new ArrayList();
+
+    public void reset() {
+        displayProperties = new ArrayList();
+        addProperties = new ArrayList();
+        groupbyProperties = new ArrayList();
+        orderProperties = new ArrayList();
+    }
+
+    public void setDistinct(boolean distinct) {
+        this.distinct = distinct;
+    }
+
+    public boolean isDistinct() {
+        return distinct;
+    }
+
+    public void setDisplayProperties(List properties) {
+         displayProperties = properties;
+    }
+
+    public void setDisplayProperties(String[] properties) {
+        displayProperties = Arrays.asList(properties);
+    }
+
+    public List getDisplayProperties() {
+        return displayProperties;
+    }
+
+    public void setDisplayProperty(String property) {
+        displayProperties = new ArrayList();
+        displayProperties.add(property);
+    }
+
+    public void addProperty(String property) {
+        addProperties.add(property);
+    }
+
+    public void addGroupByProperty(String property) {
+        groupbyProperties.add(property);
+    }
+
+    public void addOrderProperty(String property) {
+        orderProperties.add(new OrderClause(property, OrderClause.DESC));
+    }
+
+    public void addOrderProperty(String property, String order) {
+        addOrderProperty(property, order.equals("desc") ? OrderClause.DESC : OrderClause.ASC);
+    }
+
+    public void addOrderProperty(String property, int order) {
+        orderProperties.add(new OrderClause(property, order));
+    }
+}

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/util/Util.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/util/Util.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/util/Util.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -1,25 +1,25 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * 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.
- *
- * @author ludovic
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * 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.
+ *
+ * @author ludovic
+ * @author sdumitriu
+ */
 
 package com.xpn.xwiki.util;
 
@@ -145,7 +145,10 @@
     }
 
     public static Map getObject(XWikiRequest request, String prefix) {
-        Map map = request.getParameterMap();
+        return getSubMap(request.getParameterMap(), prefix);
+    }
+
+    public static Map getSubMap(Map map, String prefix) {
         HashMap map2 = new HashMap();
         Iterator it = map.keySet().iterator();
         while (it.hasNext()) {
@@ -154,6 +157,9 @@
                 String newname = name.substring(prefix.length()+1);
                 map2.put(newname, map.get(name));
             }
+            if (name.equals(prefix)) {
+                map2.put("", map.get(name));
+            }
         }
         return map2;
     }

Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/test/AllTests.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/AllTests.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/AllTests.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -68,7 +68,6 @@
         suite.addTestSuite(StatsTest.class);
         suite.addTestSuite(StoreHibernateTest.class);
         suite.addTestSuite(StoreHibernateCacheTest.class);
-        suite.addTestSuite(StoreObjectRCSFileTest.class);
         suite.addTestSuite(StoreObjectHibernateTest.class);
         suite.addTestSuite(SearchTest.class);
         suite.addTestSuite(UserTest.class);

Added: xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryGeneratorTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryGeneratorTest.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryGeneratorTest.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -0,0 +1,119 @@
+package com.xpn.xwiki.test.plugin.query;
+
+import com.xpn.xwiki.plugin.query.XWikiQuery;
+import com.xpn.xwiki.plugin.query.IQueryFactory;
+import com.xpn.xwiki.plugin.query.QueryPlugin;
+import com.xpn.xwiki.plugin.XWikiPluginManager;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.objects.classes.BaseClass;
+import com.xpn.xwiki.objects.classes.PropertyClass;
+import com.xpn.xwiki.objects.BaseObject;
+import com.xpn.xwiki.test.Utils;
+import com.xpn.xwiki.test.HibernateTestCase;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.store.XWikiHibernateStore;
+
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ldubost
+ * Date: 10 sept. 2006
+ * Time: 13:38:09
+ * To change this template use File | Settings | File Templates.
+ */
+public class QueryGeneratorTest extends HibernateTestCase {
+    IQueryFactory qf;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        getXWiki().setPluginManager(new XWikiPluginManager("com.xpn.xwiki.plugin.query.QueryPlugin", getXWikiContext()));
+        QueryPlugin plugin = (QueryPlugin) getXWiki().getPluginManager().getPlugin("query");
+        //qf = (QueryFactory) plugin.getPluginApi(plugin, getXWikiContext());
+        qf = plugin;
+    }
+
+    public void testQueryGenerator(XWikiQuery query, String result) throws XWikiException {
+        assertEquals(result, qf.makeQuery(query));
+    }
+
+    public void testQueryGenerator() throws XWikiException {
+        XWikiHibernateStore hb = getXWiki().getHibernateStore();
+        XWikiDocument doc = new XWikiDocument("Test", "TestClass");
+        Utils.prepareClass(doc, "Test.TestClass");
+        Utils.prepareAdvancedClass(doc, "Test.TestClass");
+        hb.saveXWikiDoc(doc, getXWikiContext());
+
+        XWikiQuery query = new XWikiQuery();
+        query.setParam("Test.TestClass_first_name", "Artem");
+
+        assertEquals(query.getClasses().size(), 1);
+        assertTrue(query.getClasses().contains("Test.TestClass"));
+
+        testQueryGenerator(query, "//*/*/obj/Test/TestClass[jcr:like(@f:first_name, '%Artem%')]/@name");
+        query = new XWikiQuery();
+        query.setParam("Test.TestClass_first_name_exact", "Artem");
+        testQueryGenerator(query, "//*/*/obj/Test/TestClass[@f:first_name='Artem']/@name");
+        query = new XWikiQuery();
+        query.setParam("Test.TestClass_first_name_not", "Artem");
+        testQueryGenerator(query, "//*/*/obj/Test/TestClass[@f:first_name!='Artem']/@name");
+        query = new XWikiQuery();
+        query.setParam("Test.TestClass_age_morethan", new Integer(20));
+        testQueryGenerator(query, "//*/*/obj/Test/TestClass[@f:age>20]/@name");
+        query = new XWikiQuery();
+        query.setParam("Test.TestClass_age_lessthan", new Integer(20));
+        testQueryGenerator(query, "//*/*/obj/Test/TestClass[@f:age<20]/@name");
+        query = new XWikiQuery();
+        query.setParam("Test.TestClass_category", "1");
+        testQueryGenerator(query, "//*/*/obj/Test/TestClass[jcr:contains(@f:category,'1')]/@name");
+        String[] params = {"1", "2"};
+        query = new XWikiQuery();
+        query.setParam("Test.TestClass_category", params);
+        testQueryGenerator(query, "//*/*/obj/Test/TestClass[(jcr:contains(@f:category,'1') or jcr:contains(@f:category,'2'))]/@name");
+    }
+
+    public void prepareData(XWikiHibernateStore hb) throws XWikiException {
+        XWikiDocument doc = new XWikiDocument("Test", "TestClass");
+        BaseClass bclass = Utils.prepareClass(doc, "Test.TestClass");
+        hb.saveXWikiDoc(doc, getXWikiContext());
+
+        XWikiDocument doc1 = new XWikiDocument("Test", "TestObject");
+        // hb.saveXWikiDoc(doc1, getXWikiContext());
+        BaseObject object  = new BaseObject();
+        doc1.setObject(bclass.getName(), 0, object);
+        object.setClassName(bclass.getName());
+        object.setName(doc1.getFullName());
+        object.put("first_name", ((PropertyClass)bclass.get("first_name")).fromString("Artem"));
+        object.put("last_name", ((PropertyClass)bclass.get("last_name")).fromString("Melentev"));
+        object.put("age", ((PropertyClass)bclass.get("age")).fromString("20"));
+        object.put("password", ((PropertyClass)bclass.get("password")).fromString("sesame"));
+        object.put("comment",((PropertyClass)bclass.get("comment")).fromString("Hello1\nHello2\nHello3\n"));
+        hb.saveXWikiDoc(doc1, getXWikiContext());
+    }
+
+    public void testRunQuery() throws XWikiException {
+        XWikiHibernateStore hb = getXWiki().getHibernateStore();
+        prepareData(hb);
+
+        XWikiQuery query = new XWikiQuery();
+        query.setParam("Test.TestClass_first_name", "abc");
+        List list = xwiki.search(query, context);
+        assertEquals("List should have 0 item", 0, list.size());
+        query.setParam("Test.TestClass_first_name", "rte");
+        list = xwiki.search(query, context);
+        assertEquals("List should have 1 item", 1, list.size());
+    }
+
+    public void testRunQueryAsTable() throws XWikiException {
+        XWikiHibernateStore hb = getXWiki().getHibernateStore();
+        prepareData(hb);
+
+        XWikiQuery query = new XWikiQuery();
+        query.setParam("Test.TestClass_first_name", "art");
+        String[] displayProperties = { "Test.TestClass_first_name", "Test.TestClass_last_name", "Test.TestClass_age", "doc.name", "link"};
+        query.setDisplayProperties(displayProperties);
+        String result =  xwiki.searchAsTable(query, context);
+        assertTrue("Result is invalid:\r\n" + result, result.indexOf("dfdfsd")!=-1);
+    }
+
+}

Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginTest.java	2006-09-11 11:12:10 UTC (rev 1302)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginTest.java	2006-09-11 13:31:07 UTC (rev 1303)
@@ -45,54 +45,56 @@
 import com.xpn.xwiki.plugin.XWikiPluginManager;
 import com.xpn.xwiki.plugin.query.IQueryFactory;
 import com.xpn.xwiki.plugin.query.QueryPlugin;
+import com.xpn.xwiki.plugin.query.XWikiQuery;
 import com.xpn.xwiki.store.XWikiHibernateStore;
 import com.xpn.xwiki.store.XWikiStoreInterface;
 import com.xpn.xwiki.test.HibernateTestCase;
 import com.xpn.xwiki.test.Utils;
+import junit.framework.TestCase;
 
 public class QueryPluginTest extends HibernateTestCase {
-	private static final Object[] NOTHING = new Object[]{};
-	IQueryFactory qf;
-	
-	protected void setUp() throws Exception {		
-		super.setUp();
-		getXWiki().setPluginManager(new XWikiPluginManager("com.xpn.xwiki.plugin.query.QueryPlugin", getXWikiContext()));
+    private static final Object[] NOTHING = new Object[]{};
+    IQueryFactory qf;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        getXWiki().setPluginManager(new XWikiPluginManager("com.xpn.xwiki.plugin.query.QueryPlugin", getXWikiContext()));
         QueryPlugin plugin = (QueryPlugin) getXWiki().getPluginManager().getPlugin("query");
         //qf = (QueryFactory) plugin.getPluginApi(plugin, getXWikiContext());
         qf = plugin;
-	}
-	
-	public Object loadobj(Object obj) throws XWikiException {
-		if (obj instanceof XWikiDocument)
-			obj = getXWiki().getDocument(((XWikiDocument)obj).getFullName(), getXWikiContext());
-		else if (obj instanceof BaseObject) {
-			final BaseObject obj1 = (BaseObject) obj;
-			final XWikiDocument doc1 = getXWiki().getDocument(obj1.getName(), getXWikiContext());
-			obj = doc1.getObject(obj1.getClassName(), obj1.getNumber());					
-		}/* else if (obj instanceof XWikiAttachment) {
+    }
+
+    public Object loadobj(Object obj) throws XWikiException {
+        if (obj instanceof XWikiDocument)
+            obj = getXWiki().getDocument(((XWikiDocument)obj).getFullName(), getXWikiContext());
+        else if (obj instanceof BaseObject) {
+            final BaseObject obj1 = (BaseObject) obj;
+            final XWikiDocument doc1 = getXWiki().getDocument(obj1.getName(), getXWikiContext());
+            obj = doc1.getObject(obj1.getClassName(), obj1.getNumber());
+        }/* else if (obj instanceof XWikiAttachment) {
 			XWikiAttachment att = (XWikiAttachment) obj;
 			getXWiki().getStore().loadAttachmentContent(att, getXWikiContext(), true);
 			obj = att;
 		}*/
-		return obj;
-	}
-	
-	public void checkEquals(List lst, Object[] exps) throws XWikiException, InvalidQueryException {
-		assertEquals("Length not same", exps.length, lst.size());
-		for (int i=0; i<exps.length; i++) {
-			Object obj = lst.get(i);
-			Object exp = exps[i];			
-			if (obj instanceof Object[]) {
-				Object[] obj0 = (Object[]) obj,
-						exp0 = (Object[]) exp;
-				assertEquals(obj0.length, exp0.length);
-				for (int j=0; i<obj0.length; i++) {					
-					assertEquals(obj0[j], exp0[j]);
-				}
-			} else {
-				obj = loadobj(obj);
-				exp = loadobj(exp);
-				if (exp==obj) continue; // XXX: bugs with proxy objects?
+        return obj;
+    }
+
+    public void checkEquals(List lst, Object[] exps) throws XWikiException, InvalidQueryException {
+        assertEquals("Length not same", exps.length, lst.size());
+        for (int i=0; i<exps.length; i++) {
+            Object obj = lst.get(i);
+            Object exp = exps[i];
+            if (obj instanceof Object[]) {
+                Object[] obj0 = (Object[]) obj,
+                        exp0 = (Object[]) exp;
+                assertEquals(obj0.length, exp0.length);
+                for (int j=0; i<obj0.length; i++) {
+                    assertEquals(obj0[j], exp0[j]);
+                }
+            } else {
+                obj = loadobj(obj);
+                exp = loadobj(exp);
+                if (exp==obj) continue; // XXX: bugs with proxy objects?
                 if (exp instanceof XWikiDocument)
                  assertEquals("Objects #"+i+" not equals",
                          ((XWikiDocument)obj).toFullXML(context),
@@ -103,46 +105,46 @@
                          ((XWikiAttachment)obj).toStringXML(false, false, context),
                          ((XWikiAttachment)exp).toStringXML(false, false, context));
                 else if( exp instanceof Date)
-                    assertEquals("Objects #"+i+" not equals", (((Date)obj).getTime()/1000)*1000, (((Date)exp).getTime()/1000)*1000);                    
+                    assertEquals("Objects #"+i+" not equals", (((Date)obj).getTime()/1000)*1000, (((Date)exp).getTime()/1000)*1000);
                 else
                  assertEquals("Objects #"+i+" not equals", obj, exp);
-			}
-		}
-	}
-	public void testSearchXP(String sqx, Object[] exps) throws XWikiException, InvalidQueryException {
-		checkEquals(qf.xpath(sqx).list(), exps);
-	}
-	public void testSearchXP1(String sqx, Object exp1) throws XWikiException, InvalidQueryException {
-		checkEquals(qf.xpath(sqx).list(), new Object[]{exp1});
-	}
-	public void testSearchXP1(String sqx, long exp1) throws XWikiException, InvalidQueryException {
-		testSearchXP1(sqx, new Long(exp1));
-	}
-	public void testSearchXP1(String sqx, int exp1) throws XWikiException, InvalidQueryException {
-		testSearchXP1(sqx, new Integer(exp1));
-	}
-	public void testSearchQl(String sq, Object[] exps) throws XWikiException, InvalidQueryException {
-		checkEquals(qf.ql(sq).list(), exps);
-	}
-	public void testSearchQl1(String sq, Object exp1) throws XWikiException, InvalidQueryException {
-		checkEquals(qf.ql(sq).list(), new Object[]{exp1});
-	}
-	public void testSearchXPnQl(String sqx, String sqs, Object[] exps) throws InvalidQueryException, XWikiException {
-		testSearchXP(sqx, exps);
-		testSearchQl(sqs, exps);
-	}
-	public void testSearchXPnQl1(String sqx, String sqs, Object exp1) throws InvalidQueryException, XWikiException {
-		testSearchXP1(sqx, exp1);
-		testSearchQl1(sqs, exp1);
-	}
-	
-	public void testWebDocs() throws XWikiException, InvalidQueryException {
-		XWikiHibernateStore hibstore = getXWiki().getHibernateStore();
-		
-		testSearchXP("//*/*",		NOTHING);
-		checkEquals(qf.getDocs("*/*", null, null).list(), NOTHING);		
-		
-		XWikiDocument doc1 = new XWikiDocument("Main", "WebHome");
+            }
+        }
+    }
+    public void testSearchXP(String sqx, Object[] exps) throws XWikiException, InvalidQueryException {
+        checkEquals(qf.xpath(sqx).list(), exps);
+    }
+    public void testSearchXP1(String sqx, Object exp1) throws XWikiException, InvalidQueryException {
+        checkEquals(qf.xpath(sqx).list(), new Object[]{exp1});
+    }
+    public void testSearchXP1(String sqx, long exp1) throws XWikiException, InvalidQueryException {
+        testSearchXP1(sqx, new Long(exp1));
+    }
+    public void testSearchXP1(String sqx, int exp1) throws XWikiException, InvalidQueryException {
+        testSearchXP1(sqx, new Integer(exp1));
+    }
+    public void testSearchQl(String sq, Object[] exps) throws XWikiException, InvalidQueryException {
+        checkEquals(qf.ql(sq).list(), exps);
+    }
+    public void testSearchQl1(String sq, Object exp1) throws XWikiException, InvalidQueryException {
+        checkEquals(qf.ql(sq).list(), new Object[]{exp1});
+    }
+    public void testSearchXPnQl(String sqx, String sqs, Object[] exps) throws InvalidQueryException, XWikiException {
+        testSearchXP(sqx, exps);
+        testSearchQl(sqs, exps);
+    }
+    public void testSearchXPnQl1(String sqx, String sqs, Object exp1) throws InvalidQueryException, XWikiException {
+        testSearchXP1(sqx, exp1);
+        testSearchQl1(sqs, exp1);
+    }
+
+    public void testWebDocs() throws XWikiException, InvalidQueryException {
+        XWikiHibernateStore hibstore = getXWiki().getHibernateStore();
+
+        testSearchXP("//*/*",		NOTHING);
+        checkEquals(qf.getDocs("*/*", null, null).list(), NOTHING);
+
+        XWikiDocument doc1 = new XWikiDocument("Main", "WebHome");
         doc1.setContent("no content");
         doc1.setAuthor("Artem Melentev");
         doc1.setParent("Main.WebHome");
@@ -221,7 +223,7 @@
         checkEquals(qf.getDocs("*/*[@author!='Someone']", null, null).list(), new Object[]{doc1, doc3});
         testSearchXP("//Test/*[@author='Someone']",					new Object[]{doc4});
         checkEquals(qf.getDocs("Test/*[@author='Someone']", null, null).list(), new Object[]{doc4});
-        
+
         testSearchXP("//*/*[@author!='Someone' and jcr:like(@name, '%3')]",	new Object[]{doc3});
         checkEquals(qf.getDocs("*/*[@author!='Someone' and jcr:like(@name, '%3')]", null, null).list(), new Object[]{doc3});
         testSearchXP("//*/*[@author!='Someone' and not(jcr:like(@name, '%3'))]",	new Object[]{doc1});
@@ -246,19 +248,19 @@
         checkEquals(qf.getChildDocs("Main.WebHome2", "@name", null).list(), new Object[]{doc3.getName(),doc4.getName(),doc5.getName()});
         testSearchXP("//*/*[@parent='Main.WebHome2' and (@author='Artem Melentev' or @content='is content')]",	new Object[]{doc3,doc5});
         checkEquals(qf.getDocs("*/*[@parent='Main.WebHome2' and (@author='Artem Melentev' or @content='is content')]", null, null).list(), new Object[]{doc3,doc5});
-        
+
         checkEquals(qf.xpath("//*/* order by @creationDate descending").setMaxResults(2).list(), new Object[]{doc5,doc4});
         checkEquals(qf.getDocs("*/*", "", "- at creationDate").setMaxResults(2).list(), new Object[]{doc5,doc4});
-        
+
         checkEquals(qf.getDocs("*.*[@author='Artem Melentev']", "@author", "").setDistinct(true).list(), new Object[]{"Artem Melentev"});
         checkEquals(qf.getDocs("*.*[@author='Artem Melentev']", "@author", "").setDistinct(false).list(), new Object[]{"Artem Melentev", "Artem Melentev"});
-        
+
         testSearchXPnQl1("/element(WebHome4, xwiki:document)/@parent", "select parent from xwiki:document where name='WebHome4'", "Main.WebHome2");
-	}
-	
-	// XXX: Attachments don`t store it`s document!!!
-	public void testAttachments() throws XWikiException, IOException, InvalidQueryException {
-		XWikiHibernateStore hb = getXWiki().getHibernateStore();
+    }
+
+    // XXX: Attachments don`t store it`s document!!!
+    public void testAttachments() throws XWikiException, IOException, InvalidQueryException {
+        XWikiHibernateStore hb = getXWiki().getHibernateStore();
         // hb.beginTransaction(getXWikiContext());
 
         XWikiDocument doc1 = new XWikiDocument("Test", "TestAttach1");
@@ -266,17 +268,17 @@
         doc1.setAuthor("Someone");
         doc1.setParent("Test.WebHome");
         hb.saveXWikiDoc(doc1, getXWikiContext());
-        
+
         Utils.setStandardData();
         XWikiAttachment attachment1 = new XWikiAttachment(doc1, "testfile1");
         byte[] attachcontent1 = Utils.getDataAsBytes(new File(Utils.filename));
         attachment1.setContent(attachcontent1);
         doc1.saveAttachmentContent(attachment1, getXWikiContext());
-        doc1.getAttachmentList().add(attachment1);        
+        doc1.getAttachmentList().add(attachment1);
         hb.saveXWikiDoc(doc1, getXWikiContext());
-                
+
         // attachment1 = (XWikiAttachment) hb.getSession(getXWikiContext()).load(XWikiAttachment.class, new Long(attachment1.getId()));
-         
+
         testSearchXP("//*/*/attach/*", new Object[]{attachment1});
         testSearchXPnQl1("//element(*, xwiki:attachment)", "select * from xwiki:attachment", attachment1);
         checkEquals(qf.getAttachment("*/*", "*", null).list(), new Object[]{attachment1});
@@ -294,7 +296,7 @@
         testSearchXP("//*/*/attach/testfile1", new Object[]{attachment1});
         testSearchXP1("/attach/testfile1", attachment1);
         checkEquals(qf.getAttachment("*/*", "testfile1", null).list(), new Object[]{attachment1});
-        
+
         XWikiAttachment attachment2 = new XWikiAttachment(doc1, "testfile2");
         byte[] attachcontent2 = Utils.getDataAsBytes(new File(Utils.filename2));
         attachment2.setContent(attachcontent2);
@@ -303,7 +305,7 @@
         doc1.getAttachmentList().add(attachment2);
         hb.saveXWikiDoc(doc1, getXWikiContext());
         // attachment2 = (XWikiAttachment) hb.getSession(getXWikiContext()).load(XWikiAttachment.class, new Long(attachment2.getId()));
-        
+
         testSearchXP("//*/*/attach/* order by @filename",				new Object[]{attachment1, attachment2});
         testSearchXPnQl("/element(*,xwiki:attachment) order by @filename", "select * from xwiki:attachment order by filename", new Object[]{attachment1, attachment2});
         checkEquals(qf.getAttachment("*/*", "*", "@filename").list(), new Object[]{attachment1,attachment2});
@@ -315,13 +317,13 @@
         checkEquals(qf.getAttachment("*/*", "testfile2", null).list(), new Object[]{attachment2});
         testSearchXP("//Test/TestAttach1/attach/testfile1", new Object[]{attachment1});
         checkEquals(qf.getAttachment("Test/TestAttach1", "testfile1", null).list(), new Object[]{attachment1});
-        
+
         XWikiDocument doc2 = new XWikiDocument("Test", "TestAttach2");
         doc2.setContent("no content");
         doc2.setAuthor("Someone over");
         doc2.setParent("Test.WebHome");
         hb.saveXWikiDoc(doc2, getXWikiContext()); // XXX: Was same attachments of different documents be? That would query return? 2 or 1
-        
+
         XWikiAttachment attachment3 = new XWikiAttachment(doc2, "testfile1");
         byte[] attachcontent3 = Utils.getDataAsBytes(new File(Utils.filename));
         attachment3.setContent(attachcontent3);
@@ -342,23 +344,23 @@
         checkEquals(qf.getAttachment("Test.*[@author='Someone']", "*[@comment!='']", null).list(), new Object[]{attachment2});
         // hb.endTransaction(getXWikiContext(), false);
 
-	}
-	
-	public void testObjects() throws HibernateException, XWikiException, InvalidQueryException {		
-		XWikiHibernateStore hb = getXWiki().getHibernateStore();
-		XWikiDocument doc0, doc = doc0 = new XWikiDocument("Test", "TestClass");		
-		BaseClass bclass1, bclass = bclass1 = Utils.prepareClass(doc, "Test.TestClass");
-		hb.saveXWikiDoc(doc, getXWikiContext());
-		
-		XWikiDocument doc1 = doc = new XWikiDocument("Test", "TestObject");
-		hb.saveXWikiDoc(doc, getXWikiContext());
-		
-		testSearchXP("//*/*/obj/*/*",									NOTHING);
-		checkEquals(qf.getObjects("*/*","*/*",null,null).list(), NOTHING);
-		testSearchXP("//*/*/obj/*/*/@doc:self",						NOTHING);
-		checkEquals(qf.getObjects("*/*","*.*","@doc:self",null).list(), NOTHING);
-		
-		BaseObject object1, object = object1 = new BaseObject();
+    }
+
+    public void testObjects() throws HibernateException, XWikiException, InvalidQueryException {
+        XWikiHibernateStore hb = getXWiki().getHibernateStore();
+        XWikiDocument doc0, doc = doc0 = new XWikiDocument("Test", "TestClass");
+        BaseClass bclass1, bclass = bclass1 = Utils.prepareClass(doc, "Test.TestClass");
+        hb.saveXWikiDoc(doc, getXWikiContext());
+
+        XWikiDocument doc1 = doc = new XWikiDocument("Test", "TestObject");
+        hb.saveXWikiDoc(doc, getXWikiContext());
+
+        testSearchXP("//*/*/obj/*/*",									NOTHING);
+        checkEquals(qf.getObjects("*/*","*/*",null,null).list(), NOTHING);
+        testSearchXP("//*/*/obj/*/*/@doc:self",						NOTHING);
+        checkEquals(qf.getObjects("*/*","*.*","@doc:self",null).list(), NOTHING);
+
+        BaseObject object1, object = object1 = new BaseObject();
         doc.setObject(bclass.getName(), 0, object);
         object.setClassName(bclass.getName());
         object.setName(doc.getFullName());
@@ -366,9 +368,9 @@
         object.put("last_name", ((PropertyClass)bclass.get("last_name")).fromString("Melentev"));
         object.put("age", ((PropertyClass)bclass.get("age")).fromString("20"));
         object.put("password", ((PropertyClass)bclass.get("password")).fromString("sesame"));
-        object.put("comment",((PropertyClass)bclass.get("comment")).fromString("Hello1\nHello2\nHello3\n"));       
+        object.put("comment",((PropertyClass)bclass.get("comment")).fromString("Hello1\nHello2\nHello3\n"));
         hb.saveXWikiDoc(doc, getXWikiContext());
-        
+
         testSearchXP("//*/*/obj/*/*",							new Object[]{object1});
         checkEquals(qf.getObjects("*/*","*/*",null,null).list(), new Object[]{object1});
         testSearchXP("//Test/TestObject/obj/*/*",				new Object[]{object1});
@@ -383,14 +385,14 @@
         checkEquals(qf.getObjects("Test/TestObject","Test.*",null,null).list(), new Object[]{object1});
         testSearchXP("//Test/TestObject/obj/*/TestClass",		new Object[]{object1});
         checkEquals(qf.getObjects("Test.TestObject","*.TestClass",null,null).list(), new Object[]{object1});
-        
+
         testSearchXP("//Test/TestObject/obj/Test/TestClass/(@name, at className)",			new Object[]{new Object[]{"Test.TestObject", "Test.TestClass"}});
         checkEquals(qf.getObjects("Test.TestObject","Test.TestClass","@name, at className",null).list(), new Object[]{new Object[]{"Test.TestObject", "Test.TestClass"}});
-        
+
         testSearchXP("//*/*/obj/*/*/@doc:self",						new Object[]{doc1});
-		checkEquals(qf.getObjects("*/*","*/*","@doc:self",null).list(), new Object[]{doc1});
-        
-		doc = doc1;
+        checkEquals(qf.getObjects("*/*","*/*","@doc:self",null).list(), new Object[]{doc1});
+
+        doc = doc1;
         BaseObject object2 = object = new BaseObject();
         doc.setObject("Test.TestClass", 1, object);
         object.setClassName("Test.TestClass");
@@ -401,7 +403,7 @@
         object.put("password", ((PropertyClass)bclass.get("password")).fromString("sesame"));
         object.put("comment",((PropertyClass)bclass.get("comment")).fromString("Hello2\nHello3\nHello4\n"));
         getXWiki().getStore().saveXWikiDoc(doc, getXWikiContext());
-        
+
         testSearchXP("//*/*/obj/*/* order by @number",						new Object[]{object1, object2});
         checkEquals(qf.getObjects("*/*","*/*",null,"+ at number").list(), new Object[]{object1, object2});
         testSearchXP("//*/*/obj/*/* order by @number descending",				new Object[]{object2, object1});
@@ -429,43 +431,43 @@
         testSearchXP("//Test/TestObject/obj/Test/TestClass/@f:first_name order by @f:age descending",	new Object[]{"Ivan", "Artem"});
         checkEquals(qf.getObjects("*/*","Test.TestClass","@f:first_name","- at f:age").list(), new Object[]{"Ivan", "Artem"});
         checkEquals(qf.getObjects("*/*","Test.TestClass","@f:first_name","@f:age descending").list(), new Object[]{"Ivan", "Artem"});
-        
+
         testSearchXP("//Test/TestObject/obj/Test/TestClass[@f:age=20]/@f:password",	new Object[]{"sesame"}); // security is in QueryPluginApi
         checkEquals(qf.getObjects("Test.TestObject","Test.TestClass[@f:age=20]","@f:password", null).list(), new Object[]{"sesame"});
         testSearchXP("//*/*/obj/Test/TestClass/@f:first_name order by @f:first_name",	new Object[]{"Artem", "Ivan"});
         checkEquals(qf.getObjects("Test.TestObject","Test.TestClass","@f:first_name", "@f:first_name").list(), new Object[]{"Artem", "Ivan"});
         checkEquals(qf.getObjects("Test.TestObject","Test.TestClass","@f:first_name", "@f:first_name ascending").list(), new Object[]{"Artem", "Ivan"});
-        
+
         testSearchXP("//*/*/obj/Test/TestClass/@f:first_name order by @f:password, @f:age",	new Object[]{"Artem", "Ivan"});
         checkEquals(qf.getObjects("Test.TestObject","Test.TestClass","@f:first_name", "@f:password, at f:age").list(), new Object[]{"Artem", "Ivan"});
         testSearchXP("//*/*/obj/Test/TestClass/@f:first_name order by @f:password descending, @f:age descending",	new Object[]{"Ivan", "Artem"});
         checkEquals(qf.getObjects("Test.TestObject","Test.TestClass","@f:first_name", "- at f:password,- at f:age").list(), new Object[]{"Ivan", "Artem"});
         testSearchXP("//*/*/obj/Test/TestClass/(@f:first_name, at f:age) order by @f:password descending, @f:age descending",	new Object[]{new Object[]{"Ivan", new Long(21)}, new Object[]{"Artem", new Long(20)}});
         checkEquals(qf.getObjects("Test.TestObject","Test.TestClass","@f:first_name, at f:age", "- at f:password,- at f:age").list(), new Object[]{new Object[]{"Ivan", new Long(21)}, new Object[]{"Artem", new Long(20)}});
-        
+
         testSearchXP("//*/*/obj/Test/TestClass[@f:first_name='Artem']/@doc:name",			new Object[]{"TestObject"});
-		checkEquals(qf.getObjects("*/*","Test.TestClass[@f:first_name='Artem']","@doc:name",null).list(), new Object[]{"TestObject"});
+        checkEquals(qf.getObjects("*/*","Test.TestClass[@f:first_name='Artem']","@doc:name",null).list(), new Object[]{"TestObject"});
         testSearchXP("//*/*/obj/Test/TestClass[@f:first_name!='Artem']/@doc:fullName",			new Object[]{"Test.TestObject"});
-		checkEquals(qf.getObjects("*/*","Test.TestClass[@f:first_name!='Artem']","@doc:fullName",null).list(), new Object[]{"Test.TestObject"});
-		testSearchXP("//*/*/obj/Test/TestClass[@f:first_name!='Artem' and @f:first_name!='Ivan']/@doc:web",	NOTHING);
-		checkEquals(qf.getObjects("*/*","Test.TestClass[@f:first_name!='Artem' and @f:first_name!='Ivan']","@doc:fullName",null).list(), NOTHING);
-		
-		testSearchXP("//*/*/obj/Test/TestClas