NIHVIVO-2411 Create a TemplateUtils class to slightly simplify the browse templates.
This commit is contained in:
parent
af3ca17ef1
commit
b688d6f1c6
2 changed files with 54 additions and 5 deletions
|
@ -0,0 +1,53 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.web;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import freemarker.template.TemplateCollectionModel;
|
||||||
|
import freemarker.template.TemplateMethodModelEx;
|
||||||
|
import freemarker.template.TemplateModel;
|
||||||
|
import freemarker.template.TemplateModelException;
|
||||||
|
import freemarker.template.TemplateScalarModel;
|
||||||
|
import freemarker.template.TemplateSequenceModel;
|
||||||
|
import freemarker.template.utility.DeepUnwrap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
public class TemplateUtils {
|
||||||
|
private static final Log log = LogFactory.getLog(TemplateUtils.class);
|
||||||
|
|
||||||
|
public static class DropFromSequence implements TemplateMethodModelEx {
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
@Override
|
||||||
|
public Object exec(List args) throws TemplateModelException {
|
||||||
|
if (args.size() != 2) {
|
||||||
|
throw new TemplateModelException("Wrong number of arguments");
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateModel sequenceWrapper = (TemplateModel) args.get(0);
|
||||||
|
if (!(sequenceWrapper instanceof TemplateSequenceModel)
|
||||||
|
&& !(sequenceWrapper instanceof TemplateCollectionModel)) {
|
||||||
|
throw new TemplateModelException(
|
||||||
|
"First argument must be a sequence or a collection");
|
||||||
|
}
|
||||||
|
TemplateModel unwantedWrapper = (TemplateModel) args.get(1);
|
||||||
|
if (!(unwantedWrapper instanceof TemplateScalarModel)) {
|
||||||
|
throw new TemplateModelException(
|
||||||
|
"Second argument must be a string");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> sequence = (List<String>) DeepUnwrap
|
||||||
|
.unwrap(sequenceWrapper);
|
||||||
|
String unwanted = (String) DeepUnwrap.unwrap(unwantedWrapper);
|
||||||
|
|
||||||
|
sequence.remove(unwanted);
|
||||||
|
return sequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,11 +17,7 @@
|
||||||
</h1>
|
</h1>
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
<#assign typesString>
|
<#assign cleanTypes = 'edu.cornell.mannlib.vitro.webapp.web.TemplateUtils$DropFromSequence'?new()(individual.mostSpecificTypes, vclass) />
|
||||||
[<#list individual.mostSpecificTypes as type><#if type != vclass>,"${type}"</#if></#list>]
|
|
||||||
</#assign>
|
|
||||||
<#assign cleanTypes = typesString?replace("[,", "[")?eval >
|
|
||||||
|
|
||||||
<#if cleanTypes?size == 1>
|
<#if cleanTypes?size == 1>
|
||||||
<span class="title">${cleanTypes[0]}</span>
|
<span class="title">${cleanTypes[0]}</span>
|
||||||
<#elseif (cleanTypes?size > 1) >
|
<#elseif (cleanTypes?size > 1) >
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue