Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

valid Name is getting truncated while using JcrUtil.createValidName()

Avatar

Level 2

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:

https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/co...

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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();

}

View solution in original post

0 Replies

Avatar

Correct answer by
Community Advisor

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();

}