Update of /var/cvs/applications/dove/src/org/mmbase/applications/dove
In directory james.mmbase.org:/tmp/cvs-serv18739

Modified Files:
      Tag: MMBase-1_8
        Dove.java 
Log Message:
  MMB-1636


See also: 
http://cvs.mmbase.org/viewcvs/applications/dove/src/org/mmbase/applications/dove
See also: http://www.mmbase.org/jira/browse/MMB-1636


Index: Dove.java
===================================================================
RCS file: 
/var/cvs/applications/dove/src/org/mmbase/applications/dove/Dove.java,v
retrieving revision 1.78.2.7
retrieving revision 1.78.2.8
diff -u -b -r1.78.2.7 -r1.78.2.8
--- Dove.java   19 Mar 2008 12:04:01 -0000      1.78.2.7
+++ Dove.java   2 Apr 2008 14:49:35 -0000       1.78.2.8
@@ -54,7 +54,7 @@
  *
  * @author Pierre van Rooden
  * @since MMBase-1.5
- * @version $Id: Dove.java,v 1.78.2.7 2008/03/19 12:04:01 andre Exp $
+ * @version $Id: Dove.java,v 1.78.2.8 2008/04/02 14:49:35 michiel Exp $
  */
 
 public class Dove extends AbstractDove {
@@ -155,7 +155,7 @@
         fel.setAttribute(ELM_TYPE, dataType.getBaseTypeIdentifier());
         fel.setAttribute(ELM_NAME, fname);
         fel.setAttribute("nodemanager", nm.getName());
-        Iterator i = 
dataType.getEnumerationValues(node.getCloud().getLocale(), node.getCloud(), 
node, f);
+        Iterator i = getOptionList(dataType, node.getCloud(), node, f);
         if (i != null) {
             Element ol = addContentElement("optionlist", "", out);
             ol.setAttribute("name", "_" + node.getNodeManager().getName() + 
"_" + f.getName());
@@ -172,6 +172,45 @@
         }
         return fel;
     }
+
+    private Iterator  getOptionList(DataType dataType, Cloud cloud, 
org.mmbase.bridge.Node node, Field f) {
+        Iterator i = dataType.getEnumerationValues(cloud.getLocale(), cloud, 
node, f);
+        if (i != null) return i;
+
+        long min = Long.MIN_VALUE;
+        long max = Long.MAX_VALUE;
+        if (dataType instanceof IntegerDataType) {
+            IntegerDataType idt = (IntegerDataType) dataType;
+            min = idt.getMin() + (idt.isMinInclusive() ? 0 : 1);
+            max = idt.getMax() - (idt.isMaxInclusive() ? 0 : 1);
+        }
+
+
+        if (dataType instanceof LongDataType) {
+            LongDataType ldt = (LongDataType) dataType;
+            min = ldt.getMin() + (ldt.isMinInclusive() ? 0 : 1);
+            max = ldt.getMax() - (ldt.isMaxInclusive() ? 0 : 1);
+        }
+        if ((double) max - min < 200.0) {
+            final long end = max;
+            final long start = min;
+            return new Iterator() {
+                long value = start;
+                public boolean hasNext() {
+                    return value <= end;
+                }
+                public Object next() {
+                    Long v = new Long(value++);
+                    return new org.mmbase.util.Entry(v, v);
+                }
+                public void remove() {
+                    throw new UnsupportedOperationException();
+                }
+            };
+        }
+        return null;
+
+    }
     /**
      * Handles a node storing its content in a DOM element.
      * This method accepts a object to store, as well as a DOM element, which
@@ -316,7 +355,7 @@
             data.setAttribute(ELM_NUMBER, ""+nrel.getNumber());
             out.appendChild(data);
             getDataNode(relation, data, nrel);
-            if (objectDef!=null) {
+            if (objectDef != null) {
                 Element nodeData = doc.createElement(OBJECT);
                 nodeData.setAttribute(ELM_NUMBER, ""+otherNumber);
                 data.appendChild(nodeData);
@@ -627,7 +666,7 @@
                             specialization = origin.getName();
                         }
                     }
-                    if 
(dataType.getEnumerationValues(nm.getCloud().getLocale(), nm.getCloud(), null, 
fielddef) != null) {
+                    if (getOptionList(dataType, nm.getCloud(), null, fielddef) 
!= null) {
                         specialization = "enum";
                     } else if (dataType instanceof StringDataType) {
                         if (((StringDataType) 
dataType).getPattern().matcher("a\na").matches()) {
@@ -651,7 +690,8 @@
                             baseType = "string";
                         } else if (dataType instanceof BinaryDataType) {
                             Pattern p = ((BinaryDataType) 
dataType).getValidMimeTypes();
-                            if (p.matcher("image/someimageformat").matches()) {
+                            if (p.matcher("image/someimageformat").matches() &&
+                                ! 
p.matcher("application/nonimageformat").matches()) {
                                 specialization = "image";
                             } else {
                                 specialization = "file";
@@ -1312,7 +1352,7 @@
                 }
             } else {
                 // give error not a org. node
-                Element err = addContentElement(ERROR,"Invalid status 
"+status+" for node : "+alias,out);
+                Element err = addContentElement(ERROR,"Invalid status '" + 
status + "' for node : "+alias,out);
                 err.setAttribute(ELM_TYPE, IS_SERVER);
                 return false;
             }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to