See OWASP
- * XXE Cheat Sheet
- *
- * @param reader the reader to disable the features on
- * @throws SAXNotRecognizedException
- * @throws SAXNotSupportedException
- */
- private void disableExternalResourceFetching(XMLReader reader)
- throws SAXNotRecognizedException, SAXNotSupportedException {
- reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
- reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
- reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
- }
-
- /**
- * Checks if the specified string is empty or null and if so, returns null. Otherwise simply
- * returns the string.
- *
- * @param s The string to check.
- * @return Null if the specified string was null, or empty, otherwise returns the string the
- * caller passed in.
- */
- private static String checkForEmptyString(String s) {
- if (s == null) return null;
- if (s.length() == 0) return null;
-
- return s;
- }
-
- /**
- * Safely parses the specified string as an integer and returns the value. If a
- * NumberFormatException occurs while parsing the integer, an error is logged and -1 is
- * returned.
- *
- * @param s The string to parse and return as an integer.
- * @return The integer value of the specified string, otherwise -1 if there were any problems
- * parsing the string as an integer.
- */
- private static int parseInt(String s) {
- try {
- return Integer.parseInt(s);
- } catch (NumberFormatException nfe) {
- log.error("Unable to parse integer value '" + s + "'", nfe);
- }
-
- return -1;
- }
-
- /**
- * Safely parses the specified string as a long and returns the value. If a
- * NumberFormatException occurs while parsing the long, an error is logged and -1 is returned.
- *
- * @param s The string to parse and return as a long.
- * @return The long value of the specified string, otherwise -1 if there were any problems
- * parsing the string as a long.
- */
- private static long parseLong(String s) {
- try {
- return Long.parseLong(s);
- } catch (NumberFormatException nfe) {
- log.error("Unable to parse long value '" + s + "'", nfe);
- }
-
- return -1;
- }
-
- /** Perform a url decode on the given value if specified. Return value by default; */
- private static String decodeIfSpecified(String value, boolean decode) {
- return decode ? SdkHttpUtils.urlDecode(value) : value;
- }
-
- /**
- * Parses a ListBucket response XML document from an input stream.
- *
- * @param inputStream XML data input stream.
- * @return the XML handler object populated with data parsed from the XML stream.
- * @throws SdkClientException
- */
- public ListBucketHandler parseListBucketObjectsResponse(
- InputStream inputStream, final boolean shouldSDKDecodeResponse) throws IOException {
- ListBucketHandler handler = new ListBucketHandler(shouldSDKDecodeResponse);
- parseXmlInputStream(handler, sanitizeXmlDocument(handler, inputStream));
-
- return handler;
- }
-
- /**
- * Parses a ListBucketV2 response XML document from an input stream.
- *
- * @param inputStream XML data input stream.
- * @return the XML handler object populated with data parsed from the XML stream.
- * @throws SdkClientException
- */
- public ListObjectsV2Handler parseListObjectsV2Response(
- InputStream inputStream, final boolean shouldSDKDecodeResponse) throws IOException {
- ListObjectsV2Handler handler = new ListObjectsV2Handler(shouldSDKDecodeResponse);
- parseXmlInputStream(handler, sanitizeXmlDocument(handler, inputStream));
-
- return handler;
- }
-
- /**
- * Parses a ListVersions response XML document from an input stream.
- *
- * @param inputStream XML data input stream.
- * @return the XML handler object populated with data parsed from the XML stream.
- * @throws SdkClientException
- */
- public ListVersionsHandler parseListVersionsResponse(
- InputStream inputStream, final boolean shouldSDKDecodeResponse) throws IOException {
- ListVersionsHandler handler = new ListVersionsHandler(shouldSDKDecodeResponse);
- parseXmlInputStream(handler, sanitizeXmlDocument(handler, inputStream));
- return handler;
- }
-
- /**
- * Parses a ListAllMyBuckets response XML document from an input stream.
- *
- * @param inputStream XML data input stream.
- * @return the XML handler object populated with data parsed from the XML stream.
- * @throws SdkClientException
- */
- public ListAllMyBucketsHandler parseListMyBucketsResponse(InputStream inputStream)
- throws IOException {
- ListAllMyBucketsHandler handler = new ListAllMyBucketsHandler();
- parseXmlInputStream(handler, sanitizeXmlDocument(handler, inputStream));
- return handler;
- }
-
- /**
- * Parses an AccessControlListHandler response XML document from an input stream.
- *
- * @param inputStream XML data input stream.
- * @return the XML handler object populated with data parsed from the XML stream.
- * @throws SdkClientException
- */
- public AccessControlListHandler parseAccessControlListResponse(InputStream inputStream)
- throws IOException {
- AccessControlListHandler handler = new AccessControlListHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- /**
- * Parses a LoggingStatus response XML document for a bucket from an input stream.
- *
- * @param inputStream XML data input stream.
- * @return the XML handler object populated with data parsed from the XML stream.
- * @throws SdkClientException
- */
- public BucketLoggingConfigurationHandler parseLoggingStatusResponse(InputStream inputStream)
- throws IOException {
- BucketLoggingConfigurationHandler handler = new BucketLoggingConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public BucketLifecycleConfigurationHandler parseBucketLifecycleConfigurationResponse(
- InputStream inputStream) throws IOException {
- BucketLifecycleConfigurationHandler handler = new BucketLifecycleConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public BucketCrossOriginConfigurationHandler parseBucketCrossOriginConfigurationResponse(
- InputStream inputStream) throws IOException {
- BucketCrossOriginConfigurationHandler handler = new BucketCrossOriginConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public String parseBucketLocationResponse(InputStream inputStream) throws IOException {
- BucketLocationHandler handler = new BucketLocationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler.getLocation();
- }
-
- public BucketVersioningConfigurationHandler parseVersioningConfigurationResponse(
- InputStream inputStream) throws IOException {
- BucketVersioningConfigurationHandler handler = new BucketVersioningConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public BucketWebsiteConfigurationHandler parseWebsiteConfigurationResponse(
- InputStream inputStream) throws IOException {
- BucketWebsiteConfigurationHandler handler = new BucketWebsiteConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public BucketReplicationConfigurationHandler parseReplicationConfigurationResponse(
- InputStream inputStream) throws IOException {
- BucketReplicationConfigurationHandler handler = new BucketReplicationConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public BucketTaggingConfigurationHandler parseTaggingConfigurationResponse(
- InputStream inputStream) throws IOException {
- BucketTaggingConfigurationHandler handler = new BucketTaggingConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public BucketAccelerateConfigurationHandler parseAccelerateConfigurationResponse(
- InputStream inputStream) throws IOException {
- BucketAccelerateConfigurationHandler handler = new BucketAccelerateConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public DeleteObjectsHandler parseDeletedObjectsResult(InputStream inputStream)
- throws IOException {
- DeleteObjectsHandler handler = new DeleteObjectsHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public CopyObjectResultHandler parseCopyObjectResponse(InputStream inputStream)
- throws IOException {
- CopyObjectResultHandler handler = new CopyObjectResultHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public CompleteMultipartUploadHandler parseCompleteMultipartUploadResponse(
- InputStream inputStream) throws IOException {
- CompleteMultipartUploadHandler handler = new CompleteMultipartUploadHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public InitiateMultipartUploadHandler parseInitiateMultipartUploadResponse(
- InputStream inputStream) throws IOException {
- InitiateMultipartUploadHandler handler = new InitiateMultipartUploadHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public ListMultipartUploadsHandler parseListMultipartUploadsResponse(InputStream inputStream)
- throws IOException {
- ListMultipartUploadsHandler handler = new ListMultipartUploadsHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public ListPartsHandler parseListPartsResponse(InputStream inputStream) throws IOException {
- ListPartsHandler handler = new ListPartsHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public GetObjectTaggingHandler parseObjectTaggingResponse(InputStream inputStream)
- throws IOException {
- GetObjectTaggingHandler handler = new GetObjectTaggingHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public GetBucketMetricsConfigurationHandler parseGetBucketMetricsConfigurationResponse(
- InputStream inputStream) throws IOException {
- GetBucketMetricsConfigurationHandler handler = new GetBucketMetricsConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public ListBucketMetricsConfigurationsHandler parseListBucketMetricsConfigurationsResponse(
- InputStream inputStream) throws IOException {
- ListBucketMetricsConfigurationsHandler handler =
- new ListBucketMetricsConfigurationsHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public GetBucketAnalyticsConfigurationHandler parseGetBucketAnalyticsConfigurationResponse(
- InputStream inputStream) throws IOException {
- GetBucketAnalyticsConfigurationHandler handler =
- new GetBucketAnalyticsConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public ListBucketAnalyticsConfigurationHandler parseListBucketAnalyticsConfigurationResponse(
- InputStream inputStream) throws IOException {
- ListBucketAnalyticsConfigurationHandler handler =
- new ListBucketAnalyticsConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public GetBucketInventoryConfigurationHandler parseGetBucketInventoryConfigurationResponse(
- InputStream inputStream) throws IOException {
- GetBucketInventoryConfigurationHandler handler =
- new GetBucketInventoryConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- public ListBucketInventoryConfigurationsHandler parseBucketListInventoryConfigurationsResponse(
- InputStream inputStream) throws IOException {
- ListBucketInventoryConfigurationsHandler handler =
- new ListBucketInventoryConfigurationsHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- /**
- * @param inputStream
- * @return true if the bucket's is configured as Requester Pays, false if it is configured as
- * Owner pays.
- * @throws SdkClientException
- */
- public RequestPaymentConfigurationHandler parseRequestPaymentConfigurationResponse(
- InputStream inputStream) throws IOException {
- RequestPaymentConfigurationHandler handler = new RequestPaymentConfigurationHandler();
- parseXmlInputStream(handler, inputStream);
- return handler;
- }
-
- // ////////////
- // Handlers //
- // ////////////
-
- /** Handler for ListBucket response XML documents. */
- public static class ListBucketHandler extends AbstractHandler {
- private final ObjectListing objectListing = new ObjectListing();
- private final boolean shouldSDKDecodeResponse;
-
- private S3ObjectSummary currentObject = null;
- private Owner currentOwner = null;
- private String lastKey = null;
-
- public ListBucketHandler(final boolean shouldSDKDecodeResponse) {
- this.shouldSDKDecodeResponse = shouldSDKDecodeResponse;
- }
-
- public ObjectListing getObjectListing() {
- return objectListing;
- }
-
- @Override
- protected void doStartElement(String uri, String name, String qName, Attributes attrs) {
-
- if (in("ListBucketResult")) {
- if (name.equals("Contents")) {
- currentObject = new S3ObjectSummary();
- currentObject.setBucketName(objectListing.getBucketName());
- }
- } else if (in("ListBucketResult", "Contents")) {
- if (name.equals("Owner")) {
- currentOwner = new Owner();
- }
- }
- }
-
- @Override
- protected void doEndElement(String uri, String name, String qName) {
- if (atTopLevel()) {
- if (name.equals("ListBucketResult")) {
- /*
- * S3 only includes the NextMarker XML element if the
- * request specified a delimiter, but for consistency we'd
- * like to always give easy access to the next marker if
- * we're returning a list of results that's truncated.
- */
- if (objectListing.isTruncated() && objectListing.getNextMarker() == null) {
-
- String nextMarker = null;
- if (!objectListing.getObjectSummaries().isEmpty()) {
- nextMarker =
- objectListing
- .getObjectSummaries()
- .get(objectListing.getObjectSummaries().size() - 1)
- .getKey();
-
- } else if (!objectListing.getCommonPrefixes().isEmpty()) {
- nextMarker =
- objectListing
- .getCommonPrefixes()
- .get(objectListing.getCommonPrefixes().size() - 1);
- } else {
- log.error(
- "S3 response indicates truncated results, "
- + "but contains no object summaries or "
- + "common prefixes.");
- }
-
- objectListing.setNextMarker(nextMarker);
- }
- }
- } else if (in("ListBucketResult")) {
- if (name.equals("Name")) {
- objectListing.setBucketName(getText());
- if (log.isDebugEnabled()) {
- log.debug("Examining listing for bucket: " + objectListing.getBucketName());
- }
-
- } else if (name.equals("Prefix")) {
- objectListing.setPrefix(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
-
- } else if (name.equals("Marker")) {
- objectListing.setMarker(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
-
- } else if (name.equals("NextMarker")) {
- objectListing.setNextMarker(
- decodeIfSpecified(getText(), shouldSDKDecodeResponse));
-
- } else if (name.equals("MaxKeys")) {
- objectListing.setMaxKeys(parseInt(getText()));
-
- } else if (name.equals("Delimiter")) {
- objectListing.setDelimiter(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
-
- } else if (name.equals("EncodingType")) {
- objectListing.setEncodingType(
- shouldSDKDecodeResponse ? null : checkForEmptyString(getText()));
- } else if (name.equals("IsTruncated")) {
- String isTruncatedStr = StringUtils.lowerCase(getText());
-
- if (isTruncatedStr.startsWith("false")) {
- objectListing.setTruncated(false);
- } else if (isTruncatedStr.startsWith("true")) {
- objectListing.setTruncated(true);
- } else {
- throw new IllegalStateException(
- "Invalid value for IsTruncated field: " + isTruncatedStr);
- }
-
- } else if (name.equals("Contents")) {
- objectListing.getObjectSummaries().add(currentObject);
- currentObject = null;
- }
- } else if (in("ListBucketResult", "Contents")) {
- if (name.equals("Key")) {
- lastKey = getText();
- currentObject.setKey(decodeIfSpecified(lastKey, shouldSDKDecodeResponse));
- } else if (name.equals("LastModified")) {
- currentObject.setLastModified(ServiceUtils.parseIso8601Date(getText()));
-
- } else if (name.equals("ETag")) {
- currentObject.setETag(ServiceUtils.removeQuotes(getText()));
-
- } else if (name.equals("Size")) {
- currentObject.setSize(parseLong(getText()));
-
- } else if (name.equals("StorageClass")) {
- currentObject.setStorageClass(getText());
-
- } else if (name.equals("Owner")) {
- currentObject.setOwner(currentOwner);
- currentOwner = null;
- }
- } else if (in("ListBucketResult", "Contents", "Owner")) {
- if (name.equals("ID")) {
- currentOwner.setId(getText());
-
- } else if (name.equals("DisplayName")) {
- currentOwner.setDisplayName(getText());
- }
- } else if (in("ListBucketResult", "CommonPrefixes")) {
- if (name.equals("Prefix")) {
- objectListing
- .getCommonPrefixes()
- .add(decodeIfSpecified(getText(), shouldSDKDecodeResponse));
- }
- }
- }
- }
-
- /** Handler for ListObjectsV2 response XML documents. */
- public static class ListObjectsV2Handler extends AbstractHandler {
- private final ListObjectsV2Result result = new ListObjectsV2Result();
- private final boolean shouldSDKDecodeResponse;
-
- private S3ObjectSummary currentObject = null;
- private Owner currentOwner = null;
- private String lastKey = null;
-
- public ListObjectsV2Handler(final boolean shouldSDKDecodeResponse) {
- this.shouldSDKDecodeResponse = shouldSDKDecodeResponse;
- }
-
- public ListObjectsV2Result getResult() {
- return result;
- }
-
- @Override
- protected void doStartElement(String uri, String name, String qName, Attributes attrs) {
-
- if (in("ListBucketResult")) {
- if (name.equals("Contents")) {
- currentObject = new S3ObjectSummary();
- currentObject.setBucketName(result.getBucketName());
- }
- } else if (in("ListBucketResult", "Contents")) {
- if (name.equals("Owner")) {
- currentOwner = new Owner();
- }
- }
- }
-
- @Override
- protected void doEndElement(String uri, String name, String qName) {
- if (atTopLevel()) {
- if (name.equals("ListBucketResult")) {
- /*
- * S3 only includes the NextContinuationToken XML element if the
- * request specified a delimiter, but for consistency we'd
- * like to always give easy access to the next token if
- * we're returning a list of results that's truncated.
- */
- if (result.isTruncated() && result.getNextContinuationToken() == null) {
-
- String nextContinuationToken = null;
- if (!result.getObjectSummaries().isEmpty()) {
- nextContinuationToken =
- result.getObjectSummaries()
- .get(result.getObjectSummaries().size() - 1)
- .getKey();
-
- } else {
- log.error(
- "S3 response indicates truncated results, "
- + "but contains no object summaries.");
- }
-
- result.setNextContinuationToken(nextContinuationToken);
- }
- }
- } else if (in("ListBucketResult")) {
- if (name.equals("Name")) {
- result.setBucketName(getText());
- if (log.isDebugEnabled()) {
- log.debug("Examining listing for bucket: " + result.getBucketName());
- }
-
- } else if (name.equals("Prefix")) {
- result.setPrefix(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
-
- } else if (name.equals("MaxKeys")) {
- result.setMaxKeys(parseInt(getText()));
-
- } else if (name.equals("NextContinuationToken")) {
- result.setNextContinuationToken(getText());
-
- } else if (name.equals("ContinuationToken")) {
- result.setContinuationToken(getText());
-
- } else if (name.equals("StartAfter")) {
- result.setStartAfter(decodeIfSpecified(getText(), shouldSDKDecodeResponse));
-
- } else if (name.equals("KeyCount")) {
- result.setKeyCount(parseInt(getText()));
-
- } else if (name.equals("Delimiter")) {
- result.setDelimiter(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
-
- } else if (name.equals("EncodingType")) {
- result.setEncodingType(checkForEmptyString(getText()));
- } else if (name.equals("IsTruncated")) {
- String isTruncatedStr = StringUtils.lowerCase(getText());
-
- if (isTruncatedStr.startsWith("false")) {
- result.setTruncated(false);
- } else if (isTruncatedStr.startsWith("true")) {
- result.setTruncated(true);
- } else {
- throw new IllegalStateException(
- "Invalid value for IsTruncated field: " + isTruncatedStr);
- }
-
- } else if (name.equals("Contents")) {
- result.getObjectSummaries().add(currentObject);
- currentObject = null;
- }
- } else if (in("ListBucketResult", "Contents")) {
- if (name.equals("Key")) {
- lastKey = getText();
- currentObject.setKey(decodeIfSpecified(lastKey, shouldSDKDecodeResponse));
- } else if (name.equals("LastModified")) {
- currentObject.setLastModified(ServiceUtils.parseIso8601Date(getText()));
-
- } else if (name.equals("ETag")) {
- currentObject.setETag(ServiceUtils.removeQuotes(getText()));
-
- } else if (name.equals("Size")) {
- currentObject.setSize(parseLong(getText()));
-
- } else if (name.equals("StorageClass")) {
- currentObject.setStorageClass(getText());
-
- } else if (name.equals("Owner")) {
- currentObject.setOwner(currentOwner);
- currentOwner = null;
- }
- } else if (in("ListBucketResult", "Contents", "Owner")) {
- if (name.equals("ID")) {
- currentOwner.setId(getText());
-
- } else if (name.equals("DisplayName")) {
- currentOwner.setDisplayName(getText());
- }
- } else if (in("ListBucketResult", "CommonPrefixes")) {
- if (name.equals("Prefix")) {
- result.getCommonPrefixes()
- .add(decodeIfSpecified(getText(), shouldSDKDecodeResponse));
- }
- }
- }
- }
-
- /**
- * Handler for ListAllMyBuckets response XML documents. The document is parsed into {@link
- * Bucket}s available via the {@link #getBuckets()} method.
- */
- public static class ListAllMyBucketsHandler extends AbstractHandler {
-
- private final ListRequestPaymentConfiguration object.
- */
- public static class RequestPaymentConfigurationHandler extends AbstractHandler {
-
- private String payer = null;
-
- public RequestPaymentConfiguration getConfiguration() {
- return new RequestPaymentConfiguration(Payer.valueOf(payer));
- }
-
- @Override
- protected void doStartElement(String uri, String name, String qName, Attributes attrs) {}
-
- @Override
- protected void doEndElement(String uri, String name, String qName) {
- if (in("RequestPaymentConfiguration")) {
- if (name.equals("Payer")) {
- payer = getText();
- }
- }
- }
- }
-
- /** Handler for ListVersionsResult XML document. */
- public static class ListVersionsHandler extends AbstractHandler {
-
- private final VersionListing versionListing = new VersionListing();
- private final boolean shouldSDKDecodeResponse;
-
- private S3VersionSummary currentVersionSummary;
- private Owner currentOwner;
-
- public ListVersionsHandler(final boolean shouldSDKDecodeResponse) {
- this.shouldSDKDecodeResponse = shouldSDKDecodeResponse;
- }
-
- public VersionListing getListing() {
- return versionListing;
- }
-
- @Override
- protected void doStartElement(String uri, String name, String qName, Attributes attrs) {
-
- if (in("ListVersionsResult")) {
- if (name.equals("Version")) {
- currentVersionSummary = new S3VersionSummary();
- currentVersionSummary.setBucketName(versionListing.getBucketName());
-
- } else if (name.equals("DeleteMarker")) {
- currentVersionSummary = new S3VersionSummary();
- currentVersionSummary.setBucketName(versionListing.getBucketName());
- currentVersionSummary.setIsDeleteMarker(true);
- }
- } else if (in("ListVersionsResult", "Version")
- || in("ListVersionsResult", "DeleteMarker")) {
- if (name.equals("Owner")) {
- currentOwner = new Owner();
- }
- }
- }
-
- @Override
- protected void doEndElement(String uri, String name, String qName) {
-
- if (in("ListVersionsResult")) {
- if (name.equals("Name")) {
- versionListing.setBucketName(getText());
-
- } else if (name.equals("Prefix")) {
- versionListing.setPrefix(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
- } else if (name.equals("KeyMarker")) {
- versionListing.setKeyMarker(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
- } else if (name.equals("VersionIdMarker")) {
- versionListing.setVersionIdMarker(checkForEmptyString(getText()));
-
- } else if (name.equals("MaxKeys")) {
- versionListing.setMaxKeys(Integer.parseInt(getText()));
-
- } else if (name.equals("Delimiter")) {
- versionListing.setDelimiter(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
-
- } else if (name.equals("EncodingType")) {
- versionListing.setEncodingType(
- shouldSDKDecodeResponse ? null : checkForEmptyString(getText()));
- } else if (name.equals("NextKeyMarker")) {
- versionListing.setNextKeyMarker(
- decodeIfSpecified(
- checkForEmptyString(getText()), shouldSDKDecodeResponse));
-
- } else if (name.equals("NextVersionIdMarker")) {
- versionListing.setNextVersionIdMarker(getText());
-
- } else if (name.equals("IsTruncated")) {
- versionListing.setTruncated("true".equals(getText()));
-
- } else if (name.equals("Version") || name.equals("DeleteMarker")) {
-
- versionListing.getVersionSummaries().add(currentVersionSummary);
-
- currentVersionSummary = null;
- }
- } else if (in("ListVersionsResult", "CommonPrefixes")) {
- if (name.equals("Prefix")) {
- final String commonPrefix = checkForEmptyString(getText());
- versionListing
- .getCommonPrefixes()
- .add(
- shouldSDKDecodeResponse
- ? SdkHttpUtils.urlDecode(commonPrefix)
- : commonPrefix);
- }
- } else if (in("ListVersionsResult", "Version")
- || in("ListVersionsResult", "DeleteMarker")) {
-
- if (name.equals("Key")) {
- currentVersionSummary.setKey(
- decodeIfSpecified(getText(), shouldSDKDecodeResponse));
-
- } else if (name.equals("VersionId")) {
- currentVersionSummary.setVersionId(getText());
-
- } else if (name.equals("IsLatest")) {
- currentVersionSummary.setIsLatest("true".equals(getText()));
-
- } else if (name.equals("LastModified")) {
- currentVersionSummary.setLastModified(ServiceUtils.parseIso8601Date(getText()));
-
- } else if (name.equals("ETag")) {
- currentVersionSummary.setETag(ServiceUtils.removeQuotes(getText()));
-
- } else if (name.equals("Size")) {
- currentVersionSummary.setSize(Long.parseLong(getText()));
-
- } else if (name.equals("Owner")) {
- currentVersionSummary.setOwner(currentOwner);
- currentOwner = null;
-
- } else if (name.equals("StorageClass")) {
- currentVersionSummary.setStorageClass(getText());
- }
- } else if (in("ListVersionsResult", "Version", "Owner")
- || in("ListVersionsResult", "DeleteMarker", "Owner")) {
-
- if (name.equals("ID")) {
- currentOwner.setId(getText());
- } else if (name.equals("DisplayName")) {
- currentOwner.setDisplayName(getText());
- }
- }
- }
- }
-
- public static class BucketWebsiteConfigurationHandler extends AbstractHandler {
-
- private final BucketWebsiteConfiguration configuration =
- new BucketWebsiteConfiguration(null);
-
- private RoutingRuleCondition currentCondition = null;
- private RedirectRule currentRedirectRule = null;
- private RoutingRule currentRoutingRule = null;
-
- public BucketWebsiteConfiguration getConfiguration() {
- return configuration;
- }
-
- @Override
- protected void doStartElement(String uri, String name, String qName, Attributes attrs) {
-
- if (in("WebsiteConfiguration")) {
- if (name.equals("RedirectAllRequestsTo")) {
- currentRedirectRule = new RedirectRule();
- }
- } else if (in("WebsiteConfiguration", "RoutingRules")) {
- if (name.equals("RoutingRule")) {
- currentRoutingRule = new RoutingRule();
- }
- } else if (in("WebsiteConfiguration", "RoutingRules", "RoutingRule")) {
- if (name.equals("Condition")) {
- currentCondition = new RoutingRuleCondition();
- } else if (name.equals("Redirect")) {
- currentRedirectRule = new RedirectRule();
- }
- }
- }
-
- @Override
- protected void doEndElement(String uri, String name, String qName) {
- if (in("WebsiteConfiguration")) {
- if (name.equals("RedirectAllRequestsTo")) {
- configuration.setRedirectAllRequestsTo(currentRedirectRule);
- currentRedirectRule = null;
- }
- } else if (in("WebsiteConfiguration", "IndexDocument")) {
- if (name.equals("Suffix")) {
- configuration.setIndexDocumentSuffix(getText());
- }
- } else if (in("WebsiteConfiguration", "ErrorDocument")) {
- if (name.equals("Key")) {
- configuration.setErrorDocument(getText());
- }
- } else if (in("WebsiteConfiguration", "RoutingRules")) {
- if (name.equals("RoutingRule")) {
- configuration.getRoutingRules().add(currentRoutingRule);
- currentRoutingRule = null;
- }
- } else if (in("WebsiteConfiguration", "RoutingRules", "RoutingRule")) {
- if (name.equals("Condition")) {
- currentRoutingRule.setCondition(currentCondition);
- currentCondition = null;
- } else if (name.equals("Redirect")) {
- currentRoutingRule.setRedirect(currentRedirectRule);
- currentRedirectRule = null;
- }
- } else if (in("WebsiteConfiguration", "RoutingRules", "RoutingRule", "Condition")) {
- if (name.equals("KeyPrefixEquals")) {
- currentCondition.setKeyPrefixEquals(getText());
- } else if (name.equals("HttpErrorCodeReturnedEquals")) {
- currentCondition.setHttpErrorCodeReturnedEquals(getText());
- }
- } else if (in("WebsiteConfiguration", "RedirectAllRequestsTo")
- || in("WebsiteConfiguration", "RoutingRules", "RoutingRule", "Redirect")) {
-
- if (name.equals("Protocol")) {
- currentRedirectRule.setProtocol(getText());
-
- } else if (name.equals("HostName")) {
- currentRedirectRule.setHostName(getText());
-
- } else if (name.equals("ReplaceKeyPrefixWith")) {
- currentRedirectRule.setReplaceKeyPrefixWith(getText());
-
- } else if (name.equals("ReplaceKeyWith")) {
- currentRedirectRule.setReplaceKeyWith(getText());
-
- } else if (name.equals("HttpRedirectCode")) {
- currentRedirectRule.setHttpRedirectCode(getText());
- }
- }
- }
- }
-
- public static class BucketVersioningConfigurationHandler extends AbstractHandler {
-
- private final BucketVersioningConfiguration configuration =
- new BucketVersioningConfiguration();
-
- public BucketVersioningConfiguration getConfiguration() {
- return configuration;
- }
-
- @Override
- protected void doStartElement(String uri, String name, String qName, Attributes attrs) {}
-
- @Override
- protected void doEndElement(String uri, String name, String qName) {
- if (in("VersioningConfiguration")) {
- if (name.equals("Status")) {
- configuration.setStatus(getText());
-
- } else if (name.equals("MfaDelete")) {
- String mfaDeleteStatus = getText();
-
- if (mfaDeleteStatus.equals("Disabled")) {
- configuration.setMfaDeleteEnabled(false);
- } else if (mfaDeleteStatus.equals("Enabled")) {
- configuration.setMfaDeleteEnabled(true);
- } else {
- configuration.setMfaDeleteEnabled(null);
- }
- }
- }
- }
- }
-
- public static class BucketAccelerateConfigurationHandler extends AbstractHandler {
-
- private final BucketAccelerateConfiguration configuration =
- new BucketAccelerateConfiguration((String) null);
-
- public BucketAccelerateConfiguration getConfiguration() {
- return configuration;
- }
-
- @Override
- protected void doStartElement(String uri, String name, String qName, Attributes attrs) {}
-
- @Override
- protected void doEndElement(String uri, String name, String qName) {
- if (in("AccelerateConfiguration")) {
- if (name.equals("Status")) {
- configuration.setStatus(getText());
- }
- }
- }
- }
-
- /*
- *
- * InternalError
- *
- *
- */
- public static class BucketReplicationConfigurationHandler extends AbstractHandler {
-
- private final BucketReplicationConfiguration bucketReplicationConfiguration =
- new BucketReplicationConfiguration();
- private String currentRuleId;
- private ReplicationRule currentRule;
- private ReplicationDestinationConfig destinationConfig;
- private AccessControlTranslation accessControlTranslation;
- private EncryptionConfiguration encryptionConfiguration;
- private SourceSelectionCriteria sourceSelectionCriteria;
- private SseKmsEncryptedObjects sseKmsEncryptedObjects;
- private static final String REPLICATION_CONFIG = "ReplicationConfiguration";
- private static final String ROLE = "Role";
- private static final String RULE = "Rule";
- private static final String DESTINATION = "Destination";
- private static final String ID = "ID";
- private static final String PREFIX = "Prefix";
- private static final String STATUS = "Status";
- private static final String BUCKET = "Bucket";
- private static final String STORAGECLASS = "StorageClass";
- private static final String ACCOUNT = "Account";
- private static final String ACCESS_CONTROL_TRANSLATION = "AccessControlTranslation";
- private static final String OWNER = "Owner";
- private static final String ENCRYPTION_CONFIGURATION = "EncryptionConfiguration";
- private static final String REPLICA_KMS_KEY_ID = "ReplicaKmsKeyID";
- private static final String SOURCE_SELECTION_CRITERIA = "SourceSelectionCriteria";
- private static final String SSE_KMS_ENCRYPTED_OBJECTS = "SseKmsEncryptedObjects";
-
- public BucketReplicationConfiguration getConfiguration() {
- return bucketReplicationConfiguration;
- }
-
- @Override
- protected void doStartElement(String uri, String name, String qName, Attributes attrs) {
-
- if (in(REPLICATION_CONFIG)) {
- if (name.equals(RULE)) {
- currentRule = new ReplicationRule();
- }
- } else if (in(REPLICATION_CONFIG, RULE)) {
- if (name.equals(DESTINATION)) {
- destinationConfig = new ReplicationDestinationConfig();
- } else if (name.equals(SOURCE_SELECTION_CRITERIA)) {
- sourceSelectionCriteria = new SourceSelectionCriteria();
- }
- } else if (in(REPLICATION_CONFIG, RULE, DESTINATION)) {
- if (name.equals(ACCESS_CONTROL_TRANSLATION)) {
- accessControlTranslation = new AccessControlTranslation();
- } else if (name.equals(ENCRYPTION_CONFIGURATION)) {
- encryptionConfiguration = new EncryptionConfiguration();
- }
- } else if (in(REPLICATION_CONFIG, RULE, SOURCE_SELECTION_CRITERIA)) {
- if (name.equals(SSE_KMS_ENCRYPTED_OBJECTS)) {
- sseKmsEncryptedObjects = new SseKmsEncryptedObjects();
- }
- }
- }
-
- @Override
- protected void doEndElement(String uri, String name, String qName) {
- if (in(REPLICATION_CONFIG)) {
- if (name.equals(RULE)) {
- bucketReplicationConfiguration.addRule(currentRuleId, currentRule);
- currentRule = null;
- currentRuleId = null;
- destinationConfig = null;
- sseKmsEncryptedObjects = null;
- accessControlTranslation = null;
- encryptionConfiguration = null;
- } else if (name.equals(ROLE)) {
- bucketReplicationConfiguration.setRoleARN(getText());
- }
- } else if (in(REPLICATION_CONFIG, RULE)) {
- if (name.equals(ID)) {
- currentRuleId = getText();
- } else if (name.equals(PREFIX)) {
- currentRule.setPrefix(getText());
- } else if (name.equals(SOURCE_SELECTION_CRITERIA)) {
- currentRule.setSourceSelectionCriteria(sourceSelectionCriteria);
- } else {
- if (name.equals(STATUS)) {
- currentRule.setStatus(getText());
-
- } else if (name.equals(DESTINATION)) {
- currentRule.setDestinationConfig(destinationConfig);
- }
- }
- } else if (in(REPLICATION_CONFIG, RULE, SOURCE_SELECTION_CRITERIA)) {
- if (name.equals(SSE_KMS_ENCRYPTED_OBJECTS)) {
- sourceSelectionCriteria.setSseKmsEncryptedObjects(sseKmsEncryptedObjects);
- }
- } else if (in(
- REPLICATION_CONFIG,
- RULE,
- SOURCE_SELECTION_CRITERIA,
- SSE_KMS_ENCRYPTED_OBJECTS)) {
- if (name.equals(STATUS)) {
- sseKmsEncryptedObjects.setStatus(getText());
- }
- } else if (in(REPLICATION_CONFIG, RULE, DESTINATION)) {
- if (name.equals(BUCKET)) {
- destinationConfig.setBucketARN(getText());
- } else if (name.equals(STORAGECLASS)) {
- destinationConfig.setStorageClass(getText());
- } else if (name.equals(ACCOUNT)) {
- destinationConfig.setAccount(getText());
- } else if (name.equals(ACCESS_CONTROL_TRANSLATION)) {
- destinationConfig.setAccessControlTranslation(accessControlTranslation);
- } else if (name.equals(ENCRYPTION_CONFIGURATION)) {
- destinationConfig.setEncryptionConfiguration(encryptionConfiguration);
- }
- } else if (in(REPLICATION_CONFIG, RULE, DESTINATION, ACCESS_CONTROL_TRANSLATION)) {
- if (name.equals(OWNER)) {
- accessControlTranslation.setOwner(getText());
- }
- } else if (in(REPLICATION_CONFIG, RULE, DESTINATION, ENCRYPTION_CONFIGURATION)) {
- if (name.equals(REPLICA_KMS_KEY_ID)) {
- encryptionConfiguration.setReplicaKmsKeyID(getText());
- }
- }
- }
- }
-
- public static class BucketTaggingConfigurationHandler extends AbstractHandler {
-
- private final BucketTaggingConfiguration configuration = new BucketTaggingConfiguration();
-
- private MapCode
-