001/* 002 * (C) Copyright 2019 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.blob; 020 021import java.io.IOException; 022import java.util.Map; 023 024import org.nuxeo.ecm.core.blob.AbstractBlobStoreConfiguration; 025import org.nuxeo.ecm.core.blob.CachingConfiguration; 026import org.nuxeo.ecm.core.blob.DigestConfiguration; 027 028/** 029 * Abstract blob store configuration for cloud providers. 030 * 031 * @since 11.1 032 */ 033public abstract class CloudBlobStoreConfiguration extends AbstractBlobStoreConfiguration { 034 035 public static final String DIRECTDOWNLOAD_PROPERTY = "directdownload"; 036 037 public static final String DEFAULT_DIRECTDOWNLOAD = "false"; 038 039 public static final String DIRECTDOWNLOAD_EXPIRE_PROPERTY = "directdownload.expire"; 040 041 public static final long DEFAULT_DIRECTDOWNLOAD_EXPIRE = 60L * 60L; // 1h 042 043 public static final String DIGEST_ALGORITHM_PROPERTY = "digest"; 044 045 public final DigestConfiguration digestConfiguration; 046 047 public final CachingConfiguration cachingConfiguration; 048 049 public final boolean directDownload; 050 051 public final long directDownloadExpire; 052 053 public CloudBlobStoreConfiguration(String systemPropertyPrefix, Map<String, String> properties) throws IOException { 054 super(systemPropertyPrefix, properties); 055 056 digestConfiguration = new DigestConfiguration(systemPropertyPrefix, properties); 057 cachingConfiguration = new CachingConfiguration(systemPropertyPrefix, properties); 058 059 directDownload = parseDirectDownload(); 060 directDownloadExpire = parseDirectDownloadExpire(); 061 } 062 063 protected boolean parseDirectDownload() { 064 return Boolean.parseBoolean(getProperty(DIRECTDOWNLOAD_PROPERTY, DEFAULT_DIRECTDOWNLOAD)); 065 } 066 067 protected long parseDirectDownloadExpire() { 068 long expire = getLongProperty(DIRECTDOWNLOAD_EXPIRE_PROPERTY); 069 if (expire < 0) { 070 expire = DEFAULT_DIRECTDOWNLOAD_EXPIRE; 071 } 072 return expire; 073 } 074 075}