use of org.craftercms.core.exception.UrlTransformationException in project core by craftercms.
the class ContentBundleShortToLongUrlTransformer method getLongUrlLookingInBundle.
private String getLongUrlLookingInBundle(Context context, CachingOptions cachingOptions, String shortUrl) throws UrlTransformationException {
ContentBundleUrl parsedUrl = urlParser.getContentBundleUrl(shortUrl);
String prefix = parsedUrl.getPrefix();
String originalBase = parsedUrl.getBaseNameAndExtensionToken();
String suffix = parsedUrl.getSuffix();
if (originalBase == null) {
originalBase = "";
}
if (suffix == null) {
suffix = "";
}
String base = originalBase;
int delimiterIdx;
do {
String currentShortUrl = prefix + base + suffix;
String longUrl = getLongUrl(context, cachingOptions, currentShortUrl, false);
if (StringUtils.isNotEmpty(longUrl)) {
if (!originalBase.equals(base)) {
// Put original base back in long URL.
longUrl = longUrl.replace(base, originalBase);
}
return longUrl;
}
delimiterIdx = base.lastIndexOf(baseDelimiter);
if (delimiterIdx > 0) {
base = base.substring(0, delimiterIdx);
}
} while (delimiterIdx >= 0);
// come here if URL is not found in content store
throw new UrlTransformationException("Unable to map the short url '" + shortUrl + "' to a long url");
}
use of org.craftercms.core.exception.UrlTransformationException in project core by craftercms.
the class UrlTransformationEngineImpl method doTransformUrl.
@Override
protected String doTransformUrl(Context context, CachingOptions cachingOptions, String transformerName, String url) throws UrlTransformationException {
UrlTransformer transformer = transformers.get(transformerName);
if (transformer == null) {
throw new UrlTransformationException("Url transformer " + transformerName + " not found");
}
String result = transformer.transformUrl(context, cachingOptions, url);
if (StringUtils.isEmpty(result)) {
result = "/";
}
if (logger.isDebugEnabled()) {
logger.debug("Transformation in: " + url + ", Transformation out: " + result);
}
return result;
}
Aggregations