Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

How to read an external js file in java class.

Avatar

Level 2

I am trying to generate hash value for a javascript file in my java class. Im not able to pass the path of the javascript file to my Java method. Could you please suggest where to store js files and how to access them from my java model?

 

For example, could someone suggest what path to give for my js script here - 

 

public String Hashes() {
List<String> jsFiles = new ArrayList<>();
jsFiles.add("/pathtojsfile.js");
 
}

 

Thanks

6 Replies

Avatar

Level 8

Keep the js file in your project DAM location (example: /content/dam/abc/jsFiles

Read the js file from java logic. 

Query: Are you going to modify the js file content from java logic?

no, I just need to read the js file and generate hash 512 for the same to avoid using unsafe-inline in CSP. So this should work?

public String Hashes() {
List<StringjsFiles = new ArrayList<>();
jsFiles.add("/content/dam/abc/jsFiles");
 
}

Avatar

Community Advisor

hi @Silvia_Joyce_Balraj  you can save the file in DAM location or etc/clientlibs location. But can you explain the exact business requirement for this. Never came across such ask till now 

Avatar

Community Advisor

Hi @Silvia_Joyce_Balraj 

Were the user suggestions helpful? Let us know if more details are needed or mark the answer as correct. If you found a solution independently, please share it with the community.



Arun Patidar

Avatar

Administrator

@Silvia_Joyce_Balraj Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni