Skip to content

Instantly share code, notes, and snippets.

@ahmed-musallam
Last active August 1, 2018 23:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmed-musallam/c060b81b165f292d97f4c9aa01ffe9dd to your computer and use it in GitHub Desktop.
Save ahmed-musallam/c060b81b165f292d97f4c9aa01ffe9dd to your computer and use it in GitHub Desktop.
Import/Export namespaces from/to AEM instances
import com.google.gson.JsonArray
import com.google.gson.JsonObject
/**
* This script will print a JSON array of all namespaces on current AEM instance
* Each JSON object in the array will be of the format:
* {"prefix":"The namespace prefix", "uri":"The namespace uri"}
*
*/
def reg = session.getWorkspace().getNamespaceRegistry();
def jsonArray = new JsonArray()
reg.getPrefixes().each { prefix ->
def uri = reg.getURI(prefix)
def json = new JsonObject()
json.addProperty("prefix", prefix)
json.addProperty("uri", uri)
jsonArray.add(json)
}
print jsonArray.toString()
import com.google.gson.Gson;
/**
* This script will import a JSON array of all namespaces into current AEM instance
* Each JSON object in the array should be of the format:
* {"prefix":"The namespace prefix", "uri":"The namespace uri"}
*/
// Add the exported prefixes (from previous) into this string
def jsonString = '[{"prefix":"stFNT","uri":"http://ns.adobe.com/xap/1.0/sType/Font#"}]
class NameSpace {
String prefix;
String uri;
}
def gson = new Gson()
NameSpace[] namespaces = gson.fromJson(jsonString, NameSpace[].class);
def reg = session.getWorkspace().getNamespaceRegistry();
namespaces.each{ n ->
print "Registering namespace: prefix=${n.prefix}, uri=${n.uri}"
reg.registerNamespace(n.prefix, n.uri) // register the namespace
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment