Author: sdumitriu
Date: 2008-02-07 20:54:05 +0100 (Thu, 07 Feb 2008)
New Revision: 7354

Modified:
   
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBListClass.java
Log:
[cleanup] Apply codestyle


Modified: 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBListClass.java
===================================================================
--- 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBListClass.java
   2008-02-07 19:53:32 UTC (rev 7353)
+++ 
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/objects/classes/DBListClass.java
   2008-02-07 19:54:05 UTC (rev 7354)
@@ -26,24 +26,23 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 
-import com.xpn.xwiki.XWiki;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.objects.meta.PropertyMetaClass;
-import com.xpn.xwiki.plugin.query.QueryPlugin;
-
-import java.util.StringTokenizer;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ecs.xhtml.input;
+
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.objects.BaseCollection;
 import com.xpn.xwiki.objects.BaseProperty;
 import com.xpn.xwiki.objects.DBStringListProperty;
 import com.xpn.xwiki.objects.ListProperty;
-import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.objects.meta.PropertyMetaClass;
+import com.xpn.xwiki.plugin.query.QueryPlugin;
 
-
 public class DBListClass extends ListClass
 {
     private static final Log LOG = LogFactory.getLog(DBListClass.class);
@@ -97,7 +96,7 @@
     public List getDBList(XWikiContext context)
     {
         List list = getCachedDBList(context);
-        if (list==null || getIntValue("cache") != 1) {
+        if (list == null || getIntValue("cache") != 1) {
 
             XWiki xwiki = context.getWiki();
             String query = getQuery(context);
@@ -109,8 +108,10 @@
                 try {
                     if ((xwiki.getHibernateStore() != null) && 
(!query.startsWith("/"))) {
                         list = makeList(xwiki.search(query, context));
-                    } else  {
-                        list = makeList(((QueryPlugin) 
xwiki.getPlugin("query", context)).xpath(query).list());
+                    } else {
+                        list =
+                            makeList(((QueryPlugin) xwiki.getPlugin("query", 
context)).xpath(
+                                query).list());
                     }
                 } catch (Exception e) {
                     e.printStackTrace();
@@ -150,7 +151,7 @@
         }
         return map;
     }
-    
+
     public String getQuery(XWikiContext context)
     {
         String sql = getSql();
@@ -160,7 +161,7 @@
             LOG.warn("Failed to render SQL script [" + sql + "]. Internal 
error ["
                 + e.getMessage() + "]. Continuing with non-rendered script.");
         }
-        if ((sql == null) || (sql.trim().equals(""))) {
+        if (StringUtils.isBlank(sql)) {
             String classname = getClassname();
             String idField = getIdField();
             String valueField = getValueField();
@@ -168,35 +169,32 @@
                 valueField = idField;
             }
             if (context.getWiki().getHibernateStore() != null) {
-                StringBuffer select = new StringBuffer("select "); 
+                StringBuffer select = new StringBuffer("select ");
                 StringBuffer tables =
                     new StringBuffer(" from XWikiDocument as doc, BaseObject 
as obj");
                 StringBuffer where =
                     new StringBuffer(" where doc.fullName=obj.name and 
obj.className='");
                 where.append(classname).append("'");
-                
+
                 if (idField.startsWith("doc.") || idField.startsWith("obj.")) {
                     select.append(idField);
                 } else {
                     select.append("idprop.value");
                     tables.append(", StringProperty as idprop");
-                    where.append(" and obj.id=idprop.id.id and 
idprop.id.name='")
-                       .append(idField)
-                       .append("'");
+                    where.append(" and obj.id=idprop.id.id and 
idprop.id.name='").append(idField)
+                        .append("'");
                 }
-                
+
                 if (valueField.startsWith("doc.") || 
valueField.startsWith("obj.")) {
-                       select.append(", ").append(valueField);
-                }
-                else {
+                    select.append(", ").append(valueField);
+                } else {
                     if (idField.equals(valueField)) {
-                       select.append(", idprop.value");
+                        select.append(", idprop.value");
                     } else {
-                       select.append(", valueprop.value");
-                       tables.append(", StringProperty as valueprop");
+                        select.append(", valueprop.value");
+                        tables.append(", StringProperty as valueprop");
                         where.append(" and obj.id=valueprop.id.id and 
valueprop.id.name='")
-                               .append(valueField)
-                               .append("'");
+                            .append(valueField).append("'");
                     }
                 }
                 // Let's create the sql
@@ -250,7 +248,8 @@
         setStringValue("valueField", valueField);
     }
 
-    public List getCachedDBList(XWikiContext context) {
+    public List getCachedDBList(XWikiContext context)
+    {
         if (isCache()) {
             return cachedDBList;
         } else {
@@ -258,7 +257,8 @@
         }
     }
 
-    public void setCachedDBList(List cachedDBList, XWikiContext context) {
+    public void setCachedDBList(List cachedDBList, XWikiContext context)
+    {
         if (isCache()) {
             this.cachedDBList = cachedDBList;
         } else {
@@ -266,210 +266,220 @@
         }
     }
 
-    public void flushCache() {
+    public void flushCache()
+    {
         this.cachedDBList = null;
     }
 
     // return first or second col from user query
-    public String returnCol(String hibquery, boolean first) {
-               String firstCol = "-", secondCol = "-";
+    public String returnCol(String hibquery, boolean first)
+    {
+        String firstCol = "-", secondCol = "-";
 
-       int fromIndx = hibquery.indexOf("from");
+        int fromIndx = hibquery.indexOf("from");
 
-       if(fromIndx > 0) {
-                String firstPart = hibquery.substring(0, fromIndx);
-                firstPart.replaceAll("\\s+", " ");
-                int comIndx = hibquery.indexOf(",");
+        if (fromIndx > 0) {
+            String firstPart = hibquery.substring(0, fromIndx);
+            firstPart.replaceAll("\\s+", " ");
+            int comIndx = hibquery.indexOf(",");
 
-                //there are more than one columns to select- take the second 
one (the value)
-                if(comIndx > 0 && comIndx < fromIndx) {
+            // there are more than one columns to select- take the second one 
(the value)
+            if (comIndx > 0 && comIndx < fromIndx) {
 
-                        StringTokenizer st = new StringTokenizer(firstPart, " 
,()", true);
-                        ArrayList words = new ArrayList();
+                StringTokenizer st = new StringTokenizer(firstPart, " ,()", 
true);
+                ArrayList words = new ArrayList();
 
-                        while(st.hasMoreTokens())
-                                words.add(st.nextToken().toLowerCase());
+                while (st.hasMoreTokens())
+                    words.add(st.nextToken().toLowerCase());
 
-                        int comma = words.indexOf(",") - 1;
-                        while(words.get(comma).toString().compareTo(" ") == 0) 
{
-                                comma--;
-                        }
-                        firstCol = words.get(comma).toString().trim();
+                int comma = words.indexOf(",") - 1;
+                while (words.get(comma).toString().compareTo(" ") == 0) {
+                    comma--;
+                }
+                firstCol = words.get(comma).toString().trim();
 
-                        comma = words.indexOf(",") + 1;
-                        while(words.get(comma).toString().compareTo(" ") == 0) 
{
-                                 comma++;
-                        }
+                comma = words.indexOf(",") + 1;
+                while (words.get(comma).toString().compareTo(" ") == 0) {
+                    comma++;
+                }
 
-                if(words.get(comma).toString().compareTo("(") == 0) {
-                        int i = comma+1;
-                        while(words.get(i).toString().compareTo(")") != 0) {
-                                secondCol += words.get(i).toString();
-                                i++;
-                        }
-                        secondCol += ")";
-                }
-                else secondCol = words.get(comma).toString().trim();
-                }
-                //has only one column
-                else {
-                         int i = fromIndx - 1;
-                         while(firstPart.charAt(i) == ' ')
-                                 i--;
-                         String col = " ";
-                         while(firstPart.charAt(i) != ' ') {
-                                 col += firstPart.charAt(i);
-                                 i--;
-                         }
-                         String reverse = " ";
-                         for(i = (col.length()-1); i >= 0; i--)
-                                 reverse += col.charAt(i);
-                         firstCol = reverse.trim();
-                }
-       }
-       if(first == true) return firstCol;
-       else return secondCol;
+                if (words.get(comma).toString().compareTo("(") == 0) {
+                    int i = comma + 1;
+                    while (words.get(i).toString().compareTo(")") != 0) {
+                        secondCol += words.get(i).toString();
+                        i++;
+                    }
+                    secondCol += ")";
+                } else
+                    secondCol = words.get(comma).toString().trim();
+            }
+            // has only one column
+            else {
+                int i = fromIndx - 1;
+                while (firstPart.charAt(i) == ' ')
+                    i--;
+                String col = " ";
+                while (firstPart.charAt(i) != ' ') {
+                    col += firstPart.charAt(i);
+                    i--;
+                }
+                String reverse = " ";
+                for (i = (col.length() - 1); i >= 0; i--)
+                    reverse += col.charAt(i);
+                firstCol = reverse.trim();
+            }
+        }
+        if (first == true)
+            return firstCol;
+        else
+            return secondCol;
     }
 
-    //the result of the second query, to retrieve the value
-    public String getValue(String val, String sql, XWikiContext context) {
-       String firstCol = returnCol(sql, true);
-       String secondCol = returnCol(sql, false);
+    // the result of the second query, to retrieve the value
+    public String getValue(String val, String sql, XWikiContext context)
+    {
+        String firstCol = returnCol(sql, true);
+        String secondCol = returnCol(sql, false);
 
-       String newsql = sql.substring(0, sql.indexOf(firstCol));
-       newsql += secondCol + " ";
-       newsql += sql.substring(sql.indexOf("from"));
-       newsql += "and " + firstCol + "='" + val + "'";
+        String newsql = sql.substring(0, sql.indexOf(firstCol));
+        newsql += secondCol + " ";
+        newsql += sql.substring(sql.indexOf("from"));
+        newsql += "and " + firstCol + "='" + val + "'";
 
-       Object[] list = null;
-       XWiki xwiki = context.getWiki();
-       String res = "";
-       try {
-                       list = xwiki.search(newsql, context).toArray();
-                       if(list.length > 0) res = list[0].toString();
-               }catch(Exception e) {
-                       e.printStackTrace();
-               }
-       return res;
+        Object[] list = null;
+        XWiki xwiki = context.getWiki();
+        String res = "";
+        try {
+            list = xwiki.search(newsql, context).toArray();
+            if (list.length > 0)
+                res = list[0].toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return res;
     }
 
-
-    //override the method from parent ListClass
+    // override the method from parent ListClass
     public void displayEdit(StringBuffer buffer, String name, String prefix,
-            BaseCollection object, XWikiContext context)
-        {
-            //input display
-            if (getDisplayType().equals("input")) {
-               input input = new input();
-                input.setType("text");
-                input.setSize(getSize());
-                boolean changeInputName = false;
-                boolean setInpVal = true;
+        BaseCollection object, XWikiContext context)
+    {
+        // input display
+        if (getDisplayType().equals("input")) {
+            input input = new input();
+            input.setType("text");
+            input.setSize(getSize());
+            boolean changeInputName = false;
+            boolean setInpVal = true;
 
-                BaseProperty prop = (BaseProperty) object.safeget(name);
-                String val = "";
-                if (prop != null)  val = prop.toFormString();
+            BaseProperty prop = (BaseProperty) object.safeget(name);
+            String val = "";
+            if (prop != null)
+                val = prop.toFormString();
 
-                if(isPicker()) {
-                       input.addAttribute("autocomplete", "off");
-                       String path = "";
-                       try {
-                               XWiki xwiki = context.getWiki();
-                               path = xwiki.getURL("Main.WebHome", "view", 
context);
-                       } catch(XWikiException e) {
-                               e.printStackTrace();
-                         }
-                               String classname = this.getObject().getName();
-                               String fieldname = this.getName();
-                               String hibquery = this.getSql();
-                               String secondCol = "-", firstCol = "-";
+            if (isPicker()) {
+                input.addAttribute("autocomplete", "off");
+                String path = "";
+                try {
+                    XWiki xwiki = context.getWiki();
+                    path = xwiki.getURL("Main.WebHome", "view", context);
+                } catch (XWikiException e) {
+                    e.printStackTrace();
+                }
+                String classname = this.getObject().getName();
+                String fieldname = this.getName();
+                String hibquery = this.getSql();
+                String secondCol = "-", firstCol = "-";
 
-                               if(hibquery != null && !hibquery.equals("")) {
-                                       firstCol = returnCol(hibquery, true);
-                                       secondCol = returnCol(hibquery, false);
+                if (hibquery != null && !hibquery.equals("")) {
+                    firstCol = returnCol(hibquery, true);
+                    secondCol = returnCol(hibquery, false);
 
-                                       if(secondCol.compareTo("-") != 0) {
-                                               changeInputName = true;
-                                               input hidden = new input();
-                                               hidden.setID(prefix + name);
-                                               hidden.setName(prefix + name);
-                                               hidden.setType("hidden");
-                                               if(val != null && 
!val.equals("")) hidden.setValue(val);
-                                               
buffer.append(hidden.toString());
+                    if (secondCol.compareTo("-") != 0) {
+                        changeInputName = true;
+                        input hidden = new input();
+                        hidden.setID(prefix + name);
+                        hidden.setName(prefix + name);
+                        hidden.setType("hidden");
+                        if (val != null && !val.equals(""))
+                            hidden.setValue(val);
+                        buffer.append(hidden.toString());
 
-                                               input.setValue(getValue(val, 
hibquery, context));
-                                               setInpVal = false;
-                                       }
-                               }
-
-                               String script = 
"\""+path+"?xpage=suggest&amp;classname="+classname+"&amp;fieldname="+fieldname+"&amp;firCol="+firstCol+"&amp;secCol="+secondCol+"&amp;\"";
-                               String varname = "\"input\"";
-                           String seps = "\""+this.getSeparators()+"\"";
-                           if(isMultiSelect())
-                               input.setOnFocus("new ajaxSuggest(this, 
{script:"+script+", varname:"+varname+", seps:"+seps+"} )");
-                           else
-                               input.setOnFocus("new ajaxSuggest(this, 
{script:"+script+", varname:"+varname+"} )");
-
-
-
+                        input.setValue(getValue(val, hibquery, context));
+                        setInpVal = false;
+                    }
                 }
 
-                       if(changeInputName == true) {
-                                       input.setName(prefix + name + 
"_suggest");
-                                       input.setID(prefix + name + "_suggest");
-                       }
-                else {
-                                       input.setName(prefix + name);
-                                       input.setID(prefix + name);
-                                }
-                       if(setInpVal == true) input.setValue(val);
+                String script =
+                    "\"" + path + "?xpage=suggest&amp;classname=" + classname 
+ "&amp;fieldname="
+                        + fieldname + "&amp;firCol=" + firstCol + 
"&amp;secCol=" + secondCol
+                        + "&amp;\"";
+                String varname = "\"input\"";
+                String seps = "\"" + this.getSeparators() + "\"";
+                if (isMultiSelect())
+                    input.setOnFocus("new ajaxSuggest(this, {script:" + script 
+ ", varname:"
+                        + varname + ", seps:" + seps + "} )");
+                else
+                    input.setOnFocus("new ajaxSuggest(this, {script:" + script 
+ ", varname:"
+                        + varname + "} )");
 
-                buffer.append(input.toString());
+            }
 
-            } else if (getDisplayType().equals("radio") || 
getDisplayType().equals("checkbox")) {
-                displayRadioEdit(buffer, name, prefix, object, context);
+            if (changeInputName == true) {
+                input.setName(prefix + name + "_suggest");
+                input.setID(prefix + name + "_suggest");
             } else {
-                displaySelectEdit(buffer, name, prefix, object, context);
+                input.setName(prefix + name);
+                input.setID(prefix + name);
             }
+            if (setInpVal == true)
+                input.setValue(val);
 
-            if (!getDisplayType().equals("input")) {
-                org.apache.ecs.xhtml.input hidden = new input(input.hidden, 
prefix + name, "");
-                buffer.append(hidden);
-            }
+            buffer.append(input.toString());
+
+        } else if (getDisplayType().equals("radio") || 
getDisplayType().equals("checkbox")) {
+            displayRadioEdit(buffer, name, prefix, object, context);
+        } else {
+            displaySelectEdit(buffer, name, prefix, object, context);
         }
 
+        if (!getDisplayType().equals("input")) {
+            org.apache.ecs.xhtml.input hidden = new input(input.hidden, prefix 
+ name, "");
+            buffer.append(hidden);
+        }
+    }
+
     public void displayView(StringBuffer buffer, String name, String prefix,
-            BaseCollection object, XWikiContext context)
-        {
-               if(isPicker() && getSql().compareTo("") != 0) {
-                       BaseProperty prop = (BaseProperty) object.safeget(name);
-                       String val = "";
-                       if(prop != null) val = prop.toFormString();
-                       Map map = getMap(context);
+        BaseCollection object, XWikiContext context)
+    {
+        if (isPicker() && getSql().compareTo("") != 0) {
+            BaseProperty prop = (BaseProperty) object.safeget(name);
+            String val = "";
+            if (prop != null)
+                val = prop.toFormString();
+            Map map = getMap(context);
 
-                       String  secondCol = returnCol(getSql(), false);
-                       if(secondCol.compareTo("-") != 0) {
-                               String res = getValue(val, getSql(), context);
-                       buffer.append(getDisplayValue(res, name, map, context));
-                       }
-                       else buffer.append(getDisplayValue(val, name, map, 
context));
-               }
-               else {
-                               List selectlist;
-                    String separator = getSeparator();
-                    BaseProperty prop = (BaseProperty) object.safeget(name);
-                    Map map = getMap(context);
-                    if ((prop instanceof ListProperty) || (prop instanceof 
DBStringListProperty)) {
-                        selectlist = (List) prop.getValue();
-                        List newlist = new ArrayList();
-                        for (Iterator it = selectlist.iterator(); 
it.hasNext();) {
-                            newlist.add(getDisplayValue(it.next(), name, map, 
context));
-                        }
-                        buffer.append(StringUtils.join(newlist.toArray(), 
separator));
-                    } else {
-                       buffer.append(getDisplayValue(prop.getValue(), name, 
map, context));
-                    }
-               }
+            String secondCol = returnCol(getSql(), false);
+            if (secondCol.compareTo("-") != 0) {
+                String res = getValue(val, getSql(), context);
+                buffer.append(getDisplayValue(res, name, map, context));
+            } else
+                buffer.append(getDisplayValue(val, name, map, context));
+        } else {
+            List selectlist;
+            String separator = getSeparator();
+            BaseProperty prop = (BaseProperty) object.safeget(name);
+            Map map = getMap(context);
+            if ((prop instanceof ListProperty) || (prop instanceof 
DBStringListProperty)) {
+                selectlist = (List) prop.getValue();
+                List newlist = new ArrayList();
+                for (Iterator it = selectlist.iterator(); it.hasNext();) {
+                    newlist.add(getDisplayValue(it.next(), name, map, 
context));
+                }
+                buffer.append(StringUtils.join(newlist.toArray(), separator));
+            } else {
+                buffer.append(getDisplayValue(prop.getValue(), name, map, 
context));
+            }
         }
+    }
 
 }

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to