Search in sources :

Example 1 with XmlWriter

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

the class AclXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified AccessControlList object to an XML fragment that can be sent to COS.
 *
 * @param acl The AccessControlList to convert to XML.
 *
 * @return an XML representation of the Access Control List object, suitable to send in a
 *         request to COS.
 */
public byte[] convertToXmlByteArray(AccessControlList acl) throws CosClientException {
    Owner owner = acl.getOwner();
    if (owner == null) {
        throw new CosClientException("Invalid AccessControlList: missing an COS Owner");
    }
    XmlWriter xml = new XmlWriter();
    xml.start("AccessControlPolicy");
    xml.start("Owner");
    if (owner.getId() != null) {
        xml.start("ID").value(owner.getId()).end();
    }
    if (owner.getDisplayName() != null) {
        xml.start("DisplayName").value(owner.getDisplayName()).end();
    }
    xml.end();
    xml.start("AccessControlList");
    for (Grant grant : acl.getGrantsAsList()) {
        xml.start("Grant");
        convertToXml(grant.getGrantee(), xml);
        xml.start("Permission").value(grant.getPermission().toString()).end();
        xml.end();
    }
    xml.end();
    xml.end();
    return xml.getBytes();
}
Also used : CosClientException(com.qcloud.cos.exception.CosClientException) XmlWriter(com.qcloud.cos.internal.XmlWriter)

Example 2 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(BucketRefererConfiguration refererConfiguration) {
    XmlWriter xml = new XmlWriter();
    xml.start("RefererConfiguration");
    xml.start("Status").value(refererConfiguration.getStatus()).end();
    xml.start("RefererType").value(refererConfiguration.getRefererType()).end();
    xml.start("DomainList");
    for (String domain : refererConfiguration.getDomainList()) {
        xml.start("Domain").value(domain).end();
    }
    xml.end();
    String emptyReferConfiguration = refererConfiguration.getEmptyReferConfiguration();
    if (emptyReferConfiguration != null && (emptyReferConfiguration == BucketRefererConfiguration.DENY || emptyReferConfiguration == BucketRefererConfiguration.ALLOW)) {
        xml.start("EmptyReferConfiguration").value(emptyReferConfiguration).end();
    }
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.qcloud.cos.internal.XmlWriter)

Example 3 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 versioning configuration into an XML byte array.
 *
 * @param versioningConfiguration The configuration to convert.
 *
 * @return The XML byte array representation.
 */
public byte[] convertToXmlByteArray(BucketVersioningConfiguration versioningConfiguration) {
    XmlWriter xml = new XmlWriter();
    xml.start("VersioningConfiguration");
    xml.start("Status").value(versioningConfiguration.getStatus()).end();
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.qcloud.cos.internal.XmlWriter)

Example 4 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 {@link BucketCrossOriginConfiguration} object to an XML fragment that
 * can be sent to Qcloud COS.
 *
 * @param config The {@link BucketCrossOriginConfiguration}
 */
/*
     * <CORSConfiguration>
             <CORSRule>
               <AllowedOrigin>http://www.foobar.com</AllowedOrigin>
               <AllowedMethod>GET</AllowedMethod>
               <MaxAgeSeconds>3000</MaxAgeSec>
               <ExposeHeader>x-cos-meta</ExposeHeader>
             </CORSRule>
       </CORSConfiguration>
     */
public byte[] convertToXmlByteArray(BucketCrossOriginConfiguration config) throws CosClientException {
    XmlWriter xml = new XmlWriter();
    xml.start("CORSConfiguration");
    for (CORSRule rule : config.getRules()) {
        writeRule(xml, rule);
    }
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.qcloud.cos.internal.XmlWriter)

Example 5 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(BucketTaggingConfiguration config) throws CosClientException {
    XmlWriter xml = new XmlWriter();
    xml.start("Tagging");
    for (TagSet tagset : config.getAllTagSets()) {
        writeRule(xml, tagset);
    }
    xml.end();
    return xml.getBytes();
}
Also used : 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