}
if( !"doc".equals( parser.getLocalName().toLowerCase(Locale.ENGLISH) ) ) {
throw new RuntimeException( "must be 'lst', not: "+parser.getLocalName() );
}
SolrDocument doc = new SolrDocument();
StringBuilder builder = new StringBuilder();
KnownType type = null;
String name = null;
// just eat up the events...
int depth = 0;
while( true )
{
switch (parser.next()) {
case XMLStreamConstants.START_ELEMENT:
depth++;
builder.setLength( 0 ); // reset the text
type = KnownType.get( parser.getLocalName() );
if( type == null ) {
throw new RuntimeException( "this must be known type! not: "+parser.getLocalName() );
}
name = null;
int cnt = parser.getAttributeCount();
for( int i=0; i<cnt; i++ ) {
if( "name".equals( parser.getAttributeLocalName( i ) ) ) {
name = parser.getAttributeValue( i );
break;
}
}
if( name == null ) {
throw new XMLStreamException( "requires 'name' attribute: "+parser.getLocalName(), parser.getLocation() );
}
// Handle multi-valued fields
if( type == KnownType.ARR ) {
for( Object val : readArray( parser ) ) {
doc.addField( name, val );
}
depth--; // the array reading clears out the 'endElement'
}
else if( !type.isLeaf ) {
throw new XMLStreamException( "must be value or array", parser.getLocation() );
}
break;
case XMLStreamConstants.END_ELEMENT:
if( --depth < 0 ) {
return doc;
}
//System.out.println( "FIELD:"+type+"::"+name+"::"+builder );
Object val = type.read( builder.toString().trim() );
if( val == null ) {
throw new XMLStreamException( "error reading value:"+type, parser.getLocation() );
}
doc.addField( name, val );
break;
case XMLStreamConstants.SPACE: // TODO? should this be trimmed? make sure it only gets one/two space?
case XMLStreamConstants.CDATA:
case XMLStreamConstants.CHARACTERS: