Skip to content

Instantly share code, notes, and snippets.

@OlivierJaquemet
Last active February 9, 2018 11:40
Show Gist options
  • Save OlivierJaquemet/71bc20708832a391593d3a286ef27b83 to your computer and use it in GitHub Desktop.
Save OlivierJaquemet/71bc20708832a391593d3a286ef27b83 to your computer and use it in GitHub Desktop.
JPlatform URL Media template JSP allowing GitHub Gist URL to be inserted and displayed in Jalios JPlatform
# 1. Copy JSP in your JPlatform webapp
# 2. Declare this JPlatform URL media template with the following properties (adapte th JSP path) :
# GitHub Gist
media.template.default.URL.github-gist.enabled: true
media.template.default.URL.github-gist.regex: ^(?:https?:)?//gist.github.com/([A-Za-z\\d](?:[A-Za-z\\d]|-(?=[A-Za-z\\d])){0,38})/([0-9A-Za-z]+).*
media.template.default.URL.github-gist.jsp: /jcore/media/url/mediaTemplateGitHubGist.jsp
<%--
@Summary: Template used to display a GitHub Gist
--%><%@ page import="java.util.regex.Matcher" %><%
%><%@ page import="java.util.regex.Pattern" %><%
%><%@ include file='/jcore/doInitPage.jspf' %><%
%><%@ include file='/jcore/media/mediaTemplateInit.jspf' %><%
if (Util.isEmpty(url)){
return;
}
String gistRegex = channel.getProperty("media.template.default.URL.github-gist.regex", "");
Pattern gistPattern = Pattern.compile(gistRegex, Pattern.CASE_INSENSITIVE);
Matcher matcher = gistPattern.matcher(url);
if (!matcher.matches()) {
return;
}
String gistUserName = matcher.group(1);
String gistId = matcher.group(2);
if (Util.isEmpty(gistUserName) || Util.isEmpty(gistId)){
return;
}
String cssClass = encodeForHTMLAttribute(getUntrustedStringParameter("class", "embed-responsive-16by9"));
String cssStyle = encodeForHTMLAttribute(getUntrustedStringParameter("style", ""));
cssClass = cssClass != null ? "class=\"github-gist embed-responsive "+cssClass+"\"" : "class=\"github-gist embed-responsive embed-responsive-16by9\"";
cssStyle = cssStyle != null ? "style=\""+cssStyle+"\"" : "";
%>
<div <%= cssClass %> <%= cssStyle %>>
<iframe class="embed-responsive-item"
src="https://gist.github.com/<%= encodeForURL(gistUserName) %>/<%= encodeForURL(gistId) %>.pibb"
frameborder="0"
allowfullscreen></iframe>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment