Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
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();

}



Arun Patidar

View solution in original post

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

}



Arun Patidar