| | |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | | import com.google.inject.Inject; |
| | | import com.google.inject.Singleton; |
| | | import javax.servlet.ServletContext; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServlet; |
| | |
| | | import com.gitblit.utils.JGitUtils; |
| | | import com.gitblit.utils.MarkdownUtils; |
| | | import com.gitblit.utils.StringUtils; |
| | | import com.google.inject.Inject; |
| | | import com.google.inject.Singleton; |
| | | |
| | | /** |
| | | * Serves the content of a branch. |
| | |
| | | branch = Repository.shortenRefName(branch).replace('/', fsc); |
| | | } |
| | | |
| | | String encodedPath = path == null ? "" : path.replace(' ', '-'); |
| | | encodedPath = encodedPath.replace('/', fsc); |
| | | return baseURL + Constants.RAW_PATH + repository + "/" + (branch == null ? "" : (branch + "/" + (path == null ? "" : encodedPath))); |
| | | String encodedPath = path == null ? "" : path.replace('/', fsc); |
| | | return baseURL + Constants.RAW_PATH + repository + "/" + (branch == null ? "" : (branch + "/" + encodedPath)); |
| | | } |
| | | |
| | | protected String getBranch(String repository, HttpServletRequest request) { |
| | |
| | | } else { |
| | | repository = path.substring(0, slash); |
| | | } |
| | | offset += ( slash + 1 ); |
| | | offset = ( slash + 1 ); |
| | | r = repositoryManager.getRepository(repository, false); |
| | | if (repository.equals(path)) { |
| | | // either only repository in url or no repository found |
| | |
| | | return; |
| | | } |
| | | |
| | | Map<String, String> quickContentTypes = new HashMap<>(); |
| | | quickContentTypes.put("html", "text/html"); |
| | | quickContentTypes.put("htm", "text/html"); |
| | | quickContentTypes.put("xml", "application/xml"); |
| | | quickContentTypes.put("json", "application/json"); |
| | | |
| | | List<PathModel> pathEntries = JGitUtils.getFilesInPath(r, requestedPath, commit); |
| | | if (pathEntries.isEmpty()) { |
| | | // requested a specific resource |
| | | String file = StringUtils.getLastPathElement(requestedPath); |
| | | try { |
| | | // query Tika for the content type |
| | | Tika tika = new Tika(); |
| | | String contentType = tika.detect(file); |
| | | |
| | | String ext = StringUtils.getFileExtension(file).toLowerCase(); |
| | | String contentType = quickContentTypes.get(ext); |
| | | |
| | | if (contentType == null) { |
| | | List<String> exts = runtimeManager.getSettings().getStrings(Keys.web.prettyPrintExtensions); |
| | | if (exts.contains(ext)) { |
| | | // extension is a registered text type for pretty printing |
| | | contentType = "text/plain"; |
| | | } else { |
| | | // query Tika for the content type |
| | | Tika tika = new Tika(); |
| | | contentType = tika.detect(file); |
| | | } |
| | | } |
| | | |
| | | if (contentType == null) { |
| | | // ask the container for the content type |
| | |
| | | } |
| | | } |
| | | |
| | | if (isTextType(contentType)) { |
| | | if (isTextType(contentType) || isTextDataType(contentType)) { |
| | | |
| | | // load, interpret, and serve text content as UTF-8 |
| | | String [] encodings = runtimeManager.getSettings().getStrings(Keys.web.blobEncodings).toArray(new String[0]); |
| | |
| | | return false; |
| | | } |
| | | |
| | | protected boolean isTextDataType(String contentType) { |
| | | if ("image/svg+xml".equals(contentType)) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * Override all text types to be plain text. |
| | | * |
| | |
| | | served = true; |
| | | } |
| | | } finally { |
| | | tw.release(); |
| | | tw.close(); |
| | | rw.dispose(); |
| | | } |
| | | |