* @throws ParserConfigurationException
* @throws FactoryConfigurationError
*/
protected String buildDistributionConfigXmlDocument(DistributionConfig config)
throws TransformerException, ParserConfigurationException, FactoryConfigurationError {
XMLBuilder builder = XMLBuilder.create(config.isStreamingDistributionConfig()
? "StreamingDistributionConfig"
: "DistributionConfig")
.a("xmlns", XML_NAMESPACE);
builder.e("CallerReference").t(config.getCallerReference() == null ? String.valueOf(System.currentTimeMillis()) : config.getCallerReference());
XMLBuilder aliasesBuilder = builder.e("Aliases");
if(config.getCNAMEs() != null && config.getCNAMEs().length > 0) {
aliasesBuilder.e("Quantity").t(String.valueOf(config.getCNAMEs().length));
XMLBuilder items = aliasesBuilder.e("Items");
for(String cname : config.getCNAMEs()) {
items.e("CNAME").t(cname);
}
}
else {
aliasesBuilder.e("Quantity").t(String.valueOf("0"));
}
if(config.getDefaultRootObject() != null) {
builder.e("DefaultRootObject").t(config.getDefaultRootObject());
}
else {
builder.e("DefaultRootObject");
}
if(config.isStreamingDistributionConfig()) {
if(config.getOrigins().length == 1) {
final S3Origin bucket = (S3Origin) config.getOrigins()[0];
final XMLBuilder origin = builder.e("S3Origin");
origin.e("DomainName").t(sanitizeS3BucketName(bucket.getDomainName()));
origin.e("OriginAccessIdentity");
if(bucket.getOriginAccessIdentity() != null) {
origin.t(bucket.getOriginAccessIdentity());
}
}
}
else {
XMLBuilder originsBuilder = builder
.e("Origins")
.e("Quantity").t(String.valueOf(config.getOrigins().length)).up()
.e("Items");
for(Origin origin : config.getOrigins()) {
originsBuilder.importXMLBuilder(buildOrigin(origin));
}
}
if(config.isStreamingDistributionConfig()) {
builder.importXMLBuilder(buildTrustedSigners(config.getTrustedSignerAwsAccountNumbers()));