use of com.enonic.xp.portal.url.PageUrlParams in project xp by enonic.
the class PortalUrlServiceImpl_pageUrlTest method createUrl_toMe.
@Test
public void createUrl_toMe() {
final PageUrlParams params = new PageUrlParams().portalRequest(this.portalRequest).param("a", 3);
final String url = this.service.pageUrl(params);
assertEquals("/site/default/draft/context/path?a=3", url);
}
use of com.enonic.xp.portal.url.PageUrlParams in project xp by enonic.
the class PortalUrlServiceImpl_pageUrlTest method createUrl_withRelativePath.
@Test
public void createUrl_withRelativePath() {
final PageUrlParams params = new PageUrlParams().portalRequest(this.portalRequest).path("a/b").param("a", 3);
final String url = this.service.pageUrl(params);
assertEquals("/site/default/draft/context/path/a/b?a=3", url);
}
use of com.enonic.xp.portal.url.PageUrlParams in project xp by enonic.
the class PortalUrlServiceImpl_pageUrlTest method createUrl_absolute.
@Test
public void createUrl_absolute() {
final PageUrlParams params = new PageUrlParams().type(UrlTypeConstants.ABSOLUTE).portalRequest(this.portalRequest).param("a", 3);
when(req.getServerName()).thenReturn("localhost");
when(req.getScheme()).thenReturn("http");
when(req.getServerPort()).thenReturn(80);
final String url = this.service.pageUrl(params);
assertEquals("http://localhost/site/default/draft/context/path?a=3", url);
}
use of com.enonic.xp.portal.url.PageUrlParams in project xp by enonic.
the class PageHandlerWorker method renderShortcut.
private PortalResponse renderShortcut(final Content content) {
final Property shortcut = content.getData().getProperty(SHORTCUT_TARGET_PROPERTY);
final Reference target = shortcut == null ? null : shortcut.getReference();
if (target == null || target.getNodeId() == null) {
throw WebException.notFound("Missing shortcut target");
}
final PageUrlParams pageUrlParams = new PageUrlParams().id(target.toString()).portalRequest(this.request);
final Multimap<String, String> params = pageUrlParams.getParams();
params.putAll(this.request.getParams());
params.putAll(getShortcutParameters(content));
final String targetUrl = this.portalUrlService.pageUrl(pageUrlParams);
return PortalResponse.create().status(HttpStatus.TEMPORARY_REDIRECT).header("Location", targetUrl).build();
}
use of com.enonic.xp.portal.url.PageUrlParams in project xp by enonic.
the class HtmlLinkProcessor method process.
public String process(final String text, final String urlType, final PortalRequest portalRequest, final List<Integer> imageWidths, final String imageSizes) {
String processedHtml = text;
final ImmutableMap<String, ImageStyle> imageStyleMap = getImageStyleMap(portalRequest);
final Matcher contentMatcher = CONTENT_PATTERN.matcher(text);
while (contentMatcher.find()) {
if (contentMatcher.groupCount() >= NB_GROUPS) {
final String tagName = contentMatcher.group(TAG_NAME_INDEX);
final String attr = contentMatcher.group(ATTR_INDEX);
final String attrValue = contentMatcher.group(ATTR_VALUE_INDEX);
final String link = contentMatcher.group(LINK_INDEX);
final String type = contentMatcher.group(TYPE_INDEX);
final String mode = contentMatcher.group(MODE_INDEX);
final String id = contentMatcher.group(ID_INDEX);
final String urlParamsString = contentMatcher.groupCount() == PARAMS_INDEX ? contentMatcher.group(PARAMS_INDEX) : null;
switch(type) {
case CONTENT_TYPE:
PageUrlParams pageUrlParams = new PageUrlParams().type(urlType).id(id).portalRequest(portalRequest);
final String pageUrl = portalUrlService.pageUrl(pageUrlParams);
processedHtml = processedHtml.replaceFirst(Pattern.quote(attrValue), "\"" + pageUrl + "\"");
break;
case IMAGE_TYPE:
final Map<String, String> urlParams = extractUrlParams(urlParamsString);
ImageStyle imageStyle = getImageStyle(imageStyleMap, urlParams);
ImageUrlParams imageUrlParams = new ImageUrlParams().type(urlType).id(id).scale(getScale(imageStyle, urlParams, null)).filter(getFilter(imageStyle)).portalRequest(portalRequest);
final String imageUrl = portalUrlService.imageUrl(imageUrlParams);
final StringBuilder replacement = new StringBuilder("\"" + imageUrl + "\"");
if ("img".equals(tagName) && "src".equals(attr)) {
final String srcsetValues = Objects.requireNonNullElse(imageWidths, List.<Integer>of()).stream().map(imageWidth -> {
final ImageUrlParams imageParams = new ImageUrlParams().type(urlType).id(id).scale(getScale(imageStyle, urlParams, imageWidth)).filter(getFilter(imageStyle)).portalRequest(portalRequest);
return portalUrlService.imageUrl(imageParams) + " " + imageWidth + "w";
}).collect(Collectors.joining(","));
if (!srcsetValues.isEmpty()) {
replacement.append(" srcset=\"").append(srcsetValues).append("\"");
}
if (imageSizes != null && !imageSizes.isBlank()) {
replacement.append(" sizes=\"").append(imageSizes).append("\"");
}
}
processedHtml = processedHtml.replaceFirst(Pattern.quote(attrValue), replacement.toString());
break;
default:
AttachmentUrlParams attachmentUrlParams = new AttachmentUrlParams().type(urlType).id(id).download(DOWNLOAD_MODE.equals(mode)).portalRequest(portalRequest);
final String attachmentUrl = portalUrlService.attachmentUrl(attachmentUrlParams);
processedHtml = processedHtml.replaceFirst(Pattern.quote(attrValue), "\"" + attachmentUrl + "\"");
break;
}
}
}
return processedHtml;
}
Aggregations