Programatically creating Package using Jcrpackagemanager by translating path | Community
Skip to main content
AEMProfile
Level 2
February 17, 2023

Programatically creating Package using Jcrpackagemanager by translating path

  • February 17, 2023
  • 2 replies
  • 1172 views

Hi,

 

I want to programatically create package & translate the path in created package. For example '/content/dam/abc/hero.png' needs to be '/content/dam/bcd/hero.png'. Is it possible to do this using Jcrpackage manager api with filter/translate options? I tried below code but it is not working.

 

JcrPackageManager jcrPackageManager = packaging.getPackageManager(request.getResourceResolver().adaptTo(Session.class)); JcrPackage jcrPackage = jcrPackageManager.create("my_packages", "translatedpackage","1.0"); JcrPackageDefinition definition = jcrPackage.getDefinition(); DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter(); filter.translate(new SimplePathMapping("/content/dam/abc/", "/bcd/")); PathFilterSet pathFilterSet = new PathFilterSet(); pathFilterSet.setRoot("/content/dam/abc/hero.png"); definition.setFilter(filter,true); ProgressTrackerListener listener = new DefaultProgressListener(); jcrPackageManager.assemble(jcrPackage, listener);

 

I was expecting output package to have translated path but it is not working. Any suggestions?

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

2 replies

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 17, 2023

You would need to run "translations" project on the particular DAM folder path. Then after, you can create content packages. Programmatically create AEM Translation Projects | by Vishal | Medium

B_Sravan
Community Advisor
Community Advisor
February 18, 2023

Hi @aemprofile ,

since the created package is not yet built I am thinking that's the reason why it isn't able to hold the filters. Try this way:

1. get a built package through package manager API,

2. get the filters' list List<PathFilterSet> getFilterSets().

3. perform the usual collections List and string operations to change the filter paths and proceed to package it.

later you can add any listeners to automate this if needed.

-Sravan

AEMProfile
Level 2
February 19, 2023

Hi @b_sravan I tried with existing package but no luck, it does not translate while export. I can only translate while importing.