@@ -339,7 +339,6 @@ public String generate() {
339339 }
340340
341341 public String generate (String source ) {
342-
343342 boolean useRootPath = this .config .useRootPath ;
344343 if (this .useRootPath != null ) {
345344 useRootPath = this .useRootPath ;
@@ -405,8 +404,7 @@ public String generate(String source) {
405404 String resourceType = this .resourceType ;
406405 if (resourceType == null ) resourceType = "image" ;
407406 String finalResourceType = finalizeResourceType (resourceType , type , urlSuffix , useRootPath , config .shorten );
408- String prefix = unsignedDownloadUrlPrefix (source , config .cloudName , config .privateCdn , config .cdnSubdomain , config .secureCdnSubdomain , config .cname , config .secure , config .secureDistribution );
409-
407+ String prefix = unsignedDownloadUrlPrefix (source , config );
410408 String join = StringUtils .join (new String []{prefix , finalResourceType , signature , transformationStr , version , source }, "/" );
411409 String url = StringUtils .mergeSlashesInUrl (join );
412410
@@ -507,49 +505,52 @@ public String finalizeResourceType(String resourceType, String type, String urlS
507505 return result ;
508506 }
509507
510- public String unsignedDownloadUrlPrefix (String source , String cloudName , boolean privateCdn , boolean cdnSubdomain , Boolean secureCdnSubdomain , String cname , boolean secure , String secureDistribution ) {
511- if (this . config .cloudName .startsWith ("/" )) {
512- return "/res" + this . config .cloudName ;
508+ public static String unsignedDownloadUrlPrefix (String source , Configuration config ) {
509+ if (config .cloudName .startsWith ("/" )) {
510+ return "/res" + config .cloudName ;
513511 }
514- boolean sharedDomain = !this . config .privateCdn ;
512+ boolean sharedDomain = !config .privateCdn ;
515513
516514 String prefix ;
515+ String cloudName ;
516+ String secureDistribution = config .secureDistribution ;
517+ Boolean secureCdnSubdomain = null ;
517518
518- if (this . config .secure ) {
519- if (StringUtils .isEmpty (this . config .secureDistribution ) || this . config .secureDistribution .equals (Cloudinary .OLD_AKAMAI_SHARED_CDN )) {
520- secureDistribution = this . config .privateCdn ? this . config .cloudName + "-res.cloudinary.com" : Cloudinary .SHARED_CDN ;
519+ if (config .secure ) {
520+ if (StringUtils .isEmpty (config .secureDistribution ) || config .secureDistribution .equals (Cloudinary .OLD_AKAMAI_SHARED_CDN )) {
521+ secureDistribution = config .privateCdn ? config .cloudName + "-res.cloudinary.com" : Cloudinary .SHARED_CDN ;
521522 }
522523 if (!sharedDomain ) {
523524 sharedDomain = secureDistribution .equals (Cloudinary .SHARED_CDN );
524525 }
525526
526527 if (secureCdnSubdomain == null && sharedDomain ) {
527- secureCdnSubdomain = this . config .cdnSubdomain ;
528+ secureCdnSubdomain = config .cdnSubdomain ;
528529 }
529530
530531 if (secureCdnSubdomain != null && secureCdnSubdomain == true ) {
531- secureDistribution = this . config .secureDistribution .replace ("res.cloudinary.com" , "res-" + shard (source ) + ".cloudinary.com" );
532+ secureDistribution = config .secureDistribution .replace ("res.cloudinary.com" , "res-" + shard (source ) + ".cloudinary.com" );
532533 }
533534
534535 prefix = "https://" + secureDistribution ;
535- } else if (StringUtils .isNotBlank (this . config .cname )) {
536- String subdomain = this . config .cdnSubdomain ? "a" + shard (source ) + "." : "" ;
537- prefix = "http://" + subdomain + this . config .cname ;
536+ } else if (StringUtils .isNotBlank (config .cname )) {
537+ String subdomain = config .cdnSubdomain ? "a" + shard (source ) + "." : "" ;
538+ prefix = "http://" + subdomain + config .cname ;
538539 } else {
539540 String protocol = "http://" ;
540- cloudName = this . config .privateCdn ? this . config .cloudName + "-" : "" ;
541+ cloudName = config .privateCdn ? config .cloudName + "-" : "" ;
541542 String res = "res" ;
542- String subdomain = this . config .cdnSubdomain ? "-" + shard (source ) : "" ;
543+ String subdomain = config .cdnSubdomain ? "-" + shard (source ) : "" ;
543544 String domain = ".cloudinary.com" ;
544545 prefix = StringUtils .join (new String []{protocol , cloudName , res , subdomain , domain }, "" );
545546 }
546547 if (sharedDomain ) {
547- prefix += "/" + this . config .cloudName ;
548+ prefix += "/" + config .cloudName ;
548549 }
549550 return prefix ;
550551 }
551552
552- private String shard (String input ) {
553+ private static String shard (String input ) {
553554 CRC32 crc32 = new CRC32 ();
554555 crc32 .update (Util .getUTF8Bytes (input ));
555556 return String .valueOf ((crc32 .getValue () % 5 + 5 ) % 5 + 1 );
0 commit comments