Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.s3.model.transform;
 
Factory for creating XML fragments from AccessControlList objects that can be sent to Amazon S3 as part of requests.
 
 public class AclXmlFactory {

    
Converts the specified AccessControlList object to an XML fragment that can be sent to Amazon S3.

Parameters:
acl The AccessControlList to convert to XML.
Returns:
an XML representation of the Access Control List object, suitable to send in a request to Amazon S3.
 
     public byte[] convertToXmlByteArray(AccessControlList aclthrows AmazonClientException {
         Owner owner = acl.getOwner();
         if (owner == null) {
             throw new AmazonClientException("Invalid AccessControlList: missing an S3Owner");
         }
 
         XmlWriter xml = new XmlWriter();
         xml.start("AccessControlPolicy""xmlns".);
         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();
     }

    
Returns an XML fragment representing the specified Grantee.

Parameters:
grantee The grantee to convert to an XML representation that can be sent to Amazon S3 as part of a request.
xml The XmlWriter to which to concatenate this node to.
Returns:
The given XmlWriter containing the specified grantee.
Throws:
com.amazonaws.AmazonClientException If the specified grantee type isn't recognized.
 
     protected XmlWriter convertToXml(Grantee granteeXmlWriter xmlthrows AmazonClientException {
         if (grantee instanceof CanonicalGrantee) {
             return convertToXml((CanonicalGrantee)granteexml);
         } else if (grantee instanceof EmailAddressGrantee) {
             return convertToXml((EmailAddressGrantee)granteexml);
         } else if (grantee instanceof GroupGrantee) {
             return convertToXml((GroupGrantee)granteexml);
         } else {
             throw new AmazonClientException("Unknown Grantee type: " + grantee.getClass().getName());
         }
     }

    
Returns an XML fragment representing the specified canonical grantee.

Parameters:
grantee The canonical grantee to convert to an XML representation that can be sent to Amazon S3 as part of request.
xml The XmlWriter to which to concatenate this node to.
Returns:
The given XmlWriter containing the specified canonical grantee.
    protected XmlWriter convertToXml(CanonicalGrantee granteeXmlWriter xml) {
        xml.start("Grantee"new String[] {"xmlns:xsi" , "xsi:type"},
                new String[] {"http://www.w3.org/2001/XMLSchema-instance""CanonicalUser"});
        xml.start("ID").value(grantee.getIdentifier()).end();
        xml.end();
        return xml;
    }

    
Returns an XML fragment representing the specified email address grantee.

Parameters:
grantee The email address grantee to convert to an XML representation that can be sent to Amazon S3 as part of request.
xml The XmlWriter to which to concatenate this node to.
Returns:
The given XmlWriter containing the specified email address grantee
    protected XmlWriter convertToXml(EmailAddressGrantee granteeXmlWriter xml) {
        xml.start("Grantee"new String[] {"xmlns:xsi" , "xsi:type"},
                new String[] {"http://www.w3.org/2001/XMLSchema-instance""AmazonCustomerByEmail"});
        xml.start("EmailAddress").value(grantee.getIdentifier()).end();
        xml.end();
        return xml;
    }

    
Returns an XML fragment representing the specified group grantee.

Parameters:
grantee The group grantee to convert to an XML representation that can be sent to Amazon S3 as part of request.
xml The XmlWriter to which to concatenate this node to.
Returns:
The given XmlWriter containing the specified group grantee.
    protected XmlWriter convertToXml(GroupGrantee granteeXmlWriter xml) {
        xml.start("Grantee"new String[] {"xmlns:xsi" , "xsi:type"},
                new String[] {"http://www.w3.org/2001/XMLSchema-instance""Group"});
        xml.start("URI").value(grantee.getIdentifier()).end();
        xml.end();
        return xml;
    }
New to GrepCode? Check out our FAQ X