Search in sources :

Example 6 with XmlWriter

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

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified
 * {@link com.amazonaws.services.s3.model.metrics.MetricsConfiguration}
 * object to an XML fragment that can be sent to Amazon S3.
 *
 * @param config The
 *            {@link com.amazonaws.services.s3.model.metrics.MetricsConfiguration}
 *            .
 */
/*
     * <MetricsConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
     * <Id>metrics-id</Id> <Filter> <!-- A filter should have only one of
     * Prefix, Tag or And--> <Prefix>prefix</Prefix> <Tag> <Key>Project</Key>
     * <Value>Foo</Value> </Tag> <And> <Prefix>documents/</Prefix> <Tag>
     * <Key>foo</Key> <Value>bar</Value> </Tag> </And> </Filter>
     * </MetricsConfiguration>
     */
public byte[] convertToXmlByteArray(MetricsConfiguration config) throws AmazonClientException {
    final XmlWriter xml = new XmlWriter();
    xml.start("MetricsConfiguration", "xmlns", Constants.XML_NAMESPACE);
    addParameterIfNotNull(xml, "Id", config.getId());
    writeMetricsFilter(xml, config.getFilter());
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 7 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, CORSRule rule) {
    xml.start("CORSRule");
    if (rule.getId() != null) {
        xml.start("ID").value(rule.getId()).end();
    }
    if (rule.getAllowedOrigins() != null) {
        for (final String origin : rule.getAllowedOrigins()) {
            xml.start("AllowedOrigin").value(origin).end();
        }
    }
    if (rule.getAllowedMethods() != null) {
        for (final AllowedMethods method : rule.getAllowedMethods()) {
            xml.start("AllowedMethod").value(method.toString()).end();
        }
    }
    if (rule.getMaxAgeSeconds() != 0) {
        xml.start("MaxAgeSeconds").value(Integer.toString(rule.getMaxAgeSeconds())).end();
    }
    if (rule.getExposedHeaders() != null) {
        for (final String header : rule.getExposedHeaders()) {
            xml.start("ExposeHeader").value(header).end();
        }
    }
    if (rule.getAllowedHeaders() != null) {
        for (final String header : rule.getAllowedHeaders()) {
            xml.start("AllowedHeader").value(header).end();
        }
    }
    // </CORSRule>
    xml.end();
}
Also used : AllowedMethods(com.amazonaws.services.s3.model.CORSRule.AllowedMethods)

Example 8 with XmlWriter

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

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified
 * {@link com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration}
 * object to an XML fragment that can be sent to Amazon S3.
 *
 * @param config The
 *            {@link com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration}
 */
/*
     * <AnalyticsConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
     * <Id>XXX</Id> <Filter> <And> <Prefix>documents/</Prefix> <Tag>
     * <Key>foo</Key> <Value>bar</Value> </Tag> </And> </Filter>
     * <StorageClassAnalysis> <DataExport>
     * <OutputSchemaVersion>1</OutputSchemaVersion> <Destination>
     * <S3BucketDestination> <Format>CSV</Format>
     * <BucketAccountId>123456789</BucketAccountId>
     * <Bucket>destination-bucket</Bucket> <Prefix>destination-prefix</Prefix>
     * </S3BucketDestination> </Destination> </DataExport>
     * </StorageClassAnalysis> </AnalyticsConfiguration>
     */
public byte[] convertToXmlByteArray(AnalyticsConfiguration config) throws AmazonClientException {
    final XmlWriter xml = new XmlWriter();
    xml.start("AnalyticsConfiguration", "xmlns", Constants.XML_NAMESPACE);
    addParameterIfNotNull(xml, "Id", config.getId());
    writeAnalyticsFilter(xml, config.getFilter());
    writeStorageClassAnalysis(xml, config.getStorageClassAnalysis());
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 9 with XmlWriter

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

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified accelerate configuration into an XML byte array.
 *
 * @param accelerateConfiguration The configuration to convert.
 * @return The XML byte array representation.
 */
public byte[] convertToXmlByteArray(BucketAccelerateConfiguration accelerateConfiguration) {
    final XmlWriter xml = new XmlWriter();
    xml.start("AccelerateConfiguration", "xmlns", Constants.XML_NAMESPACE);
    xml.start("Status").value(accelerateConfiguration.getStatus()).end();
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 10 with XmlWriter

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

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified notification configuration into an XML byte array.
 *
 * @param notificationConfiguration The configuration to convert.
 * @return The XML byte array representation.
 */
public byte[] convertToXmlByteArray(BucketNotificationConfiguration notificationConfiguration) {
    final XmlWriter xml = new XmlWriter();
    xml.start("NotificationConfiguration", "xmlns", Constants.XML_NAMESPACE);
    final Map<String, NotificationConfiguration> configurations = notificationConfiguration.getConfigurations();
    for (final Map.Entry<String, NotificationConfiguration> entry : configurations.entrySet()) {
        final String configName = entry.getKey();
        final NotificationConfiguration config = entry.getValue();
        if (config instanceof TopicConfiguration) {
            xml.start("TopicConfiguration");
            xml.start("Id").value(configName).end();
            xml.start("Topic").value(((TopicConfiguration) config).getTopicARN()).end();
            addEventsAndFilterCriteria(xml, config);
            xml.end();
        } else if (config instanceof QueueConfiguration) {
            xml.start("QueueConfiguration");
            xml.start("Id").value(configName).end();
            xml.start("Queue").value(((QueueConfiguration) config).getQueueARN()).end();
            addEventsAndFilterCriteria(xml, config);
            xml.end();
        } else if (config instanceof CloudFunctionConfiguration) {
            xml.start("CloudFunctionConfiguration");
            xml.start("Id").value(configName).end();
            xml.start("InvocationRole").value(((CloudFunctionConfiguration) config).getInvocationRoleARN()).end();
            xml.start("CloudFunction").value(((CloudFunctionConfiguration) config).getCloudFunctionARN()).end();
            addEventsAndFilterCriteria(xml, config);
            xml.end();
        } else if (config instanceof LambdaConfiguration) {
            xml.start("CloudFunctionConfiguration");
            xml.start("Id").value(configName).end();
            xml.start("CloudFunction").value(((LambdaConfiguration) config).getFunctionARN()).end();
            addEventsAndFilterCriteria(xml, config);
            xml.end();
        }
    }
    xml.end();
    return xml.getBytes();
}
Also used : CloudFunctionConfiguration(com.amazonaws.services.s3.model.CloudFunctionConfiguration) QueueConfiguration(com.amazonaws.services.s3.model.QueueConfiguration) NotificationConfiguration(com.amazonaws.services.s3.model.NotificationConfiguration) BucketNotificationConfiguration(com.amazonaws.services.s3.model.BucketNotificationConfiguration) LambdaConfiguration(com.amazonaws.services.s3.model.LambdaConfiguration) TopicConfiguration(com.amazonaws.services.s3.model.BucketNotificationConfiguration.TopicConfiguration) Map(java.util.Map) XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

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