Changeset 2751

Show
Ignore:
Timestamp:
08/14/09 15:32:28 (12 months ago)
Author:
csims
Message:

More parsing updates

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/dev-dd/org.javarosa.graphing/src/org/javarosa/graphing/parser/StatisticsXMLParser.java

    r2750 r2751  
    77import java.io.InputStream; 
    88import java.io.InputStreamReader; 
    9 import java.util.Hashtable; 
    109 
     10import org.javarosa.core.util.OrderedHashtable; 
    1111import org.javarosa.graphing.model.StatisticsModel; 
    1212import org.javarosa.graphing.model.StatisticsReport; 
    1313import org.kxml2.io.KXmlParser; 
    14 import org.kxml2.io.KXmlSerializer; 
    1514import org.kxml2.kdom.Document; 
    1615import org.kxml2.kdom.Element; 
     
    2322 */ 
    2423public class StatisticsXMLParser { 
    25         Hashtable handlers = new Hashtable(); 
    26          
    27         private interface ElementHandler { 
    28                 public void handle(Element e, StatisticsModel m) throws StatisticsXmlParseException; 
    29         } 
    3024         
    3125        public StatisticsXMLParser() { 
     
    10195                 
    10296                String name = e.getAttributeValue(null,"name"); 
    103                 String index = e.getAttributeValue(null,"index"); 
     97                String index = e.getAttributeValue(null,"indices"); 
    10498                if(name != null) { 
    10599                        modelName = name; 
     
    108102                } 
    109103                 
    110                 Hashtable fullData = new Hashtable(); 
     104                OrderedHashtable fullData = new OrderedHashtable(); 
     105                 
     106                try { 
     107                        e = e.getElement("","valuesets"); 
     108                } catch(Exception ex) { 
     109                        ex.printStackTrace(); 
     110                        throw new StatisticsXmlParseException("No Value Sets in Dataset"); 
     111                } 
    111112                 
    112113                int childElements = e.getChildCount(); 
     
    117118                        Element child = e.getElement(i); 
    118119                        if(child.getName().equals("values")) { 
    119                                 String entryType = child.getAttributeValue(null, "value"); 
     120                                String entryType = child.getAttributeValue(null, "name"); 
    120121                                if(primaryEntry == null) { 
    121122                                        primaryEntry = entryType; 
    122123                                } 
    123124                                entityTitle = index;  
    124                                 Hashtable entries = parseEntries(child); 
     125                                OrderedHashtable entries = parseEntries(child); 
    125126                                fullData.put(entryType, entries); 
    126127                        } else { 
     
    134135        } 
    135136         
    136         private Hashtable parseEntries(Element entities) throws StatisticsXmlParseException { 
    137                 Hashtable entries = new Hashtable(); 
     137        private OrderedHashtable parseEntries(Element entities) throws StatisticsXmlParseException { 
     138                OrderedHashtable entries = new OrderedHashtable(); 
    138139                int childElements = entities.getChildCount(); 
    139140                for(int i = 0; i < childElements; ++i) { 
     
    142143                        } else { 
    143144                        Element child = entities.getElement(i); 
    144                         if(child.getName().equals("entry")) { 
     145                        if(child.getName().equals("value")) { 
    145146                                try{ 
    146147                                        String key = (String)child.getAttributeValue("","index"); 
     
    152153                                } 
    153154                        } else { 
    154                                 throw new StatisticsXmlParseException("All entry children must be elements"); 
     155                                System.out.println("Non value element of valueset: " + child.getName()); 
    155156                        } 
    156157                        }