Search in sources :

Example 6 with XmlWriter

use of com.qcloud.cos.internal.XmlWriter in project cos-java-sdk-v5 by tencentyun.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

public byte[] convertToXmlByteArray(BucketIntelligentTierConfiguration configuration) throws CosClientException {
    XmlWriter xml = new XmlWriter();
    xml.start("IntelligentTieringConfiguration");
    String status = configuration.getStatus();
    xml.start("Status").value(status).end();
    BucketIntelligentTierConfiguration.Transition transition = configuration.getTransition();
    if (status.equals(BucketIntelligentTierConfiguration.ENABLED) && transition != null) {
        xml.start("Transition");
        xml.start("Days").value(Integer.toString(transition.getDays())).end();
        xml.start("RequestFrequent").value(Integer.toString(transition.getRequestFrequent())).end();
        xml.end();
    }
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.qcloud.cos.internal.XmlWriter)

Example 7 with XmlWriter

use of com.qcloud.cos.internal.XmlWriter in project cos-java-sdk-v5 by tencentyun.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified website configuration into an XML byte array to
 * send to COS.
 *
 * 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) {
    XmlWriter xml = new XmlWriter();
    xml.start("WebsiteConfiguration");
    if (websiteConfiguration.getIndexDocumentSuffix() != null) {
        XmlWriter indexDocumentElement = xml.start("IndexDocument");
        indexDocumentElement.start("Suffix").value(websiteConfiguration.getIndexDocumentSuffix()).end();
        indexDocumentElement.end();
    }
    if (websiteConfiguration.getErrorDocument() != null) {
        XmlWriter errorDocumentElement = xml.start("ErrorDocument");
        errorDocumentElement.start("Key").value(websiteConfiguration.getErrorDocument()).end();
        errorDocumentElement.end();
    }
    RedirectRule redirectAllRequestsTo = websiteConfiguration.getRedirectAllRequestsTo();
    if (redirectAllRequestsTo != null) {
        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) {
        XmlWriter routingRules = xml.start("RoutingRules");
        for (RoutingRule rule : websiteConfiguration.getRoutingRules()) {
            writeRule(routingRules, rule);
        }
        routingRules.end();
    }
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.qcloud.cos.internal.XmlWriter)

Example 8 with XmlWriter

use of com.qcloud.cos.internal.XmlWriter in project cos-java-sdk-v5 by tencentyun.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

public byte[] convertToXmlByteArray(BucketDomainConfiguration domainConfiguration) {
    XmlWriter xml = new XmlWriter();
    xml.start("DomainConfiguration");
    for (DomainRule rule : domainConfiguration.getDomainRules()) {
        writeRule(xml, rule);
    }
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.qcloud.cos.internal.XmlWriter)

Example 9 with XmlWriter

use of com.qcloud.cos.internal.XmlWriter in project cos-java-sdk-v5 by tencentyun.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

public byte[] convertToXmlByteArray(InventoryConfiguration config) throws CosClientException {
    XmlWriter xml = new XmlWriter();
    xml.start("InventoryConfiguration");
    xml.start("Id").value(config.getId()).end();
    xml.start("IsEnabled").value(String.valueOf(config.isEnabled())).end();
    xml.start("IncludedObjectVersions").value(config.getIncludedObjectVersions()).end();
    writeInventoryDestination(xml, config.getDestination());
    writeInventoryFilter(xml, config.getInventoryFilter());
    addInventorySchedule(xml, config.getSchedule());
    addInventoryOptionalFields(xml, config.getOptionalFields());
    // </InventoryConfiguration>
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.qcloud.cos.internal.XmlWriter)

Example 10 with XmlWriter

use of com.qcloud.cos.internal.XmlWriter in project cos-java-sdk-v5 by tencentyun.

the class ObjectTaggingXmlFactory method convertToXmlByteArray.

public byte[] convertToXmlByteArray(ObjectTagging tagging) {
    XmlWriter writer = new XmlWriter();
    writer.start("Tagging").start("TagSet");
    for (Tag tag : tagging.getTagSet()) {
        writer.start("Tag");
        writer.start("Key").value(tag.getKey()).end();
        writer.start("Value").value(tag.getValue()).end();
        // </Tag>
        writer.end();
    }
    // </TagSet>
    writer.end();
    // </Tagging>
    writer.end();
    return writer.getBytes();
}
Also used : Tag(com.qcloud.cos.model.Tag.Tag) XmlWriter(com.qcloud.cos.internal.XmlWriter)

Aggregations

XmlWriter (com.qcloud.cos.internal.XmlWriter)13 CosClientException (com.qcloud.cos.exception.CosClientException)1 Rule (com.qcloud.cos.model.BucketLifecycleConfiguration.Rule)1 Tag (com.qcloud.cos.model.Tag.Tag)1