Search in sources :

Example 21 with XmlWriter

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

the class BucketConfigurationXmlFactory method writeStorageClassAnalysis.

private void writeStorageClassAnalysis(XmlWriter xml, StorageClassAnalysis storageClassAnalysis) {
    if (storageClassAnalysis == null) {
        return;
    }
    xml.start("StorageClassAnalysis");
    if (storageClassAnalysis.getDataExport() != null) {
        final StorageClassAnalysisDataExport dataExport = storageClassAnalysis.getDataExport();
        xml.start("DataExport");
        addParameterIfNotNull(xml, "OutputSchemaVersion", dataExport.getOutputSchemaVersion());
        writeAnalyticsExportDestination(xml, dataExport.getDestination());
        // </DataExport>
        xml.end();
    }
    // </StorageClassAnalysis>
    xml.end();
}
Also used : StorageClassAnalysisDataExport(com.amazonaws.services.s3.model.analytics.StorageClassAnalysisDataExport)

Example 22 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 BucketLifecycleConfiguration} object to an
 * XML fragment that can be sent to Amazon S3.
 *
 * @param config The {@link BucketLifecycleConfiguration}
 */
/*
     * <LifecycleConfiguration> <Rule> <ID>logs-rule</ID>
     * <Status>Enabled</Status> <Transition> <Days>30</Days>
     * <StorageClass>GLACIER</StorageClass> </Transition> <Expiration>
     * <Days>365</Days> </Expiration> <NoncurrentVersionTransition>
     * <NoncurrentDays>7</NoncurrentDays> <StorageClass>GLACIER</StorageClass>
     * </NoncurrentVersionTransition> <NoncurrentVersionExpiration>
     * <NoncurrentDays>14</NoncurrentDays> </NoncurrentVersionExpiration>
     * <Filter> <!-- A filter can have only one of Prefix, Tag or And. -->
     * <Prefix>logs/</Prefix> <Tag> <Key>key1</Key> <Value>value1</Value> </Tag>
     * <And> <Prefix>logs/</Prefix> <Tag> <Key>key1</Key> <Value>value1</Value>
     * </Tag> <Tag> <Key>key1</Key> <Value>value1</Value> </Tag> </And>
     * </Filter> </Rule> <Rule> <ID>image-rule</ID> <Prefix>image/</Prefix>
     * <Status>Enabled</Status> <Transition>
     * <Date>2012-12-31T00:00:00.000Z</Date>
     * <StorageClass>GLACIER</StorageClass> </Transition> <Expiration>
     * <Date>2020-12-31T00:00:00.000Z</Date> </Expiration>
     * <AbortIncompleteMultipartUpload>
     * <DaysAfterInitiation>10</DaysAfterInitiation>
     * </AbortIncompleteMultipartUpload> </Rule> </LifecycleConfiguration>
     */
public byte[] convertToXmlByteArray(BucketLifecycleConfiguration config) throws AmazonClientException {
    final XmlWriter xml = new XmlWriter();
    xml.start("LifecycleConfiguration");
    for (final Rule rule : config.getRules()) {
        writeRule(xml, rule);
    }
    xml.end();
    return xml.getBytes();
}
Also used : CORSRule(com.amazonaws.services.s3.model.CORSRule) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) ReplicationRule(com.amazonaws.services.s3.model.ReplicationRule) RoutingRule(com.amazonaws.services.s3.model.RoutingRule) RedirectRule(com.amazonaws.services.s3.model.RedirectRule) FilterRule(com.amazonaws.services.s3.model.FilterRule) XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 23 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 website configuration into an XML byte array to
 * send to S3. Sample XML:
 * <WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
 * <IndexDocument> <Suffix>index.html</Suffix> </IndexDocument>
 * <ErrorDocument> <Key>404.html</Key> </ErrorDocument>
 * </WebsiteConfiguration>
 *
 * @param websiteConfiguration The configuration to convert.
 * @return The XML byte array representation.
 */
