/*
 * #%L
 * Kipeto Core
 * %%
 * Copyright (C) 2010 - 2011 Ecclesia Versicherungsdienst GmbH
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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.
 * #L%
 */
package de.ecclesia.kipeto.repository;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class StrategySelector {

	private static final Logger logger = LoggerFactory.getLogger(StrategySelector.class);

	public static ReadingRepositoryStrategy getReadingStrategy(String url) {
		return getReadingStrategy(url, null, null);
	}

	public static ReadingRepositoryStrategy getReadingStrategy(String url, File tempDir) {
		return getReadingStrategy(url, null, tempDir);
	}

	public static ReadingRepositoryStrategy getReadingStrategy(String url, AuthenticationProvider authenticationProvider) {
		return getReadingStrategy(url, authenticationProvider, null);
	}	
	
	
	public static ReadingRepositoryStrategy getReadingStrategy(String url, AuthenticationProvider authenticationProvider, File tempDir) {
		ReadingRepositoryStrategy repository;
		if (url.toLowerCase().startsWith("http:")) {
			repository = new HttpRepositoryStrategy(url);
		} else if (url.toLowerCase().startsWith("ssh:")) {
			repository = new SFTPRepositoryStrategy(url, authenticationProvider, tempDir);
		} else {
			repository = new FileRepositoryStrategy(new File(url), tempDir);
		}

		logger.debug("Selecting reading strategy {} for URL {}", repository.getClass().getSimpleName(), url);

		return repository;
	}

	public static WritingRepositoryStrategy getWritingStrategy(String url) {
		return getWritingStrategy(url, null);
	}

	public static WritingRepositoryStrategy getWritingStrategy(String url, File tempDir) {
		return getWritingStrategy(url, null, tempDir);
	}

	public static WritingRepositoryStrategy getWritingStrategy(String url, AuthenticationProvider authenticationProvider, File tempDir) {
		WritingRepositoryStrategy repository;

		if (url.toLowerCase().startsWith("http:")) {
			throw new UnsupportedOperationException("There is no WritingRepositoryStrategy for http-Repositorys");
		} else if (url.toLowerCase().startsWith("ssh:")) {
			repository = new SFTPRepositoryStrategy(url, authenticationProvider, tempDir);
		} else {
			repository = new FileRepositoryStrategy(new File(url), tempDir);
		}

		logger.debug("Selecting writing strategy {} for URL {}", repository.getClass().getSimpleName(), url);

		return repository;
	}
}

@@ -1355,21 +1355,17 @@
 ull);%0A%09%7D
-%09%0A%09%0A%09
+%0A
 %0A%09public
@@ -1492,16 +1492,43 @@
 pDir) %7B%0A
+%09%09url = url.toLowerCase();%0A
 %09%09Readin
@@ -1559,16 +1559,17 @@
 sitory;%0A
+%0A
 %09%09if (ur
@@ -1566,37 +1566,50 @@
 %0A%0A%09%09if (url.
-toLowerCase()
+startsWith(%22http:%22) %7C%7C url
 .startsWith(
@@ -1605,32 +1605,33 @@
 startsWith(%22http
+s
 :%22)) %7B%0A%09%09%09reposi

Add https support