john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

AppProperties S3Service

// 2012-08-29 johnpfeiffer requires JohnStringUtils
// TODO: further validation: host (dns or ip), user

public class S3Service
{
    protected static final String PARAMS3ISAVAILABLE = "s3.isAvailable";
    protected static final String PARAMS3ACCESSKEY = "s3.accessKey";
    protected static final String PARAMS3SECRETACCESSKEY = "s3.secretAccessKey";
    protected static final String PARAMS3BUCKETNAME = "s3.bucketName";
    protected static final String PARAMS3RRS = "s3.RRS";
    protected static final String PARAMS3SERVICEENDPOINT = "s3.serviceEndpoint";
    protected static final String PARAMS3HTTPSONLY = "s3.httpsOnly";
    protected static final String PARAMS3PORT = "s3.Port";

    private boolean s3IsAvailable = false;
    private String s3AccessKey = "";
    private boolean s3RRS = false;
    private String s3SecretAccessKey = "";
    private boolean s3HttpsOnly = false;
    private String s3BucketName = "";
    private int s3Port = 80;
    private String s3ServiceEndpoint = "";

    S3Service()
    {
    }

    S3Service( boolean s3IsAvailable , String s3AccessKey , boolean s3RRS , String s3SecretAccessKey , boolean s3HttpsOnly , String s3BucketName , int s3Port ,
            String s3ServiceEndpoint )
    {
        super();
        if( s3AccessKey == null )
        {
            throw new IllegalArgumentException( "ERROR: s3AccessKey cannot be null" );
        }
        if( s3SecretAccessKey == null )
        {
            throw new IllegalArgumentException( "ERROR: s3SecretAccessKey cannot be null" );
        }
        if( s3BucketName == null )
        {
            throw new IllegalArgumentException( "ERROR: s3BucketName cannot be null" );
        }
        if( s3ServiceEndpoint == null )
        {
            throw new IllegalArgumentException( "ERROR: s3ServiceEndpoint cannot be null" );
        }
        this.s3IsAvailable = s3IsAvailable;
        this.s3AccessKey = s3AccessKey;
        this.s3RRS = s3RRS;
        this.s3SecretAccessKey = s3SecretAccessKey;
        this.s3HttpsOnly = s3HttpsOnly;
        this.s3BucketName = s3BucketName;
        this.s3Port = s3Port;
        this.s3ServiceEndpoint = s3ServiceEndpoint;
    }

    protected String getString( String header )
    {
        StringBuilder strb = new StringBuilder();
        String newline = System.getProperty( "line.separator" );
        strb.append( header + PARAMS3ISAVAILABLE + "=" + s3IsAvailable + newline );
        strb.append( header + PARAMS3ACCESSKEY + "=" + s3AccessKey + newline );
        strb.append( header + PARAMS3RRS + "=" + s3RRS + newline );
        strb.append( header + PARAMS3SECRETACCESSKEY + "=" + s3SecretAccessKey + newline );
        strb.append( header + PARAMS3HTTPSONLY + "=" + s3HttpsOnly + newline );
        strb.append( header + PARAMS3BUCKETNAME + "=" + s3BucketName + newline );
        strb.append( header + PARAMS3PORT + "=" + s3Port + newline );
        strb.append( header + PARAMS3SERVICEENDPOINT + "=" + s3ServiceEndpoint + newline );
        return strb.toString();
    }

    protected String getHTMLForm()
    {
        StringBuilder strb = new StringBuilder();
        String newline = "<br /><br />" + System.getProperty( "line.separator" );
        String space = "&#xA0;";
        strb.append( "<label>AccessKey Username:</label>" + space + space + "<input type='text' name='" + PARAMS3ACCESSKEY + "' size='60' value='"
                + JohnStringUtils.safeHTML( s3AccessKey ) + "' /> " + newline );
        strb.append( "<label>SecretAccessKey:</label>" + space + space + "<input type='text' name='" + PARAMS3SECRETACCESSKEY + "' size='40' value='"
                + JohnStringUtils.safeHTML( s3SecretAccessKey ) + "' /> " + newline );
        strb.append( "<label>BucketName:</label>" + space + space + "<input type='text' name='" + PARAMS3BUCKETNAME + "' size='40' value='"
                + JohnStringUtils.safeHTML( s3BucketName ) + "' /> " + newline );
        return strb.toString();
    }

} // end class

  • « AppProperties NirvanixService
  • AppProperties StorageGatewayService »

Published

Aug 30, 2012

Category

java-servlet

~288 words

Tags

  • appproperties 18
  • java-servlet 61
  • s3service 1