Author: julien(a)jboss.com
Date: 2007-03-07 11:07:04 -0500 (Wed, 07 Mar 2007)
New Revision: 6576
Added:
trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java
Modified:
trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/DataType.java
Log:
support various data types
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java 2007-03-07
15:40:11 UTC (rev 6575)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java 2007-03-07
16:07:04 UTC (rev 6576)
@@ -25,6 +25,12 @@
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.util.LocalizedString;
import org.jboss.portal.widget.google.type.DataType;
+import org.jboss.portal.widget.google.type.StringType;
+import org.jboss.portal.widget.google.type.LocationType;
+import org.jboss.portal.widget.google.type.HiddenType;
+import org.jboss.portal.widget.google.type.BoolType;
+import org.jboss.portal.widget.google.type.ListType;
+import org.jboss.portal.widget.google.type.EnumType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -72,13 +78,13 @@
Iterator userPrefsEltIterator = XML.getChildrenIterator(moduleElt,
"UserPref");
while (userPrefsEltIterator.hasNext())
{
- Element userPrefs = (Element)userPrefsEltIterator.next();
- String nameAttr = userPrefs.getAttribute("name");
- String displayNameAttr = userPrefs.getAttribute("displayName");
- String urlParamAttr = userPrefs.getAttribute("urlparam");
- String dataTypeAttr = userPrefs.getAttribute("datatype");
- String requiredAttr = userPrefs.getAttribute("required");
- String defaultValueAttr = userPrefs.getAttribute("default_value");
+ Element userPref = (Element)userPrefsEltIterator.next();
+ String nameAttr = userPref.getAttribute("name");
+ String displayNameAttr = userPref.getAttribute("displayName");
+ String urlParamAttr = userPref.getAttribute("urlparam");
+ String dataTypeAttr = userPref.getAttribute("datatype");
+ String requiredAttr = userPref.getAttribute("required");
+ String defaultValueAttr = userPref.getAttribute("default_value");
// We don't support that for now
if (urlParamAttr.length() > 0)
@@ -87,11 +93,40 @@
}
// String is default type when not specified
- DataType dataType = DataType.STRING_TYPE;
+ DataType dataType = StringType.getInstance();
if (dataTypeAttr.length() > 0)
{
- int dataTypeValue = DataType.parseDataTypeLiteral(dataTypeAttr);
- dataType = new DataType(dataTypeValue);
+ int dataTypeOrdinal = DataType.parseDataTypeLiteral(dataTypeAttr);
+ switch(dataTypeOrdinal)
+ {
+ case DataType.HIDDEN:
+ dataType = HiddenType.getInstance();
+ break;
+ case DataType.BOOL:
+ dataType = BoolType.getInstance();
+ break;
+ case DataType.STRING:
+ dataType = StringType.getInstance();
+ break;
+ case DataType.LIST:
+ dataType = ListType.getInstance();
+ break;
+ case DataType.ENUM:
+ Collection values = new ArrayList();
+ for (Iterator i = XML.getChildrenIterator(userPref,
"EnumValue");i.hasNext();)
+ {
+ Element enumValueElt = (Element)i.next();
+ String valueAttr = enumValueElt.getAttribute("value");
+ String displayValueAttr =
enumValueElt.getAttribute("display_value");
+ EnumType.Value value = new EnumType.Value(valueAttr,
displayValueAttr.length() > 0 ? displayValueAttr : null);
+ values.add(value);
+ }
+ dataType = new EnumType(values);
+ break;
+ case DataType.LOCATION:
+ dataType = LocationType.getInstance();
+ break;
+ }
}
//
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java 2007-03-07
16:07:04 UTC (rev 6576)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.widget.google.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class BoolType extends DataType
+{
+
+ /** . */
+ private static final BoolType INSTANCE = new BoolType();
+
+ public static BoolType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private BoolType()
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return BOOL;
+ }
+}
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/type/DataType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/DataType.java 2007-03-07
15:40:11 UTC (rev 6575)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/DataType.java 2007-03-07
16:07:04 UTC (rev 6576)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class DataType
+public abstract class DataType
{
/** . */
@@ -47,36 +47,8 @@
/** . */
public static final int LOCATION = 5;
- /** . */
- public static final DataType STRING_TYPE = new DataType(STRING);
+ public abstract int getOrdinal();
- /** . */
- private final int value;
-
- /** . */
- private final Object object;
-
- public DataType(int ordinal)
- {
- this(ordinal, null);
- }
-
- public DataType(int dataType, Object dataObject)
- {
- this.value = dataType;
- this.object = dataObject;
- }
-
- public int getValue()
- {
- return value;
- }
-
- public Object getObject()
- {
- return object;
- }
-
public static int parseDataTypeLiteral(String literal)
{
if ("string".equals(literal))
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java 2007-03-07
16:07:04 UTC (rev 6576)
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.widget.google.type;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class EnumType extends DataType
+{
+
+ /** . */
+ private final ArrayList values;
+
+ public EnumType(Collection values)
+ {
+ this.values = new ArrayList(values.size());
+
+ // We just check that objects contained are of the right type
+ for (Iterator i = values.iterator();i.hasNext();)
+ {
+ Value value = (Value)i.next();
+ values.add(value);
+ }
+ }
+
+ public int getSize()
+ {
+ return values.size();
+ }
+
+ public Value getValue(int index)
+ {
+ return (Value)values.get(index);
+ }
+
+ public int getOrdinal()
+ {
+ return ENUM;
+ }
+
+ public static class Value
+ {
+
+ /** . */
+ private final String value;
+
+ /** . */
+ private final String displayValue;
+
+ public Value(String value, String displayValue)
+ {
+ this.value = value;
+ this.displayValue = displayValue;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public String getDisplayValue()
+ {
+ return displayValue;
+ }
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java 2007-03-07
16:07:04 UTC (rev 6576)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.widget.google.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class HiddenType extends DataType
+{
+
+ /** . */
+ private static final HiddenType INSTANCE = new HiddenType();
+
+ public static HiddenType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private HiddenType()
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return HIDDEN;
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java 2007-03-07
16:07:04 UTC (rev 6576)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.widget.google.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ListType extends DataType
+{
+
+ /** . */
+ private static final ListType INSTANCE = new ListType();
+
+ public static ListType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private ListType()
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return LIST;
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java 2007-03-07
16:07:04 UTC (rev 6576)
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.widget.google.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class LocationType extends DataType
+{
+
+ /** . */
+ private static final LocationType INSTANCE = new LocationType();
+
+ public static LocationType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return LOCATION;
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java 2007-03-07
16:07:04 UTC (rev 6576)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.widget.google.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class StringType extends DataType
+{
+
+ /** . */
+ private static final StringType INSTANCE = new StringType();
+
+ public static StringType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private StringType()
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return STRING;
+ }
+}