-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
30 changed files
with
2,310 additions
and
329 deletions.
There are no files selected for viewing
147 changes: 137 additions & 10 deletions
147
modules/lib/lib-portal/src/main/java/com/enonic/xp/lib/portal/url/AttachmentUrlHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,154 @@ | ||
package com.enonic.xp.lib.portal.url; | ||
|
||
import java.util.Set; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
import com.enonic.xp.portal.PortalRequest; | ||
import com.enonic.xp.portal.url.AttachmentUrlParams; | ||
import com.enonic.xp.portal.url.PortalUrlService; | ||
import com.enonic.xp.script.ScriptValue; | ||
import com.enonic.xp.script.bean.BeanContext; | ||
import com.enonic.xp.script.bean.ScriptBean; | ||
|
||
public final class AttachmentUrlHandler | ||
extends AbstractUrlHandler | ||
implements ScriptBean | ||
{ | ||
private static final Set<String> VALID_URL_PROPERTY_KEYS = | ||
Set.of( "id", "path", "name", "type", "download", "label", "params" ); | ||
private PortalRequest request; | ||
|
||
private PortalUrlService urlService; | ||
|
||
private String id; | ||
|
||
private String path; | ||
|
||
private String urlType; | ||
|
||
private String name; | ||
|
||
private String label; | ||
|
||
private String projectName; | ||
|
||
private String branch; | ||
|
||
private String baseUrlKey; | ||
|
||
private boolean offline; | ||
|
||
private boolean download; | ||
|
||
private Multimap<String, String> queryParams; | ||
|
||
@Override | ||
protected String buildUrl( final Multimap<String, String> map ) | ||
public void initialize( final BeanContext context ) | ||
{ | ||
final AttachmentUrlParams params = new AttachmentUrlParams().portalRequest( this.request ).setAsMap( map ); | ||
return this.urlService.attachmentUrl( params ); | ||
this.request = context.getBinding( PortalRequest.class ).get(); | ||
this.urlService = context.getService( PortalUrlService.class ).get(); | ||
} | ||
|
||
@Override | ||
protected boolean isValidParam( final String param ) | ||
public void setId( final String id ) | ||
{ | ||
return VALID_URL_PROPERTY_KEYS.contains( param ); | ||
this.id = id; | ||
} | ||
|
||
public void setPath( final String path ) | ||
{ | ||
this.path = path; | ||
} | ||
|
||
public void setUrlType( final String urlType ) | ||
{ | ||
this.urlType = urlType; | ||
} | ||
|
||
public void setName( final String name ) | ||
{ | ||
this.name = name; | ||
} | ||
|
||
public void setLabel( final String label ) | ||
{ | ||
this.label = label; | ||
} | ||
|
||
public void setOffline( final boolean offline ) | ||
{ | ||
this.offline = offline; | ||
} | ||
|
||
public void setProjectName( final String projectName ) | ||
{ | ||
this.projectName = projectName; | ||
} | ||
|
||
public void setBranch( final String branch ) | ||
{ | ||
this.branch = branch; | ||
} | ||
|
||
public void setBaseUrlKey( final String baseUrlKey ) | ||
{ | ||
this.baseUrlKey = baseUrlKey; | ||
} | ||
|
||
public void setOffline( final Boolean offline ) | ||
{ | ||
this.offline = Objects.requireNonNullElse( offline, false ); | ||
} | ||
|
||
public void setDownload( final Boolean download ) | ||
{ | ||
this.download = Objects.requireNonNullElse( download, false ); | ||
} | ||
|
||
public void setQueryParams( final ScriptValue params ) | ||
{ | ||
if ( params == null ) | ||
{ | ||
return; | ||
} | ||
|
||
this.queryParams = HashMultimap.create(); | ||
|
||
for ( final Map.Entry<String, Object> param : params.getMap().entrySet() ) | ||
{ | ||
final Object value = param.getValue(); | ||
if ( value instanceof Iterable values ) | ||
{ | ||
for ( final Object v : values ) | ||
{ | ||
queryParams.put( param.getKey(), v.toString() ); | ||
} | ||
} | ||
else | ||
{ | ||
queryParams.put( param.getKey(), value.toString() ); | ||
} | ||
} | ||
} | ||
|
||
public String createUrl() | ||
{ | ||
final AttachmentUrlParams params = new AttachmentUrlParams().portalRequest( this.request ) | ||
.id( this.id ) | ||
.path( this.path ) | ||
.type( this.urlType ) | ||
.name( this.name ) | ||
.label( this.label ) | ||
.download( this.download ) | ||
.projectName( this.projectName ) | ||
.branch( this.branch ) | ||
.baseUrlKey( this.baseUrlKey ) | ||
.offline( this.offline ); | ||
|
||
if ( this.queryParams != null ) | ||
{ | ||
this.queryParams.forEach( params::param ); | ||
} | ||
|
||
return urlService.attachmentUrl( params ); | ||
} | ||
} |
160 changes: 148 additions & 12 deletions
160
modules/lib/lib-portal/src/main/java/com/enonic/xp/lib/portal/url/ImageUrlHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,166 @@ | ||
package com.enonic.xp.lib.portal.url; | ||
|
||
import java.util.Set; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
import com.enonic.xp.portal.PortalRequest; | ||
import com.enonic.xp.portal.url.ImageUrlParams; | ||
import com.enonic.xp.portal.url.PortalUrlService; | ||
import com.enonic.xp.script.ScriptValue; | ||
import com.enonic.xp.script.bean.BeanContext; | ||
import com.enonic.xp.script.bean.ScriptBean; | ||
|
||
public final class ImageUrlHandler | ||
extends AbstractUrlHandler | ||
implements ScriptBean | ||
{ | ||
private static final Set<String> VALID_URL_PROPERTY_KEYS = Set.of( "id", "path", "scale", "quality", "background", "format", "filter", "contextPath", "type", "params" ); | ||
private PortalRequest request; | ||
|
||
private PortalUrlService urlService; | ||
|
||
private String id; | ||
|
||
private String path; | ||
|
||
private String urlType; | ||
|
||
private String background; | ||
|
||
private Integer quality; | ||
|
||
private String filter; | ||
|
||
private String format; | ||
|
||
private String scale; | ||
|
||
private String projectName; | ||
|
||
private String branch; | ||
|
||
private String baseUrlKey; | ||
|
||
private boolean offline; | ||
|
||
private Multimap<String, String> queryParams; | ||
|
||
@Override | ||
protected String buildUrl( final Multimap<String, String> map ) | ||
public void initialize( final BeanContext context ) | ||
{ | ||
this.request = context.getBinding( PortalRequest.class ).get(); | ||
this.urlService = context.getService( PortalUrlService.class ).get(); | ||
} | ||
|
||
public void setId( final String id ) | ||
{ | ||
final ImageUrlParams params = new ImageUrlParams(). | ||
setAsMap( map ). | ||
portalRequest( request ). | ||
validate(); | ||
this.id = id; | ||
} | ||
|
||
return this.urlService.imageUrl( params ); | ||
public void setPath( final String path ) | ||
{ | ||
this.path = path; | ||
} | ||
|
||
@Override | ||
protected boolean isValidParam( final String param ) | ||
public void setUrlType( final String urlType ) | ||
{ | ||
this.urlType = urlType; | ||
} | ||
|
||
public void setBackground( final String background ) | ||
{ | ||
this.background = background; | ||
} | ||
|
||
public void setQuality( final Integer quality ) | ||
{ | ||
this.quality = quality; | ||
} | ||
|
||
public void setFilter( final String filter ) | ||
{ | ||
return VALID_URL_PROPERTY_KEYS.contains( param ); | ||
this.filter = filter; | ||
} | ||
|
||
public void setFormat( final String format ) | ||
{ | ||
this.format = format; | ||
} | ||
|
||
public void setScale( final String scale ) | ||
{ | ||
this.scale = scale; | ||
} | ||
|
||
public void setProjectName( final String projectName ) | ||
{ | ||
this.projectName = projectName; | ||
} | ||
|
||
public void setBranch( final String branch ) | ||
{ | ||
this.branch = branch; | ||
} | ||
|
||
public void setBaseUrlKey( final String baseUrlKey ) | ||
{ | ||
this.baseUrlKey = baseUrlKey; | ||
} | ||
|
||
public void setOffline( final Boolean offline ) | ||
{ | ||
this.offline = Objects.requireNonNullElse( offline, false ); | ||
} | ||
|
||
public void setQueryParams( final ScriptValue params ) | ||
{ | ||
if ( params == null ) | ||
{ | ||
return; | ||
} | ||
|
||
this.queryParams = HashMultimap.create(); | ||
|
||
for ( final Map.Entry<String, Object> param : params.getMap().entrySet() ) | ||
{ | ||
final Object value = param.getValue(); | ||
if ( value instanceof Iterable values ) | ||
{ | ||
for ( final Object v : values ) | ||
{ | ||
queryParams.put( param.getKey(), v.toString() ); | ||
} | ||
} | ||
else | ||
{ | ||
queryParams.put( param.getKey(), value.toString() ); | ||
} | ||
} | ||
} | ||
|
||
public String createUrl() | ||
{ | ||
final ImageUrlParams params = new ImageUrlParams().portalRequest( this.request ) | ||
.id( this.id ) | ||
.path( this.path ) | ||
.type( this.urlType ) | ||
.background( this.background ) | ||
.quality( this.quality ) | ||
.filter( this.filter ) | ||
.format( this.format ) | ||
.scale( this.scale ) | ||
.projectName( this.projectName ) | ||
.branch( this.branch ) | ||
.baseUrlKey( this.baseUrlKey ) | ||
.offline( this.offline ); | ||
|
||
if ( this.queryParams != null ) | ||
{ | ||
this.queryParams.forEach( params::param ); | ||
} | ||
|
||
return this.urlService.imageUrl( params ); | ||
} | ||
|
||
} |
Oops, something went wrong.