EnterMedia contains an advanced event system. With the EnterMedia events system you can: The best way to demonstrate events is give an example. For this example I will be creating a new event which will go through all of the items in the photo catalog, if the item contains the word 'portrait' in the title it will rotate the image 90 degrees.
  1. Add an xconf file to the catalogs events folder. For this example I called my file autorotate.xconf. The xconf file defines the actions the event should perform. In this case my event will be running a script called autorotate.bsh. You can also have your event run path actions or page actions. Here is the text for autorotate.xconf:
    <page>
    <property name="virtual">true</property>
    <path-action name="Script.run" allowduplicates="true">
    <script>/${catalogid}/events/scripts/autorotate.bsh</script>
    </path-action>
    </page>
  2. Now for the hard part, write the script. The following bit of code will iterate over all assets in a catalog, if you only want certain items in a catalog you can modify the searcher to fit your needs.
    import org.openedit.data.Searcher;
    import com.openedit.hittracker.SearchQuery;
    import com.openedit.hittracker.HitTracker;
    
    public void init()
    {
    	catalogid = context.getPageValue("catalogid");
    	log.info("Auto rotating assets in " + catalogid);
    	mediaArchive = context.getPageValue("mediaarchive");
    	int count = 0;
    	
    	//load xml file that contains what libraries have special permissions
    	searcherManager = mediaArchive.getSearcherManager();
    	
    	//search for all of the assets in the catalog
    	Searcher targetsearcher = mediaarchive.getAssetSearcher();
    	SearchQuery q = targetsearcher.createSearchQuery();
    	q.addMatches("category", "index");
    	
    	HitTracker hits = targetsearcher.search(q);
    	
    	//loop through every asset in the catalog
    	for (Iterator iterator = hits.iterator(); iterator.hasNext();)
    	{
    		hit = iterator.next();
    	}
    }
    
    init();
    
    In this case I only want the assets that contain 'portrait' in the title so I change:
    q.addMatches("category", "index");
    
    to:
    q.addMatches("assettitle", "portrait");
    
    Next in the for loop we need to load the asset object and set it's rotation. Which is accomplished with the following code:
    //load the asset
    asset = mediaArchive.getAssetBySourcePath(hit.get("sourcepath"));
    //set the rotation 8 is the value for 90 degrees see
    asset.set("imageorientation", "8");
    
  3. Finally, the fun part, running the script. Go to the events page and click the run link for our new auto rotate event. If the auto rotate event does not show up click the reload link.
Last Updated: Thu Dec 03 13:56:01 EST 2009