Last active
August 1, 2018 23:09
-
-
Save ahmed-musallam/c060b81b165f292d97f4c9aa01ffe9dd to your computer and use it in GitHub Desktop.
Import/Export namespaces from/to AEM instances
This file contains hidden or 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
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() |
This file contains hidden or 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
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