I am using JcrUtil.createValidName()API to create a valid node name for assets. JcrUtil.createValidName()is returning a valid node as “myfile_document_brandpdfc240676828additionalfeatureshelp08185555” for all below strings. The values are getting truncated(_V1) after 64 chars.
MyFile_Document_Brand_PDF_C24067_6828_Additional_Features_Help_08185555_V1
MyFile_Document_Brand_PDF_C24067_6828_Additional_Features_Help_08185555_V9
MyFile_Document_Brand_PDF_C24067_6828_Additional_Features_Help_08185555_V13
Could someone help me to avoid truncation with similar functionality?
Here is code snippet:
String fileName="MyFile_Document_Brand_PDF_C24067_6828_Additional_Features_Help_08185555_V1";
String nodeName=JcrUtil.createValidName(fileName,JcrUtil.HYPHEN_LABEL_CHAR_MAPPING);
API Reference:
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Its OOTB JCRUtils class limitation to convert title into a node with 64 character conversion.
If you know the file name format, you can simply create your own getName method like below:
private String createValidName(String title, char separator) {
String validName = title.toLowerCase();
String pattern = "^[a-zA-Z0-9_-]+$";
char[] chrs = validName.toCharArray();
StringBuffer name = new StringBuffer(chrs.length);
for (int i = 0; i < validName.length(); i++) {
String s = Character.toString(chrs[i]);
if (s.matches(pattern)) {
name.append(chrs[i]);
} else {
name.append(separator);
}
}
return name.toString();
}
Hi,
Its OOTB JCRUtils class limitation to convert title into a node with 64 character conversion.
If you know the file name format, you can simply create your own getName method like below:
private String createValidName(String title, char separator) {
String validName = title.toLowerCase();
String pattern = "^[a-zA-Z0-9_-]+$";
char[] chrs = validName.toCharArray();
StringBuffer name = new StringBuffer(chrs.length);
for (int i = 0; i < validName.length(); i++) {
String s = Character.toString(chrs[i]);
if (s.matches(pattern)) {
name.append(chrs[i]);
} else {
name.append(separator);
}
}
return name.toString();
}
Thanks arunpatidar26 . We have written custom code
Views
Replies
Total Likes