Best Practices from Oracle Development's A‑Team

Lookup up a translated asset with Groovy elements

Dolf Dijkstra
Cloud Solutions Architect

In our continued exploration of Groovy as an alternative to traditional JSP element to implement the rendering business logic, we step today into multi-dimensionable assets. Or to put it more simply: how do I look up a translated asset in Groovy.

The example makes use of the FirstSiteII sample site assets. The assetids reference that site.

The code itself is straight forward once you understand the moving parts. To lookup a translated asset 3 components are used: a Dimension (the french locale), a DimensionSet (what it the falldown locale order for the requested locale), and the translated asset. Most of the MDA API works with Collections which makes to sometimes a bit hard to read.


import com.fatwire.assetapi.data.AssetId import com.fatwire.mda.Dimension import com.fatwire.mda.DimensionFilterInstance import com.fatwire.mda.DimensionManager import com.fatwire.mda.DimensionSetInstance import com.fatwire.mda.DimensionSetManager import com.fatwire.system.Session import com.fatwire.system.SessionFactory import com.openmarket.xcelerate.asset.AssetIdImpl import com.openmarket.xcelerate.asset.DimensionSetManagerImpl Session session = SessionFactory.getSession(ics); DimensionSetManager dimensionSetManager =  new DimensionSetManagerImpl(ics); DimensionManager dimensionManager =  (DimensionManager) session.getManager(DimensionManager.class.getName()); AssetId french = new AssetIdImpl("Dimension", 1154551493546L); Collection<AssetId> preferredDimensionIds = Collections.singleton(french); List<Dimension> preferredDimensions = dimensionManager.loadDimensions(preferredDimensionIds); DimensionSetInstance dimset = dimensionSetManager.loadDimensionSet(1154551493573L); //FSIIGlobal DimensionFilterInstance dimensionFilter = dimset.getFilter(); if (dimensionFilter != null){      dimensionFilter.setDimensonPreference(preferredDimensions);      Collection<AssetId> home = Collections.singleton(new AssetIdImpl("Page", 1118867611403L)); //The English home page      Collection<AssetId> filtered = dimensionFilter.filterAssets(home);      for (AssetId id: filtered){            ics.StreamEvalBytes(id.toString());            ics.StreamEvalBytes("<br/>");      } }

As you can see, the DimensionSet it populated with the preferred Dimension, in our case the French locale, and then it filters for the English 'Home' asset. The returned result in our sample is a single asset: the French HomePage asset.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha