Search in sources :

Example 11 with XmlWriter

use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method writeRule.

private void writeRule(XmlWriter xml, RoutingRule rule) {
    xml.start("RoutingRule");
    final RoutingRuleCondition condition = rule.getCondition();
    if (condition != null) {
        xml.start("Condition");
        xml.start("KeyPrefixEquals");
        if (condition.getKeyPrefixEquals() != null) {
            xml.value(condition.getKeyPrefixEquals());
        }
        // </KeyPrefixEquals">
        xml.end();
        if (condition.getHttpErrorCodeReturnedEquals() != null) {
            xml.start("HttpErrorCodeReturnedEquals ").value(condition.getHttpErrorCodeReturnedEquals()).end();
        }
        // </Condition>
        xml.end();
    }
    xml.start("Redirect");
    final RedirectRule redirect = rule.getRedirect();
    if (redirect != null) {
        if (redirect.getprotocol() != null) {
            xml.start("Protocol").value(redirect.getprotocol()).end();
        }
        if (redirect.getHostName() != null) {
            xml.start("HostName").value(redirect.getHostName()).end();
        }
        if (redirect.getReplaceKeyPrefixWith() != null) {
            xml.start("ReplaceKeyPrefixWith").value(redirect.getReplaceKeyPrefixWith()).end();
        }
        if (redirect.getReplaceKeyWith() != null) {
            xml.start("ReplaceKeyWith").value(redirect.getReplaceKeyWith()).end();
        }
        if (redirect.getHttpRedirectCode() != null) {
            xml.start("HttpRedirectCode").value(redirect.getHttpRedirectCode()).end();
        }
    }
    // </Redirect>
    xml.end();
    // </CORSRule>
    xml.end();
}
Also used : RedirectRule(com.amazonaws.services.s3.model.RedirectRule) RoutingRuleCondition(com.amazonaws.services.s3.model.RoutingRuleCondition)

Example 12 with XmlWriter

use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method addEventsAndFilterCriteria.

private void addEventsAndFilterCriteria(XmlWriter xml, NotificationConfiguration config) {
    for (final String event : config.getEvents()) {
        xml.start("Event").value(event).end();
    }
    final Filter filter = config.getFilter();
    if (filter != null) {
        validateFilter(filter);
        xml.start("Filter");
        if (filter.getS3KeyFilter() != null) {
            validateS3KeyFilter(filter.getS3KeyFilter());
            xml.start("S3Key");
            for (final FilterRule filterRule : filter.getS3KeyFilter().getFilterRules()) {
                xml.start("FilterRule");
                xml.start("Name").value(filterRule.getName()).end();
                xml.start("Value").value(filterRule.getValue()).end();
                xml.end();
            }
            xml.end();
        }
        xml.end();
    }
}
Also used : Filter(com.amazonaws.services.s3.model.Filter) AnalyticsFilter(com.amazonaws.services.s3.model.analytics.AnalyticsFilter) LifecycleFilter(com.amazonaws.services.s3.model.lifecycle.LifecycleFilter) InventoryFilter(com.amazonaws.services.s3.model.inventory.InventoryFilter) S3KeyFilter(com.amazonaws.services.s3.model.S3KeyFilter) MetricsFilter(com.amazonaws.services.s3.model.metrics.MetricsFilter) FilterRule(com.amazonaws.services.s3.model.FilterRule)

Example 13 with XmlWriter

use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

public byte[] convertToXmlByteArray(BucketReplicationConfiguration replicationConfiguration) {
    final XmlWriter xml = new XmlWriter();
    xml.start("ReplicationConfiguration");
    final Map<String, ReplicationRule> rules = replicationConfiguration.getRules();
    final String role = replicationConfiguration.getRoleARN();
    xml.start("Role").value(role).end();
    for (final Map.Entry<String, ReplicationRule> entry : rules.entrySet()) {
        final String ruleId = entry.getKey();
        final ReplicationRule rule = entry.getValue();
        xml.start("Rule");
        xml.start("ID").value(ruleId).end();
        xml.start("Prefix").value(rule.getPrefix()).end();
        xml.start("Status").value(rule.getStatus()).end();
        final ReplicationDestinationConfig config = rule.getDestinationConfig();
        xml.start("Destination");
        xml.start("Bucket").value(config.getBucketARN()).end();
        if (config.getStorageClass() != null) {
            xml.start("StorageClass").value(config.getStorageClass()).end();
        }
        xml.end();
        xml.end();
    }
    xml.end();
    return xml.getBytes();
}
Also used : ReplicationDestinationConfig(com.amazonaws.services.s3.model.ReplicationDestinationConfig) ReplicationRule(com.amazonaws.services.s3.model.ReplicationRule) Map(java.util.Map) XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 14 with XmlWriter

use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.

the class MultiObjectDeleteXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified {@link DeleteObjectsRequest} object to an XML
 * fragment that can be sent to Amazon S3.
 *
 * @param rq The {@link DeleteObjectsRequest}
 */
public byte[] convertToXmlByteArray(DeleteObjectsRequest rq) throws AmazonClientException {
    XmlWriter xml = new XmlWriter();
    xml.start("Delete");
    if (rq.getQuiet()) {
        xml.start("Quiet").value("true").end();
    }
    for (KeyVersion keyVersion : rq.getKeys()) {
        writeKeyVersion(xml, keyVersion);
    }
    xml.end();
    return xml.getBytes();
}
Also used : KeyVersion(com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion) XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 15 with XmlWriter

use of com.amazonaws.services.s3.internal.XmlWriter in project aws-sdk-android by aws-amplify.

the class RequestXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified list of PartETags to an XML fragment that can be
 * sent to the CompleteMultipartUpload operation of Amazon S3.
 *
 * @param partETags The list of part ETags containing the data to include in
 *            the new XML fragment.
 * @return A byte array containing the data
 */
public static byte[] convertToXmlByteArray(List<PartETag> partETags) {
    XmlWriter xml = new XmlWriter();
    xml.start("CompleteMultipartUpload");
    if (partETags != null) {
        Collections.sort(partETags, new Comparator<PartETag>() {

            @Override
            public int compare(PartETag tag1, PartETag tag2) {
                if (tag1.getPartNumber() < tag2.getPartNumber())
                    return -1;
                if (tag1.getPartNumber() > tag2.getPartNumber())
                    return 1;
                return 0;
            }
        });
        for (PartETag partEtag : partETags) {
            xml.start("Part");
            xml.start("PartNumber").value(Integer.toString(partEtag.getPartNumber())).end();
            xml.start("ETag").value(partEtag.getETag()).end();
            xml.end();
        }
    }
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter) PartETag(com.amazonaws.services.s3.model.PartETag)

Aggregations

XmlWriter (com.amazonaws.services.s3.internal.XmlWriter)19 RedirectRule (com.amazonaws.services.s3.model.RedirectRule)3 NoncurrentVersionTransition (com.amazonaws.services.s3.model.BucketLifecycleConfiguration.NoncurrentVersionTransition)2 CORSRule (com.amazonaws.services.s3.model.CORSRule)2 FilterRule (com.amazonaws.services.s3.model.FilterRule)2 ReplicationRule (com.amazonaws.services.s3.model.ReplicationRule)2 RoutingRule (com.amazonaws.services.s3.model.RoutingRule)2 Map (java.util.Map)2 AmazonClientException (com.amazonaws.AmazonClientException)1 Rule (com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule)1 Transition (com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Transition)1 BucketNotificationConfiguration (com.amazonaws.services.s3.model.BucketNotificationConfiguration)1 TopicConfiguration (com.amazonaws.services.s3.model.BucketNotificationConfiguration.TopicConfiguration)1 AllowedMethods (com.amazonaws.services.s3.model.CORSRule.AllowedMethods)1 CloudFunctionConfiguration (com.amazonaws.services.s3.model.CloudFunctionConfiguration)1 KeyVersion (com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion)1 Filter (com.amazonaws.services.s3.model.Filter)1 Grant (com.amazonaws.services.s3.model.Grant)1 LambdaConfiguration (com.amazonaws.services.s3.model.LambdaConfiguration)1 NotificationConfiguration (com.amazonaws.services.s3.model.NotificationConfiguration)1