public byte[] convertToXmlByteArray(BucketWebsiteConfiguration websiteConfiguration) {
    final XmlWriter xml = new XmlWriter();
    xml.start("WebsiteConfiguration", "xmlns", Constants.XML_NAMESPACE);
    if (websiteConfiguration.getIndexDocumentSuffix() != null) {
        final XmlWriter indexDocumentElement = xml.start("IndexDocument");
        indexDocumentElement.start("Suffix").value(websiteConfiguration.getIndexDocumentSuffix()).end();
        indexDocumentElement.end();
    }
    if (websiteConfiguration.getErrorDocument() != null) {
        final XmlWriter errorDocumentElement = xml.start("ErrorDocument");
        errorDocumentElement.start("Key").value(websiteConfiguration.getErrorDocument()).end();
        errorDocumentElement.end();
    }
    final RedirectRule redirectAllRequestsTo = websiteConfiguration.getRedirectAllRequestsTo();
    if (redirectAllRequestsTo != null) {
        final XmlWriter redirectAllRequestsElement = xml.start("RedirectAllRequestsTo");
        if (redirectAllRequestsTo.getprotocol() != null) {
            xml.start("Protocol").value(redirectAllRequestsTo.getprotocol()).end();
        }
        if (redirectAllRequestsTo.getHostName() != null) {
            xml.start("HostName").value(redirectAllRequestsTo.getHostName()).end();
        }
        if (redirectAllRequestsTo.getReplaceKeyPrefixWith() != null) {
            xml.start("ReplaceKeyPrefixWith").value(redirectAllRequestsTo.getReplaceKeyPrefixWith()).end();
        }
        if (redirectAllRequestsTo.getReplaceKeyWith() != null) {
            xml.start("ReplaceKeyWith").value(redirectAllRequestsTo.getReplaceKeyWith()).end();
        }
        redirectAllRequestsElement.end();
    }
    if (websiteConfiguration.getRoutingRules() != null && websiteConfiguration.getRoutingRules().size() > 0) {
        final XmlWriter routingRules = xml.start("RoutingRules");
        for (final RoutingRule rule : websiteConfiguration.getRoutingRules()) {
            writeRule(routingRules, rule);
        }
        routingRules.end();
    }
    xml.end();
    return xml.getBytes();
}
Also used : RedirectRule(com.amazonaws.services.s3.model.RedirectRule) RoutingRule(com.amazonaws.services.s3.model.RoutingRule) XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 24 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 logging configuration into an XML byte array.
 *
 * @param loggingConfiguration The configuration to convert.
 * @return The XML byte array representation.
 */
public byte[] convertToXmlByteArray(BucketLoggingConfiguration loggingConfiguration) {
    // Default log file prefix to the empty string if none is specified
    String logFilePrefix = loggingConfiguration.getLogFilePrefix();
    if (logFilePrefix == null) {
        logFilePrefix = "";
    }
    final XmlWriter xml = new XmlWriter();
    xml.start("BucketLoggingStatus", "xmlns", Constants.XML_NAMESPACE);
    if (loggingConfiguration.isLoggingEnabled()) {
        xml.start("LoggingEnabled");
        xml.start("TargetBucket").value(loggingConfiguration.getDestinationBucketName()).end();
        xml.start("TargetPrefix").value(loggingConfiguration.getLogFilePrefix()).end();
        xml.end();
    }
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 25 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 versioning configuration into an XML byte array.
 *
 * @param versioningConfiguration The configuration to convert.
 * @return The XML byte array representation.
 */
public byte[] convertToXmlByteArray(BucketVersioningConfiguration versioningConfiguration) {
    final XmlWriter xml = new XmlWriter();
    xml.start("VersioningConfiguration", "xmlns", Constants.XML_NAMESPACE);
    xml.start("Status").value(versioningConfiguration.getStatus()).end();
    final Boolean mfaDeleteEnabled = versioningConfiguration.isMfaDeleteEnabled();
    if (mfaDeleteEnabled != null) {
        if (mfaDeleteEnabled) {
            xml.start("MfaDelete").value("Enabled").end();
        } else {
            xml.start("MfaDelete").value("Disabled").end();
        }
    }
    xml.end();
    return xml.getBytes();
}
Also used : 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