private String parseMetadata ( DocumentMetadata metadata ) throws IOException { ResultItem item = result . next ( ) ; String uri = item . asString ( ) ; if ( uri == null ) { throw new IOException ( "Missing document URI for metadata." ) ; } item = result . next ( ) ; //node-kind, must exist String nKind = item . asString ( ) ; metadata . setFormat ( nKind ) ; item = result . next ( ) ; // handle collections, may not be present while ( item != null && item . getItemType ( ) == ValueType . XS_STRING ) { if ( ! copyCollection ) { item = result . next ( ) ; continue ; } metadata . addCollection ( item . asString ( ) ) ; item = result . next ( ) ; } // handle permissions, may not be present StringBuilder buf = new StringBuilder ( ) ; buf . append ( "<perms>" ) ; while ( item != null && ValueType . ELEMENT == item . getItemType ( ) ) { if ( ! copyPermission ) { item = result . next ( ) ; continue ; } try { readPermission ( ( XdmElement ) item . getItem ( ) , metadata , buf ) ; } catch ( Exception e ) { throw new IOException ( e ) ; } item = result . next ( ) ; } buf . append ( "</perms>" ) ; metadata . setPermString ( buf . toString ( ) ) ; // handle quality, always present even if not requested (barrier) metadata . setQuality ( ( XSInteger ) item . getItem ( ) ) ; // handle metadata item = result . next ( ) ; if ( copyMetadata ) { XdmItem metaItem = item . getItem ( ) ; if ( metaItem instanceof JsonItem ) { JsonNode node = ( ( JsonItem ) metaItem ) . asJsonNode ( ) ; metadata . meta = new HashMap < String , String > ( node . size ( ) ) ; for ( Iterator < String > names = node . fieldNames ( ) ; names . hasNext ( ) ; ) { String key = names . next ( ) ; JsonNode nodeVal = node . get ( key ) ; metadata . meta . put ( key , nodeVal . asText ( ) ) ; } item = result . next ( ) ; } } // handle prop:properties node, optional // if not present, there will be a 0 as a marker if ( copyProperties && ValueType . ELEMENT == item . getItemType ( ) ) { String pString = item . asString ( ) ; if ( pString != null ) { metadata . setProperties ( pString ) ; } item = result . next ( ) ; } if ( ValueType . XS_INTEGER != item . getItemType ( ) ) { throw new IOException ( uri + " unexpected " + item . getItemType ( ) + " " + item . asString ( ) + ", expected " + ValueType . XS_INTEGER + " 0" ) ; } return uri ; }
Parse metadata from the sequence store it into the DocumentMetadata object passed in