Ignore:
Timestamp:
2009-10-04T12:39:37+02:00 (15 years ago)
Author:
Gubaer
Message:

Fixes provided by stoeckr, got accidentally overwritten in r2243

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java

    r2243 r2244  
    8181        }
    8282
     83        protected long getAttributeLong(Attributes attr, String name, long defaultValue) throws SAXException{
     84            String v = attr.getValue(name);
     85            if (v == null)
     86                return defaultValue;
     87            Long l = 0l;
     88            try {
     89                l = Long.parseLong(v);
     90            } catch(NumberFormatException e) {
     91                throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v));
     92            }
     93            if (l < 0) {
     94                throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long (>=0). Got ''{1}''.", name, v));
     95            }
     96            return l;
     97        }
     98
    8399        protected Double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{
    84100            String v = attr.getValue(name);
     
    86102                throwException(tr("Missing mandatory attribute ''{0}''.", name));
    87103            }
    88             double d = 0;
     104            double d = 0.0;
    89105            try {
    90106                d = Double.parseDouble(v);
     
    92108                throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v));
    93109            }
    94             if (d < 0) {
    95                 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double (>=0). Got ''{1}''.", name, v));
    96             }
    97110            return d;
    98111        }
     
    103116                throwException(tr("Missing mandatory attribute ''{0}''.", name));
    104117            }
     118            return v;
     119        }
     120
     121        protected String getAttributeString(Attributes attr, String name, String defaultValue) {
     122            String v = attr.getValue(name);
     123            if (v == null)
     124                return defaultValue;
    105125            return v;
    106126        }
     
    123143            long changesetId = getMandatoryAttributeLong(atts,"changeset");
    124144            boolean visible= getMandatoryAttributeBoolean(atts, "visible");
    125             long uid = getMandatoryAttributeLong(atts, "uid");
    126             String user = getMandatoryAttributeString(atts, "user");
     145            long uid = getAttributeLong(atts, "uid",-1);
     146            String user = getAttributeString(atts, "user", tr("<anonymous>"));
    127147            String v = getMandatoryAttributeString(atts, "timestamp");
    128148            Date timestamp = DateUtils.fromString(v);
Note: See TracChangeset for help on using the changeset viewer.