import java.util .*;
import java.lang .*;
import java.io .*;
class Ideone {
static void main( String[ ] args) {
def canonicalName = "/Example/Exchange/Groups/Roles/Staff/Staff-Role1" ;
def domain = "DC=" + canonicalName.tokenize ( "/" ) .reverse ( ) [ - 1 ] + ",DC=COM" ;
def ouDN = "OU=" + canonicalName.tokenize ( "/" ) .reverse ( ) [ 1 ] ;
def ouName = canonicalName.tokenize ( "/" ) .reverse ( ) [ 1 ] ;
def path = "OU=" + canonicalName.tokenize ( "/" ) .reverse ( ) [ 1 ..- 2 ] .join ( ",OU=" ) ;
System.out .println ( "Domain Value = " + domain) ;
System.out .println ( "OU DN Value = " + ouDN) ;
System.out .println ( "OU Name Value = " + ouName) ;
System.out .println ( "Full Path Value = " + path) ;
System.out .println ( "Complete = " + path + ',' + domain) ;
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CiAKY2xhc3MgSWRlb25lIHsKICAgIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewoJCWRlZiBjYW5vbmljYWxOYW1lID0gIi9FeGFtcGxlL0V4Y2hhbmdlL0dyb3Vwcy9Sb2xlcy9TdGFmZi9TdGFmZi1Sb2xlMSI7CgkJZGVmIGRvbWFpbiA9ICJEQz0iICsgY2Fub25pY2FsTmFtZS50b2tlbml6ZSgiLyIpLnJldmVyc2UoKVstMV0gKyAiLERDPUNPTSI7CgkJZGVmIG91RE4gPSAiT1U9IiArIGNhbm9uaWNhbE5hbWUudG9rZW5pemUoIi8iKS5yZXZlcnNlKClbMV07CgkJZGVmIG91TmFtZSA9IGNhbm9uaWNhbE5hbWUudG9rZW5pemUoIi8iKS5yZXZlcnNlKClbMV07CgkJZGVmIHBhdGggPSAiT1U9IiArIGNhbm9uaWNhbE5hbWUudG9rZW5pemUoIi8iKS5yZXZlcnNlKClbMS4uLTJdLmpvaW4oIixPVT0iKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oIkRvbWFpbiBWYWx1ZSA9ICIgKyBkb21haW4pOwoJCVN5c3RlbS5vdXQucHJpbnRsbigiT1UgRE4gVmFsdWUgPSAiICsgb3VETik7CgkJU3lzdGVtLm91dC5wcmludGxuKCJPVSBOYW1lIFZhbHVlID0gIiArIG91TmFtZSk7CgkJU3lzdGVtLm91dC5wcmludGxuKCJGdWxsIFBhdGggVmFsdWUgPSAiICsgcGF0aCk7CgkJU3lzdGVtLm91dC5wcmludGxuKCJDb21wbGV0ZSA9ICIgKyBwYXRoICsgJywnICsgZG9tYWluKTsKICAgIH0KfQ==
stdout
Domain Value = DC=Example,DC=COM
OU DN Value = OU=Staff
OU Name Value = Staff
Full Path Value = OU=Staff,OU=Roles,OU=Groups,OU=Exchange
Complete = OU=Staff,OU=Roles,OU=Groups,OU=Exchange,DC=Example,DC=COM