Skip to content

Instantly share code, notes, and snippets.

@klcodanr
Created January 19, 2022 15:04
Show Gist options
  • Save klcodanr/d1b60ed084a05b6ef7839cc76022e783 to your computer and use it in GitHub Desktop.
Save klcodanr/d1b60ed084a05b6ef7839cc76022e783 to your computer and use it in GitHub Desktop.
Quick Groovy script to check which characters are supported in jcr local names
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