/testJcrNodeNames.groovy Secret
Created
January 19, 2022 15:04
Star
You must be signed in to star a gist
Quick Groovy script to check which characters are supported in jcr local names
This file contains 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 javax.jcr.*; | |
import java.util.*; | |
import java.util.stream.*; | |
import java.io.*; | |
import java.nio.*; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
// quick script to check which characters are supported in jcr local names | |
Session session = resourceResolver.adaptTo(Session.class); | |
Node test = session.getNode('/content/test'); | |
unsupportedText = new File("~/Desktop/unsupported.txt"); | |
writer = new BufferedWriter(new FileWriter(unsupportedText)); | |
Node bucket = test.addNode('bucket-0',"nt:unstructured"); | |
session.save(); | |
session.refresh(false) | |
int group = 0; | |
List<Map<String,Object>> failedCodepoints = new ArrayList<>(); | |
for (int i=0; i<=1114110; i++) { | |
if (Character.isDefined(i)){ | |
println "Creating node ${Integer.toHexString(i)}: ${new String(Character.toChars(i))}"; | |
try{ | |
bucket.addNode("test-${new String(Character.toChars(i))}-test","nt:unstructured"); | |
session.save(); | |
}catch(RepositoryException re){ | |
char[] chars = Character.toChars(i); | |
for(char c : chars){ | |
failedCodepoints.add([character: new String(c), num: i, unicode: String.format("\\u%04x", (int) c), name: Character.getName((int)c)]); | |
writer.println("${String.format("\\u%04x", (int) c)}: ${Character.getName((int)c)}") | |
writer.flush(); | |
} | |
session.refresh(false) | |
} | |
} | |
if(i > 0 && i % 1000 == 0){ | |
group++; | |
bucket = test.addNode("bucket-${group}","nt:unstructured"); | |
} | |
} | |
println failedCodepoints | |
ObjectMapper mapper = new ObjectMapper(); | |
file = new File("~/Desktop/unsupported.json"); | |
mapper.writeValue(file,failedCodepoints); | |
writer.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment