Created
June 17, 2013 21:11
-
-
Save anonymous/5800488 to your computer and use it in GitHub Desktop.
replace text
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
getPage("/content/acs1/en/pressroom/presspacs/2013/acs-presspac-march-20-2013").recurse{ p-> | |
p.node.recurse{ n -> | |
def txtNode = n.get("text") | |
if(txtNode?.contains(p.name)){ | |
def xml = new XmlSlurper().parseText(txtNode)?.childNodes()?.each(){ | |
if(it.name =="img"){ | |
def src = it.attributes().get("src") | |
println 'Page NAME : ' + p.name | |
println ' IMG TAG SRC : ' + src | |
println ' PARENT name ' + p.node.parent.name | |
def oldPath = "presspacs/" + p.name | |
def newPath = "presspacs/" + p.node.parent.name + "/" + p.name | |
println ' REPLACING.... : ' + oldPath +" with " + newPath | |
def repTxtNode = txtNode.replace(oldPath,newPath) | |
n.set("text",repTxtNode) | |
} | |
} | |
} | |
println 'SAVING SESSION' | |
session.save() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getPage("/content/acs1/en/pressroom/presspacs").recurse{ p->
p.node.recurse{ n ->
def txtNode = n.get("text")
if(txtNode?.contains('src="/content/acs1/en/pressroom/presspacs/' + p.name) && p.parent.name != "presspacs"){
println ( 'Page NAME : ' + p.name)
def oldPath = 'src="/content/acs1/en/pressroom/presspacs/' + p.name
def newPath = 'src="/content/acs1/en/pressroom/presspacs/' + p.parent.name + "/" + p.name
println(' REPLACING.... : ' + oldPath +" with " + newPath)
def repTxtNode = txtNode.replaceAll(oldPath,newPath)
n.set("text",repTxtNode)
println ('new txt node : ' + repTxtNode)
println ( ' SAVING SESSION')
session.save()
}else{
println("skipping " + n.path + " , does not match filter")
}
}