-
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.
- Loading branch information
1 parent
6afa583
commit a64d0ef
Showing
17 changed files
with
1,432 additions
and
12 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
.../lib/lib-portal/src/main/java/com/enonic/xp/lib/portal/url/AttachmentMediaUrlHandler.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 |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.enonic.xp.lib.portal.url; | ||
|
||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
import com.enonic.xp.portal.PortalRequest; | ||
import com.enonic.xp.portal.url.AttachmentMediaUrlParams; | ||
import com.enonic.xp.portal.url.ContextPathType; | ||
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 class AttachmentMediaUrlHandler | ||
implements ScriptBean | ||
{ | ||
protected Supplier<PortalRequest> requestSupplier; | ||
|
||
protected Supplier<PortalUrlService> urlServiceSupplier; | ||
|
||
private String contentId; | ||
|
||
private String contentPath; | ||
|
||
private String urlType; | ||
|
||
private ContextPathType contextPathType; | ||
|
||
private Multimap<String, String> queryParams; | ||
|
||
private String projectName; | ||
|
||
private String branch; | ||
|
||
private String name; | ||
|
||
private String label; | ||
|
||
private Boolean download; | ||
|
||
@Override | ||
public void initialize( final BeanContext context ) | ||
{ | ||
this.requestSupplier = context.getBinding( PortalRequest.class ); | ||
this.urlServiceSupplier = context.getService( PortalUrlService.class ); | ||
} | ||
|
||
public void setId( final String contentId ) | ||
{ | ||
this.contentId = contentId; | ||
} | ||
|
||
public void setPath( final String contentPath ) | ||
{ | ||
this.contentPath = contentPath; | ||
} | ||
|
||
public void setUrlType( final String urlType ) | ||
{ | ||
this.urlType = urlType; | ||
} | ||
|
||
public void setContextPathType( final ContextPathType contextPathType ) | ||
{ | ||
this.contextPathType = contextPathType; | ||
} | ||
|
||
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 void setProjectName( final String projectName ) | ||
{ | ||
this.projectName = projectName; | ||
} | ||
|
||
public void setBranch( final String branch ) | ||
{ | ||
this.branch = branch; | ||
} | ||
|
||
public void setName( final String name ) | ||
{ | ||
this.name = name; | ||
} | ||
|
||
public void setLabel( final String label ) | ||
{ | ||
this.label = label; | ||
} | ||
|
||
public void setDownload( final Boolean download ) | ||
{ | ||
this.download = download; | ||
} | ||
|
||
public String createUrl() | ||
{ | ||
final AttachmentMediaUrlParams params = AttachmentMediaUrlParams.create() | ||
.contentId( this.contentId ) | ||
.contentPath( this.contentPath ) | ||
.urlType( this.urlType ) | ||
.contextPathType( this.contextPathType ) | ||
.addQueryParams( this.queryParams ) | ||
.projectName( this.projectName ) | ||
.branch( this.branch ) | ||
.name( this.name ) | ||
.label( this.label ) | ||
.download( this.download ) | ||
.webRequest( this.requestSupplier.get() ) | ||
.build(); | ||
|
||
return this.urlServiceSupplier.get().attachmentMediaUrl( params ); | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
modules/lib/lib-portal/src/main/java/com/enonic/xp/lib/portal/url/ImageMediaUrlHandler.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 |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package com.enonic.xp.lib.portal.url; | ||
|
||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
import com.enonic.xp.portal.PortalRequest; | ||
import com.enonic.xp.portal.url.ContextPathType; | ||
import com.enonic.xp.portal.url.ImageMediaUrlParams; | ||
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 class ImageMediaUrlHandler | ||
implements ScriptBean | ||
{ | ||
protected Supplier<PortalRequest> requestSupplier; | ||
|
||
protected Supplier<PortalUrlService> urlServiceSupplier; | ||
|
||
private String contentId; | ||
|
||
private String contentPath; | ||
|
||
private String urlType; | ||
|
||
private ContextPathType contextPathType; | ||
|
||
private Multimap<String, String> queryParams; | ||
|
||
private String projectName; | ||
|
||
private String branch; | ||
|
||
private String background; | ||
|
||
private Integer quality; | ||
|
||
private String filter; | ||
|
||
private String format; | ||
|
||
private String scale; | ||
|
||
@Override | ||
public void initialize( final BeanContext context ) | ||
{ | ||
this.requestSupplier = context.getBinding( PortalRequest.class ); | ||
this.urlServiceSupplier = context.getService( PortalUrlService.class ); | ||
} | ||
|
||
public void setId( final String contentId ) | ||
{ | ||
this.contentId = contentId; | ||
} | ||
|
||
public void setPath( final String contentPath ) | ||
{ | ||
this.contentPath = contentPath; | ||
} | ||
|
||
public void setUrlType( final String urlType ) | ||
{ | ||
this.urlType = urlType; | ||
} | ||
|
||
public void setContextPathType( final String contextPathType ) | ||
{ | ||
this.contextPathType = ContextPathType.from( contextPathType ); | ||
} | ||
|
||
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 void setProjectName( final String projectName ) | ||
{ | ||
this.projectName = projectName; | ||
} | ||
|
||
public void setBranch( final String branch ) | ||
{ | ||
this.branch = branch; | ||
} | ||
|
||
public void setBackground( final String background ) | ||
{ | ||
this.background = background; | ||
} | ||
|
||
public void setQuality( final Integer quality ) | ||
{ | ||
this.quality = quality; | ||
} | ||
|
||
public void setFilter( final String filter ) | ||
{ | ||
this.filter = filter; | ||
} | ||
|
||
public void setFormat( final String format ) | ||
{ | ||
this.format = format; | ||
} | ||
|
||
public void setScale( final String scale ) | ||
{ | ||
this.scale = scale; | ||
} | ||
|
||
public String createUrl() | ||
{ | ||
final ImageMediaUrlParams imageMediaUrlParams = ImageMediaUrlParams.create() | ||
.contentId( this.contentId ) | ||
.contentPath( this.contentPath ) | ||
.contextPathType( this.contextPathType ) | ||
.webRequest( this.requestSupplier.get() ) | ||
.urlType( this.urlType ) | ||
.addQueryParams( this.queryParams ) | ||
.background( this.background ) | ||
.scale( this.scale ) | ||
.filter( this.filter ) | ||
.quality( this.quality ) | ||
.format( this.format ) | ||
.projectName( this.projectName ) | ||
.branch( this.branch ) | ||
.build(); | ||
|
||
return urlServiceSupplier.get().imageMediaUrl( imageMediaUrlParams ); | ||
} | ||
|
||
} |
Oops, something went wrong.