FileDocCategorySizeDatePackage
SAXParserTestSupport.javaAPI DocAndroid 1.5 API19647Wed May 06 22:41:06 BST 2009tests.api.javax.xml.parsers

SAXParserTestSupport

public class SAXParserTestSupport extends Object
Support for SAXParserTest. Shares the element keys used in the golden files. Compares the result of the parser with golden data. Contains the handler classes used to track the output of the parser.

Fields Summary
public static final char
SEPARATOR_ELEMENT
public static final char
SEPARATOR_STRING
public static final char
SEPARATOR_DATA
public static final String
XML_WF
public static final String
XML_NWF
public static final String
XML_WF_OUT_DH
public static final String
XML_WF_OUT_HB
public static final String
XML_SYSTEM_ID
public static final String
KEY_IS_START_DOC
public static final String
KEY_IS_END_DOC
public static final String
KEY_TEXT
public static final String
KEY_ERROR
public static final String
KEY_FATAL_ERROR
public static final String
KEY_WARNING
public static final String
KEY_END_ELEMENT
public static final String
KEY_END_PREFIX_MAPPING
public static final String
KEY_IGNORABLE_WHITE_SPACE
public static final String
KEY_NOTATION_DECL
public static final String
KEY_PROCESSING_INSTRUCTION
public static final String
KEY_RESOLVE_ENTITY
public static final String
KEY_DOCUMENT_LOCATORS
public static final String
KEY_SKIPPED_ENTITY
public static final String
KEY_START_ELEMENT
public static final String
KEY_START_PREFIX_MAPPING
public static final String
KEY_UNPARSED_ENTITY_DECL
static String[]
KEYS
Constructors Summary
Methods Summary
public static booleanequalsMaps(java.util.HashMap original, java.util.HashMap result)
Compares the content of two HashMaps. One map should be the reference containing the correct string for each xml document element and the other should contain the elements filled with output from the parser.

param
original the reference
param
result the result of the parser
return
true if they're equal.


        if(original == null && result == null) {
            return true;
        } else {
            if(original.size() != result.size()) return false;

            for(int i = 0; i < KEYS.length; i++) {
                if(!original.get(KEYS[i]).equals(result.get(KEYS[i]))) {
                    System.out.println("for "+KEYS[i]+": original:" + 
                            original.get(KEYS[i]));
                    System.out.println();
                    System.out.println("  result:" + result.get(KEYS[i]));
                    System.out.println();
                    return false;
                }
            }
            return true;
        }
    
public java.util.HashMapreadFile(java.lang.String fileName)
Initialize the SAXParserTest reference by filling in the data from the file passed to the method. This will be the reference to compare against with the output of the parser.


     
        String tmp = System.getProperty("java.io.tmpdir", ".");
        
        new File(tmp).mkdirs();
        new File(tmp, XML_WF).mkdirs();
        new File(tmp, XML_NWF).mkdirs();
        new File(tmp, XML_WF_OUT_DH).mkdirs();
        new File(tmp, XML_WF_OUT_HB).mkdirs();
    
        HashMap<String, String> storage = new HashMap<String, String>();
        try {

            InputStream is = new FileInputStream(fileName);

            int c = is.read();

            StringBuffer str = new StringBuffer();
            int i = 0;
            while(c != -1) {
                if((char)c == SEPARATOR_DATA) {
                  //  if(str.length() > 0) {
                        if(i < KEYS.length) {
                            storage.put(KEYS[i], str.toString());
                        //    System.out.println(str.toString());
                            str.setLength(0);
                            i++;
                        }
                  //  }
                } else {
                    str.append((char)c);
                }
                try {
                    c = is.read();
                } catch (Exception e) {
                    c = -1;
                }
            }
            try {
                is.close();
            } catch (IOException e) {
            }

        } catch(IOException ioe) {
            System.out.println("IOException during processing the file: "
                    + fileName);
        }
        return storage;