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

com.ja.smarkdown.Index Maven / Gradle / Ivy

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

import java.net.HttpURLConnection;

import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import lombok.Data;

import org.apache.commons.lang3.StringUtils;

import com.ja.smarkdown.load.ResourceLoader;
import com.ja.smarkdown.model.ResourceInfo;
import com.ja.smarkdown.preprocessing.MarkdownPreprocessor;
import com.ja.smarkdown.util.UrlUtils;

@Named
@RequestScoped
@Data
public class Index {

	@Inject
	private MarkdownPreprocessor preprocessor;
	@Inject
	private ResourceLoader loader;

	private String page = "index";

	private Boolean checkDuplicates;

	public String getContent() {
		final ResourceInfo doc = loader.loadResource(getPageName() + ".md",
				checkDuplicates);
		if (doc == null) {
			FacesContext.getCurrentInstance().getExternalContext()
					.setResponseStatus(HttpURLConnection.HTTP_NOT_FOUND);
			return "Page not found.";
		}
		return preprocessor.process(page, doc);
	}

	public String getPageName() {
		return StringUtils.removeEnd(UrlUtils.decode(page), ".html");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy