use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class SiteLinkDirective method getValue.
@Override
protected String getValue(Environment env, Map params) throws TemplateModelException, IOException {
String path = getStringValue(params.get("path"));
String targetJournal = getStringValue(params.get("journalKey"));
String handlerName = getStringValue(params.get("handlerName"));
boolean absoluteLink = TemplateModelUtil.getBooleanValue((TemplateModel) params.get("absoluteLink"));
SitePageContext sitePageContext = new SitePageContext(siteResolver, env);
Site site = sitePageContext.getSite();
Link.Factory linkFactory = (targetJournal == null) ? (absoluteLink ? Link.toAbsoluteAddress(site) : Link.toLocalSite(site)) : Link.toForeignSite(site, targetJournal, siteSet);
final Link link;
if (handlerName != null) {
Map<String, ?> variables = TemplateModelUtil.getAsMap((TemplateModel) params.get("pathVariables"));
ListMultimap<String, ?> queryParameters = TemplateModelUtil.getAsMultimap((TemplateModel) params.get("queryParameters"));
List<?> wildcardValues = TemplateModelUtil.getAsList((TemplateModel) params.get("wildcardValues"));
link = linkFactory.toPattern(requestMappingContextDictionary, handlerName, variables, queryParameters, wildcardValues);
} else if (path != null) {
link = linkFactory.toPath(path);
} else {
throw new RuntimeException("Either a path or handlerName parameter is required");
}
return link.get(sitePageContext.getRequest());
}
use of org.ambraproject.wombat.config.site.Site in project wombat by PLOS.
the class AppRootPage method buildMappingTable.
private ImmutableList<MappingTableRow> buildMappingTable() {
Table<RequestMappingContext, Site, String> table = HashBasedTable.create();
Set<RequestMappingContext> sitelessMappings = new HashSet<>();
ImmutableList<Site> allSites = siteSet.getSites().asList();
for (RequestMappingContextDictionary.MappingEntry entry : requestMappingContextDictionary.getAll()) {
RequestMappingContext mapping = entry.getMapping();
Optional<Site> site = entry.getSite();
String handlerName = entry.getHandlerName();
if (site.isPresent()) {
table.put(mapping, site.get(), handlerName);
} else {
sitelessMappings.add(mapping);
for (Site s : allSites) {
table.put(mapping, s, handlerName);
}
}
}
Set<RequestMappingContext> mappings = table.rowKeySet();
List<MappingTableRow> rows = new ArrayList<>(mappings.size());
for (final RequestMappingContext mapping : mappings) {
final List<String> row = new ArrayList<>(allSites.size());
for (Site site : allSites) {
String cell = table.get(mapping, site);
row.add(Strings.nullToEmpty(cell));
}
final String mappingRepresentation = represent(mapping);
final boolean isGlobal = sitelessMappings.contains(mapping);
rows.add(new MappingTableRow() {
@Override
public String getPattern() {
return mappingRepresentation;
}
@Override
public List<String> getRow() {
return row;
}
@Override
public boolean isGlobal() {
return isGlobal;
}
});
}
return ROW_ORDERING.immutableSortedCopy(rows);
}
Aggregations