4545import com .aliyun .oss .model .InventoryOSSBucketDestination ;
4646import com .aliyun .oss .model .InventorySchedule ;
4747import com .aliyun .oss .model .InventoryServerSideEncryptionKMS ;
48+ import com .aliyun .oss .model .ListObjectsV2Result ;
4849import org .jdom .Document ;
4950import org .jdom .Element ;
5051import org .jdom .input .JDOMParseException ;
@@ -183,6 +184,7 @@ public final class ResponseParsers {
183184 public static final GetBucketInventoryConfigurationParser getBucketInventoryConfigurationParser = new GetBucketInventoryConfigurationParser ();
184185 public static final ListBucketInventoryConfigurationsParser listBucketInventoryConfigurationsParser = new ListBucketInventoryConfigurationsParser ();
185186 public static final ListObjectsReponseParser listObjectsReponseParser = new ListObjectsReponseParser ();
187+ public static final ListObjectsV2ResponseParser listObjectsV2ResponseParser = new ListObjectsV2ResponseParser ();
186188 public static final ListVersionsReponseParser listVersionsReponseParser = new ListVersionsReponseParser ();
187189 public static final PutObjectReponseParser putObjectReponseParser = new PutObjectReponseParser ();
188190 public static final PutObjectProcessReponseParser putObjectProcessReponseParser = new PutObjectProcessReponseParser ();
@@ -747,6 +749,21 @@ public ObjectListing parse(ResponseMessage response) throws ResponseParseExcepti
747749 }
748750
749751 }
752+
753+ public static final class ListObjectsV2ResponseParser implements ResponseParser <ListObjectsV2Result > {
754+
755+ @ Override
756+ public ListObjectsV2Result parse (ResponseMessage response ) throws ResponseParseException {
757+ try {
758+ ListObjectsV2Result result = parseListObjectsV2 (response .getContent ());
759+ result .setRequestId (response .getRequestId ());
760+ return result ;
761+ } finally {
762+ safeCloseResponse (response );
763+ }
764+ }
765+
766+ }
750767
751768 public static final class ListVersionsReponseParser implements ResponseParser <VersionListing > {
752769
@@ -1194,6 +1211,10 @@ public static ObjectListing parseListObjects(InputStream responseBody) throws Re
11941211 ossObjectSummary .setStorageClass (elem .getChildText ("StorageClass" ));
11951212 ossObjectSummary .setBucketName (objectListing .getBucketName ());
11961213
1214+ if (elem .getChild ("Type" ) != null ) {
1215+ ossObjectSummary .setType (elem .getChildText ("Type" ));
1216+ }
1217+
11971218 String id = elem .getChild ("Owner" ).getChildText ("ID" );
11981219 String displayName = elem .getChild ("Owner" ).getChildText ("DisplayName" );
11991220 ossObjectSummary .setOwner (new Owner (id , displayName ));
@@ -1217,6 +1238,93 @@ public static ObjectListing parseListObjects(InputStream responseBody) throws Re
12171238 }
12181239
12191240 }
1241+
1242+ /**
1243+ * Unmarshall list objects response body to ListObjectsV2Result.
1244+ */
1245+ @ SuppressWarnings ("unchecked" )
1246+ public static ListObjectsV2Result parseListObjectsV2 (InputStream responseBody ) throws ResponseParseException {
1247+
1248+ try {
1249+ Element root = getXmlRootElement (responseBody );
1250+
1251+ ListObjectsV2Result result = new ListObjectsV2Result ();
1252+ result .setBucketName (root .getChildText ("Name" ));
1253+ result .setMaxKeys (Integer .valueOf (root .getChildText ("MaxKeys" )));
1254+ result .setTruncated (Boolean .valueOf (root .getChildText ("IsTruncated" )));
1255+ result .setKeyCount (Integer .valueOf (root .getChildText ("KeyCount" )));
1256+
1257+ if (root .getChild ("Prefix" ) != null ) {
1258+ String prefix = root .getChildText ("Prefix" );
1259+ result .setPrefix (isNullOrEmpty (prefix ) ? null : prefix );
1260+ }
1261+
1262+ if (root .getChild ("Delimiter" ) != null ) {
1263+ String delimiter = root .getChildText ("Delimiter" );
1264+ result .setDelimiter (isNullOrEmpty (delimiter ) ? null : delimiter );
1265+ }
1266+
1267+ if (root .getChild ("ContinuationToken" ) != null ) {
1268+ String continuationToken = root .getChildText ("ContinuationToken" );
1269+ result .setContinuationToken (isNullOrEmpty (continuationToken ) ? null : continuationToken );
1270+ }
1271+
1272+ if (root .getChild ("NextContinuationToken" ) != null ) {
1273+ String nextContinuationToken = root .getChildText ("NextContinuationToken" );
1274+ result .setNextContinuationToken (isNullOrEmpty (nextContinuationToken ) ? null : nextContinuationToken );
1275+ }
1276+
1277+ if (root .getChild ("EncodingType" ) != null ) {
1278+ String encodeType = root .getChildText ("EncodingType" );
1279+ result .setEncodingType (isNullOrEmpty (encodeType ) ? null : encodeType );
1280+ }
1281+
1282+ if (root .getChild ("StartAfter" ) != null ) {
1283+ String startAfter = root .getChildText ("StartAfter" );
1284+ result .setStartAfter (isNullOrEmpty (startAfter ) ? null : startAfter );
1285+ }
1286+
1287+ List <Element > objectSummaryElems = root .getChildren ("Contents" );
1288+ for (Element elem : objectSummaryElems ) {
1289+ OSSObjectSummary ossObjectSummary = new OSSObjectSummary ();
1290+
1291+ ossObjectSummary .setKey (elem .getChildText ("Key" ));
1292+ ossObjectSummary .setETag (trimQuotes (elem .getChildText ("ETag" )));
1293+ ossObjectSummary .setLastModified (DateUtil .parseIso8601Date (elem .getChildText ("LastModified" )));
1294+ ossObjectSummary .setSize (Long .valueOf (elem .getChildText ("Size" )));
1295+ ossObjectSummary .setStorageClass (elem .getChildText ("StorageClass" ));
1296+ ossObjectSummary .setBucketName (result .getBucketName ());
1297+
1298+ if (elem .getChild ("Type" ) != null ) {
1299+ ossObjectSummary .setType (elem .getChildText ("Type" ));
1300+ }
1301+
1302+ if (elem .getChild ("Owner" ) != null ) {
1303+ String id = elem .getChild ("Owner" ).getChildText ("ID" );
1304+ String displayName = elem .getChild ("Owner" ).getChildText ("DisplayName" );
1305+ ossObjectSummary .setOwner (new Owner (id , displayName ));
1306+ }
1307+
1308+ result .addObjectSummary (ossObjectSummary );
1309+ }
1310+
1311+ List <Element > commonPrefixesElems = root .getChildren ("CommonPrefixes" );
1312+
1313+ for (Element elem : commonPrefixesElems ) {
1314+ String prefix = elem .getChildText ("Prefix" );
1315+ if (!isNullOrEmpty (prefix )) {
1316+ result .addCommonPrefix (prefix );
1317+ }
1318+ }
1319+
1320+ return result ;
1321+ } catch (JDOMParseException e ) {
1322+ throw new ResponseParseException (e .getPartialDocument () + ": " + e .getMessage (), e );
1323+ } catch (Exception e ) {
1324+ throw new ResponseParseException (e .getMessage (), e );
1325+ }
1326+
1327+ }
12201328
12211329 /**
12221330 * Unmarshall list objects response body to object listing.
@@ -2392,12 +2500,14 @@ public static BucketInfo parseGetBucketInfo(InputStream responseBody) throws Res
23922500 bucketInfo .setBucket (bucket );
23932501
23942502 // comment
2395- String comment = bucketElem .getChildText ("Comment" );
2396- bucketInfo .setComment (comment );
2503+ if (bucketElem .getChild ("Comment" ) != null ) {
2504+ String comment = bucketElem .getChildText ("Comment" );
2505+ bucketInfo .setComment (comment );
2506+ }
23972507
23982508 // data redundancy type
2399- String dataRedundancyString = bucketElem .getChildText ("DataRedundancyType" );
2400- if ( dataRedundancyString != null ) {
2509+ if ( bucketElem .getChild ("DataRedundancyType" ) != null ) {
2510+ String dataRedundancyString = bucketElem . getChildText ( "DataRedundancyType" );
24012511 DataRedundancyType dataRedundancyType = DataRedundancyType .parse (dataRedundancyString );
24022512 bucketInfo .setDataRedundancyType (dataRedundancyType );
24032513 }
0 commit comments