Fix code highlighting

This commit is contained in:
jamesagnew 2014-06-26 09:06:10 -04:00
parent 3bc1d35698
commit 97e17f9149
4 changed files with 199 additions and 45 deletions

View File

@ -34,6 +34,8 @@ import java.util.TimeZone;
import javax.xml.bind.DatatypeConverter; import javax.xml.bind.DatatypeConverter;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.FastDateFormat; import org.apache.commons.lang3.time.FastDateFormat;
import ca.uhn.fhir.model.api.BasePrimitive; import ca.uhn.fhir.model.api.BasePrimitive;
@ -44,17 +46,17 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
private static final FastDateFormat ourYearFormat = FastDateFormat.getInstance("yyyy"); private static final FastDateFormat ourYearFormat = FastDateFormat.getInstance("yyyy");
private static final FastDateFormat ourYearMonthDayFormat = FastDateFormat.getInstance("yyyy-MM-dd"); private static final FastDateFormat ourYearMonthDayFormat = FastDateFormat.getInstance("yyyy-MM-dd");
private static final FastDateFormat ourYearMonthFormat = FastDateFormat.getInstance("yyyy-MM");
private static final FastDateFormat ourYearMonthDayNoDashesFormat = FastDateFormat.getInstance("yyyyMMdd"); private static final FastDateFormat ourYearMonthDayNoDashesFormat = FastDateFormat.getInstance("yyyyMMdd");
private static final FastDateFormat ourYearMonthDayTimeFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss"); private static final FastDateFormat ourYearMonthDayTimeFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss");
private static final FastDateFormat ourYearMonthDayTimeZoneFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssZZ");
private static final FastDateFormat ourYearMonthDayTimeMilliZoneFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
private static final FastDateFormat ourYearMonthDayTimeMilliFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS"); private static final FastDateFormat ourYearMonthDayTimeMilliFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS");
private static final FastDateFormat ourYearMonthDayTimeMilliZoneFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
private static final FastDateFormat ourYearMonthDayTimeZoneFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssZZ");
private static final FastDateFormat ourYearMonthFormat = FastDateFormat.getInstance("yyyy-MM");
private TemporalPrecisionEnum myPrecision = TemporalPrecisionEnum.SECOND; private TemporalPrecisionEnum myPrecision = TemporalPrecisionEnum.SECOND;
private Date myValue;
private TimeZone myTimeZone; private TimeZone myTimeZone;
private boolean myTimeZoneZulu = false; private boolean myTimeZoneZulu = false;
private Date myValue;
/** /**
* Gets the precision for this datatype using field values from * Gets the precision for this datatype using field values from
@ -67,6 +69,10 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
return myPrecision; return myPrecision;
} }
public TimeZone getTimeZone() {
return myTimeZone;
}
@Override @Override
public Date getValue() { public Date getValue() {
return myValue; return myValue;
@ -113,6 +119,20 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
} }
} }
public boolean isTimeZoneZulu() {
return myTimeZoneZulu;
}
/**
* Returns <code>true</code> if this object represents a date that is today's date
*
* @throws NullPointerException if {@link #getValue()} returns <code>null</code>
*/
public boolean isToday() {
Validate.notNull(myValue, getClass().getSimpleName() + " contains null value");
return DateUtils.isSameDay(new Date(), myValue);
}
/** /**
* Sets the precision for this datatype using field values from * Sets the precision for this datatype using field values from
* {@link Calendar}. Valid values are: * {@link Calendar}. Valid values are:
@ -132,6 +152,14 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
myPrecision = thePrecision; myPrecision = thePrecision;
} }
public void setTimeZone(TimeZone theTimeZone) {
myTimeZone = theTimeZone;
}
public void setTimeZoneZulu(boolean theTimeZoneZulu) {
myTimeZoneZulu = theTimeZoneZulu;
}
@Override @Override
public void setValue(Date theValue) throws DataFormatException { public void setValue(Date theValue) throws DataFormatException {
myValue = theValue; myValue = theValue;
@ -214,22 +242,6 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
} }
} }
public TimeZone getTimeZone() {
return myTimeZone;
}
public void setTimeZone(TimeZone theTimeZone) {
myTimeZone = theTimeZone;
}
public boolean isTimeZoneZulu() {
return myTimeZoneZulu;
}
public void setTimeZoneZulu(boolean theTimeZoneZulu) {
myTimeZoneZulu = theTimeZoneZulu;
}
private void clearTimeZone() { private void clearTimeZone() {
myTimeZone = null; myTimeZone = null;
myTimeZoneZulu = false; myTimeZoneZulu = false;

View File

@ -25,6 +25,7 @@ import static org.apache.commons.lang3.StringUtils.*;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -290,8 +291,11 @@ public class RestfulTesterServlet extends HttpServlet {
return; return;
} }
returnsResource = ResultType.TAGLIST; url = url.replace("&amp;", "&");
outcomeDescription = "Tag List"; client.loadPage().url(url).execute();
returnsResource = ResultType.BUNDLE;
outcomeDescription = "Bundle Page";
} else if ("delete".equals(method)) { } else if ("delete".equals(method)) {
RuntimeResourceDefinition def = getResourceType(theReq); RuntimeResourceDefinition def = getResourceType(theReq);
@ -551,11 +555,11 @@ public class RestfulTesterServlet extends HttpServlet {
theContext.setVariable("bundle", bundle); theContext.setVariable("bundle", bundle);
theContext.setVariable("resultStatus", resultStatus); theContext.setVariable("resultStatus", resultStatus);
theContext.setVariable("requestUrl", requestUrl); theContext.setVariable("requestUrl", requestUrl);
String requestBodyText = StringEscapeUtils.escapeHtml4(requestBody); String requestBodyText = format(requestBody, ctEnum);
theContext.setVariable("requestBody", requestBody); theContext.setVariable("requestBody", requestBodyText);
theContext.setVariable("requestSyntaxHighlighterClass", requestSyntaxHighlighterClass); theContext.setVariable("requestSyntaxHighlighterClass", requestSyntaxHighlighterClass);
String resultBodyText = StringEscapeUtils.escapeHtml4(resultBody); String resultBodyText = format(resultBody, ctEnum);
theContext.setVariable("resultBody", resultBody); theContext.setVariable("resultBody", resultBodyText);
theContext.setVariable("resultBodyIsLong", resultBodyText.length() > 1000); theContext.setVariable("resultBodyIsLong", resultBodyText.length() > 1000);
theContext.setVariable("resultSyntaxHighlighterClass", resultSyntaxHighlighterClass); theContext.setVariable("resultSyntaxHighlighterClass", resultSyntaxHighlighterClass);
theContext.setVariable("requestHeaders", requestHeaders); theContext.setVariable("requestHeaders", requestHeaders);
@ -569,6 +573,117 @@ public class RestfulTesterServlet extends HttpServlet {
} }
} }
private String format(String theResultBody, EncodingEnum theEncodingEnum) {
String str = StringEscapeUtils.escapeHtml4(theResultBody);
if (str == null || theEncodingEnum == null) {
return str;
}
StringBuilder b = new StringBuilder();
if (theEncodingEnum == EncodingEnum.JSON) {
boolean inValue = false;
boolean inQuote = false;
for (int i = 0; i < str.length(); i++) {
char prevChar = (i > 0) ? str.charAt(i-1): ' ';
char nextChar = str.charAt(i);
char nextChar2 = (i + 1) < str.length() ? str.charAt(i + 1) : ' ';
char nextChar3 = (i + 2) < str.length() ? str.charAt(i + 2) : ' ';
char nextChar4 = (i + 3) < str.length() ? str.charAt(i + 3) : ' ';
char nextChar5 = (i + 4) < str.length() ? str.charAt(i + 4) : ' ';
char nextChar6 = (i + 5) < str.length() ? str.charAt(i + 5) : ' ';
if (inQuote) {
b.append(nextChar);
if (prevChar != '\\' && nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') {
b.append("quot;</span>");
i += 5;
inQuote = false;
}else if (nextChar == '\\' && nextChar2 == '"') {
b.append("quot;</span>");
i += 5;
inQuote = false;
}
} else {
if (nextChar == ':') {
inValue = true;
b.append(nextChar);
}else if (nextChar == '[' || nextChar == '[') {
b.append("<span class='hlControl'>");
b.append(nextChar);
b.append("</span>");
inValue = false;
}else if (nextChar == '}' || nextChar == '}' || nextChar == ',') {
b.append("<span class='hlControl'>");
b.append(nextChar);
b.append("</span>");
inValue = false;
} else if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') {
if (inValue) {
b.append("<span class='hlQuot'>&quot;");
}else {
b.append("<span class='hlTagName'>&quot;");
}
inQuote = true;
i += 5;
}else if (nextChar == ':') {
b.append("<span class='hlControl'>");
b.append(nextChar);
b.append("</span>");
inValue = true;
} else {
b.append(nextChar);
}
}
}
} else {
boolean inQuote = false;
boolean inTag = false;
for (int i = 0; i < str.length(); i++) {
char nextChar = str.charAt(i);
char nextChar2 = (i + 1) < str.length() ? str.charAt(i + 1) : ' ';
char nextChar3 = (i + 2) < str.length() ? str.charAt(i + 2) : ' ';
char nextChar4 = (i + 3) < str.length() ? str.charAt(i + 3) : ' ';
char nextChar5 = (i + 4) < str.length() ? str.charAt(i + 4) : ' ';
char nextChar6 = (i + 5) < str.length() ? str.charAt(i + 5) : ' ';
if (inQuote) {
b.append(nextChar);
if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') {
b.append("quot;</span>");
i += 5;
inQuote = false;
}
} else if (inTag) {
if (nextChar == '&' && nextChar2 == 'g' && nextChar3 == 't' && nextChar4 == ';') {
b.append("</span><span class='hlControl'>&gt;</span>");
inTag = false;
i += 3;
} else if (nextChar == ' ') {
b.append("</span><span class='hlAttr'>");
b.append(nextChar);
} else if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') {
b.append("<span class='hlQuot'>&quot;");
inQuote = true;
i += 5;
} else {
b.append(nextChar);
}
} else {
if (nextChar == '&' && nextChar2 == 'l' && nextChar3 == 't' && nextChar4 == ';') {
b.append("<span class='hlControl'>&lt;</span><span class='hlTagName'>");
inTag = true;
i += 3;
} else {
b.append(nextChar);
}
}
}
}
return b.toString();
}
private EncodingEnum getRequestEncoding(HttpServletRequest theReq) { private EncodingEnum getRequestEncoding(HttpServletRequest theReq) {
EncodingEnum encoding; EncodingEnum encoding;
if ("xml".equals(theReq.getParameter("encoding"))) { if ("xml".equals(theReq.getParameter("encoding"))) {
@ -638,7 +753,6 @@ public class RestfulTesterServlet extends HttpServlet {
} }
} }
ctx.setVariable("resourceCounts", resourceCounts); ctx.setVariable("resourceCounts", resourceCounts);
ctx.setVariable("conf", conformance); ctx.setVariable("conf", conformance);
ctx.setVariable("base", myServerBase); ctx.setVariable("base", myServerBase);

View File

@ -907,7 +907,7 @@
<td>Request Body</td> <td>Request Body</td>
<td valign="top" style="margin: 0px; padding: 0px;"> <td valign="top" style="margin: 0px; padding: 0px;">
<pre class="requestBodyPre resultBodyPlaceholder" id="requestBodyPlaceholder">...loading...</pre> <pre class="requestBodyPre resultBodyPlaceholder" id="requestBodyPlaceholder">...loading...</pre>
<pre th:text="${requestBody}" th:class="${requestSyntaxHighlighterClass} + ' resultBodyPre pre'" id="requestBodyActual" style="display: none;">{}</pre> <pre th:utext="${requestBody}" th:class="${requestSyntaxHighlighterClass} + ' resultBodyPre pre'" id="requestBodyActual" style="display: none;">{}</pre>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -953,7 +953,7 @@
<h4 class="panel-title"> <h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"> <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
<i id="collapseOneIcon" class="fa fa-minus-square-o"></i> <i id="collapseOneIcon" class="fa fa-minus-square-o"></i>
<span th:text="'Bundle contains ' + ${bundle.entries.size} + ' entries'"/> <span th:text="'Bundle contains ' + ${bundle.totalResults.value} + ' entries'"/>
</a> </a>
<!-- Prev/Next Page Buttons --> <!-- Prev/Next Page Buttons -->
@ -968,7 +968,7 @@
$('#page-prev-btn').click(function() { $('#page-prev-btn').click(function() {
var btn = $(this); var btn = $(this);
btn.button('loading'); btn.button('loading');
btn.append($('<input />', { type: 'hidden', name: 'pageUrl', value: '<th:block th:text="${bundle.linkPrevious}"/>' })); btn.append($('<input />', { type: 'hidden', name: 'page-url', value: '<th:block th:text="${bundle.linkPrevious}"/>' }));
}); });
</script> </script>
@ -983,7 +983,7 @@
$('#page-next-btn').click(function() { $('#page-next-btn').click(function() {
var btn = $(this); var btn = $(this);
btn.button('loading'); btn.button('loading');
btn.append($('<input />', { type: 'hidden', name: 'pageUrl', value: '<th:block th:text="${bundle.linkNext}"/>' })); btn.append($('<input />', { type: 'hidden', name: 'page-url', value: '<th:block th:text="${bundle.linkNext}"/>' }));
}); });
</script> </script>
@ -992,6 +992,14 @@
<div id="collapseOne" class="panel-collapse collapse in"> <div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body" style="padding-bottom: 0px;"> <div class="panel-body" style="padding-bottom: 0px;">
<table class="table table-condensed" style="padding-bottom: 0px; margin-bottom: 0px;"> <table class="table table-condensed" style="padding-bottom: 0px; margin-bottom: 0px;">
<thead>
<tr>
<th></th>
<th>Title</th>
<th>Updated</th>
</tr>
</thead>
<tbody>
<tr th:each="entry : ${bundle.entries}"> <tr th:each="entry : ${bundle.entries}">
<td> <td>
<button class="btn btn-primary btn-xs" th:onclick="'readFromEntriesTable(this, \'' + ${entry.resource.id.resourceType} + '\', \'' + ${entry.resource.id.idPart} + '\', \'' + ${entry.resource.id.versionIdPart} + '\');'" type="submit" name="action" value="read">Read</button> <button class="btn btn-primary btn-xs" th:onclick="'readFromEntriesTable(this, \'' + ${entry.resource.id.resourceType} + '\', \'' + ${entry.resource.id.idPart} + '\', \'' + ${entry.resource.id.versionIdPart} + '\');'" type="submit" name="action" value="read">Read</button>
@ -999,7 +1007,11 @@
</td> </td>
<td th:text="${entry.title}"> <td th:text="${entry.title}">
</td> </td>
<td th:if="${entry.updated.value} == null"></td>
<td th:if="${entry.updated.value} != null and ${entry.updated.today} == true" th:text="${#dates.format(entry.updated.value, 'HH:mm:ss')}"></td>
<td th:if="${entry.updated.value} != null and ${entry.updated.today} == false" th:text="${#dates.format(entry.updated.value, 'yyyy-MM-dd')}"></td>
</tr> </tr>
</tbody>
</table> </table>
<script type="text/javascript"> <script type="text/javascript">
function readFromEntriesTable(source, type, id, vid) { function readFromEntriesTable(source, type, id, vid) {
@ -1060,7 +1072,7 @@
<td valign="top" style="margin: 0px; padding: 0px; font-weight: normal;"> <td valign="top" style="margin: 0px; padding: 0px; font-weight: normal;">
<pre class="resultBodyPre resultBodyPlaceholder" id="resultBodyPlaceholder">...loading...</pre> <pre class="resultBodyPre resultBodyPlaceholder" id="resultBodyPlaceholder">...loading...</pre>
<div id="resultBodyActual" class="resultBodyActual" style="display: none;"> <div id="resultBodyActual" class="resultBodyActual" style="display: none;">
<pre id="resultBodyActualPre" th:text="${resultBody}" th:class="(${resultBodyIsLong} ? '' : ${resultSyntaxHighlighterClass}) + ' resultBodyPre pre'">{}</pre> <pre id="resultBodyActualPre" th:utext="${resultBody}" th:class="(${resultBodyIsLong} ? '' : ${resultSyntaxHighlighterClass}) + ' resultBodyPre pre'">{}</pre>
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -32,6 +32,22 @@ SPAN.headerName {
font-size: 0.8em; font-size: 0.8em;
} }
.hlQuot {
color: #88F;
}
.hlAttr {
color: #888;
}
.hlTagName {
color: #006699;
}
.hlControl {
color: #660000;
}
.hlText {
color: #000000;
}
SPAN.headerValue { SPAN.headerValue {
color: #70A070; color: #70A070;
font-family: monospace; font-family: monospace;