How to read an external js file in java class. | Community
Skip to main content
Level 2
April 2, 2024

How to read an external js file in java class.

  • April 2, 2024
  • 4 replies
  • 1793 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

Level 7
April 2, 2024

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?

Level 2
April 2, 2024

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");
 
}
Jagadeesh_Prakash
Community Advisor
Community Advisor
April 2, 2024

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 

Level 2
April 2, 2024

I need to generate hashes for scripts for CSP

arunpatidar
Community Advisor
Community Advisor
April 8, 2024

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
kautuk_sahni
Community Manager
Community Manager
May 16, 2024

@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