All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ja.smarkdown.location.http.AbstractHttpDocumentProvider Maven / Gradle / Ivy

There is a newer version: 0.8.0
Show newest version
package com.ja.smarkdown.location.http;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import com.ja.smarkdown.load.AbstractDocumentProvider;
import com.ja.smarkdown.model.ResourceInfo;

@Slf4j
public class AbstractHttpDocumentProvider extends
		AbstractDocumentProvider {

	@Getter
	private String realProtocol;

	public AbstractHttpDocumentProvider(final String protocol) {
		this(protocol, protocol);
	}

	public AbstractHttpDocumentProvider(final String protocol,
			final String realProtocol) {
		super(protocol, "");
		this.realProtocol = realProtocol;
	}

	@Override
	protected ResourceInfo getResource(final HttpLocation location,
			final String path) throws FileNotFoundException {
		final String url = resolveUrl(path);
		log.debug("Resolved url={}", url);
		try {
			final URL resourceUrl = new URL(url);
			return new ResourceInfo(path, location, resourceUrl.openStream());
		} catch (final IOException e) {
			throw new FileNotFoundException(path + " " + e);
		}
	}

	protected String resolveUrl(final String path) {
		return String.format("%s%s", getRealProtocol(), path);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy