use of org.craftercms.core.exception.CrafterException in project engine by craftercms.
the class SiteItemScriptResolverImpl method getScriptUrls.
@Override
public List<String> getScriptUrls(SiteItem item) {
List<String> scriptUrls = null;
SiteContext siteContext = SiteContext.getCurrent();
if (siteContext != null) {
String contentType = item.getItem().queryDescriptorValue(contentTypeXPathQuery);
if (StringUtils.isNotEmpty(contentType)) {
String scriptUrl = getScriptUrlForContentType(contentType);
if (StringUtils.isNotEmpty(scriptUrl)) {
try {
// Check that the script exists. If not, ignore.
if (storeService.exists(siteContext.getContext(), scriptUrl)) {
if (logger.isDebugEnabled()) {
logger.debug("Script for content type '" + contentType + "' found at " + scriptUrl);
}
scriptUrls = new ArrayList<>();
scriptUrls.add(scriptUrl);
}
if (logger.isDebugEnabled()) {
logger.debug("No script for content type '" + contentType + "' found at " + scriptUrl);
}
} catch (CrafterException e) {
logger.error("Error retrieving script for content type '" + contentType + "' at " + scriptUrl, e);
}
}
}
if (CollectionUtils.isNotEmpty(scriptUrls)) {
List<String> additionalUrls = item.getItem().queryDescriptorValues(scriptsXPathQuery);
if (scriptUrls == null) {
scriptUrls = new ArrayList<>();
}
if (CollectionUtils.isNotEmpty(additionalUrls)) {
scriptUrls.addAll(additionalUrls);
}
} else {
scriptUrls = item.getItem().queryDescriptorValues(scriptsXPathQuery);
}
}
return scriptUrls;
}
use of org.craftercms.core.exception.CrafterException in project engine by craftercms.
the class PageRenderController method getControllerScript.
protected Script getControllerScript(SiteContext siteContext, HttpServletRequest request, String pageUrl) {
ScriptFactory scriptFactory = siteContext.getScriptFactory();
if (scriptFactory == null) {
throw new IllegalStateException("No script factory associated to current site context '" + siteContext.getSiteName() + "'");
}
String scriptUrl = getScriptUrl(siteContext, scriptFactory, request, pageUrl);
try {
// Check controller script exists
if (storeService.exists(siteContext.getContext(), scriptUrl)) {
if (logger.isDebugEnabled()) {
logger.debug("Controller script found for page " + pageUrl + " at " + scriptUrl);
}
return scriptFactory.getScript(scriptUrl);
} else if (logger.isDebugEnabled()) {
logger.debug("No controller script for page " + pageUrl + " at " + scriptUrl);
}
} catch (CrafterException e) {
logger.error("Error while trying to retrieve controller script at " + scriptUrl, e);
}
return null;
}
use of org.craftercms.core.exception.CrafterException in project engine by craftercms.
the class SiteItemScriptResolverImplTest method createContentStoreService.
private ContentStoreService createContentStoreService() {
ContentStoreService storeService = mock(ContentStoreService.class);
when(storeService.exists(any(Context.class), eq("/scripts/pages/mypage1.groovy"))).thenReturn(true);
when(storeService.exists(any(Context.class), eq("/scripts/pages/mypage2.groovy"))).thenReturn(false);
when(storeService.exists(any(Context.class), eq("/scripts/pages/mypage3.groovy"))).thenThrow(new CrafterException());
return storeService;
}
use of org.craftercms.core.exception.CrafterException in project engine by craftercms.
the class SiteContextResolvingFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
SiteContext siteContext = contextResolver.getContext((HttpServletRequest) request);
if (siteContext == null) {
throw new CrafterException("No site context was resolved for the current request");
}
SiteContext.setCurrent(siteContext);
try {
chain.doFilter(request, response);
} finally {
SiteContext.clear();
}
}
use of org.craftercms.core.exception.CrafterException in project engine by craftercms.
the class ReloadableMappingsSiteResolver method loadMappings.
protected void loadMappings() throws CrafterException {
Properties tmpMappings = new Properties();
try {
tmpMappings.load(mappingsFile.getInputStream());
} catch (IOException e) {
throw new CrafterException("Unable to load domain name to site name mappings from " + mappingsFile, e);
}
Properties newMappings = new Properties();
for (Map.Entry<Object, Object> entry : tmpMappings.entrySet()) {
String trimmedKey = entry.getKey().toString().trim();
String trimmedVal = entry.getValue().toString().trim();
newMappings.setProperty(trimmedKey, trimmedVal);
}
logger.info("Domain name to site name mappings loaded from " + mappingsFile);
mappings = newMappings;
}
Aggregations